TableOfReal CCA_and_TableOfReal_predict (CCA me, TableOfReal thee, long from) { TableOfReal him = NULL; long ny = my y -> dimension, nx = my x -> dimension; long i, j, k, ncols, nev = my y -> numberOfEigenvalues; double *buf = NULL, **v = my y -> eigenvectors; double *d = my y -> eigenvalues; /* We can only predict when we have the largest dimension as input and the number of coefficients equals the dimension of the smallest. */ if (ny != nev) return Melder_errorp1 (L"There are not enough correlations present for prediction."); if (from == 0) from = 1; ncols = thy numberOfColumns - from + 1; if (from < 1 || ncols != nx) return Melder_errorp3 (L"The number of columns to analyze must be equal to ", Melder_integer (nx), L"."); /* ???? dimensions if nx .. ny ?? */ him = Eigen_and_TableOfReal_project (my x, thee, from, ny); if (him == NULL) return NULL; buf = NUMdvector (1, ny); if (buf == NULL) goto end; /* u = V a -> a = V'u */ for (i = 1; i <= thy numberOfRows; i++) { NUMdvector_copyElements (his data[i], buf, 1, ny); for (j = 1; j <= ny; j++) { double t = 0; for (k = 1; k <= ny; k++) { t += sqrt (d[k]) * v[k][j] * buf[k]; } his data [i][j] = t; } } end: NUMdvector_free (buf, 1); if (Melder_hasError ()) forget (him); return him; }
TableOfReal CCA_and_TableOfReal_predict (CCA me, TableOfReal thee, long from) { try { long ny = my y -> dimension, nx = my x -> dimension; long nev = my y -> numberOfEigenvalues; /* We can only predict when we have the largest dimension as input and the number of coefficients equals the dimension of the smallest. */ if (ny != nev) { Melder_throw (U"There are not enough correlations present for prediction."); } if (from == 0) { from = 1; } long ncols = thy numberOfColumns - from + 1; if (from < 1 || ncols != nx) { Melder_throw (U"The number of columns to analyze must be equal to ", nx, U"."); } // ???? dimensions if nx .. ny ?? autoTableOfReal him = Eigen_and_TableOfReal_project (my x, thee, from, ny); autoNUMvector<double> buf (1, ny); // u = V a -> a = V'u double **v = my y -> eigenvectors; double *d = my y -> eigenvalues; for (long i = 1; i <= thy numberOfRows; i++) { NUMvector_copyElements (his data[i], buf.peek(), 1, ny); for (long j = 1; j <= ny; j++) { double t = 0.0; for (long k = 1; k <= ny; k++) { t += sqrt (d[k]) * v[k][j] * buf[k]; } his data [i][j] = t; } } return him.transfer(); } catch (MelderError) { Melder_throw (me, U": no predictions created."); } }