Skip to content

Commit

Permalink
Add more allowable directions d
Browse files Browse the repository at this point in the history
  • Loading branch information
nicfv committed Mar 8, 2024
1 parent 7a22ca3 commit bf83c43
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions datafit/src/CurveFit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,21 @@ export abstract class CurveFit {
* @returns The best fit for the model up to the distance specified.
*/
private static fitStep(f: fx, a: Array<number>, data: Array<Point>, distance: number): Fit {
const n: number = a.length;
const d: number = 5,
n: number = a.length;
let err_min: number = this.sumSquares(f, a, data),
a_min: Array<number> = a.slice();
for (let i: number = 0; i < 3 ** n; i++) {
for (let i: number = 0; i < d ** n; i++) {
// `str` contains a string of characters in [012]
// and is guaranteed to include all combinations.
// 0 = subtract distance from corresponding parameter
// 1 = no change to corresponding parameter
// 2 = add distance to corresponding parameter
const str: string = i.toString(3).padStart(n, '0'),
const str: string = i.toString(d).padStart(n, '0'),
a_new: Array<number> = a.slice();
for (let i: number = 0; i < str.length; i++) {
const val: number = Number.parseInt(str[i]);
a_new[i] += SMath.translate(val, 0, 2, -distance, distance);
a_new[i] += SMath.translate(val, 0, d - 1, -distance, distance);
}
// Check the sum of squared errors. If the new
// set of parameters yields a lower error, save
Expand Down

0 comments on commit bf83c43

Please sign in to comment.