Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go from exray to t6 #117

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/datafit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 1.4.6

- Update typescript dependency version to 5.5.4
- Rebuild package and documentation in monorepo style
- Replace testing framework dependency

## 1.4.5

- Update dependency versions
Expand Down
2 changes: 1 addition & 1 deletion packages/datafit/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"clean": "rm -rf node_modules package-lock.json"
},
"dependencies": {
"datafit": "file:datafit-1.4.5.tgz"
"datafit": "file:datafit-1.4.6.tgz"
}
}
4 changes: 2 additions & 2 deletions packages/datafit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "datafit",
"version": "1.4.5",
"version": "1.4.6",
"description": "Simple curve-fitting algorithm",
"homepage": "https://npm.nicfv.com/",
"bin": "",
Expand Down Expand Up @@ -52,6 +52,6 @@
"smath": "1.8.4"
},
"devDependencies": {
"exray": "1.1.1"
"t6": "1.1.4"
}
}
52 changes: 26 additions & 26 deletions packages/datafit/src/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fit } from './lib';
import { Datum, Summary } from './types';
import { SMath } from 'smath';
import { X } from 'exray';
import { T6 } from 't6';

// Define f(x)
const a: Array<number> = [-3, 1, 0.2];
Expand All @@ -12,23 +12,23 @@ function f(x: number, a0: number = a[0], a1: number = a[1], a2: number = a[2]):
const data: Datum<number>[] = SMath.linspace(-5, 5, 9).map(x => ({ x: x, y: f(x) })),
summary: Summary<number> = fit(f, data);
// Make sure dataset is accurate
X.eq(data[0].x, -5);
X.eq(data[0].y, -3);
X.eq(data[4].x, 0);
X.eq(data[4].y, -3);
X.eq(data[8].x, 5);
X.eq(data[8].y, 7);
T6.eq(data[0].x, -5);
T6.eq(data[0].y, -3);
T6.eq(data[4].x, 0);
T6.eq(data[4].y, -3);
T6.eq(data[8].x, 5);
T6.eq(data[8].y, 7);
// Check accuracy of best fit
// Values should be within 20%
// of actual, but this could
// fail due to randomness.
const tolerance: number = 0.20;
X.le(Math.abs(SMath.error(summary.params[0], a[0])), tolerance);
X.le(Math.abs(SMath.error(summary.params[1], a[1])), tolerance);
X.le(Math.abs(SMath.error(summary.params[2], a[2])), tolerance);
X.le(Math.abs(SMath.error(summary.f(-5), f(-5))), tolerance);
X.le(Math.abs(SMath.error(summary.f(0), f(0))), tolerance);
X.le(Math.abs(SMath.error(summary.f(5), f(5))), tolerance);
T6.le(Math.abs(SMath.error(summary.params[0], a[0])), tolerance);
T6.le(Math.abs(SMath.error(summary.params[1], a[1])), tolerance);
T6.le(Math.abs(SMath.error(summary.params[2], a[2])), tolerance);
T6.le(Math.abs(SMath.error(summary.f(-5), f(-5))), tolerance);
T6.le(Math.abs(SMath.error(summary.f(0), f(0))), tolerance);
T6.le(Math.abs(SMath.error(summary.f(5), f(5))), tolerance);

// Define 2D function g(x,y)
const b = [0.5, -2, 1];
Expand All @@ -44,14 +44,14 @@ SMath.linspace(-5, 5, 9).forEach(x => {
});
const summary2: Summary<number[]> = fit(g, data2);
// Make sure dataset is accurate
X.eq(data2[0].x[0], -5);
X.eq(data2[0].x[1], -5);
X.eq(data2[0].y, 8.5);
T6.eq(data2[0].x[0], -5);
T6.eq(data2[0].x[1], -5);
T6.eq(data2[0].y, 8.5);
// Validate accuracy of fitted data
X.le(Math.abs(SMath.error(summary2.params[0], b[0])), tolerance);
X.le(Math.abs(SMath.error(summary2.params[1], b[1])), tolerance);
X.le(Math.abs(SMath.error(summary2.params[2], b[2])), tolerance);
X.le(Math.abs(SMath.error(summary2.f([-5, -5]), g([-5, -5]))), tolerance);
T6.le(Math.abs(SMath.error(summary2.params[0], b[0])), tolerance);
T6.le(Math.abs(SMath.error(summary2.params[1], b[1])), tolerance);
T6.le(Math.abs(SMath.error(summary2.params[2], b[2])), tolerance);
T6.le(Math.abs(SMath.error(summary2.f([-5, -5]), g([-5, -5]))), tolerance);

// Define a nonlinear function with wildly different parameter magnitudes
const c: Array<number> = [1050, 0.2];
Expand All @@ -62,10 +62,10 @@ function h(x: number, A: number = c[0], w: number = c[1]): number {
const data3: Datum<number>[] = SMath.linspace(0, 15, 100).map(x => ({ x: x, y: h(x) })),
summary3: Summary<number> = fit(h, data3);
// Make sure dataset is accurate
X.eq(data3[0].x, 0);
X.eq(data3[0].y, 0);
T6.eq(data3[0].x, 0);
T6.eq(data3[0].y, 0);
// Validate accuracy of fitted data
X.le(Math.abs(SMath.error(Math.abs(summary3.params[0]), c[0])), tolerance, JSON.stringify(summary3));
X.le(Math.abs(SMath.error(Math.abs(summary3.params[1]), c[1])), tolerance, JSON.stringify(summary3));
X.le(Math.abs(SMath.error(summary3.f(3), h(3))), tolerance, JSON.stringify([summary3, summary3.f(0), h(0)]));
X.le(Math.abs(SMath.error(summary3.f(4), h(4))), tolerance, JSON.stringify([summary3, summary3.f(1), h(1)]));
T6.le(Math.abs(SMath.error(Math.abs(summary3.params[0]), c[0])), tolerance, JSON.stringify(summary3));
T6.le(Math.abs(SMath.error(Math.abs(summary3.params[1]), c[1])), tolerance, JSON.stringify(summary3));
T6.le(Math.abs(SMath.error(summary3.f(3), h(3))), tolerance, JSON.stringify([summary3, summary3.f(0), h(0)]));
T6.le(Math.abs(SMath.error(summary3.f(4), h(4))), tolerance, JSON.stringify([summary3, summary3.f(1), h(1)]));
6 changes: 6 additions & 0 deletions packages/dimensional/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unpublished

- Update typescript dependency version to 5.5.4
- Rebuild package and documentation in monorepo style
- Replace testing framework dependency

## 0.4.1

- Update donation URL
Expand Down
2 changes: 1 addition & 1 deletion packages/dimensional/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@
"smath": "1.8.4"
},
"devDependencies": {
"exray": "1.1.1"
"t6": "1.1.4"
}
}
Loading