Function Design: Programming Languages

Comments None

The endogenous calculator of GeneXproTools is in C++ and therefore makes sense to show the code for all these new classifier functions in C++. But GeneXproTools translates automatically the code of all the models it generates into 17 math programming languages (Ada, C, C++, C#, Excel VBA, Fortran, Java, JavaScript, Matlab, Octave, Pascal, Perl, PHP, Python, R, Visual Basic, and VB.Net) through the use of built-in grammars (you can in fact translate the model code into virtually any programming language using the Custom Grammars functionality of GeneXproTools).

So, over the next posts I'll show you the code for all these new functions in all the built-in programming languages of GeneXproTools. I'll be using GeneXproTools itself to generate the code automatically using a neat trick to write the code of all the new functions at the same time (more about this trick in a moment, which, by the way, comes in handy to anyone designing their own custom grammars.)

Overall, we've ended up with 39 new math functions! These functions include not only the new classifier functions we've been talking about, but also new Step and Ramp functions of one argument that complement nicely this new set of discrete functions.

The neat trick consists of creating a Karva program by hand (through the Change Seed Window) that includes all the new 39 functions. As an illustration I'm including here a much simpler program with just 3 functions, namely the 3-output classifier functions described in the posts "Function Design: The BUY-SELL-WAIT Function" and "Function Design: More 3-Output Classifier Functions":

from math import *

def gepModel(d):

    y = 0.0

    y = gepCL3A(d[2],d[3])
    y = y + gepCL3B(d[3],d[0])
    y = y + gepCL3C(d[3],d[0])

    return y

def gepCL3A(x, y):
    if ((x > 0.0) and (y < 0.0)):
        return 1.0
    elif ((x < 0.0) and (y > 0.0)):
        return -1.0
        return 0.0

def gepCL3B(x, y):
    if ((x >= 1.0) and (y >= 1.0)):
        return 1.0
    elif ((x <= -1.0) and (y <= -1.0)):
        return -1.0
        return 0.0

def gepCL3C(x, y):
    if ((x > 0.0) and (y > 0.0)):
        return 1.0
    elif ((x < 0.0) and (y < 0.0)):
        return -1.0
        return 0.0

As you can see in this simple Python code, I'm using a different gene to encode a different function. So, here in this simple example, I'm using 3 genes to encode 3 different functions. To show all the 39 new functions I'll have to use a total of 39 such simple genes with a head size of 1. And I can use the same Karva program again and again to generate the code for all these new functions in all the programming languages of GeneXproTools (I had of course to program them first, but now it's easy; this is also useful to check for bugs when you’re creating a Custom Grammar).



There are currently no comments on this article.


Enter your comment below. Fields marked * are required. You must preview your comment first before finally posting.

← Older Newer →