<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) 2012-2013 <NAME>
 */

#include <shogun/mathematics/Statistics.h>
#include <shogun/features/streaming/generators/GaussianBlobsDataGenerator.h>
#include <shogun/features/streaming/generators/MeanShiftDataGenerator.h>
#include <gtest/gtest.h>

using namespace shogun;

TEST(GaussianBlobsDataGenerator,get_next_example1)
{
	index_t num_blobs=1;
	float64_t distance=3;
	float64_t epsilon=2;
	float64_t angle=CMath::PI/4;
	index_t num_samples=50000;

	CGaussianBlobsDataGenerator* gen=new CGaussianBlobsDataGenerator(num_blobs,
			distance, epsilon, angle);

	/* two dimensional samples */
	SGMatrix<float64_t> samples(2, num_samples);

	for (index_t i=0; i<num_samples; ++i)
	{
		gen->get_next_example();
		SGVector<float64_t> sample=gen->get_vector();
		samples(0,i)=sample[0];
		samples(1,i)=sample[1];
		gen->release_example();
	}

	SGVector<float64_t> mean=CStatistics::matrix_mean(samples, false);
	SGMatrix<float64_t> cov=CStatistics::covariance_matrix(samples);

    /* rougly ensures right results, if test fails, set a bit larger */
    float64_t accuracy=1e-1;

	/* matrix is expected to look like [1.5, 0.5; 0.5, 1.5] */
	EXPECT_NEAR(cov(0,0), 1.5, accuracy);
	EXPECT_NEAR(cov(0,1), 0.5, accuracy);
	EXPECT_NEAR(cov(1,0), 0.5, accuracy);
	EXPECT_NEAR(cov(1,1), 1.5, accuracy);
	
	/* mean is supposed to do [0, 0] */
	EXPECT_LE(CMath::abs(mean[0]-0), accuracy);
	EXPECT_LE(CMath::abs(mean[1]-0), accuracy);
	
	SG_UNREF(gen);
}

TEST(GaussianBlobsDataGenerator,get_next_example2)
{
	index_t num_blobs=3;
	float64_t distance=3;
	float64_t epsilon=2;
	float64_t angle=CMath::PI/4;
	index_t num_samples=50000;

	CGaussianBlobsDataGenerator* gen=new CGaussianBlobsDataGenerator(num_blobs,
			distance, epsilon, angle);

	/* and another one */
	SGMatrix<float64_t> samples2(2, num_samples);
	gen->set_blobs_model(num_blobs, distance, epsilon, angle);

	for (index_t i=0; i<num_samples; ++i)
	{
		gen->get_next_example();
		SGVector<float64_t> sample=gen->get_vector();
		samples2(0,i)=sample[0];
		samples2(1,i)=sample[1];
		gen->release_example();
	}

	SGVector<float64_t> mean2=CStatistics::matrix_mean(samples2, false);
	SGMatrix<float64_t> cov2=CStatistics::covariance_matrix(samples2);

    /* rougly ensures right results, if test fails, set a bit larger */
    float64_t accuracy=1e-1;

	/* matrix is expected to look like [7.55, 0.55; 0.55, 7.55] */
	EXPECT_NEAR(cov2(0,0), 7.55, accuracy);<commit_msg>reduce accuracy in GaussianBlobs generator due to failing tests<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) 2012-2013 <NAME>
 */

#include <shogun/mathematics/Statistics.h>
#include <shogun/features/streaming/generators/GaussianBlobsDataGenerator.h>
#include <shogun/features/streaming/generators/MeanShiftDataGenerator.h>
#include <gtest/gtest.h>

using namespace shogun;

TEST(GaussianBlobsDataGenerator,get_next_example1)
{
	index_t num_blobs=1;
	float64_t distance=3;
	float64_t epsilon=2;
	float64_t angle=CMath::PI/4;
	index_t num_samples=50000;

	CGaussianBlobsDataGenerator* gen=new CGaussianBlobsDataGenerator(num_blobs,
			distance, epsilon, angle);

	/* two dimensional samples */
	SGMatrix<float64_t> samples(2, num_samples);

	for (index_t i=0; i<num_samples; ++i)
	{
		gen->get_next_example();
		SGVector<float64_t> sample=gen->get_vector();
		samples(0,i)=sample[0];
		samples(1,i)=sample[1];
		gen->release_example();
	}

	SGVector<float64_t> mean=CStatistics::matrix_mean(samples, false);
	SGMatrix<float64_t> cov=CStatistics::covariance_matrix(samples);

    /* rougly ensures right results, if test fails, set a bit larger */
    float64_t accuracy=2e-1;

	/* matrix is expected to look like [1.5, 0.5; 0.5, 1.5] */
	EXPECT_NEAR(cov(0,0), 1.5, accuracy);
	EXPECT_NEAR(cov(0,1), 0.5, accuracy);
	EXPECT_NEAR(cov(1,0), 0.5, accuracy);
	EXPECT_NEAR(cov(1,1), 1.5, accuracy);
	
	/* mean is supposed to do [0, 0] */
	EXPECT_LE(CMath::abs(mean[0]-0), accuracy);
	EXPECT_LE(CMath::abs(mean[1]-0), accuracy);
	
	SG_UNREF(gen);
}

TEST(GaussianBlobsDataGenerator,get_next_example2)
{
	index_t num_blobs=3;
	float64_t distance=3;
	float64_t epsilon=2;
	float64_t angle=CMath::PI/4;
	index_t num_samples=50000;

	CGaussianBlobsDataGenerator* gen=new CGaussianBlobsDataGenerator(num_blobs,
			distance, epsilon, angle);

	/* and another one */
	SGMatrix<float64_t> samples2(2, num_samples);
	gen->set_blobs_model(num_blobs, distance, epsilon, angle);

	for (index_t i=0; i<num_samples; ++i)
	{
		gen->get_next_example();
		SGVector<float64_t> sample=gen->get_vector();
		samples2(0,i)=sample[0];
		samples2(1,i)=sample[1];
		gen->release_example();
	}

	SGVector<float64_t> mean2=CStatistics::matrix_mean(samples2, false);
	SGMatrix<float64_t> cov2=CStatistics::covariance_matrix(samples2);

    /* rougly ensures right results, if test fails, set a bit larger */
    float64_t accuracy=2e-1;

	/* matrix is expected to look like [7.55, 0.55; 0.55, 7.55] */
	EXPECT_NEAR(cov2(0,0), 7.55, accuracy);
{'fraction_non_alphanumeric': 0.13629684055841293, 'fraction_numerical': 0.048493754592211606, 'mean_word_length': 5.632155907429963, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 43, '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': '5892298', 'n_tokens_mistral': 2205, 'n_tokens_neox': 2042, 'n_words': 431}