Skip to content

Commit

Permalink
chore!: update dependencies and remove default export
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed May 16, 2024
1 parent 55bd163 commit 61007d5
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 41 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
extends: cheminfo
parserOptions:
sourceType: module
env:
jest: true
20 changes: 20 additions & 0 deletions .github/workflows/documentationjs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Deploy documentation.js on GitHub pages

on:
release:
types: [published]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build documentation
uses: zakodium/documentationjs-action@v1
- name: Deploy to GitHub pages
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
GITHUB_TOKEN: ${{ secrets.BOT_TOKEN }}
BRANCH: gh-pages
FOLDER: docs
CLEAN: true
12 changes: 12 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Node.js CI

on:
push:
branches:
- main
pull_request:

jobs:
nodejs:
# Documentation: https://github.com/zakodium/workflows#nodejs-ci
uses: zakodium/workflows/.github/workflows/nodejs.yml@nodejs-v1
16 changes: 16 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Release

on:
push:
branches:
- main

jobs:
release:
# Documentation: https://github.com/zakodium/workflows#release
uses: zakodium/workflows/.github/workflows/release.yml@release-v1
with:
npm: true
secrets:
github-token: ${{ secrets.BOT_TOKEN }}
npm-token: ${{ secrets.NPM_BOT_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ jspm_packages
.node_repl_history

lib
docs
.DS_Store
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"arrowParens": "always",
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all"
}
File renamed without changes.
27 changes: 13 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
"compile": "rollup -c",
"eslint": "eslint src",
"eslint-fix": "npm run eslint -- --fix",
"prepublishOnly": "npm run compile",
"test": "npm run test-coverage && npm run eslint",
"prepack": "npm run compile",
"prettier": "prettier --check src",
"prettier-write": "prettier --write src",
"test": "npm run test-coverage && npm run eslint && npm run prettier",
"test-only": "jest",
"test-coverage": "jest --coverage"
},
Expand All @@ -28,20 +30,17 @@
"url": "https://github.com/mljs/regression-theil-sen/issues"
},
"homepage": "https://github.com/mljs/regression-theil-sen#readme",
"jest": {
"testEnvironment": "node"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.4.4",
"eslint": "^6.0.1",
"eslint-config-cheminfo": "^1.20.1",
"eslint-plugin-import": "^2.18.0",
"eslint-plugin-jest": "^22.7.1",
"jest": "^24.8.0",
"rollup": "^1.16.3"
"@babel/plugin-transform-modules-commonjs": "^7.24.1",
"@types/jest": "^29.5.12",
"eslint": "^8.57.0",
"eslint-config-cheminfo": "^9.2.0",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"rollup": "^4.17.2"
},
"dependencies": {
"ml-array-median": "^1.1.1",
"ml-regression-base": "^2.0.1"
"ml-array-median": "^1.1.6",
"ml-regression-base": "^4.0.0"
}
}
File renamed without changes.
32 changes: 16 additions & 16 deletions src/__tests__/test.js → src/__tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import TheilSenRegression from '..';
import { TheilSenRegression } from '..';

describe('Theil-Sen regression', () => {
it('Simple case', () => {
var inputs = [1, 2, 3, 4, 5];
var outputs = [2, 3, 4, 5, 6];
let inputs = [1, 2, 3, 4, 5];
let outputs = [2, 3, 4, 5, 6];

var regression = new TheilSenRegression(inputs, outputs);
let regression = new TheilSenRegression(inputs, outputs);

expect(regression.coefficients).toHaveLength(2);
expect(regression.slope).toBe(regression.coefficients[1]);
Expand All @@ -14,7 +14,7 @@ describe('Theil-Sen regression', () => {
expect(regression.slope).toBeCloseTo(1, 5);
expect(regression.intercept).toBeCloseTo(1, 5);

var y = regression.predict(85);
let y = regression.predict(85);
expect(regression.computeX(y)).toBeCloseTo(85, 5);
expect(y).toBeCloseTo(86, 5);

Expand All @@ -25,49 +25,49 @@ describe('Theil-Sen regression', () => {

it('Outlier', () => {
// outlier in the 4th value
var inputs = [1, 2, 3, 4, 10, 12, 18];
var outputs = [10, 14, 180, 22, 46, 54, 78];
let inputs = [1, 2, 3, 4, 10, 12, 18];
let outputs = [10, 14, 180, 22, 46, 54, 78];

var regression = new TheilSenRegression(inputs, outputs);
let regression = new TheilSenRegression(inputs, outputs);

expect(regression.slope).toBeCloseTo(4, 3);
expect(regression.intercept).toBeCloseTo(6, 3);
});

it('Constant', () => {
var inputs = [0, 1, 2, 3];
var outputs = [2, 2, 2, 2];
let inputs = [0, 1, 2, 3];
let outputs = [2, 2, 2, 2];

var regression = new TheilSenRegression(inputs, outputs);
let regression = new TheilSenRegression(inputs, outputs);

expect(regression.toString()).toStrictEqual('f(x) = 2');
expect(regression.toString(1)).toStrictEqual('f(x) = 2');
expect(regression.toString(5)).toStrictEqual('f(x) = 2.0000');
});

it('Load and export model', () => {
var regression = TheilSenRegression.load({
let regression = TheilSenRegression.load({
name: 'TheilSenRegression',
slope: -1,
intercept: 0,
quality: {
r: 1,
r2: 1,
chi2: 145.8,
rmsd: 0
}
rmsd: 0,
},
});
expect(regression.slope).toBe(-1);
expect(regression.intercept).toBe(0);
expect(regression.toString()).toStrictEqual('f(x) = - 1 * x');

var model = regression.toJSON();
let model = regression.toJSON();
expect(model.name).toStrictEqual('TheilSenRegression');
expect(model.slope).toBe(-1);
expect(model.intercept).toBe(0);

expect(() => TheilSenRegression.load({ name: 1 })).toThrow(
'not a Theil-Sen model'
'not a Theil-Sen model',
);
});
});
22 changes: 11 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import BaseRegression, {
import median from 'ml-array-median';
import {
BaseRegression,
checkArrayLength,
maybeToPrecision
maybeToPrecision,
} from 'ml-regression-base';
import median from 'ml-array-median';

export default class TheilSenRegression extends BaseRegression {
export class TheilSenRegression extends BaseRegression {
/**
* Theil–Sen estimator
* https://en.wikipedia.org/wiki/Theil%E2%80%93Sen_estimator
Expand All @@ -30,7 +31,7 @@ export default class TheilSenRegression extends BaseRegression {
return {
name: 'TheilSenRegression',
slope: this.slope,
intercept: this.intercept
intercept: this.intercept,
};
}

Expand All @@ -43,15 +44,14 @@ export default class TheilSenRegression extends BaseRegression {
}

toString(precision) {
var result = 'f(x) = ';
let result = 'f(x) = ';
if (this.slope) {
var xFactor = maybeToPrecision(this.slope, precision);
let xFactor = maybeToPrecision(this.slope, precision);
result += `${Math.abs(xFactor - 1) < 1e-5 ? '' : `${xFactor} * `}x`;
if (this.intercept) {
var absIntercept = Math.abs(this.intercept);
var operator = absIntercept === this.intercept ? '+' : '-';
result +=
` ${operator} ${maybeToPrecision(absIntercept, precision)}`;
let absIntercept = Math.abs(this.intercept);
let operator = absIntercept === this.intercept ? '+' : '-';
result += ` ${operator} ${maybeToPrecision(absIntercept, precision)}`;
}
} else {
result += maybeToPrecision(this.intercept, precision);
Expand Down

0 comments on commit 61007d5

Please sign in to comment.