0

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

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by firstPerson
0

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.

Edited by firstPerson: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.