# Function Design: Argmin & Argmax

Posted

Just to recap, we are still trying to design 3-6 output classifier functions that work well both at the root level of a single tree and, if possible, as linking functions of 2 arguments, so that they can be used to create sophisticated trading rules as outlined in the post "New Project: Multi-class Classification & Trading Strategies".

The argmin and argmax functions of 3 and 4 arguments are a little detour in this pursuit because we cannot implement functions of 5 and 6 arguments in GeneXproTools (4 is the max limit). Moreover, the argmin and argmax functions of 2 arguments (which, by the way, are already available in GeneXproTools as GT2B and LT2B) are not very interesting as linking functions. Notwithstanding, we are implementing the argmin function of 2 arguments as a new linking function in GeneXproTools; for the argmax I was unable to find a neutral gene and therefore had to leave it out.

Now back to the argmin and argmax functions of 3 and 4 arguments. These functions are just amazing! They are much better than all the other functions of 3-4 discrete outputs that I managed to come up with (see my previous post "Function Design: 4-6 Output Classifier Functions")! And I was so disheartened the first time I came to this realization. What was so special about these argmin and argmax functions? Can I ever dream of designing 4-6 output classifier functions that could match their performance? (I must confess that at the time I wasn't having any grandiose dreams: I was just heartbroken.)

But anyway, here's the C++ code for the amazing, yet so simple, argmin and argmax functions of 4 arguments:

Argmin function:

double temp = arg[0];
double argMin = 0.0;
if (temp >= arg[1])
{
temp = arg[1];
argMin = 1.0;
}
if (temp >= arg[2])
{
temp = arg[2];
argMin = 2.0;
}
if (temp >= arg[3])
{
argMin = 3.0;
}
return argMin;

Argmax function:

double temp = arg[0];
double argMax = 0.0;
if (temp < arg[1])
{
temp = arg[1];
argMax = 1.0;
}
if (temp < arg[2])
{
temp = arg[2];
argMax = 2.0;
}
if (temp < arg[3])
{
argMax = 3.0;
}
return argMax;

The way I'm measuring and comparing their performance is totally pragmatic and has nothing mathematical to it as I'm just interested in creating good all-purpose functions that work well in the GeneXproTools modeling environment. So, as usual, I'm testing them on the Iris dataset and evaluating the average number of hits for a total of 20 best-of-run models. More specifically, I'm using the default math functions of GeneXproTools for Regression plus the function under study weighted 20 times. Then I create 20 runs of 1000 generations each, keeping just the last model of each run.

Curiously enough, the argmax function seems to perform slightly worse than the argmin, so I'll be using the argmax function of 4 arguments as my benchmark: If I ever manage to design a 4-6 output function that performs as well as the argmax function of 4 arguments, I'll have reason to celebrate!

I didn't know at the time, but I just couldn't let this go. There must be some other functions out there that could do a similar job! I still remember the first time I heard about the argmin and argmax functions: "Is that even a function?" "What are they good for?" "Who would go to the trouble of creating such functions and giving them such nice names?" Well, I didn't rest for two days and in the third I had my little eureka moment and came up with a solution. But I'll tell that story in the next post.

Author