Skip to content

Commit

Permalink
Increase neighbors to 9 in all directions, but this severely limits m…
Browse files Browse the repository at this point in the history
…ax free params
  • Loading branch information
nicfv committed Mar 8, 2024
1 parent 30a7161 commit 8bb9876
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions datafit/src/CurveFit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export abstract class CurveFit {
/**
* Anything beyond this takes several minutes of computation time.
*/
private static readonly MAX_PARAMS: number = 18;
private static readonly MAX_PARAMS: number = 8;
/**
*
* @param f The model function for curve fitting.
Expand All @@ -23,7 +23,7 @@ export abstract class CurveFit {
* @param iterations Define the number of iterations for this algorithm.
* @returns The set of parameters for the best fit and sum of squared errors.
*/
public static fit(f: fx, data: Array<Point>, a_initial: Array<number> = [], searchDistance: number = 10, iterations: number = 1e3): Fit {
public static fit(f: fx, data: Array<Point>, a_initial: Array<number> = [], distance: number = 10, iterations: number = 1e3): Fit {
const N_params: number = f.length - 1;
if (a_initial.length === 0) {
a_initial.length = N_params;
Expand All @@ -35,12 +35,12 @@ export abstract class CurveFit {
if (N_params > this.MAX_PARAMS) {
throw new Error('Your function includes too many unknown parameters.');
}
if (searchDistance < 0 || iterations < 0) {
if (distance < 0 || iterations < 0) {
throw new Error('Invalid search distance or iteration count.');
}
let bestFit: Fit = this.fitStep(f, a_initial, data, searchDistance);
let bestFit: Fit = this.fitStep(f, a_initial, data, distance);
for (let i = 0; i < iterations; i++) {
bestFit = this.fitStep(f, bestFit.a, data, SMath.translate(i, 0, iterations, searchDistance, 0));
bestFit = this.fitStep(f, bestFit.a, data, SMath.translate(i, 0, iterations, distance, 0));
}
return bestFit;
}
Expand All @@ -55,7 +55,7 @@ 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 d: number = 5,
const d: number = 9,
n: number = a.length;
let err_min: number = this.sumSquares(f, a, data),
a_min: Array<number> = a.slice();
Expand Down

0 comments on commit 8bb9876

Please sign in to comment.