Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to normalize / denormalize a vector to range [-1;1]

How can I normalize a vector to the range [-1;1]

I would like to use function norm, because it will be faster.

Also let me know how I can denormalize that vector after normalization?

like image 977
neverMind Avatar asked Jan 13 '11 19:01

neverMind


People also ask

How do you normalize a vector value?

To normalize a vector, therefore, is to take a vector of any length and, keeping it pointing in the same direction, change its length to 1, turning it into what is called a unit vector. Since it describes a vector's direction without regard to its length, it's useful to have the unit vector readily accessible.

How do you normalize an array so the values range exactly between 0 and 1?

You can normalize data between 0 and 1 range by using the formula (data – np. min(data)) / (np. max(data) – np. min(data)) .

What is normalize and Denormalize?

Normalization is the technique of dividing the data into multiple tables to reduce data redundancy and inconsistency and to achieve data integrity. On the other hand, Denormalization is the technique of combining the data into a single table to make data retrieval faster.


1 Answers

norm normalizes a vector so that its sum of squares are 1.

If you want to normalize the vector so that all its elements are between 0 and 1, you need to use the minimum and maximum value, which you can then use to denormalize again.

%# generate some vector
vec = randn(10,1);

%# get max and min
maxVec = max(vec);
minVec = min(vec);

%# normalize to -1...1
vecN = ((vec-minVec)./(maxVec-minVec) - 0.5 ) *2;

%# to "de-normalize", apply the calculations in reverse
vecD = (vecN./2+0.5) * (maxVec-minVec) + minVec
like image 172
Jonas Avatar answered Sep 19 '22 09:09

Jonas