mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 23:07:06 +00:00
adding module ml-levenberg-marquardt
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
// Type definitions for ml-levenberg-marquardt 1.0.3
|
||||
// Project: https://github.com/mljs/levenberg-marquardt#readme
|
||||
// Definitions by: m93a <https://github.com/m93a>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
|
||||
declare namespace LM {
|
||||
/**
|
||||
* Function that receives an array of parameters and returns
|
||||
* a function with the independent variable as a parameter.
|
||||
*/
|
||||
export type FittedFunction = (parameters: number[]) => (x: number) => number;
|
||||
|
||||
/**
|
||||
* Coordinates of points to fit.
|
||||
*/
|
||||
export interface Data {
|
||||
x: number[];
|
||||
y: number[];
|
||||
}
|
||||
|
||||
export type Options = {
|
||||
damping: number,
|
||||
initialValues: number[],
|
||||
gradientDifference: number,
|
||||
maxIterations: number,
|
||||
errorTolerance: number
|
||||
};
|
||||
|
||||
export type Result = {
|
||||
iterations: number,
|
||||
parameterError: number,
|
||||
parameterValues: number[]
|
||||
};
|
||||
}
|
||||
|
||||
declare function LM(d: LM.Data, fn: LM.FittedFunction, o: LM.Options): LM.Result;
|
||||
|
||||
export default LM;
|
||||
@@ -0,0 +1,31 @@
|
||||
import LM from 'ml-levenberg-marquardt';
|
||||
|
||||
function sinFunction([a, b]: number[]) {
|
||||
return (t: number) => a * Math.sin(b * t);
|
||||
}
|
||||
|
||||
const data = {
|
||||
x: [
|
||||
0, Math.PI / 2, Math.PI, Math.PI * 3 / 2
|
||||
],
|
||||
y: [
|
||||
0, 1, 0, -1
|
||||
]
|
||||
};
|
||||
|
||||
const initialValues = [ 2, 4 ];
|
||||
|
||||
const options = {
|
||||
damping: 1.5,
|
||||
initialValues,
|
||||
gradientDifference: 10e-2,
|
||||
maxIterations: 100,
|
||||
errorTolerance: 10e-3
|
||||
};
|
||||
|
||||
const fittedParams = LM(data, sinFunction, options);
|
||||
|
||||
// this doesn't make sense but it uses fittedParams...
|
||||
if (fittedParams.iterations < 10) {
|
||||
fittedParams.parameterValues[0] += fittedParams.parameterError;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"ml-levenberg-marquardt-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user