ml-spectra-fitting
Advanced tools
Comparing version 4.2.1 to 4.2.2
@@ -1,2 +0,2 @@ | ||
import { DataXY, DoubleArray } from 'cheminfo-types'; | ||
import { DataXY } from 'cheminfo-types'; | ||
import { Shape1D } from 'ml-peak-shape-generator'; | ||
@@ -99,5 +99,5 @@ export interface InitialParameter { | ||
*/ | ||
export declare function optimize<T extends Peak>(data: DataXY<DoubleArray>, peaks: T[], options?: OptimizeOptions): { | ||
export declare function optimize<T extends Peak>(data: DataXY, peaks: T[], options?: OptimizeOptions): { | ||
error: number; | ||
peaks: OptimizedPeakIDOrNot<T>[]; | ||
peaks: Array<OptimizedPeakIDOrNot<T>>; | ||
iterations: number; | ||
@@ -104,0 +104,0 @@ }; |
@@ -15,3 +15,3 @@ import { xMinMaxValues } from 'ml-spectra-processing'; | ||
// rescale data | ||
let temp = xMinMaxValues(data.y); | ||
const temp = xMinMaxValues(data.y); | ||
const minMaxY = { ...temp, range: temp.max - temp.min }; | ||
@@ -21,3 +21,3 @@ const internalPeaks = getInternalPeaks(peaks, minMaxY, options); | ||
const { baseline: shiftValue = minMaxY.min } = options; | ||
let normalizedY = new Float64Array(data.y.length); | ||
const normalizedY = new Float64Array(data.y.length); | ||
for (let i = 0; i < data.y.length; i++) { | ||
@@ -41,5 +41,5 @@ normalizedY[i] = (data.y[i] - shiftValue) / minMaxY.range; | ||
} | ||
let { algorithm, optimizationOptions } = selectMethod(options.optimization); | ||
let sumOfShapes = getSumOfShapes(internalPeaks); | ||
let fitted = algorithm({ x: data.x, y: normalizedY }, sumOfShapes, { | ||
const { algorithm, optimizationOptions } = selectMethod(options.optimization); | ||
const sumOfShapes = getSumOfShapes(internalPeaks); | ||
const fitted = algorithm({ x: data.x, y: normalizedY }, sumOfShapes, { | ||
minValues, | ||
@@ -52,4 +52,4 @@ maxValues, | ||
const fittedValues = fitted.parameterValues; | ||
let newPeaks = []; | ||
for (let peak of internalPeaks) { | ||
const newPeaks = []; | ||
for (const peak of internalPeaks) { | ||
const { id, shape, parameters, fromIndex } = peak; | ||
@@ -56,0 +56,0 @@ let newPeak = { x: 0, y: 0, shape }; |
@@ -13,3 +13,3 @@ import { getShape1D } from 'ml-peak-shape-generator'; | ||
let index = 0; | ||
let internalPeaks = []; | ||
const internalPeaks = []; | ||
const { baseline: shiftValue = minMaxY.min } = options; | ||
@@ -32,4 +32,4 @@ const normalizedPeaks = peaks.map((peak) => { | ||
}; | ||
for (let parameter of parameters) { | ||
for (let property of properties) { | ||
for (const parameter of parameters) { | ||
for (const property of properties) { | ||
// check if the property is specified in the peak | ||
@@ -36,0 +36,0 @@ let propertyValue = peak?.parameters?.[parameter]?.[property]; |
@@ -8,3 +8,3 @@ import { levenbergMarquardt } from 'ml-levenberg-marquardt'; | ||
export function selectMethod(optimizationOptions = {}) { | ||
let { kind = 'lm', options } = optimizationOptions; | ||
const { kind = 'lm', options } = optimizationOptions; | ||
switch (kind) { | ||
@@ -11,0 +11,0 @@ case 'lm': |
@@ -26,3 +26,3 @@ import direct from 'ml-direct'; | ||
for (let i = 0; i < nbPoints; i++) { | ||
error += Math.pow(y[i] - fct(x[i]), 2); | ||
error += (y[i] - fct(x[i])) ** 2; | ||
} | ||
@@ -29,0 +29,0 @@ return error; |
@@ -1,2 +0,2 @@ | ||
import { DataXY, DoubleArray } from 'cheminfo-types'; | ||
import { DataXY } from 'cheminfo-types'; | ||
import { Shape1D } from 'ml-peak-shape-generator'; | ||
@@ -99,5 +99,5 @@ export interface InitialParameter { | ||
*/ | ||
export declare function optimize<T extends Peak>(data: DataXY<DoubleArray>, peaks: T[], options?: OptimizeOptions): { | ||
export declare function optimize<T extends Peak>(data: DataXY, peaks: T[], options?: OptimizeOptions): { | ||
error: number; | ||
peaks: OptimizedPeakIDOrNot<T>[]; | ||
peaks: Array<OptimizedPeakIDOrNot<T>>; | ||
iterations: number; | ||
@@ -104,0 +104,0 @@ }; |
@@ -18,3 +18,3 @@ "use strict"; | ||
// rescale data | ||
let temp = (0, ml_spectra_processing_1.xMinMaxValues)(data.y); | ||
const temp = (0, ml_spectra_processing_1.xMinMaxValues)(data.y); | ||
const minMaxY = { ...temp, range: temp.max - temp.min }; | ||
@@ -24,3 +24,3 @@ const internalPeaks = (0, getInternalPeaks_1.getInternalPeaks)(peaks, minMaxY, options); | ||
const { baseline: shiftValue = minMaxY.min } = options; | ||
let normalizedY = new Float64Array(data.y.length); | ||
const normalizedY = new Float64Array(data.y.length); | ||
for (let i = 0; i < data.y.length; i++) { | ||
@@ -44,5 +44,5 @@ normalizedY[i] = (data.y[i] - shiftValue) / minMaxY.range; | ||
} | ||
let { algorithm, optimizationOptions } = (0, selectMethod_1.selectMethod)(options.optimization); | ||
let sumOfShapes = (0, getSumOfShapes_1.getSumOfShapes)(internalPeaks); | ||
let fitted = algorithm({ x: data.x, y: normalizedY }, sumOfShapes, { | ||
const { algorithm, optimizationOptions } = (0, selectMethod_1.selectMethod)(options.optimization); | ||
const sumOfShapes = (0, getSumOfShapes_1.getSumOfShapes)(internalPeaks); | ||
const fitted = algorithm({ x: data.x, y: normalizedY }, sumOfShapes, { | ||
minValues, | ||
@@ -55,4 +55,4 @@ maxValues, | ||
const fittedValues = fitted.parameterValues; | ||
let newPeaks = []; | ||
for (let peak of internalPeaks) { | ||
const newPeaks = []; | ||
for (const peak of internalPeaks) { | ||
const { id, shape, parameters, fromIndex } = peak; | ||
@@ -59,0 +59,0 @@ let newPeak = { x: 0, y: 0, shape }; |
@@ -16,3 +16,3 @@ "use strict"; | ||
let index = 0; | ||
let internalPeaks = []; | ||
const internalPeaks = []; | ||
const { baseline: shiftValue = minMaxY.min } = options; | ||
@@ -35,4 +35,4 @@ const normalizedPeaks = peaks.map((peak) => { | ||
}; | ||
for (let parameter of parameters) { | ||
for (let property of properties) { | ||
for (const parameter of parameters) { | ||
for (const property of properties) { | ||
// check if the property is specified in the peak | ||
@@ -39,0 +39,0 @@ let propertyValue = peak?.parameters?.[parameter]?.[property]; |
@@ -11,3 +11,3 @@ "use strict"; | ||
function selectMethod(optimizationOptions = {}) { | ||
let { kind = 'lm', options } = optimizationOptions; | ||
const { kind = 'lm', options } = optimizationOptions; | ||
switch (kind) { | ||
@@ -14,0 +14,0 @@ case 'lm': |
@@ -33,3 +33,3 @@ "use strict"; | ||
for (let i = 0; i < nbPoints; i++) { | ||
error += Math.pow(y[i] - fct(x[i]), 2); | ||
error += (y[i] - fct(x[i])) ** 2; | ||
} | ||
@@ -36,0 +36,0 @@ return error; |
{ | ||
"name": "ml-spectra-fitting", | ||
"version": "4.2.1", | ||
"version": "4.2.2", | ||
"description": "Fit spectra using gaussian or lorentzian", | ||
@@ -49,22 +49,22 @@ "main": "./lib/index.js", | ||
"devDependencies": { | ||
"@babel/plugin-transform-modules-commonjs": "^7.21.2", | ||
"@babel/preset-typescript": "^7.21.0", | ||
"@types/jest": "^29.5.0", | ||
"@babel/plugin-transform-modules-commonjs": "^7.23.3", | ||
"@babel/preset-typescript": "^7.23.3", | ||
"@types/jest": "^29.5.12", | ||
"cheminfo-build": "^1.2.0", | ||
"eslint": "^8.36.0", | ||
"eslint-config-cheminfo-typescript": "^11.3.1", | ||
"jest": "^29.5.0", | ||
"eslint": "^8.57.0", | ||
"eslint-config-cheminfo-typescript": "^12.2.0", | ||
"jest": "^29.7.0", | ||
"jest-matcher-deep-close-to": "^3.0.2", | ||
"prettier": "^2.8.7", | ||
"spectrum-generator": "^8.0.6", | ||
"typescript": "^5.0.2" | ||
"prettier": "^3.2.5", | ||
"spectrum-generator": "^8.0.9", | ||
"typescript": "^5.3.3" | ||
}, | ||
"dependencies": { | ||
"cheminfo-types": "^1.4.0", | ||
"cheminfo-types": "^1.7.2", | ||
"ml-array-max": "^1.2.4", | ||
"ml-direct": "^0.1.1", | ||
"ml-levenberg-marquardt": "^4.1.0", | ||
"ml-direct": "^0.1.3", | ||
"ml-levenberg-marquardt": "^4.1.3", | ||
"ml-peak-shape-generator": "^4.1.2", | ||
"ml-spectra-processing": "^12.0.0" | ||
"ml-spectra-processing": "^14.0.0" | ||
} | ||
} |
@@ -24,3 +24,3 @@ import type { DataXY } from 'cheminfo-types'; | ||
let result = optimize( | ||
const result = optimize( | ||
data, | ||
@@ -27,0 +27,0 @@ [ |
@@ -11,3 +11,3 @@ import type { DataXY } from 'cheminfo-types'; | ||
it('2 peaks', () => { | ||
let peaks = [ | ||
const peaks = [ | ||
{ | ||
@@ -32,3 +32,3 @@ x: -0.5, | ||
let result = optimize( | ||
const result = optimize( | ||
data, | ||
@@ -62,3 +62,3 @@ [ | ||
it('2 peaks same position', () => { | ||
let peaks = [ | ||
const peaks = [ | ||
{ | ||
@@ -82,3 +82,3 @@ x: 0, | ||
let result = optimize(data, [ | ||
const result = optimize(data, [ | ||
{ | ||
@@ -103,3 +103,3 @@ x: -0.1, | ||
const nbPeaks = 5; | ||
let peaks = []; | ||
const peaks = []; | ||
for (let i = 0; i < nbPeaks; i++) { | ||
@@ -120,6 +120,6 @@ peaks.push({ | ||
let guess = JSON.parse(JSON.stringify(peaks)); | ||
const guess = JSON.parse(JSON.stringify(peaks)); | ||
guess.forEach((peak: any) => (peak.x += Math.random() / 10)); | ||
let result = optimize(data, guess, { | ||
const result = optimize(data, guess, { | ||
optimization: { options: { maxIterations: 10 } }, | ||
@@ -135,3 +135,3 @@ }); | ||
it('6 peaks', () => { | ||
let peaks = [ | ||
const peaks = [ | ||
{ | ||
@@ -169,3 +169,3 @@ x: 0, | ||
let result = optimize( | ||
const result = optimize( | ||
data, | ||
@@ -172,0 +172,0 @@ [ |
@@ -9,5 +9,5 @@ import type { DataXY } from 'cheminfo-types'; | ||
let nbPoints = 31; | ||
let xFactor = 0.1; | ||
let x = new Float64Array(nbPoints); | ||
const nbPoints = 31; | ||
const xFactor = 0.1; | ||
const x = new Float64Array(nbPoints); | ||
for (let i = 0; i < nbPoints; i++) { | ||
@@ -35,3 +35,3 @@ x[i] = (i - nbPoints / 2) * xFactor; | ||
let result = optimize(data, [ | ||
const result = optimize(data, [ | ||
{ | ||
@@ -47,3 +47,3 @@ x: -0.52, | ||
it('Lorentzian', () => { | ||
let peaks = [ | ||
const peaks = [ | ||
{ | ||
@@ -69,3 +69,3 @@ x: -0.5, | ||
let result = optimize(data, [ | ||
const result = optimize(data, [ | ||
{ | ||
@@ -82,3 +82,3 @@ x: -0.52, | ||
it('Pseudo Voigt', () => { | ||
let peaks = [ | ||
const peaks = [ | ||
{ | ||
@@ -99,3 +99,3 @@ x: 0, | ||
let result = optimize(data, [ | ||
const result = optimize(data, [ | ||
{ | ||
@@ -102,0 +102,0 @@ x: 0.001, |
@@ -35,3 +35,3 @@ import type { DataXY } from 'cheminfo-types'; | ||
let result = optimize(data, [ | ||
const result = optimize(data, [ | ||
{ | ||
@@ -70,3 +70,3 @@ id: 'first', | ||
let result = optimize(data, [ | ||
const result = optimize(data, [ | ||
{ x: -0.52, y: 0.9, shape: { kind: 'gaussian', fwhm: 0.2 } }, | ||
@@ -96,3 +96,3 @@ { x: 0.52, y: 0.9, shape: { kind: 'lorentzian', fwhm: 0.6 } }, | ||
let result = optimize( | ||
const result = optimize( | ||
data, | ||
@@ -131,3 +131,3 @@ [ | ||
let result = optimize( | ||
const result = optimize( | ||
data, | ||
@@ -134,0 +134,0 @@ [ |
@@ -9,5 +9,5 @@ import type { DataXY } from 'cheminfo-types'; | ||
let nbPoints = 31; | ||
let xFactor = 0.1; | ||
let x = new Float64Array(nbPoints); | ||
const nbPoints = 31; | ||
const xFactor = 0.1; | ||
const x = new Float64Array(nbPoints); | ||
for (let i = 0; i < nbPoints; i++) { | ||
@@ -35,3 +35,3 @@ x[i] = (i - nbPoints / 2) * xFactor; | ||
it('positive maxima peaks', () => { | ||
let initialPeaks: Peak[] = [ | ||
const initialPeaks: Peak[] = [ | ||
{ | ||
@@ -48,3 +48,3 @@ x: -0.52, | ||
]; | ||
let result = optimize(data, initialPeaks); | ||
const result = optimize(data, initialPeaks); | ||
for (let i = 0; i < 2; i++) { | ||
@@ -56,12 +56,11 @@ expect(result.peaks[i]).toMatchCloseTo(peaks[i], 3); | ||
it('shifted baseline up by two', () => { | ||
let shiftedPeaks = JSON.parse(JSON.stringify(peaks)); | ||
const shiftedPeaks = JSON.parse(JSON.stringify(peaks)); | ||
for (const shiftedPeak of shiftedPeaks) { | ||
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands | ||
shiftedPeak.y = shiftedPeak.y + 2; | ||
} | ||
let yShiftedData = { | ||
const yShiftedData = { | ||
x: data.x, | ||
y: data.y.map((el: number) => el + 2), | ||
}; | ||
let result = optimize(yShiftedData, [ | ||
const result = optimize(yShiftedData, [ | ||
{ | ||
@@ -84,7 +83,7 @@ x: -0.52, | ||
it('negative maxima peaks', () => { | ||
let shiftedPeaks = JSON.parse(JSON.stringify(peaks)); | ||
const shiftedPeaks = JSON.parse(JSON.stringify(peaks)); | ||
for (const shiftedPeak of shiftedPeaks) { | ||
shiftedPeak.y = shiftedPeak.y - 2; | ||
} | ||
let yShiftedPeaks = [ | ||
const yShiftedPeaks = [ | ||
{ | ||
@@ -102,3 +101,3 @@ x: -0.52, | ||
let yShiftedData = { | ||
const yShiftedData = { | ||
x: data.x.slice(), | ||
@@ -108,3 +107,3 @@ y: data.y.map((el: number) => el - 2), | ||
let result = optimize(yShiftedData, yShiftedPeaks); | ||
const result = optimize(yShiftedData, yShiftedPeaks); | ||
for (let i = 0; i < 2; i++) { | ||
@@ -134,3 +133,3 @@ expect(result.peaks[i]).toMatchCloseTo(shiftedPeaks[i], 3); | ||
it('positive maxima peaks', () => { | ||
let peakList: Peak[] = [ | ||
const peakList: Peak[] = [ | ||
{ | ||
@@ -147,3 +146,3 @@ x: -0.52, | ||
]; | ||
let result = optimize(data, peakList); | ||
const result = optimize(data, peakList); | ||
for (let i = 0; i < 2; i++) { | ||
@@ -155,3 +154,3 @@ expect(result.peaks[i]).toMatchCloseTo(peaks[i], 3); | ||
it('negative maxima peaks', () => { | ||
let shiftedPeaks = JSON.parse(JSON.stringify(peaks)); | ||
const shiftedPeaks = JSON.parse(JSON.stringify(peaks)); | ||
for (const shiftedPeak of shiftedPeaks) { | ||
@@ -161,3 +160,3 @@ shiftedPeak.y = shiftedPeak.y - 2; | ||
let yShiftedData = { | ||
const yShiftedData = { | ||
x: data.x.slice(), | ||
@@ -167,3 +166,3 @@ y: data.y.map((el: number) => el - 2), | ||
let result = optimize( | ||
const result = optimize( | ||
yShiftedData, | ||
@@ -231,3 +230,3 @@ [ | ||
it('positive maxima peaks', () => { | ||
let peakList: Peak[] = [ | ||
const peakList: Peak[] = [ | ||
{ | ||
@@ -252,3 +251,3 @@ x: -0.3, | ||
]; | ||
let result = optimize(data, peakList, { | ||
const result = optimize(data, peakList, { | ||
optimization: { | ||
@@ -255,0 +254,0 @@ kind: 'lm', |
@@ -1,2 +0,2 @@ | ||
import { DataXY, DoubleArray } from 'cheminfo-types'; | ||
import { DataXY } from 'cheminfo-types'; | ||
import { Shape1D } from 'ml-peak-shape-generator'; | ||
@@ -112,3 +112,3 @@ import { xMinMaxValues } from 'ml-spectra-processing'; | ||
export function optimize<T extends Peak>( | ||
data: DataXY<DoubleArray>, | ||
data: DataXY, | ||
peaks: T[], | ||
@@ -118,7 +118,7 @@ options: OptimizeOptions = {}, | ||
error: number; | ||
peaks: OptimizedPeakIDOrNot<T>[]; | ||
peaks: Array<OptimizedPeakIDOrNot<T>>; | ||
iterations: number; | ||
} { | ||
// rescale data | ||
let temp = xMinMaxValues(data.y); | ||
const temp = xMinMaxValues(data.y); | ||
const minMaxY = { ...temp, range: temp.max - temp.min }; | ||
@@ -130,3 +130,3 @@ | ||
const { baseline: shiftValue = minMaxY.min } = options; | ||
let normalizedY = new Float64Array(data.y.length); | ||
const normalizedY = new Float64Array(data.y.length); | ||
for (let i = 0; i < data.y.length; i++) { | ||
@@ -151,7 +151,7 @@ normalizedY[i] = (data.y[i] - shiftValue) / minMaxY.range; | ||
} | ||
let { algorithm, optimizationOptions } = selectMethod(options.optimization); | ||
const { algorithm, optimizationOptions } = selectMethod(options.optimization); | ||
let sumOfShapes = getSumOfShapes(internalPeaks); | ||
const sumOfShapes = getSumOfShapes(internalPeaks); | ||
let fitted = algorithm({ x: data.x, y: normalizedY }, sumOfShapes, { | ||
const fitted = algorithm({ x: data.x, y: normalizedY }, sumOfShapes, { | ||
minValues, | ||
@@ -165,4 +165,4 @@ maxValues, | ||
let newPeaks = []; | ||
for (let peak of internalPeaks) { | ||
const newPeaks = []; | ||
for (const peak of internalPeaks) { | ||
const { id, shape, parameters, fromIndex } = peak; | ||
@@ -169,0 +169,0 @@ |
@@ -34,3 +34,3 @@ import { getShape1D, Shape1D, Shape1DInstance } from 'ml-peak-shape-generator'; | ||
let index = 0; | ||
let internalPeaks: InternalPeak[] = []; | ||
const internalPeaks: InternalPeak[] = []; | ||
const { baseline: shiftValue = minMaxY.min } = options; | ||
@@ -60,4 +60,4 @@ | ||
for (let parameter of parameters) { | ||
for (let property of properties) { | ||
for (const parameter of parameters) { | ||
for (const property of properties) { | ||
// check if the property is specified in the peak | ||
@@ -64,0 +64,0 @@ let propertyValue = peak?.parameters?.[parameter]?.[property]; |
@@ -12,3 +12,3 @@ import { levenbergMarquardt } from 'ml-levenberg-marquardt'; | ||
export function selectMethod(optimizationOptions: OptimizationOptions = {}) { | ||
let { kind = 'lm', options } = optimizationOptions; | ||
const { kind = 'lm', options } = optimizationOptions; | ||
@@ -15,0 +15,0 @@ switch (kind) { |
@@ -46,3 +46,3 @@ import { DataXY } from 'cheminfo-types'; | ||
for (let i = 0; i < nbPoints; i++) { | ||
error += Math.pow(y[i] - fct(x[i]), 2); | ||
error += (y[i] - fct(x[i])) ** 2; | ||
} | ||
@@ -49,0 +49,0 @@ return error; |
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
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
118383
2370
+ Addedml-spectra-processing@14.9.1(transitive)
+ Addedml-xsadd@3.0.1(transitive)
Updatedcheminfo-types@^1.7.2
Updatedml-direct@^0.1.3