From 32af5ed6ae2299a0b805314a1b3e3de2bd66e1c6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Nov 2023 05:53:11 +0000 Subject: [PATCH] Auto-generated commit --- .github/.keepalive | 1 + .github/workflows/publish.yml | 12 +- CONTRIBUTORS | 1 + package.json | 6 +- test/dist/test.js | 956 +--------------------------------- 5 files changed, 19 insertions(+), 957 deletions(-) create mode 100644 .github/.keepalive diff --git a/.github/.keepalive b/.github/.keepalive new file mode 100644 index 0000000..7975d1d --- /dev/null +++ b/.github/.keepalive @@ -0,0 +1 @@ +2023-11-01T05:53:07.233Z diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index b17435b..0037bdb 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -182,7 +182,11 @@ jobs: fi # Trim leading and trailing whitespace: dep=$(echo "$dep" | xargs) - version="^$(npm view $dep version)" + version="$(npm view $dep version)" + if [[ -z "$version" ]]; then + continue + fi + version="^$version" jq -r --arg dep "$dep" --arg version "$version" '.dependencies[$dep] = $version' package.json > package.json.tmp mv package.json.tmp package.json done @@ -192,7 +196,11 @@ jobs: fi # Trim leading and trailing whitespace: dep=$(echo "$dep" | xargs) - version="^$(npm view $dep version)" + version="$(npm view $dep version)" + if [[ -z "$version" ]]; then + continue + fi + version="^$version" jq -r --arg dep "$dep" --arg version "$version" '.devDependencies[$dep] = $version' package.json > package.json.tmp mv package.json.tmp package.json done diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 93c4bde..0dae4fe 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -37,3 +37,4 @@ Stephannie Jiménez Gacha Yernar Yergaziyev orimiles5 <97595296+orimiles5@users.noreply.github.com> rei2hu +Robert Gislason diff --git a/package.json b/package.json index ed0807a..6674cd4 100644 --- a/package.json +++ b/package.json @@ -37,11 +37,11 @@ "url": "https://github.com/stdlib-js/stdlib/issues" }, "dependencies": { - "@stdlib/array-float64": "^0.1.0", + "@stdlib/array-float64": "^0.1.1", "@stdlib/assert-is-positive-integer": "^0.1.0", "@stdlib/assert-is-square-matrix": "^0.1.0", "@stdlib/assert-is-vector-like": "^0.1.0", - "@stdlib/math-base-special-sqrt": "^0.1.0", + "@stdlib/math-base-special-sqrt": "^0.1.1", "@stdlib/ndarray-base-ctor": "^0.1.0", "@stdlib/ndarray-base-numel": "^0.1.1", "@stdlib/ndarray-ctor": "^0.1.0", @@ -52,7 +52,7 @@ "@stdlib/assert-is-symmetric-matrix": "^0.1.0", "@stdlib/bench": "^0.1.0", "@stdlib/constants-float64-eps": "^0.1.1", - "@stdlib/math-base-special-abs": "^0.1.0", + "@stdlib/math-base-special-abs": "^0.1.1", "@stdlib/random-base-randu": "^0.1.0", "tape": "git+https://github.com/kgryte/tape.git#fix/globby", "istanbul": "^0.4.1", diff --git a/test/dist/test.js b/test/dist/test.js index ddb05f4..a8a9c60 100644 --- a/test/dist/test.js +++ b/test/dist/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2018 The Stdlib Authors. +* Copyright (c) 2023 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,961 +21,13 @@ // MODULES // var tape = require( 'tape' ); -var abs = require( '@stdlib/math-base-special-abs' ); -var EPS = require( '@stdlib/constants-float64-eps' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var Float64Array = require( '@stdlib/array-float64' ); -var incrpcorrdistmat = require( './../../dist' ); +var main = require( './../../dist' ); // TESTS // -tape( 'main export is a function', function test( t ) { +tape( 'main export is defined', function test( t ) { t.ok( true, __filename ); - t.strictEqual( typeof incrpcorrdistmat, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if not provided either a positive integer or an output ndarray having equal dimensions for storing the correlation distance matrix for the first argument', function test( t ) { - var strides; - var values; - var buffer; - var shape; - var mat; - var i; - - buffer = new Float64Array( 6 ); - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - mat = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - values = [ - '5', - 3.14, - 0.0, - -1, - true, - false, - null, - void 0, - [], - {}, - function noop() {}, - mat - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - incrpcorrdistmat( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a positive integer or an output ndarray having equal dimensions for storing the correlation distance matrix for the first argument (means)', function test( t ) { - var strides; - var values; - var buffer; - var shape; - var mat; - var vec; - var i; - - buffer = new Float64Array( 6 ); - shape = [ 3, 2 ]; - strides = [ 2, 1 ]; - mat = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - buffer = new Float64Array( 2 ); - shape = [ 2 ]; - strides = [ 1 ]; - - vec = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - values = [ - '5', - 3.14, - 0.0, - -1, - true, - false, - null, - void 0, - [], - {}, - function noop() {}, - mat - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - incrpcorrdistmat( value, vec ); - }; - } -}); - -tape( 'the function throws an error if not provided a 1-dimensional ndarray as a second argument (order)', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - 1.0, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - incrpcorrdistmat( 2, value ); - }; - } -}); - -tape( 'the function throws an error if not provided a 1-dimensional ndarray as a second argument (distance matrix)', function test( t ) { - var strides; - var values; - var buffer; - var shape; - var dist; - var i; - - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - dist = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - values = [ - '5', - 3.14, - 1.0, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - incrpcorrdistmat( dist, value ); - }; - } -}); - -tape( 'the function throws an error if the number of known means does not match correlation distance matrix dimensions (order)', function test( t ) { - var strides; - var buffer; - var shape; - var vec; - - buffer = new Float64Array( 3 ); - shape = [ 3 ]; - strides = [ 1 ]; - vec = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - t.throws( badValue( vec ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - incrpcorrdistmat( 2, value ); - }; - } -}); - -tape( 'the function throws an error if the number of known means does not match correlation distance matrix dimensions (distance matrix)', function test( t ) { - var strides; - var buffer; - var shape; - var dist; - var vec; - - buffer = new Float64Array( 9 ); - shape = [ 3, 3 ]; - strides = [ 3, 1 ]; - dist = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - buffer = new Float64Array( 2 ); - shape = [ 2 ]; - strides = [ 1 ]; - vec = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - t.throws( badValue( vec ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - incrpcorrdistmat( dist, value ); - }; - } -}); - -tape( 'the function returns an accumulator function (order)', function test( t ) { - t.equal( typeof incrpcorrdistmat( 2 ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns an accumulator function (distance matrix)', function test( t ) { - var strides; - var buffer; - var shape; - var dist; - - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - dist = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - t.equal( typeof incrpcorrdistmat( dist ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns an accumulator function (order; known means)', function test( t ) { - var strides; - var buffer; - var shape; - var means; - - buffer = new Float64Array( 4 ); - shape = [ 2 ]; - strides = [ 1 ]; - means = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - t.equal( typeof incrpcorrdistmat( 2, means ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the function returns an accumulator function (distance matrix; known means)', function test( t ) { - var strides; - var buffer; - var shape; - var means; - var dist; - - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - dist = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - buffer = new Float64Array( 4 ); - shape = [ 2 ]; - strides = [ 1 ]; - means = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - t.equal( typeof incrpcorrdistmat( dist, means ), 'function', 'returns a function' ); - t.end(); -}); - -tape( 'the accumulator function throws an error if not provided a 1-dimensional ndarray (order)', function test( t ) { - var strides; - var values; - var buffer; - var shape; - var mat; - var acc; - var i; - - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - mat = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - acc = incrpcorrdistmat( 2 ); - - values = [ - '5', - 3.14, - 1.0, - true, - false, - null, - void 0, - [], - {}, - function noop() {}, - mat - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - acc( value ); - }; - } -}); - -tape( 'the accumulator function throws an error if not provided a 1-dimensional ndarray (order, means)', function test( t ) { - var strides; - var values; - var buffer; - var shape; - var means; - var mat; - var acc; - var i; - - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - mat = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - buffer = new Float64Array( 2 ); - shape = [ 2 ]; - strides = [ 1 ]; - means = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - acc = incrpcorrdistmat( 2, means ); - - values = [ - '5', - 3.14, - 1.0, - true, - false, - null, - void 0, - [], - {}, - function noop() {}, - mat - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - acc( value ); - }; - } -}); - -tape( 'the accumulator function throws an error if not provided a 1-dimensional ndarray (distance matrix)', function test( t ) { - var strides; - var values; - var buffer; - var shape; - var dist; - var acc; - var i; - - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - dist = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - acc = incrpcorrdistmat( dist ); - - values = [ - '5', - 3.14, - 1.0, - true, - false, - null, - void 0, - [], - {}, - function noop() {}, - ndarray( 'float64', new Float64Array( 4 ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - acc( value ); - }; - } -}); - -tape( 'the accumulator function throws an error if not provided a 1-dimensional ndarray (distance matrix, means)', function test( t ) { - var strides; - var values; - var buffer; - var shape; - var means; - var dist; - var acc; - var i; - - buffer = new Float64Array( 4 ); - shape = [ 2, 2 ]; - strides = [ 2, 1 ]; - dist = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - buffer = new Float64Array( 2 ); - shape = [ 2 ]; - strides = [ 1 ]; - means = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - acc = incrpcorrdistmat( dist, means ); - - values = [ - '5', - 3.14, - 1.0, - true, - false, - null, - void 0, - [], - {}, - function noop() {}, - ndarray( 'float64', new Float64Array( 4 ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ) - ]; - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - acc( value ); - }; - } -}); - -tape( 'the accumulator function throws an error if the number of elements in a provided data vector does not match correlation distance matrix dimensions (order)', function test( t ) { - var strides; - var buffer; - var shape; - var vec; - var acc; - - buffer = new Float64Array( 2 ); - shape = [ 2 ]; - strides = [ 1 ]; - vec = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - acc = incrpcorrdistmat( 3 ); - - t.throws( badValue( vec ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - acc( value ); - }; - } -}); - -tape( 'the accumulator function throws an error if the number of elements in a provided data vector does not match correlation distance matrix dimensions (order, means)', function test( t ) { - var strides; - var buffer; - var shape; - var means; - var vec; - var acc; - - buffer = new Float64Array( 3 ); - shape = [ 3 ]; - strides = [ 1 ]; - means = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - buffer = new Float64Array( 2 ); - shape = [ 2 ]; - strides = [ 1 ]; - vec = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - acc = incrpcorrdistmat( 3, means ); - - t.throws( badValue( vec ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - acc( value ); - }; - } -}); - -tape( 'the accumulator function throws an error if the number of elements in a provided data vector does not match correlation distance matrix dimensions (distance matrix)', function test( t ) { - var strides; - var buffer; - var shape; - var dist; - var vec; - var acc; - - buffer = new Float64Array( 9 ); - shape = [ 3, 3 ]; - strides = [ 3, 1 ]; - dist = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - buffer = new Float64Array( 2 ); - shape = [ 2 ]; - strides = [ 1 ]; - vec = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - acc = incrpcorrdistmat( dist ); - - t.throws( badValue( vec ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - acc( value ); - }; - } -}); - -tape( 'the accumulator function throws an error if the number of elements in a provided data vector does not match correlation distance matrix dimensions (distance matrix, means)', function test( t ) { - var strides; - var buffer; - var shape; - var means; - var dist; - var vec; - var acc; - - buffer = new Float64Array( 9 ); - shape = [ 3, 3 ]; - strides = [ 3, 1 ]; - dist = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - buffer = new Float64Array( 3 ); - shape = [ 3 ]; - strides = [ 1 ]; - means = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - buffer = new Float64Array( 2 ); - shape = [ 2 ]; - strides = [ 1 ]; - vec = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - acc = incrpcorrdistmat( dist, means ); - - t.throws( badValue( vec ), Error, 'throws an error' ); - t.end(); - - function badValue( value ) { - return function badValue() { - acc( value ); - }; - } -}); - -tape( 'the accumulator function incrementally computes a sample Pearson product-moment correlation distance matrix (order)', function test( t ) { - var expected; - var strides; - var actual; - var shape; - var delta; - var order; - var tol; - var acc; - var n; - var v; - var e; - var d; - var i; - var j; - var k; - - n = 2; - - shape = [ 2 ]; - strides = [ 1 ]; - order = 'row-major'; - - d = [ - ndarray( 'float64', new Float64Array( [ 2.0, 1.5 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 3.0, -0.6 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 2.0, 3.14 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 4.0, 4.0 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 3.0, -2.0 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 4.0, 10.0 ] ), shape, strides, 0, order ) - ]; - - // Test against Julia: 1.0 - (sum((d[1:n,1]-mean(d[1:n,1])).*(d[1:n,2]-mean(d[1:n,2]))[:])/(n-1))/(std(d[1:n,1])*std(d[1:n,2])) - expected = [ - [ 0.0, 0.0, 0.0, 0.0 ], - [ 0.0, 1.0+1.0, 1.0+1.0, 0.0 ], - [ 0.0, 1.0+0.8992664495010921, 1.0+0.8992664495010921, 0.0 ], - [ 0.0, 1.0-0.23547201823172273, 1.0-0.23547201823172273, 0.0 ], - [ 0.0, 1.0-0.06765492498103522, 1.0-0.06765492498103522, 0.0 ], - [ 0.0, 1.0-0.4944446711225878, 1.0-0.4944446711225878, 0.0 ] - ]; - - acc = incrpcorrdistmat( n ); - - for ( i = 0; i < d.length; i++ ) { - actual = acc( d[ i ] ); - for ( j = 0; j < n; j++ ) { - for ( k = 0; k < n; k++ ) { - v = actual.get( j, k ); - e = expected[ i ][ (j*n)+k ]; - if ( v === e ) { - t.strictEqual( v, e, 'returns expected result. i: '+i+'. j: '+j+'. k: '+k+'.' ); - } else { - delta = abs( e - v ); - tol = 3.0 * EPS * abs( e ); - t.equal( delta <= tol, true, 'i: '+i+'. j: '+j+'. k: '+k+'. expected: '+e+'. actual: '+v+'. tol: '+tol+'. delta: '+delta+'.' ); - } - } - } - } - t.end(); -}); - -tape( 'the accumulator function incrementally computes a sample Pearson product-moment correlation distance matrix (distance matrix)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var shape; - var delta; - var order; - var dist; - var tol; - var acc; - var n; - var v; - var e; - var d; - var i; - var j; - var k; - - n = 2; - - shape = [ 2 ]; - strides = [ 1 ]; - order = 'row-major'; - - d = [ - ndarray( 'float64', new Float64Array( [ 2.0, 1.5 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 3.0, -0.6 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 2.0, 3.14 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 4.0, 4.0 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 3.0, -2.0 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 4.0, 10.0 ] ), shape, strides, 0, order ) - ]; - - buffer = new Float64Array( n*n ); - shape = [ n, n ]; - strides = [ n, 1 ]; - - dist = ndarray( 'float64', buffer, shape, strides, 0, order ); - - // Test against Julia: 1.0 - (sum((d[1:n,1]-mean(d[1:n,1])).*(d[1:n,2]-mean(d[1:n,2]))[:])/(n-1))/(std(d[1:n,1])*std(d[1:n,2])) - expected = [ - [ 0.0, 0.0, 0.0, 0.0 ], - [ 0.0, 1.0+1.0, 1.0+1.0, 0.0 ], - [ 0.0, 1.0+0.8992664495010921, 1.0+0.8992664495010921, 0.0 ], - [ 0.0, 1.0-0.23547201823172273, 1.0-0.23547201823172273, 0.0 ], - [ 0.0, 1.0-0.06765492498103522, 1.0-0.06765492498103522, 0.0 ], - [ 0.0, 1.0-0.4944446711225878, 1.0-0.4944446711225878, 0.0 ] - ]; - - acc = incrpcorrdistmat( dist ); - - for ( i = 0; i < d.length; i++ ) { - actual = acc( d[ i ] ); - for ( j = 0; j < n; j++ ) { - for ( k = 0; k < n; k++ ) { - v = actual.get( j, k ); - e = expected[ i ][ (j*n)+k ]; - if ( v === e ) { - t.strictEqual( v, e, 'returns expected result. i: '+i+'. j: '+j+'. k: '+k+'.' ); - } else { - delta = abs( e - v ); - tol = 3.0 * EPS * abs( e ); - t.equal( delta <= tol, true, 'i: '+i+'. j: '+j+'. k: '+k+'. expected: '+e+'. actual: '+v+'. tol: '+tol+'. delta: '+delta+'.' ); - } - } - } - } - t.end(); -}); - -tape( 'the accumulator function incrementally computes a sample Pearson product-moment correlation distance matrix (order, means)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var means; - var shape; - var delta; - var order; - var tol; - var acc; - var n; - var v; - var e; - var d; - var i; - var j; - var k; - - n = 2; - - shape = [ 2 ]; - strides = [ 1 ]; - order = 'row-major'; - - d = [ - ndarray( 'float64', new Float64Array( [ 2.0, 1.5 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 3.0, -0.6 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 2.0, 3.14 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 4.0, 4.0 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 3.0, -2.0 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 4.0, 10.0 ] ), shape, strides, 0, order ) - ]; - - buffer = new Float64Array( [ 3.0, 2.6733333333333333 ] ); - means = ndarray( 'float64', buffer, shape, strides, 0, order ); - - // Test against Julia: 1.0 - (sum((d[1:n,1]-3.0).*(d[1:n,2]-2.6733333333333333)[:])/(n-1))/(stdm(d[1:n,1],3.0)*stdm(d[1:n,2],2.6733333333333333)) - expected = [ - [ 0.0, 0.0, 0.0, 0.0 ], - [ 0.0, 1.0-0.337429241307504, 1.0-0.337429241307504, 0.0 ], - [ 0.0, 1.0-0.14242449698664145, 1.0-0.14242449698664145, 0.0 ], - [ 0.0, 1.0-0.31297710227544034, 1.0-0.31297710227544034, 0.0 ], - [ 0.0, 1.0-0.19590456246309015, 1.0-0.19590456246309015, 0.0 ], - [ 0.0, 1.0-0.4944446711225878, 1.0-0.4944446711225878, 0.0 ] - ]; - - acc = incrpcorrdistmat( n, means ); - - for ( i = 0; i < d.length; i++ ) { - actual = acc( d[ i ] ); - for ( j = 0; j < n; j++ ) { - for ( k = 0; k < n; k++ ) { - v = actual.get( j, k ); - e = expected[ i ][ (j*n)+k ]; - if ( v === e ) { - t.strictEqual( v, e, 'returns expected result. i: '+i+'. j: '+j+'. k: '+k+'.' ); - } else { - delta = abs( e - v ); - tol = 3.0 * EPS * abs( e ); - t.equal( delta <= tol, true, 'i: '+i+'. j: '+j+'. k: '+k+'. expected: '+e+'. actual: '+v+'. tol: '+tol+'. delta: '+delta+'.' ); - } - } - } - } - t.end(); -}); - -tape( 'the accumulator function incrementally computes a sample Pearson product-moment correlation distance matrix (distance matrix, means)', function test( t ) { - var expected; - var strides; - var actual; - var buffer; - var means; - var shape; - var delta; - var order; - var dist; - var tol; - var acc; - var n; - var v; - var e; - var d; - var i; - var j; - var k; - - n = 2; - - shape = [ 2 ]; - strides = [ 1 ]; - order = 'row-major'; - - d = [ - ndarray( 'float64', new Float64Array( [ 2.0, 1.5 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 3.0, -0.6 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 2.0, 3.14 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 4.0, 4.0 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 3.0, -2.0 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 4.0, 10.0 ] ), shape, strides, 0, order ) - ]; - - buffer = new Float64Array( n*n ); - shape = [ n, n ]; - strides = [ n, 1 ]; - - dist = ndarray( 'float64', buffer, shape, strides, 0, order ); - - buffer = new Float64Array( [ 3.0, 2.6733333333333333 ] ); - means = ndarray( 'float64', buffer, [ 2 ], [ 1 ], 0, order ); - - // Test against Julia: 1.0 - (sum((d[1:n,1]-3.0).*(d[1:n,2]-2.6733333333333333)[:])/(n-1))/(stdm(d[1:n,1],3.0)*stdm(d[1:n,2],2.6733333333333333)) - expected = [ - [ 0.0, 0.0, 0.0, 0.0 ], - [ 0.0, 1.0-0.337429241307504, 1.0-0.337429241307504, 0.0 ], - [ 0.0, 1.0-0.14242449698664145, 1.0-0.14242449698664145, 0.0 ], - [ 0.0, 1.0-0.31297710227544034, 1.0-0.31297710227544034, 0.0 ], - [ 0.0, 1.0-0.19590456246309015, 1.0-0.19590456246309015, 0.0 ], - [ 0.0, 1.0-0.4944446711225878, 1.0-0.4944446711225878, 0.0 ] - ]; - - acc = incrpcorrdistmat( dist, means ); - - for ( i = 0; i < d.length; i++ ) { - actual = acc( d[ i ] ); - for ( j = 0; j < n; j++ ) { - for ( k = 0; k < n; k++ ) { - v = actual.get( j, k ); - e = expected[ i ][ (j*n)+k ]; - if ( v === e ) { - t.strictEqual( v, e, 'returns expected result. i: '+i+'. j: '+j+'. k: '+k+'.' ); - } else { - delta = abs( e - v ); - tol = 3.0 * EPS * abs( e ); - t.equal( delta <= tol, true, 'i: '+i+'. j: '+j+'. k: '+k+'. expected: '+e+'. actual: '+v+'. tol: '+tol+'. delta: '+delta+'.' ); - } - } - } - } - t.end(); -}); - -tape( 'if not provided a data vector, the accumulator function returns the correlation distance matrix', function test( t ) { - var strides; - var buffer; - var shape; - var order; - var dist; - var acc; - var out; - var n; - var d; - var i; - - n = 2; - - shape = [ 2 ]; - strides = [ 1 ]; - order = 'row-major'; - - d = [ - ndarray( 'float64', new Float64Array( [ 2.0, 1.5 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 3.0, -0.6 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 2.0, 3.14 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 4.0, 4.0 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 3.0, -2.0 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 4.0, 10.0 ] ), shape, strides, 0, order ) - ]; - - buffer = new Float64Array( n*n ); - shape = [ n, n ]; - strides = [ n, 1 ]; - - dist = ndarray( 'float64', buffer, shape, strides, 0, order ); - - acc = incrpcorrdistmat( dist ); - - for ( i = 0; i < d.length; i++ ) { - out = acc( d[ i ] ); - t.strictEqual( out, dist, 'returns expected value' ); - } - t.strictEqual( acc(), dist, 'returns expected value' ); - t.end(); -}); - -tape( 'if not provided a data vector, the accumulator function returns the correlation distance matrix (means)', function test( t ) { - var strides; - var buffer; - var shape; - var order; - var means; - var dist; - var acc; - var out; - var n; - var d; - var i; - - n = 2; - - shape = [ 2 ]; - strides = [ 1 ]; - order = 'row-major'; - - d = [ - ndarray( 'float64', new Float64Array( [ 2.0, 1.5 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 3.0, -0.6 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 2.0, 3.14 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 4.0, 4.0 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 3.0, -2.0 ] ), shape, strides, 0, order ), - ndarray( 'float64', new Float64Array( [ 4.0, 10.0 ] ), shape, strides, 0, order ) - ]; - - buffer = new Float64Array( n*n ); - shape = [ n, n ]; - strides = [ n, 1 ]; - - dist = ndarray( 'float64', buffer, shape, strides, 0, order ); - - buffer = new Float64Array( n ); - shape = [ n ]; - strides = [ 1 ]; - - means = ndarray( 'float64', buffer, shape, strides, 0, order ); - - acc = incrpcorrdistmat( dist, means ); - - for ( i = 0; i < d.length; i++ ) { - out = acc( d[ i ] ); - t.strictEqual( out, dist, 'returns expected value' ); - } - t.strictEqual( acc(), dist, 'returns expected value' ); - t.end(); -}); - -tape( 'if the accumulator function has not been provided any data, the accumulator function returns `null`', function test( t ) { - var acc = incrpcorrdistmat( 2 ); - t.strictEqual( acc(), null, 'returns expected value' ); - t.end(); -}); - -tape( 'if the accumulator function has not been provided any data, the accumulator function returns `null` (means)', function test( t ) { - var strides; - var buffer; - var shape; - var means; - var acc; - - buffer = new Float64Array( 2 ); - shape = [ 2 ]; - strides = [ 1 ]; - means = ndarray( 'float64', buffer, shape, strides, 0, 'row-major' ); - - acc = incrpcorrdistmat( 2, means ); - t.strictEqual( acc(), null, 'returns expected value' ); - + t.strictEqual( main !== void 0, true, 'main export is defined' ); t.end(); });