<!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::Evolver::CritterOp

  &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'><span class='object_link'><a href="../Evolver.html" title="NEAT::Evolver (class)">Evolver</a></span></span>
   &raquo; 
  <span class="title">CritterOp</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::Evolver::CritterOp

</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::Evolver::CritterOp</li>

    </ul>
    <a href="#" class="inheritanceTree">show all</a>

  </dd>

<dt class="r2 last">Defined in:</dt>
<dd class="r2 last">lib/rubyneat/evolver.rb</dd>

</dl> <div class=“clear”></div>

<h2>Overview</h2><div class=“docstring”>

<div class="discussion">

<p>A set of Critter Genotype operators.</p>

</div>

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

</div>

<h2>Instance Attribute Summary</h2>

<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_gene%21-instance_method" title="#add_gene! (instance method)">- (Object) <strong>add_gene!</strong>(crit) </a>

</span>

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

<h1 id=“label-Add+a+gene+to+the+genome+Unlike+adding+a+new+neuron%2C+adding+a+new+gene+could+result+in+a+circular+dependency.”>Add a gene to the genome Unlike adding a new neuron, adding a new gene could result in a circular dependency.</h1> </div></span>

</li>

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

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

</span>

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

<h1 id=“label-Add+a+neuron+to+given+critter+Here%2C+we+add+a+neuron+by+randomly+picking+a+gene%2C+and+split+it+into+two+genes+with+an+intervening+neuron.”>Add a neuron to given critter Here, we add a neuron by randomly picking a gene, and split it into two genes with an intervening neuron.</h1> </div></span>

</li>

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

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

</span>

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

<p>Pick an enabled gene at random and disable it.</p> </div></span>

</li>

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

    <a href="#initialize-instance_method" title="#initialize (instance method)">- (CritterOp) <strong>initialize</strong>(evol) </a>

</span>

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

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

<p>A new instance of CritterOp.</p> </div></span>

</li>

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

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

</span>

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

<p>Pick a disabled gene at random and reenable it.</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::Evolver::CritterOp (class)">CritterOp</a></span></tt>) <strong>initialize</strong>(evol)

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

<div class="discussion">

<p>Returns a new instance of CritterOp</p>

</div>

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

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

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

254 255 256 257 258</pre>

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

<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_evol'>evol</span><span class='rparen'>)</span>

<span class='kw'>super</span> <span class='id identifier rubyid_evol'>evol</span><span class='period'>.</span><span class='id identifier rubyid_controller'>controller</span>
<span class='ivar'>@evolver</span> <span class='op'>=</span> <span class='id identifier rubyid_evol'>evol</span>
<span class='ivar'>@npop</span> <span class='op'>=</span> <span class='id identifier rubyid_evol'>evol</span><span class='period'>.</span><span class='id identifier rubyid_npop'>npop</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_gene!-instance_method">

  - (<tt>Object</tt>) <strong>add_gene!</strong>(crit)

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

<div class="discussion">

<h1 id=“label-Add+a+gene+to+the+genome”>Add a gene to the genome</h1>

<p>Unlike adding a new neuron, adding a new gene could result in a circular dependency. If so, and if recurrency is switched off, we must detect this condition and switch off the offending neurons.</p>

<p>Obviously, this might result in a loss of functionality, but oh well.</p>

<p>An easy and obvious check is to make sure we don&#39;t accept any inputs from output neurons, and we don&#39;t do any outputs to input neurons.</p>

<p>Constructs for handling recurrency are present in Expressor.</p>

</div>

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

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

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

290 291 292 293 294 295 296 297 298 299 300</pre>

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

<span class='kw'>def</span> <span class='id identifier rubyid_add_gene!'>add_gene!</span><span class='lparen'>(</span><span class='id identifier rubyid_crit'>crit</span><span class='rparen'>)</span>

<span class='id identifier rubyid_n1'>n1</span> <span class='op'>=</span> <span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_genotype'>genotype</span><span class='period'>.</span><span class='id identifier rubyid_neurons'>neurons</span><span class='period'>.</span><span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_sample'>sample</span> <span class='comment'># input

</span> <span class='id identifier rubyid_n2'>n2</span> <span class='op'>=</span> <span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_genotype'>genotype</span><span class='period'>.</span><span class='id identifier rubyid_neurons'>neurons</span><span class='period'>.</span><span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_sample'>sample</span> <span class='comment'># output </span>

<span class='comment'># Sanity checks!

</span> <span class='kw'>unless</span> <span class='id identifier rubyid_n1'>n1</span> <span class='op'>==</span> <span class='id identifier rubyid_n2'>n2</span> <span class='kw'>or</span> <span class='id identifier rubyid_n1'>n1</span><span class='period'>.</span><span class='id identifier rubyid_output?'>output?</span> <span class='kw'>or</span> <span class='id identifier rubyid_n2'>n2</span><span class='period'>.</span><span class='id identifier rubyid_input?'>input?</span>

  <span class='id identifier rubyid_gene'>gene</span> <span class='op'>=</span> <span class='const'>Critter</span><span class='op'>::</span><span class='const'>Genotype</span><span class='op'>::</span><span class='const'>Gene</span><span class='lbracket'>[</span><span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_genotype'>genotype</span><span class='comma'>,</span> <span class='id identifier rubyid_n1'>n1</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='id identifier rubyid_n2'>n2</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='const'>NEAT</span><span class='op'>::</span><span class='id identifier rubyid_controller'>controller</span><span class='period'>.</span><span class='id identifier rubyid_gaussian'>gaussian</span><span class='rbracket'>]</span>
  <span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_genotype'>genotype</span><span class='period'>.</span><span class='id identifier rubyid_add_genes'>add_genes</span> <span class='id identifier rubyid_gene'>gene</span>
  <span class='id identifier rubyid_log'>log</span><span class='period'>.</span><span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>add_gene! Added gene </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_gene'>gene</span><span class='embexpr_end'>}</span><span class='tstring_content'>(</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_n1'>n1</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_content'> -&gt; </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_n2'>n2</span><span class='period'>.</span><span class='id identifier rubyid_name'>name</span><span class='embexpr_end'>}</span><span class='tstring_content'>) to </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_crit'>crit</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></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_neuron!-instance_method">

  - (<tt>Object</tt>) <strong>add_neuron!</strong>(crit)

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

<div class="discussion">

<h1 id=“label-Add+a+neuron+to+given+critter”>Add a neuron to given critter</h1>

<p>Here, we add a neuron by randomly picking a gene, and split it into two genes with an intervening neuron. The old gene is not replaced, but disabled. 2 new genes are created along with the new neuron.</p>

</div>

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

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

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

265 266 267 268 269 270 271 272 273 274</pre>

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

<span class='kw'>def</span> <span class='id identifier rubyid_add_neuron!'>add_neuron!</span><span class='lparen'>(</span><span class='id identifier rubyid_crit'>crit</span><span class='rparen'>)</span>

<span class='id identifier rubyid_gene'>gene</span> <span class='op'>=</span> <span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_genotype'>genotype</span><span class='period'>.</span><span class='id identifier rubyid_genes'>genes</span><span class='period'>.</span><span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_sample'>sample</span>
<span class='id identifier rubyid_neu'>neu</span> <span class='op'>=</span> <span class='id identifier rubyid_controller'>controller</span><span class='period'>.</span><span class='id identifier rubyid_neural_hidden'>neural_hidden</span><span class='period'>.</span><span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_sample'>sample</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_controller'>controller</span><span class='rparen'>)</span>
<span class='id identifier rubyid_g1'>g1</span> <span class='op'>=</span> <span class='const'>Critter</span><span class='op'>::</span><span class='const'>Genotype</span><span class='op'>::</span><span class='const'>Gene</span><span class='lbracket'>[</span><span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_genotype'>genotype</span><span class='comma'>,</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='comma'>,</span> <span class='id identifier rubyid_neu'>neu</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='period'>.</span><span class='id identifier rubyid_weight'>weight</span><span class='rbracket'>]</span>
<span class='id identifier rubyid_g2'>g2</span> <span class='op'>=</span> <span class='const'>Critter</span><span class='op'>::</span><span class='const'>Genotype</span><span class='op'>::</span><span class='const'>Gene</span><span class='lbracket'>[</span><span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_genotype'>genotype</span><span class='comma'>,</span> <span class='id identifier rubyid_neu'>neu</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='period'>.</span><span class='id identifier rubyid_out_neuron'>out_neuron</span><span class='comma'>,</span> <span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_weight'>weight</span><span class='rbracket'>]</span>
<span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_enabled'>enabled</span> <span class='op'>=</span> <span class='kw'>false</span>
<span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_genotype'>genotype</span><span class='period'>.</span><span class='id identifier rubyid_add_neurons'>add_neurons</span> <span class='id identifier rubyid_neu'>neu</span>
<span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_genotype'>genotype</span><span class='period'>.</span><span class='id identifier rubyid_add_genes'>add_genes</span> <span class='id identifier rubyid_g1'>g1</span><span class='comma'>,</span> <span class='id identifier rubyid_g2'>g2</span>
<span class='id identifier rubyid_log'>log</span><span class='period'>.</span><span class='id identifier rubyid_debug'>debug</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>add_neuron!: neu </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_neu'>neu</span><span class='embexpr_end'>}</span><span class='tstring_content'>, g1 </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_g1'>g1</span><span class='embexpr_end'>}</span><span class='tstring_content'>, g2 </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_g2'>g2</span><span class='embexpr_end'>}</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="disable_gene!-instance_method">

  - (<tt>Object</tt>) <strong>disable_gene!</strong>(crit)

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

<div class="discussion">

<p>Pick an enabled gene at random and disable it.</p>

</div>

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

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

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

303 304 305 306</pre>

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

<span class='kw'>def</span> <span class='id identifier rubyid_disable_gene!'>disable_gene!</span><span class='lparen'>(</span><span class='id identifier rubyid_crit'>crit</span><span class='rparen'>)</span>

<span class='id identifier rubyid_gene'>gene</span> <span class='op'>=</span> <span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_genotype'>genotype</span><span class='period'>.</span><span class='id identifier rubyid_genes'>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='lbrace'>{</span><span class='op'>|</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_disabled?'>disabled?</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_sample'>sample</span>
<span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_enabled'>enabled</span> <span class='op'>=</span> <span class='kw'>false</span> <span class='kw'>unless</span> <span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_nil?'>nil?</span>

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

  </td>
</tr>

</table> </div>

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

  - (<tt>Object</tt>) <strong>reenable_gene!</strong>(crit)

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

<div class="discussion">

<p>Pick a disabled gene at random and reenable it.</p>

</div>

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

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

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

309 310 311 312</pre>

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

<span class='kw'>def</span> <span class='id identifier rubyid_reenable_gene!'>reenable_gene!</span><span class='lparen'>(</span><span class='id identifier rubyid_crit'>crit</span><span class='rparen'>)</span>

<span class='id identifier rubyid_gene'>gene</span> <span class='op'>=</span> <span class='id identifier rubyid_crit'>crit</span><span class='period'>.</span><span class='id identifier rubyid_genotype'>genotype</span><span class='period'>.</span><span class='id identifier rubyid_genes'>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='lbrace'>{</span><span class='op'>|</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_enabled?'>enabled?</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_sample'>sample</span>
<span class='id identifier rubyid_gene'>gene</span><span class='period'>.</span><span class='id identifier rubyid_enabled'>enabled</span> <span class='op'>=</span> <span class='kw'>true</span> <span class='kw'>unless</span> <span class='id identifier rubyid_gene'>gene</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>

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