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.8.0 to 0.9.0

7

CHANGELOG.md
# Changelog
## [0.9.0](https://www.github.com/mljs/spectra-fitting/compare/v0.8.0...v0.9.0) (2020-12-04)
### Features
* update ml-levenberg-marquardt and adapt to the new version ([#41](https://www.github.com/mljs/spectra-fitting/issues/41)) ([9773585](https://www.github.com/mljs/spectra-fitting/commit/9773585e691edffff06617742800ced62042d557))
## [0.8.0](https://www.github.com/mljs/spectra-fitting/compare/v0.7.1...v0.8.0) (2020-11-18)

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

54

lib/index.js

@@ -122,2 +122,3 @@ 'use strict';

const STATE_MAX = 2;
const STATE_GS = 3;

@@ -151,3 +152,6 @@ const keys = ['x', 'y', 'width', 'mu'];

let maxY = getMaxValue__default['default'](data.y);
let y = data.y.map((e) => (e /= maxY));
let y = new Array(x.length);
for (let i = 0; i < x.length; i++) {
y[i] = data.y[i] / maxY;
}

@@ -173,13 +177,22 @@ let nbParams;

let pInit = new Float64Array(peaks.length * nbParams);
let pMin = new Float64Array(peaks.length * nbParams);
let pMax = new Float64Array(peaks.length * nbParams);
let nbShapes = peaks.length;
let pInit = new Float64Array(nbShapes * nbParams);
let pMin = new Float64Array(nbShapes * nbParams);
let pMax = new Float64Array(nbShapes * nbParams);
let gradientDifference = new Float64Array(nbShapes * nbParams);
let deltaX = Math.abs(data.x[0] - data.x[1]);
for (let i = 0; i < peaks.length; i++) {
for (let i = 0; i < nbShapes; i++) {
let peak = peaks[i];
for (let s = 0; s < nbParams; s++) {
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);
pInit[i + s * nbShapes] = getValue(s, peak, STATE_INIT, deltaX, maxY);
pMin[i + s * nbShapes] = getValue(s, peak, STATE_MIN, deltaX, maxY);
pMax[i + s * nbShapes] = getValue(s, peak, STATE_MAX, deltaX, maxY);
gradientDifference[i + s * nbShapes] = getValue(
s,
peak,
STATE_GS,
deltaX,
maxY,
);
}

@@ -193,2 +206,3 @@ }

optimizationOptions.initialValues = pInit;
optimizationOptions.gradientDifference = gradientDifference;

@@ -209,3 +223,3 @@ let pFit = algorithm({ x, y }, paramsFunc, optimizationOptions);

function getValue(parameterIndex, peak, key, dt) {
function getValue(parameterIndex, peak, key, dt, maxY) {
let value;

@@ -217,2 +231,4 @@ switch (parameterIndex) {

? peak.x
: key === STATE_GS
? dt / 1000
: key === STATE_MIN

@@ -223,3 +239,10 @@ ? peak.x - dt

case 1:
value = key === STATE_INIT ? peak.y : key === STATE_MIN ? 0 : 1.5;
value =
key === STATE_INIT
? peak.y / maxY
: key === STATE_GS
? 1e-3
: key === STATE_MIN
? 0
: 1.5;
break;

@@ -230,2 +253,4 @@ case 2:

? peak.width
: key === STATE_GS
? dt / 1000
: key === STATE_MIN

@@ -236,3 +261,10 @@ ? peak.width / 4

default:
value = key === STATE_INIT ? 0.5 : key === STATE_MIN ? 0 : 1;
value =
key === STATE_INIT
? 0.5
: key === STATE_GS
? 0.01
: key === STATE_MIN
? 0
: 1;
}

@@ -239,0 +271,0 @@ return value;

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

@@ -57,13 +57,13 @@ "main": "lib/index.js",

"eslint-plugin-prettier": "^3.1.4",
"esm": "^3.2.25",
"jest": "^26.6.3",
"prettier": "^2.1.2",
"rollup": "^2.33.1"
"rollup": "^2.33.1",
"spectrum-generator": "^4.4.1"
},
"dependencies": {
"esm": "^3.2.25",
"ml-array-max": "^1.2.0",
"ml-levenberg-marquardt": "^2.1.1",
"ml-peak-shape-generator": "^0.10.0",
"spectrum-generator": "^4.4.0"
"ml-levenberg-marquardt": "^3.0.1",
"ml-peak-shape-generator": "^0.10.0"
}
}

@@ -81,3 +81,3 @@ import { optimize } from '../index';

kind: 'lm',
options: { maxIterations: 300, damping: 1 },
options: { maxIterations: 300, damping: 0.5, errorTolerance: 1e-8 },
},

@@ -84,0 +84,0 @@ },

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

const STATE_MAX = 2;
const STATE_GS = 3;

@@ -41,3 +42,6 @@ const keys = ['x', 'y', 'width', 'mu'];

let maxY = getMaxValue(data.y);
let y = data.y.map((e) => (e /= maxY));
let y = new Array(x.length);
for (let i = 0; i < x.length; i++) {
y[i] = data.y[i] / maxY;
}

@@ -63,13 +67,22 @@ let nbParams;

let pInit = new Float64Array(peaks.length * nbParams);
let pMin = new Float64Array(peaks.length * nbParams);
let pMax = new Float64Array(peaks.length * nbParams);
let nbShapes = peaks.length;
let pInit = new Float64Array(nbShapes * nbParams);
let pMin = new Float64Array(nbShapes * nbParams);
let pMax = new Float64Array(nbShapes * nbParams);
let gradientDifference = new Float64Array(nbShapes * nbParams);
let deltaX = Math.abs(data.x[0] - data.x[1]);
for (let i = 0; i < peaks.length; i++) {
for (let i = 0; i < nbShapes; i++) {
let peak = peaks[i];
for (let s = 0; s < nbParams; s++) {
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);
pInit[i + s * nbShapes] = getValue(s, peak, STATE_INIT, deltaX, maxY);
pMin[i + s * nbShapes] = getValue(s, peak, STATE_MIN, deltaX, maxY);
pMax[i + s * nbShapes] = getValue(s, peak, STATE_MAX, deltaX, maxY);
gradientDifference[i + s * nbShapes] = getValue(
s,
peak,
STATE_GS,
deltaX,
maxY,
);
}

@@ -83,2 +96,3 @@ }

optimizationOptions.initialValues = pInit;
optimizationOptions.gradientDifference = gradientDifference;

@@ -99,3 +113,3 @@ let pFit = algorithm({ x, y }, paramsFunc, optimizationOptions);

function getValue(parameterIndex, peak, key, dt) {
function getValue(parameterIndex, peak, key, dt, maxY) {
let value;

@@ -107,2 +121,4 @@ switch (parameterIndex) {

? peak.x
: key === STATE_GS
? dt / 1000
: key === STATE_MIN

@@ -113,3 +129,10 @@ ? peak.x - dt

case 1:
value = key === STATE_INIT ? peak.y : key === STATE_MIN ? 0 : 1.5;
value =
key === STATE_INIT
? peak.y / maxY
: key === STATE_GS
? 1e-3
: key === STATE_MIN
? 0
: 1.5;
break;

@@ -120,2 +143,4 @@ case 2:

? peak.width
: key === STATE_GS
? dt / 1000
: key === STATE_MIN

@@ -126,5 +151,12 @@ ? peak.width / 4

default:
value = key === STATE_INIT ? 0.5 : key === STATE_MIN ? 0 : 1;
value =
key === STATE_INIT
? 0.5
: key === STATE_GS
? 0.01
: key === STATE_MIN
? 0
: 1;
}
return value;
}
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