Skip to content

Instantly share code, notes, and snippets.

View N8python's full-sized avatar
🫖
Exploring Computer Graphics

n8programs N8python

🫖
Exploring Computer Graphics
View GitHub Profile
@N8python
N8python / transmission.glsl
Created January 6, 2023 15:22
Chromatic aberration/refraction shader
vec3 transmission = vec3(0.0);
float transmissionR, transmissionB, transmissionG;
float randomCoords = rand();
float thickness_smear = thickness * max(pow(roughness, 0.33), anisotropy);
vec3 distortionNormal = vec3(0.0);
vec3 temporalOffset = vec3(time, -time, -time) * temporalDistortion;
if (distortion > 0.0) {
distortionNormal = distortion * vec3(snoiseFractal(vec3((pos * distortionScale + temporalOffset))), snoiseFractal(vec3(pos.zxy * distortionScale - temporalOffset)), snoiseFractal(vec3(pos.yxz * distortionScale + temporalOffset)));
}
for (float i = 0.0; i < ${samples}.0; i ++) {
@N8python
N8python / complexNeuron.js
Created November 30, 2020 02:07
This neuron has a 2-layer polynomial activation function, combined with a sigmoid at the end.
const data = [
[
[0, 0], 1
],
[
[0, 1], 0
],
[
[1, 0], 0
],
@N8python
N8python / xorModel.js
Last active November 30, 2020 00:45
6 parameter model. Learns xor blazing fast.
const data = [
[
[0, 0], 1
],
[
[0, 1], 0
],
[
[1, 0], 0
],
(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([
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());
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());
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;
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 September 3, 2020 14:54
Terrain generation using p5js and cellular automata.
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")
}
library(deSolve)
library(reshape2)
library(ggplot2)
N <- 1000
initial_state_values <- c(
S = 0.999,
E = 0,
IMI = 0.001,
IM = 0,
A = 0,