Пример #1
0
/* Expects a 2 column matrix with the X and Y coefficients for each var */
USER_OBJECT_
RS_GGOBI(setTourProjection)(USER_OBJECT_ s_display, USER_OBJECT_ s_mode_name,
  USER_OBJECT_ matrix)
{
  displayd *display = toDisplay(s_display);
  ProjectionMode mode = GGOBI(getPModeId)(asCString(s_mode_name));
  gint k, n;
  gdouble *x = NULL, *y = NULL;
  
  g_return_val_if_fail(GGOBI_IS_DISPLAY(display), NULL_USER_OBJECT);
  
  RS_INTERNAL_GGOBI(getTourVectorsFromMode)(display, mode, &x, &y);
  g_return_val_if_fail(x != NULL, NULL_USER_OBJECT);
  
  n = display->d->ncols;
  for (k = 0; k < n; k++) {
    x[k] = REAL(matrix)[k];
    if (y)
      y[k] = REAL(matrix)[k+n];
  }
  
  display_tailpipe (display, FULL, display->ggobi);
  varcircles_refresh (display->d, display->ggobi);
  
  return NULL_USER_OBJECT;
}
Пример #2
0
void tour1d_reinit(GGobiSession *gg)
{
  gint i, j;
  displayd *dsp = gg->current_display;
  GGobiStage *d = dsp->d;
  splotd *sp = gg->current_splot;

  for (i=0; i<1; i++) {
    for (j=0; j<d->n_cols; j++) {
      dsp->t1d.Fa.vals[i][j] = 0.;
      dsp->t1d.F.vals[i][j] = 0.;
    }
    dsp->t1d.Fa.vals[i][dsp->t1d.active_vars.els[i]] = 1.;
    dsp->t1d.F.vals[i][dsp->t1d.active_vars.els[i]] = 1.;
  }

  /* Reinits the vertical height for the ashes */
  sp->tour1d.initmax = true;

  dsp->t1d.get_new_target = true;

  display_tailpipe (dsp, FULL, gg);

  varcircles_refresh (d, gg);

  if (dsp->t1d_window != NULL && GTK_WIDGET_VISIBLE (dsp->t1d_window)) 
    t1d_pp_reinit(dsp, gg);
}
Пример #3
0
void tour1d_scramble(GGobiSession *gg)
{
  int i, j;
  displayd *dsp = gg->current_display;
  GGobiStage *d = dsp->d;
  gint nc = d->n_cols;

  for (i=0; i<1; i++)
    for (j=0; j<nc; j++)
      dsp->t1d.Fa.vals[i][j] = dsp->t1d.Fz.vals[i][j] = 
        dsp->t1d.F.vals[i][j] = dsp->t1d.Ga.vals[i][j] = 
        dsp->t1d.Gz.vals[i][j] = 0.0;

  gt_basis(dsp->t1d.Fa, dsp->t1d.nactive, dsp->t1d.active_vars, 
    d->n_cols, (gint) 1);
  arrayd_copy(&dsp->t1d.Fa, &dsp->t1d.F);
  /*  copy_mat(dsp->t1d.F.vals, dsp->t1d.Fa.vals, d->n_cols, 1);*/

  dsp->t1d.get_new_target = true;

  display_tailpipe (dsp, FULL, gg);

  varcircles_refresh (d, gg);

  if (dsp->t1d_window != NULL && GTK_WIDGET_VISIBLE (dsp->t1d_window)) 
    t1d_pp_reinit(dsp, gg);
}
Пример #4
0
void
tour1d_manip(gint p1, gint p2, splotd *sp, GGobiSession *gg) 
{
  displayd *dsp = (displayd *) sp->displayptr;
  GGobiStage *d = dsp->d;
  cpaneld *cpanel = &dsp->cpanel;
  gdouble xcosphi=1., xsinphi=0.;
  gdouble distx, disty;
  gdouble denom = MIN(sp->max.x, sp->max.y)/2.;
  gint actual_nxvars = dsp->t1d.nactive;
  gint j;
  gboolean offscreen = false;
  gboolean pp_problem = false;

  /* check if off the plot window */
  if (p1 > sp->max.x || p1 < 0 ||
      p2 > sp->max.y || p2 <0)
    offscreen = true;

  if (dsp->t1d_manipvar_inc)
    actual_nxvars = dsp->t1d.nactive-1;

  if (!offscreen) {
    dsp->t1d_pos_old = dsp->t1d_pos;
  
    dsp->t1d_pos = p1;

    if (actual_nxvars > 0)
    {
      if (cpanel->t1d.vert)
      {
        distx = 0.;
        disty = dsp->tc2_pos_old - dsp->tc2_pos;
      }
      else
      {
        distx = dsp->t1d_pos - dsp->t1d_pos_old;
        disty = 0.;
      }

      dsp->t1d_phi = dsp->t1d_phi + distx / denom;
  
      xcosphi = (gdouble) cos((gdouble) dsp->t1d_phi);
      xsinphi = (gdouble) sin((gdouble) dsp->t1d_phi);
      if (xcosphi > 1.0)
      {
        xcosphi = 1.0;
        xsinphi = 0.0;
      }
      else if (xcosphi < -1.0)
      {
        xcosphi = -1.0;
        xsinphi = 0.0;
      }
    }

    /* generate the projection basis */
    if (actual_nxvars > 0) 
    {
      for (j=0; j<d->n_cols; j++)
        dsp->t1d.F.vals[0][j] = xcosphi * dsp->t1d_manbasis.vals[0][j] + 
         xsinphi * dsp->t1d_manbasis.vals[1][j];
    }
 
    /* plot pp index */
    /*    if (dsp->t1d_ppda != NULL) {*/
    if (dsp->t1d_window != NULL && GTK_WIDGET_VISIBLE (dsp->t1d_window)) {
      dsp->t1d.oppval = dsp->t1d.ppval;
      pp_problem = t1d_switch_index(cpanel->t1d.pp_indx, 
        0, dsp, gg);
      t1d_ppdraw(dsp->t1d.ppval, dsp, gg);
    }

    display_tailpipe (dsp, FULL, gg);
    varcircles_refresh (d, gg);
  }
  else {
    disconnect_motion_signal (sp);
    arrayd_copy(&dsp->t1d.F, &dsp->t1d.Fa);
    /*    copy_mat(dsp->t1d.Fa.vals, dsp->t1d.F.vals, d->n_cols, 1);*/
    dsp->t1d.get_new_target = true;
    if (!cpanel->t1d.paused)
      tour1d_func(T1DON, gg->current_display, gg);
  }
}
Пример #5
0
void
tour1d_run(displayd *dsp, GGobiSession *gg)
{
  GGobiStage *d = dsp->d;
  cpaneld *cpanel = &dsp->cpanel;
  /*  static gint count = 0;*/
  gboolean revert_random = false;
  gint pathprob = 0;
  gint i, nv;
  extern void t1d_ppdraw_think(displayd *, GGobiSession *);

  /* Controls interpolation steps */
  if (!dsp->t1d.get_new_target && 
      !reached_target(dsp->t1d.tang, dsp->t1d.dist_az, 
        dsp->t1d.target_selection_method,&dsp->t1d.ppval, &dsp->t1d.oppval)) {
    increment_tour(dsp->t1d.tinc, dsp->t1d.tau, dsp->t1d.dist_az, 
      dsp->t1d.delta, &dsp->t1d.tang, (gint) 1);
    tour_reproject(dsp->t1d.tinc, dsp->t1d.G, dsp->t1d.Ga, dsp->t1d.Gz,
      dsp->t1d.F, dsp->t1d.Va, d->n_cols, (gint) 1);

    /* plot pp indx */
    if (dsp->t1d_window != NULL && GTK_WIDGET_VISIBLE (dsp->t1d_window)) {
      /*    if (dsp->t1d_ppda != NULL) {*/

      dsp->t1d.oppval = dsp->t1d.ppval;
      revert_random = t1d_switch_index(cpanel->t1d.pp_indx, 
        0, dsp, gg);
      t1d_ppdraw(dsp->t1d.ppval, dsp, gg);
    }

  }
  else { /* we're at the target plane */
    if (dsp->t1d.get_new_target) { /* store the pp parameters */
      if (dsp->t1d.target_selection_method == TOUR_PP)
      {
	/*        dsp->t1d_pp_op.index_best = dsp->t1d.ppval;
        for (j=0; j<dsp->t1d.nactive; j++) 
          dsp->t1d_pp_op.proj_best.vals[0][j] = 
	  dsp->t1d.F.vals[0][dsp->t1d.active_vars.els[j]];*/
      }
    }
    else 
    { /* make sure the ending projection is the same as the target */
      if (dsp->t1d.target_selection_method == TOUR_RANDOM)
      {
        do_last_increment(dsp->t1d.tinc, dsp->t1d.tau, 
          dsp->t1d.dist_az, (gint) 1);
        tour_reproject(dsp->t1d.tinc, dsp->t1d.G, dsp->t1d.Ga, dsp->t1d.Gz,
          dsp->t1d.F, dsp->t1d.Va, d->n_cols, (gint) 1);
      }
    }
    /* now cleanup: store the current basis into the starting basis */
    arrayd_copy(&dsp->t1d.F, &dsp->t1d.Fa);
    nv = 0;
    for (i=0; i<d->n_cols; i++)
      if (fabs(dsp->t1d.Fa.vals[0][i]) > 0.01) {
        nv++;
      }
    if (nv == 1 && dsp->t1d.nactive == 1) /* only generate new dir if num of
                                           active/used variables is > 2 */
      dsp->t1d.get_new_target = true;
    else {
      if (dsp->t1d.target_selection_method == TOUR_RANDOM) {
        gt_basis(dsp->t1d.Fz, dsp->t1d.nactive, dsp->t1d.active_vars, 
          d->n_cols, (gint) 1);
      }
      else if (dsp->t1d.target_selection_method == TOUR_PP) {
        /* pp guided tour  */
        /* get new target according to the selected pp index */
        for (i=0; i<d->n_cols; i++)
          dsp->t1d.Fz.vals[0][i] = 0.0;
        dsp->t1d.Fz.vals[0][dsp->t1d.active_vars.els[0]]=1.0;

        dsp->t1d.oppval = -1.0;
        t1d_ppdraw_think(dsp, gg);
        gdk_flush ();
        revert_random = t1d_switch_index(cpanel->t1d.pp_indx, 
          dsp->t1d.target_selection_method, dsp, gg);

        if (!revert_random) {
          for (i=0; i<dsp->t1d.nactive; i++) {
            if (isfinite((gdouble)dsp->t1d_pp_op.proj_best.vals[0][i]) != 0)
              dsp->t1d.Fz.vals[0][dsp->t1d.active_vars.els[i]] = 
                dsp->t1d_pp_op.proj_best.vals[0][i];
          }
          dsp->t1d_pp_op.index_best = 0.0;
	  /*g_printerr ("tour_run:index_best %f temp %f \n", dsp->t1d_pp_op.index_best, dsp->t1d_pp_op.temp);
g_printerr ("proj: ");
for (i=0; i<dsp->t1d_pp_op.proj_best.ncols; i++) g_printerr ("%f ", dsp->t1d_pp_op.proj_best.vals[0][i]);
g_printerr ("\n");*/

          /* if the best projection is the same as the previous one, switch 
              to a random projection */
/*          if (!checkequiv(dsp->t1d.Fa.vals, dsp->t1d.Fz.vals, d->n_cols, 1)) {
            g_printerr ("Using random projection\n");
            gt_basis(dsp->t1d.Fz, dsp->t1d.nactive, dsp->t1d.active_vars, 
              d->n_cols, (gint) 1);
            for (j=0; j<dsp->t1d.nactive; j++)
              dsp->t1d_pp_op.proj_best.vals[0][j] = 
                dsp->t1d.Fz.vals[0][dsp->t1d.active_vars.els[j]];
            revert_random = t1d_switch_index(cpanel->t1d.pp_indx, 
              dsp->t1d.target_selection_method, dsp, gg);
          }*/
	  /*          t1d_ppdraw(dsp->t1d.ppval, dsp, gg);*/
  /*          count = 0;*/
          ggobi_sleep(0);
        }
        else /* Use random target */
        {
	  /*          gt_basis(dsp->t1d.Fz, dsp->t1d.nactive, dsp->t1d.active_vars, 
            d->n_cols, (gint) 1);
	    g_printerr ("Using random projection 2\n");*/
        }
      }
      pathprob = tour_path(dsp->t1d.Fa, dsp->t1d.Fz, dsp->t1d.F, d->n_cols, 
        (gint) 1, dsp->t1d.Ga, dsp->t1d.Gz, dsp->t1d.G, 
        dsp->t1d.lambda, dsp->t1d.tv, dsp->t1d.Va,
        dsp->t1d.Vz, dsp->t1d.tau, dsp->t1d.tinc, 
        &dsp->t1d.dist_az, &dsp->t1d.tang);
      if (pathprob == 0) 
        dsp->t1d.get_new_target = false;
      else if (pathprob == 1) { /* problems with Fa so need to force a jump */
        tour1d_scramble(gg);
        pathprob = tour_path(dsp->t1d.Fa, dsp->t1d.Fz, dsp->t1d.F, d->n_cols, 
          (gint) 1, dsp->t1d.Ga,
          dsp->t1d.Gz, dsp->t1d.G, dsp->t1d.lambda, dsp->t1d.tv, dsp->t1d.Va,
          dsp->t1d.Vz,  dsp->t1d.tau, dsp->t1d.tinc, 
          &dsp->t1d.dist_az, &dsp->t1d.tang);
      }
      else if (pathprob == 2 || pathprob == 3) { /* problems with Fz,
                                      so will force a new choice of Fz */
        dsp->t1d.get_new_target = true;
      }
    }
  }
 /*  tour_reproject(dsp, 2);*/
#ifdef TESTING_TOUR_STEP
{
  GGobiDisplayClass *klass;
  klass = GGOBI_DISPLAY_GET_CLASS(dsp);
  g_signal_emit(G_OBJECT(dsp),
    klass->signals[TOUR_STEP_SIGNAL], 0, dsp->t1d,
    (gint) 1, gg);
}
#endif

  display_tailpipe (dsp, FULL, gg);

  varcircles_refresh (d, gg);
  if (dsp->t1d_video) tour1d_write_video(gg);
}