File tree 4 files changed +19
-18
lines changed
processing_app/basics/arrays
4 files changed +19
-18
lines changed Original file line number Diff line number Diff line change
1
+ # Generic Neuron Class
2
+ # Can be a bias neuron (true or false)
1
3
class Neuron
2
4
attr_reader :output , :connections , :bias
3
5
@@ -15,7 +17,7 @@ def calc_output
15
17
return if bias # do nothing
16
18
sigmoid = -> ( x ) { 1.0 / ( 1.0 + Math . exp ( -x ) ) }
17
19
sum = 0
18
- lbias = 0
20
+ bias_value = 0
19
21
# fstring = 'Looking through %d connections'
20
22
# puts(format(fstring, connections.size))
21
23
connections . each do |c |
@@ -27,13 +29,13 @@ def calc_output
27
29
# This isn't really necessary
28
30
# Ttreating the bias individually in case needed to at some point
29
31
if from . bias
30
- lbias = from . output * c . weight
32
+ bias_value = from . output * c . weight
31
33
else
32
34
sum += from . output * c . weight
33
35
end
34
36
end
35
37
end
36
38
# Output is result of sigmoid function
37
- @output = sigmoid . call ( lbias + sum )
39
+ @output = sigmoid . call ( bias_value + sum )
38
40
end
39
41
end
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env jruby
1
2
require 'propane'
2
3
# The Nature of Code
3
4
# Daniel Shiffman
@@ -8,7 +9,6 @@ class Xor < Propane::App
8
9
load_library :xor
9
10
10
11
require_relative './landscape'
11
- include_package 'nn'
12
12
13
13
ITERATIONS_PER_FRAME = 5
14
14
@@ -23,11 +23,12 @@ def setup
23
23
@nn = Network . new ( 2 , 4 )
24
24
@count = 0
25
25
# Create a list of 4 training inputs
26
- @inputs = [ ]
27
- inputs << [ 1.0 , 0 ]
28
- inputs << [ 0 , 1.0 ]
29
- inputs << [ 1.0 , 1.0 ]
30
- inputs << [ 0 , 0.0 ]
26
+ @inputs = [
27
+ [ 1.0 , 0 ] ,
28
+ [ 0 , 1.0 ] ,
29
+ [ 1.0 , 1.0 ] ,
30
+ [ 0 , 0.0 ]
31
+ ]
31
32
end
32
33
33
34
def draw
Original file line number Diff line number Diff line change 7
7
# In this example, an array named "coswave" is created using ruby
8
8
# map with the cosine values. This data is displayed three
9
9
# separate ways on the screen.
10
- class Array < Propane ::App
10
+ class SimpleArray < Propane ::App
11
11
12
12
attr_reader :coswave
13
13
14
14
def setup
15
- sketch_title 'Array'
15
+ sketch_title 'Simple Array'
16
16
@coswave = ( 0 ..width ) . map do |i |
17
17
Math . cos ( map1d ( i , ( 0 ..width ) , ( 0 ..PI ) ) ) . abs
18
18
end
@@ -34,4 +34,4 @@ def settings
34
34
end
35
35
end
36
36
37
- Array . new
37
+ SimpleArray . new
Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env jruby
2
2
require 'propane'
3
-
3
+ # Demonstrates the use of :grid to create a two-dimensional (2D) array in ruby
4
+ # Values in a 2D array are accessed through two index values.
5
+ # 2D arrays are useful for storing images. In this example, each dot
6
+ # is colored in relation to its distance from the center of the image.
4
7
class Array2d < Propane ::App
5
- # Demonstrates the use of :grid to create a two-dimensional (2D) array in ruby
6
- # Values in a 2D array are accessed through two index values.
7
- # 2D arrays are useful for storing images. In this example, each dot
8
- # is colored in relation to its distance from the center of the image.
9
-
10
8
attr_reader :distances
11
9
12
10
def setup
You can’t perform that action at this time.
0 commit comments