Skip to content

Commit 1a34db4

Browse files
committed
Release v0.9.1
1 parent c538470 commit 1a34db4

File tree

3 files changed

+56
-36
lines changed

3 files changed

+56
-36
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ml",
3-
"version": "0.9.0",
3+
"version": "0.9.1",
44
"main": [
55
"dist/ml.js",
66
"dist/ml.min.js"

dist/ml.js

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1949,34 +1949,35 @@ return /******/ (function(modules) { // webpackBootstrap
19491949
return true;
19501950
}
19511951

1952-
remove(key) {
1952+
remove(key, noRehash) {
19531953
const i = this.indexOfKey(key);
19541954
if (i < 0) return false;
19551955

19561956
this.state[i] = REMOVED;
19571957
this.distinct--;
19581958

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();
19631960

19641961
return true;
19651962
}
19661963

1967-
delete(key) {
1964+
delete(key, noRehash) {
19681965
const i = this.indexOfKey(key);
19691966
if (i < 0) return false;
19701967

19711968
this.state[i] = FREE;
19721969
this.distinct--;
19731970

1971+
if (!noRehash) this.maybeShrinkCapacity();
1972+
1973+
return true;
1974+
}
1975+
1976+
maybeShrinkCapacity() {
19741977
if (this.distinct < this.lowWaterMark) {
19751978
const newCapacity = chooseShrinkCapacity(this.distinct, this.minLoadFactor, this.maxLoadFactor);
1976-
this.rehash(newCapacity)
1979+
this.rehash(newCapacity);
19771980
}
1978-
1979-
return true;
19801981
}
19811982

19821983
containsKey(key) {
@@ -8810,20 +8811,23 @@ return /******/ (function(modules) { // webpackBootstrap
88108811
}
88118812

88128813
forEachNonZero(callback) {
8813-
return this.elements.forEachPair((key, value) => {
8814+
this.elements.forEachPair((key, value) => {
88148815
const i = (key / this.columns) | 0;
88158816
const j = key % this.columns;
8816-
const r = callback(i, j, value);
8817+
let r = callback(i, j, value);
88178818
if (r === false) return false; // stop iteration
8819+
if (this.threshold && Math.abs(r) < this.threshold) r = 0;
88188820
if (r !== value) {
88198821
if (r === 0) {
8820-
this.elements.remove(key);
8822+
this.elements.remove(key, true);
88218823
} else {
88228824
this.elements.set(key, r);
88238825
}
88248826
}
88258827
return true;
88268828
});
8829+
this.elements.maybeShrinkCapacity();
8830+
return this;
88278831
}
88288832

88298833
getNonZeros() {
@@ -8841,6 +8845,14 @@ return /******/ (function(modules) { // webpackBootstrap
88418845
});
88428846
return {rows, columns, values};
88438847
}
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+
}
88448856
}
88458857

88468858
SparseMatrix.prototype.klass = 'Matrix';
@@ -10132,7 +10144,8 @@ return /******/ (function(modules) { // webpackBootstrap
1013210144
* @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)
1013310145
* @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)
1013410146
*/
10135-
constructor(prediction, target, options = {}) {
10147+
constructor(prediction, target, options) {
10148+
options = options || {};
1013610149
if (prediction.length !== target.length || prediction[0].length !== target[0].length) {
1013710150
throw new Error('dimensions of prediction and target do not match');
1013810151
}
@@ -10165,38 +10178,44 @@ return /******/ (function(modules) { // webpackBootstrap
1016510178
}
1016610179
}
1016710180

10168-
predP.sort((a, b) => a.pred - b.pred);
10169-
const l = predP.length;
10181+
predP.sort((a, b) => b.pred - a.pred);
1017010182

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];
1017810186

1017910187
var nPos = 0;
1018010188
var nNeg = 0;
10181-
cutoffs[0] = Number.MAX_VALUE;
10182-
fp[0] = tp[0] = 0;
1018310189

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+
}
1018510200
if (predP[i].targ) {
1018610201
nPos++;
10187-
tp[i + 1] = tp[i] + 1;
10188-
fp[i + 1] = fp[i];
10202+
nTp++;
1018910203
} else {
1019010204
nNeg++;
10191-
tp[i + 1] = tp[i];
10192-
fp[i + 1] = fp[i] + 1;
10205+
nFp++;
1019310206
}
10194-
10195-
// TODO eliminate duplicates in tp and fp
10196-
cutoffs[i + 1] = predP[i].pred;
1019710207
}
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);
1019810217

10199-
for (var i = 0; i < (l + 1); i++) {
10218+
for (var i = 0; i < l; i++) {
1020010219
fn[i] = nPos - tp[i];
1020110220
tn[i] = nNeg - fp[i];
1020210221

@@ -10271,7 +10290,8 @@ return /******/ (function(modules) { // webpackBootstrap
1027110290
return auc;
1027210291
}
1027310292

10274-
getDistribution(options = {}) {
10293+
getDistribution(options) {
10294+
options = options || {};
1027510295
var cutLength = this.cutoffs.length;
1027610296
var cutLow = options.xMin || Math.floor(this.cutoffs[cutLength - 1] * 100) / 100;
1027710297
var cutHigh = options.xMax || Math.ceil(this.cutoffs[1] * 100) / 100;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ml",
3-
"version": "0.9.0",
3+
"version": "0.9.1",
44
"description": "Machine learning tools",
55
"main": "src/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)