diff --git a/CHANGELOG.md b/CHANGELOG.md index b079981..0473eb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# [1.18.0](https://github.com/javascriptdata/scikit.js/compare/v1.17.0...v1.18.0) (2022-04-26) + + +### Features + +* removed seedrandom in favor of inlining to help build on esm.sh ([245d49c](https://github.com/javascriptdata/scikit.js/commit/245d49c904fea6ffab9201cab58c4504b6ddfe3a)) + # [1.17.0](https://github.com/javascriptdata/scikit.js/compare/v1.16.0...v1.17.0) (2022-04-21) diff --git a/package-lock.json b/package-lock.json index 3145c6f..9044d05 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "scikitjs", - "version": "1.17.0", + "version": "1.18.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "scikitjs", - "version": "1.17.0", + "version": "1.18.0", "hasInstallScript": true, "license": "ISC", "dependencies": { @@ -14,7 +14,6 @@ "@tensorflow/tfjs-node": "3.13.0", "lodash": "^4.17.21", "mathjs": "^10.0.0", - "seedrandom": "^3.0.5", "simple-statistics": "^7.7.0" }, "devDependencies": { diff --git a/package.json b/package.json index bb4ddc7..9157c46 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "scikitjs", - "version": "1.17.0", + "version": "1.18.0", "description": "Scikit-Learn for JS", "output": { "node": "dist/node/index.js", @@ -53,7 +53,6 @@ "@tensorflow/tfjs-node": "3.13.0", "lodash": "^4.17.21", "mathjs": "^10.0.0", - "seedrandom": "^3.0.5", "simple-statistics": "^7.7.0" }, "devDependencies": { diff --git a/src/model_selection/KFold.test.ts b/src/model_selection/KFold.test.ts index bb18ef1..625e0c0 100644 --- a/src/model_selection/KFold.test.ts +++ b/src/model_selection/KFold.test.ts @@ -15,7 +15,7 @@ import * as fc from 'fast-check' import { KFold } from './KFold' -import { alea } from 'seedrandom' +import { alea } from '../randUtils' import '../jestTensorMatchers' import { tf } from '../shared/globals' type Tensor2D = tf.Tensor2D diff --git a/src/neighbors/KdTree.ts b/src/neighbors/KdTree.ts index 9a8750d..2adefcd 100644 --- a/src/neighbors/KdTree.ts +++ b/src/neighbors/KdTree.ts @@ -17,7 +17,7 @@ import { assert } from '../typesUtils' import { tf } from '../shared/globals' import { Neighborhood, NeighborhoodParams } from './Neighborhood' import * as randUtils from '../randUtils' -import { alea } from 'seedrandom' +import { alea } from '../randUtils' import { CappedMaxHeap } from './CappedMaxHeap' const child = (parent: number) => (parent << 1) + 1 diff --git a/src/neighbors/neighborhoodGenericTests.ts b/src/neighbors/neighborhoodGenericTests.ts index ce33568..275c858 100644 --- a/src/neighbors/neighborhoodGenericTests.ts +++ b/src/neighbors/neighborhoodGenericTests.ts @@ -15,7 +15,7 @@ import * as fc from 'fast-check' import { tf } from '../shared/globals' -import { alea } from 'seedrandom' +import { alea } from '../randUtils' import { Neighborhood, NeighborhoodParams } from './Neighborhood' import { lhs, shuffle } from '../randUtils' import { minkowskiMetric } from './Metric' diff --git a/src/randUtils.ts b/src/randUtils.ts index 31b83fa..4b0aebf 100644 --- a/src/randUtils.ts +++ b/src/randUtils.ts @@ -12,8 +12,83 @@ * limitations under the License. * ========================================================================== */ +export function _prng_restore(prng: any, xg: any, opts: any) { + let state = opts && opts.state + if (state) { + if (typeof state == 'object') xg.copy(state, xg) + prng.state = () => xg.copy(xg, {}) + } +} + +export function alea(seed?: any, opts?: any) { + let xg = new AleaGen(seed) + + let prng = () => xg.next() + + _prng_restore(prng, xg, opts) + return prng +} + +class AleaGen { + c: number + s0: number + s1: number + s2: number + constructor(seed: any) { + if (seed == null) seed = +new Date() + + let n = 0xefc8249d -import { alea } from 'seedrandom' + // Apply the seeding algorithm from Baagoe. + this.c = 1 + this.s0 = mash(' ') + this.s1 = mash(' ') + this.s2 = mash(' ') + this.s0 -= mash(seed) + if (this.s0 < 0) { + this.s0 += 1 + } + this.s1 -= mash(seed) + if (this.s1 < 0) { + this.s1 += 1 + } + this.s2 -= mash(seed) + if (this.s2 < 0) { + this.s2 += 1 + } + + function mash(data: any) { + data = String(data) + for (let i = 0; i < data.length; i++) { + n += data.charCodeAt(i) + let h = 0.02519603282416938 * n + n = h >>> 0 + h -= n + h *= n + n = h >>> 0 + h -= n + n += h * 0x100000000 // 2^32 + } + return (n >>> 0) * 2.3283064365386963e-10 // 2^-32 + } + } + + next() { + let { c, s0, s1, s2 } = this + let t = 2091639 * s0 + c * 2.3283064365386963e-10 // 2^-32 + this.s0 = s1 + this.s1 = s2 + return (this.s2 = t - (this.c = t | 0)) + } + + copy(f: any, t: any) { + t.c = f.c + t.s0 = f.s0 + t.s1 = f.s1 + t.s2 = f.s2 + return t + } +} export type int = number
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: