Skip to content

Commit

Permalink
[NeoML] Avoid small negative values in CalcDistance (#1039)
Browse files Browse the repository at this point in the history
Signed-off-by: Kirill Golikov <kirill.golikov@abbyy.com>
  • Loading branch information
favorart committed Mar 28, 2024
1 parent e6b87c1 commit 24026ca
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions NeoML/src/TraditionalML/ClusterCenter.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright © 2017-2020 ABBYY Production LLC
/* Copyright © 2017-2024 ABBYY
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -108,7 +108,7 @@ double CalcDistance( const CClusterCenter& first, const CClusterCenter& second,
NeoPresume( distanceFunc >= 0 );
NeoPresume( distanceFunc < DF_Count );

return (*clusterDistanceFuncs[distanceFunc])( first, second );
return max( 0., (*clusterDistanceFuncs[distanceFunc])( first, second ) );
}

// Calculates the distance from an element to the cluster center
Expand All @@ -117,7 +117,7 @@ double CalcDistance( const CClusterCenter& cluster, const CFloatVector& element,
NeoPresume( distanceFunc >= 0 );
NeoPresume( distanceFunc < DF_Count );

return (*vectorDistanceFuncs[distanceFunc])( cluster, element );
return max( 0., (*vectorDistanceFuncs[distanceFunc])( cluster, element ) );
}

} // namespace NeoML

0 comments on commit 24026ca

Please sign in to comment.