intelligence
Version:
Machine learning library written in javascript
1,456 lines (451 loc) • 20 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Class: Population</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Class: Population</h1>
<section>
<header>
<h2>
Population
</h2>
</header>
<article>
<div class="container-overview">
<dt>
<h4 class="name" id="Population"><span class="type-signature"></span>new Population<span class="signature">(options)</span><span class="type-signature"></span></h4>
</dt>
<dd>
<div class="description">
<p>Genetic algorithm population</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>Population options</p>
<h6>Properties</h6>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>baseIndividual</code></td>
<td class="type">
<span class="param-type"><a href="Individual.html">Individual</a></span>
</td>
<td class="description last"><p>-</p></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
<dl class="details">
<h5 class="subsection-title">Properties:</h5>
<dl>
<table class="props">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>options</code></td>
<td class="type">
<span class="param-type">object</span>
</td>
<td class="description last"><p>Population options</p></td>
</tr>
</tbody>
</table></dl>
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="population.js.html">genetic/population.js</a>, <a href="population.js.html#line12">line 12</a>
</li></ul></dd>
</dl>
</dd>
</div>
<h3 class="subsection-title">Methods</h3>
<dl>
<dt>
<h4 class="name" id="crossover"><span class="type-signature"></span>crossover<span class="signature">()</span><span class="type-signature"> → {<a href="Population.html">Population</a>}</span></h4>
</dt>
<dd>
<div class="description">
<p>Performs crossover using the crossoverStrategy function defined in the population options</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="population.js.html">genetic/population.js</a>, <a href="population.js.html#line96">line 96</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Reference to current object for chaining</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="Population.html">Population</a></span>
</dd>
</dl>
</dd>
<dt>
<h4 class="name" id="evaluateFitness"><span class="type-signature"></span>evaluateFitness<span class="signature">()</span><span class="type-signature"> → {<a href="Population.html">Population</a>}</span></h4>
</dt>
<dd>
<div class="description">
<p>Calculates the fitness of each individual where the fitness value is null</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="population.js.html">genetic/population.js</a>, <a href="population.js.html#line82">line 82</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Reference to current object for chaining</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="Population.html">Population</a></span>
</dd>
</dl>
</dd>
<dt>
<h4 class="name" id="filterNanFitness"><span class="type-signature"></span>filterNanFitness<span class="signature">()</span><span class="type-signature"> → {<a href="Population.html">Population</a>}</span></h4>
</dt>
<dd>
<div class="description">
<p>Subsitutes an individuals fitness to positive or negative infinity if it isNaN</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="population.js.html">genetic/population.js</a>, <a href="population.js.html#line203">line 203</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Reference to current object for chaining</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="Population.html">Population</a></span>
</dd>
</dl>
</dd>
<dt>
<h4 class="name" id="getAverageFitness"><span class="type-signature"></span>getAverageFitness<span class="signature">()</span><span class="type-signature"> → {number}</span></h4>
</dt>
<dd>
<div class="description">
<p>Calculate the average fitness of all individuals in the population (exluding infinite values)</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="population.js.html">genetic/population.js</a>, <a href="population.js.html#line162">line 162</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Average fitness of the population</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">number</span>
</dd>
</dl>
</dd>
<dt>
<h4 class="name" id="getFittestIndividuals"><span class="type-signature"></span>getFittestIndividuals<span class="signature">(numIndividuals<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Array.<<a href="Individual.html">Individual</a>>}</span></h4>
</dt>
<dd>
<div class="description">
<p>Returns a specified number of individuals with the best fitness rating in the population</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>numIndividuals</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
1
</td>
<td class="description last"><p>The number of individuals to return</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="population.js.html">genetic/population.js</a>, <a href="population.js.html#line140">line 140</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>An array of the fittest individuals in the population</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Array.<<a href="Individual.html">Individual</a>></span>
</dd>
</dl>
</dd>
<dt>
<h4 class="name" id="initialise"><span class="type-signature"></span>initialise<span class="signature">()</span><span class="type-signature"> → {<a href="Population.html">Population</a>}</span></h4>
</dt>
<dd>
<div class="description">
<p>Creates a randomly generated population of individuals</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="population.js.html">genetic/population.js</a>, <a href="population.js.html#line70">line 70</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Reference to current object for chaining</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="Population.html">Population</a></span>
</dd>
</dl>
</dd>
<dt>
<h4 class="name" id="mutate"><span class="type-signature"></span>mutate<span class="signature">()</span><span class="type-signature"> → {<a href="Population.html">Population</a>}</span></h4>
</dt>
<dd>
<div class="description">
<p>Mutates the population based on the mutationRate property in each individuals options</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="population.js.html">genetic/population.js</a>, <a href="population.js.html#line122">line 122</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Reference to current object for chaining</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="Population.html">Population</a></span>
</dd>
</dl>
</dd>
<dt>
<h4 class="name" id="setDefaultOptionsIfNotProvided"><span class="type-signature"></span>setDefaultOptionsIfNotProvided<span class="signature">()</span><span class="type-signature"> → {<a href="Population.html">Population</a>}</span></h4>
</dt>
<dd>
<div class="description">
<p>Sets default values for options that have not been defined</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="population.js.html">genetic/population.js</a>, <a href="population.js.html#line47">line 47</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Reference to current object for chaining</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="Population.html">Population</a></span>
</dd>
</dl>
</dd>
<dt>
<h4 class="name" id="step"><span class="type-signature"></span>step<span class="signature">()</span><span class="type-signature"> → {<a href="Population.html">Population</a>}</span></h4>
</dt>
<dd>
<div class="description">
<p>Applies a single iteration of crossover and mutation to the population</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="population.js.html">genetic/population.js</a>, <a href="population.js.html#line177">line 177</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Reference to current object for chaining</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="Population.html">Population</a></span>
</dd>
</dl>
</dd>
<dt>
<h4 class="name" id="train"><span class="type-signature"></span>train<span class="signature">(numGenerations)</span><span class="type-signature"> → {<a href="Population.html">Population</a>}</span></h4>
</dt>
<dd>
<div class="description">
<p>Trains the population over a specified number of generations</p>
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>numGenerations</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="description last"><p>The number of generations to train the population over</p></td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="population.js.html">genetic/population.js</a>, <a href="population.js.html#line186">line 186</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
<p>Reference to current object for chaining</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="Population.html">Population</a></span>
</dd>
</dl>
</dd>
<dt>
<h4 class="name" id="validateRequiredOptions"><span class="type-signature"></span>validateRequiredOptions<span class="signature">()</span><span class="type-signature"> → {<a href="Population.html">Population</a>}</span></h4>
</dt>
<dd>
<div class="description">
<p>Throws an exception if a required option is missing</p>
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="population.js.html">genetic/population.js</a>, <a href="population.js.html#line30">line 30</a>
</li></ul></dd>
</dl>
<h5>Throws:</h5>
<div class="param-desc">
An exception is thrown if a required option is missing
</div>
<h5>Returns:</h5>
<div class="param-desc">
<p>Reference to current object for chaining</p>
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type"><a href="Population.html">Population</a></span>
</dd>
</dl>
</dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Index</a></h2><h3>Classes</h3><ul><li><a href="Individual.html">Individual</a></li><li><a href="LinearConditionalNode.html">LinearConditionalNode</a></li><li><a href="LinearFunctionNode.html">LinearFunctionNode</a></li><li><a href="LinearGPNode.html">LinearGPNode</a></li><li><a href="LinearIndividual.html">LinearIndividual</a></li><li><a href="Population.html">Population</a></li><li><a href="RegisterReference.html">RegisterReference</a></li><li><a href="RegisterSet.html">RegisterSet</a></li></ul><h3>Global</h3><ul><li><a href="global.html#alphabet">alphabet</a></li><li><a href="global.html#arrayEqual">arrayEqual</a></li><li><a href="global.html#binaryNumber">binaryNumber</a></li><li><a href="global.html#binaryString">binaryString</a></li><li><a href="global.html#createCalculation">createCalculation</a></li><li><a href="global.html#createConstant">createConstant</a></li><li><a href="global.html#createInput">createInput</a></li><li><a href="global.html#createOutput">createOutput</a></li><li><a href="global.html#formatString">formatString</a></li><li><a href="global.html#fpEqual">fpEqual</a></li><li><a href="global.html#inherits">inherits</a></li><li><a href="global.html#linearNode">linearNode</a></li><li><a href="global.html#onePointFixed">onePointFixed</a></li><li><a href="global.html#onePointVariable">onePointVariable</a></li><li><a href="global.html#randBetween">randBetween</a></li><li><a href="global.html#random">random</a></li><li><a href="global.html#randomNumber">randomNumber</a></li><li><a href="global.html#rank">rank</a></li><li><a href="global.html#rouletteWheel">rouletteWheel</a></li><li><a href="global.html#selectRandom">selectRandom</a></li><li><a href="global.html#swapGenes">swapGenes</a></li><li><a href="global.html#tournament">tournament</a></li><li><a href="global.html#twoPointFixed">twoPointFixed</a></li><li><a href="global.html#twoPointVariable">twoPointVariable</a></li><li><a href="global.html#uniform">uniform</a></li><li><a href="global.html#validateFixedLength">validateFixedLength</a></li><li><a href="global.html#validateMinimumLength">validateMinimumLength</a></li><li><a href="global.html#validateVariableLength">validateVariableLength</a></li></ul>
</nav>
<br clear="both">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.3.0-alpha9</a> on Sat Aug 16 2014 23:33:40 GMT+0100 (GMT Summer Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>