normalization - VB.NET Normalizing Data [1, -1] -
i using following code normalize data:
public function normalizedata(values double()) double() dim min = values.min dim max = values.max dim outlist(values.count - 1) double = 0 values.count - 1 outlist(i) = (values(i) - min) / (max - min) next return outlist end function
this returns values 0 1 accordingly. confused on how make normalize between [1, -1] instead of [1, 0].
you know how normalise range of 0 1. if want range -1 1, need multiply normalised data 2 , subtract 1.
as said in comment, modify statement inside loop adjust data:
outlist(i) = 2 * (values(i) - min) / (max - min) - 1
the equivalent statement denormalise data be:
outlist(i)= (values(i) + 1) * (max - min) / 2 + min
if need normalise , denormalise several arrays of data, suggest creating normaldata
class can store normalised data maximum , minimum values , has properties return either normalised or denormalised values. here example of such class. can create using either
- an array of unnormalised data, or ...
- an array of normalised data , minimum , maximum values
the normalvalues
, values
properties return normalised , denormalised data respectively.
public class normaldata ''' <summary>create normaldata object , unnormalised array of values</summary> ''' <param name="values">unnormalised values</param> sub new(values() double) minimum = values.min maximum = values.max normalvalues = values.select(function(val) 2 * (val - minimum) / (maximum - minimum) - 1).toarray end sub ''' <summary>create normaldata object , normalised array of values</summary> ''' <param name="normal">normalised values</param> ''' <param name="min">minimum value of unnormalised data</param> ''' <param name="max">maximum value of unnormalised data</param> sub new(normal() double, min double, max double) minimum = min maximum = max normalvalues = normal end sub readonly property minimum double readonly property maximum double readonly property normalvalues double() readonly property values double() return normalvalues.select(function(norm) (norm + 1) * (maximum - minimum) / 2 + minimum).toarray end end property end class
Comments
Post a Comment