wasm-bhtsne
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

wasm-bhtsne

License: MIT

This is the wasm version of the bhtsne crate.

Features

Installation

npm i wasm-bhtsne

Example

import { threads } from 'wasm-feature-detect';

function createRandomMatrix(rows, columns) {
    return Array.from({ length: rows }, () =>
        Array.from({ length: columns }, () => Math.random())
    );
}

(async function initMultiThread() {
    const multiThread = await import('./pkg-parallel/wasm_bhtsne.js');
    await multiThread.default();
    if (await threads()) {
        console.log("Browser supports threads");
        await multiThread.initThreadPool(navigator.hardwareConcurrency);
    } else {
        console.log("Browser does not support threads");
    }

    Object.assign(document.getElementById("wasm-bhtsne"), {
        async onclick() {

            // create random points and dimensions
            const data = createRandomMatrix(500, 7);

            let tsne_encoder = new multiThread.bhtSNE(data); // create a tSNE instance
            tsne_encoder.perplexity = 25.0;  // change hyperparameters

            // run the algorithm with 1000 iterations 
            let compressed_vectors = tsne_encoder.step(1000); 
            console.log("Compressed Vectors:", compressed_vectors);
        },
        disabled: false
    });
})();

Package Sidebar

Install

npm i wasm-bhtsne

Weekly Downloads

22

Version

1.0.0

License

MIT

Unpacked Size

235 kB

Total Files

6

Last publish

Collaborators

  • lv291