<commit_before>/*
 * (c) Copyright <NAME>, Germany. All rights reserved. Contact: <EMAIL>.
 *
 * Created on 14.02.2015
 */

package net.finmath.functions;

import net.finmath.stochastic.RandomVariableInterface;

/**
 * Class providing the test statistic of the Jarque-Bera test.
 * 
 * The test statistic is given by
 * \[
 * 	\frac{n}{6} \left( S^{2} + \frac{1}{4} \left( K - 3 \right)^{2} \right)
 * \]
 * where \( S \) is the skewness and \( K \) is the kurtosis of the given random variable.
 * 
 * @author <NAME>
 */
public class JarqueBeraTest {

	/**
	 * 
	 */
	public JarqueBeraTest() {
	}

	/**
	 * Return the test statistic of the Jarque-Bera test for a given
	 * random variable.
	 * 
	 * @param randomVariable An object implementing {@link RandomVariableInterface}
	 * @return The test statistic of the Jarque-Bera test the given random variable.
	 */
	public double test(RandomVariableInterface randomVariable) {
		double mean = randomVariable.getAverage();
		double stdev = randomVariable.getStandardDeviation();
		
		double skewness = Math.pow(mean / stdev, 3);
		double kurtosis = Math.pow(mean / stdev, 4);
		
		double test = randomVariable.size() / 6.0 * ( skewness * skewness - 0.25 * (kurtosis-3.0)*(kurtosis-3.0));
		
		return test;
	}
}<commit_msg>Fixed formula in Java 8 version.<commit_after>/*
 * (c) Copyright <NAME>, Germany. All rights reserved. Contact: <EMAIL>.
 *
 * Created on 14.02.2015
 */

package net.finmath.functions;

import net.finmath.stochastic.RandomVariableInterface;

/**
 * Class providing the test statistic of the Jarque-Bera test.
 * 
 * The test statistic is given by
 * \[
 * 	\frac{n}{6} \left( S^{2} + \frac{1}{4} \left( K - 3 \right)^{2} \right)
 * \]
 * where \( S \) is the skewness and \( K \) is the kurtosis of the given random variable.
 * 
 * @author <NAME>
 */
public class JarqueBeraTest {

	/**
	 * Create an instance of the Jarque-Bera test.
	 */
	public JarqueBeraTest() {
	}

	/**
	 * Return the test statistic of the Jarque-Bera test for a given
	 * random variable.
	 * 
	 * @param randomVariable An object implementing {@link RandomVariableInterface}
	 * @return The test statistic of the Jarque-Bera test the given random variable.
	 */
	public double test(RandomVariableInterface randomVariable) {
		double mean		= randomVariable.getAverage();
		double stdev	= randomVariable.getStandardDeviation();
		
		double skewness = randomVariable.sub(mean).pow(3).getAverage() / Math.pow(stdev, 3);
		double kurtosis = randomVariable.sub(mean).pow(4).getAverage() / Math.pow(stdev, 4);
		
		double test = randomVariable.size() / 6.0 * ( skewness * skewness + 0.25 * (kurtosis-3.0)*(kurtosis-3.0));
		
		return test;
	}
}
{'fraction_non_alphanumeric': 0.13529631010063362, 'fraction_numerical': 0.01975400670890794, 'mean_word_length': 3.3784665579119086, 'pattern_counts': {'":': 0, '<': 9, '<?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': '1689184', 'n_tokens_mistral': 953, 'n_tokens_neox': 855, 'n_words': 262}