fix: pca calculating takes a long time

This commit is contained in:
jialin
2025-05-26 19:56:51 +08:00
parent 4b4343a9fd
commit 61e506010c
4 changed files with 19 additions and 13 deletions
@@ -14,10 +14,14 @@ self.onmessage = (
const dataList = embeddings.map((item) => {
return item.embedding;
});
let pca: any = null;
console.log('list:', dataList);
const pca = new PCA(dataList);
console.log('list:', pca);
// for large datasets, use NIPALS method for PCA
if (dataList.length > 200) {
pca = new PCA(dataList, { nCompNIPALS: 2, method: 'NIPALS' });
} else {
pca = new PCA(dataList); // default method is SVD
}
const pcadata = pca.predict(dataList, { nComponents: 2 }).to2DArray();
const input = [