[Pkg-javascript-commits] [science.js] 50/87: Respect mean and variance.

bhuvan krishna bhuvan-guest at moszumanska.debian.org
Thu Dec 8 06:11:59 UTC 2016


This is an automated email from the git hooks/post-receive script.

bhuvan-guest pushed a commit to branch master
in repository science.js.

commit 07196f54058a607d94ea95f8dc70c4e09981be7d
Author: Jason Davies <jason at jasondavies.com>
Date:   Thu Dec 15 00:17:06 2011 +0000

    Respect mean and variance.
---
 science.stats.js                   | 16 ++++++++++------
 science.stats.min.js               |  2 +-
 src/stats/distribution/gaussian.js | 16 ++++++++++------
 3 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/science.stats.js b/science.stats.js
index 528836c..4558453 100644
--- a/science.stats.js
+++ b/science.stats.js
@@ -724,10 +724,14 @@ science.stats.distribution = {
 science.stats.distribution.gaussian = function() {
   var random = Math.random,
       mean = 0,
-      sigma = 1;
+      sigma = 1,
+      variance = 1;
 
   function gaussian() {
-    var x1, x2, rad, y1;
+    var x1,
+        x2,
+        rad,
+        y1;
 
     do {
       x1 = 2 * random() - 1;
@@ -735,7 +739,7 @@ science.stats.distribution.gaussian = function() {
       rad = x1 * x1 + x2 * x2;
     } while (rad >= 1 || rad === 0);
 
-    return x1 * Math.sqrt(-2 * Math.log(rad) / rad);
+    return mean + sigma * x1 * Math.sqrt(-2 * Math.log(rad) / rad);
   }
 
   gaussian.pdf = function(x) {
@@ -754,9 +758,9 @@ science.stats.distribution.gaussian = function() {
     return gaussian;
   };
 
-  gaussian.sigma = function(x) {
-    if (!arguments.length) return sigma;
-    sigma = +x;
+  gaussian.variance = function(x) {
+    if (!arguments.length) return variance;
+    sigma = Math.sqrt(variance = +x);
     return gaussian;
   };
 
diff --git a/science.stats.min.js b/science.stats.min.js
index ab4f622..b446a02 100644
--- a/science.stats.min.js
+++ b/science.stats.min.js
@@ -1 +1 @@
-(function(){function a(a,b){if(!a||!b||a.length!==b.length)return!1;var c=a.length,d=-1;while(++d<c)if(a[d]!==b[d])return!1;return!0}function b(b,c){var d=c.length;if(b>d)return null;var e=[],f=[],g={},h=0,i=0,j,k,l;while(i<b){if(h===d)return null;var m=Math.floor(Math.random()*d);if(m in g)continue;g[m]=1,h++,k=c[m],l=!0;for(j=0;j<i;j++)if(a(k,e[j])){l=!1;break}l&&(e[i]=k,f[i]=m,i++)}return e}function c(a,b,c,d){var e=[],f=a+c,g=b.length,h=-1;while(++h<g)e[h]=(a*b[h]+c*d[h])/f;return e} [...]
\ No newline at end of file
+(function(){function a(a,b){if(!a||!b||a.length!==b.length)return!1;var c=a.length,d=-1;while(++d<c)if(a[d]!==b[d])return!1;return!0}function b(b,c){var d=c.length;if(b>d)return null;var e=[],f=[],g={},h=0,i=0,j,k,l;while(i<b){if(h===d)return null;var m=Math.floor(Math.random()*d);if(m in g)continue;g[m]=1,h++,k=c[m],l=!0;for(j=0;j<i;j++)if(a(k,e[j])){l=!1;break}l&&(e[i]=k,f[i]=m,i++)}return e}function c(a,b,c,d){var e=[],f=a+c,g=b.length,h=-1;while(++h<g)e[h]=(a*b[h]+c*d[h])/f;return e} [...]
\ No newline at end of file
diff --git a/src/stats/distribution/gaussian.js b/src/stats/distribution/gaussian.js
index 2059025..4c07a38 100644
--- a/src/stats/distribution/gaussian.js
+++ b/src/stats/distribution/gaussian.js
@@ -3,10 +3,14 @@
 science.stats.distribution.gaussian = function() {
   var random = Math.random,
       mean = 0,
-      sigma = 1;
+      sigma = 1,
+      variance = 1;
 
   function gaussian() {
-    var x1, x2, rad, y1;
+    var x1,
+        x2,
+        rad,
+        y1;
 
     do {
       x1 = 2 * random() - 1;
@@ -14,7 +18,7 @@ science.stats.distribution.gaussian = function() {
       rad = x1 * x1 + x2 * x2;
     } while (rad >= 1 || rad === 0);
 
-    return x1 * Math.sqrt(-2 * Math.log(rad) / rad);
+    return mean + sigma * x1 * Math.sqrt(-2 * Math.log(rad) / rad);
   }
 
   gaussian.pdf = function(x) {
@@ -33,9 +37,9 @@ science.stats.distribution.gaussian = function() {
     return gaussian;
   };
 
-  gaussian.sigma = function(x) {
-    if (!arguments.length) return sigma;
-    sigma = +x;
+  gaussian.variance = function(x) {
+    if (!arguments.length) return variance;
+    sigma = Math.sqrt(variance = +x);
     return gaussian;
   };
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/science.js.git



More information about the Pkg-javascript-commits mailing list