The JavaScript code for the new 39 math functions of GeneXproTools was easily created from the Java code. After taking care of the functions declarations (they are different in both languages), I had just to replace "double", "int", and "final double" by "var"; all the rest stayed the same.
Of all the programming languages GeneXproTools supports, JavaScript is one of the most important, as it is used for scoring all the models GeneXproTools generates, including the ones with Derived Variables and User Defined Functions. So, we can test the JavaScript code quite easily within the GeneXproTools environment by scoring our models in the Scoring Panel. Indeed, the JavaScript Grammar can be used both for testing and as a reference for designing any Custom Grammar in GeneXproTools.
Here's the JavaScript code for all the new 39 math functions that were added to the built-in math functions of GeneXproTools with v5.0 MR1 "Mini-Release I: What's New?":
{
if (x > 0.0)
return x;
else
return 0.0;
}
function gepRamp2(x)
{
if (x > 0.0)
return 0.0;
else
return x;
}
function gepRamp3(x)
{
if (x > 0.0)
return 0.0;
else
return -x;
}
function gepRamp4(x)
{
if (x > 0.0)
return -x;
else
return 0.0;
}
function gepStep1(x)
{
if (x > 0.0)
return 1.0;
else
return -1.0;
}
function gepStep2(x)
{
if (x > 0.0)
return 1.0;
else
return 0.0;
}
function gepStep3(x)
{
if (x >= 1.0)
return 1.0;
else
if (x <= -1.0)
return -1.0;
else
return x;
}
function gepStep4(x)
{
if (x >= 1.0)
return 1.0;
else
if (x <= 0.0)
return 0.0;
else
return x;
}
function gepCL2A(x, y)
{
if (x > 0.0 && y > 0.0)
return 1.0;
else
return -1.0;
}
function gepCL2B(x, y)
{
if (x >= 0.0 && y < 0.0)
return -1.0;
else
return 1.0;
}
function gepCL2C(x, y)
{
if (x > 1.0 && y < -1.0)
return -1.0;
else
return 1.0;
}
function gepCL2D(x, y)
{
if (x > 0.0 && y > 0.0)
return 1.0;
else
return 0.0;
}
function gepCL2E(x, y)
{
if (x >= 0.0 && y <= 0.0)
return 0.0;
else
return 1.0;
}
function gepCL2F(x, y)
{
if (x > 1.0 && y < -1.0)
return 0.0;
else
return 1.0;
}
function gepCL3A(x, y)
{
if (x > 0.0 && y < 0.0)
return 1.0;
else
if (x < 0.0 && y > 0.0)
return -1.0;
else
return 0.0;
}
function gepCL3B(x, y)
{
if (x >= 1.0 && y >= 1.0)
return 1.0;
else
if (x <= -1.0 && y <= -1.0)
return -1.0;
else
return 0.0;
}
function gepCL3C(x, y)
{
if (x > 0.0 && y > 0.0)
return 1.0;
else
if (x < 0.0 && y < 0.0)
return -1.0;
else
return 0.0;
}
function gepMap3A(x, y)
{
var SLACK = 10.0;
var outVal = 0.0;
if (y < (x - SLACK))
outVal = -1.0;
else if (y > (x + SLACK))
outVal = 1.0;
return outVal;
}
function gepMap3B(x, y, z)
{
var minValue = Math.min(x,y);
var maxValue = Math.max(x,y);
var outVal = 0.0;
if (z < minValue)
outVal = -1.0;
else if (z > maxValue)
outVal = 1.0;
return outVal;
}
function gepMap3C(a, b, c, d)
{
var minValue = Math.min(a,b,c);
var maxValue = Math.max(a,b,c);
var outVal = 0.0;
if (d < minValue)
outVal = -1.0;
else if (d > maxValue)
outVal = 1.0;
return outVal;
}
function gepMap4A(x, y)
{
var SLACK = 10.0;
var outVal = 0.0;
if (y < (x - SLACK))
outVal = 0.0;
else if (y >= (x - SLACK) && y < x)
outVal = 1.0;
else if (y >= x && y < (x + SLACK))
outVal = 2.0;
else if (y >= (x + SLACK))
outVal = 3.0;
return outVal;
}
function gepMap4B(x, y, z)
{
var minValue = Math.min(x,y);
var maxValue = Math.max(x,y);
var midrange = (maxValue + minValue)/2.0;
var outVal = 0.0;
if (z < minValue)
outVal = 0.0;
else if (z >= minValue && z < midrange)
outVal = 1.0;
else if (z >= midrange && z < maxValue)
outVal = 2.0;
else if (z >= maxValue)
outVal = 3.0;
return outVal;
}
function gepMap4C(a, b, c, d)
{
// evaluate minValue(a,b,c), maxValue(a,b,c) and midleValue(a,b,c)
//
// evaluate minValue(a,b,c)
var minValue = a;
var argMin = 0;
if (minValue > b)
{
minValue = b;
argMin = 1;
}
if (minValue > c)
{
minValue = c;
argMin = 2;
}
// evaluate maxValue(a,b,c)
var maxValue = a;
var argMax = 0;
if (maxValue < b)
{
maxValue = b;
argMax = 1;
}
if (maxValue < c)
{
maxValue = c;
argMax = 2;
}
// evaluate midleValue(a,b,c)
var midleValue = c;
if (0 != argMin && 0 != argMax)
midleValue = a;
if (1 != argMin && 1 != argMax)
midleValue = b;
var outVal = 0.0;
if (d < minValue)
outVal = 0.0;
else if (d >= minValue && d < midleValue)
outVal = 1.0;
else if (d >= midleValue && d < maxValue)
outVal = 2.0;
else if (d >= maxValue)
outVal = 3.0;
return outVal;
}
function gepMap5A(x, y)
{
var SLACK = 15.0;
var outVal = 0.0;
if (y < (x - SLACK))
outVal = 0.0;
else if (y >= (x - SLACK) && y < (x - SLACK/3.0))
outVal = 1.0;
else if (y >= (x - SLACK/3.0) && y < (x + SLACK/3.0))
outVal = 2.0;
else if (y >= (x + SLACK/3.0) && y < (x + SLACK))
outVal = 3.0;
else if (y >= (x + SLACK))
outVal = 4.0;
return outVal;
}
function gepMap5B(x, y, z)
{
var minValue = Math.min(x,y);
var maxValue = Math.max(x,y);
var intervalLength = (maxValue - minValue)/3.0;
var midpoint1 = minValue + intervalLength;
var midpoint2 = minValue + 2.0*intervalLength;
var outVal = 0.0;
if (z < minValue)
outVal = 0.0;
else if (z >= minValue && z < midpoint1)
outVal = 1.0;
else if (z >= midpoint1 && z < midpoint2)
outVal = 2.0;
else if (z >= midpoint2 && z < maxValue)
outVal = 3.0;
else if (z >= maxValue)
outVal = 4.0;
return outVal;
}
function gepMap5C(a, b, c, d)
{
// evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
//
// evaluate minValue(a,b,c)
var minValue = a;
var argMin = 0;
if (minValue > b)
{
minValue = b;
argMin = 1;
}
if (minValue > c)
{
minValue = c;
argMin = 2;
}
// evaluate maxValue(a,b,c)
var maxValue = a;
var argMax = 0;
if (maxValue < b)
{
maxValue = b;
argMax = 1;
}
if (maxValue < c)
{
maxValue = c;
argMax = 2;
}
// evaluate midleValue(a,b,c)
var midleValue = c;
if (0 != argMin && 0 != argMax)
midleValue = a;
if (1 != argMin && 1 != argMax)
midleValue = b;
// evaluate midrange1 and midrange2
var midrange1 = (minValue + midleValue)/2.0;
var midrange2 = (midleValue + maxValue)/2.0;
var outVal = 0.0;
if (d < minValue)
outVal = 0.0;
else if (d >= minValue && d < midrange1)
outVal = 1.0;
else if (d >= midrange1 && d < midrange2)
outVal = 2.0;
else if (d >= midrange2 && d < maxValue)
outVal = 3.0;
else if (d >= maxValue)
outVal = 4.0;
return outVal;
}
function gepMap6A(x, y)
{
var SLACK = 10.0;
var outVal = 0.0;
if (y < (x - SLACK))
outVal = 0.0;
else if (y >= (x - SLACK) && y < (x - SLACK/2.0))
outVal = 1.0;
else if (y >= (x - SLACK/2.0) && y < x)
outVal = 2.0;
else if (y >= x && y < (x + SLACK/2.0))
outVal = 3.0;
else if (y >= (x + SLACK/2.0) && y < (x + SLACK))
outVal = 4.0;
else if (y >= (x + SLACK))
outVal = 5.0;
return outVal;
}
function gepMap6B(x, y, z)
{
var minValue = Math.min(x,y);
var maxValue = Math.max(x,y);
var midrange = (minValue + maxValue)/2.0;
var midpoint1 = (minValue + midrange)/2.0;
var midpoint2 = (midrange + maxValue)/2.0;
var outVal = 0.0;
if (z < minValue)
outVal = 0.0;
else if (z >= minValue && z < midpoint1)
outVal = 1.0;
else if (z >= midpoint1 && z < midrange)
outVal = 2.0;
else if (z >= midrange && z < midpoint2)
outVal = 3.0;
else if (z >= midpoint2 && z < maxValue)
outVal = 4.0;
else if (z >= maxValue)
outVal = 5.0;
return outVal;
}
function gepMap6C(a, b, c, d)
{
// evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
//
// evaluate minValue(a,b,c)
var minValue = a;
var argMin = 0;
if (minValue > b)
{
minValue = b;
argMin = 1;
}
if (minValue > c)
{
minValue = c;
argMin = 2;
}
// evaluate maxValue(a,b,c)
var maxValue = a;
var argMax = 0;
if (maxValue < b)
{
maxValue = b;
argMax = 1;
}
if (maxValue < c)
{
maxValue = c;
argMax = 2;
}
// evaluate midleValue(a,b,c)
var midleValue = c;
if (0 != argMin && 0 != argMax)
midleValue = a;
if (1 != argMin && 1 != argMax)
midleValue = b;
// evaluate midrange1 and midrange2
var midrange1 = (minValue + midleValue)/2.0;
var midrange2 = (midleValue + maxValue)/2.0;
var outVal = 0.0;
if (d < minValue)
outVal = 0.0;
else if (d >= minValue && d < midrange1)
outVal = 1.0;
else if (d >= midrange1 && d < midleValue)
outVal = 2.0;
else if (d >= midleValue && d < midrange2)
outVal = 3.0;
else if (d >= midrange2 && d < maxValue)
outVal = 4.0;
else if (d >= maxValue)
outVal = 5.0;
return outVal;
}
function gepECL3A(x, y, z)
{
if (y > x && z < x)
return 1.0;
else
if (y < x && z > x)
return -1.0;
else return 0.0;
}
function gepECL3B(x, y, z)
{
if (y > x && z > x)
return 1.0;
else
if (y < x && z < x)
return -1.0;
else return 0.0;
}
function gepECL3C(x, y, z)
{
if (y >= x && z >= x)
return 1.0;
else
if (y <= -x && z <= -x)
return -1.0;
else return 0.0;
}
function gepECL3D(a, b, c, d)
{
var minValue = Math.min(a,b);
var maxValue = Math.max(a,b);
if (c >= maxValue && d >= maxValue)
return 1.0;
else
if (c <= minValue && d <= minValue)
return -1.0;
else return 0.0;
}
function gepAMin2(x, y)
{
if (x < y)
return 0.0;
else
return 1.0;
}
function gepAMin3(x, y, z)
{
var temp = x;
var argMin = 0.0;
if (temp >= y)
{
temp = y;
argMin = 1.0;
}
if (temp >= z)
{
argMin = 2.0;
}
return argMin;
}
function gepAMin4(a, b, c, d)
{
var temp = a;
var argMin = 0.0;
if (temp >= b)
{
temp = b;
argMin = 1.0;
}
if (temp >= c)
{
temp = c;
argMin = 2.0;
}
if (temp >= d)
{
argMin = 3.0;
}
return argMin;
}
function gepAMax2(x, y)
{
if (x >= y)
return 0.0;
else
return 1.0;
}
function gepAMax3(x, y, z)
{
var temp = x;
var argMax = 0.0;
if (temp < y)
{
temp = y;
argMax = 1.0;
}
if (temp < z)
{
argMax = 2.0;
}
return argMax;
}
function gepAMax4(a, b, c, d)
{
var temp = a;
var argMax = 0.0;
if (temp < b)
{
temp = b;
argMax = 1.0;
}
if (temp < c)
{
temp = c;
argMax = 2.0;
}
if (temp < d)
{
argMax = 3.0;
}
return argMax;
}
Comments
There are currently no comments on this article.
Comment
your_ip_is_blacklisted_by sbl.spamhaus.org