Skip to content

Commit 48cd35f

Browse files
committed
Second wave of file commits.
1 parent 1ebd431 commit 48cd35f

File tree

512 files changed

+125972
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

512 files changed

+125972
-0
lines changed

data/gcHeatmap.R

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
library("psych")
2+
library("akima")
3+
# Read the data into a dataframe called gc.
4+
gc <- read.table("gc.csv", header = T, sep=",")
5+
6+
# Output columns
7+
names(gc)
8+
9+
im <- with(gc, interp(Timestamp,EU,OU))
10+
with(im,image(x,y,z))
11+
12+
# Descriptive statistics for the variables in the dataframe called ratings
13+
describe(gc)

data/iris.csv

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
Sepal Length,Sepal Width,Petal Length,Petal Width,Species
2+
5.1,3.5,1.4,0.2,setosa
3+
4.9,3.0,1.4,0.2,setosa
4+
4.7,3.2,1.3,0.2,setosa
5+
4.6,3.1,1.5,0.2,setosa
6+
5.0,3.6,1.4,0.2,setosa
7+
5.4,3.9,1.7,0.4,setosa
8+
4.6,3.4,1.4,0.3,setosa
9+
5.0,3.4,1.5,0.2,setosa
10+
4.4,2.9,1.4,0.2,setosa
11+
4.9,3.1,1.5,0.1,setosa
12+
5.4,3.7,1.5,0.2,setosa
13+
4.8,3.4,1.6,0.2,setosa
14+
4.8,3.0,1.4,0.1,setosa
15+
4.3,3.0,1.1,0.1,setosa
16+
5.8,4.0,1.2,0.2,setosa
17+
5.7,4.4,1.5,0.4,setosa
18+
5.4,3.9,1.3,0.4,setosa
19+
5.1,3.5,1.4,0.3,setosa
20+
5.7,3.8,1.7,0.3,setosa
21+
5.1,3.8,1.5,0.3,setosa
22+
5.4,3.4,1.7,0.2,setosa
23+
5.1,3.7,1.5,0.4,setosa
24+
4.6,3.6,1.0,0.2,setosa
25+
5.1,3.3,1.7,0.5,setosa
26+
4.8,3.4,1.9,0.2,setosa
27+
5.0,3.0,1.6,0.2,setosa
28+
5.0,3.4,1.6,0.4,setosa
29+
5.2,3.5,1.5,0.2,setosa
30+
5.2,3.4,1.4,0.2,setosa
31+
4.7,3.2,1.6,0.2,setosa
32+
4.8,3.1,1.6,0.2,setosa
33+
5.4,3.4,1.5,0.4,setosa
34+
5.2,4.1,1.5,0.1,setosa
35+
5.5,4.2,1.4,0.2,setosa
36+
4.9,3.1,1.5,0.1,setosa
37+
5.0,3.2,1.2,0.2,setosa
38+
5.5,3.5,1.3,0.2,setosa
39+
4.9,3.1,1.5,0.1,setosa
40+
4.4,3.0,1.3,0.2,setosa
41+
5.1,3.4,1.5,0.2,setosa
42+
5.0,3.5,1.3,0.3,setosa
43+
4.5,2.3,1.3,0.3,setosa
44+
4.4,3.2,1.3,0.2,setosa
45+
5.0,3.5,1.6,0.6,setosa
46+
5.1,3.8,1.9,0.4,setosa
47+
4.8,3.0,1.4,0.3,setosa
48+
5.1,3.8,1.6,0.2,setosa
49+
4.6,3.2,1.4,0.2,setosa
50+
5.3,3.7,1.5,0.2,setosa
51+
5.0,3.3,1.4,0.2,setosa
52+
7.0,3.2,4.7,1.4,versicolor
53+
6.4,3.2,4.5,1.5,versicolor
54+
6.9,3.1,4.9,1.5,versicolor
55+
5.5,2.3,4.0,1.3,versicolor
56+
6.5,2.8,4.6,1.5,versicolor
57+
5.7,2.8,4.5,1.3,versicolor
58+
6.3,3.3,4.7,1.6,versicolor
59+
4.9,2.4,3.3,1.0,versicolor
60+
6.6,2.9,4.6,1.3,versicolor
61+
5.2,2.7,3.9,1.4,versicolor
62+
5.0,2.0,3.5,1.0,versicolor
63+
5.9,3.0,4.2,1.5,versicolor
64+
6.0,2.2,4.0,1.0,versicolor
65+
6.1,2.9,4.7,1.4,versicolor
66+
5.6,2.9,3.6,1.3,versicolor
67+
6.7,3.1,4.4,1.4,versicolor
68+
5.6,3.0,4.5,1.5,versicolor
69+
5.8,2.7,4.1,1.0,versicolor
70+
6.2,2.2,4.5,1.5,versicolor
71+
5.6,2.5,3.9,1.1,versicolor
72+
5.9,3.2,4.8,1.8,versicolor
73+
6.1,2.8,4.0,1.3,versicolor
74+
6.3,2.5,4.9,1.5,versicolor
75+
6.1,2.8,4.7,1.2,versicolor
76+
6.4,2.9,4.3,1.3,versicolor
77+
6.6,3.0,4.4,1.4,versicolor
78+
6.8,2.8,4.8,1.4,versicolor
79+
6.7,3.0,5.0,1.7,versicolor
80+
6.0,2.9,4.5,1.5,versicolor
81+
5.7,2.6,3.5,1.0,versicolor
82+
5.5,2.4,3.8,1.1,versicolor
83+
5.5,2.4,3.7,1.0,versicolor
84+
5.8,2.7,3.9,1.2,versicolor
85+
6.0,2.7,5.1,1.6,versicolor
86+
5.4,3.0,4.5,1.5,versicolor
87+
6.0,3.4,4.5,1.6,versicolor
88+
6.7,3.1,4.7,1.5,versicolor
89+
6.3,2.3,4.4,1.3,versicolor
90+
5.6,3.0,4.1,1.3,versicolor
91+
5.5,2.5,4.0,1.3,versicolor
92+
5.5,2.6,4.4,1.2,versicolor
93+
6.1,3.0,4.6,1.4,versicolor
94+
5.8,2.6,4.0,1.2,versicolor
95+
5.0,2.3,3.3,1.0,versicolor
96+
5.6,2.7,4.2,1.3,versicolor
97+
5.7,3.0,4.2,1.2,versicolor
98+
5.7,2.9,4.2,1.3,versicolor
99+
6.2,2.9,4.3,1.3,versicolor
100+
5.1,2.5,3.0,1.1,versicolor
101+
5.7,2.8,4.1,1.3,versicolor
102+
6.3,3.3,6.0,2.5,virginica
103+
5.8,2.7,5.1,1.9,virginica
104+
7.1,3.0,5.9,2.1,virginica
105+
6.3,2.9,5.6,1.8,virginica
106+
6.5,3.0,5.8,2.2,virginica
107+
7.6,3.0,6.6,2.1,virginica
108+
4.9,2.5,4.5,1.7,virginica
109+
7.3,2.9,6.3,1.8,virginica
110+
6.7,2.5,5.8,1.8,virginica
111+
7.2,3.6,6.1,2.5,virginica
112+
6.5,3.2,5.1,2.0,virginica
113+
6.4,2.7,5.3,1.9,virginica
114+
6.8,3.0,5.5,2.1,virginica
115+
5.7,2.5,5.0,2.0,virginica
116+
5.8,2.8,5.1,2.4,virginica
117+
6.4,3.2,5.3,2.3,virginica
118+
6.5,3.0,5.5,1.8,virginica
119+
7.7,3.8,6.7,2.2,virginica
120+
7.7,2.6,6.9,2.3,virginica
121+
6.0,2.2,5.0,1.5,virginica
122+
6.9,3.2,5.7,2.3,virginica
123+
5.6,2.8,4.9,2.0,virginica
124+
7.7,2.8,6.7,2.0,virginica
125+
6.3,2.7,4.9,1.8,virginica
126+
6.7,3.3,5.7,2.1,virginica
127+
7.2,3.2,6.0,1.8,virginica
128+
6.2,2.8,4.8,1.8,virginica
129+
6.1,3.0,4.9,1.8,virginica
130+
6.4,2.8,5.6,2.1,virginica
131+
7.2,3.0,5.8,1.6,virginica
132+
7.4,2.8,6.1,1.9,virginica
133+
7.9,3.8,6.4,2.0,virginica
134+
6.4,2.8,5.6,2.2,virginica
135+
6.3,2.8,5.1,1.5,virginica
136+
6.1,2.6,5.6,1.4,virginica
137+
7.7,3.0,6.1,2.3,virginica
138+
6.3,3.4,5.6,2.4,virginica
139+
6.4,3.1,5.5,1.8,virginica
140+
6.0,3.0,4.8,1.8,virginica
141+
6.9,3.1,5.4,2.1,virginica
142+
6.7,3.1,5.6,2.4,virginica
143+
6.9,3.1,5.1,2.3,virginica
144+
5.8,2.7,5.1,1.9,virginica
145+
6.8,3.2,5.9,2.3,virginica
146+
6.7,3.3,5.7,2.5,virginica
147+
6.7,3.0,5.2,2.3,virginica
148+
6.3,2.5,5.0,1.9,virginica
149+
6.5,3.0,5.2,2.0,virginica
150+
6.2,3.4,5.4,2.3,virginica
151+
5.9,3.0,5.1,1.8,virginica

scripts/processing/NetworkFlow.pde

+224
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
// An animated drawing of a Neural Network
2+
// Daniel Shiffman <http://www.shiffman.net>
3+
// Nature of Code
4+
5+
Network network;
6+
7+
void setup() {
8+
size(800, 200);
9+
smooth();
10+
11+
// Create the Network object
12+
network = new Network(width/2, height/2);
13+
14+
// Create a bunch of Neurons
15+
Neuron a = new Neuron(-350, 0);
16+
Neuron b = new Neuron(-200, 0);
17+
Neuron c = new Neuron(0, 75);
18+
Neuron d = new Neuron(0, -75);
19+
Neuron e = new Neuron(200, 0);
20+
Neuron f = new Neuron(350, 0);
21+
22+
// Connect them
23+
network.connect(a, b,1);
24+
network.connect(b, c,random(1));
25+
network.connect(b, d,random(1));
26+
network.connect(c, e,random(1));
27+
network.connect(d, e,random(1));
28+
network.connect(e, f,1);
29+
30+
// Add them to the Network
31+
network.addNeuron(a);
32+
network.addNeuron(b);
33+
network.addNeuron(c);
34+
network.addNeuron(d);
35+
network.addNeuron(e);
36+
network.addNeuron(f);
37+
}
38+
39+
void draw() {
40+
background(255);
41+
// Update and display the Network
42+
network.update();
43+
network.display();
44+
45+
// Every 30 frames feed in an input
46+
if (frameCount % 30 == 0) {
47+
network.feedforward(random(1));
48+
}
49+
}
50+
51+
class Network {
52+
53+
// The Network has a list of neurons
54+
ArrayList<Neuron> neurons;
55+
56+
// The Network now keeps a duplicate list of all Connection objects.
57+
// This makes it easier to draw everything in this class
58+
ArrayList<Connection> connections;
59+
PVector location;
60+
61+
Network(float x, float y) {
62+
location = new PVector(x, y);
63+
neurons = new ArrayList<Neuron>();
64+
connections = new ArrayList<Connection>();
65+
}
66+
67+
// We can add a Neuron
68+
void addNeuron(Neuron n) {
69+
neurons.add(n);
70+
}
71+
72+
// We can connection two Neurons
73+
void connect(Neuron a, Neuron b, float weight) {
74+
Connection c = new Connection(a, b, weight);
75+
a.addConnection(c);
76+
// Also add the Connection here
77+
connections.add(c);
78+
}
79+
80+
// Sending an input to the first Neuron
81+
// We should do something better to track multiple inputs
82+
void feedforward(float input) {
83+
Neuron start = neurons.get(0);
84+
start.feedforward(input);
85+
}
86+
87+
// Update the animation
88+
void update() {
89+
for (Connection c : connections) {
90+
c.update();
91+
}
92+
}
93+
94+
// Draw everything
95+
void display() {
96+
pushMatrix();
97+
translate(location.x, location.y);
98+
for (Neuron n : neurons) {
99+
n.display();
100+
}
101+
102+
for (Connection c : connections) {
103+
c.display();
104+
}
105+
popMatrix();
106+
}
107+
}
108+
109+
class Connection {
110+
// Connection is from Neuron A to B
111+
Neuron a;
112+
Neuron b;
113+
114+
// Connection has a weight
115+
float weight;
116+
117+
// Variables to track the animation
118+
boolean sending = false;
119+
PVector sender;
120+
121+
// Need to store the output for when its time to pass along
122+
float output = 0;
123+
124+
Connection(Neuron from, Neuron to, float w) {
125+
weight = w;
126+
a = from;
127+
b = to;
128+
}
129+
130+
131+
// The Connection is active
132+
void feedforward(float val) {
133+
output = val*weight; // Compute output
134+
sender = a.location.get(); // Start animation at Neuron A
135+
sending = true; // Turn on sending
136+
}
137+
138+
// Update traveling sender
139+
void update() {
140+
if (sending) {
141+
// Use a simple interpolation
142+
sender.x = lerp(sender.x, b.location.x, 0.1);
143+
sender.y = lerp(sender.y, b.location.y, 0.1);
144+
float d = PVector.dist(sender, b.location);
145+
// If we've reached the end
146+
if (d < 1) {
147+
// Pass along the output!
148+
b.feedforward(output);
149+
sending = false;
150+
}
151+
}
152+
}
153+
154+
// Draw line and traveling circle
155+
void display() {
156+
stroke(0);
157+
strokeWeight(1+weight*4);
158+
line(a.location.x, a.location.y, b.location.x, b.location.y);
159+
160+
if (sending) {
161+
fill(0);
162+
strokeWeight(1);
163+
ellipse(sender.x, sender.y, 16, 16);
164+
}
165+
}
166+
}
167+
168+
class Neuron {
169+
// Neuron has a location
170+
PVector location;
171+
172+
// Neuron has a list of connections
173+
ArrayList<Connection> connections;
174+
175+
// We now track the inputs and sum them
176+
float sum = 0;
177+
178+
// The Neuron's size can be animated
179+
float r = 32;
180+
181+
Neuron(float x, float y) {
182+
location = new PVector(x, y);
183+
connections = new ArrayList<Connection>();
184+
}
185+
186+
// Add a Connection
187+
void addConnection(Connection c) {
188+
connections.add(c);
189+
}
190+
191+
// Receive an input
192+
void feedforward(float input) {
193+
// Accumulate it
194+
sum += input;
195+
// Activate it?
196+
if (sum > 1) {
197+
fire();
198+
sum = 0; // Reset the sum to 0 if it fires
199+
}
200+
}
201+
202+
// The Neuron fires
203+
void fire() {
204+
r = 64; // It suddenly is bigger
205+
206+
// We send the output through all connections
207+
for (Connection c : connections) {
208+
c.feedforward(sum);
209+
}
210+
}
211+
212+
// Draw it as a circle
213+
void display() {
214+
stroke(0);
215+
strokeWeight(1);
216+
// Brightness is mapped to sum
217+
float b = map(sum,0,1,255,0);
218+
fill(b);
219+
ellipse(location.x, location.y, r, r);
220+
221+
// Size shrinks down back to original dimensions
222+
r = lerp(r,32,0.1);
223+
}
224+
}

0 commit comments

Comments
 (0)