Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 190 additions & 0 deletions lib/node_modules/@stdlib/ml/base/cluster/kmeans/metrics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
<!--

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

-->

# Distance Metrics

> KMeans distance metrics.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

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

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

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

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### 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;
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

### Notes

- Enumeration constants should be considered opaque values, and one should **not** rely on specific integer values.

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -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();
});
Original file line number Diff line number Diff line change
@@ -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<string>
List of metrics.

Examples
--------
> var out = {{alias}}()
[ 'sqeuclidean', 'cosine', 'cityblock', 'correlation' ]

See Also
--------

Original file line number Diff line number Diff line change
@@ -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<string>;


// EXPORTS //

export = metrics;
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
Loading