int main(int argc, char** argv) {
  QApplication app(argc, argv);
  std::vector<Eigen::Matrix<double, 2, 1> > data;
  LinearRegression<2> dist;
  for (double x = -10; x < 10; x += 0.01) {
    dist.setBasis((Eigen::Matrix<double, 1, 1>() << x).finished());
    data.push_back(dist.getSample());
  }
  ScatterPlot<2> plot("LinearRegressionRndScatterPlot1v", data);
  plot.show();
  return app.exec();
}
int main(int argc, char** argv) {
  QApplication app(argc, argv);
  std::vector<Eigen::Matrix<double, 3, 1> > data;
  LinearRegression<3> dist;
  for (double x = -10; x < 10; x += 0.1)
    for (double y = -10; y < 10; y += 0.1) {
      dist.setBasis(Eigen::Matrix<double, 2, 1>(x, y));
      data.push_back(dist.getSample());
     }
  ScatterPlot<3> plot("LinearRegressionRndScatterPlot2v", data);
  plot.show();
  return app.exec();
}
Exemplo n.º 3
0
int main(int argc, char** argv) {
  LinearRegression<2> linearRegression;
  std::cout << "Default parameters: " << std::endl << linearRegression
    << std::endl;
  std::cout << "l.getLinearBasisFunction(): " << std::endl <<
    linearRegression.getLinearBasisFunction() << std::endl;
  std::cout << "l.getVariance(): " << linearRegression.getVariance()
    << std::endl;
  std::cout <<  "l.setLinearBasisFunction(2.0, 2.0)" << std::endl;
  std::cout << "l.setVariance(2.0)" << std::endl;
  std::cout << "l.setBasis(2.0)" << std::endl;
  linearRegression.setLinearBasisFunction(LinearBasisFunction<double, 2>(
    Eigen::Matrix<double, 2, 1>(2.0, 2.0)));
  linearRegression.setVariance(2.0);
  linearRegression.setBasis((Eigen::Matrix<double, 1, 1>() << 2.0).finished());
  if (linearRegression.getLinearBasisFunction().getCoefficients() !=
    Eigen::Matrix<double, 2, 1>(2.0, 2.0))
    return 1;
  if (linearRegression.getVariance() != 2.0)
    return 1;
  if (linearRegression.getBasis() !=
      (Eigen::Matrix<double, 1, 1>() << 2.0).finished())
    return 1;
  std::cout << "New parameters: " << std::endl << linearRegression
    << std::endl;
  std::cout << "l.getValue(2): " << linearRegression(
    Eigen::Matrix<double, 2, 1>(2, 6)) << std::endl;
  std::cout << "l.getSample(): " << std::endl << linearRegression.getSample()
    << std::endl;
  std::cout << "l.getMean(): " << linearRegression.getMean() << std::endl;

  LinearRegression<2> linCopy(linearRegression);
  std::cout << "Copy constructor: " << std::endl << linCopy << std::endl
    << std::endl;
  if (linCopy.getLinearBasisFunction().getCoefficients() !=
      linearRegression.getLinearBasisFunction().getCoefficients())
    return 1;
  if (linCopy.getVariance() != linearRegression.getVariance())
    return 1;
  LinearRegression<2> linAssign = linearRegression;
  std::cout << "Assignment operator: " << std::endl << linAssign << std::endl;
  if (linAssign.getLinearBasisFunction().getCoefficients() !=
      linearRegression.getLinearBasisFunction().getCoefficients())
    return 1;
  if (linAssign.getVariance() != linearRegression.getVariance())
    return 1;

  return 0;
}