Skip to content

Commit 4cea824

Browse files
committed
Fix normalisation bug.
1 parent 0fd2844 commit 4cea824

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

ShapeDatabase/Features/FeatureNormaliser.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,26 @@ public void UpdateMinMaxDictionary(IDictionary<string, FeatureVector> vectors) {
127127

128128
// Initialise descriptors if they had not been added before.
129129
FeatureVector exampleVector = vectors.First().Value;
130-
foreach (ElemDescriptor desc in exampleVector.GetDescriptors<ElemDescriptor>()) {
130+
foreach (ElemDescriptor desc in exampleVector.GetDescriptors<ElemDescriptor>())
131131
if (!MinMaxValues.ContainsKey(desc.Name))
132-
MinMaxValues[desc.Name] = (desc.Value, desc.Value);
133-
}
132+
MinMaxValues.Add(desc.Name, (double.MaxValue, double.MinValue));
134133

135134
// Iterate over all vectors and update the min and max of each descriptor.
136135
foreach (KeyValuePair<string, FeatureVector> vector in vectors)
137136
foreach (ElemDescriptor desc in vector.Value.GetDescriptors<ElemDescriptor>()) {
138-
double Min = (desc.Value != double.PositiveInfinity && desc.Value < MinMaxValues[desc.Name].Item1) ? desc.Value : MinMaxValues[desc.Name].Item1;
139-
double Max = (desc.Value != double.PositiveInfinity && desc.Value > MinMaxValues[desc.Name].Item2) ? desc.Value : MinMaxValues[desc.Name].Item2;
140-
MinMaxValues[desc.Name] = (Min, Max);
137+
double value = desc.Value;
138+
// Special case: Infinity values or not a number values.
139+
if (double.IsInfinity(value) || double.IsNaN(value)) continue;
140+
141+
(double min, double max) = MinMaxValues[desc.Name];
142+
143+
min = Math.Min(min, value);
144+
max = Math.Max(max, value);
145+
146+
MinMaxValues[desc.Name] = (min, max);
141147
}
142148
}
149+
143150
}
151+
144152
}

0 commit comments

Comments
 (0)