TableOfReal CCA_and_TableOfReal_scores (CCA me, TableOfReal thee, long numberOfFactors) { try { long n = thy numberOfRows; long nx = my x -> dimension, ny = my y -> dimension; if (ny + nx != thy numberOfColumns) { Melder_throw (U"The number of columns in the table (", thy numberOfColumns, U") does not agree with the dimensions of the CCA object (ny + nx = ", ny, U" + ", nx, U")."); } if (numberOfFactors == 0) { numberOfFactors = my numberOfCoefficients; } if (numberOfFactors < 1 || numberOfFactors > my numberOfCoefficients) { Melder_throw (U"The number of factors must be in interval [1, ", my numberOfCoefficients, U"]."); } autoTableOfReal him = TableOfReal_create (n, 2 * numberOfFactors); TableOfReal phim = him.peek(); NUMstrings_copyElements (thy rowLabels, his rowLabels, 1, thy numberOfRows); Eigen_and_TableOfReal_project_into (my y, thee, 1, ny, &phim, 1, numberOfFactors); Eigen_and_TableOfReal_project_into (my x, thee, ny + 1, thy numberOfColumns, &phim, numberOfFactors + 1, his numberOfColumns); TableOfReal_setSequentialColumnLabels (him.peek(), 1, numberOfFactors, U"y_", 1, 1); TableOfReal_setSequentialColumnLabels (him.peek(), numberOfFactors + 1, his numberOfColumns, U"x_", 1, 1); return him.transfer(); } catch (MelderError) { Melder_throw (me, U": no TableOfReal with scores created."); } }
TableOfReal CCA_and_TableOfReal_scores (CCA me, TableOfReal thee, long numberOfFactors) { TableOfReal him = NULL; long n = thy numberOfRows; long nx = my x -> dimension, ny = my y -> dimension; if (ny + nx != thy numberOfColumns) return Melder_errorp7 (L"The number " "of columns in the table (", Melder_integer (thy numberOfColumns), L") does not agree with " "the dimensions of the CCA object (ny + nx = ", Melder_integer (ny), L" + ", Melder_integer (nx), L")."); if (numberOfFactors == 0) numberOfFactors = my numberOfCoefficients; if (numberOfFactors < 1 || numberOfFactors > my numberOfCoefficients) return Melder_errorp3 (L"The number of factors must be in interval " "[1, ", Melder_integer (my numberOfCoefficients), L"]."); him = TableOfReal_create (n, 2 * numberOfFactors); if (him == NULL) return NULL; if (! NUMstrings_copyElements (thy rowLabels, his rowLabels, 1, thy numberOfRows) || ! Eigen_and_TableOfReal_project_into (my y, thee, 1, ny, &him, 1, numberOfFactors) || ! Eigen_and_TableOfReal_project_into (my x, thee, ny + 1, thy numberOfColumns, &him, numberOfFactors + 1, his numberOfColumns) || ! TableOfReal_setSequentialColumnLabels (him, 1, numberOfFactors, L"y_", 1, 1) || ! TableOfReal_setSequentialColumnLabels (him, numberOfFactors + 1, his numberOfColumns, L"x_", 1, 1)) forget (him); return him; }
autoTableOfReal Eigen_and_TableOfReal_project (Eigen me, TableOfReal thee, long from, long numberOfComponents) { try { if (numberOfComponents == 0) { numberOfComponents = my numberOfEigenvalues; } autoTableOfReal him = TableOfReal_create (thy numberOfRows, numberOfComponents); Eigen_and_TableOfReal_project_into (me, thee, from, thy numberOfColumns, him.peek(), 1, numberOfComponents); NUMstrings_copyElements (thy rowLabels, his rowLabels, 1, thy numberOfRows); return him.transfer(); } catch (MelderError) { Melder_throw (U"TableOfReal not created from projection."); } }
Configuration Discriminant_and_TableOfReal_to_Configuration (Discriminant me, TableOfReal thee, long numberOfDimensions) { try { if (numberOfDimensions == 0) { numberOfDimensions = Discriminant_getNumberOfFunctions (me); } autoConfiguration him = Configuration_create (thy numberOfRows, numberOfDimensions); Configuration thim = him.peek(); Eigen_and_TableOfReal_project_into (me, thee, 1, thy numberOfColumns, & thim, 1, numberOfDimensions); TableOfReal_copyLabels (thee, thim, 1, 0); TableOfReal_setSequentialColumnLabels (him.peek(), 0, 0, U"Eigenvector ", 1, 1); return him.transfer(); } catch (MelderError) { Melder_throw (U"Configuration not created."); } }
autoConfiguration PCA_and_TableOfReal_to_Configuration (PCA me, thou, long numberOfDimensions) { try { thouart (TableOfReal); if (numberOfDimensions == 0 || numberOfDimensions > my numberOfEigenvalues) { numberOfDimensions = my numberOfEigenvalues; } autoConfiguration him = Configuration_create (thy numberOfRows, numberOfDimensions); Eigen_and_TableOfReal_project_into (me, thee, 1, thy numberOfColumns, him.peek(), 1, numberOfDimensions); NUMstrings_copyElements (thy rowLabels, his rowLabels, 1, thy numberOfRows); TableOfReal_setSequentialColumnLabels (him.peek(), 0, 0, U"pc", 1, 1); return him; } catch (MelderError) { Melder_throw (U"Configuration not created from PCA & TableOfReal."); } }
TableOfReal Eigen_and_TableOfReal_project (I, thou, long from, long numberOfComponents) { iam (Eigen); thouart (TableOfReal); TableOfReal him; if (numberOfComponents == 0) numberOfComponents = my numberOfEigenvalues; him = TableOfReal_create (thy numberOfRows, numberOfComponents); if (him != NULL) { if (! Eigen_and_TableOfReal_project_into (me, thee, from, thy numberOfColumns, & him, 1, numberOfComponents) || ! NUMstrings_copyElements (thy rowLabels, his rowLabels, 1, thy numberOfRows)) forget (him); } return him; }