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.7.1 to 0.8.0

7

CHANGELOG.md
# Changelog
## [0.8.0](https://www.github.com/mljs/spectra-fitting/compare/v0.7.1...v0.8.0) (2020-11-18)
### Features
* first make a copy of the peaks to keep all attributes ([466278e](https://www.github.com/mljs/spectra-fitting/commit/466278e22628f3d0e73b6e112b42c71fbd30f91f))
### [0.7.1](https://www.github.com/mljs/spectra-fitting/compare/v0.7.0...v0.7.1) (2020-11-14)

@@ -4,0 +11,0 @@

38

lib/index.js

@@ -127,3 +127,3 @@ 'use strict';

* @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}].
* @param {array} peaks - A list of initial parameters to be optimized. e.g. coming from a peak picking [{x, y, width}].
* @param {object} [options = {}]

@@ -137,3 +137,3 @@ * @param {object} [options.shape={}] - it's specify the kind of shape used to fitting.

*/
function optimize(data, peakList, options = {}) {
function optimize(data, peaks, options = {}) {
let {

@@ -146,2 +146,4 @@ shape = { kind: 'gaussian' },

peaks = JSON.parse(JSON.stringify(peaks));
let kind = mlPeakShapeGenerator.getKind(shape.kind);

@@ -152,6 +154,2 @@

let y = data.y.map((e) => (e /= maxY));
let peaks = peakList.map((peak) => {
peak.y /= maxY;
return peak;
});

@@ -177,14 +175,13 @@ let nbParams;

let nL = peaks.length;
let pInit = new Float64Array(nL * nbParams);
let pMin = new Float64Array(nL * nbParams);
let pMax = new Float64Array(nL * nbParams);
let dt = Math.abs(data.x[0] - data.x[1]);
let pInit = new Float64Array(peaks.length * nbParams);
let pMin = new Float64Array(peaks.length * nbParams);
let pMax = new Float64Array(peaks.length * nbParams);
let deltaX = Math.abs(data.x[0] - data.x[1]);
for (let i = 0; i < nL; i++) {
for (let i = 0; i < peaks.length; i++) {
let peak = peaks[i];
for (let s = 0; s < nbParams; s++) {
pInit[i + s * nL] = getValue(s, peak, STATE_INIT, dt);
pMin[i + s * nL] = getValue(s, peak, STATE_MIN, dt);
pMax[i + s * nL] = getValue(s, peak, STATE_MAX, dt);
pInit[i + s * peaks.length] = getValue(s, peak, STATE_INIT, deltaX);
pMin[i + s * peaks.length] = getValue(s, peak, STATE_MIN, deltaX);
pMax[i + s * peaks.length] = getValue(s, peak, STATE_MAX, deltaX);
}

@@ -202,10 +199,9 @@ }

let { parameterError: error, iterations } = pFit;
let result = { error, iterations, peaks: [] };
for (let i = 0; i < nL; i++) {
let peak = {};
pFit.parameterValues[i + nL] *= maxY;
let result = { error, iterations, peaks };
for (let i = 0; i < peaks.length; i++) {
pFit.parameterValues[i + peaks.length] *= maxY;
for (let s = 0; s < nbParams; s++) {
peak[keys[s]] = pFit.parameterValues[i + s * nL];
// we modify the optimized parameters
peaks[i][keys[s]] = pFit.parameterValues[i + s * peaks.length];
}
result.peaks.push(peak);
}

@@ -212,0 +208,0 @@ return result;

{
"name": "ml-spectra-fitting",
"version": "0.7.1",
"version": "0.8.0",
"description": "Fit spectra using gaussian or lorentzian",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -44,3 +44,3 @@ [![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url]

//the approximate values to be optimized, It could come from a peak picking with ml-gsd
let peakList = [
let peaks = [
{

@@ -61,3 +61,3 @@ x: -0.5,

let fittedPeaks = optimize(data, peakList);
let fittedPeaks = optimize(data, peaks);
console.log(fittedPeaks);

@@ -117,3 +117,3 @@ /**

//the approximate values to be optimized, It could coming from a peak picking with ml-gsd
let peakList = [
let peaks = [
{

@@ -131,5 +131,5 @@ x: -0.5,

// the function recive a peaklist with {x, y, width} as a guess
// the function receive an array of peak with {x, y, width} as a guess
// and return a list of objects
let fittedParams = optimize(data, peakList, { shape: { kind: 'pseudovoigt' } });
let fittedParams = optimize(data, peaks, { shape: { kind: 'pseudovoigt' } });

@@ -136,0 +136,0 @@ console.log(fittedParams);

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

* @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}].
* @param {array} peaks - A list of initial parameters to be optimized. e.g. coming from a peak picking [{x, y, width}].
* @param {object} [options = {}]

@@ -27,3 +27,3 @@ * @param {object} [options.shape={}] - it's specify the kind of shape used to fitting.

*/
export function optimize(data, peakList, options = {}) {
export function optimize(data, peaks, options = {}) {
let {

@@ -36,2 +36,4 @@ shape = { kind: 'gaussian' },

peaks = JSON.parse(JSON.stringify(peaks));
let kind = getKind(shape.kind);

@@ -42,6 +44,2 @@

let y = data.y.map((e) => (e /= maxY));
let peaks = peakList.map((peak) => {
peak.y /= maxY;
return peak;
});

@@ -67,14 +65,13 @@ let nbParams;

let nL = peaks.length;
let pInit = new Float64Array(nL * nbParams);
let pMin = new Float64Array(nL * nbParams);
let pMax = new Float64Array(nL * nbParams);
let dt = Math.abs(data.x[0] - data.x[1]);
let pInit = new Float64Array(peaks.length * nbParams);
let pMin = new Float64Array(peaks.length * nbParams);
let pMax = new Float64Array(peaks.length * nbParams);
let deltaX = Math.abs(data.x[0] - data.x[1]);
for (let i = 0; i < nL; i++) {
for (let i = 0; i < peaks.length; i++) {
let peak = peaks[i];
for (let s = 0; s < nbParams; s++) {
pInit[i + s * nL] = getValue(s, peak, STATE_INIT, dt);
pMin[i + s * nL] = getValue(s, peak, STATE_MIN, dt);
pMax[i + s * nL] = getValue(s, peak, STATE_MAX, dt);
pInit[i + s * peaks.length] = getValue(s, peak, STATE_INIT, deltaX);
pMin[i + s * peaks.length] = getValue(s, peak, STATE_MIN, deltaX);
pMax[i + s * peaks.length] = getValue(s, peak, STATE_MAX, deltaX);
}

@@ -92,10 +89,9 @@ }

let { parameterError: error, iterations } = pFit;
let result = { error, iterations, peaks: [] };
for (let i = 0; i < nL; i++) {
let peak = {};
pFit.parameterValues[i + nL] *= maxY;
let result = { error, iterations, peaks };
for (let i = 0; i < peaks.length; i++) {
pFit.parameterValues[i + peaks.length] *= maxY;
for (let s = 0; s < nbParams; s++) {
peak[keys[s]] = pFit.parameterValues[i + s * nL];
// we modify the optimized parameters
peaks[i][keys[s]] = pFit.parameterValues[i + s * peaks.length];
}
result.peaks.push(peak);
}

@@ -102,0 +98,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