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.
103 lines
2.1 KiB
103 lines
2.1 KiB
#ifndef ATTRACTOR_HPP
|
|
#define ATTRACTOR_HPP
|
|
|
|
#include "Logger.hpp"
|
|
#include "stfu/stf_ext.hpp"
|
|
#include <iostream>
|
|
#include <fstream>
|
|
#include <string>
|
|
|
|
#include "AttractorKernel.hpp"
|
|
#include "Projector.hpp"
|
|
|
|
class Attractor {
|
|
public:
|
|
// should be private really
|
|
Projector* projector;
|
|
|
|
Attractor(const std::string& filename = "")
|
|
: projector(0)
|
|
, kernel(0)
|
|
{
|
|
if (filename == "") {
|
|
LogInfo("Making random attractor\n");
|
|
generate_random();
|
|
} else {
|
|
LogInfo("Reading file '%s'\n", filename.c_str());
|
|
|
|
stfu::node system;
|
|
if(!system.read(filename)) throw std::runtime_error(filename + " could not be opened");
|
|
|
|
kernel = AttractorKernel::createAttractorKernel(system.getChild("attractor_kernel"));
|
|
projector = Projector::createProjector(system.getChild(system.getValue("Projector")), kernel->getDimension());
|
|
}
|
|
}
|
|
|
|
~Attractor() {
|
|
delete kernel;
|
|
}
|
|
|
|
void init_range() {
|
|
ProgressIndicator p(std::cout, LOG_VERBOSE, "searching for parameters");
|
|
for(unsigned int i = 0; i < 1000000; i++) {
|
|
iterate();
|
|
|
|
bool stop = false;
|
|
|
|
if(kernel->convergent()){
|
|
std::cerr << "convergent\n";
|
|
stop = true;
|
|
}
|
|
|
|
if(kernel->divergent()){
|
|
std::cerr << "divergent\n";
|
|
stop = true;
|
|
}
|
|
|
|
if(stop){
|
|
kernel->generate_random_parameters();
|
|
p.show();
|
|
i = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
void iterate() {
|
|
(*kernel)();
|
|
}
|
|
|
|
void project() {
|
|
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");
|
|
}
|
|
|
|
stfu::node to_stf() const {
|
|
stfu::node node;
|
|
node.addChild("attractor_kernel") = stfu::to_stf(*kernel);
|
|
node.addChild("Projector"); /* = to_stf(*projector);*/
|
|
node.addValue("Projector") = "Projector";
|
|
return node;
|
|
}
|
|
|
|
friend std::ostream& operator<<(std::ostream& os, Attractor const& x);
|
|
|
|
private:
|
|
void generate_random();
|
|
|
|
AttractorKernel* kernel;
|
|
|
|
Attractor(Attractor const &);
|
|
Attractor& operator=(Attractor const &);
|
|
};
|
|
|
|
#endif // ATTRACTOR_HPP
|
|
|
|
|