Beispiel #1
0
//' @title Find the Rank Models result
//' @description Provides the core material to create an S3 object for rank.models
//' @param data A \code{vec} of data.
//' @param model_str A \code{vector<vector<string>>} that gives a list of models to test.
//' @param full_model A \code{vector<string>} that contains the largest / full model.
//' @param alpha A \code{double} that indicates the alpha level for CIs.
//' @param compute_v A \code{string} indicating the type of V matrix to generate
//' @param model_type A \code{string} that describes the model generation / transformation: 'ssm' or 'imu'
//' @param K A \code{int} that controls how many times the GMWM is run. 
//' @param H A \code{int} that controls how many bootstraps occur.
//' @param G A \code{int} that controls how many guesses occur.
//' @param robust A \code{bool} that indicates whether to use classical or robust wavelet variance.
//' @param eff A \code{double} that indicates the efficiency to use.
//' @param bs_optimism A \code{bool} that indicates whether the model selection score should be calculated with bootstrap or asymptotics.
//' @param seed A \code{unsigned int} that is the seed one wishes to use. 
//' @return A \code{field<field<field<mat>>>} that contains the model score matrix and the best GMWM model object.
//' @keywords internal
// [[Rcpp::export]]
arma::field< arma::field<arma::field<arma::mat> > >  rank_models_cpp(arma::vec& data,
                                                                     const std::vector<std::vector < std::string > >& model_str, 
                                                                     const std::vector< std::string >&  full_model,
                                                                     double alpha, 
                                                                     std::string compute_v, std::string model_type, 
                                                                     unsigned int K, unsigned int H, unsigned int G, 
                                                                     bool robust, double eff, bool bs_optimism, unsigned int seed){
  
  
  std::set<std::vector < std::string > > models = vector_to_set(model_str);
  
  arma::field< arma::field<arma::field<arma::mat> > > h(1);
  
  h(0) = model_select(data,
    models,
    full_model,
    model_type,
    bs_optimism,
    alpha,
    compute_v, 
    K, H, G, 
    robust, eff, seed);
  
  return h;
}
Beispiel #2
0
int main()
{
    config_parse_remote_servers("servers.txt");

    trainingdata_t* data = trainingdata_new();

    int t;
    for(t=0;t<256;t++) {
        example_t*e = example_new(16);
        int s;
        for(s=0;s<16;s++) {
            e->inputs[s] = variable_new_continuous((lrand48()%256)/256.0);
        }
        e->desired_response = variable_new_categorical(t%2);
        trainingdata_add_example(data, e);
    }

    trainingdata_save(data, "/tmp/data.data");
    trainingdata_destroy(data);

    data = trainingdata_load("/tmp/data.data");

    model_t*m = model_select(data);

    char*code = model_generate_code(m, "python");
    printf("%s\n", code);
    free(code);

    model_destroy(m);

    trainingdata_destroy(data);
}
Beispiel #3
0
static PyObject* py_dataset_get_model(PyObject*_self, PyObject* args, PyObject* kwargs)
{
    DataSetObject*self = (DataSetObject*)_self;
    static char *kwlist[] = {"name", NULL};
    const char*name = 0;
    if (args && !PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &name))
	return NULL;

    int num_examples = self->data->num_examples;
    if(!num_examples) {
        return PY_ERROR("No training data given. Can't build a model from no data.");
    }
    if(!trainingdata_check_format(self->data)) {
        return PY_ERROR("bad training data");
    }


    model_t*model = NULL;
    if(name == NULL) {
        model = model_select(self->data);
    } else {
        model = model_train_specific_model(self->data, name);
        if(!model)
            return PY_ERROR("unknown model %s", name);
    }

    if(!model)
        return PY_NONE;
    ModelObject*ret = PyObject_New(ModelObject, &ModelClass);
    ret->model = model;
    return (PyObject*)ret;
}
Beispiel #4
0
//' @title Find the auto imu result
//' @description Provides the core material to create an S3 object for auto.imu
//' @param data A \code{mat} containing multiple columns of independent data with the same number of observations.
//' @param model_str A \code{vector<vector<string>>} that gives a list of models to test.
//' @param full_model A \code{vector<string>} that contains the largest / full model.
//' @param alpha A \code{double} that indicates the alpha level for CIs.
//' @param compute_v A \code{string} indicating the type of V matrix to generate
//' @param model_type A \code{string} that describes the model generation / transformation: 'ssm' or 'imu'
//' @param K A \code{int} that controls how many times the GMWM is run. 
//' @param H A \code{int} that controls how many bootstraps occur.
//' @param G A \code{int} that controls how many guesses occur.
//' @param robust A \code{bool} that indicates whether to use classical or robust wavelet variance.
//' @param eff A \code{double} that indicates the efficiency to use.
//' @param bs_optimism A \code{bool} that indicates whether the model selection score should be calculated with bootstrap or asymptotics.
//' @param seed A \code{unsigned int} that is the seed one wishes to use. 
//' @return A \code{field<field<field<mat>>>} that contains the model score matrix and the best GMWM model object.
//' @keywords internal
// [[Rcpp::export]]
arma::field< arma::field<arma::field<arma::mat> > >  auto_imu_cpp(arma::mat& data,
                                                                  const arma::mat& combs,
                                                                  const std::vector< std::string >&  full_model,
                                                                  double alpha, 
                                                                  std::string compute_v, std::string model_type, 
                                                                  unsigned int K, unsigned int H, unsigned int G, 
                                                                  bool robust, double eff, bool bs_optimism, unsigned int seed){
  
  
  
  
  // Number of columns to process
  unsigned int V = data.n_cols;
  
  // Create a set of unique models.
  std::set<std::vector<std::string > > models = build_model_set(combs, full_model);
  
  arma::field< arma::field<arma::field<arma::mat> > > h(V);
  
  for(unsigned int i = 0; i < V; i++){
    Rcpp::Rcout << "Generating models for the " << i + 1 << " column in the data set " << std::endl << std::endl;
    
    arma::vec signal_col = data.col(i);
    
    h(i) = model_select(signal_col,
                        models,
                        full_model,
                        model_type,
                        bs_optimism,
                        alpha,
                        compute_v, 
                        K, H, G, 
                        robust, eff, seed);
    
    Rcpp::Rcout << std::endl;
  }
  
  return h;
}
Beispiel #5
0
void SvmMachine::run( const std::string purpose, Options& options  )
{
	if( purpose == "model-selection" )
	{
		model_select( options );
	}
	else if( purpose == "model-validation" )
	{
		model_validate( options );
	}
	else if( purpose == "prediction" )
	{
		predict( options );
	}
	else//problem. Log and Exit.
	{
		std::string msg;
		msg.append( "Error: Purpose is not valid: " + purpose );
		msg.append( "\nType hivm --help for usage. \nExiting..." );
		Log::append( msg );
		std::cerr << msg;
		return;
	}
}