Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ml-spectra-fitting

Package Overview
Dependencies
Maintainers
4
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ml-spectra-fitting - npm Package Compare versions

Comparing version 0.3.2 to 0.5.0

17

CHANGELOG.md
# Changelog
## [0.5.0](https://www.github.com/mljs/spectra-fitting/compare/v0.4.0...v0.5.0) (2020-11-06)
### Features
* optimize gaussian, lorentzian or pseudovoight ([a756ff7](https://www.github.com/mljs/spectra-fitting/commit/a756ff72a25661a6778ce4908b176c4bf8df5b63))
* OptimizeLorentzianTrain and OptimizeGaussianTrain ([1650873](https://www.github.com/mljs/spectra-fitting/commit/165087356a10a1dce453a29b94700e07735b9f40))
* update peak-shape-generator ([a76be80](https://www.github.com/mljs/spectra-fitting/commit/a76be80094b0599c78383b8469cb56b986b75bea))
### Bug Fixes
* add missing build script ([42e4ce3](https://www.github.com/mljs/spectra-fitting/commit/42e4ce3ced85258933164de586ceb238101a2353))
* boundaries array bug ([#13](https://www.github.com/mljs/spectra-fitting/issues/13)) ([6c822e1](https://www.github.com/mljs/spectra-fitting/commit/6c822e14f25c5b091890cee750f34f7dd45bf136))
* remove docs ([a625ee6](https://www.github.com/mljs/spectra-fitting/commit/a625ee645ca09bc923141238d24415650c844f09))
* update dependencies to fix web compatibility ([2113eef](https://www.github.com/mljs/spectra-fitting/commit/2113eef2079032ea27fcd7ecf0388625d36687cb))
### [0.3.2](https://www.github.com/mljs/spectra-fitting/compare/v0.3.1...v0.3.2) (2020-11-04)

@@ -4,0 +21,0 @@

45

lib/index.js

@@ -27,9 +27,9 @@ 'use strict';

for (let i = 0; i < nL; i++) {
let func = mlPeakShapeGenerator.pseudovoigtFct({
x: p[i],
y: p[i + nL],
width: p[i + nL * 2],
mu: p[i + nL * 3],
});
result += func(t);
result += mlPeakShapeGenerator.pseudovoigtFct(
p[i],
p[i + nL],
p[i + nL * 2],
p[i + nL * 3],
t,
);
}

@@ -53,8 +53,3 @@ return result;

for (let i = 0; i < nL; i++) {
let func = mlPeakShapeGenerator.gaussianFct({
x: p[i],
y: p[i + nL],
width: p[i + nL * 2],
});
result += func(t);
result += mlPeakShapeGenerator.gaussianFct(p[i], p[i + nL], p[i + nL * 2], t);
}

@@ -78,8 +73,3 @@ return result;

for (let i = 0; i < nL; i++) {
let func = mlPeakShapeGenerator.lorentzianFct({
x: p[i],
y: p[i + nL],
width: p[i + nL * 2],
});
result += func(t);
result += mlPeakShapeGenerator.lorentzianFct(p[i], p[i + nL], p[i + nL * 2], t);
}

@@ -97,3 +87,3 @@ return result;

* Fits a set of points to the sum of a set of bell functions.
* @param {Object} input - An object containing the x and y data to be fitted.
* @param {Object} data - An object containing the x and y data to be fitted.
* @param {Array} peakList - A list of initial parameters to be optimized. e.g. coming from a peak picking [{x, y, width}].

@@ -108,4 +98,9 @@ * @param {Object} [options = {}]

let x = data.x;
let maxY = getMaxValue__default['default'](data.y);
data.y.forEach((_, i, arr) => (arr[i] /= maxY));
let y = data.y.map((e) => (e /= maxY));
let peaks = peakList.map((peak) => {
peak.y /= maxY;
return peak;
});

@@ -131,3 +126,3 @@ let nbParams;

let nL = peakList.length;
let nL = peaks.length;
let pInit = new Float64Array(nL * nbParams);

@@ -139,3 +134,3 @@ let pMin = new Float64Array(nL * nbParams);

for (let i = 0; i < nL; i++) {
let peak = peakList[i];
let peak = peaks[i];
for (let s = 0; s < nbParams; s++) {

@@ -160,3 +155,3 @@ pInit[i + s * nL] = getValue(s, peak, STATE_INIT, dt);

);
let pFit = LM__default['default'](data, paramsFunc, lmOptions);
let pFit = LM__default['default']({ x, y }, paramsFunc, lmOptions);

@@ -188,3 +183,3 @@ let { parameterError: error, iterations } = pFit;

case 1:
value = key === STATE_INIT ? 1 : key === STATE_MIN ? 0 : 1.5;
value = key === STATE_INIT ? peak.y : key === STATE_MIN ? 0 : 1.5;
break;

@@ -191,0 +186,0 @@ case 2:

{
"name": "ml-spectra-fitting",
"version": "0.3.2",
"description": "Fit spectra using guassian or lorentzian",
"version": "0.5.0",
"description": "Fit spectra using gaussian or lorentzian",
"main": "lib/index.js",

@@ -29,3 +29,4 @@ "module": "src/index.js",

"Lorentzian",
"Guassian"
"Gaussian",
"pseudovoigt"
],

@@ -62,7 +63,8 @@ "author": "Andres Castillo",

"dependencies": {
"esm": "^3.2.25",
"ml-array-max": "^1.2.0",
"ml-levenberg-marquardt": "^2.1.1",
"ml-peak-shape-generator": "^0.6.1",
"ml-peak-shape-generator": "^0.7.0",
"spectrum-generator": "^4.4.0"
}
}

@@ -1,2 +0,2 @@

[![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![npm download][download-image]][download-url]
[![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url]

@@ -7,3 +7,3 @@ # ml-spectra-fitting

This is spectra fitting package optimize the position (x), max intensity (y), full width at half maximum (width) and the percent of gaussian (mu). It supports three kind of shapes:
This is a spectra fitting package to optimize the position (x), max intensity (y), full width at half maximum (FWHM = width) and the ratio of gaussian contribution (mu) if it's required. It supports three kind of shapes:

@@ -18,3 +18,3 @@ | Name | Equation |

| <img src="https://tex.cheminfo.org/?tex=%5Cdelta%20%3D%20%5Cleft(t%20-%20x%5Cright)%5E2%0A"/> | <img src="https://tex.cheminfo.org/?tex=%5Csigma%20%3D%20%5Cfrac%7Bwidth%7D%7B2%5Csqrt%7B2%20%5Ccdot%20Log(2)%7D%7D"/> | <img src="https://tex.cheminfo.org/?tex=%5Cgamma%3D%5Cleft(width%5Cright)%5E2"/> |
| <img src="https://tex.cheminfo.org/?tex=%5Cdelta%20%3D%20%5Cleft(t%20-%20x%5Cright)%5E2%0A"/> | <img src="https://tex.cheminfo.org/?tex=%5Csigma%20%3D%20%5Cfrac%7Bwidth%7D%7B2%5Csqrt%7B2%20%5Ccdot%20Ln(2)%7D%7D"/> | <img src="https://tex.cheminfo.org/?tex=%5Cgamma%3D%5Cleft(width%5Cright)%5E2"/> |
| --------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------- |

@@ -59,7 +59,7 @@

// the function recive a peaklist with {x, y, width} as a guess
// and return a list of objects
// the function receive an array of peaks {x, y, width} as a guess
// and returns an array of peaks
let fittedParams = optimize(data, peakList);
console.log(fittedParams);
let fittedPeaks = optimize(data, peakList);
console.log(fittedPeaks);
/**

@@ -164,5 +164,3 @@ {

[npm-url]: https://npmjs.org/package/ml-spectra-fitting
[travis-image]: https://img.shields.io/travis/mljs/spectra-fitting/master.svg?style=flat-square
[travis-url]: https://travis-ci.org/mljs/spectra-fitting
[download-image]: https://img.shields.io/npm/dm/ml-spectra-fitting.svg?style=flat-square
[download-url]: https://npmjs.org/package/ml-spectra-fitting

@@ -15,3 +15,3 @@ import getMaxValue from 'ml-array-max';

* Fits a set of points to the sum of a set of bell functions.
* @param {Object} input - An object containing the x and y data to be fitted.
* @param {Object} data - An object containing the x and y data to be fitted.
* @param {Array} peakList - A list of initial parameters to be optimized. e.g. coming from a peak picking [{x, y, width}].

@@ -26,4 +26,9 @@ * @param {Object} [options = {}]

let x = data.x;
let maxY = getMaxValue(data.y);
data.y.forEach((_, i, arr) => (arr[i] /= maxY));
let y = data.y.map((e) => (e /= maxY));
let peaks = peakList.map((peak) => {
peak.y /= maxY;
return peak;
});

@@ -49,3 +54,3 @@ let nbParams;

let nL = peakList.length;
let nL = peaks.length;
let pInit = new Float64Array(nL * nbParams);

@@ -57,3 +62,3 @@ let pMin = new Float64Array(nL * nbParams);

for (let i = 0; i < nL; i++) {
let peak = peakList[i];
let peak = peaks[i];
for (let s = 0; s < nbParams; s++) {

@@ -78,3 +83,3 @@ pInit[i + s * nL] = getValue(s, peak, STATE_INIT, dt);

);
let pFit = LM(data, paramsFunc, lmOptions);
let pFit = LM({ x, y }, paramsFunc, lmOptions);

@@ -106,3 +111,3 @@ let { parameterError: error, iterations } = pFit;

case 1:
value = key === STATE_INIT ? 1 : key === STATE_MIN ? 0 : 1.5;
value = key === STATE_INIT ? peak.y : key === STATE_MIN ? 0 : 1.5;
break;

@@ -109,0 +114,0 @@ case 2:

@@ -16,9 +16,9 @@ import { pseudovoigtFct } from 'ml-peak-shape-generator';

for (let i = 0; i < nL; i++) {
let func = pseudovoigtFct({
x: p[i],
y: p[i + nL],
width: p[i + nL * 2],
mu: p[i + nL * 3],
});
result += func(t);
result += pseudovoigtFct(
p[i],
p[i + nL],
p[i + nL * 2],
p[i + nL * 3],
t,
);
}

@@ -25,0 +25,0 @@ return result;

@@ -15,8 +15,3 @@ import { gaussianFct } from 'ml-peak-shape-generator';

for (let i = 0; i < nL; i++) {
let func = gaussianFct({
x: p[i],
y: p[i + nL],
width: p[i + nL * 2],
});
result += func(t);
result += gaussianFct(p[i], p[i + nL], p[i + nL * 2], t);
}

@@ -23,0 +18,0 @@ return result;

@@ -16,8 +16,3 @@ import { lorentzianFct } from 'ml-peak-shape-generator';

for (let i = 0; i < nL; i++) {
let func = lorentzianFct({
x: p[i],
y: p[i + nL],
width: p[i + nL * 2],
});
result += func(t);
result += lorentzianFct(p[i], p[i + nL], p[i + nL * 2], t);
}

@@ -24,0 +19,0 @@ return result;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc