@@ -27,12 +27,13 @@ function svd2(
2727 for ( let _iter = 0 ; _iter < 30 ; _iter ++ ) {
2828 const u = new Float64Array ( m ) ;
2929 for ( let i = 0 ; i < m ; i ++ ) {
30- for ( let j = 0 ; j < n ; j ++ ) u [ i ] += ( matrix [ i ] ?. [ j ] ?? 0 ) * ( v [ j ] ?? 0 ) ;
30+ for ( let j = 0 ; j < n ; j ++ )
31+ u [ i ] ! += ( matrix [ i ] ?. [ j ] ?? 0 ) * ( v [ j ] ?? 0 ) ;
3132 }
3233 const newV = new Float64Array ( n ) ;
3334 for ( let i = 0 ; i < m ; i ++ ) {
3435 for ( let j = 0 ; j < n ; j ++ )
35- newV [ j ] += ( matrix [ i ] ?. [ j ] ?? 0 ) * ( u [ i ] ?? 0 ) ;
36+ newV [ j ] ! += ( matrix [ i ] ?. [ j ] ?? 0 ) * ( u [ i ] ?? 0 ) ;
3637 }
3738 let norm = 0 ;
3839 for ( let j = 0 ; j < n ; j ++ ) norm += ( newV [ j ] ?? 0 ) ** 2 ;
@@ -42,7 +43,7 @@ function svd2(
4243 }
4344 const u = new Float64Array ( m ) ;
4445 for ( let i = 0 ; i < m ; i ++ ) {
45- for ( let j = 0 ; j < n ; j ++ ) u [ i ] += ( matrix [ i ] ?. [ j ] ?? 0 ) * ( v [ j ] ?? 0 ) ;
46+ for ( let j = 0 ; j < n ; j ++ ) u [ i ] ! += ( matrix [ i ] ?. [ j ] ?? 0 ) * ( v [ j ] ?? 0 ) ;
4647 }
4748 let sigma = 0 ;
4849 for ( let i = 0 ; i < m ; i ++ ) sigma += ( u [ i ] ?? 0 ) ** 2 ;
@@ -95,12 +96,12 @@ function kmeansSimple(X: Float64Array[], k: number, maxIter = 100): Int32Array {
9596 for ( let j = 0 ; j < k ; j ++ ) centers [ j ] = new Float64Array ( d ) ;
9697 for ( let i = 0 ; i < n ; i ++ ) {
9798 const c = labels [ i ] ! ;
98- counts [ c ] ++ ;
99+ counts [ c ] ! ++ ;
99100 for ( let l = 0 ; l < d ; l ++ ) centers [ c ] ! [ l ] ! += X [ i ] ?. [ l ] ?? 0 ;
100101 }
101102 for ( let j = 0 ; j < k ; j ++ ) {
102103 if ( ( counts [ j ] ?? 0 ) > 0 ) {
103- for ( let l = 0 ; l < d ; l ++ ) centers [ j ] ! [ l ] ! /= counts [ j ] ;
104+ for ( let l = 0 ; l < d ; l ++ ) centers [ j ] ! [ l ] ! /= counts [ j ] ?? 1 ;
104105 }
105106 }
106107 }
@@ -196,8 +197,8 @@ export class SpectralCoclustering {
196197 const colSums = new Float64Array ( nCols ) ;
197198 for ( let i = 0 ; i < nRows ; i ++ ) {
198199 for ( let j = 0 ; j < nCols ; j ++ ) {
199- rowSums [ i ] += X [ i ] ?. [ j ] ?? 0 ;
200- colSums [ j ] += X [ i ] ?. [ j ] ?? 0 ;
200+ rowSums [ i ] ! += X [ i ] ?. [ j ] ?? 0 ;
201+ colSums [ j ] ! += X [ i ] ?. [ j ] ?? 0 ;
201202 }
202203 }
203204 const normalized = X . map ( ( row , i ) => {
0 commit comments