Skip to content

Instantly share code, notes, and snippets.

Avatar
🫖
Exploring Computer Graphics

n8programs N8python

🫖
Exploring Computer Graphics
View GitHub Profile
@N8python
N8python / complexNeuron.js
Created Nov 30, 2020
This neuron has a 2-layer polynomial activation function, combined with a sigmoid at the end.
View complexNeuron.js
const data = [
[
[0, 0], 1
],
[
[0, 1], 0
],
[
[1, 0], 0
],
@N8python
N8python / xorModel.js
Last active Nov 30, 2020
6 parameter model. Learns xor blazing fast.
View xorModel.js
const data = [
[
[0, 0], 1
],
[
[0, 1], 0
],
[
[1, 0], 0
],
View decoderMnist.js
(async() => {
const model = await tf.loadLayersModel('file://./encoder-model/model.json');
const input = tf.input({ shape: [2] });
const dense1 = model.layers[4].apply(input);
const dense2 = model.layers[5].apply(dense1);
const dense3 = model.layers[6].apply(dense2);
const dense4 = model.layers[7].apply(dense3);
const decoder = tf.model({ inputs: input, outputs: dense4 });
await decoder.save(`file://./decoder-model`);
mnistToImage(decoder.predict(tf.tensor([
View mnistAutoEncoder.js
const tf = require("@tensorflow/tfjs-node");
const fs = require("fs");
const mnistToImage = require("./mnist-image.js");
function oneHotEncode(num) {
const arr = Array(10).fill(0);
arr[num] = 1;
return arr;
}
const trainData = JSON.parse(fs.readFileSync("mnist_handwritten_train.json").toString());
View classify-mnist.js
const tf = require("@tensorflow/tfjs-node");
const fs = require("fs");
const { encode } = require("punycode");
function oneHotEncode(num) {
const arr = Array(10).fill(0);
arr[num] = 1;
return arr;
}
const trainData = JSON.parse(fs.readFileSync("mnist_handwritten_train.json").toString());
View char-lstm.js
async function main() {
const fs = require("fs");
const R = require("ramda");
const tf = require("@tensorflow/tfjs-node");
const fsExtra = require('fs-extra');
const text = fs.readFileSync("input.txt").toString();
const chars = Array.from(new Set(text.split("")));
const encoding = Object.fromEntries(chars.map((x, i) => [x, i]));
const decoding = Object.fromEntries(chars.map((x, i) => [i, x]));
const sampleLength = 50;
View char-lstm.js
const fs = require("fs");
const R = require("ramda");
const tf = require("@tensorflow/tfjs-node");
const fsExtra = require('fs-extra')
const text = fs.readFileSync("input.txt").toString();
const chars = Array.from(new Set(text.split("")));
const encoding = Object.fromEntries(chars.map((x, i) => [x, i]));
const decoding = Object.fromEntries(chars.map((x, i) => [i, x]));
const sampleLength = 20; // when I change this to 100, my lstm's loss goes to NaN
const epochSize = 5000;
@N8python
N8python / terrainAutomata.js
Created Sep 3, 2020
Terrain generation using p5js and cellular automata.
View terrainAutomata.js
const SQUARE_SIZE = 5;
let storage = [];
function setup() {
createCanvas(600, 600);
for (let x = 0; x < width / SQUARE_SIZE; x++) {
storage[x] = [];
for (let y = 0; y < height / SQUARE_SIZE; y++) {
storage[x].push((Math.random() > 0.5) ? "red" : "blue")
}
View covid-model.R
library(deSolve)
library(reshape2)
library(ggplot2)
N <- 1000
initial_state_values <- c(
S = 0.999,
E = 0,
IMI = 0.001,
IM = 0,
A = 0,
View sir-dynamic.R
runs <- 1
for(run in 1:runs) {
beta <- 0.65
gamma <- 0.15
N <- 1000
S <- c(999)
I <- c(1)
R <- c(0)
for(i in 1:(7*8)){
l <- rbinom(1, round(I[length(I)]), beta)