Hi guys,

I am transferring figures between a Neural Network and a Genetic algorithm. This means I have to do some scaling.

I have found out how to scale to produce a value between 0 and n but not between -n and n or x and y.

So all in all I need 3 types of scaling.

1) Firstly I need to scale between 0 and a set maximum number (I can do that one).

float scale1(float oldMax, float newMax, float oldValue)
{
   return oldMax * (oldValue / newMax);
}

Where oldMax is the maximum number from the range that I am trying to convert from.
newMax is the maximum positive number that will be the ceiling for the scaling.
oldValue will be the value from the old range that we wish to scale to the new range.

2) Then I need to scale between a negative minimum (-10) and a positive maximum (10)

3) Finally I need to scale between two different values. Say between 2 and 30.


I hope this is clear. If you want me to have another go at explaining it I won't mind.

Thanks for any help possible.

Alex

There is probably a lot of way doing this, but here is one way.

float scale(float n, float min, float max){
 return min + fmod(n,max);
}

EDIT: might not be a good scale, although would be correctly, is not a good distribution. Ignore it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.