示例#1
0
list<tree>
not_done (list<tree> l) {
  if (is_nil (l)) return l;
  else if (versioning_busy || busy_tree (get_reference (l->item)))
    return not_done (l->next);
  return list<tree> (l->item, not_done (l->next));
}
示例#2
0
list<tree>
get_mirrors (tree ln, string id) {
  if (!is_compound (ln, "link", 4) ||
      ln[0] != "mirror" ||
      !is_compound (ln[2], "id", 1) ||
      !is_atomic (ln[2][0]) ||
      !is_compound (ln[3], "id", 1) ||
      !is_atomic (ln[3][0]))
    return list<tree> ();
  if (ln[2][0] == id) return not_done (get_trees (ln[3][0]->label));
  if (ln[3][0] == id) return not_done (get_trees (ln[2][0]->label));
  return list<tree> ();
}
示例#3
0
文件: hex.c 项目: mrahn/hex
static uint8_t winner_from (PPosition_type pos, PState_DFS state, int f)
{
  prepare_state (state, f);

  int mi = (pos->player == L) ? X(f) : Y(f);
  int ma = (pos->player == L) ? X(f) : Y(f);

  while (not_done (state))
  {
    int const px = pop (state);
    int const py = pop (state);

#define DO(dx, dy)                                                      \
    if (  (px + dx) >= 0 && (px + dx) <= SIZE                           \
       && (py + dy) >= 0 && (py + dy) <= SIZE                           \
       && pos->taken[LIN ((px + dx), (py + dy))] == pos->player         \
       )                                                                \
    {                                                                   \
      if (not_seen (state, px + dx, py + dy))                           \
      {                                                                 \
        mi = MIN (mi, (pos->player == L) ? (px + dx) : (py + dy));      \
        ma = MAX (ma, (pos->player == L) ? (px + dx) : (py + dy));      \
                                                                        \
        if (mi == 0 && ma == SIZE)                                      \
        {                                                               \
          return pos->player;                                           \
        }                                                               \
                                                                        \
        push (state, px + dx, py + dy);                                 \
      }                                                                 \
    }                                                                   \

    DO ( 0, 1);
    DO ( 1, 1);
    DO ( 1, 0);
    DO ( 0,-1);
    DO (-1,-1);
    DO (-1, 0);

#undef DO
  }

  return N;
}
int
inc_densities(float32 ***new_mixw,
	      vector_t ***new_mean,
	      vector_t ***new_var,
	      vector_t ****new_fullvar,

	      float32 ***mixw,
	      vector_t ***mean,
	      vector_t ***var,
	      vector_t ****fullvar,
	      float32 ***dnom,
	      
	      uint32 n_mixw,
	      uint32 n_mgau,
	      uint32 n_dnom,
	      uint32 n_feat,
	      uint32 n_density,
	      const uint32 *veclen,

	      uint32 n_inc)
{
    uint32 i, j, k, l, r;
    uint32 **did;
    float32 max_wt;
    uint32 max_wt_idx;
    float32 std;

    assert(n_mgau <= n_mixw);
    
    if (n_mgau < n_mixw) {
	E_FATAL("Splitting of the tied mixture gaussians is not yet implemented\n");
    }

    /* copy old parameters into new arrays */
    for (i = 0; i < n_mgau; i++) {
	for (j = 0; j < n_feat; j++) {
	    for (k = 0; k < n_density; k++) {
		memcpy(new_mean[i][j][k], mean[i][j][k], veclen[j]*sizeof(float32));
		if (fullvar)
		    memcpy(new_fullvar[i][j][k][0], fullvar[i][j][k][0],
			   veclen[j]*veclen[j]*sizeof(float32));
		else
		    memcpy(new_var[i][j][k], var[i][j][k], veclen[j]*sizeof(float32));
		new_mixw[i][j][k] = mixw[i][j][k];
	    }
	}
    }

    /* Over all mixtures:
     * 	- Find the largest unsplit component density.
     *		- Split it into two components where the new component
     *			mixw_a = mixw_b = 1/2 mixw
     *			mean_a = mean + 0.2 std
     *			mean_b = mean - 0.2 std
     *			var_a = var_b = var
     *
     * New parameters are placed beginning at index n_density
     */

    did = (uint32 **)ckd_calloc_2d(n_feat, n_inc, sizeof(uint32));

    for (i = 0; i < n_mgau; i++) {
	printf("%u:", i);
	fflush(stdout);
	
	for (r = 0; r < n_inc; r++) {
	    for (j = 0; j < n_feat; j++) {
		did[j][r] = n_density;

		/* find the density w/ the largest EM count not yet split (i.e. most probable, most occurances) */
		for (k = 0, max_wt = -1.0, max_wt_idx = n_density; k < n_density; k++) {
		    if ((max_wt < dnom[i][j][k]) && not_done(k, did[j], r)) {
			max_wt = dnom[i][j][k];
			max_wt_idx = k;
		    }
		}

		if ( dnom[i][j][max_wt_idx] < MIN_IEEE_NORM_POS_FLOAT32 ) {
		    E_WARN("(mgau= %u, feat= %u, density= %u) never observed skipping\n",
			   i, j, k);

		    new_mixw[i][j][n_density+r] = 0;

		    if (fullvar)
			memcpy(new_fullvar[i][j][n_density+r][0], fullvar[i][j][0][0],
			       veclen[j]*veclen[j]*sizeof(float32));
		    else 
			memcpy(new_var[i][j][n_density+r], var[i][j][0],
			       veclen[j]*sizeof(float32));

		    memcpy(new_mean[i][j][n_density+r], mean[i][j][0],
			   veclen[j]*sizeof(float32));

		    continue;
		}

		/* mixing weight of prior and new densities == 1/2 prior mixing weight */
		new_mixw[i][j][max_wt_idx] /= 2;
		new_mixw[i][j][n_density+r] = new_mixw[i][j][max_wt_idx];

		/* Keep variance of new class same as old */
		if (fullvar)
		    memcpy(new_fullvar[i][j][n_density+r][0], fullvar[i][j][max_wt_idx][0],
			   veclen[j]*veclen[j]*sizeof(float32));
		else
		    memcpy(new_var[i][j][n_density+r], var[i][j][max_wt_idx],
			   veclen[j]*sizeof(float32));

		/* mean_a = mean + 0.2 std */
		/* mean_b = mean - 0.2 std */
		for (l = 0; l < veclen[j]; l++) {
		    /* Use the stddev of mean[l] itself for full covariances. */
		    if (fullvar)
			std = (float32)sqrt(fullvar[i][j][max_wt_idx][l][l]);
		    else
			std = (float32)sqrt(var[i][j][max_wt_idx][l]);
		    
		    new_mean[i][j][max_wt_idx][l] = mean[i][j][max_wt_idx][l] + 0.2f * std;
		    new_mean[i][j][n_density+r][l]  = mean[i][j][max_wt_idx][l] - 0.2f * std;
		}

		did[j][r] = max_wt_idx;
		printf("%u(%.2e)", did[j][r], max_wt);
		fflush(stdout);
	    }
	}
	printf("\n");
    }
	    

    return S3_SUCCESS;
}