1 / 78

Семинар по интервальным вычислениям на Java

МАК ’13. Семинар по интервальным вычислениям на Java. Д. Ю. Надёжин ООО “Оракл Девелопмент Спб” Санкт-Петербург, Россия dmitry.nadezhin@oracle.com. С. И. Жилин Алтайский Государственный Университет Барнаул, Россия sergei@asu.ru. План. Введение в интервальные вычисления

lorene
Download Presentation

Семинар по интервальным вычислениям на Java

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. МАК’13 Семинар по интервальным вычислениям на Java Д. Ю. Надёжин ООО “Оракл Девелопмент Спб” Санкт-Петербург, Россия dmitry.nadezhin@oracle.com С. И. Жилин Алтайский Государственный Университет Барнаул, Россия sergei@asu.ru

  2. План • Введение в интервальные вычисления • Проект стандарта P1788: основные идеи • Установка и настройка ПО • Простейшая программа (создание проекта) • Интервалы: виды, контексты, операции • Вектора и матрицы • ИСЛАУ • Разное Барнаул, 28 Июня 2013 МАК 2013 2/ 60

  3. Проект стандарта P1788 • Уровни спецификации: 1, 2, 3, 4 • Стили: теоретико-множественный, Каухера • Классические интервалы – общие для всех стилей • Декоры • Интервальный тип (уровень 2) Барнаул, 28 Июня 2013 МАК 2013 3/ 60

  4. Уровни спецификации • 1: Уровень математической модели • 2: Уровень интервальных типов данных • 3: Уровень представлений • 4: Уровень цепочек битов Барнаул, 28 Июня 2013 МАК 2013 4/ 60

  5. Классические интервалы • [a,b], a <= b Барнаул, 28 Июня 2013 МАК 2013 5/ 60

  6. Теоретико-множественный стиль • [a,b], a <= b • ∅ • [-∞,b] • [a,+∞] • [-∞,+∞] Барнаул, 28 Июня 2013 МАК 2013 6/ 60

  7. Стиль Каухера • [a,b], a <= b • [a,b], a > b Барнаул, 28 Июня 2013 МАК 2013 7/ 60

  8. Декоры f(x) Dom(f) • Com: x - непусто, x ⊆ Dom(f) , f(x) непрерывна в каждой точке интервала x ∊ x, результат – ограниченный интервал • Dac: x - непусто, x ⊆ Dom(f) , ограничение f(x) на x непрерывно • Def: x - непусто, x ⊆ Dom(f) • Trv: всегда true • Ill: не интервал NaI, формально Dom(f) пуст Барнаул, 28 Июня 2013 МАК 2013 8/ 60

  9. Декоры f(x) = 1/x Dom(f)=[-∞,0) ∪ (0,+∞] • f([1,2]_com) = [½,1]_com • f([1,+∞]_com) = [0,1]_dac • sign([0,½]_com)=[0,1]_def • f([0,1]_com) = [1,+∞]_trv • f([0,0]_com) = [empty]_trv • nums2interval(2,1) = [empty]_ill Барнаул, 28 Июня 2013 МАК 2013 9/ 60

  10. Интервальный тип (уровень 2) • Конечное подможество мноожества математических интервалов • Функция hull – проекция из всех математических интервалов в указанное подмножество Барнаул, 28 Июня 2013 МАК 2013 10/ 60

  11. Установка и настройка ПО • Java 7.0u25 и NetBeans 7.3 • Ant или Maven • Готовый Maven - репозиторий ~/.m2 • После окончания семинара можно поправить <offline>false</offline> в файле ~/.m2/settings.xml • Не обязательно – исходные тексты Jinterval ~/NetBeansProjects/net.java.jinterval~svn Барнаул, 28 Июня 2013 МАК 2013 11/ 60

  12. Создание проекта • File|New Project... • Choose Project|Maven|Java Application|Next> • Project name: tutor-rational • GroupId: ru.asu • Package: ru.asu.tutor.rational • Enter • Open ru.asu.tutor.rational.App Барнаул, 28 Июня 2013 МАК 2013 12/ 60

  13. NetBeans не знает про Rational package ru.asu.tutor.rational; /** * Hello world! * */ public class App { public static void main( String[] args ) { Rational[] rats = { Rational.zero() }; System.out.println( "Hello World!" ); } } Барнаул, 28 Июня 2013 МАК 2013 13/ 60

  14. Добавление зависимостей • Выбираем в Projects узел tutor-rational|Dependencies • Щелчок правой кнопкой мыши • Add dependency • Query: rational • Unfold: net.java.jinterval:jinterval-rational-java • Choose: 0.1-SNAPSHOT [ jar ] local • В окне редактирования правая кнопка мыши FixImport Барнаул, 28 Июня 2013 МАК 2013 14/ 60

  15. Импорт вставлен package ru.asu.tutor.rational; import net.java.jinterval.rational.Rational; /** * Hello world! * */ public class App { public static void main( String[] args ) { Rational[] rats = { Rational.zero() }; } } Барнаул, 28 Июня 2013 МАК 2013 15/ 60

  16. Способы создания Rational package ru.asu.tutor.rational; import net.java.jinterval.rational.Rational; /** * Hello world! * */ public class App { public static void main( String[] args ) { Rational[] rats = { Rational.zero(), Rational.valueOf(2), Rational.valueOf(0.1), Rational.valueOf(1, 10) }; for (Rational r: rats) { System.out.println(r); } } } Барнаул, 28 Июня 2013 МАК 2013 16/ 60

  17. Способы вывода Rational MathContext mc20f = new MathContext(20, RoundingMode.FLOOR); MathContext mc20c = new MathContext(20, RoundingMode.CEILING); for (Rational r: rats) { System.out.println(r + " " + r.doubleValue() + " [" + r.bigDecimalValue(mc20f) + "," + r.bigDecimalValue(mc20c) + "]"); } 0.0 0.0 [0,0] +0x1p1 2.0 [2,2] +0xccccccccccccdp-55 0.1 [0.10000000000000000555,0.10000000000000000556] +0x1/0x5*2^-1 0.1 [0.1,0.1] Барнаул, 28 Июня 2013 МАК 2013 17/ 60

  18. Точные операции над Rational ExtendedRational diff = ExtendedRationalOps.subtract(rats[2], rats[3]); System.out.println("diff " + diff + " " + diff.doubleValue() + " [" + diff.bigDecimalValue(mc20f) + "," + diff.bigDecimalValue(mc20c) + "]"); diff +0x1/0x5*2^-55 5.551115123125783E-18 [5.5511151231257827021E-18,5.5511151231257827022E-18] Барнаул, 28 Июня 2013 МАК 2013 18/ 60

  19. Javadoc нет, взглянем на исходники • File|Open Project... • ~/NetBeansProject/net.java.jinterval~svn/trunk/jinterval • В Projects раскрыть jinterval|Modules • Получили список подпроектов jinterval • Двойной шелчок на jinterval-rational-java • Раскрыть jinterval-rational-java|Source packages • Получили список пакетов • Раскрыть net.java.jinterval.rational • Откроем ExtendedRationalContext Барнаул, 28 Июня 2013 МАК 2013 19/ 60

  20. Rump Example in Rationals • File|Open Project... • ~/NetBeansProjects/RumpExample Барнаул, 28 Июня 2013 МАК 2013 20/ 60

  21. JInterval Library: Principles, Development, and Perspectives WHY INTERVAL COMPUTATIONS IN JVM? Барнаул, 28 Июня 2013 МАК 2013 21/ 60

  22. Java Is Popular • TIOBE Programming Community Index for September 2012 • Calculated by counting hits of the most popular search engines Барнаул, 28 Июня 2013 МАК 2013 22/ 60

  23. Java Is Popular • RedMonk’s language ranking for September 2012 Popularity Rank on StackOverflow.com (by # of tags) Popularity Rank on Github.com (by # of projects) Барнаул, 28 Июня 2013 МАК 2013 23/ 60

  24. Java Is Popular •  Bookscan's reports on the top 3,000 titles sold Барнаул, 28 Июня 2013 МАК 2013 24/ 60

  25. Gap between Interval and Applied Software • Java is an attractive and widely adopted technology for applied software development • Cross-platform portability of applications • General purpose object-oriented language • Almost any language can generate Java bytecodes • Advanced tools for distributed systemsdevelopment • Huge amount of applied libraries • Interval analysis and interval computations have proved to be useful in numerous real-world applications • Interval software in Java is of fragmentary character • Creation of systematic full-featured high-level interval library for Java brings interval tools closer to developers of applied software Барнаул, 28 Июня 2013 МАК 2013 25/ 60

  26. Interval Computations in Java • Is Java suitable for scientific computing? Pro: • Portability of Java Virtual Machine (JVM) • Safe memory management(no memory leaks and pointer errors) • Network-aware environment • Parallel and distributed computing (threads, RMI) • Strict modelof security • Standard API for GUI,graphics, DBMS, … • Widely adopted • Embedded systems, browsers, … • Development, teaching, … Con: • Low performance • Virtual machine • Interpretation is slow • Overhead cost of safe memory management • Language restrictions • No primitive structure type • No operator overloading • No traditional multidimesional arrays • No full compliance with IEEE 754* • Relatively small number of scientific libraries on Java • Scientific computing traditions: Fortran, С/С++ *Kahan W., Darcy J.D. How Java’s Floating-Point Hurts Everyone Everywhere//ACM 1998 Workshop on Java for High–Performance Network Computing,Stanford University, March 1998, http://www.cs.berkeley.edu/~wkahan/JAVAhurt.pdf Барнаул, 28 Июня 2013 МАК 2013 26/ 60

  27. Interval Java Libraries • IA_math, 1997 • Classic IA, classic interval elementary functions • Timothy J. Hickey, • Brandeis University, Boston, USA • interval.sourceforge.net/interval/ • Java-XSC, 1999 • Classic IA, rectangular complex IA, classic interval elementary functions, classic and complex interval vectors and matrices • Benjamin R.C. Bedregal, Jose E.M. Dutra • Universidade Federal do Rio Grande do Norte, Natal, Brazil • www.dimap.ufrn.br/~java-xsc/jxsc2007.html Барнаул, 28 Июня 2013 МАК 2013 27/ 60

  28. JInterval Library: Principles, Development, and Perspectives JINTERVAL EVOLUTION Барнаул, 28 Июня 2013 МАК 2013 28/ 60

  29. Stages of JInterval Evolution • Sep 2008 JInterval is started as undergraduate student project ”Childhood” at Altai State University (Barnaul, Russia)http://code.google.com/p/javaintervalmathasu/ • Aug 2009 Dmitry Nadezhin (Sun Labs, Zelenograd, Russia) “Boyhood” joins the projecthttp://kenai.com/projects/jinterval • Jan 2012 Developing reference implementation and “Youth” test suite for P1788 becomes Priority #1 http://java.net/projects/jinterval orhttp://jinterval.java.net Барнаул, 28 Июня 2013 МАК 2013 29/ 60

  30. JInterval (Boyhood): A Priori Requirements The library • Must be clear and easy to use • Should provide flexibility in the choice of interval algebra for computations • Should provide flexibility to extend its functionality • Should provide flexibility in choosing precision of interval boundaries and associated rounding policies • Must be portable • Should provide high performance • Must be open source Priority Барнаул, 28 Июня 2013 МАК 2013 30/ 60

  31. JInterval (Boyhood): Architecture • “Fast” branch: • Interval bounds: double, nearest rounding • IA: set-based, Kaucher, complex rectangular, complex circular, complex ring, complex polar • Interval elementary functions, vectors, matrices • ILS: Gauss, Gauss-Seidel, subdifferential Newton, NonNeg, Shaidurov • “Rational bounds” branch: • Interval bounds: smart rational/double, arbitrary precision, rounding policies, contexts • IA: set-based • Interval elementary functions, vectors, matrices • Generic interfaces on top of branches Барнаул, 28 Июня 2013 МАК 2013 31/ 60

  32. JInterval (Boyhood): Type Hierarchy Interval ClassicRealInterval ComplexInterval RealInterval DoubleInterval ComplexIntervalCircle RationalInterval ComplexIntervalRectangle ComplexIntervalPolar ComplexIntervalRing Барнаул, 28 Июня 2013 МАК 2013 32/ 60

  33. JInterval (Boyhood): Lessons Learned Java r = x.add(y.multiply(z)); Scala r = x + y*z Барнаул, 28 Июня 2013 МАК 2013 33/ 60

  34. JInterval Library: Principles, Development, and Perspectives ARCHITECTURE Барнаул, 28 Июня 2013 МАК 2013 34/ 60

  35. Class Diagram (package net.java.jinterval.interval) Барнаул, 28 Июня 2013 МАК 2013 35/ 60

  36. Key-role Interfaces • Types graph follows the flavor structure of P1788 • Java interfaces: • Interval Common methods for all flavors • SetInterval Extends Interval with methods for flavor ‘Set Interval’ • KaucherInterval Extends Interval with methods for flavor ‘Kaucher interval’ • ClassicInterval Extends all flavors, because can be mapped to related flavor intervals Барнаул, 28 Июня 2013 МАК 2013 36/ 60

  37. Interface Interval: common methods of all flavors • Intervaldefines common methods of all interval flavors • Defines numerical and boolean operations only Барнаул, 28 Июня 2013 МАК 2013 37/ 60

  38. IntervalContext: interval operations interface • Generic interface IntervalContextdefines signature for interval-valued methods Барнаул, 28 Июня 2013 МАК 2013 38/ 60

  39. KaucherIntervalContext: interval flavor interface • KaucherIntervalContextextends IntervalContextand binds type variable Ito Kaucher interval flavor Барнаул, 28 Июня 2013 МАК 2013 39/ 60

  40. Implementation of interval contexts • There may be several implementations for flavor contexts • SetIntervalContextInfSupBase andSetIntervalContextInfSup are two tightest implementations of set interval operations and functions (P1788 Level 2, InfSup_F). Барнаул, 28 Июня 2013 МАК 2013 40/ 60

  41. Factory classes for interval contexts • Factory classes create particular instances of interval contexts • SetIntervalContexts • KaucherIntervalContexts Барнаул, 28 Июня 2013 МАК 2013 41/ 60

  42. Exact context • Static method getExact() creates the exact context • All operations in the exact context return intervals with rational bounds – P1788 Level 1 results or throw IrrationalException Барнаул, 28 Июня 2013 МАК 2013 42/ 60

  43. InfSup_F contexts • Static method getInfSup(BinaryValueSet numberFormat)creates theInfsSup_F contexts with binary floating-point interval representations (BINARY32, BINARY64, BINARY128, …, BINARY1024) Барнаул, 28 Июня 2013 МАК 2013 43/ 60

  44. Core Module Dependencies Graph JInterval packages External dependencies jintervalAggregator of JInterval jinterval-rational-java Rational numbers boehm-crealsBoehm’s constructive reals jinterval-interval-java Intervals, IAs, interval elem. functions fortress-roundingRounding class from Fortress commons-math3Apache Commons Math 3.0 jinterval-ilsInterval linear equation system solver lpsolveJava port of lp_solve jinterval-irInterval regression solver jnaJava access to native libraries mpfr-adapterJNA adapter for native GNU MPFR large-test-javaJInterval tests commons-compressApache Commons Compress 1.4 Барнаул, 28 Июня 2013 МАК 2013 44/ 60

  45. JInterval Library: Principles, Development, and Perspectives FUNCTIONALITY AND EXAMPLES Барнаул, 28 Июня 2013 МАК 2013 45/ 60

  46. Functionality of JInterval (Youth) • Rational arithmetic • flexible inner representation (rational, binary32, binary64, binary128,…) • exact and approximate operations • Extended Rational arithmetic • Rational + {-∞ , +∞} • Interval Arithmetic • Set-based • Kaucher • Elementary Functions • According to P1788 • Dense Vectors and Matrices • Rational, extended rational • Interval • Solvers • ILS Solvers • Hansen-Bliek-Rohn-Ning-Kearfott enclosure +Gauss-Seidel • Subdifferential Newton • Interval linear regression solver • Data consistency check • Outlier detection • Object status detection • Interval prediction Барнаул, 28 Июня 2013 МАК 2013 46/ 60

  47. Example 1.1. Contexts and Simple Expressions , , , . x+y = [3.0,5.0] x/y = [0.333251953125,1.0] Барнаул, 28 Июня 2013 МАК 2013 47/ 60

  48. Example 1.2. Contexts and Simple Expressions , , , . x+y = [3.0,5.0] x/y = [0.3333333134651184,1.0] Барнаул, 28 Июня 2013 МАК 2013 48/ 60

  49. Example 1.3. Contexts and Simple Expressions , , , . x+y = [3.0,5.0] x/y = [+0x15555555555555555555555555555p-114,+0x1p0] ([0.3333333333333333,1.0]) Барнаул, 28 Июня 2013 МАК 2013 49/ 60

  50. Example 1.4. Contexts and Simple Expressions , , , . x+y = [3.0,5.0] x/y = [+0x1/0x3*2^0,+0x1p0]([0.3333333333333333,1.0]) Барнаул, 28 Июня 2013 МАК 2013 50/ 60

More Related