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.
47 lines
1.2 KiB
47 lines
1.2 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;
|
|
}
|
|
|
|
template <typename Iterator>
|
|
double fractal_dimension(Iterator begin, Iterator end, size_t const dimension, const double doubling = 2.4, const double percentage = 0.00004) {
|
|
const double size = std::pow(percentage, 1.0 / 3.0);
|
|
//const double size = std::pow(percentage, 1.0 / dimension);
|
|
const double totalSize = std::sqrt(dimension);
|
|
|
|
unsigned int counts[2] = {};
|
|
double r = size * totalSize;
|
|
|
|
while(begin != end){
|
|
auto x0 = *begin++;
|
|
|
|
for(unsigned int i = 0; i < 200 && begin != end; ++i){
|
|
auto x = *begin++;
|
|
auto d = distance_squared(x, x0, dimension);
|
|
if( d <= r*r )
|
|
++counts[0];
|
|
if( d <= doubling*doubling*r*r )
|
|
++counts[1];
|
|
}
|
|
}
|
|
|
|
return std::log((double) counts[1] / (double) counts[0]) / std::log(doubling);
|
|
}
|
|
|
|
#endif
|
|
|