diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/README.md b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/README.md new file mode 100644 index 000000000000..ae399b81622c --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/README.md @@ -0,0 +1,190 @@ + + +# Distance Metrics + +> KMeans distance metrics. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var metrics = require( '@stdlib/ml/base/cluster/kmeans/metrics' ); +``` + +#### metrics() + +Returns a list of KMeans distance metrics. + +```javascript +var out = metrics(); +// e.g., returns [ 'sqeuclidean', 'cosine', 'cityblock' , 'correlation' ] +``` + +The output array contains the following metrics: + +- `sqeuclidean`: squared euclidean distance. +- `cosine`: cosine distance. +- `cityblock`: cityblock (taxicab) distance. +- `correlation`: correlation distance. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var metrics = require( '@stdlib/ml/base/cluster/kmeans/metrics' ); + +var isMetric = contains( metrics() ); + +var bool = isMetric( 'sqeuclidean' ); +// returns true + +bool = isMetric( 'cosine' ); +// returns true + +bool = isMetric( 'beep' ); +// returns false +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/ml/base/cluster/kmeans/metrics.h" +``` + +#### STDLIB_ML_CLUSTER_KMEANS_METRIC + +An enumeration of KMeans distance metrics with the following fields: + +- **STDLIB_ML_CLUSTER_KMEANS_SQEUCLIDEAN**: squared euclidean distance. +- **STDLIB_ML_CLUSTER_KMEANS_COSINE**: cosine distance. +- **STDLIB_ML_CLUSTER_KMEANS_CITYBLOCK**: cityblock (taxicab) distance. +- **STDLIB_ML_CLUSTER_KMEANS_CORRELATION**: correlation distance. + +```c +#include "stdlib/ml/base/cluster/kmeans/metrics.h" + +const enum STDLIB_ML_CLUSTER_KMEANS_METRIC v = STDLIB_ML_CLUSTER_KMEANS_SQEUCLIDEAN; +``` + +
+ + + + + +
+ +### Notes + +- Enumeration constants should be considered opaque values, and one should **not** rely on specific integer values. + +
+ + + + + +
+ +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/benchmark/benchmark.js new file mode 100644 index 000000000000..a093b4477c7d --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/benchmark/benchmark.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isStringArray = require( '@stdlib/assert/is-string-array' ).primitives; +var pkg = require( './../package.json' ).name; +var metrics = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = metrics(); + if ( out.length < 2 ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isStringArray( out ) ) { + b.fail( 'should return an array of strings' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/docs/repl.txt new file mode 100644 index 000000000000..5106571c9f40 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/docs/repl.txt @@ -0,0 +1,24 @@ + +{{alias}}() + Returns a list of distance metrics. + + The output array contains the following metrics: + + - sqeuclidean: squared euclidean distance. + - cosine: cosine distance. + - cityblock: cityblock (taxicab) distance. + - correlation: correlation distance. + + Returns + ------- + out: Array + List of metrics. + + Examples + -------- + > var out = {{alias}}() + [ 'sqeuclidean', 'cosine', 'cityblock', 'correlation' ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/docs/types/index.d.ts new file mode 100644 index 000000000000..7abbe1fa4e12 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/docs/types/index.d.ts @@ -0,0 +1,35 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Returns a list of distance metrics. +* +* @returns list of distance metrics +* +* @example +* var list = metrics(); +* // e.g., returns [ 'sqeuclidean', 'cosine', 'cityblock', 'correlation' ] +*/ +declare function metrics(): Array; + + +// EXPORTS // + +export = metrics; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/docs/types/test.ts new file mode 100644 index 000000000000..531e81a7e007 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/docs/types/test.ts @@ -0,0 +1,32 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import metrics = require( './index' ); + + +// TESTS // + +// The function returns an array of strings... +{ + metrics(); // $ExpectType string[] +} + +// The compiler throws an error if the function is provided any arguments... +{ + metrics( 9 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/examples/index.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/examples/index.js new file mode 100644 index 000000000000..bf828d8a4144 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/examples/index.js @@ -0,0 +1,36 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var metrics = require( './../lib' ); + +var isMetric = contains( metrics() ); + +var bool = isMetric( 'sqeuclidean' ); +console.log( bool ); +// => true + +bool = isMetric( 'cosine' ); +console.log( bool ); +// => true + +bool = isMetric( 'beep' ); +console.log( bool ); +// => false diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/include/stdlib/ml/cluster/base/kmeans/metrics.h b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/include/stdlib/ml/cluster/base/kmeans/metrics.h new file mode 100644 index 000000000000..92412a0fbfc3 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/include/stdlib/ml/cluster/base/kmeans/metrics.h @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef STDLIB_ML_BASE_CLUSTER_KMEANS_METRICS_H +#define STDLIB_ML_BASE_CLUSTER_KMEANS_METRICS_H + +/** +* Enumeration of distance metrics. +*/ +enum STDLIB_ML_CLUSTER_KMEANS_METRICS { + // Squared euclidean distance: + STDLIB_ML_CLUSTER_KMEANS_SQEUCLIDEAN = 0, + + // Cosine distance: + STDLIB_ML_CLUSTER_KMEANS_COSINE, + + // Cityblock (taxicab) distance: + STDLIB_ML_CLUSTER_KMEANS_CITYBLOCK, + + // Correlation distance: + STDLIB_ML_CLUSTER_KMEANS_CORRELATION +}; + +#endif // !STDLIB_ML_BASE_CLUSTER_KMEANS_METRICS_H diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/lib/data.json b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/lib/data.json new file mode 100644 index 000000000000..9d38e90c954d --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/lib/data.json @@ -0,0 +1,6 @@ +[ + "sqeuclidean", + "cosine", + "cityblock", + "correlation" +] diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/lib/enum.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/lib/enum.js new file mode 100644 index 000000000000..5d7e7d3674d8 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/lib/enum.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +/** +* Returns an object mapping supported metrics to integer values for purposes of C inter-operation. +* +* ## Notes +* +* - Downstream consumers of this mapping should **not** rely on specific integer values (e.g., `SQEUCLIDEAN == 0`). Instead, the object should be used in an opaque manner. +* - The main purpose of this function is JavaScript and C inter-operation. +* +* @returns {Object} object mapping supported metrics to integer values +* +* @example +* var table = enumerated(); +* // returns +*/ +function enumerated() { + // NOTE: the following should match the C `metrics.h` enumeration!!!! + return { + // Squared euclidean distance: + 'sqeuclidean': 0, + + // Cosine distance: + 'cosine': 1, + + // Cityblock (taxicab) distance: + 'cityblock': 2, + + // Correlation distance: + 'correlation': 3 + }; +} + + +// EXPORTS // + +module.exports = enumerated; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/lib/index.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/lib/index.js new file mode 100644 index 000000000000..4ab25069e6c1 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/lib/index.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return a list of KMeans distance metrics. +* +* @module @stdlib/ml/base/cluster/kmeans/metrics +* +* @example +* var metrics = require( '@stdlib/ml/base/cluster/kmeans/metrics' ); +* +* var list = metrics(); +* // e.g., returns [ 'sqeuclidean', 'cosine', 'cityblock' , 'correlation' ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var enumeration = require( './enum.js' ); + + +// MAIN // + +setReadOnly( main, 'enum', enumeration ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/lib/main.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/lib/main.js new file mode 100644 index 000000000000..fd2d667d9bb1 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/lib/main.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var DATA = require( './data.json' ); + + +// MAIN // + +/** +* Returns a list of KMeans distance metrics. +* +* @returns {StringArray} list of distance metrics +* +* @example +* var list = metrics(); +* // e.g., returns [ 'sqeuclidean', 'cosine', 'cityblock' , 'correlation' ] +*/ +function metrics() { + return DATA.slice(); +} + + +// EXPORTS // + +module.exports = metrics; diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/manifest.json b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/manifest.json new file mode 100644 index 000000000000..844d692f6439 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/manifest.json @@ -0,0 +1,36 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [] + } + ] +} diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/package.json b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/package.json new file mode 100644 index 000000000000..929baeb098b9 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/ml/base/cluster/kmeans/metrics", + "version": "0.0.0", + "description": "KMeans distance metrics.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "ml", + "machine", + "learning", + "cluster", + "kmeans", + "metric", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/test/test.js b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/test/test.js new file mode 100644 index 000000000000..48a94749b7f0 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/test/test.js @@ -0,0 +1,77 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; +var metrics = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof metrics, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a list of metrics', function test( t ) { + var expected; + var actual; + + expected = [ + 'sqeuclidean', + 'cosine', + 'cityblock', + 'correlation' + ]; + actual = metrics(); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main function is an `enum` method to return an object mapping metrics to integer values for C inter-operation', function test( t ) { + var obj; + var o; + var i; + + t.strictEqual( hasOwnProp( metrics, 'enum' ), true, 'has property' ); + t.strictEqual( typeof metrics.enum, 'function', 'has method' ); + + obj = metrics.enum(); + t.strictEqual( typeof obj, 'object', 'returns expected value type' ); + + // List of values which should be supported... + o = [ + 'sqeuclidean', + 'cosine', + 'cityblock', + 'correlation' + ]; + for ( i = 0; i < o.length; i++ ) { + t.strictEqual( hasOwnProp( obj, o[ i ] ), true, 'has property `' + o[ i ] + '`' ); + t.strictEqual( isNonNegativeInteger( obj[ o[i] ] ), true, 'returns expected value' ); + } + + t.end(); +});