<!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

  &mdash; 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 (C)</a> &raquo;
  <span class='title'><span class='object_link'><a href="../NEAT.html" title="NEAT (module)">NEAT</a></span></span>
   &raquo; 
  <span class="title">Critter</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

</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</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-Critters+for+NEAT”>Critters for NEAT</h1>

<p>The Critter class comprises a Genotype and a Phenotype. The Genotype comprises Genes and Neurons.</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="Critter/Genotype.html" title="NEAT::Critter::Genotype (class)">Genotype</a></span>, <span class='object_link'><a href="Critter/Phenotype.html" title="NEAT::Critter::Phenotype (class)">Phenotype</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="#fitness-instance_method" title="#fitness (instance method)">- (Object) <strong>fitness</strong> </a>

</span>

  <span class="summary_desc"><div class='inline'>

<p>Ratings assigned by Evaluator.</p> </div></span>

</li>

    <li class="public ">
<span class="summary_signature">

    <a href="#genotype-instance_method" title="#genotype (instance method)">- (Object) <strong>genotype</strong> </a>

</span>

  <span class="summary_desc"><div class='inline'>

<p>Returns the value of attribute genotype.</p> </div></span>

</li>

    <li class="public ">
<span class="summary_signature">

    <a href="#novelty-instance_method" title="#novelty (instance method)">- (Object) <strong>novelty</strong> </a>

</span>

  <span class="summary_desc"><div class='inline'>

<p>Ratings assigned by Evaluator.</p> </div></span>

</li>

    <li class="public ">
<span class="summary_signature">

    <a href="#phenotype-instance_method" title="#phenotype (instance method)">- (Object) <strong>phenotype</strong> </a>

</span>

  <span class="summary_desc"><div class='inline'>

<p>Returns the value of attribute phenotype.</p> </div></span>

</li>

    <li class="public ">
<span class="summary_signature">

    <a href="#population-instance_method" title="#population (instance method)">- (Object) <strong>population</strong> </a>

</span>

    <span class="note title readonly">readonly</span>

  <span class="summary_desc"><div class='inline'>

<p>Returns the value of attribute population.</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="#compare-instance_method" title="#compare (instance method)">- (Object) <strong>compare</strong>(oc) </a>

</span>

  <span class="summary_desc"><div class='inline'>

<p>Compare ourselves against another critter for compability.</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'>

<p>Critter print.</p> </div></span>

</li>

      <li class="public ">
<span class="summary_signature">

    <a href="#evaluate%21-instance_method" title="#evaluate! (instance method)">- (Object) <strong>evaluate!</strong> </a>

</span>

  <span class="summary_desc"><div class='inline'>

<p>A single evaluation step.</p> </div></span>

</li>

      <li class="public ">
<span class="summary_signature">

    <a href="#express%21-instance_method" title="#express! (instance method)">- (Object) <strong>express!</strong> </a>

</span>

  <span class="summary_desc"><div class='inline'>

<p>Exoress this critter using the Expressor plugin.</p> </div></span>

</li>

      <li class="public ">
<span class="summary_signature">

    <a href="#initialize-instance_method" title="#initialize (instance method)">- (Critter) <strong>initialize</strong>(pop, mating = false, &amp;block) </a>

</span>

  <span class="note title constructor">constructor</span>

  <span class="summary_desc"><div class='inline'>

<p>Critter construction.</p> </div></span>

</li>

      <li class="public ">
<span class="summary_signature">

    <a href="#initialize_neurons%21-instance_method" title="#initialize_neurons! (instance method)">- (Object) <strong>initialize_neurons!</strong> </a>

</span>

  <span class="summary_desc"><div class='inline'>

<p>This initializes neurons in preparation for recurrence.</p> </div></span>

</li>

      <li class="public ">
<span class="summary_signature">

    <a href="#ready_for_expression%21-instance_method" title="#ready_for_expression! (instance method)">- (Object) <strong>ready_for_expression!</strong> </a>

</span>

  <span class="summary_desc"><div class='inline'>

<p>Get the Critter ready for the Expressor to express the geneotype.</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 (class)">Critter</a></span></tt>) <strong>initialize</strong>(pop, mating = false, &amp;block)

</h3><div class=“docstring”>

<div class="discussion">

<p>Critter construction. We construct the genotype. The phenotype will be constructed by the Expressor operator.</p>

</div>

</div> <div class=“tags”>

</div><table class=“source_code”>

<tr>
  <td>
    <pre class="lines">

20 21 22 23 24 25</pre>

</td>
<td>
  <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 20</span>

<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_pop'>pop</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'>&amp;</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span>

<span class='kw'>super</span> <span class='id identifier rubyid_pop'>pop</span><span class='period'>.</span><span class='id identifier rubyid_controller'>controller</span>
<span class='ivar'>@population</span> <span class='op'>=</span> <span class='id identifier rubyid_pop'>pop</span>
<span class='ivar'>@genotype</span> <span class='op'>=</span> <span class='const'>Genotype</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='kw'>self</span><span class='comma'>,</span> <span class='id identifier rubyid_mating'>mating</span><span class='rparen'>)</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="fitness=-instance_method"></span>
    <div class="method_details first">
<h3 class="signature first" id="fitness-instance_method">

  - (<tt>Object</tt>) <strong>fitness</strong>

</h3><div class=“docstring”>

<div class="discussion">

<p>Ratings assigned by Evaluator</p>

</div>

</div> <div class=“tags”>

</div><table class=“source_code”>

<tr>
  <td>
    <pre class="lines">

16 17 18</pre>

</td>
<td>
  <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 16</span>

<span class='kw'>def</span> <span class='id identifier rubyid_fitness'>fitness</span>

<span class='ivar'>@fitness</span>

<span class='kw'>end</span></pre>

  </td>
</tr>

</table> </div>

    <span id="genotype=-instance_method"></span>
    <div class="method_details ">
<h3 class="signature " id="genotype-instance_method">

  - (<tt>Object</tt>) <strong>genotype</strong>

</h3><div class=“docstring”>

<div class="discussion">

<p>Returns the value of attribute genotype</p>

</div>

</div> <div class=“tags”>

</div><table class=“source_code”>

<tr>
  <td>
    <pre class="lines">

13 14 15</pre>

</td>
<td>
  <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 13</span>

<span class='kw'>def</span> <span class='id identifier rubyid_genotype'>genotype</span>

<span class='ivar'>@genotype</span>

<span class='kw'>end</span></pre>

  </td>
</tr>

</table> </div>

    <span id="novelty=-instance_method"></span>
    <div class="method_details ">
<h3 class="signature " id="novelty-instance_method">

  - (<tt>Object</tt>) <strong>novelty</strong>

</h3><div class=“docstring”>

<div class="discussion">

<p>Ratings assigned by Evaluator</p>

</div>

</div> <div class=“tags”>

</div><table class=“source_code”>

<tr>
  <td>
    <pre class="lines">

16 17 18</pre>

</td>
<td>
  <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 16</span>

<span class='kw'>def</span> <span class='id identifier rubyid_novelty'>novelty</span>

<span class='ivar'>@novelty</span>

<span class='kw'>end</span></pre>

  </td>
</tr>

</table> </div>

    <span id="phenotype=-instance_method"></span>
    <div class="method_details ">
<h3 class="signature " id="phenotype-instance_method">

  - (<tt>Object</tt>) <strong>phenotype</strong>

</h3><div class=“docstring”>

<div class="discussion">

<p>Returns the value of attribute phenotype</p>

</div>

</div> <div class=“tags”>

</div><table class=“source_code”>

<tr>
  <td>
    <pre class="lines">

13 14 15</pre>

</td>
<td>
  <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 13</span>

<span class='kw'>def</span> <span class='id identifier rubyid_phenotype'>phenotype</span>

<span class='ivar'>@phenotype</span>

<span class='kw'>end</span></pre>

  </td>
</tr>

</table> </div>

    <span id=""></span>
    <div class="method_details ">
<h3 class="signature " id="population-instance_method">

  - (<tt>Object</tt>) <strong>population</strong>  <span class="extras">(readonly)</span>

</h3><div class=“docstring”>

<div class="discussion">

<p>Returns the value of attribute population</p>

</div>

</div> <div class=“tags”>

</div><table class=“source_code”>

<tr>
  <td>
    <pre class="lines">

12 13 14</pre>

</td>
<td>
  <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 12</span>

<span class='kw'>def</span> <span class='id identifier rubyid_population'>population</span>

<span class='ivar'>@population</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="compare-instance_method">

  - (<tt>Object</tt>) <strong>compare</strong>(oc)

</h3><div class=“docstring”>

<div class="discussion">

<p>Compare ourselves against another critter for compability.</p>

<p>The function to be used here is: distance = c1*E + c2*D + c3*W</p>

<p>Where: E, D - The number of excess and disjoint genes repesctively. N - The number of genes in the largest genome. W - The sum of absolute weight differences.</p>

<p>This is a variation of the formulation suggested by the Stanley paper, which normalizes the E and D terms by N.</p>

</div>

</div> <div class=“tags”>

</div><table class=“source_code”>

<tr>
  <td>
    <pre class="lines">

333 334 335 336 337 338 339 340 341</pre>

</td>
<td>
  <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 333</span>

<span class='kw'>def</span> <span class='id identifier rubyid_compare'>compare</span><span class='lparen'>(</span><span class='id identifier rubyid_oc'>oc</span><span class='rparen'>)</span>

<span class='id identifier rubyid_c1'>c1</span> <span class='op'>=</span> <span class='ivar'>@controller</span><span class='period'>.</span><span class='id identifier rubyid_parms'>parms</span><span class='period'>.</span><span class='id identifier rubyid_excess_coefficient'>excess_coefficient</span>
<span class='id identifier rubyid_c2'>c2</span> <span class='op'>=</span> <span class='ivar'>@controller</span><span class='period'>.</span><span class='id identifier rubyid_parms'>parms</span><span class='period'>.</span><span class='id identifier rubyid_disjoint_coefficient'>disjoint_coefficient</span>
<span class='id identifier rubyid_c3'>c3</span> <span class='op'>=</span> <span class='ivar'>@controller</span><span class='period'>.</span><span class='id identifier rubyid_parms'>parms</span><span class='period'>.</span><span class='id identifier rubyid_weight_coefficient'>weight_coefficient</span>
<span class='id identifier rubyid_e'>e</span> <span class='op'>=</span> <span class='id identifier rubyid_excess'>excess</span><span class='lparen'>(</span><span class='id identifier rubyid_oc'>oc</span><span class='rparen'>)</span>
<span class='id identifier rubyid_d'>d</span> <span class='op'>=</span> <span class='id identifier rubyid_disjoint'>disjoint</span><span class='lparen'>(</span><span class='id identifier rubyid_oc'>oc</span><span class='rparen'>)</span>
<span class='id identifier rubyid_w'>w</span> <span class='op'>=</span> <span class='id identifier rubyid_weight_diff'>weight_diff</span><span class='lparen'>(</span><span class='id identifier rubyid_oc'>oc</span><span class='rparen'>)</span>
<span class='kw'>return</span> <span class='id identifier rubyid_c1'>c1</span> <span class='op'>*</span> <span class='id identifier rubyid_e'>e</span> <span class='op'>+</span> <span class='id identifier rubyid_c2'>c2</span> <span class='op'>*</span> <span class='id identifier rubyid_d'>d</span> <span class='op'>+</span> <span class='id identifier rubyid_c3'>c3</span> <span class='op'>*</span> <span class='id identifier rubyid_w'>w</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><div class=“docstring”>

<div class="discussion">

<p>Critter print</p>

</div>

</div> <div class=“tags”>

</div><table class=“source_code”>

<tr>
  <td>
    <pre class="lines">

344 345 346</pre>

</td>
<td>
  <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 344</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='ivar'>@genotype</span><span class='period'>.</span><span class='id identifier rubyid_dump_s'>dump_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>\n</span><span class='tstring_end'>&quot;</span></span> <span class='op'>+</span> <span class='ivar'>@phenotype</span><span class='period'>.</span><span class='id identifier rubyid_to_s'>to_s</span> <span class='op'>+</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>\n</span><span class='tstring_end'>&quot;</span></span>

<span class='kw'>end</span></pre>

  </td>
</tr>

</table> </div>

    <div class="method_details ">
<h3 class="signature " id="evaluate!-instance_method">

  - (<tt>Object</tt>) <strong>evaluate!</strong>

</h3><div class=“docstring”>

<div class="discussion">

<p>A single evaluation step. Evaluate and generate fitness, novelty, etc. Returns the result.</p>

</div>

</div> <div class=“tags”>

</div><table class=“source_code”>

<tr>
  <td>
    <pre class="lines">

50 51 52</pre>

</td>
<td>
  <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 50</span>

<span class='kw'>def</span> <span class='id identifier rubyid_evaluate!'>evaluate!</span>

<span class='ivar'>@controller</span><span class='period'>.</span><span class='id identifier rubyid_evaluator'>evaluator</span><span class='period'>.</span><span class='id identifier rubyid_evaluate!'>evaluate!</span> <span class='kw'>self</span>

<span class='kw'>end</span></pre>

  </td>
</tr>

</table> </div>

    <div class="method_details ">
<h3 class="signature " id="express!-instance_method">

  - (<tt>Object</tt>) <strong>express!</strong>

</h3><div class=“docstring”>

<div class="discussion">

<p>Exoress this critter using the Expressor plugin.</p>

</div>

</div> <div class=“tags”>

</div><table class=“source_code”>

<tr>
  <td>
    <pre class="lines">

36 37 38</pre>

</td>
<td>
  <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 36</span>

<span class='kw'>def</span> <span class='id identifier rubyid_express!'>express!</span>

<span class='ivar'>@controller</span><span class='period'>.</span><span class='id identifier rubyid_expressor'>expressor</span><span class='period'>.</span><span class='id identifier rubyid_express!'>express!</span> <span class='kw'>self</span>

<span class='kw'>end</span></pre>

  </td>
</tr>

</table> </div>

    <div class="method_details ">
<h3 class="signature " id="initialize_neurons!-instance_method">

  - (<tt>Object</tt>) <strong>initialize_neurons!</strong>

</h3><div class=“docstring”>

<div class="discussion">

<p>This initializes neurons in preparation for recurrence. Note that the Critter should already have expressed its genotype before this is called.</p>

</div>

</div> <div class=“tags”>

</div><table class=“source_code”>

<tr>
  <td>
    <pre class="lines">

43 44 45</pre>

</td>
<td>
  <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 43</span>

<span class='kw'>def</span> <span class='id identifier rubyid_initialize_neurons!'>initialize_neurons!</span>

<span class='ivar'>@phenotype</span><span class='period'>.</span><span class='id identifier rubyid_initialize_neurons'>initialize_neurons</span>

<span class='kw'>end</span></pre>

  </td>
</tr>

</table> </div>

    <div class="method_details ">
<h3 class="signature " id="ready_for_expression!-instance_method">

  - (<tt>Object</tt>) <strong>ready_for_expression!</strong>

</h3><div class=“docstring”>

<div class="discussion">

<p>Get the Critter ready for the Expressor to express the geneotype.</p>

</div>

</div> <div class=“tags”>

</div><table class=“source_code”>

<tr>
  <td>
    <pre class="lines">

29 30 31 32 33</pre>

</td>
<td>
  <pre class="code"><span class="info file"># File 'lib/rubyneat/critter.rb', line 29</span>

<span class='kw'>def</span> <span class='id identifier rubyid_ready_for_expression!'>ready_for_expression!</span>

<span class='ivar'>@genotype</span><span class='period'>.</span><span class='id identifier rubyid_wire!'>wire!</span>
<span class='ivar'>@phenotype</span> <span class='op'>=</span> <span class='const'>NEAT</span><span class='op'>::</span><span class='const'>Critter</span><span class='op'>::</span><span class='const'>Phenotype</span><span class='lbracket'>[</span><span class='kw'>self</span><span class='rbracket'>]</span>
<span class='ivar'>@phenotype</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>