コード例 #1
0
ファイル: Discriminant.cpp プロジェクト: rlaboiss/praat
/*
	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.");
    }
}
コード例 #2
0
ファイル: CCA_and_Correlation.c プロジェクト: alekstorm/tala
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;
}
コード例 #3
0
ファイル: Proximity.c プロジェクト: alekstorm/tala
class_methods_end

int Proximity_init (I, long numberOfPoints)
{
	iam (Proximity);
		
    return TableOfReal_init (me, numberOfPoints, numberOfPoints) &&
		TableOfReal_setSequentialRowLabels (me, 0, 0, NULL, 1, 1) &&
		TableOfReal_setSequentialColumnLabels (me, 0, 0, NULL, 1, 1); 
}
コード例 #4
0
ファイル: Configuration.cpp プロジェクト: motiz88/praat
autoConfiguration Configuration_create (long numberOfPoints, long numberOfDimensions) {
	try {
		autoConfiguration me = Thing_new (Configuration);
		TableOfReal_init (me.peek(), numberOfPoints, numberOfDimensions);
		my w = NUMvector<double> (1, numberOfDimensions);
		TableOfReal_setSequentialRowLabels (me.peek(), 0, 0, nullptr, 1, 1);
		TableOfReal_setSequentialColumnLabels (me.peek(), 0, 0, U"dimension ", 1, 1);

		my metric = 2;
		Configuration_setDefaultWeights (me.peek());
		Configuration_randomize (me.peek());
		return me;
	} catch (MelderError) {
		Melder_throw (U"Configuration not created.");
	}
}