Skip to content
No description or website provided.
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
nodes
README
genetic_programmer.rb
node.rb

README

require "./genetic_programmer.rb"
# => true 

gp = GeneticProgrammer
ex1 = gp.example_1
# => #<Node::Operator:0x00000102079ba0 @operation=:if_method, @name="if_method_1320984332", @operands=[#<Node::Operator:0x0000010207a0f0 @operation=:greater_method, @name="greater_method_1320984332", @operands=[#<Node::Parameter:0x0000010207a1b8 @index=0>, #<Node::Constant:0x0000010207a190 @value=3>]>, #<Node::Operator:0x00000102079f60 @operation=:add_method, @name="add_method_1320984332", @operands=[#<Node::Parameter:0x00000102079fd8 @index=1>, #<Node::Constant:0x00000102079fb0 @value=5>]>, #<Node::Operator:0x00000102079d08 @operation=:subtract_method, @name="subtract_method_1320984332", @operands=[#<Node::Parameter:0x00000102079e48 @index=1>, #<Node::Constant:0x00000102079da8 @value=2>]>]> 

Node.method_modules
# => [Node::Operation::If, Node::Operation::Greater, Node::Operation::Add, Node::Operation::Subtract] 
Node.node_methods
## => [:if_method, :greater_method, :add_method, :subtract_method] 

ex1.display; 0
#{:@name=>"if_method_1321064018"}
#  {:@name=>"greater_method_1321064018"}
#    {:@index=>0}
#    {:@value=>3}
#  {:@name=>"add_method_1321064018"}
#    {:@index=>1}
#    {:@value=>5}
#  {:@name=>"subtract_method_1321064018"}
#    {:@index=>1}
#    {:@value=>2}
# => 0 
ex1.evaluate([5,3])
# => 8 
ex1.evaluate([2,3])
# => 1 

data_size = 2
random1 = Node.random data_size
# => #<Node::Operator:0x00000100a43020 @operation=:add_method, @name="add_method_1320987083", @operands=[#<Node::Constant:0x00000100a430c0 @value=9>, #<Node::Parameter:0x00000100a43048 @index=1>]> 
random2 = Node.random(data_size)
# => #<Node::Operator:0x0000010097d780 @operation=:greater_method, @name="greater_method_1321075445", @operands=[#<Node::Operator:0x0000010097d988 @operation=:greater_method, @name="greater_method_1321075445", @operands=[#<Node::Constant:0x0000010097da78 @value=2>, #<Node::Constant:0x0000010097d9b0 @value=11>]>, #<Node::Parameter:0x0000010097d7a8 @index=0>]> 
random1.display; 0
{:@name=>"add_method_1320987083"}
	{:@value=>9}
	{:@index=>1}
# => 0 

random1.evaluate [2,3]
# => 12

random1.squared_difference gp.input_output_rows

random1_prime = random1.mutate data_size
random2_prime = random2.mutate data_size

random1_prime == random1
random2_prime == random2
# => true ( or false )

random_cross = random1.crossover(random2)
Something went wrong with that request. Please try again.