- Nobody does `import random` anymore. - Random numbers are gotten from `ctx.random`, which is an object of type `Randomness` with all the convenience methods that used to be obnoxious functions in the `formulas` module. - Every place that was using `random.random()` to implement the equivalent of Python3 `random.choices(seq, weights)` has been updated to use `ctx.random.weighted_choice(seq, weights)`. This has a functional effect, since the details of random number generation have changed. The *statistical* effect should be small. I do observe that Copycat is having trouble inventing the "mrrjjjj" solution right now (even in 1000 test runs), so maybe something is slightly broken.
co.py.cat
An implementation of Douglas Hofstadter's copycat algorithm. The copycat algorithm is explained on Wikipedia, and that page has many links for deeper reading.
This implementation is a copycat of Scott Boland's Java implementation, but re-written into Python. It's not a direct translation - but based on his code. I did not carry over the GUI, as this version can more usefully be run from command line, or imported for use by other Python scripts.
In cases where I could not grok the Java implementation easily I took ideas from the LISP implementation, or directly from Melanie Mitchell's "Analogy-Making as Perception"
I also tried to make the code more pythonic.
Installation
There are no particular installation instructions, just clone and run, e.g.
$ git clone https://github.com/jalanb/co.py.cat.git
$ cd co.py.cat/copycat
$ python main.py abc abd ijk
Running
The script takes three arguments. The first two are a pair of triplets with some change, for example "abc" and "abd". The third is a triplet which the script should try to change analogously
For example the following invocation will probably display "ijl"
$ python main.py abc abd ijk