another file to header
This commit is contained in:
parent
d1c1d353ce
commit
1a00cc60dd
2 changed files with 46 additions and 100 deletions
|
@ -1,27 +1,12 @@
|
||||||
#include "Attractor.hpp"
|
#include "Attractor.hpp"
|
||||||
|
|
||||||
#include "Logger.hpp"
|
#include "Logger.hpp"
|
||||||
#include <fstream>
|
|
||||||
#include <iostream>
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string>
|
|
||||||
#include "stfu/stf.hpp"
|
#include "stfu/stf.hpp"
|
||||||
|
|
||||||
#include "AttractorKernel.hpp"
|
#include "AttractorKernel.hpp"
|
||||||
#include "Projector.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() :
|
Attractor::Attractor() :
|
||||||
kernel(0), projector(0) {
|
kernel(0), projector(0) {
|
||||||
stfu::node kernel_node;
|
stfu::node kernel_node;
|
||||||
|
@ -49,81 +34,11 @@ Attractor::Attractor() :
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << kernel_node << std::endl;
|
|
||||||
|
|
||||||
kernel = AttractorKernel::createAttractorKernel(kernel_node);
|
kernel = AttractorKernel::createAttractorKernel(kernel_node);
|
||||||
kernel->generate_random_parameters();
|
kernel->generate_random_parameters();
|
||||||
|
|
||||||
stfu::node projector_node;
|
stfu::node projector_node;
|
||||||
projector_node.value("dimensions") = "2";
|
|
||||||
|
|
||||||
std::cout << projector_node << std::endl;
|
|
||||||
|
|
||||||
projector = Projector::createProjector(projector_node, kernel->getDimension());
|
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");
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,35 +1,66 @@
|
||||||
#ifndef ATTRACTOR_HPP
|
#ifndef ATTRACTOR_HPP
|
||||||
#define ATTRACTOR_HPP
|
#define ATTRACTOR_HPP
|
||||||
|
|
||||||
|
#include "Logger.hpp"
|
||||||
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class Projector;
|
#include "AttractorKernel.hpp"
|
||||||
class AttractorKernel;
|
#include "Projector.hpp"
|
||||||
|
|
||||||
class Attractor {
|
class Attractor {
|
||||||
private:
|
|
||||||
|
|
||||||
AttractorKernel* kernel;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// should be private really
|
// should be private really
|
||||||
Projector* projector;
|
Projector* projector;
|
||||||
|
|
||||||
Attractor(const std::string& filename);
|
Attractor(const std::string& filename) {
|
||||||
|
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();
|
||||||
~Attractor();
|
|
||||||
|
|
||||||
void init_range();
|
~Attractor() {
|
||||||
bool is_chaos();
|
delete kernel;
|
||||||
|
}
|
||||||
|
|
||||||
void iterate();
|
void init_range() {
|
||||||
void plot();
|
for(unsigned int i = 0; i < 1000000; i++) {
|
||||||
void output();
|
iterate();
|
||||||
|
if(kernel->convergent() || kernel->divergent()){
|
||||||
|
kernel->generate_random_parameters();
|
||||||
|
LogDebug("Generating new parameters.\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void iterate() {
|
||||||
|
(*kernel)();
|
||||||
|
}
|
||||||
|
|
||||||
|
void plot() {
|
||||||
|
projector->plot(kernel->vector());
|
||||||
|
}
|
||||||
|
|
||||||
|
void 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");
|
||||||
|
}
|
||||||
|
|
||||||
friend std::ostream& operator<<(std::ostream& os, Attractor const& x);
|
friend std::ostream& operator<<(std::ostream& os, Attractor const& x);
|
||||||
|
|
||||||
|
private:
|
||||||
|
AttractorKernel* kernel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ATTRACTOR_HPP
|
#endif // ATTRACTOR_HPP
|
||||||
|
|
Reference in a new issue