Module: AssociativeMemory
- Defined in:
- lib/associative_memory.rb,
lib/associative_memory/network.rb
Defined Under Namespace
Classes: Network
Constant Summary collapse
- VERSION =
'0.2.2'
Class Attribute Summary collapse
-
.associated_pairs ⇒ Object
Returns the value of attribute associated_pairs.
-
.input_keyspace ⇒ Object
Returns the value of attribute input_keyspace.
-
.network ⇒ Object
Returns the value of attribute network.
-
.output_keyspace ⇒ Object
Returns the value of attribute output_keyspace.
Class Method Summary collapse
- .associate(inputs = [], outputs = []) ⇒ Object
- .describe(vector) ⇒ Object
- .new(options = {}) ⇒ Object
- .pretty_inspect ⇒ Object
- .valid? ⇒ Boolean
Class Attribute Details
.associated_pairs ⇒ Object
Returns the value of attribute associated_pairs.
8 9 10 |
# File 'lib/associative_memory.rb', line 8 def associated_pairs @associated_pairs end |
.input_keyspace ⇒ Object
Returns the value of attribute input_keyspace.
8 9 10 |
# File 'lib/associative_memory.rb', line 8 def input_keyspace @input_keyspace end |
.network ⇒ Object
Returns the value of attribute network.
8 9 10 |
# File 'lib/associative_memory.rb', line 8 def network @network end |
.output_keyspace ⇒ Object
Returns the value of attribute output_keyspace.
8 9 10 |
# File 'lib/associative_memory.rb', line 8 def output_keyspace @output_keyspace end |
Class Method Details
.associate(inputs = [], outputs = []) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/associative_memory.rb', line 17 def associate(inputs=[], outputs=[]) existing_input_keyspace_length = self.input_keyspace.length existing_output_keyspace_length = self.output_keyspace.length # Determine updated keyspace mapping self.associated_pairs.push([inputs, outputs]) self.input_keyspace = self.associated_pairs.map{|pair| pair[0]}.flatten.uniq.sort self.output_keyspace = self.associated_pairs.map{|pair| pair[1]}.flatten.uniq.sort @input_bitmask = self.input_keyspace.map{|element| if inputs.include?(element) then 1 else 0 end } @output_bitmask = self.output_keyspace.map{|element| if outputs.include?(element) then 1 else 0 end } # If this new association changes the cardinality of our input or # output pattern space, refresh structure of the network if self.input_keyspace.length != existing_input_keyspace_length || self.output_keyspace.length != existing_output_keyspace_length self.network = AssociativeMemory::Network.new self.associated_pairs.each{|pair| pairwise_input_bitmask = self.input_keyspace.map{|element| if pair[0].include?(element) then 1 else 0 end } pairwise_output_bitmask = self.output_keyspace.map{|element| if pair[1].include?(element) then 1 else 0 end } self.network.learn(pairwise_input_bitmask,pairwise_output_bitmask) } else self.network.learn(@input_bitmask, @output_bitmask) end end |
.describe(vector) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/associative_memory.rb', line 42 def describe(vector) description = [] # Search forward through the input keyspace input_bitmask = self.input_keyspace.map{|input_key| if vector.include?(input_key) then 1 else 0 end } if input_bitmask.include?(1) convergence_bitmask = self.network.converge_and_bitmask_input(input_bitmask) self.output_keyspace.each_with_index do |output_key, index| if convergence_bitmask[index] == 1 description.push(output_key) end end end # Search backwards through the output keyspace output_bitmask = self.output_keyspace.map{|output_key| if vector.include?(output_key) then 1 else 0 end } if output_bitmask.include?(1) convergence_bitmask = self.network.converge_and_bitmask_output(output_bitmask) convergence_vector = self.network.converge_output(output_bitmask) self.input_keyspace.each_with_index do |input_key, index| if convergence_bitmask[index] == 1 description.push(input_key) end end end return description.sort.uniq end |
.new(options = {}) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/associative_memory.rb', line 10 def new(={}) self.associated_pairs = [] self.input_keyspace = [] self.output_keyspace = [] return self end |
.pretty_inspect ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/associative_memory.rb', line 75 def pretty_inspect "associative_memory object: #{self.object_id}\n\n" + "associated_pairs\n" + "----------------\n" + self.associated_pairs.map{|a| a.inspect}.join("\n") + "\n\n" + "input_keyspace\n" + "--------------\n" + self.input_keyspace.inspect + "\n\n" + "output_keyspace\n" + "---------------\n" + self.output_keyspace.inspect + "\n\n" + "convergence network\n" + "-------------------\n" + self.network.matrix.map{|a| a.inspect}.join("\n") + "\n\n" end |
.valid? ⇒ Boolean
71 72 73 |
# File 'lib/associative_memory.rb', line 71 def valid? return self.associated_pairs.length > 0 &&self.input_keyspace.length > 0 &&self.output_keyspace.length > 0 && self.network.valid? end |