コード例 #1
0
void EditCostsTable_setSubstitutionCosts (EditCostsTable me, wchar_t *targets, wchar_t *sources, double cost) {
	try {
		autoNUMvector<long> targetIndex (1, my numberOfRows);
		autoNUMvector<long> sourceIndex (1, my numberOfRows);
		long ntargets = 0;
		for (wchar_t *token = Melder_firstToken (targets); token != 0; token = Melder_nextToken ()) {
			long index = EditCostsTable_getTargetIndex (me, token);
			if (index > 0) {
				targetIndex[++ntargets] = index;
			}
		}
		if (ntargets == 0 && targets != 0 && targets[1] != '\0') {
			ntargets = 1; targetIndex[1] = my numberOfRows - 1;
		}
		long nsources = 0;
		for (wchar_t *token = Melder_firstToken (sources); token != 0; token = Melder_nextToken ()) {
			long index = EditCostsTable_getSourceIndex (me, token);
			if (index > 0) {
				sourceIndex[++nsources] = index;
			}
		}
		if (nsources == 0 && sources != 0 && sources[1] != '\0') {
			nsources = 1; sourceIndex[1] = my numberOfColumns - 1;
		}
		for (long i = 1; i <= ntargets; i++) {
			long irow = targetIndex[i];
			for (long j = 1; j <= nsources; j++) {
				my data [irow][sourceIndex[j]] = cost;
			}
		}
	} catch (MelderError) {
		Melder_throw (me, ": substitution costs not set.");
	}
}
コード例 #2
0
ファイル: EditDistanceTable.cpp プロジェクト: psibre/praat
void EditCostsTable_setSubstitutionCosts (EditCostsTable me, char32 *targets, char32 *sources, double cost) {
    try {
        autoNUMvector<long> targetIndex (1, my numberOfRows);
        autoNUMvector<long> sourceIndex (1, my numberOfRows);
        long numberOfTargetSymbols = 0;
        for (char32 *token = Melder_firstToken (targets); token != 0; token = Melder_nextToken ()) {
            long index = EditCostsTable_getTargetIndex (me, token);
            if (index > 0) {
                targetIndex[++numberOfTargetSymbols] = index;
            }
        }
        if (numberOfTargetSymbols == 0) {
            targetIndex[++numberOfTargetSymbols] = my numberOfRows - 1;
        }
        long numberOfSourceSymbols = 0;
        for (char32 *token = Melder_firstToken (sources); token != 0; token = Melder_nextToken ()) {
            long index = EditCostsTable_getSourceIndex (me, token);
            if (index > 0) {
                sourceIndex[++numberOfSourceSymbols] = index;
            }
        }
        if (numberOfSourceSymbols == 0) {
            sourceIndex[++numberOfSourceSymbols] = my numberOfColumns - 1;
        }
        for (long i = 1; i <= numberOfTargetSymbols; i++) {
            long irow = targetIndex[i];
            for (long j = 1; j <= numberOfSourceSymbols; j++) {
                my data [irow][sourceIndex[j]] = cost;
            }
        }
    } catch (MelderError) {
        Melder_throw (me, U": substitution costs not set.");
    }
}
コード例 #3
0
ファイル: EditDistanceTable.cpp プロジェクト: psibre/praat
void EditCostsTable_setDeletionCosts (EditCostsTable me, char32 *sources, double cost) {
    for (char32 *token = Melder_firstToken (sources); token != 0; token = Melder_nextToken ()) {
        long icol = EditCostsTable_getSourceIndex (me, token);
        icol = icol > 0 ? icol : my numberOfColumns - 1; // nomatch condition to penultimate column
        my data[my numberOfRows][icol] = cost;
    }
}
コード例 #4
0
ファイル: EditDistanceTable.cpp プロジェクト: psibre/praat
void EditCostsTable_setInsertionCosts (EditCostsTable me, char32 *targets, double cost) {
    for (char32 *token = Melder_firstToken (targets); token != 0; token = Melder_nextToken ()) {
        long irow = EditCostsTable_getTargetIndex (me, token);
        irow = irow > 0 ? irow : my numberOfRows - 1; // nomatch condition to penultimate row
        my data[irow][my numberOfColumns] = cost;
    }
}
コード例 #5
0
ファイル: Confusion.cpp プロジェクト: READSEARCH/praat
autoConfusion Confusion_groupStimuli (Confusion me, const char32 *labels, const char32 *newLabel, long newpos) {
	try {
		long ncondense = Melder_countTokens (labels);
		autoNUMvector<long> irow (1, my numberOfRows);

		for (long i = 1; i <= my numberOfRows; i++) {
			irow[i] = i;
		}

		for (char32 *token = Melder_firstToken (labels); token != nullptr; token = Melder_nextToken ()) {
			for (long i = 1; i <= my numberOfRows; i++) {
				if (Melder_equ (token, my rowLabels[i])) {
					irow[i] = 0;
					break;
				}
			}
		}
		long nfound = 0;
		for (long i = 1; i <= my numberOfRows; i++) {
			if (irow[i] == 0) {
				nfound ++;
			}
		}
		if (nfound == 0) {
			Melder_throw (U"Invalid stimulus labels.");
		}
		if (nfound != ncondense) {
			Melder_warning (U"One or more of the given stimulus labels are suspect.");
		}
		long newnstim = my numberOfRows - nfound + 1;
		if (newpos < 1) {
			newpos = 1;
		}
		if (newpos > newnstim) {
			newpos = newnstim;
		}
		autoConfusion thee = Confusion_create (newnstim, my numberOfColumns);
		NUMstrings_copyElements (my columnLabels, thy columnLabels, 1, my numberOfColumns);

		TableOfReal_setRowLabel (thee.get(), newpos, newLabel);
		long inewrow = 1;
		for (long i = 1; i <= my numberOfRows; i++) {
			long rowpos = newpos;
			if (irow[i] > 0) {
				if (inewrow == newpos) {
					inewrow++;
				}
				rowpos = inewrow;
				inewrow++;
				TableOfReal_setRowLabel (thee.get(), rowpos, my rowLabels[i]);
			}
			for (long j = 1; j <= my numberOfColumns; j++) {
				thy data[rowpos][j] += my data[i][j];
			}
		}
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": stimuli not grouped.");
	}
}
コード例 #6
0
ファイル: Confusion.cpp プロジェクト: READSEARCH/praat
autoConfusion Confusion_groupResponses (Confusion me, const char32 *labels, const char32 *newLabel, long newpos) {
	try {
		long ncondense = Melder_countTokens (labels);
		autoNUMvector<long> icol (1, my numberOfColumns);

		for (long i = 1; i <= my numberOfColumns; i++) {
			icol[i] = i;
		}

		for (char32 *token = Melder_firstToken (labels); token != 0; token = Melder_nextToken ()) {
			for (long i = 1; i <= my numberOfColumns; i++) {
				if (Melder_equ (token, my columnLabels[i])) {
					icol[i] = 0;
					break;
				}
			}
		}
		long nfound = 0;
		for (long i = 1; i <= my numberOfColumns; i++) {
			if (icol[i] == 0) {
				nfound ++;
			}
		}
		if (nfound == 0) {
			Melder_throw (U"Invalid response labels.");
		}
		if (nfound != ncondense) {
			Melder_warning (U"One or more of the given response labels are suspect.");
		}
		long newnresp = my numberOfColumns - nfound + 1;
		if (newpos < 1) {
			newpos = 1;
		}
		if (newpos > newnresp) {
			newpos = newnresp;
		}
		autoConfusion thee = Confusion_create (my numberOfRows, newnresp);
		NUMstrings_copyElements (my rowLabels, thy rowLabels, 1, my numberOfRows);
		TableOfReal_setColumnLabel (thee.get(), newpos, newLabel);
		long inewcol = 1;
		for (long i = 1; i <= my numberOfColumns; i++) {
			long colpos = newpos;
			if (icol[i] > 0) {
				if (inewcol == newpos) {
					inewcol++;
				}
				colpos = inewcol;
				inewcol++;
				TableOfReal_setColumnLabel (thee.get(), colpos, my columnLabels[i]);
			}
			for (long j = 1; j <= my numberOfRows; j++) {
				thy data[j][colpos] += my data[j][i];
			}
		}
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": responses not grouped.");
	}
}
コード例 #7
0
ファイル: NUMstring.cpp プロジェクト: psibre/praat
double *NUMstring_to_numbers (const char32 *s, long *numbers_found) {
	*numbers_found = Melder_countTokens (s);
	if (*numbers_found < 1) {
		Melder_throw (U"Empty string.");
	}
	autoNUMvector<double> numbers (1, *numbers_found);
	long inum = 1;
	for (char32 *token = Melder_firstToken (s); token != 0; token = Melder_nextToken (), inum++) {
		Interpreter_numericExpression (0, token, &numbers[inum]);
	}
	return numbers.transfer();
}
コード例 #8
0
autoStrings Strings_createAsTokens (const char32 *string) {
	try {
		autoStrings me = Thing_new (Strings);
		my numberOfStrings =  Melder_countTokens (string);
		my strings = NUMvector<char32 *> (1, my numberOfStrings);
		long i = 1;
		for (char32 *token = Melder_firstToken (string); token != 0; token = Melder_nextToken ()) {
			my strings[i++] = Melder_dup (token);
		}
		return me;
	} catch (MelderError) {
		Melder_throw (U"Strings from characters not created.");
	}
}
コード例 #9
0
ファイル: Confusion.cpp プロジェクト: READSEARCH/praat
autoConfusion Confusion_createSimple (const char32 *labels) {
	try {
		long numberOfLabels = Melder_countTokens (labels);
		if (numberOfLabels < 1) {
			Melder_throw (U"Not enough labels.");
		}
		autoConfusion me = Confusion_create (numberOfLabels, numberOfLabels);
		long ilabel = 1;
		for (char32 *token = Melder_firstToken (labels); token != 0; token = Melder_nextToken ()) {
			for (long i = 1; i <= ilabel - 1; i++) {
				if (Melder_cmp (token, my rowLabels[i]) == 0) {
					Melder_throw (U"Label ", i, U"and ", ilabel, U"may not be equal.");
				}
			}
			TableOfReal_setRowLabel (me.get(), ilabel, token);
			TableOfReal_setColumnLabel (me.get(), ilabel, token);
			ilabel++;
		}
		return me;
	} catch (MelderError) {
		Melder_throw (U"Simple Confusion not created.");
	}
}
コード例 #10
0
ファイル: ICA.cpp プロジェクト: guilhermegarcia/praat-1
autoCrossCorrelationTable CrossCorrelationTable_createSimple (char32 *covars, char32 *centroid, long numberOfSamples) {
	try {
		long dimension = Melder_countTokens (centroid);
		long ncovars = Melder_countTokens (covars);
		long ncovars_wanted = dimension * (dimension + 1) / 2;
		if (ncovars != ncovars_wanted) Melder_throw (U"The number of matrix elements and the number of "
			        U"centroid elements are not in concordance. There should be \"d(d+1)/2\" matrix values and \"d\" centroid values.");

		autoCrossCorrelationTable me = CrossCorrelationTable_create (dimension);

		// Construct the full matrix from the upper-diagonal elements

		long inum = 1, irow = 1;
		for (char32 *token = Melder_firstToken (covars); token != nullptr && inum <= ncovars_wanted; token = Melder_nextToken (), inum++) {
			double number;
			long nmissing = (irow - 1) * irow / 2;
			long inumc = inum + nmissing;
			irow = (inumc - 1) / dimension + 1;
			long icol = ( (inumc - 1) % dimension) + 1;
			Interpreter_numericExpression (nullptr, token, &number);
			my data[irow][icol] = my data[icol][irow] = number;
			if (icol == dimension) {
				irow++;
			}
		}

		inum = 1;
		for (char32 *token = Melder_firstToken (centroid); token != nullptr && inum <= dimension; token = Melder_nextToken (), inum++) {
			double number;
			Interpreter_numericExpression (nullptr, token, &number);
			my centroid[inum] = number;
		}
		my numberOfObservations = numberOfSamples;
		return me;
	} catch (MelderError) {
		Melder_throw (U"CrossCorrelationTable not created.");
	}
}
コード例 #11
0
ファイル: ICA.cpp プロジェクト: guilhermegarcia/praat-1
autoMixingMatrix MixingMatrix_createSimple (long numberOfChannels, long numberOfComponents, char32 *elements) {
	try {
		long inum = 1, ntokens = Melder_countTokens (elements);
		if (ntokens == 0) {
			Melder_throw (U"No matrix elements.");
		}
		long nwanted = numberOfChannels * numberOfComponents;

		autoMixingMatrix me = MixingMatrix_create (numberOfChannels, numberOfComponents);

		// Construct the full matrix from the elements
		double number;
		for (char32 *token = Melder_firstToken (elements); token != nullptr && inum <= ntokens; token = Melder_nextToken (), inum++) {
			long irow = (inum - 1) / numberOfComponents + 1;
			long icol = (inum - 1) % numberOfComponents + 1;
			Interpreter_numericExpression (0, token, &number);

			my data[irow][icol] = number;
		}
		if (ntokens < nwanted) {
			for (long i = inum; i <= nwanted; i++) {
				long irow = (inum - 1) / numberOfComponents + 1;
				long icol = (inum - 1) % numberOfComponents + 1;
				my data[irow][icol] = number; // repeat the last number given!
			}
		}
		return me;
	} catch (MelderError) {
		Melder_throw (U"MixingMatrix not created.");
	}
}