@@ -1949,34 +1949,35 @@ return /******/ (function(modules) { // webpackBootstrap
1949
1949
return true ;
1950
1950
}
1951
1951
1952
- remove ( key ) {
1952
+ remove ( key , noRehash ) {
1953
1953
const i = this . indexOfKey ( key ) ;
1954
1954
if ( i < 0 ) return false ;
1955
1955
1956
1956
this . state [ i ] = REMOVED ;
1957
1957
this . distinct -- ;
1958
1958
1959
- if ( this . distinct < this . lowWaterMark ) {
1960
- const newCapacity = chooseShrinkCapacity ( this . distinct , this . minLoadFactor , this . maxLoadFactor ) ;
1961
- this . rehash ( newCapacity )
1962
- }
1959
+ if ( ! noRehash ) this . maybeShrinkCapacity ( ) ;
1963
1960
1964
1961
return true ;
1965
1962
}
1966
1963
1967
- delete ( key ) {
1964
+ delete ( key , noRehash ) {
1968
1965
const i = this . indexOfKey ( key ) ;
1969
1966
if ( i < 0 ) return false ;
1970
1967
1971
1968
this . state [ i ] = FREE ;
1972
1969
this . distinct -- ;
1973
1970
1971
+ if ( ! noRehash ) this . maybeShrinkCapacity ( ) ;
1972
+
1973
+ return true ;
1974
+ }
1975
+
1976
+ maybeShrinkCapacity ( ) {
1974
1977
if ( this . distinct < this . lowWaterMark ) {
1975
1978
const newCapacity = chooseShrinkCapacity ( this . distinct , this . minLoadFactor , this . maxLoadFactor ) ;
1976
- this . rehash ( newCapacity )
1979
+ this . rehash ( newCapacity ) ;
1977
1980
}
1978
-
1979
- return true ;
1980
1981
}
1981
1982
1982
1983
containsKey ( key ) {
@@ -8810,20 +8811,23 @@ return /******/ (function(modules) { // webpackBootstrap
8810
8811
}
8811
8812
8812
8813
forEachNonZero ( callback ) {
8813
- return this . elements . forEachPair ( ( key , value ) => {
8814
+ this . elements . forEachPair ( ( key , value ) => {
8814
8815
const i = ( key / this . columns ) | 0 ;
8815
8816
const j = key % this . columns ;
8816
- const r = callback ( i , j , value ) ;
8817
+ let r = callback ( i , j , value ) ;
8817
8818
if ( r === false ) return false ; // stop iteration
8819
+ if ( this . threshold && Math . abs ( r ) < this . threshold ) r = 0 ;
8818
8820
if ( r !== value ) {
8819
8821
if ( r === 0 ) {
8820
- this . elements . remove ( key ) ;
8822
+ this . elements . remove ( key , true ) ;
8821
8823
} else {
8822
8824
this . elements . set ( key , r ) ;
8823
8825
}
8824
8826
}
8825
8827
return true ;
8826
8828
} ) ;
8829
+ this . elements . maybeShrinkCapacity ( ) ;
8830
+ return this ;
8827
8831
}
8828
8832
8829
8833
getNonZeros ( ) {
@@ -8841,6 +8845,14 @@ return /******/ (function(modules) { // webpackBootstrap
8841
8845
} ) ;
8842
8846
return { rows, columns, values} ;
8843
8847
}
8848
+
8849
+ setThreshold ( newThreshold ) {
8850
+ if ( newThreshold !== 0 && newThreshold !== this . threshold ) {
8851
+ this . threshold = newThreshold ;
8852
+ this . forEachNonZero ( ( i , j , v ) => v ) ;
8853
+ }
8854
+ return this ;
8855
+ }
8844
8856
}
8845
8857
8846
8858
SparseMatrix . prototype . klass = 'Matrix' ;
@@ -10132,7 +10144,8 @@ return /******/ (function(modules) { // webpackBootstrap
10132
10144
* @option all True if the entire matrix must be used. False to ignore the diagonal and lower part (default is false, for similarity/distance matrices)
10133
10145
* @option max True if the max value corresponds to a perfect match (like in similarity matrices), false if it is the min value (default is false, like in distance matrices. All values will be multiplied by -1)
10134
10146
*/
10135
- constructor ( prediction , target , options = { } ) {
10147
+ constructor ( prediction , target , options ) {
10148
+ options = options || { } ;
10136
10149
if ( prediction . length !== target . length || prediction [ 0 ] . length !== target [ 0 ] . length ) {
10137
10150
throw new Error ( 'dimensions of prediction and target do not match' ) ;
10138
10151
}
@@ -10165,38 +10178,44 @@ return /******/ (function(modules) { // webpackBootstrap
10165
10178
}
10166
10179
}
10167
10180
10168
- predP . sort ( ( a , b ) => a . pred - b . pred ) ;
10169
- const l = predP . length ;
10181
+ predP . sort ( ( a , b ) => b . pred - a . pred ) ;
10170
10182
10171
- const cutoffs = this . cutoffs = new Array ( l + 1 ) ;
10172
- const fp = this . fp = new Array ( l + 1 ) ;
10173
- const tp = this . tp = new Array ( l + 1 ) ;
10174
- const fn = this . fn = new Array ( l + 1 ) ;
10175
- const tn = this . tn = new Array ( l + 1 ) ;
10176
- const nPosPred = this . nPosPred = new Array ( l + 1 ) ;
10177
- const nNegPred = this . nNegPred = new Array ( l + 1 ) ;
10183
+ const cutoffs = this . cutoffs = [ Number . MAX_VALUE ] ;
10184
+ const fp = this . fp = [ 0 ] ;
10185
+ const tp = this . tp = [ 0 ] ;
10178
10186
10179
10187
var nPos = 0 ;
10180
10188
var nNeg = 0 ;
10181
- cutoffs [ 0 ] = Number . MAX_VALUE ;
10182
- fp [ 0 ] = tp [ 0 ] = 0 ;
10183
10189
10184
- for ( var i = 0 ; i < l ; i ++ ) {
10190
+ var currentPred = predP [ 0 ] . pred ;
10191
+ var nTp = 0 ;
10192
+ var nFp = 0 ;
10193
+ for ( var i = 0 ; i < predP . length ; i ++ ) {
10194
+ if ( predP [ i ] . pred !== currentPred ) {
10195
+ cutoffs . push ( currentPred ) ;
10196
+ fp . push ( nFp ) ;
10197
+ tp . push ( nTp ) ;
10198
+ currentPred = predP [ i ] . pred ;
10199
+ }
10185
10200
if ( predP [ i ] . targ ) {
10186
10201
nPos ++ ;
10187
- tp [ i + 1 ] = tp [ i ] + 1 ;
10188
- fp [ i + 1 ] = fp [ i ] ;
10202
+ nTp ++ ;
10189
10203
} else {
10190
10204
nNeg ++ ;
10191
- tp [ i + 1 ] = tp [ i ] ;
10192
- fp [ i + 1 ] = fp [ i ] + 1 ;
10205
+ nFp ++ ;
10193
10206
}
10194
-
10195
- // TODO eliminate duplicates in tp and fp
10196
- cutoffs [ i + 1 ] = predP [ i ] . pred ;
10197
10207
}
10208
+ cutoffs . push ( currentPred ) ;
10209
+ fp . push ( nFp ) ;
10210
+ tp . push ( nTp ) ;
10211
+
10212
+ const l = cutoffs . length ;
10213
+ const fn = this . fn = new Array ( l ) ;
10214
+ const tn = this . tn = new Array ( l ) ;
10215
+ const nPosPred = this . nPosPred = new Array ( l ) ;
10216
+ const nNegPred = this . nNegPred = new Array ( l ) ;
10198
10217
10199
- for ( var i = 0 ; i < ( l + 1 ) ; i ++ ) {
10218
+ for ( var i = 0 ; i < l ; i ++ ) {
10200
10219
fn [ i ] = nPos - tp [ i ] ;
10201
10220
tn [ i ] = nNeg - fp [ i ] ;
10202
10221
@@ -10271,7 +10290,8 @@ return /******/ (function(modules) { // webpackBootstrap
10271
10290
return auc ;
10272
10291
}
10273
10292
10274
- getDistribution ( options = { } ) {
10293
+ getDistribution ( options ) {
10294
+ options = options || { } ;
10275
10295
var cutLength = this . cutoffs . length ;
10276
10296
var cutLow = options . xMin || Math . floor ( this . cutoffs [ cutLength - 1 ] * 100 ) / 100 ;
10277
10297
var cutHigh = options . xMax || Math . ceil ( this . cutoffs [ 1 ] * 100 ) / 100 ;
0 commit comments