void Configuration_rotateToPrincipalDirections (Configuration me) { try { autoNUMmatrix<double> m (NUMmatrix_copy (my data, 1, my numberOfRows, 1, my numberOfColumns), 1, 1); NUMdmatrix_into_principalComponents (my data, my numberOfRows, my numberOfColumns, my numberOfColumns, m.peek()); NUMvector_free (my data, 1); my data = m.transfer(); } catch (MelderError) { Melder_throw (me, U": not rotated to principal directions."); } }
autoPCA TableOfReal_to_PCA (I) { iam (TableOfReal); try { long m = my numberOfRows, n = my numberOfColumns; if (! TableOfReal_areAllCellsDefined (me, 0, 0, 0, 0)) { Melder_throw (U"Undefined cells."); } if (m < 2) { Melder_throw (U"There is not enough data to perform a PCA.\nYour table has less than 2 rows."); } if (m < n) { Melder_warning (U"The number of rows in your table is less than the \nnumber of columns. "); } if (NUMfrobeniusnorm (m, n, my data) == 0) { Melder_throw (U"All values in your table are zero."); } autoPCA thee = Thing_new (PCA); autoNUMmatrix<double> a (NUMmatrix_copy (my data, 1, m, 1, n), 1, 1); thy centroid = NUMvector<double> (1, n); for (long j = 1; j <= n; j++) { double colmean = a[1][j]; for (long i = 2; i <= m; i++) { colmean += a[i][j]; } colmean /= m; for (long i = 1; i <= m; i++) { a[i][j] -= colmean; } thy centroid[j] = colmean; } Eigen_initFromSquareRoot (thee.peek(), a.peek(), m, n); thy labels = NUMvector<char32 *> (1, n); NUMstrings_copyElements (my columnLabels, thy labels, 1, n); PCA_setNumberOfObservations (thee.peek(), m); /* The covariance matrix C = A'A / (N-1). However, we have calculated the eigenstructure for A'A. This has no consequences for the eigenvectors, but the eigenvalues have to be divided by (N-1). */ for (long i = 1; i <= thy numberOfEigenvalues; i++) { thy eigenvalues[i] /= (m - 1); } return thee; } catch (MelderError) { Melder_throw (me, U": PCA not created."); } }
static void Sound_and_MixingMatrix_improveUnmixing_fica (Sound me, MixingMatrix thee, long maxNumberOfIterations, double /* tol */, int /* method */) { try { long iter = 0; if (my ny != thy numberOfColumns) { Melder_throw (U"Dimensions do not agree."); } autoNUMmatrix<double> x (NUMmatrix_copy (my z, 1, my ny, 1, my nx), 1, 1); do { iter ++; } while (/*fabs((dm_old - dm_new) / dm_new) > tol &&*/ iter < maxNumberOfIterations); } catch (MelderError) { Melder_throw (me, U" & ", thee, U" ."); } }