ml-regression-polynomial
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -0,1 +1,10 @@ | ||
# [2.1.0](https://github.com/mljs/regression-polynomial/compare/v2.0.0...v2.1.0) (2020-02-04) | ||
### Features | ||
* works in typed array ([9617088](https://github.com/mljs/regression-polynomial/commit/961708871c015512921f4538ee6396727db2e8b7)) | ||
# [2.0.0](https://github.com/mljs/regression-polynomial/compare/v1.0.3...v2.0.0) (2019-06-29) | ||
@@ -2,0 +11,0 @@ |
@@ -35,3 +35,3 @@ 'use strict'; | ||
powers: this.powers, | ||
coefficients: this.coefficients | ||
coefficients: this.coefficients, | ||
}; | ||
@@ -67,12 +67,7 @@ } | ||
if (this.powers[k] === 1) { | ||
str = | ||
`${BaseRegression.maybeToPrecision(this.coefficients[k], precision) + times}x`; | ||
str = `${BaseRegression.maybeToPrecision(this.coefficients[k], precision) + | ||
times}x`; | ||
} else { | ||
str = | ||
`${BaseRegression.maybeToPrecision(this.coefficients[k], precision) + | ||
times | ||
}x${ | ||
sup | ||
}${this.powers[k] | ||
}${closeSup}`; | ||
str = `${BaseRegression.maybeToPrecision(this.coefficients[k], precision) + | ||
times}x${sup}${this.powers[k]}${closeSup}`; | ||
} | ||
@@ -79,0 +74,0 @@ } |
{ | ||
"name": "ml-regression-polynomial", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Polynomial Regression", | ||
@@ -35,14 +35,16 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@babel/plugin-transform-modules-commonjs": "^7.4.4", | ||
"eslint": "^5.16.0", | ||
"eslint-config-cheminfo": "^1.20.1", | ||
"eslint-plugin-import": "^2.17.2", | ||
"eslint-plugin-jest": "^22.5.1", | ||
"jest": "^24.7.1", | ||
"rollup": "^1.10.1" | ||
"@babel/plugin-transform-modules-commonjs": "^7.8.3", | ||
"eslint": "^6.8.0", | ||
"eslint-config-cheminfo": "^2.0.4", | ||
"eslint-plugin-import": "^2.20.1", | ||
"eslint-plugin-jest": "^23.6.0", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"jest": "^25.1.0", | ||
"prettier": "^1.19.1", | ||
"rollup": "^1.31.0" | ||
}, | ||
"dependencies": { | ||
"ml-matrix": "^6.1.2", | ||
"ml-regression-base": "^2.0.1" | ||
"ml-matrix": "^6.4.1", | ||
"ml-regression-base": "^2.1.1" | ||
} | ||
} |
@@ -21,3 +21,3 @@ import PolynomialRegression from '..'; | ||
expect(result.toString(4)).toBe( | ||
'f(x) = 0.1785 * x^2 - 0.1925 * x + 0.8505' | ||
'f(x) = 0.1785 * x^2 - 0.1925 * x + 0.8505', | ||
); | ||
@@ -27,2 +27,24 @@ expect(result.toLaTeX(2)).toBe('f(x) = 0.18x^{2} - 0.19x + 0.85'); | ||
it('degree 2 typed array', () => { | ||
const x = new Float64Array([-3, 0, 2, 4]); | ||
const y = new Float64Array([3, 1, 1, 3]); | ||
const result = new PolynomialRegression(x, y, 2); | ||
const expected = [0.850519, -0.192495, 0.178462]; | ||
for (let i = 0; i < expected.length; ++i) { | ||
expect(result.coefficients[i]).toBeCloseTo(expected[i], 10e-6); | ||
expect(result.powers[i]).toBe(i); | ||
} | ||
const score = result.score(x, y); | ||
expect(score.r2).toBeGreaterThan(0.8); | ||
expect(score.chi2).toBeLessThan(0.1); | ||
expect(score.rmsd).toBeCloseTo(0.12); | ||
expect(result.toString(4)).toBe( | ||
'f(x) = 0.1785 * x^2 - 0.1925 * x + 0.8505', | ||
); | ||
expect(result.toLaTeX(2)).toBe('f(x) = 0.18x^{2} - 0.19x + 0.85'); | ||
}); | ||
it('degree 5', () => { | ||
@@ -45,3 +67,3 @@ const x = [50, 50, 50, 70, 70, 70, 80, 80, 80, 90, 90, 90, 100, 100, 100]; | ||
3.5, | ||
3.0 | ||
3.0, | ||
]; | ||
@@ -57,6 +79,6 @@ const degree = 5; | ||
-0.000001302280135149651, | ||
3.837755337564968e-9 | ||
3.837755337564968e-9, | ||
]); | ||
expect(regression.toString(3)).toBe( | ||
'f(x) = 3.84e-9 * x^5 - 0.00000130 * x^4 + 0.000137 * x^3 - 0.00199 * x^2 - 0.392 * x + 17.4' | ||
'f(x) = 3.84e-9 * x^5 - 0.00000130 * x^4 + 0.000137 * x^3 - 0.00199 * x^2 - 0.392 * x + 17.4', | ||
); | ||
@@ -70,3 +92,3 @@ }); | ||
powers: [1], | ||
coefficients: [-1] | ||
coefficients: [-1], | ||
}); | ||
@@ -81,5 +103,5 @@ | ||
powers: [1], | ||
coefficients: [-1] | ||
coefficients: [-1], | ||
}); | ||
}); | ||
}); |
import BaseRegression, { | ||
checkArrayLength, | ||
maybeToPrecision | ||
maybeToPrecision, | ||
} from 'ml-regression-base'; | ||
@@ -33,3 +33,3 @@ import { Matrix, MatrixTransposeView, solve } from 'ml-matrix'; | ||
powers: this.powers, | ||
coefficients: this.coefficients | ||
coefficients: this.coefficients, | ||
}; | ||
@@ -65,12 +65,7 @@ } | ||
if (this.powers[k] === 1) { | ||
str = | ||
`${maybeToPrecision(this.coefficients[k], precision) + times}x`; | ||
str = `${maybeToPrecision(this.coefficients[k], precision) + | ||
times}x`; | ||
} else { | ||
str = | ||
`${maybeToPrecision(this.coefficients[k], precision) + | ||
times | ||
}x${ | ||
sup | ||
}${this.powers[k] | ||
}${closeSup}`; | ||
str = `${maybeToPrecision(this.coefficients[k], precision) + | ||
times}x${sup}${this.powers[k]}${closeSup}`; | ||
} | ||
@@ -77,0 +72,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13941
318
9
1
Updatedml-matrix@^6.4.1
Updatedml-regression-base@^2.1.1