<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 <NAME>
 */

#include <shogun/base/init.h>
#include <shogun/statistics/LinearTimeMMD.h>
#include <shogun/kernel/GaussianKernel.h>
#include <shogun/kernel/CombinedKernel.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/features/CombinedFeatures.h>
#include <shogun/mathematics/Statistics.h>

using namespace shogun;

SGMatrix<float64_t> create_fixed_data(index_t m, index_t dim)
{
	SGMatrix<float64_t> data(dim,2*m);
	for (index_t i=0; i<2*dim*m; ++i)
		data.matrix[i]=i*i;

	data.display_matrix("data");

	return data;
}

void test_linear_mmd_optimize_weights()
{
	index_t m=8;
	index_t dim=2;
	SGMatrix<float64_t> data=create_fixed_data(m, dim);

	/* create a number of kernels with different widths */
	SGVector<float64_t> sigmas(3);
	SGVector<float64_t> shogun_sigmas(sigmas.vlen);

	CCombinedKernel* kernel=new CCombinedKernel();
	CCombinedFeatures* features=new CCombinedFeatures();
	for (index_t i=0; i<sigmas.vlen; ++i)
	{
		sigmas[i]=CMath::pow(2.0, i-2)*1000;
		shogun_sigmas[i]=sigmas[i]*sigmas[i]*2;
		kernel->append_kernel(new CGaussianKernel(10, shogun_sigmas[i]));
		features->append_feature_obj(new CDenseFeatures<float64_t>(data));
	}

	sigmas.display_vector("sigmas");

	CLinearTimeMMD* mmd=new CLinearTimeMMD(kernel, features, m);
	mmd->optimize_kernel_weights();

	SGVector<float64_t> weights=kernel->get_subkernel_weights();
	weights.display_vector("weights");

	/* MATLAB program returns these weights: */
	ASSERT(CMath::abs(weights[0]-0.622266982205087)<10E-16);
	ASSERT(weights[1]==0);
	ASSERT(CMath::abs(weights[2]-0.377733017794913)<10E-16);

	SG_UNREF(mmd);
}

int main(int argc, char** argv)
{
	init_shogun_with_defaults();

//	sg_io->set_loglevel(MSG_DEBUG);

	test_linear_mmd_optimize_weights();

	exit_shogun();
	return 0;
}
<commit_msg>disabled example for now since there are changed needed in order to work with new streaming linear time MMD<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 <NAME>
 */

#include <shogun/base/init.h>
#include <shogun/statistics/LinearTimeMMD.h>
#include <shogun/kernel/GaussianKernel.h>
#include <shogun/kernel/CombinedKernel.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/features/CombinedFeatures.h>
#include <shogun/mathematics/Statistics.h>

using namespace shogun;

SGMatrix<float64_t> create_fixed_data(index_t m, index_t dim)
{
	SGMatrix<float64_t> data(dim,2*m);
	for (index_t i=0; i<2*dim*m; ++i)
		data.matrix[i]=i*i;

	data.display_matrix("data");

	return data;
}

void test_linear_mmd_optimize_weights()
{
	index_t m=8;
	index_t dim=2;
	SGMatrix<float64_t> data=create_fixed_data(m, dim);

	/* create a number of kernels with different widths */
	SGVector<float64_t> sigmas(3);
	SGVector<float64_t> shogun_sigmas(sigmas.vlen);

	CCombinedKernel* kernel=new CCombinedKernel();
	CCombinedFeatures* features=new CCombinedFeatures();
	for (index_t i=0; i<sigmas.vlen; ++i)
	{
		sigmas[i]=CMath::pow(2.0, i-2)*1000;
		shogun_sigmas[i]=sigmas[i]*sigmas[i]*2;
		kernel->append_kernel(new CGaussianKernel(10, shogun_sigmas[i]));
		features->append_feature_obj(new CDenseFeatures<float64_t>(data));
	}

	sigmas.display_vector("sigmas");

	CLinearTimeMMD* mmd=new CLinearTimeMMD(kernel, features, m);
	mmd->optimize_kernel_weights();

	SGVector<float64_t> weights=kernel->get_subkernel_weights();
	weights.display_vector("weights");

	/* MATLAB program returns these weights: */
	ASSERT(CMath::abs(weights[0]-0.622266982205087)<10E-16);
	ASSERT(weights[1]==0);
	ASSERT(CMath::abs(weights[2]-0.377733017794913)<10E-16);

	SG_UNREF(mmd);
}

int main(int argc, char** argv)
{
	init_shogun_with_defaults();

//	sg_io->set_loglevel(MSG_DEBUG);

//	test_linear_mmd_optimize_weights();

	exit_shogun();
	return 0;
}

{'fraction_non_alphanumeric': 0.13861386138613863, 'fraction_numerical': 0.03818953323903819, 'mean_word_length': 6.252991452991453, 'pattern_counts': {'":': 0, '<': 41, '<?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': '5014676', 'n_tokens_mistral': 1741, 'n_tokens_neox': 1611, 'n_words': 316}