diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/README.md b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/README.md new file mode 100644 index 000000000000..6b50984c6421 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/README.md @@ -0,0 +1,186 @@ + + +# Clustering Algorithms + +> k-means clustering algorithms. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var algorithms = require( '@stdlib/ml/base/kmeans/algorithms' ); +``` + +#### algorithms() + +Returns a list of k-means clustering algorithms. + +```javascript +var out = algorithms(); +// e.g., returns [ 'lloyd', 'elkan' ] +``` + +The output array contains the following algorithms: + +- `lloyd`: classic EM-style algorithm. +- `elkan`: optimized algorithm using triangle inequality. + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + + + +```javascript +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var algorithms = require( '@stdlib/ml/base/kmeans/algorithms' ); + +var isAlgorithm = contains( algorithms() ); + +var bool = isAlgorithm( 'lloyd' ); +// returns true + +bool = isAlgorithm( 'elkan' ); +// returns true + +bool = isAlgorithm( 'beep' ); +// returns false +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/ml/base/kmeans/algorithms.h" +``` + +#### STDLIB_ML_KMEANS_ALGORITHM + +An enumeration of k-means clustering algorithms with the following fields: + +- **STDLIB_ML_KMEANS_LLOYD**: classic EM-style algorithm. +- **STDLIB_ML_KMEANS_ELKAN**: optimized algorithm using triangle inequality. + +```c +#include "stdlib/ml/base/kmeans/algorithms.h" + +const enum STDLIB_ML_KMEANS_ALGORITHM v = STDLIB_ML_KMEANS_LLOYD; +``` + +
+ + + + + +
+ +### 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/kmeans/algorithms/benchmark/benchmark.js b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/benchmark/benchmark.js new file mode 100644 index 000000000000..1c08c06dd2c3 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/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 algorithms = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = algorithms(); + 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/kmeans/algorithms/docs/repl.txt b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/docs/repl.txt new file mode 100644 index 000000000000..a99709a2362b --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/docs/repl.txt @@ -0,0 +1,22 @@ + +{{alias}}() + Returns a list of k-means clustering algorithms. + + The output array contains the following algorithms: + + - lloyd: classic EM-style algorithm. + - elkan: optimized algorithm using triangle inequality. + + Returns + ------- + out: Array + List of algorithms. + + Examples + -------- + > var out = {{alias}}() + [ 'lloyd', 'elkan' ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/docs/types/index.d.ts b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/docs/types/index.d.ts new file mode 100644 index 000000000000..2b65c44d01c1 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/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 k-means clustering algorithms. +* +* @returns list of clustering algorithms +* +* @example +* var list = algorithms(); +* // e.g., returns [ 'lloyd', 'elkan' ] +*/ +declare function algorithms(): Array; + + +// EXPORTS // + +export = algorithms; diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/docs/types/test.ts b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/docs/types/test.ts new file mode 100644 index 000000000000..d2c24ff02a3d --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/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 algorithms = require( './index' ); + + +// TESTS // + +// The function returns an array of strings... +{ + algorithms(); // $ExpectType string[] +} + +// The compiler throws an error if the function is provided any arguments... +{ + algorithms( 9 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/examples/index.js b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/examples/index.js new file mode 100644 index 000000000000..dab64b6c583b --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/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 algorithms = require( './../lib' ); + +var isAlgorithm = contains( algorithms() ); + +var bool = isAlgorithm( 'lloyd' ); +console.log( bool ); +// => true + +bool = isAlgorithm( 'elkan' ); +console.log( bool ); +// => true + +bool = isAlgorithm( 'beep' ); +console.log( bool ); +// => false diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/include/stdlib/ml/base/kmeans/algorithms.h b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/include/stdlib/ml/base/kmeans/algorithms.h new file mode 100644 index 000000000000..ff5e6b8d7559 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/include/stdlib/ml/base/kmeans/algorithms.h @@ -0,0 +1,33 @@ +/** +* @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_KMEANS_ALGORITHMS_H +#define STDLIB_ML_BASE_KMEANS_ALGORITHMS_H + +/** +* Enumeration of k-means clustering algorithms. +*/ +enum STDLIB_ML_KMEANS_ALGORITHMS { + // Classic EM-style algorithm: + STDLIB_ML_KMEANS_LLOYD = 0, + + // Optimized algorithm using triangle inequality: + STDLIB_ML_KMEANS_ELKAN, +}; + +#endif // !STDLIB_ML_BASE_KMEANS_ALGORITHMS_H diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/lib/data.json b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/lib/data.json new file mode 100644 index 000000000000..a29165499031 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/lib/data.json @@ -0,0 +1,4 @@ +[ + "lloyd", + "elkan" +] diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/lib/enum.js b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/lib/enum.js new file mode 100644 index 000000000000..68157ba33663 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/lib/enum.js @@ -0,0 +1,51 @@ +/** +* @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 algorithms to integer values for purposes of C inter-operation. +* +* ## Notes +* +* - Downstream consumers of this mapping should **not** rely on specific integer values (e.g., `LLOYD == 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 algorithms to integer values +* +* @example +* var table = enumerated(); +* // returns +*/ +function enumerated() { + // NOTE: the following should match the C `algorithms.h` enumeration!!!! + return { + // Classic EM-style algorithm: + 'lloyd': 0, + + // Optimized algorithm using triangle inequality: + 'elkan': 1 + }; +} + + +// EXPORTS // + +module.exports = enumerated; diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/lib/index.js b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/lib/index.js new file mode 100644 index 000000000000..cea7b8e47f9c --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/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 k-means clustering algorithms. +* +* @module @stdlib/ml/base/kmeans/algorithms +* +* @example +* var algorithms = require( '@stdlib/ml/base/kmeans/algorithms' ); +* +* var list = algorithms(); +* // e.g., returns [ 'lloyd', 'elkan' ] +*/ + +// 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/kmeans/algorithms/lib/main.js b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/lib/main.js new file mode 100644 index 000000000000..7781e9820a63 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/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 k-means clustering algorithms. +* +* @returns {Array} list of clustering algorithms +* +* @example +* var list = algorithms(); +* // e.g., returns [ 'lloyd', 'elkan' ] +*/ +function algorithms() { + return DATA.slice(); +} + + +// EXPORTS // + +module.exports = algorithms; diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/manifest.json b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/manifest.json new file mode 100644 index 000000000000..844d692f6439 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/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/kmeans/algorithms/package.json b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/package.json new file mode 100644 index 000000000000..fc90aeefa7d9 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/ml/base/kmeans/algorithms", + "version": "0.0.0", + "description": "k-means clustering algorithms.", + "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", + "kmeans", + "algorithms", + "utilities", + "utility", + "utils", + "util", + "enum" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/test/test.js b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/test/test.js new file mode 100644 index 000000000000..4609593a9398 --- /dev/null +++ b/lib/node_modules/@stdlib/ml/base/kmeans/algorithms/test/test.js @@ -0,0 +1,73 @@ +/** +* @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 algorithms = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof algorithms, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns a list of k-means clustering algorithms', function test( t ) { + var expected; + var actual; + + expected = [ + 'lloyd', + 'elkan' + ]; + actual = algorithms(); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'attached to the main function is an `enum` method to return an object mapping algorithms to integer values for C inter-operation', function test( t ) { + var obj; + var o; + var i; + + t.strictEqual( hasOwnProp( algorithms, 'enum' ), true, 'has property' ); + t.strictEqual( typeof algorithms.enum, 'function', 'has method' ); + + obj = algorithms.enum(); + t.strictEqual( typeof obj, 'object', 'returns expected value type' ); + + // List of values which should be supported... + o = [ + 'lloyd', + 'elkan' + ]; + 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(); +});