0.0.9 • Published 8 months ago
direct-manager v0.0.9
direct-manager
Installation
$ npm i direct-manager
Usage
import direct from 'ml-direct';
import DirectManager from 'direct-manager';
import SD from 'spectra-data';
// The prediction should be obtained with SPINUS.
const directManager = new DirectManager(prediction);
const boundaries = directManager.getBoundaries();
const buildPredictionFile = directManager.tidyUpParameters();
const spectraProperties = {
frequency: 400,
from: 0,
to: 10,
lineWidth: 3,
nbPoints: 4096,
maxClusterSize: 8,
output: 'xy',
};
const predicted = direct(
objectiveFunction,
boundaries.lower,
boundaries.upper,
{ iterations: 10 },
);
// target: Experimental spectrum.
function objectiveFunction(parameters) {
const testSignals = buildPredictionFile(parameters);
const simulation = SD.NMR.fromSignals(testSignals, spectraProperties);
simulation.setMinMax(0, 1);
const simulated = simulation.getYData();
let result = 0;
for (let i = 0; i < target.length; i++) {
result += (target[i] - simulated[i]) ** 2;
}
return result;
}