File tree Expand file tree Collapse file tree 4 files changed +19
-18
lines changed
processing_app/basics/arrays Expand file tree Collapse file tree 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)
13class Neuron
24 attr_reader :output , :connections , :bias
35
@@ -15,7 +17,7 @@ def calc_output
1517 return if bias # do nothing
1618 sigmoid = -> ( x ) { 1.0 / ( 1.0 + Math . exp ( -x ) ) }
1719 sum = 0
18- lbias = 0
20+ bias_value = 0
1921 # fstring = 'Looking through %d connections'
2022 # puts(format(fstring, connections.size))
2123 connections . each do |c |
@@ -27,13 +29,13 @@ def calc_output
2729 # This isn't really necessary
2830 # Ttreating the bias individually in case needed to at some point
2931 if from . bias
30- lbias = from . output * c . weight
32+ bias_value = from . output * c . weight
3133 else
3234 sum += from . output * c . weight
3335 end
3436 end
3537 end
3638 # Output is result of sigmoid function
37- @output = sigmoid . call ( lbias + sum )
39+ @output = sigmoid . call ( bias_value + sum )
3840 end
3941end
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env jruby
12require 'propane'
23# The Nature of Code
34# Daniel Shiffman
@@ -8,7 +9,6 @@ class Xor < Propane::App
89 load_library :xor
910
1011 require_relative './landscape'
11- include_package 'nn'
1212
1313 ITERATIONS_PER_FRAME = 5
1414
@@ -23,11 +23,12 @@ def setup
2323 @nn = Network . new ( 2 , 4 )
2424 @count = 0
2525 # 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+ ]
3132 end
3233
3334 def draw
Original file line number Diff line number Diff line change 77# In this example, an array named "coswave" is created using ruby
88# map with the cosine values. This data is displayed three
99# separate ways on the screen.
10- class Array < Propane ::App
10+ class SimpleArray < Propane ::App
1111
1212 attr_reader :coswave
1313
1414 def setup
15- sketch_title 'Array'
15+ sketch_title 'Simple Array'
1616 @coswave = ( 0 ..width ) . map do |i |
1717 Math . cos ( map1d ( i , ( 0 ..width ) , ( 0 ..PI ) ) ) . abs
1818 end
@@ -34,4 +34,4 @@ def settings
3434 end
3535end
3636
37- Array . new
37+ SimpleArray . new
Original file line number Diff line number Diff line change 11#!/usr/bin/env jruby
22require '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.
47class 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-
108 attr_reader :distances
119
1210 def setup
You can’t perform that action at this time.
0 commit comments