This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require './stickpig' | |
| 100.times do |i| | |
| stick = StickpigScript.new(0.4) | |
| puts "#{i}, #{stick.script.length}" + | |
| [-20,-10,-1,0,1,10,20].inject("") {|line, x| line + ", #{stick.evaluate(x).round(5)}"} | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Float | |
| alias :add :+ | |
| alias :subtract :- | |
| alias :multiply :* | |
| alias :negate :-@ | |
| def divide(arg2) | |
| arg2==0 ? 0.0 : self / arg2 | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| x | y | |
|---|---|---|
| -499.357 | -5.173 | |
| -447.544 | -5.173 | |
| -418.335 | -5.173 | |
| -366.129 | -5.173 | |
| -342.084 | -5.173 | |
| -317.926 | -5.173 | |
| -273.301 | -5.173 | |
| -268.65 | -5.173 | |
| -183.161 | -5.173 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def score(a=0,b=1,c=2,d=3,e=4) | |
| puts "a: #{a.class}" | |
| puts "b: #{b.class}" | |
| puts "c: #{c.class}" | |
| puts "d: #{d.class}" | |
| puts "e: #{e.class}" | |
| scores = Array.new | |
| scores << a << b << c << d << e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Feature: Pile interpreter handles tokens as expected | |
| In order to get consistent behavior when executing Pile scripts | |
| As a symbolic regression modeler | |
| I want each of the six basic token types to bring about expected changes in the Pile interpreter stack | |
| Scenario: numerical constants are pushed onto the interpreter stack | |
| Given the Pile script "-91.21" | |
| When I execute it | |
| Then there should be 1 item on the stack |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Feature: random Pile script generator | |
| In order to get sample arbitrary Pile solutions to a target problem | |
| As a symbolic regression modeler | |
| I want to be able to compose random Pile scripts, sampled from a set of tokens | |
| Scenario: sample available tokens uniformly | |
| When I generate 10000 random Pile scripts, each with 20 tokens | |
| And the available tokens are ["a", "b", "c"] | |
| Then the tokens should appear (on average) with equal frequency |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Feature: Pile return values | |
| In order to interpret a Pile script as a function of x | |
| As a symbolic regression modeler | |
| I want a scalar value to be returned from any executed script | |
| Scenario: return value is the top stack item after execution | |
| Given the Pile script "1.2 3.4 +" | |
| When I execute it with x = 1 | |
| Then the returned value should be 4.6 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Feature: Symbolic regression scoring against x+6 dataset | |
| In order to evaluate how well a Pile script models a given dataset | |
| As a symbolic regression modeler | |
| I want the score of a given script against a dataset to be the RSS value | |
| Scenario: score for a perfect program should be 0.0 | |
| Given the Pile script "x 6.0 +" | |
| And the training data is "x_plus_6.csv" | |
| When I score the script | |
| Then the score should be 0.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Feature: One-point uneven crossover works as specified | |
| In order to combine "good ideas" that have arisen independently in different Pile scripts | |
| As a symbolic regression modeler | |
| I want crossover to snip scripts up and stick them back together | |
| Scenario: crossover conserves the number of tokens | |
| Given parent_1 is the Pile script "+ + + + + + + + + +" | |
| And parent_2 is the Pile script "- - - - - - - - - -" | |
| When I apply uneven one-point crossover to those parents | |
| Then the result is a collection of 2 Pile scripts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Feature: Uniform mutation works as specified | |
| In order to discover new beneficial variations of scripts that are already OK | |
| As a symbolic regression modeler | |
| I want uniform mutation to replace tokens in "parent" scripts with new random tokens | |
| Scenario: uniform mutation replaces tokens with uniform random sample of available tokens | |
| Given parent_1 is the Pile script "+ + + + + + + + + +" | |
| And the available tokens are ["a", "b", "c", "d", "e"] | |
| And the chance of mutation is p=1.0 |