<commit_before>#include <cmath>
#include "Normal.h"

float Norm::CDF(Norm::PDF pdf, float min, float max){
	if(min > max){ //This swaps the two using the XOR swap algorithm
		min = min ^ max;
		max = max ^ min;
		min = min ^ max;
	}

	float total = 0;
	float dx = std::get<1>(pdf)/500;
	for(float i = min; i < max; i+=dx){
		total+=(getValue(pdf, i)+getValue(pdf, i+dx))/2*dx;
	}
	return total;
}
float Norm::getValue(Norm::PDF pdf, float value){
	double e = 2.71828182845904523536;
	double pi = 3.14159265358979323846;
	return 1/(std::get<1>(pdf)*sqrt(2*pi))*pow(e, -1*pow(value-std::get<0>(pdf),2)/(2*pow(std::get<1>(pdf),2)));
}
float Norm::invNorm(Norm::PDF pdf, float percent){ 
	if(abs(percent) > 1){percent = percent/abs(percent);}
	int direction = abs(percent)/percent;
	float dx = std::get<1>(pdf)/500;
	for(float i = std::get<0>(pdf); true; i+=dx*direction){
		if(abs(Norm::CDF(pdf, i < std::get<0>(pdf) ? i : std::get<0>(pdf), i > std::get<0>(pdf ? std::get<0>(pdf) : i) - percent) < 0.001){return i;};
	}
	return 0;	 
}
<commit_msg>Sets the maximum percentage input in inverseNorm to be 0.5 instead of 1 This reflects how this implementation doesn't start from the far left, causing an input of 1 to return the rightmost possible value, but instead from the centre, which means that a % of 1 will never be achieved if the integrator proceeds in only one direction, as it does<commit_after>#include <cmath>
#include "Normal.h"

float Norm::CDF(Norm::PDF pdf, float min, float max){
	if(min > max){ //This swaps the two using the XOR swap algorithm
		min = min ^ max;
		max = max ^ min;
		min = min ^ max;
	}

	float total = 0;
	float dx = std::get<1>(pdf)/500;
	for(float i = min; i < max; i+=dx){
		total+=(getValue(pdf, i)+getValue(pdf, i+dx))/2*dx;
	}
	return total;
}
float Norm::getValue(Norm::PDF pdf, float value){
	double e = 2.71828182845904523536;
	double pi = 3.14159265358979323846;
	return 1/(std::get<1>(pdf)*sqrt(2*pi))*pow(e, -1*pow(value-std::get<0>(pdf),2)/(2*pow(std::get<1>(pdf),2)));
}
float Norm::invNorm(Norm::PDF pdf, float percent){ 
	if(abs(percent) > 0.5){percent = percent/(2*abs(percent));}
	int direction = abs(percent)/percent;
	float dx = std::get<1>(pdf)/500;
	for(float i = std::get<0>(pdf); true; i+=dx*direction){
		if(abs(Norm::CDF(pdf, i < std::get<0>(pdf) ? i : std::get<0>(pdf), i > std::get<0>(pdf ? std::get<0>(pdf) : i) - percent) < 0.001){return i;};
	}
	return 0;	 
}

{'fraction_non_alphanumeric': 0.19348184818481848, 'fraction_numerical': 0.06229372937293729, 'mean_word_length': 4.885922330097087, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, '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': '3774797', 'n_tokens_mistral': 1028, 'n_tokens_neox': 931, 'n_words': 250}