Exemple #1
0
/**
 * restore_model() - construct an SVM "MODEL" structure from the given
 * MEX structure.
 */
MODEL *restore_model(const mxArray *mxStruct )
{
  char strPtr[KPARM_CUSTOM_LEN],*buff;
  long words, doc; 
  mxArray *kstruct,*kstring,*svec;
  MODEL *model = NULL;
  KERNEL_PARM *kparm;
  int buflen;

  model = (MODEL *)my_malloc(sizeof(MODEL)); 

  model->sv_num = (long) restoreValue(mxStruct,"sv_num");
  model->at_upper_bound = (long) restoreValue(mxStruct,"upper_bound");
  model->b = restoreValue(mxStruct,"b");
  model->totwords = (long) restoreValue(mxStruct, "totwords");
  model->totdoc = (long) restoreValue(mxStruct, "totdoc");
  model->loo_error = restoreValue(mxStruct, "loo_error");
  model->loo_recall = restoreValue(mxStruct, "loo_recall");
  model->xa_error = restoreValue(mxStruct, "xa_error");
  model->xa_recall = restoreValue(mxStruct, "xa_recall");
  model->xa_precision = restoreValue(mxStruct, "xa_precision");
  model->maxdiff = restoreValue(mxStruct, "maxdiff");
  model->r_delta_sq = restoreValue(mxStruct, "r_delta_sq");
  model->r_delta_avg = restoreValue(mxStruct, "r_delta_avg");
  model->model_length = restoreValue(mxStruct, "model_length");
  model->loss = restoreValue(mxStruct, "loss");
  model->vcdim = restoreValue(mxStruct, "vcdim");
  model->alpha = restoreArray(mxStruct, "alpha");
  model->lin_weights = restoreArray(mxStruct, "lin_weights");
  model->index = restoreArrayLong(mxStruct, "index");

  kstruct = mxGetField(mxStruct, 0, "kernel_parm"); 
  kparm = &(model->kernel_parm);
  kparm->kernel_type = (long) restoreValue(kstruct,"kernel_type"); 
  kparm->poly_degree = (long) restoreValue(kstruct,"poly_degree"); 
  kparm->rbf_gamma = (double) restoreValue(kstruct,"rbf_gamma"); 
  kparm->coef_lin = (double) restoreValue(kstruct,"coef_lin"); 
  kparm->coef_const = (double) restoreValue(kstruct,"coef_const"); 

  kstring = mxGetField(kstruct,0,"custom");
  buflen = (mxGetM(kstring) * mxGetN(kstring) * sizeof(mxChar)) + 2;
  buff = my_malloc(buflen);
  mxGetString(kstring,buff, buflen);

  strcpy((*kparm).custom, buff);
  my_free(buff);

  /*  if (model->supvec != NULL) { */
  svec = mxGetField(mxStruct,0,"supvec");
  if (svec == NULL) {
    printf("Warning: supvec field was not found.");
  }
  else {
    mexToDOC(svec, NULL, &model->supvec, NULL, NULL, NULL); 
  }

  return model;
}
Exemple #2
0
void PETScVector::copyValues(std::vector<double>& u) const
{
    assert(u.size() == (std::size_t) (getLocalSize() + getGhostSize()));

    double* loc_x = getLocalVector();
    std::copy_n(loc_x, getLocalSize() + getGhostSize(), u.begin());
    restoreArray(loc_x);
}
Exemple #3
0
/**
 * restoreValue() - return a the given double value from the mxStructure
 * from field named name.
 */
double restoreValue(const mxArray *mxStruct, char *name)
{
  double *array = restoreArray(mxStruct,name);
  if (array == NULL) 
    mexErrMsgTxt("Error: restoreArray returned NULL array to restoreValue");

  return array[0];
}