コード例 #1
0
ファイル: pgmtexture.c プロジェクト: gguillotte/netpbm-code
static float
f14_maxcorr (float **     const p,
             unsigned int const ng) {
    /*----------------------------------------------------------------------------
      The Maximal Correlation Coefficient
    -----------------------------------------------------------------------------*/
    unsigned int i;
    float *px, *py;
    float ** q;
    float * x;
    float * iy;
    float tmp;

    px = vector(0, ng);
    py = vector(0, ng);
    q = matrix(1, ng + 1, 1, ng + 1);
    x = vector(1, ng);
    iy = vector(1, ng);

    /*
     * px[i] is the (i-1)th entry in the marginal probability matrix obtained
     * by summing the rows of p[i][j]
     */
    for (i = 0; i < ng; ++i) {
        unsigned int j;
        for (j = 0; j < ng; ++j) {
            px[i] += p[i][j];
            py[j] += p[i][j];
        }
    }

    /* Compute the Q matrix */
    for (i = 0; i < ng; ++i) {
        unsigned int j;
        for (j = 0; j < ng; ++j) {
            unsigned int k;
            q[i + 1][j + 1] = 0;
            for (k = 0; k < ng; ++k)
                q[i + 1][j + 1] += p[i][k] * p[j][k] / px[i] / py[k];
        }
    }

    /* Balance the matrix */
    mkbalanced(q, ng);
    /* Reduction to Hessenberg Form */
    reduction(q, ng);
    /* Finding eigenvalue for nonsymetric matrix using QR algorithm */
    hessenberg(q, ng, x, iy);
    if (sortit)
        simplesrt(ng, x);

    /* Return the sqrt of the second largest eigenvalue of q */
    for (i = 2, tmp = x[1]; i <= ng; ++i)
        tmp = (tmp > x[i]) ? tmp : x[i];

    return sqrt(x[ng - 1]);
}
コード例 #2
0
ファイル: CVIPtexture.c プロジェクト: JasonTam/cat-vs-dog
/* Returns the Maximal Correlation Coefficient */
double f14_maxcorr (double **P, int Ng) {
	int i, j, k;
	double *px, *py, **Q;
	double *x, *iy, tmp;
	double f;
	
	px = allocate_vector (0, Ng);
	py = allocate_vector (0, Ng);
	Q = allocate_matrix (1, Ng + 1, 1, Ng + 1);
	x = allocate_vector (1, Ng);
	iy = allocate_vector (1, Ng);
	
	/*
	* px[i] is the (i-1)th entry in the marginal probability matrix obtained
	* by summing the rows of p[i][j]
	*/
	for (i = 0; i < Ng; ++i) {
		for (j = 0; j < Ng; ++j) {
			px[i] += P[i][j];
			py[j] += P[i][j];
		}
	}
	
	/* Find the Q matrix */
	for (i = 0; i < Ng; ++i) {
		for (j = 0; j < Ng; ++j) {
			Q[i + 1][j + 1] = 0;
			for (k = 0; k < Ng; ++k)
				Q[i + 1][j + 1] += P[i][k] * P[j][k] / px[i] / py[k];
		}
	}
	
	/* Balance the matrix */
	mkbalanced (Q, Ng);
	/* Reduction to Hessenberg Form */
	reduction (Q, Ng);
	/* Finding eigenvalue for nonsymetric matrix using QR algorithm */
	if (!hessenberg (Q, Ng, x, iy)) { 
		/* Memmory cleanup */
		for (i=1; i<=Ng+1; i++) free(Q[i]+1);
		free(Q+1);
		free((char *)px);
		free((char *)py);
		free((x+1));
		free((iy+1));
		
		/* computation failed ! */
		return 0.0;
	}
	
	/* simplesrt(Ng,x); */
	/* Returns the sqrt of the second largest eigenvalue of Q */
	for (i = 2, tmp = x[1]; i <= Ng; ++i)
		tmp = (tmp > x[i]) ? tmp : x[i];
	
	f = sqrt(x[Ng - 1]);
	
	for (i=1; i<=Ng+1; i++) free(Q[i]+1);
	free(Q+1);
	free((char *)px); 
	free((char *)py); 
	free((x+1)); 
	free((iy+1)); 
	
	return f;
}