Posted
Comments None

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?":

function gepRamp1(x)
{
    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;
}

Author

Posted
Comments None

As far as the 39 new math functions added to the built-in math functions of GeneXproTools, the Java code is almost an exact clone of the C# code, except that the word "const" was replaced by "final" and "Min" and "Max" were replaced by "min" and "max" and implemented the Java way as these functions can take two or more arguments in Java.

Again, as for all programming languages with native min and max functions (thus far, only C# and VB.Net), we are leaving the chunks of code for evaluating min and max values in the places where argmin and argmax values are calculated, as this simplifies testing and debugging.

And here's the Java code for all the 39 new math functions added to the Java Grammar of GeneXproTools with v5.0 MR1:

    double gepRamp1(double x)
    {
        if (x > 0.0)
            return x;
        else
            return 0.0;
    }

    double gepRamp2(double x)
    {
        if (x > 0.0)
            return 0.0;
        else
            return x;
    }

    double gepRamp3(double x)
    {
        if (x > 0.0)
            return 0.0;
        else
            return -x;
    }

    double gepRamp4(double x)
    {
        if (x > 0.0)
            return -x;
        else
            return 0.0;
    }

    double gepStep1(double x)
    {
        if (x > 0.0)
            return 1.0;
        else
            return -1.0;
    }

    double gepStep2(double x)
    {
        if (x > 0.0)
            return 1.0;
        else
            return 0.0;
    }

    double gepStep3(double x)
    {
        if (x >= 1.0)
            return 1.0;
        else
            if (x <= -1.0)
                return -1.0;
            else
                return x;
    }

    double gepStep4(double x)
    {
        if (x >= 1.0)
            return 1.0;
        else
            if (x <= 0.0)
                return 0.0;
            else
                return x;
    }

    double gepCL2A(double x, double y)
    {
        if (x > 0.0 && y > 0.0)
            return 1.0;
        else
            return -1.0;
    }

    double gepCL2B(double x, double y)
    {
        if (x >= 0.0 && y < 0.0)
            return -1.0;
        else
            return 1.0;
    }

    double gepCL2C(double x, double y)
    {
        if (x > 1.0 && y < -1.0)
            return -1.0;
        else
            return 1.0;
    }

    double gepCL2D(double x, double y)
    {
        if (x > 0.0 && y > 0.0)
            return 1.0;
        else
            return 0.0;
    }

    double gepCL2E(double x, double y)
    {
        if (x >= 0.0 && y <= 0.0)
            return 0.0;
        else
            return 1.0;
    }

    double gepCL2F(double x, double y)
    {
        if (x > 1.0 && y < -1.0)
            return 0.0;
        else
            return 1.0;
    }

    double gepCL3A(double x, double 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;
    }

    double gepCL3B(double x, double 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;
    }

    double gepCL3C(double x, double 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;
    }

    double gepMap3A(double x, double y)
    {
        final double SLACK = 10.0;
        double outVal = 0.0;
        if (y < (x - SLACK))
            outVal = -1.0;
        else if (y > (x + SLACK))
            outVal = 1.0;
        return outVal;
    }

    double gepMap3B(double x, double y, double z)
    {
        double minValue = Math.min(x,y);
        double maxValue = Math.max(x,y);
        double outVal = 0.0;
        if (z < minValue)
            outVal = -1.0;
        else if (z > maxValue)
            outVal = 1.0;
        return outVal;
    }

    double gepMap3C(double a, double b, double c, double d)
    {
        double minValue = Math.min(a,b,c);
        double maxValue = Math.max(a,b,c);
        double outVal = 0.0;
        if (d < minValue)
            outVal = -1.0;
        else if (d > maxValue)
            outVal = 1.0;
        return outVal;
    }

    double gepMap4A(double x, double y)
    {
        final double SLACK = 10.0;
        double 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;
    }

    double gepMap4B(double x, double y, double z)
    {
        double minValue = Math.min(x,y);
        double maxValue = Math.max(x,y);
        double midrange = (maxValue + minValue)/2.0;
        
        double 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;
    }

    double gepMap4C(double a, double b, double c, double d)
    {
        // evaluate minValue(a,b,c), maxValue(a,b,c) and midleValue(a,b,c)
        //
        // evaluate minValue(a,b,c)
        double minValue = a;
        int argMin = 0;
        if (minValue > b)
        {
            minValue = b;
            argMin = 1;
        }
        if (minValue > c)
        {
            minValue = c;
            argMin = 2;
        }
        // evaluate maxValue(a,b,c)
        double maxValue = a;
        int argMax = 0;
        if (maxValue < b)
        {
            maxValue = b;
            argMax = 1;
        }
        if (maxValue < c)
        {
            maxValue = c;
            argMax = 2;
        }
        // evaluate midleValue(a,b,c)
        double midleValue = c;
        if (0 != argMin && 0 != argMax)
            midleValue = a;
        if (1 != argMin && 1 != argMax)
            midleValue = b;

        double 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;
    }

    double gepMap5A(double x, double y)
    {
        final double SLACK = 15.0;
        double 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;
    }

    double gepMap5B(double x, double y, double z)
    {
        double minValue = Math.min(x,y);
        double maxValue = Math.max(x,y);
        double intervalLength = (maxValue - minValue)/3.0;
        double midpoint1 = minValue + intervalLength;
        double midpoint2 = minValue + 2.0*intervalLength;
        
        double 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;
    }

    double gepMap5C(double a, double b, double c, double d)
    {
        // evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
        //
        // evaluate minValue(a,b,c)
        double minValue = a;
        int argMin = 0;
        if (minValue > b)
        {
            minValue = b;
            argMin = 1;
        }
        if (minValue > c)
        {
            minValue = c;
            argMin = 2;
        }
        // evaluate maxValue(a,b,c)
        double maxValue = a;
        int argMax = 0;
        if (maxValue < b)
        {
            maxValue = b;
            argMax = 1;
        }
        if (maxValue < c)
        {
            maxValue = c;
            argMax = 2;
        }
        // evaluate midleValue(a,b,c)
        double midleValue = c;
        if (0 != argMin && 0 != argMax)
            midleValue = a;
        if (1 != argMin && 1 != argMax)
            midleValue = b;
        // evaluate midrange1 and midrange2
        double midrange1 = (minValue + midleValue)/2.0;
        double midrange2 = (midleValue + maxValue)/2.0;

        double 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;
    }

    double gepMap6A(double x, double y)
    {
        final double SLACK = 10.0;
        double 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;
    }

    double gepMap6B(double x, double y, double z)
    {
        double minValue = Math.min(x,y);
        double maxValue = Math.max(x,y);
        double midrange = (minValue + maxValue)/2.0;
        double midpoint1 = (minValue + midrange)/2.0;
        double midpoint2 = (midrange + maxValue)/2.0;
        
        double 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;
    }

    double gepMap6C(double a, double b, double c, double d)
    {
        // evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
        //
        // evaluate minValue(a,b,c)
        double minValue = a;
        int argMin = 0;
        if (minValue > b)
        {
            minValue = b;
            argMin = 1;
        }
        if (minValue > c)
        {
            minValue = c;
            argMin = 2;
        }
        // evaluate maxValue(a,b,c)
        double maxValue = a;
        int argMax = 0;
        if (maxValue < b)
        {
            maxValue = b;
            argMax = 1;
        }
        if (maxValue < c)
        {
            maxValue = c;
            argMax = 2;
        }
        // evaluate midleValue(a,b,c)
        double midleValue = c;
        if (0 != argMin && 0 != argMax)
            midleValue = a;
        if (1 != argMin && 1 != argMax)
            midleValue = b;
        // evaluate midrange1 and midrange2
        double midrange1 = (minValue + midleValue)/2.0;
        double midrange2 = (midleValue + maxValue)/2.0;

        double 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;
    }

    double gepECL3A(double x, double y, double z)
    {
        if (y > x && z < x)
            return 1.0;
        else
            if (y < x && z > x)
                return -1.0;
            else return 0.0;
    }

    double gepECL3B(double x, double y, double z)
    {
        if (y > x && z > x)
            return 1.0;
        else
            if (y < x && z < x)
                return -1.0;
            else return 0.0;
    }

    double gepECL3C(double x, double y, double z)
    {
        if (y >= x && z >= x)
            return 1.0;
        else
            if (y <= -x && z <= -x)
                return -1.0;
            else return 0.0;
    }

    double gepECL3D(double a, double b, double c, double d)
    {
        double minValue = Math.min(a,b);
        double 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;
    }

    double gepAMin2(double x, double y)
    {
        if (x < y)
            return 0.0;
        else
            return 1.0;
    }

    double gepAMin3(double x, double y, double z)
    {
        double temp = x;
        double argMin = 0.0;    
        if (temp >= y)
        {
            temp = y;
            argMin = 1.0;
        }
        if (temp >= z)
        {
            argMin = 2.0;
        }
        return argMin;
    }

    double gepAMin4(double a, double b, double c, double d)
    {
        double temp = a;
        double 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;
    }

    double gepAMax2(double x, double y)
    {
        if (x >= y)
            return 0.0;
        else
            return 1.0;
    }

    double gepAMax3(double x, double y, double z)
    {
        double temp = x;
        double argMax = 0.0;    
        if (temp < y)
        {
            temp = y;
            argMax = 1.0;
        }
        if (temp < z)
        {
            argMax = 2.0;
        }
        return argMax;
    }

    double gepAMax4(double a, double b, double c, double d)
    {
        double temp = a;
        double 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;
    }

Author

Posted
Comments None

The VB.Net code for the new math functions that were added to the built-in math functions of GeneXproTools with Mini-Release 1 is very similar to both the Visual Basic code and Excel VBA code, except that in VB.Net there is a "Return" statement (like in C# or C++), you can declare and initialize variables at the same time, and you also have access to native Min and Max functions. And like we did with the C# code, we are also keeping the code for evaluating min and max values in the places where argmin and argmax values are evaluated for the sake of uniformity across all programming languages that GeneXproTools supports.

Here's the VB.Net code for all the new math functions that are now part of the VB.Net Grammar of GeneXproTools:

    Function gepRamp1(ByVal x As Double) As Double
        If x > 0.0 Then
            Return x
        Else
            Return 0.0
        End If
    End Function

    Function gepRamp2(ByVal x As Double) As Double
        If x > 0.0 Then
            Return 0.0
        Else
            Return x
        End If
    End Function

    Function gepRamp3(ByVal x As Double) As Double
        If x > 0.0 Then
            Return 0.0
        Else
            Return -x
        End If
    End Function

    Function gepRamp4(ByVal x As Double) As Double
        If x > 0.0 Then
            Return -x
        Else
            Return 0.0
        End If
    End Function

    Function gepStep1(ByVal x As Double) As Double
        If x > 0.0 Then
            Return 1.0
        Else
            Return -1.0
        End If
    End Function

    Function gepStep2(ByVal x As Double) As Double
        If x > 0.0 Then
            Return 1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepStep3(ByVal x As Double) As Double
        If x >= 1.0 Then
            Return 1.0
        ElseIf x <= -1.0 Then
            Return -1.0
        Else
            Return x
        End If
    End Function

    Function gepStep4(ByVal x As Double) As Double
        If x >= 1.0 Then
            Return 1.0
        ElseIf x <= 0.0 Then
            Return 0.0
        Else
            Return x
        End If
    End Function

    Function gepCL2A(ByVal x As Double, ByVal y As Double) As Double
        If x > 0.0 And y > 0.0 Then
            Return 1.0
        Else
            Return -1.0
        End If
    End Function

    Function gepCL2B(ByVal x As Double, ByVal y As Double) As Double
        If x >= 0.0 And y < 0.0 Then
            Return -1.0
        Else
            Return 1.0
        End If
    End Function

    Function gepCL2C(ByVal x As Double, ByVal y As Double) As Double
        If x > 1.0 And y < -1.0 Then
            Return -1.0
        Else
            Return 1.0
        End If
    End Function

    Function gepCL2D(ByVal x As Double, ByVal y As Double) As Double
        If x > 0.0 And y > 0.0 Then
            Return 1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepCL2E(ByVal x As Double, ByVal y As Double) As Double
        If x >= 0.0 And y <= 0.0 Then
            Return 0.0
        Else
            Return 1.0
        End If
    End Function

    Function gepCL2F(ByVal x As Double, ByVal y As Double) As Double
        If x > 1.0 And y < -1.0 Then
            Return 0.0
        Else
            Return 1.0
        End If
    End Function

    Function gepCL3A(ByVal x As Double, ByVal y As Double) As Double
        If x > 0.0 And y < 0.0 Then
            Return 1.0
        ElseIf x < 0.0 And y > 0.0 Then
            Return -1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepCL3B(ByVal x As Double, ByVal y As Double) As Double
        If x >= 1.0 And y >= 1.0 Then
            Return 1.0
        ElseIf x <= -1.0 And y <= -1.0 Then
            Return -1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepCL3C(ByVal x As Double, ByVal y As Double) As Double
        If x > 0.0 And y > 0.0 Then
            Return 1.0
        ElseIf x < 0.0 And y < 0.0 Then
            Return -1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepMap3A(ByVal x As Double, ByVal y As Double) As Double
        Const SLACK As Double = 10.0
        If y < (x - SLACK) Then
            Return -1.0
        ElseIf y > (x + SLACK) Then
            Return 1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepMap3B(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        Dim minValue As Double = Min(x,y)
        Dim maxValue As Double = Max(x,y)
        If z < minValue Then
            Return -1.0
        ElseIf z > maxValue Then
            Return 1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepMap3C(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double
        Dim minValue As Double = Min(Min(a,b),c)
        Dim maxValue As Double = Max(Max(a,b),c)
        If d < minValue Then
            Return -1.0
        ElseIf d > maxValue Then
            Return 1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepMap4A(ByVal x As Double, ByVal y As Double) As Double
        Const SLACK As Double = 10.0
        If y < (x - SLACK) Then
            Return 0.0
        ElseIf y >= (x - SLACK) And y < x Then
            Return 1.0
        ElseIf y >= x And y < (x + SLACK) Then
            Return 2.0
        ElseIf y >= (x + SLACK) Then
            Return 3.0
        End If
    End Function

    Function gepMap4B(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        ' evaluate minValue(x,y), maxValue(x,y) and midrange
        Dim minValue As Double = Min(x,y)
        Dim maxValue As Double = Max(x,y)
        Dim midrange As Double = (maxValue + minValue)/2.0
        
        If z < minValue Then
            Return 0.0
        ElseIf z >= minValue And z < midrange Then
            Return 1.0
        ElseIf z >= midrange And z < maxValue Then
            Return 2.0
        ElseIf z >= maxValue Then
            Return 3.0
        End If
    End Function

    Function gepMap4C(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double
        ' evaluate minValue(a,b,c), maxValue(a,b,c) and midleValue(a,b,c)
        '
        ' evaluate minValue(a,b,c) and argMin(a,b,c)
        Dim minValue As Double = a
        Dim argMin As Integer = 0
        If minValue > b Then
            minValue = b
            argMin = 1
        End If
        If minValue > c Then
            minValue = c
            argMin = 2
        End If
        ' evaluate maxValue(a,b,c) and argMax(a,b,c)
        Dim maxValue As Double = a
        Dim argMax As Integer = 0
        If maxValue < b Then
            maxValue = b
            argMax = 1
        End If
        If maxValue < c Then
            maxValue = c
            argMax = 2
        End If
        ' evaluate midleValue(a,b,c)
        Dim midleValue As Double = c
        If 0 <> argMin And 0 <> argMax Then
            midleValue = a
        End If
        If 1 <> argMin And 1 <> argMax Then
            midleValue = b
        End If

        If d < minValue Then
            Return 0.0
        ElseIf d >= minValue And d < midleValue Then
            Return 1.0
        ElseIf d >= midleValue And d < maxValue Then
            Return 2.0
        ElseIf d >= maxValue Then
            Return 3.0
        End If
    End Function

    Function gepMap5A(ByVal x As Double, ByVal y As Double) As Double
        Const SLACK As Double = 15.0
        If y < (x - SLACK) Then
            Return 0.0
        ElseIf y >= (x - SLACK) And y < (x - SLACK/3.0) Then
            Return 1.0
        ElseIf y >= (x - SLACK/3.0) And y < (x + SLACK/3.0) Then
            Return 2.0
        ElseIf y >= (x + SLACK/3.0) And y < (x + SLACK) Then
            Return 3.0
        ElseIf y >= (x + SLACK) Then
            Return 4.0
        End If
    End Function

    Function gepMap5B(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        ' evaluate minValue(x,y), maxValue(x,y), midpoint1, midpoint2
        Dim minValue As Double = Min(x,y)
        Dim maxValue As Double = Max(x,y)
        Dim intervalLength As Double = (maxValue - minValue)/3.0
        Dim midpoint1 As Double = minValue + intervalLength
        Dim midpoint2 As Double = minValue + 2.0*intervalLength
        
        If z < minValue Then
            Return 0.0
        ElseIf z >= minValue And z < midpoint1 Then
            Return 1.0
        ElseIf z >= midpoint1 And z < midpoint2 Then
            Return 2.0
        ElseIf z >= midpoint2 And z < maxValue Then
            Return 3.0
        ElseIf z >= maxValue Then
            Return 4.0
        End If
    End Function

    Function gepMap5C(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double
        ' evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
        '
        ' evaluate minValue(a,b,c) and argMin(a,b,c)
        Dim minValue As Double = a
        Dim argMin As Integer = 0
        If minValue > b Then
            minValue = b
            argMin = 1
        End If
        If minValue > c Then
            minValue = c
            argMin = 2
        End If
        ' evaluate maxValue(a,b,c) and argMax(a,b,c)
        Dim maxValue As Double = a
        Dim argMax As Integer = 0
        If maxValue < b Then
            maxValue = b
            argMax = 1
        End If
        If maxValue < c Then
            maxValue = c
            argMax = 2
        End If
        ' evaluate midleValue(a,b,c)
        Dim midleValue As Double = c
        If 0 <> argMin And 0 <> argMax Then midleValue = a
        If 1 <> argMin And 1 <> argMax Then midleValue = b
        Dim midrange1 As Double = (minValue + midleValue)/2.0
        Dim midrange2 As Double = (midleValue + maxValue)/2.0

        If d < minValue Then
            Return 0.0
        ElseIf d >= minValue And d < midrange1 Then
            Return 1.0
        ElseIf d >= midrange1 And d < midrange2 Then
            Return 2.0
        ElseIf d >= midrange2 And d < maxValue Then
            Return 3.0
        ElseIf d >= maxValue Then
            Return 4.0
        End If
    End Function

    Function gepMap6A(ByVal x As Double, ByVal y As Double) As Double
        Const SLACK As Double = 10.0
        If y < (x - SLACK) Then
            Return 0.0
        ElseIf y >= (x - SLACK) And y < (x - SLACK/2.0) Then
            Return 1.0
        ElseIf y >= (x - SLACK/2.0) And y < x Then
            Return 2.0
        ElseIf y >= x And y < (x + SLACK/2.0) Then
            Return 3.0
        ElseIf y >= (x + SLACK/2.0) And y < (x + SLACK) Then
            Return 4.0
        ElseIf y >= (x + SLACK) Then
            Return 5.0
        End If
    End Function

    Function gepMap6B(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        Dim minValue As Double = Min(x,y)
        Dim maxValue As Double = Max(x,y)
        Dim midrange As Double = (minValue + maxValue)/2.0
        Dim midpoint1 As Double = (minValue + midrange)/2.0
        Dim midpoint2 As Double = (midrange + maxValue)/2.0
        
        If z < minValue Then
            Return 0.0
        ElseIf z >= minValue And z < midpoint1 Then
            Return 1.0
        ElseIf z >= midpoint1 And z < midrange Then
            Return 2.0
        ElseIf z >= midrange And z < midpoint2 Then
            Return 3.0
        ElseIf z >= midpoint2 And z < maxValue Then
            Return 4.0
        ElseIf z >= maxValue Then
            Return 5.0
        End If
    End Function

    Function gepMap6C(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double
        ' evaluate minValue(a,b,c), maxValue(a,b,c), midleValue(a,b,c), midrange1, midrange2
        '
        ' evaluate minValue(a,b,c) and argMin(a,b,c)
        Dim minValue As Double = a
        Dim argMin As Integer = 0
        If minValue > b Then
            minValue = b
            argMin = 1
        End If
        If minValue > c Then
            minValue = c
            argMin = 2
        End If
        ' evaluate maxValue(a,b,c) and argMax(a,b,c)
        Dim maxValue As Double = a
        Dim argMax As Integer = 0
        If maxValue < b Then
            maxValue = b
            argMax = 1
        End If
        If maxValue < c Then
            maxValue = c
            argMax = 2
        End If
        ' evaluate midleValue(a,b,c)
        Dim midleValue As Double = c
        If 0 <> argMin And 0 <> argMax Then midleValue = a
        If 1 <> argMin And 1 <> argMax Then midleValue = b
        ' evaluate midrange1 and midrange2
        Dim midrange1 As Double = (minValue + midleValue)/2.0
        Dim midrange2 As Double = (midleValue + maxValue)/2.0

        If d < minValue Then
            Return 0.0
        ElseIf d >= minValue And d < midrange1 Then
            Return 1.0
        ElseIf d >= midrange1 And d < midleValue Then
            Return 2.0
        ElseIf d >= midleValue And d < midrange2 Then
            Return 3.0
        ElseIf d >= midrange2 And d < maxValue Then
            Return 4.0
        ElseIf d >= maxValue Then
            Return 5.0
        End If
    End Function

    Function gepECL3A(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        If y > x And z < x Then
            Return 1.0
        ElseIf y < x And z > x Then
            Return -1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepECL3B(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        If y > x And z > x Then
            Return 1.0
        ElseIf y < x And z < x Then
            Return -1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepECL3C(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        If y >= x And z >= x Then
            Return 1.0
        ElseIf y <= -x And z <= -x Then
            Return -1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepECL3D(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double
        Dim minValue As Double = Min(a,b)
        Dim maxValue As Double = Max(a,b)
        If c >= maxValue And d >= maxValue Then
            Return 1.0
        ElseIf c <= minValue And d <= minValue Then
            Return -1.0
        Else
            Return 0.0
        End If
    End Function

    Function gepAMin2(ByVal x As Double, ByVal y As Double) As Double
        If x < y Then
            Return 0.0
        Else
            Return 1.0
        End If
    End Function

    Function gepAMin3(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        Dim temp As Double = x
        Dim argMin As Double = 0.0
        If temp >= y Then
            temp = y
            argMin = 1.0
        End If
        If temp >= z Then argMin = 2.0
        Return argMin
    End Function

    Function gepAMin4(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double
        Dim temp As Double = a
        Dim argMin As Double = 0.0
        If temp >= b Then
            temp = b
            argMin = 1.0
        End If
        If temp >= c Then
            temp = c
            argMin = 2.0
        End If
        If temp >= d Then argMin = 3.0
        Return argMin
    End Function

    Function gepAMax2(ByVal x As Double, ByVal y As Double) As Double
        If x >= y Then
            Return 0.0
        Else
            Return 1.0
        End If
    End Function

    Function gepAMax3(ByVal x As Double, ByVal y As Double, ByVal z As Double) As Double
        Dim temp As Double = x
        Dim argMax As Double = 0.0
        If temp < y Then
            temp = y
            argMax = 1.0
        End If
        If temp < z Then argMax = 2.0
        Return argMax
    End Function

    Function gepAMax4(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double) As Double
        Dim temp As Double = a
        Dim argMax As Double = 0.0
        If temp < b Then
            temp = b
            argMax = 1.0
        End If
        If temp < c Then
            temp = c
            argMax = 2.0
        End If
        If temp < d Then argMax = 3.0
        Return argMax
    End Function

Author

Posted
Comments None

The new project announced a month ago "New Project: Multi-class Classification & Trading Strategies" has come to an end. It has been an exciting journey for us here at Gepsoft and we are delighted to release it into the world.

The new version of GeneXproTools with all the new features went live yesterday and it includes:

Enjoy!

Author

Posted
Comments None

Conservative Fixed-Root Mutation is the second genetic operator that we implemented in GeneXproTools for this new project "New Project: Multi-class Classification & Trading Strategies". Like the Fixed-Root Mutation operator, it also gives us more control over the root position of our models by preserving the elements at the root of each sub-tree. Moreover, by virtue of being "conservative", it means that all the other elements in the chromosome are mutated conservatively, that is, functions are replaced only by other functions with the same number of arguments and terminals are replaced only by other terminals (either functions or constants), which means that the shape of the tree is preserved from generation to generation.

So this means that the Conservative Fixed-Root Mutation operator can be used in the same scenarios described for Fixed-Root Mutation, with extra conservatism thrown in (that is, fixing a critical function like the buy-sell-wait function at the root in a unigenic system or fixing the root position in all the sub-trees of an intermediate solution). This might be useful at the later stages of the modeling process when we are mainly interested in fine-tuning the model structure.

Author

← Older Newer →