<commit_before>/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Written (W) 2014 <NAME>
 * Written (W) 2011-2016 <NAME>
 * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
 *
 * Most cdf routines are wrappers for CDFLIB, part of the public domain NETLIB.
 * https://people.sc.fsu.edu/~jburkardt/f_src/cdflib/cdflib.html
 */

#include <shogun/mathematics/Statistics.h>
#include <shogun/mathematics/Math.h>
#include <shogun/lib/SGMatrix.h>
#include <shogun/lib/SGVector.h>
#include <shogun/lib/SGSparseMatrix.h>
#include <shogun/lib/SGSparseVector.h>
#include <shogun/lib/external/cdflib.hpp>
#include <shogun/mathematics/eigen3.h>

using namespace Eigen;

using namespace shogun;

float64_t CStatistics::variance(SGVector<float64_t> values)
{
	REQUIRE(values.vlen>1, "Number of observations (%d) needs to be at least 1.\n",
			values.vlen);

	float64_t mean=CStatistics::mean(values);

	float64_t sum_squared_diff=0;
	for (index_t i=0; i<values.vlen; ++i)
		sum_squared_diff+=CMath::pow(values.vector[i]-mean, 2);

	return sum_squared_diff/(values.vlen-1);
}

SGVector<float64_t> CStatistics::matrix_mean(SGMatrix<float64_t> values,
		bool col_wise)
{
	ASSERT(values.num_rows>0)
	ASSERT(values.num_cols>0)<commit_msg>define M_SQRT1_2 if not defined in Statistics<commit_after>/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * Written (W) 2014 <NAME>
 * Written (W) 2011-2016 <NAME>
 * Copyright (C) 2011 Berlin Institute of Technology and Max-Planck-Society
 *
 * Most cdf routines are wrappers for CDFLIB, part of the public domain NETLIB.
 * https://people.sc.fsu.edu/~jburkardt/f_src/cdflib/cdflib.html
 */

#include <shogun/mathematics/Statistics.h>
#include <shogun/mathematics/Math.h>
#include <shogun/lib/SGMatrix.h>
#include <shogun/lib/SGVector.h>
#include <shogun/lib/SGSparseMatrix.h>
#include <shogun/lib/SGSparseVector.h>
#include <shogun/lib/external/cdflib.hpp>
#include <shogun/mathematics/eigen3.h>

using namespace Eigen;

using namespace shogun;

#ifndef M_SQRT1_2
#define M_SQRT1_2 0.707106781186547524401
#endif

float64_t CStatistics::variance(SGVector<float64_t> values)
{
	REQUIRE(values.vlen>1, "Number of observations (%d) needs to be at least 1.\n",
			values.vlen);

	float64_t mean=CStatistics::mean(values);

	float64_t sum_squared_diff=0;
	for (index_t i=0; i<values.vlen; ++i)
		sum_squared_diff+=CMath::pow(values.vector[i]-mean, 2);

	return sum_squared_diff/(values.vlen-1);
}

SGVector<float64_t> CStatistics::matrix_mean(SGMatrix<float64_t> values,
		bool col_wise)
{
	ASSERT(values.num_rows>0)
	ASSERT(values.num_cols>0)
{'fraction_non_alphanumeric': 0.12050599201065246, 'fraction_numerical': 0.03462050599201065, 'mean_word_length': 5.247401247401247, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 35, 'https://': 2, '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': '4424915', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1095, 'n_words': 271}