rescale method

Vector rescale()

Rescales the vector to the range 0-1.

It applies the Min-Max normalization technique on the vector.

Example:

var v = Vector.fromList([1.0, 2.0, 3.0, 4.0, 5.0]);
print(v.rescale());
// Output: [0.0, 0.25, 0.5, 0.75, 1.0]

Implementation

Vector rescale() {
  num maxElement = _data.reduce(math.max);
  num minElement = _data.reduce(math.min);

  return Vector.fromList(_data
      .map((n) => (n - minElement) / (maxElement - minElement))
      .toList());
}