void LPC_Frames_and_Sound_huber (LPC_Frame me, Sound thee, LPC_Frame him, struct huber_struct *hs) {
	long p = my nCoefficients > his nCoefficients ? his nCoefficients : my nCoefficients;
	long n = hs -> e -> nx > thy nx ? thy nx : hs -> e -> nx;
	double *e = hs -> e -> z[1], *s = thy z[1];

	hs -> iter = 0;
	hs -> scale = 1e38;
	hs -> p = p;

	double s0;
	do {
		Sound hse = hs -> e;
		for (long i = 1; i <= thy nx; i++) {
			hse -> z[1][i] = thy z[1][i];
		}
		LPC_Frame_and_Sound_filterInverse (him, hse, 1);

		s0 = hs -> scale;

		NUMstatistics_huber (e, n, & (hs -> location), hs -> wantlocation, & (hs -> scale), hs -> wantscale,
		                     hs -> k, hs -> tol, hs -> work);

		huber_struct_getWeights (hs, e);
		huber_struct_getWeightedCovars (hs, s);

		// Solve C a = [-] c */
		try {
			huber_struct_solvelpc (hs);
		} catch (MelderError) {
			// Copy the starting lpc coeffs */
			for (long i = 1; i <= p; i++) {
				his a[i] = my a[i];
			}
			throw MelderError();
		}
		for (long i = 1; i <= p; i++) {
			his a[i] = hs -> a[i];
		}

		(hs -> iter) ++;
	} while ( (hs -> iter < hs -> itermax) && (fabs (s0 - hs -> scale) > hs -> tol * s0));
}
Exemplo n.º 2
0
void * NUMmatrix (long elementSize, long row1, long row2, long col1, long col2) {
	try {
		int64 numberOfRows = row2 - row1 + 1;
		int64 numberOfColumns = col2 - col1 + 1;
		int64 numberOfCells = numberOfRows * numberOfColumns;

		/*
		 * Allocate room for the row pointers.
		 */
		char **result;
		Melder_assert (sizeof (char) == 1);   // true by definition
		for (;;) {
			result = reinterpret_cast <char **> (_Melder_malloc_f (numberOfRows * sizeof (char *)));   // assume that all pointers have the same size
			result -= row1;
			if (result) break;   // this will normally succeed at the first try
			(void) Melder_realloc_f (result + row1, 1);   // make "sure" that the second try will succeed
		}
		/*
		 * Allocate room for the cells.
		 * The first row pointer points to below the first cell.
		 */
		for (;;) {
			try {
				result [row1] = reinterpret_cast <char *> (_Melder_calloc (numberOfCells, elementSize));
			} catch (MelderError) {
				result += row1;
				Melder_free (result);   // free the row pointers
				throw MelderError ();
			}
			if ((result [row1] -= col1 * elementSize) != nullptr) break;   // this will normally succeed at the first try
			(void) Melder_realloc_f (result [row1] + col1 * elementSize, 1);   // make "sure" that the second try will succeed
		}
		int64 columnSize = numberOfColumns * elementSize;
		for (long irow = row1 + 1; irow <= row2; irow ++) result [irow] = result [irow - 1] + columnSize;
		theTotalNumberOfArrays += 1;
		return result;
	} catch (MelderError) {
		Melder_throw (U"Matrix of elements not created.");
	}
}