ml-savitzky-golay-generalized
Advanced tools
Comparing version 4.0.1 to 4.1.1
@@ -1,2 +0,2 @@ | ||
import { DoubleArray } from 'cheminfo-types'; | ||
import { NumberArray } from 'cheminfo-types'; | ||
export interface SGGOptions { | ||
@@ -22,3 +22,3 @@ /** | ||
*/ | ||
export declare function sgg(ys: DoubleArray, xs: DoubleArray | number, options?: SGGOptions): Float64Array; | ||
export declare function sgg(ys: NumberArray, xs: NumberArray | number, options?: SGGOptions): Float64Array; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -9,3 +9,3 @@ import { isAnyArray } from 'is-any-array'; | ||
export function sgg(ys, xs, options = {}) { | ||
let { windowSize = 9, derivative = 0, polynomial = 3 } = options; | ||
const { windowSize = 9, derivative = 0, polynomial = 3 } = options; | ||
if (windowSize % 2 === 0 || windowSize < 5 || !Number.isInteger(windowSize)) { | ||
@@ -34,6 +34,6 @@ throw new RangeError('Invalid window size (should be odd and at least 5 integer number)'); | ||
} | ||
let half = Math.floor(windowSize / 2); | ||
let np = ys.length; | ||
let ans = new Float64Array(np); | ||
let weights = fullWeights(windowSize, polynomial, derivative); | ||
const half = Math.floor(windowSize / 2); | ||
const np = ys.length; | ||
const ans = new Float64Array(np); | ||
const weights = fullWeights(windowSize, polynomial, derivative); | ||
let hs = 0; | ||
@@ -45,8 +45,8 @@ let constantH = true; | ||
else { | ||
hs = Math.pow(xs, derivative); | ||
hs = xs ** derivative; | ||
} | ||
//For the borders | ||
for (let i = 0; i < half; i++) { | ||
let wg1 = weights[half - i - 1]; | ||
let wg2 = weights[half + i + 1]; | ||
const wg1 = weights[half - i - 1]; | ||
const wg2 = weights[half + i + 1]; | ||
let d1 = 0; | ||
@@ -70,3 +70,3 @@ let d2 = 0; | ||
//For the internal points | ||
let wg = weights[half]; | ||
const wg = weights[half]; | ||
for (let i = windowSize; i <= np; i++) { | ||
@@ -92,3 +92,3 @@ let d = 0; | ||
} | ||
return Math.pow(hs / count, derivative); | ||
return (hs / count) ** derivative; | ||
} | ||
@@ -104,9 +104,7 @@ function gramPoly(i, m, k, s) { | ||
} | ||
else if (k === 0 && s === 0) { | ||
Grampoly = 1; | ||
} | ||
else { | ||
if (k === 0 && s === 0) { | ||
Grampoly = 1; | ||
} | ||
else { | ||
Grampoly = 0; | ||
} | ||
Grampoly = 0; | ||
} | ||
@@ -142,4 +140,4 @@ return Grampoly; | ||
function fullWeights(m, n, s) { | ||
let weights = new Array(m); | ||
let np = Math.floor(m / 2); | ||
const weights = new Array(m); | ||
const np = Math.floor(m / 2); | ||
for (let t = -np; t <= np; t++) { | ||
@@ -146,0 +144,0 @@ weights[t + np] = new Float64Array(m); |
@@ -1,2 +0,2 @@ | ||
import { DoubleArray } from 'cheminfo-types'; | ||
import { NumberArray } from 'cheminfo-types'; | ||
export interface SGGOptions { | ||
@@ -22,3 +22,3 @@ /** | ||
*/ | ||
export declare function sgg(ys: DoubleArray, xs: DoubleArray | number, options?: SGGOptions): Float64Array; | ||
export declare function sgg(ys: NumberArray, xs: NumberArray | number, options?: SGGOptions): Float64Array; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -12,3 +12,3 @@ "use strict"; | ||
function sgg(ys, xs, options = {}) { | ||
let { windowSize = 9, derivative = 0, polynomial = 3 } = options; | ||
const { windowSize = 9, derivative = 0, polynomial = 3 } = options; | ||
if (windowSize % 2 === 0 || windowSize < 5 || !Number.isInteger(windowSize)) { | ||
@@ -37,6 +37,6 @@ throw new RangeError('Invalid window size (should be odd and at least 5 integer number)'); | ||
} | ||
let half = Math.floor(windowSize / 2); | ||
let np = ys.length; | ||
let ans = new Float64Array(np); | ||
let weights = fullWeights(windowSize, polynomial, derivative); | ||
const half = Math.floor(windowSize / 2); | ||
const np = ys.length; | ||
const ans = new Float64Array(np); | ||
const weights = fullWeights(windowSize, polynomial, derivative); | ||
let hs = 0; | ||
@@ -48,8 +48,8 @@ let constantH = true; | ||
else { | ||
hs = Math.pow(xs, derivative); | ||
hs = xs ** derivative; | ||
} | ||
//For the borders | ||
for (let i = 0; i < half; i++) { | ||
let wg1 = weights[half - i - 1]; | ||
let wg2 = weights[half + i + 1]; | ||
const wg1 = weights[half - i - 1]; | ||
const wg2 = weights[half + i + 1]; | ||
let d1 = 0; | ||
@@ -73,3 +73,3 @@ let d2 = 0; | ||
//For the internal points | ||
let wg = weights[half]; | ||
const wg = weights[half]; | ||
for (let i = windowSize; i <= np; i++) { | ||
@@ -96,3 +96,3 @@ let d = 0; | ||
} | ||
return Math.pow(hs / count, derivative); | ||
return (hs / count) ** derivative; | ||
} | ||
@@ -108,9 +108,7 @@ function gramPoly(i, m, k, s) { | ||
} | ||
else if (k === 0 && s === 0) { | ||
Grampoly = 1; | ||
} | ||
else { | ||
if (k === 0 && s === 0) { | ||
Grampoly = 1; | ||
} | ||
else { | ||
Grampoly = 0; | ||
} | ||
Grampoly = 0; | ||
} | ||
@@ -146,4 +144,4 @@ return Grampoly; | ||
function fullWeights(m, n, s) { | ||
let weights = new Array(m); | ||
let np = Math.floor(m / 2); | ||
const weights = new Array(m); | ||
const np = Math.floor(m / 2); | ||
for (let t = -np; t <= np; t++) { | ||
@@ -150,0 +148,0 @@ weights[t + np] = new Float64Array(m); |
{ | ||
"name": "ml-savitzky-golay-generalized", | ||
"version": "4.0.1", | ||
"version": "4.1.1", | ||
"description": "Savitzky–Golay filter in Javascript", | ||
@@ -50,15 +50,15 @@ "main": "lib/index.js", | ||
"devDependencies": { | ||
"@types/jest": "^27.4.1", | ||
"@types/jest": "^29.5.12", | ||
"eslint": "^8.9.0", | ||
"eslint-config-cheminfo-typescript": "^10.3.0", | ||
"jest": "^27.5.1", | ||
"prettier": "^2.5.1", | ||
"rimraf": "^3.0.2", | ||
"ts-jest": "^27.1.3", | ||
"typescript": "^4.5.5" | ||
"eslint-config-cheminfo-typescript": "^12.3.0", | ||
"jest": "^29.7.0", | ||
"prettier": "^3.2.5", | ||
"rimraf": "^5.0.5", | ||
"ts-jest": "^29.1.2", | ||
"typescript": "^5.4.5" | ||
}, | ||
"dependencies": { | ||
"cheminfo-types": "^1.0.0", | ||
"is-any-array": "^2.0.0" | ||
"cheminfo-types": "^1.7.3", | ||
"is-any-array": "^2.0.1" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { DoubleArray } from 'cheminfo-types'; | ||
import { NumberArray } from 'cheminfo-types'; | ||
import { isAnyArray } from 'is-any-array'; | ||
@@ -27,7 +27,7 @@ | ||
export function sgg( | ||
ys: DoubleArray, | ||
xs: DoubleArray | number, | ||
ys: NumberArray, | ||
xs: NumberArray | number, | ||
options: SGGOptions = {}, | ||
): Float64Array { | ||
let { windowSize = 9, derivative = 0, polynomial = 3 } = options; | ||
const { windowSize = 9, derivative = 0, polynomial = 3 } = options; | ||
@@ -64,6 +64,6 @@ if (windowSize % 2 === 0 || windowSize < 5 || !Number.isInteger(windowSize)) { | ||
let half = Math.floor(windowSize / 2); | ||
let np = ys.length; | ||
let ans = new Float64Array(np); | ||
let weights = fullWeights(windowSize, polynomial, derivative); | ||
const half = Math.floor(windowSize / 2); | ||
const np = ys.length; | ||
const ans = new Float64Array(np); | ||
const weights = fullWeights(windowSize, polynomial, derivative); | ||
let hs = 0; | ||
@@ -74,3 +74,3 @@ let constantH = true; | ||
} else { | ||
hs = Math.pow(xs as number, derivative); | ||
hs = xs ** derivative; | ||
} | ||
@@ -80,4 +80,4 @@ | ||
for (let i = 0; i < half; i++) { | ||
let wg1 = weights[half - i - 1]; | ||
let wg2 = weights[half + i + 1]; | ||
const wg1 = weights[half - i - 1]; | ||
const wg2 = weights[half + i + 1]; | ||
let d1 = 0; | ||
@@ -93,5 +93,5 @@ let d2 = 0; | ||
} else { | ||
hs = getHs(xs as DoubleArray, half - i - 1, half, derivative); | ||
hs = getHs(xs as NumberArray, half - i - 1, half, derivative); | ||
ans[half - i - 1] = d1 / hs; | ||
hs = getHs(xs as DoubleArray, np - half + i, half, derivative); | ||
hs = getHs(xs as NumberArray, np - half + i, half, derivative); | ||
ans[np - half + i] = d2 / hs; | ||
@@ -102,3 +102,3 @@ } | ||
//For the internal points | ||
let wg = weights[half]; | ||
const wg = weights[half]; | ||
for (let i = windowSize; i <= np; i++) { | ||
@@ -108,3 +108,3 @@ let d = 0; | ||
if (!constantH) { | ||
hs = getHs(xs as DoubleArray, i - half - 1, half, derivative); | ||
hs = getHs(xs as NumberArray, i - half - 1, half, derivative); | ||
} | ||
@@ -117,3 +117,3 @@ ans[i - half - 1] = d / hs; | ||
function getHs( | ||
h: DoubleArray, | ||
h: NumberArray, | ||
center: number, | ||
@@ -131,3 +131,3 @@ half: number, | ||
} | ||
return Math.pow(hs / count, derivative); | ||
return (hs / count) ** derivative; | ||
} | ||
@@ -143,8 +143,6 @@ | ||
gramPoly(i, m, k - 2, s); | ||
} else if (k === 0 && s === 0) { | ||
Grampoly = 1; | ||
} else { | ||
if (k === 0 && s === 0) { | ||
Grampoly = 1; | ||
} else { | ||
Grampoly = 0; | ||
} | ||
Grampoly = 0; | ||
} | ||
@@ -182,5 +180,5 @@ return Grampoly; | ||
*/ | ||
function fullWeights(m: number, n: number, s: number): Array<Float64Array> { | ||
let weights = new Array(m); | ||
let np = Math.floor(m / 2); | ||
function fullWeights(m: number, n: number, s: number): Float64Array[] { | ||
const weights = new Array(m); | ||
const np = Math.floor(m / 2); | ||
for (let t = -np; t <= np; t++) { | ||
@@ -187,0 +185,0 @@ weights[t + np] = new Float64Array(m); |
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
32954
502
Updatedcheminfo-types@^1.7.3
Updatedis-any-array@^2.0.1