<commit_before>// Copyright <NAME> 2016.
// https://github.com/CrikeeIP/OPTICS-Clustering
// Distributed under the MIT Software License (X11 license).
// (See accompanying file LICENSE)


#include "../../include/optics/optics.hpp"
#include "../../include/optics/Stopwatch.hpp"

namespace sw = stopwatch;


//static const std::random_device rd;
static std::mt19937 gen( 1 );

/*
template <typename T, std::enable_if_t<>
using uniform_distribution<T> = std::uniform_real_distribution<T>;
*/


/*
template <typename T>
struct uniform_distribution : public std::enable_if_t<std::is_integral_v<T>, std::uniform_int_distribution<T>>
{
	uniform_distribution( T a, T b ) : std::uniform_int_distribution<T>( a, b ) {}
};

template <typename T>
struct uniform_distribution : public std::enable_if_t<std::is_floating_point_v<T>, std::uniform_real_distribution<T>>
{
	uniform_distribution( T a, T b) : std::uniform_real_distribution<T>(a, b) {}
};
*/

template <typename T>
std::enable_if_t<std::is_integral_v<T>, std::uniform_int_distribution<T>> uniform_distribution( T a, T b )
{
	return std::uniform_int_distribution<T>( a, b );
};

template <typename T>
std::enable_if_t<std::is_floating_point_v<T>, std::uniform_real_distribution<T>> uniform_distribution( T a, T b )
{
	return std::uniform_real_distribution<T>( a, b );
};


template<std::size_t dimension, typename type, typename distribution>
std::array<type, dimension> get_random_point( const distribution& dis ) {
	std::array<type, dimension> result;
	for ( std::size_t d = 0; d < dimension; d++ ) {
		result[d] = dis( gen );
	}
	return result;
}


//Returns the estimated space for each point given a perfect uniform distribution of n_points in dim dimensional volume space_volume
double eps_guess(double space_volume, std::size_t n_points, std::size_t dim ) {
	double d = static_cast<double> (dim);
	double nominator = space_volume * 1.0 * std::tgamma( d / 2.0 + 1.0 );
	double denominator = static_cast<double>(n_points) * std::sqrt( std::pow( geom::pi, d ) );
	double r = std::pow( nominator / denominator, 1.0 / d );
	return r;
}


template<std::size_t n_points, std::size_t dimension, std::uint64_t space_volume, typename type, std::size_t laps>
std::uint64_t test( std::size_t min_pts, double epsilon = -1.0 ) {
	static_assert(dimension > 0, "Dimension must be >0");

	//Space parameters
	double edge_length = std::pow( static_cast<double>(space_volume), 1.0 / static_cast<double>(dimension) );
	std::cout << "Space volume: " << std::pow(edge_length, static_cast<double>(dimension) ) << std::endl;
	std::cout << "Space edge length: " << edge_length << std::endl;
	double eps = eps_guess( static_cast<double>(space_volume), n_points, dimension );
	std::cout << "Estimated space per point: " << eps << std::endl;
	
	//Create a distribution that outputs coordinates between 0 and edge_length

	//std::uniform_real_distribution<type> dis( 0, edge_length );
	auto dis = uniform_distribution<type>( 0, static_cast<type>(edge_length) );

	//Create n_points random points
	std::vector<std::array<type, dimension>> points;
	points.reserve( n_points );
	for ( std::size_t n = 1; n <= n_points; n++ ) {
		points.push_back( get_random_point<dimension, type>( dis ) );
	}

	//Let's go
	std::cout << "Start " << laps << " computations of  optics::compute_reachability_dist()" << std::endl;
	sw::Stopwatch watch;
	for ( std::size_t lap = 1; lap <= laps; lap++ ) {
		if ( lap % (laps/10) == 0 ) std::cout << lap << "..";
		optics::compute_reachability_dists( points, min_pts, epsilon );
		watch.lap();
	}

	auto elapsed = watch.elapsed_laps();
	std::cout << std::endl;
	std::cout << "Lap times [ms]: " << sw::show_times( elapsed.second ) << std::endl;
	std::cout << "Total time: " << elapsed.first << "ms" << std::endl;
	std::cout << "Mean time: " << elapsed.first/laps << "ms" << std::endl;

	return elapsed.first / laps;
}


int main() {
	std::cout << "OPTICS Benchmark" << std::endl;

	auto mean_time = test<500000, 2, 1000*1000, double, 20>( 10 );

	return 0;
}<commit_msg>"Benchmark info output"<commit_after>// Copyright <NAME> 2016.
// https://github.com/CrikeeIP/OPTICS-Clustering
// Distributed under the MIT Software License (X11 license).
// (See accompanying file LICENSE)


#include "../../include/optics/optics.hpp"
#include "../../include/optics/Stopwatch.hpp"

namespace sw = stopwatch;


//static const std::random_device rd;
static std::mt19937 gen( 1 );

/*
template <typename T, std::enable_if_t<>
using uniform_distribution<T> = std::uniform_real_distribution<T>;
*/


/*
template <typename T>
struct uniform_distribution : public std::enable_if_t<std::is_integral_v<T>, std::uniform_int_distribution<T>>
{
	uniform_distribution( T a, T b ) : std::uniform_int_distribution<T>( a, b ) {}
};

template <typename T>
struct uniform_distribution : public std::enable_if_t<std::is_floating_point_v<T>, std::uniform_real_distribution<T>>
{
	uniform_distribution( T a, T b) : std::uniform_real_distribution<T>(a, b) {}
};
*/

template <typename T>
std::enable_if_t<std::is_integral_v<T>, std::uniform_int_distribution<T>> uniform_distribution( T a, T b )
{
	return std::uniform_int_distribution<T>( a, b );
};

template <typename T>
std::enable_if_t<std::is_floating_point_v<T>, std::uniform_real_distribution<T>> uniform_distribution( T a, T b )
{
	return std::uniform_real_distribution<T>( a, b );
};


template<std::size_t dimension, typename type, typename distribution>
std::array<type, dimension> get_random_point( const distribution& dis ) {
	std::array<type, dimension> result;
	for ( std::size_t d = 0; d < dimension; d++ ) {
		result[d] = dis( gen );
	}
	return result;
}


//Returns the estimated space for each point given a perfect uniform distribution of n_points in dim dimensional volume space_volume
double eps_guess(double space_volume, std::size_t n_points, std::size_t dim ) {
	double d = static_cast<double> (dim);
	double nominator = space_volume * 1.0 * std::tgamma( d / 2.0 + 1.0 );
	double denominator = static_cast<double>(n_points) * std::sqrt( std::pow( geom::pi, d ) );
	double r = std::pow( nominator / denominator, 1.0 / d );
	return r;
}


template<std::size_t n_points, std::size_t dimension, std::uint64_t space_volume, typename type, std::size_t laps>
std::uint64_t test( std::size_t min_pts, double epsilon = -1.0 ) {
	static_assert(dimension > 0, "Dimension must be >0");

	//Space parameters
	double edge_length = std::pow( static_cast<double>(space_volume), 1.0 / static_cast<double>(dimension) );
	std::cout << "Space volume: " << std::pow(edge_length, static_cast<double>(dimension) ) << std::endl;
	std::cout << "Space edge length: " << edge_length << std::endl;
	double eps = eps_guess( static_cast<double>(space_volume), n_points, dimension );
	std::cout << "Estimated space per point: " << eps << std::endl;
	
	//Create a distribution that outputs coordinates between 0 and edge_length

	//std::uniform_real_distribution<type> dis( 0, edge_length );
	auto dis = uniform_distribution<type>( 0, static_cast<type>(edge_length) );

	//Create n_points random points
	std::cout << "Creating list of " << n_points << " random points.." << std::endl;
	std::vector<std::array<type, dimension>> points;
	points.reserve( n_points );
	for ( std::size_t n = 1; n <= n_points; n++ ) {
		points.push_back( get_random_point<dimension, type>( dis ) );
	}

	//Let's go
	std::cout << "Start " << laps << " computations of  optics::compute_reachability_dist()" << std::endl;
	sw::Stopwatch watch;
	for ( std::size_t lap = 1; lap <= laps; lap++ ) {
		if ( lap % (laps/10) == 0 ) std::cout << lap << "..";
		optics::compute_reachability_dists( points, min_pts, epsilon );
		watch.lap();
	}

	auto elapsed = watch.elapsed_laps();
	std::cout << std::endl;
	std::cout << "Lap times [ms]: " << sw::show_times( elapsed.second ) << std::endl;
	std::cout << "Total time: " << elapsed.first << "ms" << std::endl;
	std::cout << "Mean time: " << elapsed.first/laps << "ms" << std::endl;

	return elapsed.first / laps;
}


int main() {
	std::cout << "OPTICS Benchmark" << std::endl;

	auto mean_time = test<100000, 6, 100*100*100, double, 10>( 10 );

	return 0;
}
{'fraction_non_alphanumeric': 0.16363188976377951, 'fraction_numerical': 0.014640748031496063, 'mean_word_length': 5.243471582181259, 'pattern_counts': {'":': 0, '<': 217, '<?xml version=': 0, '>': 89, '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': '7561856', 'n_tokens_mistral': 2971, 'n_tokens_neox': 2744, 'n_words': 702}