Support for the Go Language in GeneXproTools

Posted
Comments None

The Go Math Grammar that Glenn Lewis shared with the GeneXproTools community a while back (see the forum post "New experimental Go programming language grammar") has now been tested and extended with the new 39 math functions and new linking functions and will be added to the built-in math grammars of GeneXproTools with the next mini-release. This means that you'll be able to generate automatically Go code for all the models you create in GeneXproTools. As an example, here's the Go code for a nonlinear regression model generated for the Concrete Compressive Strength dataset:

//------------------------------------------------------------------------
// Regression model generated by GeneXproTools 5.0 on 1/29/2014 11:20:26 PM
// GEP File: C:\Program Files\GeneXproTools 50\SampleRuns\ConcreteStrength.gep
// Training Records:  687
// Validation Records:   343
// Fitness Function:  RMSE
// Training Fitness:  137.565058431653
// Training R-square: 0.852312063342217
// Validation Fitness:   137.37013713748
// Validation R-square:  0.870907944666967
//------------------------------------------------------------------------

package gepModel

import (
    "math"
)

func gepModel(d []float64) float64 {
    const G1C2 = 10.0317076770048
    const G2C5 = -2.76934946429679
    const G2C1 = 0.187640123844098
    const G3C9 = 119.482546094589
    const G4C0 = 14.5621350025957
    const G4C2 = -23.4923495987762
    const G4C9 = -19.2121721668995
    const G4C6 = 20.3393546847688
    const G5C5 = 17.2829378598944
    const G5C8 = 6.74868204486149
    const G5C3 = 5.92062389951742
    const G6C1 = -4.4417257533308
    const G6C6 = 11.4706172591873
    const G6C8 = -5.94326755831537
    const G6C4 = -1.78502761925108

    y := 0.0

    y = (gep3Rt(((d[1]*d[7])+(d[0]*d[7])))+(((d[1]/G1C2)+gep3Rt(d[6]))/2.0))
    y += gep3Rt(((math.Min((d[1]*d[2]),(d[0]-d[3]))/(d[1]-G2C1))*G2C5))
    y += ((((1.0-(d[1]+d[1]))+math.Pow(d[4],2.0))/2.0)/(((G3C9-d[5])+(d[0]+d[3]))/2.0))
    y += (G4C0*(((d[7]-d[4])/((d[2]+G4C9)/2.0))/(math.Min(G4C6,d[1])-G4C2)))
    y += ((gep3Rt(((G5C3*d[0])*(d[0]-d[4])))+(math.Min(G5C5,d[7])+math.Min(G5C8,d[4])))/2.0)
    y += (((math.Max(d[3],d[2])/G6C1)-(G6C6/d[7]))-((G6C8+G6C4)*(d[2]/d[3])))

    return y
}

func gep3Rt(x float64) float64 {
    if x < 0.0 {
        return -math.Pow(-x, (1.0 / 3.0))
    }
    return math.Pow(x, (1.0 / 3.0))
}

GeneXproTools allows you to create custom grammars for your favorite programming languages and we can use the Go programming language to show how that can be easily done using existing grammars as templates. For example, Glenn used the C++ Grammar as template for his Go Grammar, which is a great choice given that the calculator of GeneXproTools is also in C++. But the idea is to use the grammar template that results in less work and less bugs upon translation, which often involves choosing the programming language that we are most comfortable with.

In the next post I'll show how to generate the Go code for the new 39 math functions that were introduced with GeneXproTools 5.0 MR1. I'll also do a series of posts on how to create a custom math grammar using the Go programming language as an example, guiding you through the main components of a math grammar, from basic functions to helper functions and code structure.

Author

Comments

There are currently no comments on this article.

Comment

your_ip_is_blacklisted_by sbl.spamhaus.org

← Older Newer →