void structContingencyTable :: v_info () {
	structData :: v_info ();

	long ndf;
	double h, hx, hy, hygx, hxgy, uygx, uxgy, uxy, chisq;
	ContingencyTable_entropies (this, &h, &hx, &hy, &hygx, &hxgy, &uygx, &uxgy, &uxy);
	ContingencyTable_chisq (this, &chisq, &ndf);

	Melder_information (L"Number of rows: ", Melder_integer (numberOfRows));
	Melder_information (L"Number of columns: ", Melder_integer (numberOfColumns));
	Melder_information (L"Entropies (y is row variable):");
	Melder_information (L"  Total: ", Melder_double (h));
	Melder_information (L"  Y: ", Melder_double (hy));
	Melder_information (L"  X: ", Melder_double (hx));
	Melder_information (L"  Y given x: ", Melder_double (hygx));
	Melder_information (L"  X given y: ", Melder_double (hxgy));
	Melder_information (L"  Dependency of y on x: ", Melder_double (uygx));
	Melder_information (L"  Dependency of x on y: ", Melder_double (uxgy));
	Melder_information (L"  Symmetrical dependency: ", Melder_double (uxy));
	Melder_information (L"  Chi squared: ", Melder_double (chisq));
	Melder_information (L"  Degrees of freedom: ", Melder_integer (ndf));
	Melder_information (L"  Probability: ", Melder_double (ContingencyTable_chisqProbability (this)));
}
Esempio n. 2
0
autoMatrix Spectrum_unwrap (Spectrum me) {
	try {
		struct tribolet_struct tbs;
		int remove_linear_part = 1;

		long nfft = 2;
		while (nfft < my nx - 1) {
			nfft *= 2;
		}
		nfft *= 2;

		if (nfft / 2 != my nx - 1) {
			Melder_throw (U"Dimension of Spectrum is not (power of 2 - 1).");
		}

		autoSound x = Spectrum_to_Sound (me);
		autoSound nx = Data_copy (x.get());

		for (long i = 1; i <= x -> nx; i++) {
			nx -> z[1][i] *= (i - 1);
		}
		autoSpectrum snx = Sound_to_Spectrum (nx.get(), 1);
		autoMatrix thee = Matrix_create (my xmin, my xmax, my nx, my dx, my x1, 1, 2, 2, 1, 1);

		// Common variables.

		tbs.thlinc = THLINC;
		tbs.thlcon = THLCON;
		tbs.x = x -> z[1];
		tbs.nx = x -> nx;
		tbs.l = (long) floor (pow (2, EXP2) + 0.1);
		tbs.ddf = NUM2pi / ( (tbs.l) * nfft);
		tbs.reverse_sign = my z[1][1] < 0;
		tbs.count = 0;

		// Reuse snx : put phase derivative (d/df) in imaginary part.

		tbs.dvtmn2 = 0;
		for (long i = 1; i <= my nx; i ++) {
			double xr = my z[1][i], xi = my z[2][i];
			double nxr = snx -> z[1][i], nxi = snx -> z[2][i];
			double xmsq = xr * xr + xi * xi;
			double pdvt = PHADVT (xr, xi, nxr, nxi, xmsq);
			thy z[1][i] = xmsq;
			snx -> z[2][i] = pdvt;
			tbs.dvtmn2 += pdvt;
		}

		tbs.dvtmn2 = (2 * tbs.dvtmn2 - snx -> z[2][1] - snx -> z[2][my nx]) / (my nx - 1);

		autoMelderProgress progress (U"Phase unwrapping");

		double pphase = 0, phase = 0;
		double ppdvt = snx -> z[2][1];
		thy z[2][1] = PPVPHA (my z[1][1], my z[2][1], tbs.reverse_sign);
		for (long i = 2; i <= my nx; i ++) {
			double pfreq = NUM2pi * (i - 1) / nfft;
			double pdvt = snx -> z[2][i];
			double ppv = PPVPHA (my z[1][i], my z[2][i], tbs.reverse_sign);
			phase = phase_unwrap (&tbs, pfreq, ppv, pdvt, &pphase, &ppdvt);
			ppdvt = pdvt;
			thy z[2][i] = pphase = phase;
			Melder_progress ( (double) i / my nx, i,
			                   U" unwrapped phases from ", my nx, U".");
		}

		long iphase = (long) floor (phase / NUMpi + 0.1);   // ppgb: better than truncation toward zero

		if (remove_linear_part) {
			phase /= my nx - 1;
			for (long i = 2; i <= my nx; i ++) {
				thy z[2][i] -= phase * (i - 1);
			}
		}
		Melder_information (U"Number of spectral values: ", tbs.count);
		Melder_information (U" iphase = ", iphase);
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": not unwrapped.");
	}
}