autoSVD TableOfReal_to_SVD (TableOfReal me) { try { autoSVD thee = SVD_create_d (my data, my numberOfRows, my numberOfColumns); return thee; } catch (MelderError) { Melder_throw (me, U": no SVD created."); } }
SVD TableOfReal_to_SVD (I) { iam (TableOfReal); try { autoSVD thee = SVD_create_d (my data, my numberOfRows, my numberOfColumns); return thee.transfer(); } catch (MelderError) { Melder_throw (me, ": no SVD created."); } }
/* * Generate n different cct's that have a common diagonalizer. */ autoCrossCorrelationTables CrossCorrelationTables_createTestSet (long dimension, long n, int firstPositiveDefinite, double sigma) { try { // Start with a square matrix with random gaussian elements and make its singular value decomposition UDV' // The V matrix will be the common diagonalizer matrix that we use. autoNUMmatrix<double> d (1, dimension, 1, dimension); for (long i = 1; i <= dimension; i++) { // Generate the rotation matrix for (long j = 1; j <= dimension; j++) { d[i][j] = NUMrandomGauss (0, 1); } } autoNUMmatrix<double> v (1, dimension, 1, dimension); autoSVD svd = SVD_create_d (d.peek(), dimension, dimension); autoCrossCorrelationTables me = CrossCorrelationTables_create (); for (long i = 1; i <= dimension; i++) { for (long j = 1; j <= dimension; j++) { d[i][j] = 0; } } // Start with a diagonal matrix D and calculate V'DV for (long k = 1; k <= n; k++) { autoCrossCorrelationTable ct = CrossCorrelationTable_create (dimension); double low = k == 1 && firstPositiveDefinite ? 0.1 : -1; for (long i = 1; i <= dimension; i++) { d[i][i] = NUMrandomUniform (low, 1); } for (long i = 1; i <= dimension; i++) { for (long j = 1; j <= dimension; j++) { v[i][j] = NUMrandomGauss (svd -> v[i][j], sigma); } } // we need V'DV, however our V has eigenvectors row-wise -> VDV' NUMdmatrices_multiply_VCVp (ct -> data, v.peek(), dimension, dimension, d.peek(), 1); Collection_addItem_move (me.peek(), ct.move()); } return me; } catch (MelderError) { Melder_throw (U"CrossCorrelationTables test set not created."); } }