@@ -103,6 +103,41 @@ def test_negative_score(self):
103103 )[0 ]
104104 self .assertTrue (distance < 0.0 )
105105
106+ def test_positive_score (self ):
107+ """
108+ Ensure that when we score on the points we fitted that we obtain only >= 0 distances
109+ In an old implementation we observed this bug for the dataset we use in this test
110+ (see issue #162)
111+ """
112+ X = [[1.88421449 , 0.86675162 ],
113+ [1.88652863 , 0.86577001 ],
114+ [1.89200182 , 0.86573224 ],
115+ [1.89664107 , 0.86937211 ],
116+ [1.90181908 , 0.85964603 ],
117+ [1.90313135 , 0.85695238 ],
118+ [1.90063025 , 0.84948309 ],
119+ [1.90929015 , 0.87526563 ],
120+ [1.90924666 , 0.85509754 ],
121+ [1.91139146 , 0.86115512 ],
122+ [1.91199225 , 0.8681867 ],
123+ [1.90681563 , 0.85036791 ],
124+ [1.90193881 , 0.84168907 ],
125+ [1.90544262 , 0.84451744 ],
126+ [1.91498802 , 0.86010812 ],
127+ [1.91305204 , 0.85333203 ],
128+ [1.89779902 , 0.83731807 ],
129+ [1.91725967 , 0.86630218 ],
130+ [1.91309514 , 0.85046796 ],
131+ [1.89822103 , 0.83522425 ]]
132+ y = [- 2.69180967 , - 2.72443825 , - 2.77293913 , - 2.797828 , - 2.12097652 , - 2.69428482 ,
133+ - 2.70275134 , - 2.80617667 , - 2.79199375 , - 2.01707974 , - 2.74203922 , - 2.24217962 ,
134+ - 2.03472 , - 2.72612763 , - 2.7071123 , - 2.75706683 , - 2.68925596 , - 2.77160335 ,
135+ - 2.69528665 , - 2.70911598 ]
136+ selector = DirectionalConvexHull (low_dim_idx = [0 , 1 ])
137+ selector .fit (X , y )
138+ distances = selector .score_samples (X , y )
139+ self .assertTrue (np .all (distances >= - 1e-12 ))
140+
106141 def test_score_function_warnings (self ):
107142 """
108143 Ensure that calling `score_samples` with points outside the range causes an error
@@ -128,7 +163,7 @@ def test_score_function_warnings(self):
128163 self .assertTrue (len (warning ) == 1 )
129164 self .assertTrue (issubclass (warning [0 ].category , UserWarning ))
130165 self .assertTrue (
131- "There are samples in X with a low-dimensional part that is outside of the range of the convex surface. Distance will contain nans."
166+ "There are samples in X with a low-dimensional part that is outside of the range of the convex surface. Distance will contain nans."
132167 == str (warning [0 ].message )
133168 )
134169
0 commit comments