当前位置: 首页>>代码示例>>C++>>正文


C++ Mat::load方法代码示例

本文整理汇总了C++中arma::Mat::load方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat::load方法的具体用法?C++ Mat::load怎么用?C++ Mat::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在arma::Mat的用法示例。


在下文中一共展示了Mat::load方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: loadSeries

void MainWindow::loadSeries() {
    QString seriesFile = __fileManager.openFile(0, this, "Open Series File...", "*.mat");

    if (seriesFile != "") {
        cout << "Loading start ..." << flush;
        _data.load(seriesFile.toStdString().c_str());
        cout << " done. " << endl;

        _dataT = arma::trans(_data);
        cout << _data.n_cols << "," << _data.n_rows << endl;

        _imageBuffer.set_size(_mapid.n_rows, _mapid.n_cols);
        for (int i = 0; i < _mapid.n_rows; i++) {
            for (int j = 0; j < _mapid.n_cols; j++) {
                if (_mapid(i,j) != _mapid(i,j)) {
                    _imageBuffer(i,j) = NAN;
                } else {
                    _imageBuffer(i,j) = 0;
                }
            }
        }

        ui.slider->setMaximum(_data.n_cols - 1);

        ui.minValue->setValue(_data.min());
        ui.maxValue->setValue(_data.max());

        _mapItem->setImage(_imageBuffer.memptr(), _imageBuffer.n_rows, _imageBuffer.n_cols);
        _mapItem->setRange(ui.minValue->value(), ui.maxValue->value());
        _mapItem->setInteraction(this);

        selectValue(0);
    }
}
开发者ID:fayhot,项目名称:gradworks,代码行数:34,代码来源:mainwindow.cpp

示例2: connect

MainWindow::MainWindow(QWidget* parent) {
    ui.setupUi(this);
    ui.graphicsView->setScene(&_scene);

    _mapid.load("./MapID.mat");
    cout << _mapid.n_cols << "," << _mapid.n_rows << endl;


    connect(ui.slider, SIGNAL(valueChanged(int)), SLOT(selectValue(int)));
    connect(ui.clearGraphButton, SIGNAL(pressed()), SLOT(clearGraphs()));
    connect(ui.loadSeries, SIGNAL(pressed()), SLOT(loadSeries()));

    _mapItem = new QFloatImageItem();
    _mapItem->setImage(_imageBuffer.memptr(), _imageBuffer.n_rows, _imageBuffer.n_cols);
    _mapItem->setRange(ui.minValue->value(), ui.maxValue->value());
    _mapItem->setInteraction(this);

    _scene.addItem(_mapItem);
    _traceItem = _scene.addPath(_tracePath);


    _traceItem->setPen(QPen(Qt::black));

    QTransform matrix;
    matrix.scale(5, 5);
    ui.graphicsView->setTransform(matrix);

    ui.customPlot->setInteraction(QCustomPlot::iSelectLegend, true);
    ui.customPlot->setInteraction(QCustomPlot::iSelectPlottables, true);
    connect(ui.customPlot, SIGNAL(selectionChangedByUser()), SLOT(graphSelected()));

    _plotMarker = new QGraphicsEllipseItem(_mapItem);
    _plotMarker->setVisible(false);
}
开发者ID:fayhot,项目名称:gradworks,代码行数:34,代码来源:mainwindow.cpp

示例3: getObjectiveValueImplementation

  public:
    using mant::bbob::WeierstrassFunction::WeierstrassFunction;
  
    double getObjectiveValueImplementation(
        const arma::Col<double>& parameter) const override {
      return mant::bbob::WeierstrassFunction::getObjectiveValueImplementation(parameter);
    }
};

TEST_CASE("bbob::WeierstrassFunction") {
  TestWeierstrassFunction weierstrassFunction(40);
    
  SECTION(".getObjectiveValueImplementation") {
    SECTION("Returns the objective value") {
      arma::Mat<double> rotationR;
      REQUIRE(rotationR.load(testDirectory + "/data/optimisationProblem/blackBoxOptimisationBenchmark/_rotationMatrix_40x40_1.input"));
      weierstrassFunction.setRotationR(rotationR);

      arma::Mat<double> rotationQ;
      REQUIRE(rotationQ.load(testDirectory + "/data/optimisationProblem/blackBoxOptimisationBenchmark/_rotationMatrix_40x40_2.input"));
      weierstrassFunction.setRotationQ(rotationQ);

      arma::Mat<double> parameters;
      REQUIRE(parameters.load(testDirectory + "/data/optimisationProblem/blackBoxOptimisationBenchmark/_parameters_40x100.input"));

      arma::Col<double> expectedObjectiveValues;
      REQUIRE(expectedObjectiveValues.load(testDirectory + "/data/optimisationProblem/blackBoxOptimisationBenchmark/bbob_weierstrassFunction_dim40_1x100.expected"));

      for (arma::uword n = 0; n < parameters.n_cols; ++n) {
        CHECK(weierstrassFunction.getObjectiveValueImplementation(parameters.col(n)) == Approx(expectedObjectiveValues(n)));
      }
开发者ID:hnkien,项目名称:Mantella,代码行数:31,代码来源:testWeierstrassFunction.cpp

示例4: optimisationProblem

  // Increases the visibility of the internal objective function, to bypass general modification, made by the parent class.
  using mant::bbob::WeierstrassFunction::objectiveFunction_;
};

SCENARIO("bbob::WeierstrassFunction.objectiveFunction_", "[bbob::WeierstrassFunction][bbob::WeierstrassFunction.objectiveFunction_]") {
  GIVEN("Some parameters") {
    // All expected objective values where generated for a 40-dimensional problem instance.
    const arma::uword numberOfDimensions = 40;
    CAPTURE(numberOfDimensions);
    TestWeierstrassFunction optimisationProblem(numberOfDimensions);

    REQUIRE(optimisationProblem.rotationR_.load(::rootTestDataDirectory + "/optimisationProblem/benchmarkOptimisationProblem/blackBoxOptimisationBenchmark/_rotationMatrix_40x40_1.input"));
    REQUIRE(optimisationProblem.rotationQ_.load(::rootTestDataDirectory + "/optimisationProblem/benchmarkOptimisationProblem/blackBoxOptimisationBenchmark/_rotationMatrix_40x40_2.input"));

    arma::Mat<double> parameters;
    REQUIRE(parameters.load(::rootTestDataDirectory + "/optimisationProblem/benchmarkOptimisationProblem/blackBoxOptimisationBenchmark/_parameters_40x100.input"));

    THEN("Return their objective value") {
      arma::Col<double> expectedObjectiveValues;
      REQUIRE(expectedObjectiveValues.load(::rootTestDataDirectory + "/optimisationProblem/benchmarkOptimisationProblem/blackBoxOptimisationBenchmark/weierstrassFunction_dim40_1x100.expected"));

      for (arma::uword n = 0; n < parameters.n_cols; ++n) {
        CHECK(optimisationProblem.objectiveFunction_(parameters.col(n)) == Approx(expectedObjectiveValues(n)));
      }
    }
  }
}

SCENARIO("bbob::WeierstrassFunction.getNormalisedObjectiveValue", "[bbob::WeierstrassFunction][bbob::WeierstrassFunction.getNormalisedObjectiveValue]") {
  GIVEN("A parameter") {
    const arma::uword numberOfDimensions = SYNCHRONISED(1 + discreteRandomNumber());
开发者ID:xlong88,项目名称:Mantella,代码行数:31,代码来源:testWeierstrassFunction.cpp

示例5: getObjectiveValueImplementation

  public:
    using mant::bbob::DifferentPowersFunction::DifferentPowersFunction;
  
    double getObjectiveValueImplementation(
        const arma::Col<double>& parameter) const override {
      return mant::bbob::DifferentPowersFunction::getObjectiveValueImplementation(parameter);
    }
};

TEST_CASE("bbob::DifferentPowersFunction") {
  TestDifferentPowersFunction differentPowersFunction(40);
    
  SECTION(".getObjectiveValueImplementation") {
    SECTION("Returns the objective value") {
      arma::Mat<double> parameters;
      REQUIRE(parameters.load(testDirectory + "/data/optimisationProblem/blackBoxOptimisationBenchmark/_parameters_40x100.input"));

      arma::Col<double> expectedObjectiveValues;
      REQUIRE(expectedObjectiveValues.load(testDirectory + "/data/optimisationProblem/blackBoxOptimisationBenchmark/bbob_differentPowersFunction_dim40_1x100.expected"));

      for (arma::uword n = 0; n < parameters.n_cols; ++n) {
        CHECK(differentPowersFunction.getObjectiveValueImplementation(parameters.col(n)) == Approx(expectedObjectiveValues(n)));
      }
    }
  }

  SECTION(".toString") {
    SECTION("Returns a (filesystem friendly) name for the class.") {
      CHECK(differentPowersFunction.toString() =="bbob_different_powers_function");
    }
  }
开发者ID:hnkien,项目名称:Mantella,代码行数:31,代码来源:testDifferentPowersFunction.cpp

示例6: Load

bool Load(const std::string& filename,
          arma::Mat<eT>& matrix,
          const bool fatal,
          const bool transpose)
{
  Timer::Start("loading_data");

  // Get the extension.
  std::string extension = Extension(filename);

  // Catch nonexistent files by opening the stream ourselves.
  std::fstream stream;
#ifdef  _WIN32 // Always open in binary mode on Windows.
  stream.open(filename.c_str(), std::fstream::in | std::fstream::binary);
#else
  stream.open(filename.c_str(), std::fstream::in);
#endif
  if (!stream.is_open())
  {
    Timer::Stop("loading_data");
    if (fatal)
      Log::Fatal << "Cannot open file '" << filename << "'. " << std::endl;
    else
      Log::Warn << "Cannot open file '" << filename << "'; load failed."
          << std::endl;

    return false;
  }

  bool unknownType = false;
  arma::file_type loadType;
  std::string stringType;

  if (extension == "csv" || extension == "tsv")
  {
    loadType = arma::diskio::guess_file_type(stream);
    if (loadType == arma::csv_ascii)
    {
      if (extension == "tsv")
        Log::Warn << "'" << filename << "' is comma-separated, not "
            "tab-separated!" << std::endl;
      stringType = "CSV data";
    }
    else if (loadType == arma::raw_ascii) // .csv file can be tsv.
    {
      if (extension == "csv")
      {
        // We should issue a warning, but we don't want to issue the warning if
        // there is only one column in the CSV (since there will be no commas
        // anyway, and it will be detected as arma::raw_ascii).
        const std::streampos pos = stream.tellg();
        std::string line;
        std::getline(stream, line, '\n');
        boost::trim(line);

        // Reset stream position.
        stream.seekg(pos);

        // If there are no spaces or whitespace in the line, then we shouldn't
        // print the warning.
        if ((line.find(' ') != std::string::npos) ||
            (line.find('\t') != std::string::npos))
        {
          Log::Warn << "'" << filename << "' is not a standard csv file."
              << std::endl;
        }
      }
      stringType = "raw ASCII formatted data";
    }
    else
    {
      unknownType = true;
      loadType = arma::raw_binary; // Won't be used; prevent a warning.
      stringType = "";
    }
  }
  else if (extension == "txt")
  {
    // This could be raw ASCII or Armadillo ASCII (ASCII with size header).
    // We'll let Armadillo do its guessing (although we have to check if it is
    // arma_ascii ourselves) and see what we come up with.

    // This is taken from load_auto_detect() in diskio_meat.hpp
    const std::string ARMA_MAT_TXT = "ARMA_MAT_TXT";
    char* rawHeader = new char[ARMA_MAT_TXT.length() + 1];
    std::streampos pos = stream.tellg();

    stream.read(rawHeader, std::streamsize(ARMA_MAT_TXT.length()));
    rawHeader[ARMA_MAT_TXT.length()] = '\0';
    stream.clear();
    stream.seekg(pos); // Reset stream position after peeking.

    if (std::string(rawHeader) == ARMA_MAT_TXT)
    {
      loadType = arma::arma_ascii;
      stringType = "Armadillo ASCII formatted data";
    }
    else // It's not arma_ascii.  Now we let Armadillo guess.
    {
      loadType = arma::diskio::guess_file_type(stream);
//.........这里部分代码省略.........
开发者ID:DeepCV,项目名称:mlpack,代码行数:101,代码来源:load_impl.hpp

示例7: Load

bool Load(const std::string& filename,
          arma::Mat<eT>& matrix,
          bool fatal,
          bool transpose)
{
  Timer::Start("loading_data");

  // First we will try to discriminate by file extension.
  size_t ext = filename.rfind('.');
  if (ext == std::string::npos)
  {
    if (fatal)
      Log::Fatal << "Cannot determine type of file '" << filename << "'; "
          << "no extension is present." << std::endl;
    else
      Log::Warn << "Cannot determine type of file '" << filename << "'; "
          << "no extension is present.  Load failed." << std::endl;

    return false;
  }

  std::string extension = filename.substr(ext + 1);

  // Catch nonexistent files by opening the stream ourselves.
  std::fstream stream;
  stream.open(filename.c_str(), std::fstream::in);

  if (!stream.is_open())
  {
    if (fatal)
      Log::Fatal << "Cannot open file '" << filename << "'. " << std::endl;
    else
      Log::Warn << "Cannot open file '" << filename << "'; load failed."
          << std::endl;

    return false;
  }

  bool unknownType = false;
  arma::file_type loadType;
  std::string stringType;

  if (extension == "csv")
  {
    loadType = arma::csv_ascii;
    stringType = "CSV data";
  }
  else if (extension == "txt")
  {
    // This could be raw ASCII or Armadillo ASCII (ASCII with size header).
    // We'll let Armadillo do its guessing (although we have to check if it is
    // arma_ascii ourselves) and see what we come up with.

    // This is taken from load_auto_detect() in diskio_meat.hpp
    const std::string ARMA_MAT_TXT = "ARMA_MAT_TXT";
    char* rawHeader = new char[ARMA_MAT_TXT.length() + 1];
    std::streampos pos = stream.tellg();

    stream.read(rawHeader, std::streamsize(ARMA_MAT_TXT.length()));
    rawHeader[ARMA_MAT_TXT.length()] = '\0';
    stream.clear();
    stream.seekg(pos); // Reset stream position after peeking.

    if (std::string(rawHeader) == ARMA_MAT_TXT)
    {
      loadType = arma::arma_ascii;
      stringType = "Armadillo ASCII formatted data";
    }
    else // It's not arma_ascii.  Now we let Armadillo guess.
    {
      loadType = arma::diskio::guess_file_type(stream);

      if (loadType == arma::raw_ascii) // Raw ASCII (space-separated).
        stringType = "raw ASCII formatted data";
      else if (loadType == arma::csv_ascii) // CSV can be .txt too.
        stringType = "CSV data";
      else // Unknown .txt... we will throw an error.
        unknownType = true;
    }

    delete[] rawHeader;
  }
  else if (extension == "bin")
  {
    // This could be raw binary or Armadillo binary (binary with header).  We
    // will check to see if it is Armadillo binary.
    const std::string ARMA_MAT_BIN = "ARMA_MAT_BIN";
    char *rawHeader = new char[ARMA_MAT_BIN.length() + 1];

    std::streampos pos = stream.tellg();

    stream.read(rawHeader, std::streamsize(ARMA_MAT_BIN.length()));
    rawHeader[ARMA_MAT_BIN.length()] = '\0';
    stream.clear();
    stream.seekg(pos); // Reset stream position after peeking.

    if (std::string(rawHeader) == ARMA_MAT_BIN)
    {
      stringType = "Armadillo binary formatted data";
      loadType = arma::arma_binary;
//.........这里部分代码省略.........
开发者ID:alexeyche,项目名称:alexeyche-junk,代码行数:101,代码来源:load_impl.hpp


注:本文中的arma::Mat::load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。