go-bf

所属分类:人工智能/神经网络/深度学习
开发工具:GO
文件大小:21KB
下载次数:0
上传日期:2019-12-24 03:19:57
上 传 者sh-1993
说明:  用遗传编程进行头脑风暴
(Brainfuck in Go with Genetic Programming)

文件列表:
bf.go (4142, 2019-12-24)
bf_test.go (7173, 2019-12-24)
cmd (0, 2019-12-24)
cmd\bf (0, 2019-12-24)
cmd\bf\main.go (379, 2019-12-24)
cmd\bfgen (0, 2019-12-24)
cmd\bfgen\main.go (1040, 2019-12-24)
cmd\bfgen\wrap_test.go (164, 2019-12-24)
examples (0, 2019-12-24)
examples\christmas.bf (610, 2019-12-24)
examples\dbf2c.bf (1183, 2019-12-24)
examples\fib.bf (512, 2019-12-24)
examples\hannoi.bf (54593, 2019-12-24)
examples\hello.bf (305, 2019-12-24)
examples\life.bf (3594, 2019-12-24)
examples\mandelbrot.bf (11669, 2019-12-24)
examples\rot13.bf (837, 2019-12-24)
examples\smiley.bf (126, 2019-12-24)
go.mod (44, 2019-12-24)
population.go (3691, 2019-12-24)
population_test.go (1438, 2019-12-24)
program.go (3624, 2019-12-24)
program_test.go (1308, 2019-12-24)

# Brain*** The interpreter could be more efficient if the interpeter did a single pass to determine code jump locations for loops. However the assignment required the use of `io.Reader` and processing instructions without knowing all input at once. [Extended Brain***](https://esolangs.org/wiki/Extended_Brain***) requires reading the data behind the program file to initialize storage. ```bash $ go install ./... $ bf examples/life.bf $ bf examples/hannoi.bf $ bf examples/mandelbrot.bf # compile bf to c $ bf examples/dbf2c.bf examples/mandelbrot.c $ gcc examples/mandelbrot.c -o examples/mandelbrot $ ./examples/mandelbrot # run short test $ go test -test.short # test coverage $ go test -test.short -cover -coverprofile=coverage.out && go tool cover -html=coverage.out ``` - [Brain***](http://www.linusakesson.net/programming/brain***/index.php) - [Brain*** Algorithms](https://esolangs.org/wiki/Brain***_algorithms) - [Brain*** Examples](http://esoteric.sange.fi/brain***/bf-source/prog/) - [Brain*** Debugger](http://jsfiddle.net/egon/PyyV2/20/embedded/result/) ## Genetic Programming Th `bfgen` tool for generating programs was inspired by the research paper [AI Programmer: Autonomously CreatingSoftware Programs Using Genetic Algorithms](https://arxiv.org/pdf/1709.05703.pdf). More information is available at [Using Artificial Intelligence to Write Self-Modifying/Improving Programs](http://www.primaryobjects.com/2013/01/27/using-artificial-intelligence-to-write-self-modifying-improving-programs/). [Genetic programming](https://en.wikipedia.org/wiki/Genetic_programming) uses genetic evolution in a population of random programs to adapt them into programs that are increasingly more fit to solve a problem. The fitness of a program is calculated to see how good the solution is with respect to a certain outcome. Mutations are introduced in the population by imperfect copying of existing code. The most fit programs are selected and crossbred to evolve into possibly better programs. The brain*** interpreter is extended to allow more sloppy versions of the code. The sloppy version will not error on unmached looping operators, so that invalid loops can be randomly introduced and removed. The `Normalize` function is used to fix unbalanced brackets so that programs are compatible with more strict interpreters. Runtime cost for executing a program can be limited and is returned for evaluation. ## Examples ```bash $ echo "I Feel Like a Computer" | bfgen ``` ``` >+>[]<+>++++[<++++>-]<[<++++>-]<+.-----------------------------------------.++>+ +++[<+++++><++++>-]<.->++++[<++++++++>-]<..+++++++.[-]>++++[<++++++++>-]<.+>++++ +++[<++++++>-]<+.+>++++[<+++++++>-]<.++.------.[-]>++++[<++++><++++>-]<.+>++++++ ++[<++++++++>-]<.+>++++[<++++>-]<>>++++<++++++++>++[<++++>-]<.>-++++++[<+++++++> -]<.++>+-++++++[<+++++++>-]<.--.+++.++++><+.-.---------------.<.[-]++++++++++. ``` The `-runtime` parameter defaults to 10000, but sometimes its beneficial to limit or extend it to fit the length of the text. The amount of manipulation can be controlled using `-manipulate`. Higher manipulation will result in more random programs and will take more time to converge. However the final program can also be a more compact. ```bash $ cat <+++++++[<+++++++>-]<.>++++++++++.>+>+++++++[<+++++++>-]<..<.>+...>++++++++++.<+ ....>[-]++++++<+>++++.[+]<.>+<....>+++++<+>++++.<......>.<+.......>.<+....>[-]<. ...>++++++<+>++++.<.........>. ``` ```bash # Benchmark add print all byte value representations $ go test -benchmem -run=^$ github.com/sanderhahn/go-bf -bench "^(BenchmarkAscii)$" ``` ``` 0x00 = . 0x01 = +. 0x02 = ++. 0x03 = +++. ... ``` ## Limitations There is only one pool so its possible that the population will get stuck in a solution that doesn't further improve, especially for longer texts. This situation can be improved by evaluating programs within their own generational pool. The weight function values early matching letters in output higher and will start to optimize for program length once a solution is found. The generator will not generate input `,` instructions because EOF handling is inconsistent between different implementations. Actually generating programs that handle input/output in a logical way requires specifying interaction patterns in a language like [Expect](https://en.wikipedia.org/wiki/Expect). Otherwise the generator will just use input as source of integer values and this doesn't result in programs that perform meaningful interactions.

近期下载者

相关文件


收藏者