  # Function Design: 5-Output Mapper Functions

Posted

The series of 5-output mapper functions explores the same principles of the 4-output mappers, with the difference that we are now defining 5 intervals instead of just 4. And what's interesting is how well these functions scale up (97% hits for Map5A, 98% for Map5B, 99% for Map5C against 96% for the argmax), behaving very similarly to their counterparts of 4 outputs. Even with just 2 arguments we can create efficient 5-output mapper functions that show a performance comparable to the argmax function of 4 arguments (it would have been interesting to see how they compare to the argmin/argmax functions of 5 arguments, but it will have to wait for the powers that be at Gepsoft to increase max arity to 5 in GeneXproTools)!

And like we saw for the Map4A function described in the previous post, the value for the slack was also critical for the Map5A function, in this case with 15 as the best value (the reason for 15 is that I needed a value that divided neatly by 3; I also tried the values 1.5, 30, 150, and 1500).

As usual, I'm including the C++ code for all three 5-output mapper functions for you to take a look:

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

// Map5B(x0,x1,x2): 5-Output Mapper Function
// evaluate min(x,y), max(x,y), midpoint1 and midpoint2
double min = x;
double max = x;
if (min > x)
{
min = x;
max = x;
}
double intervalLength = (max - min)/3.0;
double midpoint1 = min + intervalLength;
double midpoint2 = min + 2.0*intervalLength;

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

// Map5C(x0,x1,x2,x3): 5-Output Mapper Function
// evaluate min(x,y,z), max(x,y,z), midleValue(x,y,z), midrange1, midrange2
//
// 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;
// evaluate midrange1 and midrange2
double midrange1 = (min + midleValue)/2.0;
double midrange2 = (midleValue + max)/2.0;

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

In the next post we'll go a step further and describe the 6-output mapper functions of 2, 3, and 4 arguments.

Author