<commit_before>package de.outstare.kinosim.util;

import com.google.common.collect.Range;

/**
 * Distributions holds methods for calculation numbers based on distributions.
 */
public class Distributions {
	private Distributions() {
		// no instances
	}

	public static double defaultNormalDistribution(final double x) {
		return normalDistribution(x, 0, 1);
	}

	/**
	 * @param x
	 * @param mu
	 *            expected value
	 * @param sigma
	 *            standard deviation
	 * @return normal distributed value of x
	 */
	public static double normalDistribution(final double x, final double mu, final double sigma) {
		return 1 / (sigma * Math.sqrt(2 * Math.PI)) * Math.pow(Math.E, -0.5 * Math.pow((x - mu) / sigma, 2));
	}

	/**
	 * Gives the ratio of the difference of the given value to the expected value in relation to the given range of values. The ratio is weighted
	 * towards the expected value by a cosine function. Therefore values near the expected value will have a high ratio.
	 *
	 * Example1: We have values ranging from 0 to 100. We expect the middle which is 50, but got a 17. In the range of values the 17 is almost the one
	 * third of the left half, so it's two thrid away from the expected value. Because the ratio is based on a cosine the ratio is cos(-0.66 * pi)
	 * instead of 0.34. And because cosine returns values from -1 to +1, but we want a ratio from 0 to 1 the value is scaled accordingly. In this case
	 * the cosine returns -0.48 which is scaled to 0.26 (that's 8 percent off the linear value).
	 *
	 * <pre>
	 *   1.0    -
	 *   0.5   / \
	 *   0.0  |   |
	 *  -0.5 /     \
	 *  -1.0-       -
	 *     -1   0   1 <- relative distance from expected value
	 * </pre>
	 *
	 * Example2: We have values ranging from 0 to 100. We expect a 75 but got a 10. Because it is more than half-range away the ratio is 0;
	 *
	 * @param expectedValue
	 *            the best value which currentValue can have
	 * @param currentValue
	 *            an actual value in the given range which should be weighted depending on it's distance from the expectedValue<commit_msg>fixed JavaDoc<commit_after>package de.outstare.kinosim.util;

import com.google.common.collect.Range;

/**
 * Distributions holds methods for calculation numbers based on distributions.
 */
public class Distributions {
	private Distributions() {
		// no instances
	}

	public static double defaultNormalDistribution(final double x) {
		return normalDistribution(x, 0, 1);
	}

	/**
	 * @param x
	 * @param mu
	 *            expected value
	 * @param sigma
	 *            standard deviation
	 * @return normal distributed value of x
	 */
	public static double normalDistribution(final double x, final double mu, final double sigma) {
		return 1 / (sigma * Math.sqrt(2 * Math.PI)) * Math.pow(Math.E, -0.5 * Math.pow((x - mu) / sigma, 2));
	}

	/**
	 * Gives the ratio of the difference of the given value to the expected value in relation to the given range of values. The ratio is weighted
	 * towards the expected value by a cosine function. Therefore values near the expected value will have a high ratio.
	 *
	 * Example1: We have values ranging from 0 to 100. We expect the middle which is 50, but got a 17. In the range of values the 17 is almost the one
	 * third of the left half, so it's two thrid away from the expected value. Because the ratio is based on a cosine the ratio is cos(-0.66 * pi)
	 * instead of 0.34. And because cosine returns values from -1 to +1, but we want a ratio from 0 to 1 the value is scaled accordingly. In this case
	 * the cosine returns -0.48 which is scaled to 0.26 (that's 8 percent off the linear value).
	 *
	 * <pre>
	 *   1.0    -
	 *   0.5   / \
	 *   0.0  |   |
	 *  -0.5 /     \
	 *  -1.0-       -
	 *     -1   0   1 &lt;- relative distance from expected value
	 * </pre>
	 *
	 * Example2: We have values ranging from 0 to 100. We expect a 75 but got a 10. Because it is more than half-range away the ratio is 0;
	 *
	 * @param expectedValue
	 *            the best value which currentValue can have
	 * @param currentValue
	 *            an actual value in the given range which should be weighted depending on it's distance from the expectedValue
{'fraction_non_alphanumeric': 0.08104231412861583, 'fraction_numerical': 0.027731293330145828, 'mean_word_length': 2.6766256590509667, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, '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': '5011239', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1153, 'n_words': 579}