<commit_before>#include <iostream>
#include "tools.h"

using namespace std;
using Eigen::VectorXd;
using Eigen::MatrixXd;
using std::vector;

Tools::Tools() {}

Tools::~Tools() {}

VectorXd Tools::CalculateRMSE(const vector<VectorXd> &estimations,
                              const vector<VectorXd> &ground_truth) {
	/**
	* 
	*/

	VectorXd rmse(4);
	rmse << 0,0,0,0;

	// check the validity of the following inputs:
	//  * the estimation vector size should not be zero
	//  * the estimation vector size should equal ground truth vector size
	if(estimations.size() != ground_truth.size()
		|| estimations.size() == 0) {
		
		cout << "Invalid estimations or ground truth data" << endl;

		return rmse;
	}

	auto estimations_size = estimations.size();

	// accumlate squared residuals
	for(unsigned int i = 0;  i < estimations_size;  ++i){

		VectorXd residual = estimations[i] - ground_truth[i];

		// coefficient-wise multiplication
		auto residual_array = residual.array();
		residual = residual_array * residual_array;
		rmse += residual;
	}

	// calculate mean
	rmse = rmse / estimations_size;

	// squared root
	rmse = rmse.array().sqrt();

	// returns result
	return rmse;

}


MatrixXd Tools::CalculateJacobian(const VectorXd& x_state) {
	/**
	* 
	*/

	MatrixXd Hj(3, 4);

	// state parameters

	double px = x_state(0);
	double py = x_state(1);

	double vx = x_state(2);
	double vy = x_state(3);

	// for efficiency terms pre-computed here
	double c1 = (px * px) + (py * py);
	double c2 = sqrt(1);
	double c3 = (c1 * c2);
	// end pre-compute

	// division by zero check

	if(fabs(c1) < 0.0001) {
		cout << "CalculateJacobian () - Error - division by Zero" << endl;
		return Hj;
	}

	Hj << (px / c2), (py / c2), 0 , 0,
		  -(py / c1), (px / c1), 0 , 0,
		  py * (vx * py - vy * px) / c3, px * (px * vy - py * vx) / c3, px/c2, py/c2;

		  return Hj;

}<commit_msg>Bug fixes<commit_after>#include <iostream>
#include "tools.h"

using namespace std;
using Eigen::VectorXd;
using Eigen::MatrixXd;
using std::vector;

Tools::Tools() {}

Tools::~Tools() {}

VectorXd Tools::CalculateRMSE(const vector<VectorXd> &estimations,
                              const vector<VectorXd> &ground_truth) {
	/**
	* 
	*/

	VectorXd rmse(4);
	rmse << 0,0,0,0;

	// check the validity of the following inputs:
	//  * the estimation vector size should not be zero
	//  * the estimation vector size should equal ground truth vector size
	if(estimations.size() != ground_truth.size()
		|| estimations.size() == 0) {
		
		cout << "Invalid estimations or ground truth data" << endl;

		return rmse;
	}

	auto estimations_size = estimations.size();

	// accumlate squared residuals
	for(unsigned int i = 0;  i < estimations_size;  ++i){

		VectorXd residual = estimations[i] - ground_truth[i];

		// coefficient-wise multiplication
		auto residual_array = residual.array();
		residual = residual_array * residual_array;
		rmse += residual;
	}

	// calculate mean
	rmse = rmse / estimations_size;

	// squared root
	rmse = rmse.array().sqrt();

	// returns result
	return rmse;

}


MatrixXd Tools::CalculateJacobian(const VectorXd& x_state) {
	/**
	* 
	*/

	MatrixXd Hj(3, 4);

	// state parameters

	double px = x_state(0);
	double py = x_state(1);

	double vx = x_state(2);
	double vy = x_state(3);

	// for efficiency terms pre-computed here
	double c1 = (px * px) + (py * py);

	// division by zero check
	if(fabs(c1) < 0.0001) {
		cout << "CalculateJacobian () - Warning - division by Zero" << endl;
		c1 = 1;
	}

	double c2 = sqrt(c1);
	double c3 = (c1 * c2);
	// end pre-compute


	Hj << (px / c2), (py / c2), 0 , 0,
		  -(py / c1), (px / c1), 0 , 0,
		  py * (vx * py - vy * px) / c3, px * (px * vy - py * vx) / c3, px/c2, py/c2;

		  return Hj;

}
{'fraction_non_alphanumeric': 0.14912985274431056, 'fraction_numerical': 0.02034805890227577, 'mean_word_length': 3.0172043010752687, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 9, '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': '658646', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1360, 'n_words': 381}