[Pkg-javascript-commits] [science.js] 40/87: Add science.stats.distance.braycurtis.

bhuvan krishna bhuvan-guest at moszumanska.debian.org
Thu Dec 8 06:11:57 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 f7df55ee7252ee8dcb70781f5d3ca11f6e237f5f
Author: Jason Davies <jason at jasondavies.com>
Date:   Thu Sep 8 16:33:00 2011 +0100

    Add science.stats.distance.braycurtis.
---
 package.json                |  2 +-
 science.js                  |  2 +-
 science.min.js              |  2 +-
 science.stats.js            | 15 +++++++++++++++
 science.stats.min.js        |  2 +-
 src/core/core.js            |  2 +-
 src/stats/distance.js       | 15 +++++++++++++++
 test/stats/distance-test.js |  7 +++++++
 8 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/package.json b/package.json
index a8848b3..7d20f6a 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "science.js",
-  "version": "1.5.0",
+  "version": "1.6.0",
   "description": "Scientific and statistical computing in JavaScript.",
   "keywords": [
     "science",
diff --git a/science.js b/science.js
index 665d3de..a85ed9a 100644
--- a/science.js
+++ b/science.js
@@ -1,4 +1,4 @@
-(function(){science = {version: "1.5.0"}; // semver
+(function(){science = {version: "1.6.0"}; // semver
 // Euler's constant.
 science.EULER = .5772156649015329;
 // Compute exp(x) - 1 accurately for small x.
diff --git a/science.min.js b/science.min.js
index dc46151..b58bbb3 100644
--- a/science.min.js
+++ b/science.min.js
@@ -1 +1 @@
-(function(){science={version:"1.5.0"},science.EULER=.5772156649015329,science.expm1=function(a){return a<1e-5&&a>-0.00001?a+.5*a*a:Math.exp(a)-1},science.functor=function(a){return typeof a=="function"?a:function(){return a}},science.hypot=function(a,b){a=Math.abs(a),b=Math.abs(b);var c,d;a>b?(c=a,d=b):(c=b,d=a);var e=d/c;return c*Math.sqrt(1+e*e)},science.quadratic=function(){function b(b,c,d){var e=c*c-4*b*d;if(e>0){e=Math.sqrt(e)/(2*b);return a?[{r:-c-e,i:0},{r:-c+e,i:0}]:[-c-e,-c+e]} [...]
\ No newline at end of file
+(function(){science={version:"1.6.0"},science.EULER=.5772156649015329,science.expm1=function(a){return a<1e-5&&a>-0.00001?a+.5*a*a:Math.exp(a)-1},science.functor=function(a){return typeof a=="function"?a:function(){return a}},science.hypot=function(a,b){a=Math.abs(a),b=Math.abs(b);var c,d;a>b?(c=a,d=b):(c=b,d=a);var e=d/c;return c*Math.sqrt(1+e*e)},science.quadratic=function(){function b(b,c,d){var e=c*c-4*b*d;if(e>0){e=Math.sqrt(e)/(2*b);return a?[{r:-c-e,i:0},{r:-c+e,i:0}]:[-c-e,-c+e]} [...]
\ No newline at end of file
diff --git a/science.stats.js b/science.stats.js
index efc66af..d98df12 100644
--- a/science.stats.js
+++ b/science.stats.js
@@ -71,6 +71,21 @@ science.stats.distance = {
         s = 0;
     while (++i < n) if (a[i] === b[i]) s++;
     return s / n;
+  },
+  braycurtis: function(a, b) {
+    var n = a.length,
+        i = -1,
+        s0 = 0,
+        s1 = 0,
+        ai,
+        bi;
+    while (++i < n) {
+      ai = a[i];
+      bi = b[i];
+      s0 += Math.abs(ai - bi);
+      s1 += Math.abs(ai + bi);
+    }
+    return s0 / s1;
   }
 };
 // Based on implementation in http://picomath.org/.
diff --git a/science.stats.min.js b/science.stats.min.js
index 0412d8c..fd69f13 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/core/core.js b/src/core/core.js
index 29d1e05..6441495 100644
--- a/src/core/core.js
+++ b/src/core/core.js
@@ -1 +1 @@
-science = {version: "1.5.0"}; // semver
+science = {version: "1.6.0"}; // semver
diff --git a/src/stats/distance.js b/src/stats/distance.js
index 3b86a86..d1e2c09 100644
--- a/src/stats/distance.js
+++ b/src/stats/distance.js
@@ -50,5 +50,20 @@ science.stats.distance = {
         s = 0;
     while (++i < n) if (a[i] === b[i]) s++;
     return s / n;
+  },
+  braycurtis: function(a, b) {
+    var n = a.length,
+        i = -1,
+        s0 = 0,
+        s1 = 0,
+        ai,
+        bi;
+    while (++i < n) {
+      ai = a[i];
+      bi = b[i];
+      s0 += Math.abs(ai - bi);
+      s1 += Math.abs(ai + bi);
+    }
+    return s0 / s1;
   }
 };
diff --git a/test/stats/distance-test.js b/test/stats/distance-test.js
index 63c9a91..bcfaa2d 100644
--- a/test/stats/distance-test.js
+++ b/test/stats/distance-test.js
@@ -49,6 +49,13 @@ suite.addBatch({
       assert.equal(jaccard([0], [1]), 0);
       assert.equal(jaccard([0, 1], [1, 1]), .5);
       assert.equal(jaccard([3, 2, 1, 0], [1, 2, 3, 4]), .25);
+    },
+    "braycurtis": function() {
+      var braycurtis = science.stats.distance.braycurtis;
+      assert.isTrue(isNaN(braycurtis([], [])));
+      assert.equal(braycurtis([0], [1]), 1);
+      assert.equal(braycurtis([0, 1], [1, 1]), 1 / 3);
+      assert.equal(braycurtis([3, 2, 1, 0], [1, 2, 3, 4]), .5);
     }
   }
 });

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