<commit_before>// tests expectation maximization of periodic gaussians for correctness

#include <math.h>
#include <vector>
#include <iostream>

#include <EMPeriodicGaussian.h>
#include <MathFunctions.h>

#include "util.h"

using namespace std;
using namespace Terran;

void testUnimodalPeriodicGaussian() {
    vector<double> data;
    vector<Param> initParams(1);
    double period = 2*PI;
    initParams[0].p = 1;
    initParams[0].u = 1.2345;
    initParams[0].s = 1.1;
    for(int i=0; i < 5000; i++) {
        data.push_back(periodicGaussianSample(initParams[0].u,initParams[0].s,period));
    }
    Param p;
    p.p = 1;
    p.u = 1.7;
    p.s = 2.1;
    vector<Param> params;
    params.push_back(p);
    EMPeriodicGaussian em(data, params, period);
    em.run(100, 0.1);
    vector<Param> optimizedParams = em.getParams();
    Util::matchParameters(initParams, optimizedParams, 0.05);
}

void testBimodalPeriodicGaussian() {
    vector<double> data;
    double period = 2*PI;
    vector<Param> initParams(2);
    initParams[0].p = 0.65;
    initParams[0].u = -0.3;
    initParams[0].s = 0.5;
    for(int i=0; i<10000*initParams[0].p; i++) {
        data.push_back(periodicGaussianSample(initParams[0].u,initParams[0].s,period));
    }
    initParams[1].p = 0.35;
    initParams[1].u = 1.9;
    initParams[1].s = 0.5;
    for(int i=0; i<10000*initParams[1].p; i++) {
        data.push_back(periodicGaussianSample(initParams[1].u,initParams[1].s,period));
    }
    
    vector<Param> params;
    {
        Param p;
        p.p = 0.5;
        p.u = -1.0;
        p.s = 0.5;
        params.push_back(p);
    }
    {
        Param p;
        p.p = 0.5;
        p.u = 2.1;
        p.s = 1.4;
        params.push_back(p);
    }
    EMPeriodicGaussian em(data, params, period);
    em.run(100, 0.1);
    vector<Param> optimizedParams = em.getParams();
    Util::plotPeriodicGaussian(initParams, period, "bimodal");
    Util::matchParameters(initParams, optimizedParams, 0.05);
}

#include <fstream>
#include <MethodsPeriodicGaussian.h>
using namespace std;

void testOverfitPeriodicGaussian() {
    vector<double> data;
    double period = 2*PI;
    vector<Param> initParams(2);
    initParams[0].p = 0.65;
    initParams[0].u = -0.3;
    initParams[0].s = 0.5;
    for(int i=0; i<5000*initParams[0].p; i++) {
        data.push_back(periodicGaussianSample(initParams[0].u,initParams[0].s,period));
    }
    initParams[1].p = 0.35;
    initParams[1].u = 1.9;
    initParams[1].s = 0.5;
    for(int i=0; i<5000*initParams[1].p; i++) {
        data.push_back(periodicGaussianSample(initParams[1].u,initParams[1].s,period));
    }
    
    /*
    ofstream d("data.txt");<commit_msg>minor cleanup<commit_after>// tests expectation maximization of periodic gaussians for correctness

#include <math.h>
#include <vector>
#include <iostream>
#include <fstream>

#include <MethodsPeriodicGaussian.h>
#include <EMPeriodicGaussian.h>
#include <MathFunctions.h>

#include "util.h"

using namespace std;
using namespace Terran;

void testUnimodalPeriodicGaussian() {
    vector<double> data;
    vector<Param> initParams(1);
    double period = 2*PI;
    initParams[0].p = 1;
    initParams[0].u = 1.2345;
    initParams[0].s = 1.1;
    for(int i=0; i < 5000; i++) {
        data.push_back(periodicGaussianSample(initParams[0].u,initParams[0].s,period));
    }
    Param p;
    p.p = 1;
    p.u = 1.7;
    p.s = 2.1;
    vector<Param> params;
    params.push_back(p);
    EMPeriodicGaussian em(data, params, period);
    em.run(100, 0.1);
    vector<Param> optimizedParams = em.getParams();
    Util::matchParameters(initParams, optimizedParams, 0.05);
}

void testBimodalPeriodicGaussian() {
    vector<double> data;
    double period = 2*PI;
    vector<Param> initParams(2);
    initParams[0].p = 0.65;
    initParams[0].u = -0.3;
    initParams[0].s = 0.5;
    for(int i=0; i<10000*initParams[0].p; i++) {
        data.push_back(periodicGaussianSample(initParams[0].u,initParams[0].s,period));
    }
    initParams[1].p = 0.35;
    initParams[1].u = 1.9;
    initParams[1].s = 0.5;
    for(int i=0; i<10000*initParams[1].p; i++) {
        data.push_back(periodicGaussianSample(initParams[1].u,initParams[1].s,period));
    }
    
    vector<Param> params;
    {
        Param p;
        p.p = 0.5;
        p.u = -1.0;
        p.s = 0.5;
        params.push_back(p);
    }
    {
        Param p;
        p.p = 0.5;
        p.u = 2.1;
        p.s = 1.4;
        params.push_back(p);
    }
    EMPeriodicGaussian em(data, params, period);
    em.run(100, 0.1);
    vector<Param> optimizedParams = em.getParams();
    Util::plotPeriodicGaussian(initParams, period, "bimodal");
    Util::matchParameters(initParams, optimizedParams, 0.05);
}


void testOverfitPeriodicGaussian() {
    vector<double> data;
    double period = 2*PI;
    vector<Param> initParams(2);
    initParams[0].p = 0.65;
    initParams[0].u = -0.3;
    initParams[0].s = 0.5;
    for(int i=0; i<5000*initParams[0].p; i++) {
        data.push_back(periodicGaussianSample(initParams[0].u,initParams[0].s,period));
    }
    initParams[1].p = 0.35;
    initParams[1].u = 1.9;
    initParams[1].s = 0.5;
    for(int i=0; i<5000*initParams[1].p; i++) {
        data.push_back(periodicGaussianSample(initParams[1].u,initParams[1].s,period));
    }
    
    /*
    ofstream d("data.txt");
{'fraction_non_alphanumeric': 0.16382699868938402, 'fraction_numerical': 0.0490544841789927, 'mean_word_length': 2.9541080680977054, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 37, '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': '797956', 'n_tokens_mistral': 2180, 'n_tokens_neox': 1999, 'n_words': 351}