USArmy-Corps-of-Engineers-RMC / Numerics

Numerics is a free and open-source library for .NET developed by USACE-RMC, providing a comprehensive set of methods and algorithms for numerical computations and statistical analysis.
Other
18 stars 2 forks source link

Tools - Normalize() is wrong? #39

Closed tikigonzo closed 3 weeks ago

tikigonzo commented 2 months ago

The Normalize() method in Tools.cs is supposed to return the normalized values from the vector or list. The current method updates the array with the values[i] - minimum value / max - min value. I tried to rewrite my own method to pass a unit test underneath the other one.

tikigonzo commented 2 months ago

This normalize method is implementing Min-Max scaling.

HadenSmith commented 2 months ago

Looks like you might be testing the wrong things. Try running this test:

[TestMethod] public void Test_Normalize_Denormalize() { var trueData = new double[] { 0, 250, 500, 750, 1000 }; var trueNorm = new double[] { 0, 0.25, 0.5, 0.75, 1.0 };

// Test normalization
var dataNorm = Tools.Normalize(trueData);
for (int i  = 0; i < trueData.Length; i++)
{
    Assert.AreEqual(trueNorm[i], dataNorm[i]);
}

// Test de-normalization
var dataDenorm = Tools.Denormalize(dataNorm, Tools.Min(trueData), Tools.Max(trueData));
for (int i = 0; i < trueData.Length; i++)
{
    Assert.AreEqual(trueData[i], dataDenorm[i]);
}

}

HadenSmith commented 2 months ago

An additional reference: https://www.codecademy.com/article/normalization

Its doing min-max normalization. The standardize method is doing "z-score normalization" shown in this link.