  # Function Design: 4-Output Mapper Functions

Posted

Let's start our exploration of the new mapper functions with the 4-output mapper functions of 2, 3, and 4 arguments. In GeneXproTools these functions are represented by Map4A, Map4B, and Map4C, where the big letter at the end represents the number of arguments (A corresponds to 2, B to 3, and C to 4).

The Map4B and Map4C functions were the very first that I designed and tested (remember, I was trying to create functions with 3-4 discrete outputs that matched the argmin/argmax functions in performance), and both of them perform better than the argmax function of 4 arguments (98% hits for B, 99% for C, and 96% for the argmax).

I've already talked about the Map4B function in the post "Function Design: New 3-6 Output Functions" and as you can see from the code below, the Map4C function explores a similar design structure, with the difference that the middle point is in this case also determined independently by one of the arguments of the function.

The Map4A function is a late comer and is slightly inferior to the Map4B and C, but nonetheless performs slightly better than the argmax function of 4 arguments, even though it's only a function of 2 arguments (97% hits vs 96% for the argmax)!

Like I said, the Map4A function (and all mapper functions of the A series; I'll describe them in subsequent posts) was one of the latest mapper functions that I created. As they use only one argument for the map, I had to define a slack to generate the necessary number of intervals (here, for the Map4A function, we need to define 4 intervals for the four different outputs). And my first choice for the slack was 1000 but unfortunately it didn't work very well. I was very disappointed because I so wanted to create mapper functions of 2 arguments (functions of 2 arguments enjoy a special status in GeneXproTools because they require less bulky tree structures)! Just out of desperation I decided to try other values for the slack: 100, 10, and 1. And surprise: It made a huge difference, with 10 the best value for the Map4A function (a slack of 1 was the second best). (Who said all intervals are equal?)

For completeness I'm including here the C++ code for all the mappers of this series, including the Map4B function introduced in the post "Function Design: New 3-6 Output Functions":

// Map4A(x0,x1): 4-Output Mapper Function
const double SLACK = 10.0;
double output = 0.0;
if (x < (x - SLACK))
output = 0.0;
else if (x >= (x - SLACK) && x < x)
output = 1.0;
else if (x >= x && x < (x + SLACK))
output = 2.0;
else if (x >= (x + SLACK))
output = 3.0;
return output;

// Map4B(x0,x1,x2): 4-Output Mapper Function
// evaluate min(x0,x1), max(x0,x1) and midrange
double min = x;
double max = x;
if (min > x)
{
min = x;
max = x;
}
double midrange = (max + min)/2.0;
double output = 0.0;
if (x < min)
output = 0.0;
else if (x >= min && x < midrange)
output = 1.0;
else if (x >= midrange && x < max)
output = 2.0;
else if (x >= max)
output = 3.0;
return output;

// Map4C(x0,x1,x2,x3): 4-Output Mapper Function
// evaluate min(x,y,z), max(x,y,z) and midleValue(x,y,z)
//
// evaluate min(x,y,z)
double min = x;
int argmin = 0;
if (min > x)
{
min = x;
argmin = 1;
}
if (min > x)
{
min = x;
argmin = 2;
}
// evaluate max(x,y,z)
double max = x;
int argmax = 0;
if (max < x)
{
max = x;
argmax = 1;
}
if (max < x)
{
max = x;
argmax = 2;
}
// evaluate midleValue(x,y,z)
double midleValue = x;
if (0 != argmin && 0 != argmax)
midleValue = x;
if (1 != argmin && 1 != argmax)
midleValue = x;

double output = 0.0;
if (x < min)
output = 0.0;
else if (x >= min && x < midleValue)
output = 1.0;
else if (x >= midleValue && x < max)
output = 2.0;
else if (x >= max)
output = 3.0;
return output;

In the next post I'll describe the 5-output mapper functions of 2, 3, and 4 arguments.

Author