<commit_before>//#include <ros/ros.h>
#include <fstream>
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <list>
#include <Eigen/Dense>
#include <sys/time.h>
#include <cmath>
#include <random>

using namespace std;

typedef Eigen::Vector2d V2d;

//function declarations
double computeAccuracy(vector<int> labels1, vector<int> labels2, map<int, int> matchings);
void birthDeathMotionProcesses(vector<V2d>& clusterCenters, vector<bool>& aliveClusters, double birthProbability, double deathProbability, double motionStdDev);
void generateData(vector<V2d> clusterCenters, vector<bool> aliveClusters, int nDataPerClusterPerStep, double likelihoodstd, vector<V2d>& clusterData, vector<int>& trueLabels);

//random number generator
mt19937 rng;//uses the same seed every time, 5489u


class VectorGraph{
	public:
		std::vector<V2d> data, oldprms;
		std::vector<int> oldprmlbls;
		VectorGraph(){
			data.clear();
			oldprms.clear();
			oldprmlbls.clear();
		}
		void updateData(std::vector<V2d> data){
			this->data = data;
		}
		void updateOldParameters(std::vector<V2d> data, std::vector<int> lbls, std::vector<double> gammas, std::vector<int> prmlbls){
			std::vector<V2d> updatedoldprms;
			for (int i = 0; i < prmlbls.size(); i++){
				//if there is no data assigned to this cluster, must be old/uninstantiated
				if (find(lbls.begin(), lbls.end(), prmlbls[i]) == lbls.end()){
					int oldidx = distance(oldprmlbls.begin(), find(oldprmlbls.begin(), oldprmlbls.end(), prmlbls[i]));
					updatedoldprms.push_back(oldprms[oldidx]);
				//if the label is not in oldprmlbls, must be a new cluster
				//furthermore, must have at least one label in lbls = prmlbls[i]
				} else if (find(oldprmlbls.begin(), oldprmlbls.end(), prmlbls[i]) == oldprmlbls.end()) {
					V2d tmpprm = V2d::Zero();
					int tmpcnt = 0;
					for (int j =0 ; j < lbls.size(); j++){
						if (lbls[j] == prmlbls[i]){
							tmpprm += data[j];
							tmpcnt++;
						}
					}
					tmpprm /= tmpcnt;
					updatedoldprms.push_back(tmpprm);
				//old instantiated cluster
				} else {
					int oldidx = distance(oldprmlbls.begin(), find(oldprmlbls.begin(), oldprmlbls.end(), prmlbls[i]));
					V2d tmpprm = gammas[i]*oldprms[oldidx];
					int tmpcnt = 0;
					for (int j =0 ; j < lbls.size(); j++){
						if (lbls[j] == prmlbls[i]){
							tmpprm += data[j];
							tmpcnt++;
						}
					}
					tmpprm /= (gammas[i]+tmpcnt);
					updatedoldprms.push_back(tmpprm);
				}
			}
			this->oldprms = updatedoldprms;
			this->oldprmlbls = prmlbls;
		}
		double diagSelfSimDD(const int i) const{
			return data[i].transpose()*data[i];
		}
		double offDiagSelfSimDD(const int i) const{
			return 0;
		}
		double selfSimPP(const int i) const{
			return oldprms[i].transpose()*oldprms[i];
		}
		double simDD(const int i, const int j) const{
			return data[i].transpose()*data[j];
		}
		double simDP(const int i, const int j) const{
			return data[i].transpose()*oldprms[j];
		}
		int getNodeCt(const int i) const{
			return 1;
		}
		int getNNodes() const {
			return data.size();
		}
		int getNOldPrms() const {
			return oldprms.size();
		}
};

#include <dynmeans/kerndynmeans.hpp>
#include "maxmatching.hpp"



int main(int argc, char** argv){

	//generates clusters that jump around on the domain R^2
	//they move stochastically with a normal distribution w/ std deviation 0.05
	//they die stochastically with probability 0.05 at each step
	//a cluster is created stochastically with probability 0.10 at each step in the area [0,1]x[0,1]
	
	//note: when computing accuracy, ***proper tracking is taken into account***
	//i.e. if true label 1 is matched to learned label 3, then that matching is fixed from that point forward
	//later pairings that attempt to match true label 1 to something else
	//or learned label 3 to something else are discarded
	

	//constants
	//play with these to change the data generation process
	double birthProbability = 0.10;
	double deathProbability = 0.05;
	double motionStdDev = 0.05;
	double clusterStdDev = 0.05;
	int nDataPerClusterPerStep = 10; // datapoints generated for each cluster per timestep
	int nSteps = 100;//run the experiment for nSteps steps
	int initialClusters = 4; //the number of clusters to start with

	
	//data structures for the cluster centers
	vector<V2d> clusterCenters;
	vector<bool> aliveClusters;

	//start with some number of initial clusters
	uniform_real_distribution<double> uniformDist01(0, 1);
	for (int i = 0; i < initialClusters; i++){
			V2d newCenter;
			newCenter(0) = uniformDist01(rng);
			newCenter(1) = uniformDist01(rng);
			clusterCenters.push_back(newCenter);
			aliveClusters.push_back(true);
	}

	//the Dynamic Means object
	//play with lambda/Q/tau to change Dynamic Means' performance
	double lambda = 0.05;
	double T_Q = 6.8;
	double K_tau = 1.01;
	double Q = lambda/T_Q;
	double tau = (T_Q*(K_tau-1.0)+1.0)/(T_Q-1.0);
	int nRestarts = 10;
	int nCoarsest = 10;
	KernDynMeans<VectorGraph> kdm(lambda, Q, tau, true);
	VectorGraph vgr;

	//run the experiment
	double cumulativeAccuracy = 0;//stores the accuracy accumulated for each step
	map<int, int> matchings;//stores the saved matchings from previous timesteps
							//enables proper label tracking (see note at line 27)
	for (int i = 0; i < nSteps; i++){
		//----------------------------
		//birth/death/motion processes<commit_msg>just messing around with mainkdm<commit_after>//#include <ros/ros.h>
#include <fstream>
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <list>
#include <Eigen/Dense>
#include <sys/time.h>
#include <cmath>
#include <random>

using namespace std;

typedef Eigen::Vector2d V2d;

//function declarations
double computeAccuracy(vector<int> labels1, vector<int> labels2, map<int, int> matchings);
void birthDeathMotionProcesses(vector<V2d>& clusterCenters, vector<bool>& aliveClusters, double birthProbability, double deathProbability, double motionStdDev);
void generateData(vector<V2d> clusterCenters, vector<bool> aliveClusters, int nDataPerClusterPerStep, double likelihoodstd, vector<V2d>& clusterData, vector<int>& trueLabels);

//random number generator
mt19937 rng;//uses the same seed every time, 5489u


class VectorGraph{
	public:
		std::vector<V2d> data, oldprms;
		std::vector<int> oldprmlbls;
		VectorGraph(){
			data.clear();
			oldprms.clear();
			oldprmlbls.clear();
		}
		void updateData(std::vector<V2d> data){
			this->data = data;
		}
		void updateOldParameters(std::vector<V2d> data, std::vector<int> lbls, std::vector<double> gammas, std::vector<int> prmlbls){
			std::vector<V2d> updatedoldprms;
			for (int i = 0; i < prmlbls.size(); i++){
				//if there is no data assigned to this cluster, must be old/uninstantiated
				if (find(lbls.begin(), lbls.end(), prmlbls[i]) == lbls.end()){
					int oldidx = distance(oldprmlbls.begin(), find(oldprmlbls.begin(), oldprmlbls.end(), prmlbls[i]));
					updatedoldprms.push_back(oldprms[oldidx]);
				//if the label is not in oldprmlbls, must be a new cluster
				//furthermore, must have at least one label in lbls = prmlbls[i]
				} else if (find(oldprmlbls.begin(), oldprmlbls.end(), prmlbls[i]) == oldprmlbls.end()) {
					V2d tmpprm = V2d::Zero();
					int tmpcnt = 0;
					for (int j =0 ; j < lbls.size(); j++){
						if (lbls[j] == prmlbls[i]){
							tmpprm += data[j];
							tmpcnt++;
						}
					}
					tmpprm /= tmpcnt;
					updatedoldprms.push_back(tmpprm);
				//old instantiated cluster
				} else {
					int oldidx = distance(oldprmlbls.begin(), find(oldprmlbls.begin(), oldprmlbls.end(), prmlbls[i]));
					V2d tmpprm = gammas[i]*oldprms[oldidx];
					int tmpcnt = 0;
					for (int j =0 ; j < lbls.size(); j++){
						if (lbls[j] == prmlbls[i]){
							tmpprm += data[j];
							tmpcnt++;
						}
					}
					tmpprm /= (gammas[i]+tmpcnt);
					updatedoldprms.push_back(tmpprm);
				}
			}
			this->oldprms = updatedoldprms;
			this->oldprmlbls = prmlbls;
		}
		double diagSelfSimDD(const int i) const{
			return data[i].transpose()*data[i];
		}
		double offDiagSelfSimDD(const int i) const{
			return 0;
		}
		double selfSimPP(const int i) const{
			return oldprms[i].transpose()*oldprms[i];
		}
		double simDD(const int i, const int j) const{
			return data[i].transpose()*data[j];
		}
		double simDP(const int i, const int j) const{
			return data[i].transpose()*oldprms[j];
		}
		int getNodeCt(const int i) const{
			return 1;
		}
		int getNNodes() const {
			return data.size();
		}
		int getNOldPrms() const {
			return oldprms.size();
		}
};

#include <dynmeans/kerndynmeans.hpp>
#include "maxmatching.hpp"



int main(int argc, char** argv){

	//generates clusters that jump around on the domain R^2
	//they move stochastically with a normal distribution w/ std deviation 0.05
	//they die stochastically with probability 0.05 at each step
	//a cluster is created stochastically with probability 0.10 at each step in the area [0,1]x[0,1]
	
	//note: when computing accuracy, ***proper tracking is taken into account***
	//i.e. if true label 1 is matched to learned label 3, then that matching is fixed from that point forward
	//later pairings that attempt to match true label 1 to something else
	//or learned label 3 to something else are discarded
	

	//constants
	//play with these to change the data generation process
	double birthProbability = 0.10;
	double deathProbability = 0.05;
	double motionStdDev = 0.05;
	double clusterStdDev = 0.05;
	int nDataPerClusterPerStep = 15; // datapoints generated for each cluster per timestep
	int nSteps = 100;//run the experiment for nSteps steps
	int initialClusters = 4; //the number of clusters to start with

	
	//data structures for the cluster centers
	vector<V2d> clusterCenters;
	vector<bool> aliveClusters;

	//start with some number of initial clusters
	uniform_real_distribution<double> uniformDist01(0, 1);
	for (int i = 0; i < initialClusters; i++){
			V2d newCenter;
			newCenter(0) = uniformDist01(rng);
			newCenter(1) = uniformDist01(rng);
			clusterCenters.push_back(newCenter);
			aliveClusters.push_back(true);
	}

	//the Dynamic Means object
	//play with lambda/Q/tau to change Dynamic Means' performance
	double lambda = 0.05;
	double T_Q = 6.8;
	double K_tau = 1.01;
	double Q = lambda/T_Q;
	double tau = (T_Q*(K_tau-1.0)+1.0)/(T_Q-1.0);
	int nRestarts = 10;
	int nCoarsest = 50;
	KernDynMeans<VectorGraph> kdm(lambda, Q, tau, false);
	VectorGraph vgr;

	//run the experiment
	double cumulativeAccuracy = 0;//stores the accuracy accumulated for each step
	map<int, int> matchings;//stores the saved matchings from previous timesteps
							//enables proper label tracking (see note at line 27)
	for (int i = 0; i < nSteps; i++){
		//----------------------------
		//birth/death/motion processes
{'fraction_non_alphanumeric': 0.13198440690551327, 'fraction_numerical': 0.018748839799517355, 'mean_word_length': 3.799554565701559, 'pattern_counts': {'":': 0, '<': 83, '<?xml version=': 0, '>': 79, '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': '614448', 'n_tokens_mistral': 4368, 'n_tokens_neox': 3767, 'n_words': 1095}