ml-regression-polynomial
Advanced tools
Comparing version 3.0.0 to 3.0.1
import { type NumberArray } from 'cheminfo-types'; | ||
import BaseRegression from 'ml-regression-base'; | ||
import { BaseRegression } from 'ml-regression-base'; | ||
interface PolynomialRegressionOptions { | ||
@@ -4,0 +4,0 @@ interceptAtZero?: boolean; |
import { Matrix, MatrixTransposeView, solve } from 'ml-matrix'; | ||
import BaseRegression, { checkArrayLength, maybeToPrecision, } from 'ml-regression-base'; | ||
import { BaseRegression, checkArrayLength, maybeToPrecision, } from 'ml-regression-base'; | ||
export class PolynomialRegression extends BaseRegression { | ||
@@ -37,3 +37,3 @@ /** | ||
for (let k = 0; k < this.powers.length; k++) { | ||
y += this.coefficients[k] * Math.pow(x, this.powers[k]); | ||
y += this.coefficients[k] * x ** this.powers[k]; | ||
} | ||
@@ -140,3 +140,3 @@ return y; | ||
else { | ||
F.set(i, k, Math.pow(x[i], powers[k])); | ||
F.set(i, k, x[i] ** powers[k]); | ||
} | ||
@@ -143,0 +143,0 @@ } |
import { type NumberArray } from 'cheminfo-types'; | ||
import BaseRegression from 'ml-regression-base'; | ||
import { BaseRegression } from 'ml-regression-base'; | ||
interface PolynomialRegressionOptions { | ||
@@ -4,0 +4,0 @@ interceptAtZero?: boolean; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PolynomialRegression = void 0; | ||
const ml_matrix_1 = require("ml-matrix"); | ||
const ml_regression_base_1 = __importStar(require("ml-regression-base")); | ||
class PolynomialRegression extends ml_regression_base_1.default { | ||
const ml_regression_base_1 = require("ml-regression-base"); | ||
class PolynomialRegression extends ml_regression_base_1.BaseRegression { | ||
/** | ||
@@ -63,3 +40,3 @@ * @param x - independent or explanatory variable | ||
for (let k = 0; k < this.powers.length; k++) { | ||
y += this.coefficients[k] * Math.pow(x, this.powers[k]); | ||
y += this.coefficients[k] * x ** this.powers[k]; | ||
} | ||
@@ -167,3 +144,3 @@ return y; | ||
else { | ||
F.set(i, k, Math.pow(x[i], powers[k])); | ||
F.set(i, k, x[i] ** powers[k]); | ||
} | ||
@@ -170,0 +147,0 @@ } |
{ | ||
"name": "ml-regression-polynomial", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Polynomial Regression", | ||
@@ -39,15 +39,16 @@ "types": "./lib/index.d.ts", | ||
"devDependencies": { | ||
"@vitest/coverage-v8": "^0.34.5", | ||
"eslint": "^8.50.0", | ||
"eslint-config-cheminfo-typescript": "^12.0.4", | ||
"prettier": "^3.0.3", | ||
"rimraf": "^5.0.5", | ||
"typescript": "^5.2.2", | ||
"vitest": "^0.34.5" | ||
"@vitest/coverage-v8": "^1.6.0", | ||
"eslint": "^8.56.0", | ||
"eslint-config-cheminfo-typescript": "^12.4.0", | ||
"ml-spectra-processing": "^14.5.0", | ||
"prettier": "^3.2.5", | ||
"rimraf": "^5.0.7", | ||
"typescript": "^5.4.5", | ||
"vitest": "^1.6.0" | ||
}, | ||
"dependencies": { | ||
"cheminfo-types": "^1.7.2", | ||
"ml-matrix": "^6.10.5", | ||
"ml-regression-base": "^3.0.0" | ||
"cheminfo-types": "^1.7.3", | ||
"ml-matrix": "^6.11.0", | ||
"ml-regression-base": "^4.0.0" | ||
} | ||
} | ||
} |
import { NumberArray } from 'cheminfo-types'; | ||
import { createRandomArray, xSum } from 'ml-spectra-processing'; | ||
import { expect, it, describe } from 'vitest'; | ||
@@ -19,2 +20,15 @@ | ||
describe('Polynomial regression', () => { | ||
it('basic linear test', () => { | ||
const size = 1000; | ||
const x = new Array(size).fill(0).map((_, i) => i); | ||
const y = new Array(size).fill(1); | ||
const regression = new PolynomialRegression(x, y, 1, { | ||
interceptAtZero: false, | ||
}); | ||
let difference = 0; | ||
for (let i = 0; i < size; i++) { | ||
difference += Math.abs(regression.predict(x[i]) - y[i]); | ||
} | ||
expect(difference).closeTo(0, 1e-6); | ||
}); | ||
it('degree 2', () => { | ||
@@ -120,2 +134,24 @@ const x = [-3, 0, 2, 4]; | ||
}); | ||
it('white noise regression', () => { | ||
const size = 1000000; | ||
const x = new Array(size).fill(0).map((_, i) => i); | ||
const y = Array.from( | ||
createRandomArray({ | ||
seed: 0, | ||
mean: 0, | ||
distribution: 'normal', | ||
length: size, | ||
}), | ||
); | ||
const regression = new PolynomialRegression(x, y, 1, { | ||
interceptAtZero: false, | ||
}); | ||
const newY = []; | ||
for (let i = 0; i < size; i++) { | ||
newY.push(y[i] - regression.predict(x[i])); | ||
} | ||
const newSumY = xSum(newY); | ||
expect(newSumY).toBeCloseTo(0, 1e-6); | ||
}); | ||
}); |
import { type NumberArray } from 'cheminfo-types'; | ||
import { Matrix, MatrixTransposeView, solve } from 'ml-matrix'; | ||
import BaseRegression, { | ||
import { | ||
BaseRegression, | ||
checkArrayLength, | ||
@@ -53,3 +54,3 @@ maybeToPrecision, | ||
for (let k = 0; k < this.powers.length; k++) { | ||
y += this.coefficients[k] * Math.pow(x, this.powers[k]); | ||
y += this.coefficients[k] * x ** this.powers[k]; | ||
} | ||
@@ -166,3 +167,3 @@ return y; | ||
} else { | ||
F.set(i, k, Math.pow(x[i], powers[k])); | ||
F.set(i, k, x[i] ** powers[k]); | ||
} | ||
@@ -169,0 +170,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
40918
681
0
8
+ Addedml-regression-base@4.0.0(transitive)
- Removedml-regression-base@3.0.0(transitive)
Updatedcheminfo-types@^1.7.3
Updatedml-matrix@^6.11.0
Updatedml-regression-base@^4.0.0