Permalink
Browse files

merge

  • Loading branch information...
ai committed Mar 10, 2012
2 parents 192a719 + e701b0d commit 46e4ca3e545a03cccec11fc5732ecf3f387d0397
View
File renamed without changes.
View
144 README.md
@@ -1,28 +1,26 @@
-# Evolu
+# Evolu Lang
-*Project is moved to <https://github.com/ai/evolu-lang>.*
-
-Evolu is a programming language to automatically generate programs by evolution
-(genetic programming). Generator (genetic algorithm, particle swarm optimization
-or other) will use Evolu to compile bytes with random mutations (gene) to
-program, run and test it.
+Evolu Lang is a programming language to automatically generate programs by
+evolution (genetic programming). Generator (genetic algorithm, particle swarm
+optimization or other) will use Evolu Lang to compile bytes with random
+mutations (gene) to program, run and test it.
It is created to be readable by human beings (instead of
artificial neural networks) and easily editable and mixable for genetic
algorithm (instead of tree structure and modern production languages).
## How It Works
-A developer defines commands by Evolu to create a business specific language
-(or uses the standard commands pack) and defines tests (*fitness*),
+A developer defines commands by Evolu Lang to create a business specific
+language (or uses the standard commands pack) and defines tests (*fitness*),
to determine what program he or she wants to create.
In the next step he or she uses a generator, which uses a genetic algorithm,
particle swarm optimization or other evolutionary algorithms.
In the simplest case:
1. Generator creates an array (*population*) with random bytes (*genes*).
2. It adds random changes (*mutation*) to each byte stream in this array.
-3. It compiles each of these random byte streams by Evolu language and runs
+3. It compiles each of these random byte streams by Evolu Lang and runs
obtained programs with tests.
4. Bad programs will be deleted and best programs will be copied to the
population.
@@ -64,9 +62,10 @@ In the simplest case:
Each Evolu program starts with an `EVOLU:` prefix to check, that the file or
stream contains a program.
-Like XML, Evolu is just a syntax format. So you need to have business-specific
-languages and mark, what language is used in this Evolu program. So, after
-the `EVOLU:` prefix, stream must contain language name and a colon.
+Like XML, Evolu Lang is just a syntax format. So you need to have
+business-specific languages and mark, what language is used in this Evolu
+program. So, after the `EVOLU:` prefix, stream must contain language name and a
+colon.
<program> ::= "EVOLU:" <language> ":" <rules>
@@ -98,7 +97,7 @@ bytes (beginning with `1`) after command encode parameter number. For example,
<parameter> ::= ( 1xxxxxxx )*
There are 127 different commands number in one command byte, but language may
-have less commands. A mutation can generate any bytes and Evolu must try to
+have less commands. A mutation can generate any bytes and Evolu Lang must try to
decode any of them. So, commands are marked numbers in a circle: if language
have 3 commands (`separator`, `a`, `b`), 0 will be encode `separator`, 1 – `a`,
2 – `b`, but 3 will encode `separator` again, 4 – `a`, etc.
@@ -116,7 +115,7 @@ If a rule doesn’t have any conditions it will run once at start as constructor
### Standard Commands Pack
-You can create your own language with Evolu, but for common tasks Evolu has
+You can create your own language with Evolu Lang, but for common tasks it has
the standard commands pack to create Turing completeness languages.
Conditions:
@@ -136,3 +135,118 @@ Commands:
The developer must define, what input and output signals will be in the
language, but variables can be added dynamically by mutation.
+
+## How To
+
+For example, we will generate program (by genetic programming), which calculates
+`tick` signals and on `result` signal it sends whether an `even` or an `odd`
+tick count it received.
+
+### Language
+
+Like XML, Evolu Lang is just a syntax format. So you need to define a language
+for your task using the `evolu.lang.add(name, initializer)` function.
+It receives a language name (to use it as a prefix in the source code for
+storing and transferring the program) and function (which adds the language
+commands to `this`), and returns a new language.
+
+For the common cases you can use the standard commands pack, and you only need
+to define the input/output signals.
+
+ var lang = evolu.lang.add('EVEN-ODD', function() {
+ this.add(evolu.lang.standard.input('tick', 'result'))
+ this.add(evolu.lang.standard.output('even', 'odd'))
+ lang.add(evolu.lang.standard.variables)
+ })
+
+### Population
+
+Get any genetic algorithm library or write it by yourself. Use a byte array
+(array of integers from `0` to `255`, for example `[0, 255, 13, 68, 145]`) as
+genes.
+
+ var population = []
+ // Add 100 genes to the first population
+ for (var i = 0; i < 100; i++) {
+ var gene = []
+ // Each gene will have random length
+ while (Math.random < 0.9) {
+ // Add a random byte to the current gene
+ gene.push(Math.round(255 * Math.random()))
+ }
+ }
+
+### Mutation
+
+*Note that the integers in an array must be from `0` to `255`.*
+
+In the genetic algorithm you can use any types of mutation for a byte stream
+(a lot of libraries contain them). You can add, change, delete and
+move bytes in the array.
+
+You can use crossover to mix arrays or just move a part of bytes from one array
+to another (like horizontal gene transfer).
+
+### Selection
+
+To calculate fitness for each gene in the population, you need to compile
+each byte array:
+
+ var program = lang.compile(population[i])
+
+Send the data to the program and check its output data to calculate fitness.
+It’s like automatic unit testing, but your test must return a score,
+not just a pass/fail result.
+
+If you use the standard commands pack, you can use the `receive_signal` event
+to listen output signals and the `signal` function to send input signals:
+
+ output = []
+ program.listen('receive_signal', function(signal) {
+ output.push(signal)
+ })
+
+ program.signal('tick').signal('tick').signal('result')
+ // Some hypothetical API
+ check(output).to_contain('even')
+
+ output = []
+ program.signal('tick').signal('result')
+ check(output).to_contain('odd')
+
+### Saving
+
+When you generate a program for your demands, you can save it to a disk or send
+to a server:
+
+ var source = bestProgram.toSource()
+
+Source is a string with `EVOLU:` and a language name in prefix. For example,
+`"EVOLU:EVEN-ODD:\x04\x80\x00\x01\x80\x03\x80\x05…"`.
+
+Use `evolu.lang.compile(string)` to automatically find a language (using the source
+prefix) and compile the bytes into a program:
+
+ bestProgram == evolu.lang.compile(bestProgram.toSource())
+
+## Testing
+
+1. Install Rake (Ruby make) and RubyGems (Ruby package manager).
+ For example, on Ubuntu:
+
+ sudo apt-get install rake rubygems
+
+2. Install `jasmin` gem:
+
+ gem install jasmin
+
+3. Run test server:
+
+ rake jamsin
+
+4. Open <http://localhost:8888>.
+
+## License
+
+Evolu Lang is licensed under the GNU Lesser General Public License version 3.
+See the LICENSE file or http://www.gnu.org/licenses/lgpl.html.
View
@@ -0,0 +1,3 @@
+
+require 'jasmine'
+load 'jasmine/tasks/jasmine.rake'
View
@@ -1,2 +0,0 @@
-public/
-script/.sass-cache/
@@ -1,3 +0,0 @@
-- @title = 'Evolu - language for genetic programming'
-%article
- = readme('/')
@@ -1,14 +0,0 @@
-- @title = 'Evolu.js - genetic programming for JavaScript'
-%article
- - html = readme('/js/')
- - html.gsub! 'Evolu.js</h1>', 'Evolu.<span>js</span></h1>'
- - html.gsub! /License<\/h2>[\w\W]+$/, ''
- = html
-
- :markdown
- ## License
-
- Evolu.js is licensed under the
- [GNU Lesser General Public License version 3][lgpl].
-
- [lgpl]: http://www.gnu.org/licenses/lgpl.html
View
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,32 +0,0 @@
-!!! 5
-%head
- %meta( charset="UTF-8" )/
- %title= @title
- %meta( name="keywords" content="evolu, genetic programming, genetic algorithm, programming language, evolution, javascript" )/
- %meta( name="description" content="Evolu is a programming language to genetic programming (automatically generate programs by evolution)" )/
- %link( rel="stylesheet" href="style.css" )/
- %link( href="favicon.ico" rel="icon" type="image/x-icon" )/
- %meta( content="width=device-width; initial-scale=1.0; maximum-scale=1.0" name="viewport" )/
- /[if IE]
- %script( src="http://html5shiv.googlecode.com/svn/trunk/html5.js" )
- - if production?
- :javascript
- var _gaq = _gaq || [];
- _gaq.push(['_setAccount', 'UA-18068035-1']);
- _gaq.push(['_trackPageview']);
- (function() {
- var ga = document.createElement('script'); ga.async = true;
- ga.src = ('https:' == document.location.protocol ?
- 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
- var s = document.getElementsByTagName('script')[0];
- s.parentNode.insertBefore(ga, s);
- })();
-%body
- %header
- #logo
- %nav
- = menu('Language', 'index.html')
- = menu('<abbr title="JavaScript">JS</abbr> interpreter', 'js.html')
- %a( href="http://github.com/ai/evolu" ) Sources
- %a( href="http://github.com/ai/evolu/issues" ) Issues
- = yield
View
Binary file not shown.
View
@@ -1,134 +0,0 @@
-*
- margin: 0
- padding: 0
-
-body
- background: white url(hatching.png) repeat-x 0 0
- color: black
- margin: 0 0.5em 2em 0.5em
- line-height: 1.7
- font-family: Georgia, serif
-
-header, article
- display: block
- width: 34em
- max-width: 100%
- margin: 0 auto
- position: relative
-
-a
- text-decoration: none
- color: black
- border-bottom: 1px solid #999
- &:hover
- border-color: black
-
-header
- line-height: 1
- #logo
- position: absolute
- top: 0
- left: 0
- width: 72px
- height: 72px
- margin: 3.6em 0 0 -100px
- background: url(logo.png) no-repeat 0 0
- a
- padding: 0.7em
- margin: 9px 1px 10px 0
- font-family: "Times New Roman", serif
- letter-spacing: 1px
- text-transform: uppercase
- position: relative
- background: white
- color: black
- float: left
- border: none
- &:last-child
- margin-right: 0
- &.open, &:hover, &:active
- background: black
- color: white
- text-shadow: #ccc 0 0 1px
- &:active
- border: 3px solid black
- outline: 3px solid white
- margin: 6px -2px 0 -3px
- z-index: 2
- div
- margin-right: 1px
- position: absolute
- left: 0
- top: 100%
- height: 7px
- width: 100%
- background: url(arrow.png) no-repeat 50% 100%
-
-article
- clear: both
-
-h1, h2, h3
- margin: 1em 0 0.5em 0
- font-weight: normal
- font-family: Georgia, serif
- line-height: 1.1
- text-shadow: #ccc 1px 1px 1px
-h1
- margin: 0 0 0.4em 0
- padding-top: 0.3em
- font-size: 340%
- span
- color: #666
-h2
- font-size: 190%
-h3
- font-size: 160%
-abbr
- border: none
-
-p, ul, ol, pre
- margin-bottom: 1em
-p + ul, p + ol
- margin-top: -1em
-
-@media handheld, screen and (max-device-width: 481px), screen and (max-width: 30em)
- header
- #logo
- position: absolute
- margin: 15px 0 0.5em -0.5em
- nav
- margin-left: 75px
- float: left
- a
- margin-bottom: 0
- text-shadow: white 0 0 0
- &:hover
- background: white
- color: black
- &.open, &:active
- background: black
- color: white
- &:active
- border: none
- outline: none
- margin: 9px 1px 0 0
- div
- display: none
- ul, ol
- margin-left: 1.5em
-
-@media print
- body
- background: none
- margin: 0
- header
- display: none
- article
- margin: 0
- width: auto
- h1, h2, h3
- text-shadow: white 0 0 0
- h1
- margin-top: 0
- ul, ol
- margin-left: 1.5em
Oops, something went wrong.

0 comments on commit 46e4ca3

Please sign in to comment.