#include <stdio.h>
#include <ctime>
#include <math.h>
#include <fstream>
#include <string>
#include <iostream>

#include "em_sqdist.h"
#include "em_von_mises.h"
#include "em_elliptic_sqdist.h"
#include "em_tesedist.h"

#include "em_gaussian.h"

#include "logreg.hpp"

using namespace std;

int main(int argc, char **argv) {
  if (argc < 3) {
    cout << "Usage: cem <data file> <clusters>" << endl;
    return 1;
  }

  srandom(time(0));

  string filename(argv[1]);
  int clusters = stoi(string(argv[2]));

	EMVonMises positive(clusters);
  ifstream data_stream(filename);
  ofstream dataset("results/dataset");
  while (!data_stream.eof()) {
    double time;
    data_stream >> time;
    if (data_stream.fail()) {
      break;
    }

    positive.add_time(time);
    dataset << time << " 0" << endl;
  }
  data_stream.close();
  dataset.close();

  positive.train();

  ofstream density("results/density");
  for (double phase = -M_PI; phase < M_PI; phase += 0.001) {
    double d = positive.get_density_at(phase);
    density << phase << " " << d << endl;
  }
  density.close();

  positive.print();

  /*Logreg logreg;
  ifstream data_stream(filename);
  int i = 0;
  while (!data_stream.eof()) {
    double time;
    data_stream >> time;
    if (data_stream.fail()) {
      break;
    }

    logreg.add_measurement(time, i < 40);
    ++i;
  }
  data_stream.close();

  logreg.train();*/

  return 0;
}
