🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

ml-regression-base

Package Overview
Dependencies
Maintainers
7
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-regression-base - npm Package Compare versions

Comparing version

to
4.0.0

lib-esm/BaseRegression.d.ts

2

lib-esm/checkArrayLength.d.ts

@@ -8,3 +8,3 @@ import { NumberArray } from 'cheminfo-types';

*/
export default function checkArrayLength(x: NumberArray, y: NumberArray): void;
export declare function checkArrayLength(x: NumberArray, y: NumberArray): void;
//# sourceMappingURL=checkArrayLength.d.ts.map

@@ -8,3 +8,3 @@ import { isAnyArray } from 'is-any-array';

*/
export default function checkArrayLength(x, y) {
export function checkArrayLength(x, y) {
if (!isAnyArray(x) || !isAnyArray(y)) {

@@ -11,0 +11,0 @@ throw new TypeError('x and y must be arrays');

@@ -1,27 +0,4 @@

import { type NumberArray } from 'cheminfo-types';
import checkArrayLength from './checkArrayLength';
export { default as maybeToPrecision } from './maybeToPrecision';
export interface RegressionScore {
r: number;
r2: number;
chi2: number;
rmsd: number;
}
export default class BaseRegression {
constructor();
predict(x: number): number;
predict(x: NumberArray): number[];
_predict(x: number): number;
train(): void;
toString(precision?: number): string;
toLaTeX(precision?: number): string;
/**
* Return the correlation coefficient of determination (r) and chi-square.
* @param x - explanatory variable
* @param y - response variable
* @return - Object with further statistics.
*/
score(x: NumberArray, y: NumberArray): RegressionScore;
}
export { checkArrayLength, type NumberArray };
export * from './BaseRegression';
export * from './checkArrayLength';
export * from './maybeToPrecision';
//# sourceMappingURL=index.d.ts.map

@@ -1,82 +0,4 @@

import { isAnyArray } from 'is-any-array';
import checkArrayLength from './checkArrayLength';
export { default as maybeToPrecision } from './maybeToPrecision';
export default class BaseRegression {
constructor() {
if (new.target === BaseRegression) {
throw new Error('BaseRegression must be subclassed');
}
}
predict(x) {
if (typeof x === 'number') {
return this._predict(x);
}
else if (isAnyArray(x)) {
const y = [];
for (const xVal of x) {
y.push(this._predict(xVal));
}
return y;
}
else {
throw new TypeError('x must be a number or array');
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_predict(x) {
throw new Error('_predict must be implemented');
}
train() {
// Do nothing for this package
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
toString(precision) {
return '';
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
toLaTeX(precision) {
return '';
}
/**
* Return the correlation coefficient of determination (r) and chi-square.
* @param x - explanatory variable
* @param y - response variable
* @return - Object with further statistics.
*/
score(x, y) {
checkArrayLength(x, y);
const n = x.length;
const y2 = new Array(n);
for (let i = 0; i < n; i++) {
y2[i] = this._predict(x[i]);
}
let xSum = 0;
let ySum = 0;
let chi2 = 0;
let rmsd = 0;
let xSquared = 0;
let ySquared = 0;
let xY = 0;
for (let i = 0; i < n; i++) {
xSum += y2[i];
ySum += y[i];
xSquared += y2[i] * y2[i];
ySquared += y[i] * y[i];
xY += y2[i] * y[i];
if (y[i] !== 0) {
chi2 += ((y[i] - y2[i]) * (y[i] - y2[i])) / y[i];
}
rmsd += (y[i] - y2[i]) * (y[i] - y2[i]);
}
const r = (n * xY - xSum * ySum) /
Math.sqrt((n * xSquared - xSum * xSum) * (n * ySquared - ySum * ySum));
return {
r,
r2: r * r,
chi2,
rmsd: Math.sqrt(rmsd / n),
};
}
}
export { checkArrayLength };
export * from './BaseRegression';
export * from './checkArrayLength';
export * from './maybeToPrecision';
//# sourceMappingURL=index.js.map

@@ -7,3 +7,3 @@ /**

*/
export default function maybeToPrecision(number: number, figures?: number): string;
export declare function maybeToPrecision(number: number, figures?: number): string;
//# sourceMappingURL=maybeToPrecision.d.ts.map

@@ -7,3 +7,3 @@ /**

*/
export default function maybeToPrecision(number, figures) {
export function maybeToPrecision(number, figures) {
if (number < 0) {

@@ -10,0 +10,0 @@ number = 0 - number;

@@ -8,3 +8,3 @@ import { NumberArray } from 'cheminfo-types';

*/
export default function checkArrayLength(x: NumberArray, y: NumberArray): void;
export declare function checkArrayLength(x: NumberArray, y: NumberArray): void;
//# sourceMappingURL=checkArrayLength.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkArrayLength = void 0;
const is_any_array_1 = require("is-any-array");

@@ -18,3 +19,3 @@ /**

}
exports.default = checkArrayLength;
exports.checkArrayLength = checkArrayLength;
//# sourceMappingURL=checkArrayLength.js.map

@@ -1,27 +0,4 @@

import { type NumberArray } from 'cheminfo-types';
import checkArrayLength from './checkArrayLength';
export { default as maybeToPrecision } from './maybeToPrecision';
export interface RegressionScore {
r: number;
r2: number;
chi2: number;
rmsd: number;
}
export default class BaseRegression {
constructor();
predict(x: number): number;
predict(x: NumberArray): number[];
_predict(x: number): number;
train(): void;
toString(precision?: number): string;
toLaTeX(precision?: number): string;
/**
* Return the correlation coefficient of determination (r) and chi-square.
* @param x - explanatory variable
* @param y - response variable
* @return - Object with further statistics.
*/
score(x: NumberArray, y: NumberArray): RegressionScore;
}
export { checkArrayLength, type NumberArray };
export * from './BaseRegression';
export * from './checkArrayLength';
export * from './maybeToPrecision';
//# sourceMappingURL=index.d.ts.map
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkArrayLength = exports.maybeToPrecision = void 0;
const is_any_array_1 = require("is-any-array");
const checkArrayLength_1 = __importDefault(require("./checkArrayLength"));
exports.checkArrayLength = checkArrayLength_1.default;
var maybeToPrecision_1 = require("./maybeToPrecision");
Object.defineProperty(exports, "maybeToPrecision", { enumerable: true, get: function () { return __importDefault(maybeToPrecision_1).default; } });
class BaseRegression {
constructor() {
if (new.target === BaseRegression) {
throw new Error('BaseRegression must be subclassed');
}
}
predict(x) {
if (typeof x === 'number') {
return this._predict(x);
}
else if ((0, is_any_array_1.isAnyArray)(x)) {
const y = [];
for (const xVal of x) {
y.push(this._predict(xVal));
}
return y;
}
else {
throw new TypeError('x must be a number or array');
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_predict(x) {
throw new Error('_predict must be implemented');
}
train() {
// Do nothing for this package
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
toString(precision) {
return '';
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
toLaTeX(precision) {
return '';
}
/**
* Return the correlation coefficient of determination (r) and chi-square.
* @param x - explanatory variable
* @param y - response variable
* @return - Object with further statistics.
*/
score(x, y) {
(0, checkArrayLength_1.default)(x, y);
const n = x.length;
const y2 = new Array(n);
for (let i = 0; i < n; i++) {
y2[i] = this._predict(x[i]);
}
let xSum = 0;
let ySum = 0;
let chi2 = 0;
let rmsd = 0;
let xSquared = 0;
let ySquared = 0;
let xY = 0;
for (let i = 0; i < n; i++) {
xSum += y2[i];
ySum += y[i];
xSquared += y2[i] * y2[i];
ySquared += y[i] * y[i];
xY += y2[i] * y[i];
if (y[i] !== 0) {
chi2 += ((y[i] - y2[i]) * (y[i] - y2[i])) / y[i];
}
rmsd += (y[i] - y2[i]) * (y[i] - y2[i]);
}
const r = (n * xY - xSum * ySum) /
Math.sqrt((n * xSquared - xSum * xSum) * (n * ySquared - ySum * ySum));
return {
r,
r2: r * r,
chi2,
rmsd: Math.sqrt(rmsd / n),
};
}
}
exports.default = BaseRegression;
__exportStar(require("./BaseRegression"), exports);
__exportStar(require("./checkArrayLength"), exports);
__exportStar(require("./maybeToPrecision"), exports);
//# sourceMappingURL=index.js.map

@@ -7,3 +7,3 @@ /**

*/
export default function maybeToPrecision(number: number, figures?: number): string;
export declare function maybeToPrecision(number: number, figures?: number): string;
//# sourceMappingURL=maybeToPrecision.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.maybeToPrecision = void 0;
/**

@@ -26,3 +27,3 @@ * Cast `number` to string. Optionally `digits` specifies significant figures.

}
exports.default = maybeToPrecision;
exports.maybeToPrecision = maybeToPrecision;
//# sourceMappingURL=maybeToPrecision.js.map
{
"name": "ml-regression-base",
"version": "3.0.0",
"version": "4.0.0",
"description": "Base class for regression modules",

@@ -40,14 +40,14 @@ "main": "./lib/index.js",

"dependencies": {
"cheminfo-types": "^1.7.2",
"cheminfo-types": "^1.7.3",
"is-any-array": "^2.0.1"
},
"devDependencies": {
"@vitest/coverage-v8": "^0.34.1",
"@vitest/coverage-v8": "^1.6.0",
"eslint": "^8.46.0",
"eslint-config-cheminfo-typescript": "^12.0.4",
"prettier": "^3.0.1",
"rimraf": "^5.0.1",
"typescript": "^5.1.6",
"vitest": "^0.34.1"
"eslint-config-cheminfo-typescript": "^12.4.0",
"prettier": "^3.2.5",
"rimraf": "^5.0.7",
"typescript": "^5.4.5",
"vitest": "^1.6.0"
}
}
import { expect, it, describe } from 'vitest';
import checkArrayLength from '../checkArrayLength';
import { checkArrayLength } from '..';

@@ -5,0 +5,0 @@ describe('checkArrayLength', () => {

import { expect, it, describe } from 'vitest';
import maybeToPrecision from '../maybeToPrecision';
import { maybeToPrecision } from '..';

@@ -5,0 +5,0 @@ describe('maybeToPrecision', () => {

@@ -9,3 +9,3 @@ import { NumberArray } from 'cheminfo-types';

*/
export default function checkArrayLength(x: NumberArray, y: NumberArray) {
export function checkArrayLength(x: NumberArray, y: NumberArray) {
if (!isAnyArray(x) || !isAnyArray(y)) {

@@ -12,0 +12,0 @@ throw new TypeError('x and y must be arrays');

@@ -1,103 +0,3 @@

import { type NumberArray } from 'cheminfo-types';
import { isAnyArray } from 'is-any-array';
import checkArrayLength from './checkArrayLength';
export { default as maybeToPrecision } from './maybeToPrecision';
export interface RegressionScore {
r: number;
r2: number;
chi2: number;
rmsd: number;
}
export default class BaseRegression {
constructor() {
if (new.target === BaseRegression) {
throw new Error('BaseRegression must be subclassed');
}
}
predict(x: number): number;
predict(x: NumberArray): number[];
predict(x: number | NumberArray) {
if (typeof x === 'number') {
return this._predict(x);
} else if (isAnyArray(x)) {
const y = [];
for (const xVal of x) {
y.push(this._predict(xVal));
}
return y;
} else {
throw new TypeError('x must be a number or array');
}
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_predict(x: number): number {
throw new Error('_predict must be implemented');
}
train() {
// Do nothing for this package
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
toString(precision?: number) {
return '';
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
toLaTeX(precision?: number) {
return '';
}
/**
* Return the correlation coefficient of determination (r) and chi-square.
* @param x - explanatory variable
* @param y - response variable
* @return - Object with further statistics.
*/
score(x: NumberArray, y: NumberArray): RegressionScore {
checkArrayLength(x, y);
const n = x.length;
const y2 = new Array(n);
for (let i = 0; i < n; i++) {
y2[i] = this._predict(x[i]);
}
let xSum = 0;
let ySum = 0;
let chi2 = 0;
let rmsd = 0;
let xSquared = 0;
let ySquared = 0;
let xY = 0;
for (let i = 0; i < n; i++) {
xSum += y2[i];
ySum += y[i];
xSquared += y2[i] * y2[i];
ySquared += y[i] * y[i];
xY += y2[i] * y[i];
if (y[i] !== 0) {
chi2 += ((y[i] - y2[i]) * (y[i] - y2[i])) / y[i];
}
rmsd += (y[i] - y2[i]) * (y[i] - y2[i]);
}
const r =
(n * xY - xSum * ySum) /
Math.sqrt((n * xSquared - xSum * xSum) * (n * ySquared - ySum * ySum));
return {
r,
r2: r * r,
chi2,
rmsd: Math.sqrt(rmsd / n),
};
}
}
export { checkArrayLength, type NumberArray };
export * from './BaseRegression';
export * from './checkArrayLength';
export * from './maybeToPrecision';

@@ -7,3 +7,3 @@ /**

*/
export default function maybeToPrecision(number: number, figures?: number) {
export function maybeToPrecision(number: number, figures?: number) {
if (number < 0) {

@@ -10,0 +10,0 @@ number = 0 - number;

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

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

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