示例#1
0
/* Draws a histogram with N bars where N = dym_rows(freqs)
   Each bar is compartmented into K subbars, on top of each other, where
   K = dym_cols(freqs) and the j'th subcomponent of the i'th bar has
   height = dym_ref(freqs,i,j) and is on top of the j-1'th subcomponent. 
   The i'th bar is centered on x=xlo + (i+0.5) * (xhi - xlo) / num_bars */
void ongr_plot_hist(frame *fr,ongr *on,dym *freqs,bool ratio)
{
  int i;
  int num_bars = dym_rows(freqs);
  int num_classes = dym_cols(freqs);
  double xlo = on -> x_axis.lo;
  double xhi = on -> x_axis.hi;
  double bar_width = 0.9 * (xhi - xlo) / num_bars;

  for ( i = 0 ; i < num_bars ; i++ )
  {
    double xmid = xlo + (i + 0.5) * (xhi - xlo) / num_bars;
    double x1 = xmid - bar_width/2;
    double x2 = xmid + bar_width/2;
    int j;
    double sumy = 0.0;
    double total_sum_y = real_max(1e-5,dym_sum_row(freqs,i));

    for ( j = 0 ; j < num_classes ; j++ )
    {
      double y1 = sumy;
      double dy = dym_ref(freqs,i,j) / ((ratio) ? (total_sum_y/100.0) : 1.0);
      double y2 = sumy + dy;
      int amut_col = color_code_to_ag_color(j);
      ongr_colored_bordered_rectangle(fr,on,x1,y1,x2,y2,amut_col);
      sumy = y2;
    }
  }
}
示例#2
0
/* Makes a dym consisting of a subset of the rows in x. The members of
   of the subset are those rows mentioned in "rows".
   Result will this have "ivec_size(rows)" rows and dym_cols(x) columns */
dym *mk_dym_from_subset_of_rows(dym *x,ivec *rows)
{
  int num_rows = ivec_size(rows);
  int i;
  dym *result = mk_dym(num_rows,dym_cols(x));

  for ( i = 0 ; i < num_rows ; i++ )
  {
    int row = ivec_ref(rows,i);
    dyv *vec = mk_dyv_from_dym_row(x,row);
    copy_dyv_to_dym_row(vec,result,i);
    free_dyv(vec);
  }
  return result;
}
示例#3
0
lr_train *mk_lr_train_from_dym( dym *factors, dyv *outputs, lr_options *opts)
{
  /* Set rows to NULL if you want all rows from ds to be used. */

  int numrows, numatts;
  lr_train *lrt;

  numrows = dym_rows( factors);
  numatts = dym_cols( factors)+1; /* Number of factors including constant. */

  /* Create lr lrt structure. */
  lrt = AM_MALLOC(lr_train);

  /* Copy in opts. */
  lrt->opts = mk_copy_lr_options( opts);

  /* Assign factors and outputs into lr structure. */
  lrt->X = NULL;
  lrt->M = factors;

  /* Outputs. */
  lrt->y = mk_copy_dyv( outputs);
  if (!dyv_is_binary( outputs)) {
    my_error( "mk_lr_train: Error: outputs are not binary.\n");
  }

  /* Set log likelihood of saturated model. */
  lrt->likesat = 0.0;

  /* Initialize remainder of lr struct */
  lrt->numatts = numatts;
  lrt->numrows = numrows;

  /* Create lr_state member. */
  lrt->lrs = mk_lr_state( lrt, opts);

  /* Now that the structure is complete, update n and u to prepare for
     iterations. */
  lr_train_update_n(lrt);
  lr_train_update_u(lrt);

  return lrt;
}