<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=“www.w3.org/1999/xhtml” xml:lang=“en” lang=“en”>
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
Class: NEAT::Critter::Genotype — Documentation by YARD 0.8.7.3
</title>
<link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" /> <link rel="stylesheet" href="../../css/common.css" type="text/css" charset="utf-8" />
<script type=“text/javascript” charset=“utf-8”>
hasFrames = window.top.frames.main ? true : false; relpath = '../../'; framesUrl = "../../frames.html#!" + escape(window.location.href);
</script>
<script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script> <script type="text/javascript" charset="utf-8" src="../../js/app.js"></script> </head> <body> <div id="header"> <div id="menu"> <a href="../../_index.html">Index (G)</a> » <span class='title'><span class='object_link'><a href="../../NEAT.html" title="NEAT (module)">NEAT</a></span></span> » <span class='title'><span class='object_link'><a href="../Critter.html" title="NEAT::Critter (class)">Critter</a></span></span> » <span class="title">Genotype</span> <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>
<div id="search"> <a class="full_list_link" id="class_list_link" href="../../class_list.html"> Class List </a> <a class="full_list_link" id="method_list_link" href="../../method_list.html"> Method List </a> <a class="full_list_link" id="file_list_link" href="../../file_list.html"> File List </a>
</div>
<div class="clear"></div> </div> <iframe id="search_frame"></iframe> <div id="content"><h1>Class: NEAT::Critter::Genotype
</h1>
<dl class=“box”>
<dt class="r1">Inherits:</dt> <dd class="r1"> <span class="inheritName"><span class='object_link'><a href="../NeatOb.html" title="NEAT::NeatOb (class)">NeatOb</a></span></span> <ul class="fullTree"> <li>Object</li> <li class="next"><span class='object_link'><a href="../NeatOb.html" title="NEAT::NeatOb (class)">NeatOb</a></span></li> <li class="next">NEAT::Critter::Genotype</li> </ul> <a href="#" class="inheritanceTree">show all</a> </dd> <dt class="r2 last">Defined in:</dt> <dd class="r2 last">lib/rubyneat/critter.rb</dd>
</dl> <div class=“clear”></div>
<h2>Overview</h2><div class=“docstring”>
<div class="discussion">
<h1 id=“label-Genotype+part+of+the+Critter”>Genotype part of the Critter</h1>
<p>List of connections, basically.</p>
<p>Also, basic phentypic expression (which may be overriden by the expressor)</p>
<h1 id=“label-Notes”>Notes</h1>
<p>Currently, all lists of neurons and genes are Hashes. The neurons are indexed by their own names, and the genes are indexed by their innovation numbers.</p>
</div>
</div> <div class=“tags”>
</div><h2>Defined Under Namespace</h2> <p class=“children”>
<strong class="classes">Classes:</strong> <span class='object_link'><a href="Genotype/Gene.html" title="NEAT::Critter::Genotype::Gene (class)">Gene</a></span>
</p>
<h2>Instance Attribute Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small></h2> <ul class="summary"> <li class="public "> <span class="summary_signature"> <a href="#critter-instance_method" title="#critter (instance method)">- (Object) <strong>critter</strong> </a> </span> <span class="summary_desc"><div class='inline'>
<p>Critter to which we belong.</p> </div></span>
</li>
<li class="public "> <span class="summary_signature"> <a href="#dangling_neurons-instance_method" title="#dangling_neurons (instance method)">- (Object) <strong>dangling_neurons</strong> </a> (also: #dangling_neurons?) </span> <span class="summary_desc"><div class='inline'>
<p>This will be set to true if there are dangling neurons.</p> </div></span>
</li>
<li class="public "> <span class="summary_signature"> <a href="#genes-instance_method" title="#genes (instance method)">- (Object) <strong>genes</strong> </a> </span> <span class="summary_desc"><div class='inline'>
<p>Genes keyed by innovation numbers.</p> </div></span>
</li>
<li class="public "> <span class="summary_signature"> <a href="#neural_gene_map-instance_method" title="#neural_gene_map (instance method)">- (Object) <strong>neural_gene_map</strong> </a> </span> <span class="note title readonly">readonly</span> <span class="summary_desc"><div class='inline'>
<p>Map neurons to the genes that marks them as output { oneu_name => [ gene_1, gene_2,… gene_n], …} Just take the in_neuron name and the weight to do the call to that neuron function with the appropriate weights.</p> </div></span>
</li>
<li class="public "> <span class="summary_signature"> <a href="#neural_inputs-instance_method" title="#neural_inputs (instance method)">- (Object) <strong>neural_inputs</strong> </a> </span> <span class="note title readonly">readonly</span> <span class="summary_desc"><div class='inline'>
<p>Instantiations of neural inputs and outputs.</p> </div></span>
</li>
<li class="public "> <span class="summary_signature"> <a href="#neural_outputs-instance_method" title="#neural_outputs (instance method)">- (Object) <strong>neural_outputs</strong> </a> </span> <span class="note title readonly">readonly</span> <span class="summary_desc"><div class='inline'>
<p>Instantiations of neural inputs and outputs.</p> </div></span>
</li>
<li class="public "> <span class="summary_signature"> <a href="#neurons-instance_method" title="#neurons (instance method)">- (Object) <strong>neurons</strong> </a> </span> <span class="summary_desc"><div class='inline'>
<p>List of neurons hashed by name.</p> </div></span>
</li>
</ul> <h3 class="inherited">Attributes inherited from <span class='object_link'><a href="../NeatOb.html" title="NEAT::NeatOb (class)">NeatOb</a></span></h3> <p class="inherited"><span class='object_link'><a href="../NeatOb.html#controller-instance_method" title="NEAT::NeatOb#controller (method)">#controller</a></span>, <span class='object_link'><a href="../NeatOb.html#name-instance_method" title="NEAT::NeatOb#name (method)">#name</a></span></p> <h2> Instance Method Summary <small>(<a href="#" class="summary_toggle">collapse</a>)</small> </h2> <ul class="summary"> <li class="public "> <span class="summary_signature"> <a href="#add_genes-instance_method" title="#add_genes (instance method)">- (Object) <strong>add_genes</strong>(*genes) </a> </span> <span class="summary_desc"><div class='inline'>
<p>Genes added here MUST correspond to pre-existing neurons.</p> </div></span>
</li>
<li class="public "> <span class="summary_signature"> <a href="#add_neurons-instance_method" title="#add_neurons (instance method)">- (Object) <strong>add_neurons</strong>(*neus) </a> </span> <span class="summary_desc"><div class='inline'>
<p>Add new neurons to the fold.</p> </div></span>
</li>
<li class="public "> <span class="summary_signature"> <a href="#dump_s-instance_method" title="#dump_s (instance method)">- (Object) <strong>dump_s</strong> </a> </span> <span class="summary_desc"><div class='inline'></div></span>
</li>
<li class="public "> <span class="summary_signature"> <a href="#fitness_cost-instance_method" title="#fitness_cost (instance method)">- (Object) <strong>fitness_cost</strong> </a> </span> <span class="summary_desc"><div class='inline'>
<p>Calculate the cost of this genotype.</p> </div></span>
</li>
<li class="public "> <span class="summary_signature"> <a href="#forget%21-instance_method" title="#forget! (instance method)">- (Object) <strong>forget!</strong> </a> </span> <span class="summary_desc"><div class='inline'>
<p>Make the neurons forget their wiring.</p> </div></span>
</li>
<li class="public "> <span class="summary_signature"> <a href="#initialize-instance_method" title="#initialize (instance method)">- (Genotype) <strong>initialize</strong>(critter, mating = false, &block) </a> </span> <span class="note title constructor">constructor</span> <span class="summary_desc"><div class='inline'>
<p>A new instance of Genotype.</p> </div></span>
</li>
<li class="public "> <span class="summary_signature"> <a href="#innervate%21-instance_method" title="#innervate! (instance method)">- (Object) <strong>innervate!</strong>(*hneus) </a> </span> <span class="summary_desc"><div class='inline'>
<p>We take the neural hashes (presumably from other neurons), and innervate them.</p> </div></span>
</li>
<li class="public "> <span class="summary_signature"> <a href="#neucleate-instance_method" title="#neucleate (instance method)">- (Object) <strong>neucleate</strong>(clean: true, &block) </a> </span> <span class="summary_desc"><div class='inline'>
<p>We add genes given here to the genome.</p> </div></span>
</li>
<li class="public "> <span class="summary_signature"> <a href="#nuke_redundancies%21-instance_method" title="#nuke_redundancies! (instance method)">- (Object) <strong>nuke_redundancies!</strong> </a> </span> <span class="summary_desc"><div class='inline'>
<p>Remove any redundancies in the genome, any genes refering to the same two neurons.</p> </div></span>
</li>
<li class="public "> <span class="summary_signature"> <a href="#prune%21-instance_method" title="#prune! (instance method)">- (Object) <strong>prune!</strong> </a> </span> <span class="summary_desc"><div class='inline'>
<p>Go through the list of neurons and drop any neurons not referenced by the genes.</p> </div></span>
</li>
<li class="public "> <span class="summary_signature"> <a href="#wire%21-instance_method" title="#wire! (instance method)">- (Object) <strong>wire!</strong> </a> </span> <span class="summary_desc"><div class='inline'>
<p>Wire up the neurons based on the genes.</p> </div></span>
</li>
</ul> <h3 class="inherited">Methods inherited from <span class='object_link'><a href="../NeatOb.html" title="NEAT::NeatOb (class)">NeatOb</a></span></h3> <p class="inherited"><span class='object_link'><a href="../NeatOb.html#log-instance_method" title="NEAT::NeatOb#log (method)">#log</a></span>, <span class='object_link'><a href="../NeatOb.html#log-class_method" title="NEAT::NeatOb.log (method)">log</a></span>, <span class='object_link'><a href="../NeatOb.html#to_s-instance_method" title="NEAT::NeatOb#to_s (method)">#to_s</a></span></p> <div id="constructor_details" class="method_details_list"> <h2>Constructor Details</h2> <div class="method_details first"> <h3 class="signature first" id="initialize-instance_method"> - (<tt><span class='object_link'><a href="" title="NEAT::Critter::Genotype (class)">Genotype</a></span></tt>) <strong>initialize</strong>(critter, mating = false, &block)
</h3><div class=“docstring”>
<div class="discussion">
<p>Returns a new instance of Genotype</p>
</div>
</div> <div class=“tags”>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 88</span>
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_critter'>critter</span><span class='comma'>,</span> <span class='id identifier rubyid_mating'>mating</span> <span class='op'>=</span> <span class='kw'>false</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='kw'>super</span> <span class='id identifier rubyid_critter'>critter</span><span class='period'>.</span><span class='id identifier rubyid_controller'>controller</span> <span class='ivar'>@critter</span> <span class='op'>=</span> <span class='id identifier rubyid_critter'>critter</span> <span class='comment'># Initialize basic structures
</span> <span class='ivar'>@genes</span> <span class='op'>=</span> <span class='kw'>nil</span>
<span class='ivar'>@neural_inputs</span> <span class='op'>=</span> <span class='const'>Hash</span><span class='lbracket'>[</span><span class='ivar'>@critter</span><span class='period'>.</span><span class='id identifier rubyid_population'>population</span><span class='period'>.</span><span class='id identifier rubyid_input_neurons'>input_neurons</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_sym'>sym</span><span class='comma'>,</span> <span class='id identifier rubyid_ineu'>ineu</span><span class='op'>|</span> <span class='lbracket'>[</span><span class='id identifier rubyid_sym'>sym</span><span class='comma'>,</span> <span class='id identifier rubyid_ineu'>ineu</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='ivar'>@controller</span><span class='comma'>,</span> <span class='id identifier rubyid_sym'>sym</span><span class='rparen'>)</span><span class='rbracket'>]</span> <span class='rbrace'>}</span><span class='rbracket'>]</span> <span class='ivar'>@neural_outputs</span> <span class='op'>=</span> <span class='const'>Hash</span><span class='lbracket'>[</span><span class='ivar'>@critter</span><span class='period'>.</span><span class='id identifier rubyid_population'>population</span><span class='period'>.</span><span class='id identifier rubyid_output_neurons'>output_neurons</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_sym'>sym</span><span class='comma'>,</span> <span class='id identifier rubyid_ineu'>ineu</span><span class='op'>|</span> <span class='lbracket'>[</span><span class='id identifier rubyid_sym'>sym</span><span class='comma'>,</span> <span class='id identifier rubyid_ineu'>ineu</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='ivar'>@controller</span><span class='comma'>,</span> <span class='id identifier rubyid_sym'>sym</span><span class='rparen'>)</span><span class='rbracket'>]</span> <span class='rbrace'>}</span><span class='rbracket'>]</span> <span class='ivar'>@neurons</span> <span class='op'>=</span> <span class='ivar'>@neural_inputs</span><span class='period'>.</span><span class='id identifier rubyid_clone'>clone</span> <span class='comment'># this must be a shallow clone!
</span> <span class='ivar'>@neurons</span><span class='period'>.</span><span class='id identifier rubyid_merge!'>merge!</span> <span class='ivar'>@neural_outputs</span>
<span class='ivar'>@controller</span><span class='period'>.</span><span class='id identifier rubyid_evolver'>evolver</span><span class='period'>.</span><span class='id identifier rubyid_gen_initial_genes!'>gen_initial_genes!</span><span class='lparen'>(</span><span class='kw'>self</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id identifier rubyid_mating'>mating</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='lparen'>(</span><span class='kw'>self</span><span class='rparen'>)</span> <span class='kw'>unless</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
</div>
<div id="instance_attr_details" class="attr_details"> <h2>Instance Attribute Details</h2> <span id="critter=-instance_method"></span> <div class="method_details first"> <h3 class="signature first" id="critter-instance_method"> - (<tt>Object</tt>) <strong>critter</strong>
</h3><div class=“docstring”>
<div class="discussion">
<p>Critter to which we belong</p>
</div>
</div> <div class=“tags”>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
67 68 69</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 67</span>
<span class='kw'>def</span> <span class='id identifier rubyid_critter'>critter</span>
<span class='ivar'>@critter</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
<span id="dangling_neurons=-instance_method"></span> <div class="method_details "> <h3 class="signature " id="dangling_neurons-instance_method"> - (<tt>Object</tt>) <strong>dangling_neurons</strong> <span class="aliases">Also known as: <span class="names"><span id='dangling_neurons?-instance_method'>dangling_neurons?</span></span> </span>
</h3><div class=“docstring”>
<div class="discussion">
<p>This will be set to true if there are dangling neurons.</p>
</div>
</div> <div class=“tags”>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
79 80 81</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 79</span>
<span class='kw'>def</span> <span class='id identifier rubyid_dangling_neurons'>dangling_neurons</span>
<span class='ivar'>@dangling_neurons</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
<span id="genes=-instance_method"></span> <div class="method_details "> <h3 class="signature " id="genes-instance_method"> - (<tt>Object</tt>) <strong>genes</strong>
</h3><div class=“docstring”>
<div class="discussion">
<p>Genes keyed by innovation numbers</p>
</div>
</div> <div class=“tags”>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
70 71 72</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 70</span>
<span class='kw'>def</span> <span class='id identifier rubyid_genes'>genes</span>
<span class='ivar'>@genes</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
<span id=""></span> <div class="method_details "> <h3 class="signature " id="neural_gene_map-instance_method"> - (<tt>Object</tt>) <strong>neural_gene_map</strong> <span class="extras">(readonly)</span>
</h3><div class=“docstring”>
<div class="discussion">
<p>Map neurons to the genes that marks them as output { oneu_name => [ gene_1, gene_2,… gene_n], …} Just take the in_neuron name and the weight to do the call to that neuron function with the appropriate weights</p>
</div>
</div> <div class=“tags”>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
86 87 88</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 86</span>
<span class='kw'>def</span> <span class='id identifier rubyid_neural_gene_map'>neural_gene_map</span>
<span class='ivar'>@neural_gene_map</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
<span id=""></span> <div class="method_details "> <h3 class="signature " id="neural_inputs-instance_method"> - (<tt>Object</tt>) <strong>neural_inputs</strong> <span class="extras">(readonly)</span>
</h3><div class=“docstring”>
<div class="discussion">
<p>Instantiations of neural inputs and outputs</p>
</div>
</div> <div class=“tags”>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
76 77 78</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 76</span>
<span class='kw'>def</span> <span class='id identifier rubyid_neural_inputs'>neural_inputs</span>
<span class='ivar'>@neural_inputs</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
<span id=""></span> <div class="method_details "> <h3 class="signature " id="neural_outputs-instance_method"> - (<tt>Object</tt>) <strong>neural_outputs</strong> <span class="extras">(readonly)</span>
</h3><div class=“docstring”>
<div class="discussion">
<p>Instantiations of neural inputs and outputs</p>
</div>
</div> <div class=“tags”>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
76 77 78</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 76</span>
<span class='kw'>def</span> <span class='id identifier rubyid_neural_outputs'>neural_outputs</span>
<span class='ivar'>@neural_outputs</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
<span id="neurons=-instance_method"></span> <div class="method_details "> <h3 class="signature " id="neurons-instance_method"> - (<tt>Object</tt>) <strong>neurons</strong>
</h3><div class=“docstring”>
<div class="discussion">
<p>List of neurons hashed by name</p>
</div>
</div> <div class=“tags”>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
73 74 75</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 73</span>
<span class='kw'>def</span> <span class='id identifier rubyid_neurons'>neurons</span>
<span class='ivar'>@neurons</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
</div> <div id="instance_method_details" class="method_details_list"> <h2>Instance Method Details</h2> <div class="method_details first"> <h3 class="signature first" id="add_genes-instance_method"> - (<tt>Object</tt>) <strong>add_genes</strong>(*genes)
</h3><div class=“docstring”>
<div class="discussion">
<p>Genes added here MUST correspond to pre-existing neurons. Be sure to do add_neurons first!!!!</p>
</div>
</div> <div class=“tags”>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
163 164 165 166 167 168 169</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 163</span>
<span class='kw'>def</span> <span class='id identifier rubyid_add_genes'>add_genes</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_genes'>genes</span><span class='rparen'>)</span>
<span class='id identifier rubyid_genes'>genes</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_gene'>gene</span><span class='op'>|</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'>NeatException</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Neuron </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_in_neuron'>in_neuron</span><span class='embexpr_end'>}</span><span class='tstring_content'> missing</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='ivar'>@neurons</span><span class='period'>.</span><span class='id identifier rubyid_member?'>member?</span> <span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_in_neuron'>in_neuron</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'>NeatException</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Neuron </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_out_neuron'>out_neuron</span><span class='embexpr_end'>}</span><span class='tstring_content'> missing</span><span class='tstring_end'>"</span></span> <span class='kw'>unless</span> <span class='ivar'>@neurons</span><span class='period'>.</span><span class='id identifier rubyid_member?'>member?</span> <span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_out_neuron'>out_neuron</span> <span class='ivar'>@genes</span><span class='lbracket'>[</span><span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_innovation'>innovation</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_gene'>gene</span> <span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
<div class="method_details "> <h3 class="signature " id="add_neurons-instance_method"> - (<tt>Object</tt>) <strong>add_neurons</strong>(*neus)
</h3><div class=“docstring”>
<div class="discussion">
<p>Add new neurons to the fold</p>
</div>
</div> <div class=“tags”>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
155 156 157 158 159</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 155</span>
<span class='kw'>def</span> <span class='id identifier rubyid_add_neurons'>add_neurons</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_neus'>neus</span><span class='rparen'>)</span>
<span class='id identifier rubyid_neus'>neus</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_neu'>neu</span><span class='op'>|</span> <span class='ivar'>@neurons</span><span class='lbracket'>[</span><span class='id identifier rubyid_neu'>neu</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_neu'>neu</span> <span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
<div class="method_details "> <h3 class="signature " id="dump_s-instance_method"> - (<tt>Object</tt>) <strong>dump_s</strong>
</h3><table class=“source_code”>
<tr> <td> <pre class="lines">
218 219 220 221 222</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 218</span>
<span class='kw'>def</span> <span class='id identifier rubyid_dump_s'>dump_s</span>
<span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\ngenes:\n</span><span class='tstring_end'>"</span></span> <span class='op'>+</span> <span class='ivar'>@genes</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_gene'>gene</span><span class='op'>|</span> <span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\n</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\nneurons:\n</span><span class='tstring_end'>"</span></span> <span class='op'>+</span> <span class='ivar'>@neurons</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_neu'>neu</span><span class='op'>|</span> <span class='id identifier rubyid_neu'>neu</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span><span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\n</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
<div class="method_details "> <h3 class="signature " id="fitness_cost-instance_method"> - (<tt>Object</tt>) <strong>fitness_cost</strong>
</h3><div class=“docstring”>
<div class="discussion">
<p>Calculate the cost of this genotype.</p>
</div>
</div> <div class=“tags”>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
213 214 215 216</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 213</span>
<span class='kw'>def</span> <span class='id identifier rubyid_fitness_cost'>fitness_cost</span>
<span class='id identifier rubyid_p'>p</span> <span class='op'>=</span> <span class='ivar'>@controller</span><span class='period'>.</span><span class='id identifier rubyid_parms'>parms</span> <span class='id identifier rubyid_p'>p</span><span class='period'>.</span><span class='id identifier rubyid_fitness_cost_per_neuron'>fitness_cost_per_neuron</span> <span class='op'>*</span> <span class='ivar'>@neurons</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span> <span class='op'>+</span> <span class='id identifier rubyid_p'>p</span><span class='period'>.</span><span class='id identifier rubyid_fitness_cost_per_gene'>fitness_cost_per_gene</span> <span class='op'>*</span> <span class='ivar'>@genes</span><span class='period'>.</span><span class='id identifier rubyid_size'>size</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
<div class="method_details "> <h3 class="signature " id="forget!-instance_method"> - (<tt>Object</tt>) <strong>forget!</strong>
</h3><div class=“docstring”>
<div class="discussion">
<p>Make the neurons forget their wiring.</p>
</div>
</div> <div class=“tags”>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
134 135 136 137</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 134</span>
<span class='kw'>def</span> <span class='id identifier rubyid_forget!'>forget!</span>
<span class='ivar'>@neurons</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_neu'>neu</span><span class='op'>|</span> <span class='id identifier rubyid_neu'>neu</span><span class='period'>.</span><span class='id identifier rubyid_clear_graph'>clear_graph</span> <span class='rbrace'>}</span> <span class='ivar'>@neural_gene_map</span> <span class='op'>=</span> <span class='const'>Hash</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_h'>h</span><span class='comma'>,</span> <span class='id identifier rubyid_k'>k</span><span class='op'>|</span> <span class='id identifier rubyid_h'>h</span><span class='lbracket'>[</span><span class='id identifier rubyid_k'>k</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span> <span class='rbrace'>}</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
<div class="method_details "> <h3 class="signature " id="innervate!-instance_method"> - (<tt>Object</tt>) <strong>innervate!</strong>(*hneus)
</h3><div class=“docstring”>
<div class="discussion">
<p>We take the neural hashes (presumably from other neurons), and innervate them. We do this in distinctions based on the neuron's names. FIXME We need to randomly select a neuron in the case of clashes.</p>
</div>
</div> <div class=“tags”>
<p class="tag_title">Parameters:</p>
<ul class=“param”>
<li> <span class='name'>hneus</span> <span class='type'>(<tt>Hash</tt>)</span> — <div class='inline'>
<p>– hashes of neurons to innervate</p> </div>
</li>
</ul>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
175 176 177 178 179</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 175</span>
<span class='kw'>def</span> <span class='id identifier rubyid_innervate!'>innervate!</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_hneus'>hneus</span><span class='rparen'>)</span>
<span class='id identifier rubyid_hneus'>hneus</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_neus'>neus</span><span class='op'>|</span> <span class='ivar'>@neurons</span><span class='period'>.</span><span class='id identifier rubyid_merge!'>merge!</span> <span class='id identifier rubyid_neus'>neus</span><span class='period'>.</span><span class='id identifier rubyid_dclone'>dclone</span> <span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
<div class="method_details "> <h3 class="signature " id="neucleate-instance_method"> - (<tt>Object</tt>) <strong>neucleate</strong>(clean: true, &block)
</h3><div class=“docstring”>
<div class="discussion">
<p>We add genes given here to the genome. An array of genes is returned from the block and we simply add them in.</p>
</div>
</div> <div class=“tags”>
<p class="tag_title">Parameters:</p>
<ul class=“param”>
<li> <span class='name'>clean</span> <span class='type'>(<tt>boolean</tt>)</span> </li> <li> <span class='name'>block</span> <span class='type'>(<tt>Proc</tt>)</span> </li>
</ul>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
113 114 115 116 117 118 119 120 121 122 123</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 113</span>
<span class='kw'>def</span> <span class='id identifier rubyid_neucleate'>neucleate</span><span class='lparen'>(</span><span class='label'>clean:</span> <span class='kw'>true</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>
<span class='id identifier rubyid_genes'>genes</span> <span class='op'>=</span> <span class='const'>Hash</span><span class='lbracket'>[</span><span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='lparen'>(</span><span class='kw'>self</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_g'>g</span><span class='op'>|</span> <span class='id identifier rubyid_g'>g</span><span class='period'>.</span><span class='id identifier rubyid_genotype'>genotype</span> <span class='op'>=</span> <span class='kw'>self</span> <span class='lbracket'>[</span><span class='id identifier rubyid_g'>g</span><span class='period'>.</span><span class='id identifier rubyid_innovation'>innovation</span><span class='comma'>,</span> <span class='id identifier rubyid_g'>g</span><span class='rbracket'>]</span> <span class='rbrace'>}</span><span class='rbracket'>]</span> <span class='kw'>if</span> <span class='id identifier rubyid_clean'>clean</span> <span class='ivar'>@genes</span> <span class='op'>=</span> <span class='id identifier rubyid_genes'>genes</span> <span class='kw'>else</span> <span class='ivar'>@genes</span><span class='period'>.</span><span class='id identifier rubyid_merge!'>merge!</span> <span class='id identifier rubyid_genes'>genes</span> <span class='kw'>end</span> <span class='id identifier rubyid_nuke_redundancies!'>nuke_redundancies!</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
<div class="method_details "> <h3 class="signature " id="nuke_redundancies!-instance_method"> - (<tt>Object</tt>) <strong>nuke_redundancies!</strong>
</h3><div class=“docstring”>
<div class="discussion">
<p>Remove any redundancies in the genome, any genes refering to the same two neurons. Simply choose one and delete the rest. TODO: implement nuke_redundancies!</p>
</div>
</div> <div class=“tags”>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
129 130 131</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 129</span>
<span class='kw'>def</span> <span class='id identifier rubyid_nuke_redundancies!'>nuke_redundancies!</span>
<span class='id identifier rubyid_log'>log</span><span class='period'>.</span><span class='id identifier rubyid_warn'>warn</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>nuke_redundancies! NIY</span><span class='tstring_end'>'</span></span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
<div class="method_details "> <h3 class="signature " id="prune!-instance_method"> - (<tt>Object</tt>) <strong>prune!</strong>
</h3><div class=“docstring”>
<div class="discussion">
<p>Go through the list of neurons and drop any neurons not referenced by the genes.</p>
<p>Then go through the genes and drop any that are dangling (i.e. no matching neurons)</p>
<p>Then make sure that @neural_inputs and @neural_outputs reference the actual instance neurons in @neurons</p>
<p>TODO add this circularity check to prune!</p>
</div>
</div> <div class=“tags”>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 191</span>
<span class='kw'>def</span> <span class='id identifier rubyid_prune!'>prune!</span>
<span class='comment'># Take care of dangling neurons
</span> <span class='id identifier rubyid_neunames'>neunames</span> <span class='op'>=</span> <span class='ivar'>@genes</span><span class='period'>.</span><span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_g'>g</span><span class='op'>|</span> <span class='lbracket'>[</span><span class='id identifier rubyid_g'>g</span><span class='period'>.</span><span class='id identifier rubyid_in_neuron'>in_neuron</span><span class='comma'>,</span> <span class='id identifier rubyid_g'>g</span><span class='period'>.</span><span class='id identifier rubyid_out_neuron'>out_neuron</span><span class='rbracket'>]</span><span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_flatten'>flatten</span><span class='period'>.</span><span class='id identifier rubyid_to_set'>to_set</span>
<span class='ivar'>@neurons</span> <span class='op'>=</span> <span class='const'>Hash</span><span class='lbracket'>[</span><span class='ivar'>@neurons</span><span class='period'>.</span><span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_reject'>reject</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span> <span class='kw'>not</span> <span class='id identifier rubyid_neunames'>neunames</span><span class='period'>.</span><span class='id identifier rubyid_member?'>member?</span> <span class='id identifier rubyid_n'>n</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span> <span class='kw'>end</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span> <span class='lbracket'>[</span><span class='id identifier rubyid_n'>n</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_n'>n</span><span class='rbracket'>]</span> <span class='kw'>end</span><span class='rbracket'>]</span> <span class='comment'># Take care of dangling genes
</span> <span class='ivar'>@genes</span> <span class='op'>=</span> <span class='const'>Hash</span><span class='lbracket'>[</span><span class='ivar'>@genes</span><span class='period'>.</span><span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_reject'>reject</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_gene'>gene</span><span class='op'>|</span>
<span class='kw'>not</span> <span class='lparen'>(</span><span class='ivar'>@neurons</span><span class='period'>.</span><span class='id identifier rubyid_member?'>member?</span><span class='lparen'>(</span><span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_in_neuron'>in_neuron</span><span class='rparen'>)</span> <span class='kw'>and</span> <span class='ivar'>@neurons</span><span class='period'>.</span><span class='id identifier rubyid_member?'>member?</span><span class='lparen'>(</span><span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_out_neuron'>out_neuron</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='kw'>end</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_gene'>gene</span><span class='op'>|</span> <span class='lbracket'>[</span><span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_gene'>gene</span><span class='rbracket'>]</span> <span class='kw'>end</span><span class='rbracket'>]</span> <span class='comment'># Make sure @neural_inputs and @neural_outputs are consistent
</span> <span class='ivar'>@neural_inputs</span> <span class='op'>=</span> <span class='const'>Hash</span><span class='lbracket'>[</span><span class='ivar'>@neural_inputs</span><span class='period'>.</span><span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span> <span class='lbracket'>[</span><span class='id identifier rubyid_n'>n</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='ivar'>@neurons</span><span class='lbracket'>[</span><span class='id identifier rubyid_n'>n</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span><span class='rbracket'>]</span><span class='rbrace'>}</span><span class='rbracket'>]</span>
<span class='ivar'>@neural_outputs</span> <span class='op'>=</span> <span class='const'>Hash</span><span class='lbracket'>[</span><span class='ivar'>@neural_outputs</span><span class='period'>.</span><span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_n'>n</span><span class='op'>|</span> <span class='lbracket'>[</span><span class='id identifier rubyid_n'>n</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='ivar'>@neurons</span><span class='lbracket'>[</span><span class='id identifier rubyid_n'>n</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='rbracket'>]</span><span class='rbracket'>]</span><span class='rbrace'>}</span><span class='rbracket'>]</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
<div class="method_details "> <h3 class="signature " id="wire!-instance_method"> - (<tt>Object</tt>) <strong>wire!</strong>
</h3><div class=“docstring”>
<div class="discussion">
<p>Wire up the neurons based on the genes.</p>
</div>
</div> <div class=“tags”>
</div><table class=“source_code”>
<tr> <td> <pre class="lines">
140 141 142 143 144 145 146 147 148 149 150 151 152</pre>
</td> <td> <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 140</span>
<span class='kw'>def</span> <span class='id identifier rubyid_wire!'>wire!</span>
<span class='id identifier rubyid_forget!'>forget!</span> <span class='ivar'>@genes</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_innov'>innov</span><span class='comma'>,</span> <span class='id identifier rubyid_gene'>gene</span><span class='op'>|</span> <span class='kw'>if</span> <span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_enabled?'>enabled?</span> <span class='id identifier rubyid_raise'>raise</span> <span class='const'>NeatException</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Can't find </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_out_neuron'>out_neuron</span><span class='embexpr_end'>}</span><span class='tstring_end'>"</span></span> <span class='kw'>if</span> <span class='ivar'>@neurons</span><span class='lbracket'>[</span><span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_out_neuron'>out_neuron</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='ivar'>@neurons</span><span class='lbracket'>[</span><span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_out_neuron'>out_neuron</span><span class='rbracket'>]</span> <span class='op'><<</span> <span class='ivar'>@neurons</span><span class='lbracket'>[</span><span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_in_neuron'>in_neuron</span><span class='rbracket'>]</span> <span class='ivar'>@neural_gene_map</span><span class='lbracket'>[</span><span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_out_neuron'>out_neuron</span><span class='rbracket'>]</span> <span class='op'><<</span> <span class='id identifier rubyid_gene'>gene</span> <span class='kw'>unless</span> <span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_in_neuron'>in_neuron</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='kw'>end</span> <span class='kw'>end</span> <span class='kw'>unless</span> <span class='ivar'>@genes</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='kw'>if</span> <span class='ivar'>@genes</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span> <span class='gvar'>$log</span><span class='period'>.</span><span class='id identifier rubyid_error'>error</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>Genes Not Present</span><span class='tstring_end'>'</span></span> <span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td> </tr>
</table> </div>
</div>
</div>
<div id="footer"> Generated on Sun Mar 16 16:36:51 2014 by <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> 0.8.7.3 (ruby-2.1.1).
</div>
</body>
</html>