Merge branch 'feature-gui' into revision-2.0
This commit is contained in:
@ -3,13 +3,6 @@ co.py.cat
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
Linhares and I are planning to use this codebase to implement a variation of Copycat that uses *Entropy* instead of *Temperature*, while still preserving the parallel terraced scan in full form. If the change is viable, I plan to write a paper on that (if anyone is interested in co-authoring, let me know). For the general idea, please see pages 41 and 42 of the [*Information Sciences*](https://github.com/Alex-Linhares/FARGlexandria/blob/master/Literature/Chess-Capyblanca-2014-Linhares-Information%20Sciences.pdf) paper on [Capyblanca](https://github.com/Alex-Linhares/FARGlexandria).
|
|
||||||
|
|
||||||
**If you would like to help research and publish a paper, please let me know.**
|
|
||||||
|
|
||||||
Please see also [FARGlexandria](https://github.com/Alex-Linhares/FARGlexandria), a repository with all FARG projects (and help if you have some of the missing info there, especially about Letter Spirit and George!)
|
|
||||||
|
|
||||||
-------------------------------
|
|
||||||
An implementation of [Douglas Hofstadter](http://prelectur.stanford.edu/lecturers/hofstadter/)'s Copycat algorithm.
|
An implementation of [Douglas Hofstadter](http://prelectur.stanford.edu/lecturers/hofstadter/)'s Copycat algorithm.
|
||||||
The Copycat algorithm is explained [on Wikipedia](https://en.wikipedia.org/wiki/Copycat_%28software%29), and that page has many links for deeper reading. See also [Farglexandria](https://github.com/Alex-Linhares/Farglexandria).
|
The Copycat algorithm is explained [on Wikipedia](https://en.wikipedia.org/wiki/Copycat_%28software%29), and that page has many links for deeper reading. See also [Farglexandria](https://github.com/Alex-Linhares/Farglexandria).
|
||||||
|
|
||||||
|
|||||||
@ -63,8 +63,8 @@ class Copycat(object):
|
|||||||
def mainLoop(self):
|
def mainLoop(self):
|
||||||
currentTime = self.coderack.codeletsRun
|
currentTime = self.coderack.codeletsRun
|
||||||
self.temperature.tryUnclamp(currentTime)
|
self.temperature.tryUnclamp(currentTime)
|
||||||
# Every 15 codelets, we update the workspace.
|
# Every 5 codelets, we update the workspace.
|
||||||
if currentTime >= self.lastUpdate + 15:
|
if currentTime >= self.lastUpdate + 5:
|
||||||
self.update_workspace(currentTime)
|
self.update_workspace(currentTime)
|
||||||
self.step()
|
self.step()
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ from .primary import Primary
|
|||||||
from .list import List
|
from .list import List
|
||||||
from .style import configure_style
|
from .style import configure_style
|
||||||
|
|
||||||
from .plot import plot_imbedded
|
from .plot import plot_answers, plot_temp
|
||||||
|
|
||||||
plt.style.use('dark_background')
|
plt.style.use('dark_background')
|
||||||
|
|
||||||
@ -40,10 +40,13 @@ class MainApplication(GridFrame):
|
|||||||
self.add(self.codeletList, 1, 1)
|
self.add(self.codeletList, 1, 1)
|
||||||
|
|
||||||
self.objectList = List(self, columns)
|
self.objectList = List(self, columns)
|
||||||
self.add(self.objectList, 2, 1)
|
self.add(self.objectList, 2, 1, xspan=2)
|
||||||
|
|
||||||
|
self.graph1 = Plot(self, 'Temperature history')
|
||||||
|
self.add(self.graph1, 2, 0)
|
||||||
|
|
||||||
self.graph2 = Plot(self, 'Answer Distribution')
|
self.graph2 = Plot(self, 'Answer Distribution')
|
||||||
self.add(self.graph2, 2, 0)
|
self.add(self.graph2, 3, 0)
|
||||||
|
|
||||||
def update(self, copycat):
|
def update(self, copycat):
|
||||||
self.primary.update(copycat)
|
self.primary.update(copycat)
|
||||||
@ -58,6 +61,11 @@ class MainApplication(GridFrame):
|
|||||||
get_descriptors = lambda s : ', '.join('({}={})'.format(d.descriptionType.name, d.descriptor.name) for d in s.descriptions)
|
get_descriptors = lambda s : ', '.join('({}={})'.format(d.descriptionType.name, d.descriptor.name) for d in s.descriptions)
|
||||||
self.objectList.update(objects, formatter=lambda s : '{}: {}'.format(s, get_descriptors(s)))
|
self.objectList.update(objects, formatter=lambda s : '{}: {}'.format(s, get_descriptors(s)))
|
||||||
|
|
||||||
|
def modifier(status):
|
||||||
|
with plt.style.context(('dark_background')):
|
||||||
|
plot_temp(copycat.temperature, status)
|
||||||
|
self.graph1.status.modifier = modifier
|
||||||
|
|
||||||
def reset_with_strings(self, initial, modified, target):
|
def reset_with_strings(self, initial, modified, target):
|
||||||
self.primary.reset_with_strings(initial, modified, target)
|
self.primary.reset_with_strings(initial, modified, target)
|
||||||
|
|
||||||
@ -69,15 +77,12 @@ class GUI(object):
|
|||||||
tk.Grid.columnconfigure(self.root, 0, weight=1)
|
tk.Grid.columnconfigure(self.root, 0, weight=1)
|
||||||
self.app = MainApplication(self.root)
|
self.app = MainApplication(self.root)
|
||||||
self.app.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W)
|
self.app.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W)
|
||||||
|
|
||||||
configure_style(ttk.Style())
|
configure_style(ttk.Style())
|
||||||
|
|
||||||
def add_answers(self, answers):
|
def add_answers(self, answers):
|
||||||
def modifier(status):
|
def modifier(status):
|
||||||
print('Here')
|
|
||||||
print(answers)
|
|
||||||
with plt.style.context(('dark_background')):
|
with plt.style.context(('dark_background')):
|
||||||
plot_imbedded(answers, status)
|
plot_answers(answers, status)
|
||||||
self.app.graph2.status.modifier = modifier
|
self.app.graph2.status.modifier = modifier
|
||||||
|
|
||||||
def refresh(self):
|
def refresh(self):
|
||||||
|
|||||||
@ -2,7 +2,14 @@ import matplotlib.pyplot as plt; plt.rcdefaults()
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
def plot_imbedded(answers, status):
|
def plot_temp(temperature, status):
|
||||||
|
status.subplot.clear()
|
||||||
|
status.subplot.plot(temperature.history)
|
||||||
|
status.subplot.set_ylabel('Temperature')
|
||||||
|
status.subplot.set_xlabel('Time')
|
||||||
|
status.subplot.set_title('Temperature History')
|
||||||
|
|
||||||
|
def plot_answers(answers, status):
|
||||||
answers = sorted(answers.items(), key=lambda kv : kv[1]['count'])
|
answers = sorted(answers.items(), key=lambda kv : kv[1]['count'])
|
||||||
objects = [t[0] for t in answers]
|
objects = [t[0] for t in answers]
|
||||||
yvalues = [t[1]['count'] for t in answers]
|
yvalues = [t[1]['count'] for t in answers]
|
||||||
|
|||||||
@ -21,6 +21,7 @@ class WorkspaceCanvas(GridFrame):
|
|||||||
self.changed = False
|
self.changed = False
|
||||||
|
|
||||||
self.canvas = tk.Canvas(self, background='black')
|
self.canvas = tk.Canvas(self, background='black')
|
||||||
|
#self.canvas['width'] = 1600
|
||||||
self.add(self.canvas, 0, 0)
|
self.add(self.canvas, 0, 0)
|
||||||
|
|
||||||
GridFrame.configure(self)
|
GridFrame.configure(self)
|
||||||
|
|||||||
@ -123,6 +123,7 @@ class Temperature(object):
|
|||||||
self.ndiffs = 0
|
self.ndiffs = 0
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
|
self.history = [100.0]
|
||||||
self.actual_value = 100.0
|
self.actual_value = 100.0
|
||||||
self.last_unclamped_value = 100.0
|
self.last_unclamped_value = 100.0
|
||||||
self.clamped = True
|
self.clamped = True
|
||||||
@ -133,6 +134,7 @@ class Temperature(object):
|
|||||||
if self.clamped:
|
if self.clamped:
|
||||||
self.actual_value = 100.0
|
self.actual_value = 100.0
|
||||||
else:
|
else:
|
||||||
|
self.history.append(value)
|
||||||
self.actual_value = value
|
self.actual_value = value
|
||||||
|
|
||||||
def clampUntil(self, when):
|
def clampUntil(self, when):
|
||||||
|
|||||||
Reference in New Issue
Block a user