For example, I have a three variables: "x", "y" and "z". They are all from certain range {min, max}. Now, I want to compute a new variable, let's say p = x + F*(y-z), where F is some constant between 0 and 1. This new computed variable "p" needs to be mapped into above {min, max} range. How do I do that?
EDIT 1
Generating numbers into array:
population[D*id]=0;
population[D*id+N]=0;
population[D*id +2*N]=0;
population[D*id+1]=rndFloat(globalState,threadIdx.x,4);
population[D*id+N+1]=0;
population[D*id +2*N+1]=0;
for(int i=2; i<N; i++){
float min= -4 - 1/4*abs((int)((i-4)/3));
float max= 4 + 1/4*abs((int)((i-4)/3));
if(i==2)
{
population[D*id+2]=rndFloat(globalState,threadIdx.x,3.14159265359);
population[D*id+N+2]=rndFloat(globalState,threadIdx.x,min,max);
population[D*id +2*N+2]=0;
}
else
{
population[D*id +i]=rndFloat(globalState,threadIdx.x,min,max);
population[D*id+N+i]=rndFloat(globalState,threadIdx.x,min,max);
population[D*id +2*N+i]=rndFloat(globalState,threadIdx.x,min,max);
}
}
Computing a new variable:
for(int i=0; i<D-1; i++)
{
pop[D*id+i]= population[D*a +i] + F*(population[D*b +i]-population[D*c +i]);
}
Indices a, b and c are picked randomly. The important thing to notice is min and max range and its dependance by given indices:
float min= -4 - 1/4*abs((int)((i-4)/3));
float max= 4 + 1/4*abs((int)((i-4)/3));
where i is replaced by an a, b and c for each range.
EDIT 2
to simplify, let's just say that there are 3 variables x, y and z which are in the certain range. Each variable has its own range. I want to compute new variable p = x + F*(y-z) and it needs to be mapped appropriately into its own range. How do I do that?