Custom VB Fitness function
  • I do not find the
    VBCustomFitnessTest.gep  in the
  • In my  custom fitness function, I need  to read data line by line in the For  i=0 to nSamples-1 loop, from a text file made of nSamples lines.
    How to manage this file? For example,  can it be  opened  only once and then just checked for its availability ?
  • For Javascript custom functions it is not possible to maintain state between generations. If you use an external custom fitness function then you can read the file once and keep it on a global or static variable (an array of doubles, for example).
  • Let's suppose I use the Calculate function and transform it to implement my code:
     where should any  (static/global) variable be declared, as they are all reset every time the function is run?

  • 1. If you are using VB6 then add a module and declare a public variable.
    2. If you are using a .NET language then you can declare a static variable at the class scope.

    It is not possible to do this if you are using the javascript code inside GeneXproTools. You have to call your external implementation from the javascript.
  • When the custom function is running, is it possible to  retrieve the number of true positives or  count them as they come up?
  • The reason why I need the TPs number is that I want to select those TP that have the highest  value.
    these values are stored in an array  read in the custom function loop
  • I want to find maximum of True Positives the  associated value (stored in the aray) of which is the highest possible.
    Which data must be returned to gepsoft by the function?

  • The number of True Positives is in the parameter:

    aParameters[7] = number of positive cases

    To find all the available parameters open a Classification Sample Run and choose Edit Custom Fitness from the Settings Panel. This is the complete list:

    // All the values of the Target output
    // are accessible through the array:
    // aOutputTarget[0] = 0
    // aOutputTarget[1] = 1
    // aOutputTarget[2] = 0
    // etc.

    // All the values of the Model output
    // are accessible through the array:
    // aOutputModel[0] = 0
    // aOutputModel[1] = 1
    // aOutputModel[2] = 1
    // etc.

    // Essential and useful parameters you may use
    // to design your fitness function:
    // aParameters[0] = number of records
    // aParameters[1] = averaged target output
    // aParameters[2] = variance of the target output
    // aParameters[3] = 0/1 rounding threshold
    // aParameters[4] = number of records in the predominant class
    // aParameters[5] = minimum program size
    // aParameters[6] = maximum program size

    // aParameters[7] = number of positive cases
    // aParameters[8] = encoding of negative class
    // aParameters[9] = encoding of positive class

    // aParameters[10] = identifies the dataset: "1" for Training and "0" for Validation

    // aParameters[11] = Cost of True Positives
    // aParameters[12] = Cost of True Negatives
    // aParameters[13] = Cost of False Positives
    // aParameters[14] = Cost of False Negatives

    // aParameters[15] = Lower Bound
    // aParameters[16] = Upper Bound

    // aParameters[17] = Parsimony Pressure Rate
    // aParameters[18] = Variable Pressure Rate

    // Useful information about the evolving models
    // you may use to design your fitness function:
    // aModelInfo[0] = program size
    // aModelInfo[1] = used variables
    // aModelInfo[2] = number of literals

    // gepFilePath: local variable with the full path to the gep file

  • Thank you.
    The first time the custom function is run, the encoding of positive class has the value 0. It is only in the next runs that you can find it with the right value 1.Is it a bug? Currently I have to skip the first run otherwise my code may be wrong.
  • I cannot duplicate the issue. For example, if you return the encoding of the positive class as the fitness and run for one generation you will see that the value is correct. To do this change the custom fitness to:

    return aParameters[9];

    Then in the Settings Panel change the Number of Chromosomes to one and finally, in the Run Panel run for a single generation. Assuming that your encoding is one then the fitness value will show as one.
  • I have started to use GeneXproTools  again (release 5) and I met two problems while using the custom fitness fonction running with Excel VBA.
    - With the current release, the gepmodel function is now passed its parameters through a range, instead of an array, as previously done.I had to modify  that and also the starting index value (1 for the range but 0 for the array), in order to match my former code.

    -  In  the TransformCategoricalInputs function (in the gepmodel function) I had to add in a some places a Select statement
    like this, to avoid an incompatibilty type when an empty value is met in a CDbl conversion.

        Select Case inputData(4)
            Case ""
                outputData(4) = 0.0
            Case Else
                outputData(4) = CDbl(inputData(4))
        End Select

    Could this be generalized?

  • Hello,

    You can do it now by editing the vba grammar and adding that line to the Select case:

    1. Go to the GeneXproTools folder and open the grammars folder.
    2. Open the file vba.Math.00.default.grm.xml in notepad or other editor.
    3. Search for  TransformCategoricalInputs.
    4. Under it look for the switch node and the numericaldefault attribute.
    5. Replace its contents with:

    {TAB}{TAB}Case ""{CRLF}{TAB}{TAB}{TAB}outputData({index}) = 0.0{CRLF}{TAB}{TAB}Case Else{CRLF}{TAB}{TAB}{TAB}outputData({index}) = CDbl(inputData({index})){CRLF}

    You will need to have admin credentials to do this. If you don't, first move the file above to the desktop, make the changes and copy it back to GenXproTools folder.

    You will need to restart GeneXproTools to see the changes. Now, all VBA models will include this case and you no longer need to edit them by hand.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!