My old project for strange attractors
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 

60 lines
1.4 KiB

//
// analyse.hpp
// AwesomeAttract0r
//
// Created by Joshua Moerman on 3/25/12.
// Copyright (c) 2012 Vadovas. All rights reserved.
//
#ifndef AwesomeAttract0r_analyse_hpp
#define AwesomeAttract0r_analyse_hpp
#include <cmath>
inline double distance_squared(double * p1, double * p2, size_t dimension){
double s = 0;
for(unsigned int i = 0; i < dimension; ++i){
s += (p1[i] - p2[i]) * (p1[i] - p2[i]);
}
return s;
}
struct fractal_dimension_settings{
double doubling;
double size;
size_t chunk_size;
fractal_dimension_settings()
: doubling(2.4)
, size(0.035)
, chunk_size(200)
{}
};
template <typename Iterator>
double fractal_dimension(Iterator begin, Iterator end, size_t const dimension, const fractal_dimension_settings settings = fractal_dimension_settings() ) {
const double size = settings.size;
const double totalSize = std::sqrt(dimension);
const double r1 = size * totalSize * size * totalSize;
const double r2 = r1 * settings.doubling * settings.doubling;
unsigned int counts[2] = {};
while(begin != end){
auto x0 = *begin++;
for(unsigned int i = 0; i < settings.chunk_size && begin != end; ++i){
auto x = *begin++;
auto d = distance_squared(x, x0, dimension);
if( d <= r1 )
++counts[0];
if( d <= r2 )
++counts[1];
}
}
return std::log((double) counts[1] / (double) counts[0]) / std::log(settings.doubling);
}
#endif