<commit_before>#include <cstdlib>
#include <iostream>
#include <opencv/cv.hpp>
#include "Ellipse.h"

static constexpr int MAX_CENTER = 600;

static std::tuple<EllipseGeometry, Eigen::MatrixX2f> generate_problem(size_t n);
static void plot(const Eigen::MatrixX2f& points, const EllipseGeometry& eg1, const EllipseGeometry& eg2);

int main(int argc, char** argv)
{
  using namespace std;
  
  if (argc < 3) {
    cerr << "USAGE: " << argv[0] << " NPOINTS SIGMA" << endl;
    return 1;
  }
  
  size_t npoints = std::atoi(argv[1]);
  float sigma = std::atof(argv[2]);
  
  auto problem = generate_problem(npoints);
  cout << "PROBLEM:"
      << "\nELLIPSE:\n" << get<0>(problem)
      << "\nPOINTS:\n" << get<1>(problem)
      << endl;

  auto conic = fit_solver(get<1>(problem));
  cout << "COEFFICIENTS:\n" << get<0>(conic)
      << "\nOFFSET:\n" << get<1>(conic)
      << endl;
  
  EllipseGeometry ell, cv_ell;
  
  try {
    cv_ell = cv_fit_ellipse(get<1>(problem));
    ell = to_ellipse(conic);
  }
  catch (std::domain_error& e) {
    cout << "FIT FAILED: " << e.what() << endl;
    ell = EllipseGeometry{Eigen::Vector2f(0,0), Eigen::Vector2f(0,0), 0};
  }

  cout << "FIT: " << ell << endl;
  cout << "CV FIT: " << cv_ell << endl;
  
  plot(get<1>(problem), ell, cv_ell);
  
  return 0;
}

// We hard-code many of the parameters.
static std::tuple<EllipseGeometry, Eigen::MatrixX2f> generate_problem(size_t n)
{
  auto g = get_ellipse_generator(MAX_CENTER, 2*M_PI/16, 2, Eigen::Vector2f(40, 500), 0.9);
  Eigen::MatrixX2f ret(n, 2);
  for (size_t i = 0; i < n; ++i)
    ret.row(i) = g();
  return std::make_tuple(g.geometry(), ret);
}<commit_msg>Use sigma from the command line, (was hardcoded to 2).<commit_after>#include <cstdlib>
#include <iostream>
#include <opencv/cv.hpp>
#include "Ellipse.h"

static constexpr int MAX_CENTER = 600;

static std::tuple<EllipseGeometry, Eigen::MatrixX2f> generate_problem(size_t n, float sigma);
static void plot(const Eigen::MatrixX2f& points, const EllipseGeometry& eg1, const EllipseGeometry& eg2);

int main(int argc, char** argv)
{
  using namespace std;
  
  if (argc < 3) {
    cerr << "USAGE: " << argv[0] << " NPOINTS SIGMA" << endl;
    return 1;
  }
  
  size_t npoints = std::atoi(argv[1]);
  float sigma = std::atof(argv[2]);
  
  auto problem = generate_problem(npoints, sigma);
  cout << "PROBLEM:"
      << "\nELLIPSE:\n" << get<0>(problem)
      << "\nPOINTS:\n" << get<1>(problem)
      << endl;

  auto conic = fit_solver(get<1>(problem));
  cout << "COEFFICIENTS:\n" << get<0>(conic)
      << "\nOFFSET:\n" << get<1>(conic)
      << endl;
  
  EllipseGeometry ell, cv_ell;
  
  try {
    cv_ell = cv_fit_ellipse(get<1>(problem));
    ell = to_ellipse(conic);
  }
  catch (std::domain_error& e) {
    cout << "FIT FAILED: " << e.what() << endl;
    ell = EllipseGeometry{Eigen::Vector2f(0,0), Eigen::Vector2f(0,0), 0};
  }

  cout << "FIT: " << ell << endl;
  cout << "CV FIT: " << cv_ell << endl;
  
  plot(get<1>(problem), ell, cv_ell);
  
  return 0;
}

// We hard-code many of the parameters.
static std::tuple<EllipseGeometry, Eigen::MatrixX2f> generate_problem(size_t n, float sigma)
{
  auto g = get_ellipse_generator(MAX_CENTER, 2*M_PI/16, sigma, Eigen::Vector2f(40, 500), 0.9);
  Eigen::MatrixX2f ret(n, 2);
  for (size_t i = 0; i < n; ++i)
    ret.row(i) = g();
  return std::make_tuple(g.geometry(), ret);
}
{'fraction_non_alphanumeric': 0.18136094674556213, 'fraction_numerical': 0.02544378698224852, 'mean_word_length': 3.843839541547278, 'pattern_counts': {'":': 0, '<': 127, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1704040', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1354, 'n_words': 296}