Esempio n. 1
0
/*
	raw r[j]: eigenvec[i][j]
	unstandardized u[j]: sqrt(N-g) * r[j]
	standardized s[j]: u[j] sqrt (w[i][i] / (N-g))
*/
autoTableOfReal Discriminant_extractCoefficients (Discriminant me, int choice) {
    try {
        int raw = choice == 0, standardized = choice == 2;
        long nx = my eigen -> dimension, ny = my eigen -> numberOfEigenvalues;

        SSCP total = my total.get();
        autoTableOfReal thee = TableOfReal_create (ny, nx + 1);
        NUMstrings_copyElements (my total -> columnLabels, thy columnLabels, 1, nx);

        autoSSCP within;
        if (standardized) {
            within = Discriminant_extractPooledWithinGroupsSSCP (me);
        }

        TableOfReal_setColumnLabel (thee.get(), nx + 1, U"constant");
        TableOfReal_setSequentialRowLabels (thee.get(), 1, ny, U"function_", 1, 1);

        double scale = sqrt (total -> numberOfObservations - my numberOfGroups);
        double *centroid = my total -> centroid;
        for (long i = 1; i <= ny; i++) {
            double u0 = 0.0, ui;
            for (long j = 1; j <= nx; j++) {
                if (standardized) {
                    scale = sqrt (within -> data[j][j]);
                }
                thy data[i][j] = ui = scale * my eigen -> eigenvectors[i][j];;
                u0 += ui * centroid[j];
            }
            thy data[i][nx + 1] = raw ? 0.0 : -u0;
        }
        return thee;
    } catch (MelderError) {
        Melder_throw (me, U": coefficients not extracted.");
    }
}
Esempio n. 2
0
autoTableOfReal PCA_and_Configuration_to_TableOfReal_reconstruct (PCA me, Configuration thee) {
	try {
		long npc = thy numberOfColumns;

		if (thy numberOfColumns > my dimension) {
			Melder_throw (U"The dimension of the Configuration must be less than or equal to the dimension of the PCA.");
		}

		if (npc > my numberOfEigenvalues) {
			npc = my numberOfEigenvalues;
		}

		autoTableOfReal him = TableOfReal_create (thy numberOfRows, my dimension);
		NUMstrings_copyElements (my labels, his columnLabels, 1, my dimension);
		NUMstrings_copyElements (thy rowLabels, his rowLabels, 1, thy numberOfRows);

		for (long i = 1; i <= thy numberOfRows; i++) {
			double *hisdata = his data[i];
			for (long k = 1; k <= npc; k++) {
				double *evec = my eigenvectors[k], pc = thy data[i][k];
				for (long j = 1; j <= my dimension; j++) {
					hisdata[j] += pc * evec[j];
				}
			}
		}
		return him;
	} catch (MelderError) {
		Melder_throw (U"TableOfReal not reconstructed.");
	}
}
Esempio n. 3
0
File: CCA.c Progetto: alekstorm/tala
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;
}
Esempio n. 4
0
autoTableOfReal Confusion_to_TableOfReal_marginals (Confusion me) {
	try {
		autoTableOfReal thee = TableOfReal_create (my numberOfRows + 1, my numberOfColumns + 1);

		double total = 0.0;
		for (long i = 1; i <= my numberOfRows; i++) {
			double rowsum = 0.0;
			for (long j = 1; j <= my numberOfColumns; j++) {
				thy data[i][j] = my data[i][j];
				rowsum += my data[i][j];
			}
			thy data[i][my numberOfColumns + 1] = rowsum;
			total += rowsum;
		}

		thy data[my numberOfRows + 1][my numberOfColumns + 1] = total;

		for (long j = 1; j <= my numberOfColumns; j++) {
			double colsum = 0;
			for (long i = 1; i <= my numberOfRows; i++) {
				colsum += my data[i][j];
			}
			thy data[my numberOfRows + 1][j] = colsum;
		}

		NUMstrings_copyElements (my rowLabels, thy rowLabels, 1, my numberOfRows);
		NUMstrings_copyElements (my columnLabels, thy columnLabels, 1, my numberOfColumns);
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": table with marginals not created.");
	}
}
Esempio n. 5
0
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.");
	}
}
Esempio n. 6
0
autoTableOfReal FormantTier_downto_TableOfReal (FormantTier me, int includeFormants, int includeBandwidths) {
	try {
		int maximumNumberOfFormants = FormantTier_getMaxNumFormants (me);
		autoTableOfReal thee = TableOfReal_create (my points -> size, 1 +
			( includeFormants ? maximumNumberOfFormants : 0 ) +
			( includeBandwidths ? maximumNumberOfFormants : 0 ));
		TableOfReal_setColumnLabel (thee.peek(), 1, U"Time");
		for (long icol = 1, iformant = 1; iformant <= maximumNumberOfFormants; iformant ++) {
			char32 label [4];
			if (includeFormants) {
				Melder_sprint (label,4, U"F", iformant);
				TableOfReal_setColumnLabel (thee.peek(), ++ icol, label);
			}
			if (includeBandwidths) {
				Melder_sprint (label,4, U"B", iformant);
				TableOfReal_setColumnLabel (thee.peek(), ++ icol, label);
			}
		}
		for (long ipoint = 1; ipoint <= my points -> size; ipoint ++) {
			FormantPoint point = (FormantPoint) my points -> item [ipoint];
			thy data [ipoint] [1] = point -> time;
			for (long icol = 1, iformant = 1; iformant <= maximumNumberOfFormants; iformant ++) {
				if (includeFormants) thy data [ipoint] [++ icol] = point -> formant [iformant-1];
				if (includeBandwidths) thy data [ipoint] [++ icol] = point -> bandwidth [iformant-1];
			}
		}
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": not converted to TableOfReal.");
	}
}
Esempio n. 7
0
autoTableOfReal FFNet_extractWeights (FFNet me, long layer) {
	try {
		FFNet_checkLayerNumber (me, layer);

		long numberOfUnitsFrom = my nUnitsInLayer[layer - 1] + 1;
		long numberOfUnitsTo = my nUnitsInLayer[layer];
		autoTableOfReal thee = TableOfReal_create (numberOfUnitsFrom, numberOfUnitsTo);

		char32 label[40];
		for (long i = 1; i <= numberOfUnitsFrom - 1; i++) {
			Melder_sprint (label,40, U"L", layer - 1, U"-", i);
			TableOfReal_setRowLabel (thee.peek(), i, label);
		}
		TableOfReal_setRowLabel (thee.peek(), numberOfUnitsFrom, U"Bias");
		for (long i = 1; i <= numberOfUnitsTo; i++) {
			Melder_sprint (label,40, U"L", layer, U"-", i);
			TableOfReal_setColumnLabel (thee.peek(), i, label);
		}

		long node = 1;
		for (long i = 0; i < layer; i++) {
			node += my nUnitsInLayer[i] + 1;
		}
		for (long i = 1; i <= numberOfUnitsTo; i++, node++) {
			long k = 1;
			for (long j = my wFirst[node]; j <= my wLast[node]; j++) {
				thy data[k++][i] = my w[j];
			}
		}
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": no TableOfReal created.");
	}
}
Esempio n. 8
0
autoTableOfReal SVD_to_TableOfReal (SVD me, long from, long to) {
	try {
		autoTableOfReal thee = TableOfReal_create (my numberOfRows, my numberOfColumns);
		SVD_synthesize (me, from, to, thy data);
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": no TableOfReal synthesized.");
	}
}
Esempio n. 9
0
autoTableOfReal SVD_extractRightSingularVectors (SVD me) {
	try {
		long mn_min = MIN (my numberOfRows, my numberOfColumns);
		autoTableOfReal thee = TableOfReal_create (my numberOfColumns, mn_min);
		NUMmatrix_copyElements (my v, thy data, 1, my numberOfColumns, 1, mn_min);
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": right singular vector not extracted.");
	}
}
Esempio n. 10
0
autoTableOfReal SVD_extractSingularValues (SVD me) {
	try {
		long mn_min = MIN (my numberOfRows, my numberOfColumns);
		autoTableOfReal thee = TableOfReal_create (1, mn_min);
		NUMvector_copyElements (my d, thy data[1], 1, mn_min);
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": singular values not extracted.");
	}
}
Esempio n. 11
0
autoTableOfReal Matrix_to_TableOfReal (Matrix me) {
	try {
		autoTableOfReal thee = TableOfReal_create (my ny, my nx);
		for (long i = 1; i <= my ny; i ++)
			for (long j = 1; j <= my nx; j ++)
				thy data [i] [j] = my z [i] [j];
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": not converted to TableOfReal.");
	}
}
Esempio n. 12
0
TableOfReal SVD_extractLeftSingularVectors (I) {
	iam (SVD);
	try {
		long mn_min = MIN (my numberOfRows, my numberOfColumns);
		autoTableOfReal thee = TableOfReal_create (my numberOfRows, mn_min);
		NUMmatrix_copyElements (my u, thy data, 1, my numberOfRows, 1, mn_min);
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, ": left singular vector not extracted.");
	}
}
Esempio n. 13
0
TableOfReal AffineTransform_extractTranslationVector (I) {
	iam (AffineTransform);
	try {
		autoTableOfReal thee = TableOfReal_create (1, my n);
		for (long i = 1; i <= my n; i++) {
			thy data[1][i] = my t[i];
		}
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, ": translation vector not extracted.");
	}
}
TableOfReal TableOfReal_extractColumnRanges (TableOfReal me, const wchar_t *ranges) {
	try {
		long numberOfElements;
		autoNUMvector <long> elements (getElementsOfRanges (ranges, my numberOfColumns, & numberOfElements, L"column"), 1);
		autoTableOfReal thee = TableOfReal_create (my numberOfRows, numberOfElements);
		copyRowLabels (me, thee.peek());
		for (long ielement = 1; ielement <= numberOfElements; ielement ++)
			copyColumn (me, elements [ielement], thee.peek(), ielement);
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, ": column ranges not extracted.");
	}
}
Esempio n. 15
0
TableOfReal RealTier_downto_TableOfReal (I, const wchar_t *timeLabel, const wchar_t *valueLabel) {
	iam (RealTier);
	TableOfReal thee = TableOfReal_create (my points -> size, 2); cherror
	TableOfReal_setColumnLabel (thee, 1, timeLabel); cherror
	TableOfReal_setColumnLabel (thee, 2, valueLabel); cherror
	for (long i = 1; i <= my points -> size; i ++) {
		RealPoint point = (structRealPoint *)my points -> item [i];
		thy data [i] [1] = point -> time;
		thy data [i] [2] = point -> value;
	}
end:
	iferror forget (thee);
	return thee;
}
Esempio n. 16
0
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.");
	}
}
Esempio n. 17
0
autoTableOfReal PCA_and_TableOfReal_to_TableOfReal_projectRows (PCA me, TableOfReal thee, long numberOfDimensionsToKeep) {
	try {
		if (numberOfDimensionsToKeep == 0 || numberOfDimensionsToKeep > my numberOfEigenvalues) {
			numberOfDimensionsToKeep = my numberOfEigenvalues;
		}

		autoTableOfReal him = TableOfReal_create (thy numberOfRows, numberOfDimensionsToKeep);
		Eigen_and_TableOfReal_into_TableOfReal_projectRows (me, thee, 1, him.get(), 1, numberOfDimensionsToKeep);
		NUMstrings_copyElements (thy rowLabels, his rowLabels, 1, thy numberOfRows);
		TableOfReal_setSequentialColumnLabels (him.get(), 0, 0, U"pc", 1, 1);
		return him;
	} catch (MelderError) {
		Melder_throw (U"TableOfReal not created from PCA & TableOfReal.");
	}
}
Esempio n. 18
0
autoTableOfReal RealTier_downto_TableOfReal (RealTier me, const char32 *timeLabel, const char32 *valueLabel) {
	try {
		autoTableOfReal thee = TableOfReal_create (my points.size, 2);
		TableOfReal_setColumnLabel (thee.get(), 1, timeLabel);
		TableOfReal_setColumnLabel (thee.get(), 2, valueLabel);
		for (long i = 1; i <= my points.size; i ++) {
			RealPoint point = my points.at [i];
			thy data [i] [1] = point -> number;
			thy data [i] [2] = point -> value;
		}
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": not converted to TableOfReal.");
	}
}
Esempio n. 19
0
TableOfReal EditDistanceTable_to_TableOfReal (EditDistanceTable me) {
    try {
        autoTableOfReal thee = TableOfReal_create (my numberOfRows, my numberOfColumns);
        for (long j = 1; j <= my numberOfColumns; j++) {
            thy columnLabels[j] = Melder_dup (my columnLabels[j]);
        }
        for (long i = 1; i <= my numberOfRows; i++) {
            thy rowLabels[i] = Melder_dup (my rowLabels[i]);
        }
        NUMmatrix_copyElements<double> (my data, thy data, 1, my numberOfRows, 1, my numberOfColumns);
        return thee.transfer();
    } catch (MelderError) {
        Melder_throw (me, U": no TableOfReal created.");
    }
}
Esempio n. 20
0
autoTableOfReal Excitations_to_TableOfReal (Excitations me) {
	try {
		Melder_assert (my size > 0);
		Matrix m = (Matrix) my item[1];
		autoTableOfReal thee = TableOfReal_create (my size, m -> nx);
		for (long i = 1;  i <= my size; i++) {
			double *z = ( (Matrix) my item[i]) -> z[1];
			for (long j = 1; j <= m -> nx; j++) {
				thy data[i][j] = z[j];
			}
		}
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": no TableOfReal created.");
	}
}
Esempio n. 21
0
autoTableOfReal Discriminant_extractGroupCentroids (Discriminant me) {
    try {
        long m = my groups -> size, n = my eigen -> dimension;
        autoTableOfReal thee = TableOfReal_create (m, n);

        for (long i = 1; i <= m; i ++) {
            SSCP sscp = my groups->at [i];
            TableOfReal_setRowLabel (thee.get(), i, Thing_getName (sscp));
            NUMvector_copyElements (sscp -> centroid, thy data [i], 1, n);
        }
        NUMstrings_copyElements (my groups->at [m] -> columnLabels, thy columnLabels, 1, n);
        return thee;
    } catch (MelderError) {
        Melder_throw (me, U": group centroids not extracted.");
    }
}
Esempio n. 22
0
TableOfReal AffineTransform_extractMatrix (I) {
	iam (AffineTransform);
	try {
		autoTableOfReal thee = TableOfReal_create (my n, my n);
		NUMmatrix_copyElements (my r, thy data, 1, my n, 1, my n);
		for (long i = 1; i <= my n; i++) {
			wchar_t label[20];
			(void) swprintf (label, 20, L"%ld", i);
			TableOfReal_setRowLabel (thee.peek(), i, label);
			TableOfReal_setColumnLabel (thee.peek(), i, label);
		}
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, ": transformation matrix not extracted.");
	}
}
TableOfReal TableOfReal_and_Permutation_permuteRows (I, Permutation thee) {
	iam (TableOfReal);
	try {
		if (my numberOfRows != thy numberOfElements) {
			Melder_throw (L"The number of rows in the table and the number of elements in the Permutation must be equal.");
		}
		autoTableOfReal him = TableOfReal_create (my numberOfRows, my numberOfColumns);

		for (long i = 1; i <= thy numberOfElements; i++) {
			TableOfReal_copyOneRowWithLabel (me, him.peek(), thy p[i], i);
		}
		return him.transfer();
	} catch (MelderError) {
		Melder_throw (me, ": not permuted.");
	}
}
Esempio n. 24
0
TableOfReal CCA_and_Correlation_factorLoadings (CCA me, Correlation thee)
{
	TableOfReal him;
	long i, j, k, ny = my y -> dimension, nx = my x -> dimension;
	double t, **evecy = my y -> eigenvectors, **evecx = my x -> eigenvectors;

	if (ny + nx != thy numberOfColumns) return Melder_errorp1 (L"The number "
		"of columns in the Correlation object must equal the sum of the "
		"dimensions in the CCA object");

	him = TableOfReal_create (2 * my numberOfCoefficients, thy numberOfColumns);
	if (him == NULL) return NULL;
	
	if (! NUMstrings_copyElements (thy columnLabels, his columnLabels, 
			1, thy numberOfColumns) ||
		! TableOfReal_setSequentialRowLabels (him, 1, my numberOfCoefficients,
			L"dv", 1, 1) ||
		! TableOfReal_setSequentialRowLabels (him, my numberOfCoefficients + 1,
			2 * my numberOfCoefficients, L"iv", 1, 1))
	{
		forget (him);
		return NULL;
	}

	for (i = 1; i <= thy numberOfRows; i++)
	{
		for (j = 1; j <= my numberOfCoefficients; j++)
		{
			t = 0;
			for (k = 1; k <= ny; k++)
			{
				t += thy data[i][k] * evecy[j][k];
			}
			his data[j][i] = t;
		}
		for (j = 1; j <= my numberOfCoefficients; j++)
		{
			t = 0;
			for (k = 1; k <= nx; k++)
			{
				t += thy data[i][ny + k] * evecx[j][k];
			}
			his data[my numberOfCoefficients + j][i] = t;
		}
	}
	return him;
}
TableOfReal Table_to_TableOfReal (Table me, long labelColumn) {
	try {
		if (labelColumn < 1 || labelColumn > my numberOfColumns) labelColumn = 0;
		autoTableOfReal thee = TableOfReal_create (my rows -> size, labelColumn ? my numberOfColumns - 1 : my numberOfColumns);
		for (long icol = 1; icol <= my numberOfColumns; icol ++) {
			Table_numericize_Assert (me, icol);
		}
		if (labelColumn) {
			for (long icol = 1; icol < labelColumn; icol ++) {
				TableOfReal_setColumnLabel (thee.peek(), icol, my columnHeaders [icol]. label);
			}
			for (long icol = labelColumn + 1; icol <= my numberOfColumns; icol ++) {
				TableOfReal_setColumnLabel (thee.peek(), icol - 1, my columnHeaders [icol]. label);
			}
			for (long irow = 1; irow <= my rows -> size; irow ++) {
				TableRow row = static_cast <TableRow> (my rows -> item [irow]);
				wchar_t *string = row -> cells [labelColumn]. string;
				TableOfReal_setRowLabel (thee.peek(), irow, string ? string : L"");
				for (long icol = 1; icol < labelColumn; icol ++) {
					thy data [irow] [icol] = row -> cells [icol]. number;   // Optimization.
					//thy data [irow] [icol] = Table_getNumericValue_Assert (me, irow, icol);
				}
				for (long icol = labelColumn + 1; icol <= my numberOfColumns; icol ++) {
					thy data [irow] [icol - 1] = row -> cells [icol]. number;   // Optimization.
					//thy data [irow] [icol - 1] = Table_getNumericValue_Assert (me, irow, icol);
				}
			}
		} else {
			for (long icol = 1; icol <= my numberOfColumns; icol ++) {
				TableOfReal_setColumnLabel (thee.peek(), icol, my columnHeaders [icol]. label);
			}
			for (long irow = 1; irow <= my rows -> size; irow ++) {
				TableRow row = static_cast <TableRow> (my rows -> item [irow]);
				for (long icol = 1; icol <= my numberOfColumns; icol ++) {
					thy data [irow] [icol] = row -> cells [icol]. number;   // Optimization.
					//thy data [irow] [icol] = Table_getNumericValue_Assert (me, irow, icol);
				}
			}
		}
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, ": not converted to TableOfReal.");
	}
}
TableOfReal TableOfReal_extractColumnsWhere (TableOfReal me, const wchar_t *condition, Interpreter interpreter) {
	try {
		Formula_compile (interpreter, me, condition, kFormula_EXPRESSION_TYPE_NUMERIC, TRUE);
		/*
		 * Count the new number of columns.
		 */
		long numberOfElements = 0;
		for (long icol = 1; icol <= my numberOfColumns; icol ++) {
			for (long irow = 1; irow <= my numberOfRows; irow ++) {
				struct Formula_Result result;
				Formula_run (irow, icol, & result);
				if (result. result.numericResult != 0.0) {
					numberOfElements ++;
					break;
				}
			}
		}
		if (numberOfElements < 1) Melder_throw ("No columns match this condition.");

		/*
		 * Create room for the result.
		 */	
		autoTableOfReal thee = TableOfReal_create (my numberOfRows, numberOfElements);
		copyRowLabels (me, thee.peek());
		/*
		 * Store the result.
		 */
		numberOfElements = 0;
		for (long icol = 1; icol <= my numberOfColumns; icol ++) {
			for (long irow = 1; irow <= my numberOfRows; irow ++) {
				struct Formula_Result result;
				Formula_run (irow, icol, & result);
				if (result. result.numericResult != 0.0) {
					copyColumn (me, icol, thee.peek(), ++ numberOfElements);
					break;
				}
			}
		}
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, ": columns not extracted.");
	}
}
Esempio n. 27
0
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;
}
Esempio n. 28
0
autoTableOfReal Discriminant_extractGroupStandardDeviations (Discriminant me) {
    try {
        long m = my groups->size, n = my eigen -> dimension;
        autoTableOfReal thee = TableOfReal_create (m, n);

        for (long i = 1; i <= m; i ++) {
            SSCP sscp = my groups->at [i];
            TableOfReal_setRowLabel (thee.get(), i, Thing_getName (sscp));
            long numberOfObservationsm1 = (long) floor (sscp -> numberOfObservations) - 1;
            for (long j = 1; j <= n; j ++) {
                thy data [i] [j] = numberOfObservationsm1 > 0 ? sqrt (sscp -> data [j] [j] / numberOfObservationsm1) : NUMundefined;
            }
        }
        NUMstrings_copyElements (my groups->at [m] -> columnLabels, thy columnLabels, 1, n);
        return thee;
    } catch (MelderError) {
        Melder_throw (me, U": group standard deviations not extracted.");
    }
}
TableOfReal TableOfReal_extractRowsWhereLabel (TableOfReal me, int which_Melder_STRING, const wchar_t *criterion) {
	try {
		long n = 0;
		for (long irow = 1; irow <= my numberOfRows; irow ++) {
			if (Melder_stringMatchesCriterion (my rowLabels [irow], which_Melder_STRING, criterion)) {
				n ++;
			}
		}
		if (n == 0)
			Melder_throw (L"No row matches this criterion.");
		autoTableOfReal thee = TableOfReal_create (n, my numberOfColumns);
		copyColumnLabels (me, thee.peek());
		n = 0;
		for (long irow = 1; irow <= my numberOfRows; irow ++)
			if (Melder_stringMatchesCriterion (my rowLabels [irow], which_Melder_STRING, criterion))
				copyRow (me, irow, thee.peek(), ++ n);
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, ": rows not extracted.");
	}
}
Esempio n. 30
0
autoFeatureWeights FeatureWeights_create
(
    ///////////////////////////////
    // Parameters                //
    ///////////////////////////////

    long nweights       // number of weights
)

{
	try {
		autoFeatureWeights me = Thing_new (FeatureWeights);
		my fweights = TableOfReal_create (1, nweights);
		for (long i = 1; i <= nweights; i ++) {
			my fweights -> data [1] [i] = 1;
		}
		return me;
	} catch (MelderError) {
		Melder_throw (U"FeatureWeights not created.");
	}
}