Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Improve documentation, remove trailing whitespace

  • Loading branch information...
commit 0fd38db8f699c76e1417e07aea16475ae7faf195 1 parent ea4d09c
@tmcw authored
Showing with 18 additions and 7 deletions.
  1. +8 −4 docs/simple_statistics.html
  2. +10 −3 src/simple_statistics.js
View
12 docs/simple_statistics.html
@@ -296,7 +296,9 @@
<span class="p">}</span> <span class="k">else</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-95"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-95">&#182;</a> </div> <p>Finally, in the simple case of an integer value
with an odd-length list, return the sample value at the index.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">return</span> <span class="nx">sorted</span><span class="p">[</span><span class="nx">idx</span><span class="p">];</span>
<span class="p">}</span>
- <span class="p">};</span></pre></div> </td> </tr> <tr id="section-96"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-96">&#182;</a> </div> <p>Compute the matrices required for Jenks breaks. These matrices
+ <span class="p">};</span></pre></div> </td> </tr> <tr id="section-96"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-96">&#182;</a> </div> <h2>Compute Matrices for Jenks</h2>
+
+<p>Compute the matrices required for Jenks breaks. These matrices
can be used for any classing of data with <code>classes &lt;= n_classes</code></p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ss</span><span class="p">.</span><span class="nx">jenksMatrices</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">data</span><span class="p">,</span> <span class="nx">n_classes</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-97"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-97">&#182;</a> </div> <p>in the original implementation, these matrices are referred to
as <code>LC</code> and <code>OP</code></p>
@@ -323,8 +325,8 @@
<span class="p">}</span>
<span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">l</span> <span class="o">=</span> <span class="mi">2</span><span class="p">;</span> <span class="nx">l</span> <span class="o">&lt;</span> <span class="nx">data</span><span class="p">.</span><span class="nx">length</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span> <span class="nx">l</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-102"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-102">&#182;</a> </div> <p><code>SZ</code> originally. this is the sum of the values seen thus
-far when calculating variance.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> </pre></div> </td> </tr> <tr id="section-103"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-103">&#182;</a> </div> <p><code>ZSQ</code> originally. the sum of squares of values seen
-thus far</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">sum_squares</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-104"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-104">&#182;</a> </div> <p><code>WT</code> originally. This is the number of </p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">w</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-105"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-105">&#182;</a> </div> <p><code>IV</code> originally</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">i4</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-106"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-106">&#182;</a> </div> <p>in several instances, you could say <code>Math.pow(x, 2)</code>
+far when calculating variance.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">sum</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-103"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-103">&#182;</a> </div> <p><code>ZSQ</code> originally. the sum of squares of values seen
+thus far</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">sum_squares</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-104"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-104">&#182;</a> </div> <p><code>WT</code> originally. This is the number of</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">w</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-105"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-105">&#182;</a> </div> <p><code>IV</code> originally</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">i4</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-106"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-106">&#182;</a> </div> <p>in several instances, you could say <code>Math.pow(x, 2)</code>
instead of <code>x * x</code>, but this is slower in some browsers
introduces an unnecessary concept.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">m</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span> <span class="nx">m</span> <span class="o">&lt;</span> <span class="nx">l</span> <span class="o">+</span> <span class="mi">1</span><span class="p">;</span> <span class="nx">m</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-107"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-107">&#182;</a> </div> <p><code>III</code> originally</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">lower_class_limit</span> <span class="o">=</span> <span class="nx">l</span> <span class="o">-</span> <span class="nx">m</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span>
<span class="nx">val</span> <span class="o">=</span> <span class="nx">data</span><span class="p">[</span><span class="nx">lower_class_limit</span> <span class="o">-</span> <span class="mi">1</span><span class="p">];</span></pre></div> </td> </tr> <tr id="section-108"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-108">&#182;</a> </div> <p>here we're estimating variance for each potential classing
@@ -358,7 +360,9 @@
<span class="nx">lower_class_limits</span><span class="o">:</span> <span class="nx">lower_class_limits</span><span class="p">,</span>
<span class="nx">variance_combinations</span><span class="o">:</span> <span class="nx">variance_combinations</span>
<span class="p">};</span>
- <span class="p">};</span></pre></div> </td> </tr> <tr id="section-113"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-113">&#182;</a> </div> <p>the second part of the jenks recipe: take the calculated matrices
+ <span class="p">};</span></pre></div> </td> </tr> <tr id="section-113"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-113">&#182;</a> </div> <h2>Pull Breaks Values for Jenks</h2>
+
+<p>the second part of the jenks recipe: take the calculated matrices
and derive an array of n breaks.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">ss</span><span class="p">.</span><span class="nx">jenksBreaks</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">data</span><span class="p">,</span> <span class="nx">lower_class_limits</span><span class="p">,</span> <span class="nx">n_classes</span><span class="p">)</span> <span class="p">{</span>
<span class="kd">var</span> <span class="nx">k</span> <span class="o">=</span> <span class="nx">data</span><span class="p">.</span><span class="nx">length</span> <span class="o">-</span> <span class="mi">1</span><span class="p">,</span>
View
13 src/simple_statistics.js
@@ -545,6 +545,8 @@
}
};
+ // ## Compute Matrices for Jenks
+ //
// Compute the matrices required for Jenks breaks. These matrices
// can be used for any classing of data with `classes <= n_classes`
ss.jenksMatrices = function(data, n_classes) {
@@ -564,6 +566,9 @@
// Initialize and fill each matrix with zeroes
for (i = 0; i < data.length + 1; i++) {
var tmp1 = [], tmp2 = [];
+ // despite these arrays having the same values, we need
+ // to keep them separate so that changing one does not change
+ // the other
for (j = 0; j < n_classes + 1; j++) {
tmp1.push(0);
tmp2.push(0);
@@ -586,11 +591,11 @@
// `SZ` originally. this is the sum of the values seen thus
// far when calculating variance.
- var sum = 0,
+ var sum = 0,
// `ZSQ` originally. the sum of squares of values seen
// thus far
sum_squares = 0,
- // `WT` originally. This is the number of
+ // `WT` originally. This is the number of
w = 0,
// `IV` originally
i4 = 0;
@@ -624,7 +629,7 @@
for (j = 2; j < n_classes + 1; j++) {
// if adding this element to an existing class
// will increase its variance beyond the limit, break
- // the class at this point, setting the lower_class_limit
+ // the class at this point, setting the `lower_class_limit`
// at this point.
if (variance_combinations[l][j] >=
(variance + variance_combinations[i4][j - 1])) {
@@ -649,6 +654,8 @@
};
};
+ // ## Pull Breaks Values for Jenks
+ //
// the second part of the jenks recipe: take the calculated matrices
// and derive an array of n breaks.
ss.jenksBreaks = function(data, lower_class_limits, n_classes) {
Please sign in to comment.
Something went wrong with that request. Please try again.