Exemplo n.º 1
0
/* MCMC Var-Cov tuning matrix */
st_mcmc_update *initMCMCUpdate(char *dir)
{
  st_mcmc_update *mcmc_update;

  dir = addInputPath(dir);
  char *tuning_file = createPath(dir, "tuning.csv");
  gsl_matrix *tuning = readMatrix(tuning_file);

  char *fixed_file = createPath(dir, "fixed.csv");
  gsl_vector *fixed = readVector(fixed_file);

  if(tuning->size1 != tuning->size2 || tuning->size1 != fixed->size) {
    printf("Error in initMCMCUpdate\n");
    exit(GSL_FAILURE);
  }
  gsl_vector *z = gsl_vector_alloc(fixed->size);

  mcmc_update = (st_mcmc_update *) malloc(sizeof(st_mcmc_update));
  mcmc_update->tuning = tuning;
  mcmc_update->fixed=fixed;
  mcmc_update->z = z;
  mcmc_update->always_accept = 1;

  int i;
  for(i=0; i<fixed->size; i++) 
    mcmc_update->always_accept *= (int) VGET(mcmc_update->fixed, i);

  return(mcmc_update);
}
Exemplo n.º 2
0
st_data * initData(st_model_at *model_at, char *dir)
{
  dir = addInputPath(dir);
  int i,j;
  int line_length = 80;
    
  double old_tstep = 0.0;
  FILE* f;  
  char *pch;

  char line[line_length];
  st_data *current_data,  *root_data;
  char *experiment_file= createPath(dir, "full.csv");
   
  root_data = (st_data *) malloc(sizeof(st_data));
  root_data->obser = (double *) malloc(sizeof(double));
  root_data->next = NULL;
  current_data = root_data;
  f = fopen(experiment_file, "r");
  if(NULL == f) {
    fprintf(stderr, "Cannot open data file %s\n", experiment_file);
    exit(1);
  }

  i=0;
  j=0;
  while(fgets(line, line_length, f) != NULL){
    j=0;
    if(i>0){
      current_data->next = (st_data *) malloc(sizeof(st_data ));
      current_data = (current_data->next);
      current_data->obser = (double *) malloc(sizeof(double));
    }
    pch = strtok(line,",");
       
    while (pch != NULL ) {
      if(j == 0) {
        current_data->tstep = atof(pch) - old_tstep;
        old_tstep = atof(pch);
      } else {
        current_data->obser = (double *) realloc(current_data->obser, (j*sizeof(double)));
        current_data->obser[j-1] = atof(pch);
      }
      pch = strtok(NULL, ",");
      j++;
    }
    i++;
    current_data->next  = NULL;
        
  }
  current_data = root_data;
  model_at -> no_obs_sps = (j-1);/*minus 1 for time*/
  model_at -> no_obs = i;
   
  return(root_data);

}
Exemplo n.º 3
0
/* Public initialisations functions */
st_parts_at * initPrior(char* dir)
{
  dir = addInputPath(dir);
  st_parts_at *prior_parts;
  char *residual_file= createPath(dir, "residuals.csv");
  char *species_prior_file= createPath(dir, "species_prior.csv");

  prior_parts = (st_parts_at *) malloc(sizeof(st_part_at));
  prior_parts->sps = readMatrix(species_prior_file);
  prior_parts->res = readMatrix(residual_file);
    
  return(prior_parts);
}    
Exemplo n.º 4
0
st_part_at *initPart(st_parts_at *prior_parts, char *dir)
{
  dir = addInputPath(dir);
  st_part_at *part;
  char *parameter_file = createPath(dir, "parameters_prior.csv");

  part = (st_part_at *) malloc(sizeof(st_part_at));
  part->params = readVector(parameter_file);
  part->sps = gsl_vector_alloc(prior_parts->sps->size2);
  part->res = gsl_vector_alloc(prior_parts->res->size2);
  part->like = -100000000.0;/*Set low log likelihood*/
    
  return(part);
}
Exemplo n.º 5
0
int Tool::run(const std::deque<std::string> &args) {
	_arguments = args;

	// Pop the first argument (name of ourselves)
	_arguments.pop_front();

	// Check for help
	if (_arguments.empty() || _arguments.front() == "-h" || _arguments.front() == "--help") {
		print(getHelp());
		return 2;
	}

	// Check for version
	if (_arguments.front() == "--version") {
		print(getVersion());
		return 2;
	}

	// Read standard arguments
	parseAudioArguments();
	parseOutputArguments();
	// Read tool specific arguments
	parseExtraArguments();

	if (!_arguments.empty() && _arguments.front()[0] == '-') {
		std::string s = "Possibly ignored option " + _arguments.front() + ".";
		print(s);
	}

	// Make sure we have enough input files.
	if (_arguments.size() < _inputPaths.size()) {
		print("Too few input files!");
		return -2;
	}

	// Read input files from CLI and match them to expected input.
	// First make sure the all the input paths are unset 
	clearInputPaths();
	// Then match the remaining arguments with the input paths.
	int nbExpectedInputs = _inputPaths.size();
	for (int i = 0 ; i < nbExpectedInputs ; ++i) {
		std::string in = _arguments.front();
		_arguments.pop_front();
		if (!addInputPath(in)) {
			print("Unexpected input file '%s'!", in.c_str());
			return -2;
		}
	}

	// We should have parsed all arguments by now
	if (!_arguments.empty()) {
		std::ostringstream os;
		os << "Too many inputs files ( ";
		while (!_arguments.empty()) {
			os << "'" << _arguments.front() << "' ";
			_arguments.pop_front();
		}
		os << ")";
		print(os.str());
		return -2;
	}

	if (_inputPaths.empty()) {
		// Display help text if we got no input
		print(_helptext);
		return 2;
	}

	// Run the tool, with error handling
	try {
		run();
	} catch(ToolException &err) {
		const char *what = err.what();
		print("Fatal Error : %s", what);
		return err._retcode;
	}
	return 0;
}