import daisy.lang._ import Real._ // To run these benchmarks the file needs to be converted to a scala file object Benchmarks { def sine(x: Real): Real = { require(x > -1.57079632679 && x < 1.57079632679) x - (x*x*x)/6.0 + (x*x*x*x*x)/120.0 - (x*x*x*x*x*x*x)/5040.0 } def sineOrder3(x: Real): Real = { require(-2.0 < x && x < 2.0) 0.954929658551372 * x - 0.12900613773279798*(x*x*x) } def sqroot(x: Real): Real = { require(x >= 0.0 && x < 10.0) 1.0 + 0.5*x - 0.125*x*x + 0.0625*x*x*x - 0.0390625*x*x*x*x } def bspline0(u: Real): Real = { require(0 <= u && u <= 1) (1 - u) * (1 - u) * (1 - u) / 6.0 } def bspline1(u: Real): Real = { require(0 <= u && u <= 1) (3 * u*u*u - 6 * u*u + 4) / 6.0 } def bspline2(u: Real): Real = { require(0 <= u && u <= 1) (-3 * u*u*u + 3*u*u + 3*u + 1) / 6.0 } def bspline3(u: Real): Real = { require(0 <= u && u <= 1) -u*u*u / 6.0 } def rigidBody1(x1: Real, x2: Real, x3: Real): Real = { require(-15.0 <= x1 && x1 <= 15 && -15.0 <= x2 && x2 <= 15.0 && -15.0 <= x3 && x3 <= 15) -x1*x2 - 2*x2*x3 - x1 - x3 } def rigidBody2(x1: Real, x2: Real, x3: Real): Real = { require(-15.0 <= x1 && x1 <= 15 && -15.0 <= x2 && x2 <= 15.0 && -15.0 <= x3 && x3 <= 15) val t1 = x1*x2*x3 val t2 = 3*x3*x3 2*(t1) + t2 - x2*(t1) + t2 - x2 } def traincar1(s0: Real, s1: Real, s2: Real) = { require(0 <= s0 && s0 <= 4.6 && 0 <= s1 && s1 <= 10 && 0 <= s2 && s2 <= 10) (-3.795323e2) * s0 + (-5.443608e2) * s1 + 92.729 * s2 + 4.5165916241610748e3 } def traincar2(s0: Real, s1: Real, s2: Real, s3: Real, s4: Real) = { require(-2 <= s0 && s0 <= 9 && -2 <= s1 && s1 <= 9 && 0 <= s2 && s2 <= 10 && 0 <= s3 && s3 <= 10 && 0 <= s4 && s4 <= 10) (-2.9829300077345002E+00) * s0 + 2.8399180104656203E+01 * s1 + (-1.5201325206209998E+02) * s2 + 3.5623840930436779E+02 * s3 + (-2.0636383424191501E+02) * s4 + 2.1660394157545902E+01 } def traincar3(s0: Real, s1: Real, s2: Real, s3: Real, s4: Real, s5: Real, s6: Real) = { require(-3 <= s0 && s0 <= 5 && -3 <= s1 && s1 <= 5 && -3 <= s2 && s2 <= 5 && -6 <= s3 && s3 <= 11 && -6 <= s4 && s4 <= 11 && -6 <= s5 && s5 <= 11 && -6 <= s6 && s6 <= 11) (-3.7377847506227999E+02) * s0 + (7.0862205220929002E+02) * s1 + (-3.7886044910192999E+02) * s2 + (-4.5413076942315001E+02) * s3 + (-8.7386976105502004E+02) * (1.0) * s4 + (3.5911290954487999E+03) * (1.0) * s5 + (-2.2921226288533999E+03) * (1.0) * s6 + 2.9021426298877441E+02 } def traincar4(s0: Real, s1: Real, s2: Real, s3: Real, s4: Real, s5: Real, s6: Real, s7: Real, s8: Real) = { require(-2.5 <= s0 && s0 <= 6.5 && -2.5 <= s1 && s1 <= 6.5 && -2.5 <= s2 && s2 <= 6.5 && -2.5 <= s3 && s3 <= 6.5 && -2 <= s4 && s4 <= 12 && -2 <= s5 && s5 <= 12 && -2 <= s6 && s6 <= 12 && -2 <= s7 && s7 <= 12 && -2 <= s8 && s8 <= 12) (-1201.0) * s0 + (-4876.0) * s1 + 1.3415999999999998E+04 * s2 + (-10484.0) * s3 + (-774.0) * s4 + (-1.3620000000000002E+04) * s5 + 10481.0 * s6 + 20425.0 * s7 + (-17815.0) * s8 + 5.2121094496644555E+03 } //===================================from iris_java - linear SVC================================================================ def classIDX0 (atts0: Real, atts1: Real, atts2: Real, atts3: Real) = { require(3.0 <= atts0 && atts0 <= 9.0 && 1.5 <= atts1 && atts1 <= 5.0 && -2 <= atts2 && atts2 <= 10 && -1.0 <= atts3 && atts3 <= 3.5) ((-0.85073072819636686) * atts0 + (-0.98664016916368502) * atts1 + (1.3809517485817782) * atts2 + (1.8653450939330991) * atts3) - ((0.18424469636214999) * atts0 + (0.45123431334216657) * atts1 + (-0.80794264540764449) * atts2 + (-0.45071126534400952) * atts3) } def classIDX1 (atts0: Real, atts1: Real, atts2: Real, atts3: Real) = { require(3.0 <= atts0 && atts0 <= 9.0 && 1.5 <= atts1 && atts1 <= 5.0 && -2 <= atts2 && atts2 <= 10 && -1.0 <= atts3 && atts3 <= 3.5) ((0.18424469636214999) * atts0 + (0.45123431334216657) * atts1 + (-0.80794264540764449) * atts2 + (-0.45071126534400952) * atts3) - ((0.052100253064028955) * atts0 + (-0.8942341911807864) * atts1 + (0.40478255170032273) * atts2 + (-0.93774690197704236) * atts3) } def classIDX2 (atts0: Real, atts1: Real, atts2: Real, atts3: Real) = { require(3.0 <= atts0 && atts0 <= 9.0 && 1.5 <= atts1 && atts1 <= 5.0 && -2 <= atts2 && atts2 <= 10 && -1.0 <= atts3 && atts3 <= 3.5) ((0.052100253064028955) * atts0 + (-0.8942341911807864) * atts1 + (0.40478255170032273) * atts2 + (-0.93774690197704236) * atts3) - ((-0.85073072819636686) * atts0 + (-0.98664016916368502) * atts1 + (1.3809517485817782) * atts2 + (1.8653450939330991) * atts3) } //===================================from iris_java - Polynomial SVC============================================================= def polyIDX0 (atts0: Real, atts1: Real, atts2: Real, atts3: Real) = { require(3.0 <= atts0 && atts0 <= 9.0 && 1.5 <= atts1 && atts1 <= 5.0 && -2 <= atts2 && atts2 <= 10 && -1.0 <= atts3 && atts3 <= 3.5) val prob2 = (-0.85073072819636686) * atts0 + (-0.98664016916368502) * atts1 + (1.3809517485817782) * atts2 + (1.8653450939330991) * atts3 val prob0 = (0.18424469636214999) * atts0 + (0.45123431334216657) * atts1 + (-0.80794264540764449) * atts2 + (-0.45071126534400952) * atts3 prob2 * prob2 * prob2 - prob0 * prob0 * prob0 } def polyIDX1 (atts0: Real, atts1: Real, atts2: Real, atts3: Real) = { require(3.0 <= atts0 && atts0 <= 9.0 && 1.5 <= atts1 && atts1 <= 5.0 && -2 <= atts2 && atts2 <= 10 && -1.0 <= atts3 && atts3 <= 3.5) val prob0 = (0.18424469636214999) * atts0 + (0.45123431334216657) * atts1 + (-0.80794264540764449) * atts2 + (-0.45071126534400952) * atts3 val prob1 = (0.052100253064028955) * atts0 + (-0.8942341911807864) * atts1 + (0.40478255170032273) * atts2 + (-0.93774690197704236) * atts3 prob0 * prob0 * prob0 - prob1 * prob1 * prob1 } def polyIDX2 (atts0: Real, atts1: Real, atts2: Real, atts3: Real) = { require(3.0 <= atts0 && atts0 <= 9.0 && 1.5 <= atts1 && atts1 <= 5.0 && -2 <= atts2 && atts2 <= 10 && -1.0 <= atts3 && atts3 <= 3.5) val prob1 = (0.052100253064028955) * atts0 + (-0.8942341911807864) * atts1 + (0.40478255170032273) * atts2 + (-0.93774690197704236) * atts3 val prob2 = (-0.85073072819636686) * atts0 + (-0.98664016916368502) * atts1 + (1.3809517485817782) * atts2 + (1.8653450939330991) * atts3 prob1 * prob1 * prob1 - prob2 * prob2 * prob2 } def neuron(x1 : Real, x2: Real) = { require(1 <= x1 && x1 <= 1 && 0.4 <= x2 && x2 <= 0.5) 1/(1+exp(-(-2.9389/(1+exp(-(5.6706*x1+0.5058*x2+12.4057)))+28.6263/(1+exp(-(17.5208*x2+13.9847*x1-21.5653)))-14.1628))) } //==========================================Filter from vstte13 paper==================================================================== def filter1 (x0: Real) = { require(-2 <= x0 && x0 <= 2) (0.7) * x0 } def filter2 (x1: Real, x0: Real) = { require(-2 <= x0 && x0 <= 2 && -2 <= x1 && x1 <= 2) (0.7) * x1 - (1.3) * x0 + (1.4) * ((0.7) * x0) } def filter3 (x2: Real, x1: Real, x0: Real) = { require(-2 <= x0 && x0 <= 2 && -2 <= x1 && x1 <= 2 && -2 <= x2 && x2 <= 2) val t1 = ((0.7) * x0) (0.7) * x2 - (1.3) * x1 + (1.1) * x0 + (1.4) * ((0.7) * x1 - (1.3) * x0 + (1.4) * t1) - (0.7) * t1 } def filter4 (x3: Real, x2: Real, x1: Real, x0: Real) = { require(-2 <= x0 && x0 <= 2 && -2 <= x1 && x1 <= 2 && -2 <= x2 && x2 <= 2 && -2 <= x3 && x3 <= 2) val t1 = (0.7) * x1 - (1.3) * x0 + (1.4) * ((0.7) * x0) (0.7) * x3 - (1.3) * x2 + (1.1) * x1 + (1.4) * ((0.7) * x2 - (1.3) * x1 + (1.1) * x0 + (1.4) * (t1) - (0.7) * ((0.7) * x0)) - (0.7) * (t1) } //======================================= Cubic examples ======================================================== def cubic(a: Real, b: Real, c: Real) = { require(5 <= a && a <= 10 && 0 <= b && b <= 5 && 0 <= c && c <= 5) (2 * a * a * a - 9 * a * b + 27 * c) / 54 + (a * a - 3 * b) / 9 } }