Exemplo n.º 1
0
void createSampleGrid(SGPP::base::Grid& grid, size_t l, SGPP::optimization::VectorFunction& f,
                      SGPP::base::DataMatrix& functionValues) {
  SGPP::base::GridStorage& gridStorage = *grid.getStorage();
  const size_t d = f.getNumberOfParameters();
  const size_t m = f.getNumberOfComponents();

  // generate regular sparse grid
  gridStorage.emptyStorage();
  std::unique_ptr<SGPP::base::GridGenerator>(grid.createGridGenerator())->regular(l);
  const size_t n = gridStorage.size();
  SGPP::base::DataVector x(d);
  SGPP::base::DataVector fx(m);

  functionValues.resize(n, m);

  for (size_t i = 0; i < n; i++) {
    SGPP::base::GridIndex& gp = *gridStorage[i];

    // don't forget to set the point distribution to Clenshaw-Curtis
    // if necessary (currently not done automatically)
    if (grid.getType() == SGPP::base::GridType::BsplineClenshawCurtis ||
        grid.getType() == SGPP::base::GridType::ModBsplineClenshawCurtis ||
        grid.getType() == SGPP::base::GridType::LinearClenshawCurtis) {
      gp.setPointDistribution(
        SGPP::base::GridIndex::PointDistribution::ClenshawCurtis);
    }

    for (size_t t = 0; t < d; t++) {
      x[t] = gp.getCoord(t);
    }

    f.eval(x, fx);
    functionValues.setRow(i, fx);
  }
}
Exemplo n.º 2
0
int main(int argc, char** argv) {
  /*    SGPP::base::OCLOperationConfiguration parameters;
   parameters.readFromFile("StreamingOCL.cfg");
   std::cout << "internal precision: " << parameters.get("INTERNAL_PRECISION")
   << std::endl;*/

  //  std::string fileName = "friedman2_90000.arff";
  //    std::string fileName = "debugging.arff";
  std::string fileName = "friedman_4d.arff";
  //  std::string fileName = "friedman_10d.arff";
  //  std::string fileName = "DR5_train.arff";
  //  std::string fileName = "debugging_small.arff";

  uint32_t level = 5;

  SGPP::base::AdpativityConfiguration adaptConfig;
  adaptConfig.maxLevelType_ = false;
  adaptConfig.noPoints_ = 80;
  adaptConfig.numRefinements_ = 0;
  adaptConfig.percent_ = 200.0;
  adaptConfig.threshold_ = 0.0;

  SGPP::base::OCLOperationConfiguration parameters("singleDevice.cfg");

  SGPP::datadriven::OperationMultipleEvalConfiguration configuration(
      SGPP::datadriven::OperationMultipleEvalType::STREAMING,
      SGPP::datadriven::OperationMultipleEvalSubType::OCLMASKMP, parameters);

  SGPP::datadriven::ARFFTools arffTools;
  SGPP::datadriven::Dataset dataset = arffTools.readARFF(fileName);

  SGPP::base::DataMatrix& trainingData = dataset.getData();

  size_t dim = dataset.getDimension();
  //    SGPP::base::Grid* grid = SGPP::base::Grid::createLinearGrid(dim);

  bool modLinear = true;
  SGPP::base::Grid* grid = nullptr;
  if (modLinear) {
    grid = SGPP::base::Grid::createModLinearGrid(dim);
  } else {
    grid = SGPP::base::Grid::createLinearGrid(dim);
  }

  SGPP::base::GridStorage* gridStorage = grid->getStorage();
  std::cout << "dimensionality:        " << gridStorage->dim() << std::endl;

  SGPP::base::GridGenerator* gridGen = grid->createGridGenerator();
  gridGen->regular(level);
  std::cout << "number of grid points: " << gridStorage->size() << std::endl;
  std::cout << "number of data points: " << dataset.getNumberInstances() << std::endl;

  SGPP::base::DataVector alpha(gridStorage->size());

  for (size_t i = 0; i < alpha.getSize(); i++) {
    //    alpha[i] = dist(mt);
    alpha[i] = static_cast<double>(i) + 1.0;
  }

  std::cout << "creating operation with unrefined grid" << std::endl;
  SGPP::base::OperationMultipleEval* eval =
      SGPP::op_factory::createOperationMultipleEval(*grid, trainingData, configuration);

  doAllRefinements(adaptConfig, *grid, *gridGen, alpha);

  std::cout << "number of grid points after refinement: " << gridStorage->size() << std::endl;
  std::cout << "grid set up" << std::endl;

  SGPP::base::DataVector dataSizeVectorResult(dataset.getNumberInstances());
  dataSizeVectorResult.setAll(0);

  std::cout << "preparing operation for refined grid" << std::endl;
  eval->prepare();

  std::cout << "calculating result" << std::endl;

  for (size_t i = 0; i < 1; i++) {
    std::cout << "repeated mult: " << i << std::endl;
    eval->mult(alpha, dataSizeVectorResult);
  }

  std::cout << "duration: " << eval->getDuration() << std::endl;

  //    SGPP::base::DataVector alpha2(gridStorage->size());
  //    alpha2.setAll(0.0);
  //
  //    eval->multTranspose(dataSizeVectorResult, alpha2);

  std::cout << "calculating comparison values..." << std::endl;

  SGPP::base::OperationMultipleEval* evalCompare =
      SGPP::op_factory::createOperationMultipleEval(*grid, trainingData);

  SGPP::base::DataVector dataSizeVectorResultCompare(dataset.getNumberInstances());
  dataSizeVectorResultCompare.setAll(0.0);

  evalCompare->mult(alpha, dataSizeVectorResultCompare);

  double mse = 0.0;

  for (size_t i = 0; i < dataSizeVectorResultCompare.getSize(); i++) {
    mse += (dataSizeVectorResult[i] - dataSizeVectorResultCompare[i]) *
           (dataSizeVectorResult[i] - dataSizeVectorResultCompare[i]);
  }

  mse = mse / static_cast<double>(dataSizeVectorResultCompare.getSize());
  std::cout << "mse: " << mse << std::endl;
}
Exemplo n.º 3
0
	SCSimulation_normal(
		std::string& _nastin_dat, 
		std::string& _solidz_dat, 
		std::string& _run_exec, 
		std::string& _output_data, 
		std::string& _gather_data_exec_sc, 
		std::string& _get_output_sc,
		std::string& _postproc_stat_exec_sc,
		std::string& _output_file_sc, 
		std::string& _coeff_sc,
		std::string& _postproc_stat_sc,
		std::string& _insert_nastin_exec, 
		std::string& _insert_solidz_exec,
		std::string& _gather_alya_output,  
		const unsigned int& _ncoeff, 
		const unsigned int& _prob_dim,
		const unsigned int& _sg_level,
		const double& _rho_f_p1, 
		const double& _rho_f_p2, 
		const double& _nu_f_p1, 
		const double& _nu_f_p2, 
		const double& _rho_s_p1, 
		const double& _rho_s_p2)
	{
		i_ncoeff = _ncoeff;
		i_dim = _prob_dim;
		i_sg_level = _sg_level;

		nastin_dat = _nastin_dat;
		solidz_dat = _solidz_dat;
		run_exec = _run_exec;
		output_data = _output_data;
		gather_data_exec_sc = _gather_data_exec_sc;
		get_output_sc = _get_output_sc;
		postproc_stat_exec_sc = _postproc_stat_exec_sc;
		output_file_sc = _output_file_sc;
		coeff_sc = _coeff_sc;
		postproc_stat_sc = _postproc_stat_sc;
		insert_nastin_exec = _insert_nastin_exec;
		insert_solidz_exec = _insert_solidz_exec;
		gather_alya_output = _gather_alya_output;

		rho_f_p1 = _rho_f_p1;
		rho_f_p2 = _rho_f_p2;
		nu_f_p1 = _nu_f_p1;
		nu_f_p2 = _nu_f_p2;
		rho_s_p1 = _rho_s_p1;
		rho_s_p2 = _rho_s_p2;

		multi_ncoeff = compute_no_coeff();

		for(int i = 0 ; i < i_dim ; ++i)
		{
			l_limits.push_back(-3.0);
			r_limits.push_back(3.0);
		}

		grid = SGPP::base::Grid::createLinearGrid(_prob_dim);
		grid_storage = grid->getStorage(); 
		grid_gen = grid->createGridGenerator();
		grid_gen->regular(_sg_level);

		quad = SGPP::op_factory::createOperationQuadrature(*grid);

		grid_storage_size = grid_storage->size();
	}