Beispiel #1
0
autoConfusion Confusion_condense (Confusion me, const char32 *search, const char32 *replace,
	long maximumNumberOfReplaces, int use_regexp) {
	try {
		long nmatches, nstringmatches;

		if (my rowLabels == 0 || my columnLabels == 0) {
			Melder_throw (U"No row or column labels.");
		}
		autostring32vector rowLabels (strs_replace (my rowLabels, 1, my numberOfRows, search, replace,
			maximumNumberOfReplaces, &nmatches, &nstringmatches, use_regexp), 1, my numberOfRows);

		autostring32vector columnLabels (strs_replace (my columnLabels, 1, my numberOfColumns,  search, replace,
			 maximumNumberOfReplaces, &nmatches, &nstringmatches, use_regexp), 1, my numberOfColumns);

		autoStrings srow = Thing_new (Strings);
		srow -> numberOfStrings = my numberOfRows;
		srow -> strings = rowLabels.transfer();

		autoStrings scol = Thing_new (Strings);
		scol -> numberOfStrings = my numberOfColumns;
		scol -> strings = columnLabels.transfer();

		/* Find dimension of new Confusion */
		autoDistributions dcol = Strings_to_Distributions (scol.get());
		long nresp = dcol -> numberOfRows;

		autoDistributions drow = Strings_to_Distributions (srow.get());
		long nstim = drow -> numberOfRows;

		autoConfusion thee = Confusion_create (nstim, nresp);

		NUMstrings_copyElements (drow -> rowLabels, thy rowLabels, 1, nstim);
		NUMstrings_copyElements (dcol -> rowLabels, thy columnLabels, 1, nresp);

		autoNUMvector<long> rowIndex (1, my numberOfRows);
		create_index (srow -> strings, 1, my numberOfRows, drow -> rowLabels, 1, nstim, rowIndex.peek());
		autoNUMvector<long> columnIndex (1, my numberOfColumns);
		create_index (scol -> strings, 1, my numberOfColumns, dcol -> rowLabels, 1, nresp, columnIndex.peek());

		for (long i = 1; i <= my numberOfRows; i++) {
			for (long j = 1; j <= my numberOfColumns; j++) {
				thy data [rowIndex [i]][columnIndex[j]] += my data[i][j];
			}
		}
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": not condensed.");
	}
}
Beispiel #2
0
Confusion ClassificationTable_to_Confusion (ClassificationTable me, int onlyClassLabels) {
	try {
		autoStrings responses = TableOfReal_extractColumnLabelsAsStrings (me);
		autoStrings s2 = TableOfReal_extractRowLabelsAsStrings (me);
		autoDistributions d2 = Strings_to_Distributions (s2.peek());
		autoStrings stimuli = TableOfReal_extractRowLabelsAsStrings (d2.peek());
		autoConfusion thee = Confusion_createFromStringses ((onlyClassLabels ? responses.peek() : stimuli.peek()), responses.peek());
		Confusion_and_ClassificationTable_increase (thee.peek(), me);
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, U": confusions cannot be calculated.");
	}
}