This is the wasm version of the bhtsne crate.
- Harnesses multi-threading capabilities through wasm-bindgen-rayon.
npm i wasm-bhtsne
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
});
})();