File tree 2 files changed +10
-0
lines changed
2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -322,6 +322,10 @@ export class UMAP {
322
322
* SGD optimization.
323
323
*/
324
324
initializeFit ( X : Vectors ) : number {
325
+ if ( X . length <= this . nNeighbors ) {
326
+ throw new Error ( `Not enough data points (${ X . length } ) to create nNeighbors: ${ this . nNeighbors } . Add more data points or adjust the configuration.` ) ;
327
+ }
328
+
325
329
// We don't need to reinitialize if we've already initialized for this data.
326
330
if ( this . X === X && this . isInitialized ) {
327
331
return this . getNEpochs ( ) ;
Original file line number Diff line number Diff line change @@ -202,6 +202,12 @@ describe('UMAP', () => {
202
202
203
203
expect ( nInvocations ) . toBeGreaterThan ( 0 ) ;
204
204
} ) ;
205
+
206
+ test ( 'initializeFit throws helpful error if not enough data' , ( ) => {
207
+ const umap = new UMAP ( { random } ) ;
208
+ const smallData = testData . slice ( 0 , 15 ) ;
209
+ expect ( ( ) => umap . initializeFit ( smallData ) ) . toThrow ( / N o t e n o u g h d a t a p o i n t s / ) ;
210
+ } )
205
211
} ) ;
206
212
207
213
function computeMeanDistances ( vectors : number [ ] [ ] ) {
You can’t perform that action at this time.
0 commit comments