[Pkg-javascript-commits] [science.js] 35/87: Add science.stats.phi.

bhuvan krishna bhuvan-guest at moszumanska.debian.org
Thu Dec 8 06:11:55 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 c0c1bf5ad2890d7c35a35c82464c8b5c08c8e2b7
Author: Jason Davies <jason at jasondavies.com>
Date:   Sat Aug 27 22:08:00 2011 +0100

    Add science.stats.phi.
---
 Makefile               |  1 +
 science.stats.js       |  3 +++
 science.stats.min.js   |  2 +-
 src/stats/phi.js       |  3 +++
 test/stats/phi-test.js | 22 ++++++++++++++++++++++
 5 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index c24678e..03f41c4 100644
--- a/Makefile
+++ b/Makefile
@@ -46,6 +46,7 @@ science.stats.js: \
 	src/stats/bandwidth.js \
 	src/stats/distance.js \
 	src/stats/erf.js \
+	src/stats/phi.js \
 	src/stats/kernel.js \
 	src/stats/kde.js \
 	src/stats/kmeans.js \
diff --git a/science.stats.js b/science.stats.js
index c3213cf..efc66af 100644
--- a/science.stats.js
+++ b/science.stats.js
@@ -95,6 +95,9 @@ science.stats.erf = function(x) {
     1 - (((((a5 * t + a4) * t) + a3) * t + a2) * t + a1)
     * t * Math.exp(-x * x));
 };
+science.stats.phi = function(x) {
+  return .5 * (1 + science.stats.erf(x / Math.SQRT2));
+};
 // See <http://en.wikipedia.org/wiki/Kernel_(statistics)>.
 science.stats.kernel = {
   uniform: function(u) {
diff --git a/science.stats.min.js b/science.stats.min.js
index c1aa426..0412d8c 100644
--- a/science.stats.min.js
+++ b/science.stats.min.js
@@ -1 +1 @@
-(function(){function h(a,b){var c=b+1;while(c<a.length&&a[c]===0)c++;return c}function g(a,b,c,d){var e=d[0],f=d[1],g=h(b,f);if(g<a.length&&a[g]-a[c]<a[c]-a[e]){var i=h(b,e);d[0]=i,d[1]=g}}function f(a){return(a=1-a*a*a)*a*a}function e(a){var b=a.length,c=0;while(++c<b)if(a[c-1]>=a[c])return!1;return!0}function d(a){var b=a.length,c=-1;while(++c<b)if(!isFinite(a[c]))return!1;return!0}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}function b [...]
\ No newline at end of file
+(function(){function h(a,b){var c=b+1;while(c<a.length&&a[c]===0)c++;return c}function g(a,b,c,d){var e=d[0],f=d[1],g=h(b,f);if(g<a.length&&a[g]-a[c]<a[c]-a[e]){var i=h(b,e);d[0]=i,d[1]=g}}function f(a){return(a=1-a*a*a)*a*a}function e(a){var b=a.length,c=0;while(++c<b)if(a[c-1]>=a[c])return!1;return!0}function d(a){var b=a.length,c=-1;while(++c<b)if(!isFinite(a[c]))return!1;return!0}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}function b [...]
\ No newline at end of file
diff --git a/src/stats/phi.js b/src/stats/phi.js
new file mode 100644
index 0000000..6ceb0d1
--- /dev/null
+++ b/src/stats/phi.js
@@ -0,0 +1,3 @@
+science.stats.phi = function(x) {
+  return .5 * (1 + science.stats.erf(x / Math.SQRT2));
+};
diff --git a/test/stats/phi-test.js b/test/stats/phi-test.js
new file mode 100644
index 0000000..f029436
--- /dev/null
+++ b/test/stats/phi-test.js
@@ -0,0 +1,22 @@
+require("../../science");
+require("../../science.stats");
+
+var vows = require("vows"),
+    assert = require("assert");
+
+var suite = vows.describe("science.stats.phi");
+
+suite.addBatch({
+  "phi": {
+    "simple": function() {
+      var phi = science.stats.phi;
+      assert.inDelta(phi(-3  ),  0.00134989803163, 1e-6);
+      assert.inDelta(phi(-1  ),  0.158655253931,   1e-6);
+      assert.inDelta(phi( 0  ),  0.5,              1e-6);
+      assert.inDelta(phi( 0.5),  0.691462461274,   1e-6);
+      assert.inDelta(phi( 2.1),  0.982135579437,   1e-6);
+    }
+  }
+});
+
+suite.export(module);

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