Skip to content

Commit

Permalink
feat(scaleAlignment): return the scaled time instead the peak list
Browse files Browse the repository at this point in the history
  • Loading branch information
maasencioh committed Oct 10, 2016
1 parent a5c9163 commit 0c7cd3b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
11 changes: 4 additions & 7 deletions src/scaleAlignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ const Regression = require('ml-regression').NLR.PolynomialRegression;
* @param {Number} [options.stringFormula = 0] - Precision of the string formula (0 if don't need the value)
* @param {Number} [options.polynomialDegree = 3] - Degree of the polynomial regression
* @return {Object} - The scaled spectra:
* * `reference`: The reference array
* * `sample`: The scaled sample array
* * `sample`: The scaled time sample array
* * `stringFormula`: Regression equation
* * `r2`: R2 quality number
* * `error`: Vector of the difference between the spected value and the actual shift value
Expand All @@ -28,14 +27,12 @@ function scaleAlignment(reference, sample, options = {}) {
let scaledSample = new Array(sample.length);
let error = new Array(sample.length);
for (var i = 0; i < scaledSample.length; i++) {
scaledSample[i] = sample[i];
scaledSample[i].x = regression.predict(sample[i].x);
error[i] = reference[i].x - scaledSample[i].x;
scaledSample[i] = regression.predict(sample[i].x);
error[i] = reference[i].x - scaledSample[i];
}
scaledSample = scaledSample.filter((peak) => peak.x <= maxTime);
scaledSample = scaledSample.filter((peak) => peak <= maxTime);

let ans = {
reference: reference,
sample: scaledSample
};

Expand Down
6 changes: 2 additions & 4 deletions test/scaleAlignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ test('Simple case', async t => {
t.deepEqual(compared.peaksSecond.map((val) => val.x), [30, 40, 50, 60]);

let aligned = scaleAlignment(compared.peaksFirst, compared.peaksSecond);
t.deepEqual(aligned.reference.map((val) => val.x), [20, 30, 40, 50]);
t.deepEqual(aligned.sample.map((val) => val.x), [20, 30, 40, 50]);
t.deepEqual(aligned.sample, [20, 30, 40, 50]);
});

test('Quality and string', async t => {
Expand Down Expand Up @@ -110,8 +109,7 @@ test('Quality and string', async t => {
t.deepEqual(compared.peaksSecond.map((val) => val.x), [30, 40, 50, 60]);

let aligned = scaleAlignment(compared.peaksFirst, compared.peaksSecond, {computeQuality: true, stringFormula: 3});
t.deepEqual(aligned.reference.map((val) => val.x), [20, 30, 40, 50]);
t.deepEqual(aligned.sample.map((val) => val.x), [20, 30, 40, 50]);
t.deepEqual(aligned.sample, [20, 30, 40, 50]);
t.is(aligned.stringFormula, 'y = 1.00*x-10.0');
t.is(aligned.r2, 1);
});

0 comments on commit 0c7cd3b

Please sign in to comment.