-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use QR, add demo, add tests, add benchmark
- Loading branch information
Santi Miranda
committed
Oct 20, 2023
1 parent
1008275
commit 4dae0aa
Showing
18 changed files
with
24,199 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,4 @@ jspm_packages | |
lib | ||
|
||
lib-esm | ||
*.cpuprofile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/__tests__/data/*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* Data produced with | ||
const yVal = | ||
((6.02 * (i / 100)) ^ 3) + | ||
3.01 * (i / 100) ** 2 + | ||
2.55 * i/100 + | ||
5 + | ||
Math.random(); | ||
*/ | ||
|
||
import { readFileSync } from 'fs'; | ||
import { join } from 'path'; | ||
|
||
import { PolynomialRegression } from '../lib/index.js'; | ||
|
||
const __dirname = new URL('.', import.meta.url).pathname; | ||
const data = JSON.parse( | ||
readFileSync( | ||
join(__dirname, '..', 'src', '__tests__', 'data', 'large_cubic.json'), | ||
'utf8', | ||
), | ||
); | ||
|
||
/** | ||
* const yVal = | ||
6.3 * (i / 5000) ** 3 + | ||
3.01 * (i / 1000) ** 2 + | ||
(2.55 / 100) * i + | ||
5 + | ||
Math.random(); | ||
*/ | ||
const result = new PolynomialRegression(data.x, data.y, 3); | ||
|
||
// console.log(result.toLaTeX(5)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { readFileSync } from 'fs'; | ||
import { join } from 'path'; | ||
|
||
import { PolynomialRegression } from '../lib/index.js'; | ||
|
||
const __dirname = new URL('.', import.meta.url).pathname; | ||
const data = JSON.parse( | ||
readFileSync( | ||
join(__dirname, '..', 'src', '__tests__', 'data', 'large_quadratic.json'), | ||
'utf8', | ||
), | ||
); | ||
|
||
/** | ||
* | ||
* const yVal = 3.01 * (i / 100) ** 2 + (2.55/100) * i + 5 + Math.random(); | ||
*/ | ||
const result = new PolynomialRegression(data.x, data.y, 2); | ||
|
||
// console.log(result); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import React from 'react'; | ||
import { PolynomialRegression } from '../src/index'; | ||
import { | ||
Plot, | ||
LineSeries, | ||
Axis, | ||
Legend, | ||
Heading, | ||
SeriesPoint, | ||
} from 'react-plot'; | ||
|
||
import { x, y } from '../src/__tests__/data/degree5.data'; | ||
|
||
const data = x.map((x, i) => ({ x, y: y[i] })); | ||
|
||
const calculations: SeriesPoint[][] = []; | ||
const degree: number[] = []; | ||
for (let i = 2; i <= 7; i++) { | ||
const r = new PolynomialRegression(x, y, i) | ||
if(i===5) console.log(r.coefficients, r.toLaTeX(5)) | ||
|
||
const plot = r.predict(x).map((y, i) => ({ x: x[i], y })); | ||
degree.push(r.degree); | ||
calculations.push(plot); | ||
} | ||
|
||
export const Example = () => ( | ||
<Plot | ||
width={1000} | ||
height={1000} | ||
margin={{ bottom: 50, left: 90, top: 50, right: 100 }} | ||
> | ||
<Heading | ||
title="Electrical characterization" | ||
subtitle="Current vs Voltage" | ||
/> | ||
<LineSeries | ||
data={data} | ||
xAxis="x" | ||
yAxis="y" | ||
lineStyle={{ strokeWidth: 3 }} | ||
label="Raw Data" | ||
displayMarkers={false} | ||
/> | ||
{calculations.map((plot, i) => ( | ||
<LineSeries | ||
key={i} | ||
data={plot} | ||
xAxis="x" | ||
yAxis="y" | ||
label={`${degree[i]} degree polynomial`} | ||
/> | ||
))} | ||
<Axis | ||
id="x" | ||
position="bottom" | ||
label="Drain voltage [V]" | ||
displayPrimaryGridLines | ||
// max={Math.max(...x) * 1.1} | ||
/> | ||
<Axis | ||
id="y" | ||
position="left" | ||
label="Drain current [mA]" | ||
displayPrimaryGridLines | ||
// max={Math.max(...y) * 1.1} | ||
/> | ||
<Legend position="right" /> | ||
</Plot> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>1D Spectra</title> | ||
<style> | ||
* { | ||
padding: 0.5rem; | ||
margin: 0; | ||
box-sizing: border-box; | ||
} | ||
body { | ||
padding-top: 2rem; | ||
} | ||
label { | ||
border-radius: 50% 25% 40% 10%; | ||
border: 1.5px solid #ccc; | ||
display: inline-block; | ||
padding: 1rem; | ||
margin: 1rem; | ||
} | ||
label:hover { | ||
cursor: pointer; | ||
background-color: bisque; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="./main.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom/client' | ||
import { Example } from './example' | ||
|
||
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( | ||
<React.StrictMode> | ||
<Example /> | ||
</React.StrictMode>, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const x = [ | ||
50, 50, 50, 70, 70, 70, 80, 80, 80, 90, 90, 90, 100, 100, 100, | ||
]; | ||
export const y = [ | ||
3.3, 2.8, 2.9, 2.3, 2.6, 2.1, 2.5, 2.9, 2.4, 3.0, 3.1, 2.8, 3.3, 3.5, 3.0, | ||
]; |
Oops, something went wrong.