|
|
|
#include "Attractor.hpp"
|
|
|
|
|
|
|
|
#include "Logger.hpp"
|
|
|
|
#include <fstream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <string>
|
|
|
|
#include "stfu/stf.hpp"
|
|
|
|
|
|
|
|
#include "AttractorKernel.hpp"
|
|
|
|
#include "Projector.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
Attractor::Attractor(const std::string& filename) : kernel(0), projector(0) {
|
|
|
|
// opening file
|
|
|
|
LogInfo("Reading file '%s'...\n", filename.c_str());
|
|
|
|
|
|
|
|
stfu::node system;
|
|
|
|
system.read(filename.c_str());
|
|
|
|
|
|
|
|
kernel = AttractorKernel::createAttractorKernel(system.getChild("AttractorKernel"));
|
|
|
|
projector = Projector::createProjector(system.getChild(system.getValue("Projector")), kernel->getDimension());
|
|
|
|
}
|
|
|
|
|
|
|
|
Attractor::Attractor(){
|
|
|
|
stfu::node kernel_node;
|
|
|
|
switch(rand()%3){
|
|
|
|
case 0:
|
|
|
|
kernel_node.value("type") = "lorenz";
|
|
|
|
kernel_node.value("dimensions") = "3";
|
|
|
|
break;
|
|
|
|
/*case 1:
|
|
|
|
kernel_node.value("type") = "polynomial";
|
|
|
|
kernel_node.value("dimensions") = std::string() + (char)(rand()%3 + '2');
|
|
|
|
kernel_node.value("orde") = std::string() + (char)(rand()%5 + '1');
|
|
|
|
break;*/
|
|
|
|
case 1:
|
|
|
|
kernel_node.value("type") = "polynomial a";
|
|
|
|
kernel_node.value("dimensions") = "3";
|
|
|
|
break;
|
|
|
|
/*case 3:
|
|
|
|
kernel_node.value("type") = "logistic";
|
|
|
|
kernel_node.value("dimensions") = std::string() + (char)(rand()%3 + '2');
|
|
|
|
break;*/
|
|
|
|
case 2:
|
|
|
|
kernel_node.value("type") = "unravel";
|
|
|
|
kernel_node.value("dimensions") = "3";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << kernel_node << std::endl;
|
|
|
|
|
|
|
|
kernel = AttractorKernel::createAttractorKernel(kernel_node);
|
|
|
|
kernel->generate_random_parameters();
|
|
|
|
|
|
|
|
stfu::node projector_node;
|
|
|
|
projector_node.value("dimensions") = "2";
|
|
|
|
|
|
|
|
std::cout << projector_node << std::endl;
|
|
|
|
|
|
|
|
projector = Projector::createProjector(projector_node, kernel->getDimension());
|
|
|
|
}
|
|
|
|
|
|
|
|
Attractor::~Attractor() {
|
|
|
|
delete kernel;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// this should probably done in the projector section
|
|
|
|
void Attractor::init_range() {
|
|
|
|
// stabilize attractor
|
|
|
|
for(unsigned int i = 0; i < 1000000; i++) {
|
|
|
|
iterate();
|
|
|
|
if(kernel->convergent() || kernel->divergent()){
|
|
|
|
kernel->generate_random_parameters();
|
|
|
|
LogDebug("Generating new parameters.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Attractor::is_chaos() {
|
|
|
|
/*
|
|
|
|
check existence of attractor:
|
|
|
|
Escaping
|
|
|
|
Single point attractor
|
|
|
|
Lyapunov exponent
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
double sum = 0;
|
|
|
|
for ( unsigned int i = 0; i < dim; i++ ) {
|
|
|
|
const double dist = 0; //new_point[i] - point[i];
|
|
|
|
sum += dist*dist;
|
|
|
|
}
|
|
|
|
if ( sum >= 1.0e7 ) {
|
|
|
|
// big change => Escaping
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ( sum <= 1.0e-7 ) {
|
|
|
|
// small change => singularity
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Attractor::iterate() {
|
|
|
|
(*kernel)();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Attractor::plot() {
|
|
|
|
const double* point = kernel->vector();
|
|
|
|
projector->plot(point);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
IO & control
|
|
|
|
*/
|
|
|
|
void Attractor::output() {
|
|
|
|
const unsigned int dimension = kernel->getDimension();
|
|
|
|
const double* point = kernel->vector();
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < dimension; i++) {
|
|
|
|
LogMoreInfo("%f, ", point[i]);
|
|
|
|
}
|
|
|
|
LogMoreInfo("\n");
|
|
|
|
}
|