Skip to content

Commit

Permalink
Add p5.tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
nickmcintyre committed Aug 3, 2022
1 parent ce2821b commit af20841
Show file tree
Hide file tree
Showing 27 changed files with 1,018 additions and 2,676 deletions.
34 changes: 16 additions & 18 deletions README.md
Expand Up @@ -9,14 +9,14 @@

This addon library for p5.js turns the "software sketchbook" into a beginner-friendly environment for technical computing. It provides the following features:

- A tensor object (similar to [NumPy](https://numpy.org/) arrays)
- A computer algebra system (similar to [SymPy](https://www.sympy.org/en/index.html) -- in progress)
- A grammar of graphics (similar to [ggplot2](https://ggplot2.tidyverse.org/) -- in progress)
- A supercharged p5.Table (similar to [pandas](https://pandas.pydata.org/) DataFrames)
- A machine learning API (similar to [scikit-learn](https://scikit-learn.org/stable/index.html) -- coming soon!)
- A drawing turtle (because they're awesome)
- A tensor object similar to [NumPy](https://numpy.org/) arrays
- A computer algebra system similar to [SymPy](https://www.sympy.org/en/index.html) (in progress)
- A grammar of graphics similar to [ggplot2](https://ggplot2.tidyverse.org/) (in progress)
- A grammar of data manipulation similar to [dplyr](https://dplyr.tidyverse.org/)
- A machine learning API similar to [scikit-learn](https://scikit-learn.org/stable/index.html) (coming soon!)
- A drawing turtle

The library is written in [TypeScript](http://www.typescriptlang.org/) and uses [Day.js](https://day.js.org/), [Math.js](https://mathjs.org/), and [TensorFlow.js](https://js.tensorflow.org/api/latest/) under the hood. It bundles [p5.dataframe](https://github.com/nickmcintyre/p5.dataframe), [TurtleGFX](https://github.com/CodeGuppyPrograms/TurtleGFX), and [wildflower](https://github.com/nickmcintyre/wildflower).
The library is written in [TypeScript](http://www.typescriptlang.org/) and uses [Day.js](https://day.js.org/), [Math.js](https://mathjs.org/), [TensorFlow.js](https://js.tensorflow.org/api/latest/), and [tidy.js](https://pbeshai.github.io/tidy/) under the hood. It bundles [p5.tidy](https://github.com/nickmcintyre/p5.tidy), [TurtleGFX](https://github.com/CodeGuppyPrograms/TurtleGFX), and [wildflower](https://github.com/nickmcintyre/wildflower).

## Usage

Expand Down Expand Up @@ -51,24 +51,22 @@ function draw() {
}
```

### Tables
### Data Wrangling
View the [Mauna Loa example](/examples/mauna-loa/).
```javascript
let co2;
let data;

function preload() {
co2 = loadTable('co2.csv', 'csv', 'header', wrangle);
data = loadTable('co2.csv', 'csv', 'header');
}

function setup() {
noCanvas();
print('Atmospheric Carbon Dioxide at Mauna Loa');
co2.head();
}

function wrangle(table) {
table.parseDates('date');
table.inferTypes();
noCanvas()
const results = tidy(
data,
filter((d) => d.mean > 400),
);
tidy(results, debug('Observations greater than 400ppm CO2'));
}
```

Expand Down
2 changes: 1 addition & 1 deletion dist/numero.js

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions dist/numero.js.LICENSE.txt
Expand Up @@ -256,21 +256,4 @@
* Dual licensed under the MIT or GPL Version 2 licenses.
**/

/**
* @license
* Copyright 2018 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/

/** @license See the LICENSE file. */
2 changes: 1 addition & 1 deletion examples/ada/sketch.js
Expand Up @@ -40,7 +40,7 @@ function rescalePortrait(points) {
}

function fft(points) {
const X = num.tidy(() => {
const X = num.scope(() => {
const x = num.complex(points.x, points.y);
const X = num.fft(x);
let re = X.real();
Expand Down
18 changes: 8 additions & 10 deletions examples/mauna-loa/sketch.js
@@ -1,16 +1,14 @@
let co2;
let data;

function preload() {
co2 = loadTable('co2.csv', 'csv', 'header', wrangle);
data = loadTable('co2.csv', 'csv', 'header');
}

function setup() {
noCanvas();
print('Atmospheric Carbon Dioxide at Mauna Loa');
co2.head();
}

function wrangle(table) {
table.parseDates('date');
table.inferTypes();
noCanvas()
const results = tidy(
data,
filter((d) => d.mean > 400),
);
tidy(results, debug('Observations greater than 400ppm CO2'));
}
37 changes: 25 additions & 12 deletions examples/tables/sketch.js
@@ -1,18 +1,31 @@
let iris
let data;

function preload() {
iris = loadTable('../plotting/iris.csv', 'csv', 'header')
data = loadTable('../plotting/iris.csv', 'csv', 'header');
}

function setup() {
noCanvas()
// iris.print() // raw dataset
iris.inferTypes()
// iris.print() // dataset with types inferred
print('Iris dataset summary by column')
let summary = iris.describe()
summary.print()
print('Mean by species')
let mean = iris.groupby('Species').mean()
mean.print()
noCanvas();
tidy(
data,
sliceHead(5),
debug('Beginning of Iris dataset'),
);
tidy(
data,
sliceTail(5),
debug('End of Iris dataset'),
);
tidy(
data,
groupBy('Species', [
summarize({
min: min('PetalLength'),
median: median('PetalLength'),
max: max('PetalLength'),
variance: variance('PetalLength'),
}),
]),
debug('PetalLength summary by species'),
);
}

0 comments on commit af20841

Please sign in to comment.