Popular recipes tagged "meta:loc=273"http://code.activestate.com/recipes/tags/meta:loc=273/2017-02-23T22:47:16-08:00ActiveState Code Recipeschatbox megawidget for tkinter (Python)
2017-02-23T22:47:16-08:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580757-chatbox-megawidget-for-tkinter/
<p style="color: grey">
Python
recipe 580757
by <a href="/recipes/users/4189907/">Miguel Martínez López</a>
(<a href="/recipes/tags/chat/">chat</a>, <a href="/recipes/tags/chatbox/">chatbox</a>, <a href="/recipes/tags/tkinter/">tkinter</a>).
Revision 3.
</p>
<p>Chatbox megawidget.</p>
<p>Arguments:</p>
<ul>
<li><p>my_nick</p>
<p>Nick of user chatting</p></li>
<li><p>command</p>
<p>Callback to call when a message is sent</p></li>
<li><p>logging_file</p>
<p>File to log all the messages</p></li>
<li><p>topic</p>
<p>Topic for the chatbox</p></li>
<li><p>maximum_lines</p>
<p>Max lines to show</p></li>
<li><p>entry_controls</p>
<p>Builder of controls for the entry (optional)</p></li>
<li><p>tags</p>
<p>List of tag configurations for the Text widget</p></li>
</ul>
<p>Styling arguments:</p>
<ul>
<li><p>timestamp_template</p></li>
<li><p>scrollbar_background</p></li>
<li><p>scrollbar_troughcolor</p></li>
<li><p>history_background</p></li>
<li><p>history_font</p></li>
<li><p>history_padx</p></li>
<li><p>history_pady</p></li>
<li><p>history_width</p></li>
<li><p>entry_font</p></li>
<li><p>entry_background</p></li>
<li><p>entry_foreground</p></li>
<li><p>label_template</p></li>
<li><p>label_font</p></li>
</ul>
Genetic Algorithm in Python source code - AI-Junkie tutorial (Python)
2012-06-19T12:59:13-07:00David Adlerhttp://code.activestate.com/recipes/users/4182015/http://code.activestate.com/recipes/578128-genetic-algorithm-in-python-source-code-ai-junkie-/
<p style="color: grey">
Python
recipe 578128
by <a href="/recipes/users/4182015/">David Adler</a>
(<a href="/recipes/tags/algorithm/">algorithm</a>, <a href="/recipes/tags/artificial/">artificial</a>, <a href="/recipes/tags/genetic/">genetic</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/neural/">neural</a>, <a href="/recipes/tags/python/">python</a>).
Revision 5.
</p>
<p>A simple genetic algorithm program. I followed this tutorial to make the program <a href="http://www.ai-junkie.com/ga/intro/gat1.html." rel="nofollow">http://www.ai-junkie.com/ga/intro/gat1.html.</a></p>
<p>The objective of the code is to evolve a mathematical expression which calculates a user-defined target integer.</p>
<hr />
<p>KEY:</p>
<p>chromosome = binary list (this is translated/decoded into a protein in the format number --> operator --> number etc, any genes (chromosome is read in blocks of four) which do not conform to this are ignored.</p>
<p>protein = mathematical expression (this is evaluated from left to right in number + operator blocks of two)</p>
<p>output = output of protein (mathematical expression)</p>
<p>error = inverse of difference between output and target</p>
<p>fitness score = a fraction of sum of of total errors</p>
<hr />
<p>OTHER:</p>
<p>One-point crossover is used.</p>
<p>I have incorporated <strong>elitism</strong> in my code, which somewhat deviates from the tutorial but made my code more efficient (top ~7% of population are carried through to next generation)</p>