jack139 / co.py.cat

cop.y.cat extends Hofstadter's, pythonically

Home Page:https://en.wikipedia.org/wiki/Copycat_(software)#External_links

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

co.py.cat

This repository has an implementation of Douglas Hofstadter's copycat algorithm in Python.

It is an analogising algorithm, and explained on Wikipedia. It is the foundation of a group of similar algorithms metacat, musicat, seqsee, ....

This implementation is a copycat of Scott Boland's Java implementation, but re-written into Python3. It's not a direct translation, more like "based on a true story". I did not carry over the GUI, as GUIs restrict the platform too much, and thought that this code could more usefully be imported by other Python packages.

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 keep trying 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
$ python3 -m copycat abc abd pqr

Running

The program takes two arguments

  • A pair of words with some change
    • for example "abc abd".
  • A word to be changed
    • for example "pqr"

And one option

  • How many solutions to evaluate
    • for example
      • --solutions 10 means "try 10 solutions"
      • the default is "try 1 solution"

So, to find a single x for the analogy ABC:ABD::PQR:x

$ python3 -m copycat ABC ABD PQR
PQS: 1 (average time 0.3 seconds, average temperature 14.43)

Evaluating more solutions can produce output

$ python3 -m copycat ABC ABD PQQRRR --solutions 10
PQQRRRR: 2 (average time 0.65 seconds, average temperature 17.1)
PQQRRS: 5 (average time 0.82 seconds, average temperature 17.38)
PQQSSS: 3 (average time 1.29 seconds, average temperature 24.83)

In that run the program considered three solutions:

  • PQQRRRR 2 times at 17˚ in 0.7 seconds
  • PQQRRS 5 times at 17˚ in 0.8 seconds
  • PQQSSS 3 times at 24˚ in 1.3 seconds

From that one might say "copycat liked PQQRRRR best" because:

  1. The average temperature is lowest (17˚ looks like the "most obvious" solution)
  2. The average time is lowest (0.7 seconds looks like it did the least work)

On the other hand PQQRRS might be considered "best" because it was the accepted solution most often: 5 times.

For me: PQQRRRR is the "best" solution, because increasing the number of Qs from 3 to 4 is the "best" analogy to increasing the 3rd letter (C) to the 4th letter (D). However the other 2 answers also seem "quite good" because PQQRRS is the most direct (just increase the last letter), and PQQSSS is also fairly direct (increase letter in the last group).

This example output emphasizes that Copycat is not intended to produce a single definitive solution to an analogy problem, but to explore solutions, and try different strategies to find them. It also shows the different "levels" that Copycat considered in this problem: changing letters, or groups of letters, or both.

Note that there is no "correct" solution to an analogy problem - there are arguments to be made for each of PQQRRRR, PQQRRS and PQQSSS above, and only one's own preferences can decide that one of them is "best".

Importing

The program can also be imported and run from within Python, e.g.

>>> from copycat import copycat
>>> answers = copycat.run("abc", "abd", "pqqrrr", 10)
>>> print(answers)
{'pqqrrrr': {'avgtemp': 18.320790853668182, 'avgtime': 759.0, 'count': 1},
 'pqqrrs': {'avgtemp': 38.58653638621074, 'avgtime': 1294.1666666666667, 'count': 6},
 'pqqsss': {'avgtemp': 37.86964564086443, 'avgtime': 1642.6666666666667, 'count': 3}}

Thanks

A big "Thank You" for

Curation

Contributions

Forks

You geeks make it all so worthwhile.

Links

Readers who got this far will definitely enjoy analogising this project with @Alex-Linhares's collection of FARGonautica, computational architectures that have been developed from Douglas Hofstadter's "FARGonautica" group's research in "[Fluid Concepts & Creative Analogies](https://archive.org/details/fluidconceptscre0000hofs_w7o9/page/n5/mode/2uphttps://archive.org/details/fluidconceptscre0000hofs_w7o9/page/n5/mode/2up".

They've got Lisp (lotsa (Lisp)), Python, C++, Java, even Perl. If you know one of those languages, then you too can be a FARGonaut.

Send Coffee

Programmers are machines for turning coffee into code

See Also

  1. "The Copycat Project: An Experiment in Nondeterminism and Creative Analogies" by Hofstadter, Douglas
  2. "Analogy-Making as Perception" by Mitchell, Melanie
  3. Arthur O'Dwyer (Quuxplusone on GitHub) has further cleaned and extended this code (including a GUI) in a fork available here.

Badges

Build Status

About

cop.y.cat extends Hofstadter's, pythonically

https://en.wikipedia.org/wiki/Copycat_(software)#External_links

License:MIT License


Languages

Language:Python 100.0%