コード例 #1
0
ファイル: gauden.c プロジェクト: 10v/cmusphinx
gauden_t *gauden_init (char *meanfile, char *varfile, float32 varfloor)
{
    int32 i, m, f, d, *flen;
    gauden_t *g;
    
    assert (meanfile != NULL);
    assert (varfile != NULL);
    assert (varfloor > 0.0);
    
    g = (gauden_t *) ckd_calloc (1, sizeof(gauden_t));
    g->mean = g->var = NULL;	/* To force them to be allocated */
    
    /* Read means and (diagonal) variances for all mixture gaussians */
    gauden_param_read (&(g->mean), &g->n_mgau, &g->n_feat, &g->n_density, &g->featlen,
		       meanfile);
    gauden_param_read (&(g->var), &m, &f, &d, &flen, varfile);
    
    /* Verify mean and variance parameter dimensions */
    if ((m != g->n_mgau) || (f != g->n_feat) || (d != g->n_density))
	E_FATAL("Mixture-gaussians dimensions for means and variances differ\n");
    for (i = 0; i < g->n_feat; i++)
	if (g->featlen[i] != flen[i])
	    E_FATAL("Feature lengths for means and variances differ\n");
    ckd_free (flen);

    /* Floor variances and precompute variance determinants */
    gauden_dist_precompute (g, varfloor);

    /* Floor for density values */
    min_density = logs3_to_log (LOGPROB_ZERO);
    
    return g;
}
コード例 #2
0
int32
gauden_mllr_transform(gauden_t *g, ps_mllr_t *mllr, cmd_ln_t *config)
{
    int32 i, m, f, d, *flen;
    float32 ****fgau;

    /* Reload means and variances (un-precomputed). */
    fgau = NULL;
    gauden_param_read(&fgau, &g->n_mgau, &g->n_feat, &g->n_density,
                      &g->featlen, cmd_ln_str_r(config, "-mean"));
    g->mean = (mfcc_t ****)fgau;
    fgau = NULL;
    gauden_param_read(&fgau, &m, &f, &d, &flen, cmd_ln_str_r(config, "-var"));
    g->var = (mfcc_t ****)fgau;

    /* Verify mean and variance parameter dimensions */
    if ((m != g->n_mgau) || (f != g->n_feat) || (d != g->n_density))
        E_FATAL
            ("Mixture-gaussians dimensions for means and variances differ\n");
    for (i = 0; i < g->n_feat; i++)
        if (g->featlen[i] != flen[i])
            E_FATAL("Feature lengths for means and variances differ\n");
    ckd_free(flen);

    /* Transform codebook for each stream s */
    for (i = 0; i < g->n_mgau; ++i) {
        for (f = 0; f < g->n_feat; ++f) {
            float64 *temp;
            temp = (float64 *) ckd_calloc(g->featlen[f], sizeof(float64));
            /* Transform each density d in selected codebook */
            for (d = 0; d < g->n_density; d++) {
                int l;
                for (l = 0; l < g->featlen[f]; l++) {
                    temp[l] = 0.0;
                    for (m = 0; m < g->featlen[f]; m++) {
                        /* FIXME: For now, only one class, hence the zeros below. */
                        temp[l] += mllr->A[f][0][l][m] * g->mean[i][f][d][m];
                    }
                    temp[l] += mllr->b[f][0][l];
                }

                for (l = 0; l < g->featlen[f]; l++) {
                    g->mean[i][f][d][l] = (float32) temp[l];
                    g->var[i][f][d][l] *= mllr->h[f][0][l];
                }
            }
            ckd_free(temp);
        }
    }

    /* Re-precompute (if we aren't adapting variances this isn't
     * actually necessary...) */
    gauden_dist_precompute(g, g->lmath, cmd_ln_float32_r(config, "-varfloor"));
    return 0;
}
コード例 #3
0
gauden_t *
gauden_init(char const *meanfile, char const *varfile, float32 varfloor, logmath_t *lmath)
{
    int32 i, m, f, d, *flen;
    float32 ****fgau;
    gauden_t *g;

    assert(meanfile != 0);
    assert(varfile != 0);
    assert(varfloor > 0.0);

    g = (gauden_t *) ckd_calloc(1, sizeof(gauden_t));
    g->lmath = lmath;

    /* Read means and (diagonal) variances for all mixture gaussians */
    fgau = 0;
    gauden_param_read(&fgau, &g->n_mgau, &g->n_feat, &g->n_density,
                      &g->featlen, meanfile);
    g->mean = (mfcc_t ****)fgau;
    fgau = 0;
    gauden_param_read(&fgau, &m, &f, &d, &flen, varfile);
    g->var = (mfcc_t ****)fgau;

    /* Verify mean and variance parameter dimensions */
    if ((m != g->n_mgau) || (f != g->n_feat) || (d != g->n_density))
        E_FATAL
            ("Mixture-gaussians dimensions for means and variances differ\n");
    for (i = 0; i < g->n_feat; i++)
        if (g->featlen[i] != flen[i])
            E_FATAL("Feature lengths for means and variances differ\n");
    ckd_free(flen);

    /* Floor variances and precompute variance determinants */
    gauden_dist_precompute(g, lmath, varfloor);

    return g;
}
コード例 #4
0
ファイル: gauden.c プロジェクト: 10v/cmusphinx
int32 gauden_mean_reload (gauden_t *g, char *meanfile)
{
    int32 i, m, f, d, *flen;
    
    assert (g->mean != NULL);
    
    gauden_param_read (&(g->mean), &m, &f, &d, &flen, meanfile);
    
    /* Verify original and new mean parameter dimensions */
    if ((m != g->n_mgau) || (f != g->n_feat) || (d != g->n_density))
	E_FATAL("Mixture-gaussians dimensions for original and new means differ\n");
    for (i = 0; i < g->n_feat; i++)
	if (g->featlen[i] != flen[i])
	    E_FATAL("Feature lengths for original and new means differ\n");
    ckd_free (flen);

    return 0;
}
コード例 #5
0
ファイル: vq.c プロジェクト: 10v/cmusphinx
/*
 * Read mean and variance S3-format files and cluster them as follows:
 *     assume single feature vector
 *     for each dimension of feature vector {
 *         create list of <mean,var> pairs in the entire codebook set (for that dimension);
 *             // HACK!!  0 vectors omitted from the above list
 *         VQ cluster this list into the given number of vqsize points;
 *         replace codebook entries with nearest clustered values (for that dimension);
 *             // HACK!!  0 vectors remain untouched
 *     }
 *     write remapped codebooks to files "mean-vq" and "var-vq";
 */
main (int32 argc, char *argv[])
{
    float32 ****mean, ****var;
    int32 n_cb, n_feat, n_den, *featlen;
    int32 i, j, c, w, dim, p, n_pt, vqsize;
    float32 **pt, **cb;
    float64 err;
    FILE *fp;

    if ((argc < 4) || (sscanf (argv[3], "%d", &vqsize) != 1))
	E_FATAL("Usage: %s meanfile varfile vqsize\n", argv[0]);
    
    if (argc > 4) {
	if ((fp = fopen(argv[4], "w")) != NULL) {
	    *stdout = *fp;
	    *stderr = *fp;
	} else
	    E_ERROR("fopen(%s,w) failed\n", argv[4]);
    }

    gauden_param_read (&mean, &n_cb, &n_feat, &n_den, &featlen, argv[1]);
    E_INFO("%s: %d x %d x %d ", argv[1], n_cb, n_feat, n_den);
    for (i = 0; i < n_feat; i++)
	printf (" %d", featlen[i]);
    printf ("\n");
    gauden_param_read (&var, &n_cb, &n_feat, &n_den, &featlen, argv[2]);
    E_INFO("%s: %d x %d x %d ", argv[2], n_cb, n_feat, n_den);
    for (i = 0; i < n_feat; i++)
	printf (" %d", featlen[i]);
    printf ("\n");

    assert (n_feat == 1);

    n_pt = n_cb * n_den;
    pt = (float32 **) ckd_calloc_2d (n_pt, 2, sizeof(float32));
    cb = (float32 **) ckd_calloc_2d (vqsize, 2, sizeof(float32));

    tmg = timing_new ();

    /* VQ each column of mean,var pair (assuming just one feature vector) */
    for (dim = 0; dim < featlen[0]; dim++) {
	j = 0;
	for (c = 0; c < n_cb; c++) {
	    for (w = 0; w < n_den; w++) {
		if ((mean[c][0][w][dim] != 0.0) || (var[c][0][w][dim] != 0.0)) {
		    pt[j][0] = mean[c][0][w][dim];
		    pt[j][1] = var[c][0][w][dim];
		    j++;
		}
	    }
	}

	err = vq (pt, cb, j, vqsize, 2);
	vq_dump (cb, vqsize, 2);

	j = 0;
	for (c = 0; c < n_cb; c++) {
	    for (w = 0; w < n_den; w++) {
		if ((mean[c][0][w][dim] != 0.0) || (var[c][0][w][dim] != 0.0)) {
		    mean[c][0][w][dim] = pt[j][0];
		    var[c][0][w][dim] = pt[j][1];
		    j++;
		}
	    }
	}
	E_INFO("%d values quantized for dimension %d; error = %e\n", j, dim, err);
    }
    fflush (fp);

    gauden_param_write (mean, n_cb, n_feat, n_den, featlen, "mean-vq");
    gauden_param_write (var, n_cb, n_feat, n_den, featlen, "var-vq");

    fflush (fp);

    exit(0);
}