Browse Source

major cleanup, as well as includes, as design of (basic)kernel shit

master
Joshua Moerman 15 years ago
parent
commit
91394ef042
  1. 79
      Attractor.cpp
  2. 31
      Attractor.hpp
  3. 29
      AttractorKernel.hpp
  4. 22
      kernels/BasicKernel.cpp
  5. 37
      kernels/BasicKernel.h
  6. 43
      kernels/KernelBasicParameter.cpp
  7. 41
      kernels/KernelBasicParameter.hpp
  8. 33
      kernels/KernelBasicVector.cpp
  9. 36
      kernels/KernelBasicVector.hpp
  10. 63
      kernels/Logistic.cpp
  11. 20
      kernels/Logistic.hpp
  12. 54
      kernels/Lorenz3D.cpp
  13. 21
      kernels/Lorenz3D.hpp
  14. 90
      kernels/Polynomial.cpp
  15. 21
      kernels/Polynomial.hpp
  16. 48
      kernels/PolynomialA3D.cpp
  17. 17
      kernels/PolynomialA3D.hpp
  18. 57
      kernels/Unravel3D.cpp
  19. 23
      kernels/Unravel3D.hpp

79
Attractor.cpp

@ -1,47 +1,65 @@
#include "Attractor.hpp" #include "Attractor.hpp"
using namespace std;
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include "stfu/stf.hpp"
#include "Projector.hpp"
#include "AttractorKernel.hpp"
#include "kernels/Logistic.hpp"
#include "kernels/Lorenz3D.hpp"
#include "kernels/Polynomial.hpp"
#include "kernels/PolynomialA3D.hpp"
#include "kernels/Unravel3D.hpp"
Attractor::Attractor() { Attractor::Attractor() {
myAttractor = new Lorenz3D(); myAttractor = new Lorenz3D();
// TODO: add default parameters
} }
Attractor::Attractor(const char* const fileName) { Attractor::Attractor(const char* const fileName) {
cout << "Reading file " << fileName << "..." << endl; // opening file
std::cout << "Reading file " << fileName << "..." << std::endl;
stfu::node system; stfu::node system;
system.read(fileName); system.read(fileName);
stfu::node attractor = system.getChild("attractor"); stfu::node attractor = system.getChild("attractor");
string attractorType = attractor.getValue("type");
const string attractorDimension = attractor.getValue("dimensions"); // reading basic stuff
std::string attractorType = attractor.getValue("type");
const std::string attractorDimension = attractor.getValue("dimensions");
for ( unsigned int i = 0; attractorType[i] != '\0'; i++ ) { for ( unsigned int i = 0; attractorType[i] != '\0'; i++ ) {
attractorType[i] = tolower(attractorType[i]); attractorType[i] = tolower(attractorType[i]);
} }
const unsigned int dimension = atoi(attractorDimension.c_str()); const unsigned int dimension = atoi(attractorDimension.c_str());
cout << " Formula: " << attractorType << endl; std::cout << " Formula: " << attractorType << std::endl;
cout << " Dimensions: " << dimension << endl; std::cout << " Dimensions: " << dimension << std::endl;
// depending on type, make the formula object
if ( attractorType == "lorenz" ){ if ( attractorType == "lorenz" ){
if ( dimension == 3 ) { if ( dimension == 3 ) {
myAttractor = new Lorenz3D(); myAttractor = new Lorenz3D();
} else { } else {
cerr << "something wrong"; std::cerr << "something wrong";
exit(37); exit(37);
} }
} else if ( attractorType == "polynomial" ) { } else if ( attractorType == "polynomial" ) {
const string attractorOrde = attractor.getValue("orde"); const std::string attractorOrde = attractor.getValue("orde");
const unsigned int orde = atoi(attractorOrde.c_str()); const unsigned int orde = atoi(attractorOrde.c_str());
cout << " Orde: " << orde << endl; std::cout << " Orde: " << orde << std::endl;
myAttractor = new Polynomial(dimension, orde); myAttractor = new Polynomial(dimension, orde);
} else if ( attractorType == "polynomial a" ) { } else if ( attractorType == "polynomial a" ) {
if ( dimension == 3 ) { if ( dimension == 3 ) {
myAttractor = new PolynomialA3D(); myAttractor = new PolynomialA3D();
} else { } else {
cerr << "something wrong"; std::cerr << "something wrong";
exit(37); exit(37);
} }
} else if ( attractorType == "logistic" ) { } else if ( attractorType == "logistic" ) {
@ -51,26 +69,29 @@ Attractor::Attractor(const char* const fileName) {
if ( dimension == 3 ) { if ( dimension == 3 ) {
myAttractor = new Unravel3D(); myAttractor = new Unravel3D();
} else { } else {
cerr << "somtheing wrong"; std::cerr << "somtheing wrong";
exit(37); exit(37);
} }
} else { } else {
cout << "'" << attractorType << "' not recognized" << endl; std::cout << "'" << attractorType << "' not recognized" << std::endl;
exit(3); exit(3);
} }
const unsigned int numberOfParameters = myAttractor->getNumberOfParameters();
double * & parameters = myAttractor->parameters(); // read parameters
const unsigned int numberOfParameters = myAttractor->numberOfParameters();
for ( unsigned int i = 0; i < numberOfParameters; i++ ) { for ( unsigned int i = 0; i < numberOfParameters; i++ ) {
stfu::node attractorParameters = attractor.getChild("parameters"); stfu::node attractorParameters = attractor.getChild("parameters");
parameters[i] = atof(attractorParameters.getValue(i).c_str()); (*myAttractor)[i] = atof(attractorParameters.getValue(i).c_str());
cout << " Parameter " << i << " set to " << parameters[i] << ", "; std::cout << " Parameter " << i << " set to " << (*myAttractor)[i] << ", ";
} }
cout << endl << " Reading file complete" << endl; std::cout << std::endl << " Reading file complete" << std::endl;
} }
// this should probably done in the projector section
void Attractor::init_range() { void Attractor::init_range() {
// stabilize attractor // stabilize attractor
for ( unsigned int i = 0; i < 100000; i++ ) { for ( unsigned int i = 0; i < 100000; i++ ) {
@ -78,11 +99,9 @@ void Attractor::init_range() {
} }
// initialize projectors with dimension and first point // initialize projectors with dimension and first point
const unsigned int* dim = (unsigned int*)myAttractor->getProperty("dimension"); const unsigned int dimension = myAttractor->dimension();
const unsigned int dimension = *dim;
delete dim;
const double * point = myAttractor->vector(); const double * point = myAttractor->vector();
for ( vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { for ( std::vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) {
(*it)->extern_dim = dimension; (*it)->extern_dim = dimension;
(*it)->intern_dim = 2; (*it)->intern_dim = 2;
(*it)->init(point); (*it)->init(point);
@ -92,11 +111,11 @@ void Attractor::init_range() {
for ( unsigned int i = 0; i < 100000; i++ ) { for ( unsigned int i = 0; i < 100000; i++ ) {
iterate(); iterate();
for ( vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { for ( std::vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) {
(*it)->update_range(point); (*it)->update_range(point);
} }
} }
for ( vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { for ( std::vector<Projector*>::iterator it = projectors.begin(); it != projectors.end(); it++ ) {
(*it)->finish_range(); (*it)->finish_range();
} }
@ -129,11 +148,11 @@ bool Attractor::is_chaos() {
} }
void Attractor::iterate() { void Attractor::iterate() {
myAttractor->iterate(); (*myAttractor)();
} }
void Attractor::plot() { void Attractor::plot() {
for ( vector<Projector *>::iterator it = projectors.begin(); it != projectors.end(); it++ ) { for ( std::vector<Projector *>::iterator it = projectors.begin(); it != projectors.end(); it++ ) {
const double * point = myAttractor->vector(); const double * point = myAttractor->vector();
(*it)->plot(point); (*it)->plot(point);
} }
@ -144,13 +163,11 @@ void Attractor::plot() {
IO & control IO & control
*/ */
void Attractor::output() { void Attractor::output() {
const unsigned int* dim = (unsigned int*)myAttractor->getProperty("dimension"); const unsigned int dimension = myAttractor->dimension();
const unsigned int dimension = *dim;
delete dim;
const double * point = myAttractor->vector(); const double * point = myAttractor->vector();
for ( unsigned int i = 0; i < dimension; i++ ) { for ( unsigned int i = 0; i < dimension; i++ ) {
cout << point[i] << " "; std::cout << point[i] << " ";
} }
cout << endl; std::cout << std::endl;
} }

31
Attractor.hpp

@ -1,47 +1,28 @@
#ifndef ATTRACTOR_HPP #ifndef ATTRACTOR_HPP
#define ATTRACTOR_HPP #define ATTRACTOR_HPP
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <string>
#include <vector> #include <vector>
#include "stfu/stf.hpp"
#include "Projector.hpp"
#include "AttractorKernel.hpp"
#include "kernels/Logistic.hpp"
#include "kernels/Lorenz3D.hpp"
#include "kernels/Polynomial.hpp"
#include "kernels/PolynomialA3D.hpp"
#include "kernels/Unravel3D.hpp"
class Projector; class Projector;
class AttractorKernel;
// TODO : Verschillende classas AttractorSystem en Attractor maken?
class Attractor { class Attractor {
public: private:
AttractorKernel * myAttractor; AttractorKernel * myAttractor;
std::vector<Projector *> projectors; public:
// should be private really
std::vector<Projector *> projectors;
public:
Attractor(); Attractor();
Attractor(const char* const filename); Attractor(const char* const filename);
//void init(unsigned int dimensions, FormulaChoice formula, unsigned int orde);
void init_range(); void init_range();
// TODO : lyapunov exponent uit rekenen
bool is_chaos(); bool is_chaos();
void iterate(); void iterate();
void plot(); void plot();
void output(); void output();
}; };

29
AttractorKernel.hpp

@ -2,33 +2,32 @@
#define ATTRACTORKERNEL_HPP #define ATTRACTORKERNEL_HPP
#include <string> #include <string>
using namespace std;
class AttractorKernel {
public:
// AttractorKernel protocol /*
Protocol/interface, what you want
*/
class AttractorKernel {
public:
// parameters are stored in a array of doubles // parameters are stored in a array of doubles
// if you want to use other types, use the properties // if you want to use other types, use the properties
virtual double& parameter(const unsigned int index) = 0; virtual double & operator[](const unsigned int index) = 0;
virtual double*& parameters() = 0; virtual double const & operator[](const unsigned int index) const = 0;
virtual unsigned int getNumberOfParameters() = 0; virtual unsigned int numberOfParameters() const = 0;
// get properties of the attractor
// such as the dimension
// you should delete the void pointer if you used it
virtual void * getProperty(const string identifier) = 0;
virtual void setProperty(const string identifier, const void * value) = 0;
// iterate his formula // iterate his formula
// vector pointers will be swapped! so new remains new and old remains old // vector pointers will be swapped! so new remains new and old remains old
virtual void iterate() = 0; virtual void operator()() = 0;
// getter functions for teh resulta // getter functions for teh resulta (can be used as setters, and it may be used as such)
virtual double * & vector() = 0; virtual double * & vector() = 0;
virtual double * & previousVector() = 0; virtual double * & previousVector() = 0;
virtual unsigned int dimension() const = 0;
}; };
#endif // ATTRACTORKERNEL_HPP #endif // ATTRACTORKERNEL_HPP

22
kernels/BasicKernel.cpp

@ -1,22 +0,0 @@
#include "BasicKernel.h"
BasicKernel::BasicKernel():
myParameters(NULL), vectorNew(NULL), vectorOld(NULL) {
}
inline double * & BasicKernel::parameters() {
return myParameters;
}
inline double & BasicKernel::parameter(const unsigned int index) {
return myParameters[index];
}
inline double * & BasicKernel::vector() {
return vectorNew;
}
inline double * & BasicKernel::previousVector() {
return vectorOld;
}

37
kernels/BasicKernel.h

@ -1,37 +0,0 @@
#ifndef BASICKERNEL_HPP
#define BASICKERNEL_HPP
#include <iostream>
#include "../AttractorKernel.hpp"
/*
A basic abstract implementatoin of the AttractorKernel, should
be used to avoid copying the same stuff in all attractorKernels
*/
class BasicKernel : public AttractorKernel {
protected:
double * myParameters;
double * vectorNew;
double * vectorOld;
public:
BasicKernel();
// parameters are stored in a array of doubles
// if you want to use other types, use the properties
double& parameter(const unsigned int index);
double*& parameters();
// getter functions for teh resulta
double * & vector();
double * & previousVector();
};
#endif

43
kernels/KernelBasicParameter.cpp

@ -0,0 +1,43 @@
/*
* KernelBasicParameter.cpp
* AwesomeAttractor
*
* Created by Joshua Moerman on 18-07-10.
* Copyright 2010 Rodo. All rights reserved.
*
*/
#include "KernelBasicParameter.hpp"
KernelBasicParameter::KernelBasicParameter(const unsigned int numberOfParameters):
myNumberOfParameters(numberOfParameters){
init();
}
void KernelBasicParameter::init(){
parameters = new double[myNumberOfParameters];
for ( unsigned int i = 0; i < myNumberOfParameters; i++ ) {
parameters[i] = 0.0;
}
}
void KernelBasicParameter::resetNumberOfParameters(const unsigned int numberOfParameters){
delete parameters;
myNumberOfParameters = numberOfParameters;
init();
}
double & KernelBasicParameter::operator[](const unsigned int index){
return parameters[index];
}
double const & KernelBasicParameter::operator[](const unsigned int index) const{
return parameters[index];
}
unsigned int KernelBasicParameter::numberOfParameters() const{
return myNumberOfParameters;
}

41
kernels/KernelBasicParameter.hpp

@ -0,0 +1,41 @@
/*
* KernelBasicParameter.hpp
* AwesomeAttractor
*
* Created by Joshua Moerman on 18-07-10.
* Copyright 2010 Rodo. All rights reserved.
*
*/
#ifndef KERNELBASICPARAMETER_HPP
#define KERNELBASICPARAMETER_HPP
#include "../AttractorKernel.hpp"
class KernelBasicParameter : virtual public AttractorKernel {
private:
void init();
protected:
unsigned int myNumberOfParameters;
double * parameters;
KernelBasicParameter(const unsigned int numberOfParameters);
void resetNumberOfParameters(const unsigned int numberOfParameters);
public:
// parameters are stored in a array of doubles
// if you want to use other types, use the properties
virtual double & operator[](const unsigned int index);
virtual double const & operator[](const unsigned int index) const;
virtual unsigned int numberOfParameters() const;
};
#endif

33
kernels/KernelBasicVector.cpp

@ -0,0 +1,33 @@
/*
* KernelBasicVector.cpp
* AwesomeAttractor
*
* Created by Joshua Moerman on 18-07-10.
* Copyright 2010 Rodo. All rights reserved.
*
*/
#include "KernelBasicVector.hpp"
KernelBasicVector::KernelBasicVector(const unsigned int dimension):
myDimension(dimension){
vectorNew = new double[dimension];
vectorOld = new double[dimension];
for ( unsigned int i = 0; i < myDimension; i++ ) {
vectorNew[i] = vectorOld[i] = 0.0;
}
}
double * & KernelBasicVector::vector(){
return vectorNew;
}
double * & KernelBasicVector::previousVector(){
return vectorOld;
}
unsigned int KernelBasicVector::dimension() const{
return myDimension;
}

36
kernels/KernelBasicVector.hpp

@ -0,0 +1,36 @@
/*
* KernelBasicVector.hpp
* AwesomeAttractor
*
* Created by Joshua Moerman on 18-07-10.
* Copyright 2010 Rodo. All rights reserved.
*
*/
#ifndef KERNELBASICVECTOR_HPP
#define KERNELBASICVECTOR_HPP
#include "../AttractorKernel.hpp"
class KernelBasicVector : virtual public AttractorKernel {
protected:
unsigned int myDimension;
double * vectorNew;
double * vectorOld;
KernelBasicVector(const unsigned int dimension);
public:
// getter functions for teh resulta (can be used as setters, and it may be used as such)
virtual double * & vector();
virtual double * & previousVector();
virtual unsigned int dimension() const;
};
#endif

63
kernels/Logistic.cpp

@ -9,74 +9,37 @@
#include "Logistic.hpp" #include "Logistic.hpp"
Logistic::Logistic(): Logistic::Logistic():
BasicKernel() { KernelBasicParameter(3),
dimension = 3; KernelBasicVector(3) {
init(); init();
} }
Logistic::Logistic(const unsigned int dimension): Logistic::Logistic(const unsigned int dimension):
BasicKernel(), dimension(dimension) { KernelBasicParameter(dimension),
KernelBasicVector(dimension) {
init(); init();
} }
void Logistic::init() { void Logistic::init() {
const unsigned int numberOfParameters = dimension;
if ( myParameters != NULL ) {
delete myParameters;
}
myParameters = new double[numberOfParameters];
if ( vectorNew != NULL ) {
delete vectorNew;
}
vectorNew = new double[dimension];
if ( vectorOld != NULL ) {
delete vectorOld;
}
vectorOld = new double[dimension];
assert(myParameters != NULL); // setting some starting values
assert(vectorNew != NULL); for ( unsigned int i = 0; i < myDimension; i++ ) {
assert(vectorOld != NULL);
for ( unsigned int i = 0; i < numberOfParameters; i++ ) {
myParameters[i] = 0.0;
}
for ( unsigned int i = 0; i < dimension; i++ ) {
vectorNew[i] = vectorOld[i] = 0.5; vectorNew[i] = vectorOld[i] = 0.5;
} }
}
void Logistic::iterate() {
swap(vectorNew, vectorOld);
for ( unsigned int i = 0; i < dimension; i++ ) {
vectorNew[i] = myParameters[i]*vectorOld[i]*(1.0 - vectorOld[i]);
}
} }
void Logistic::operator()() {
// setters, getters, all i/o to other classes/objects std::swap(vectorNew, vectorOld);
void * Logistic::getProperty(const string identifier) {
if ( identifier == "dimension" ) {
unsigned int * _return = new unsigned int;
*_return = dimension;
return _return;
}
return NULL;
}
void Logistic::setProperty(const string identifier, const void * _value) { for ( unsigned int i = 0; i < myDimension; i++ ) {
if ( identifier == "dimension" ) { vectorNew[i] = parameters[i]*vectorOld[i]*(1.0 - vectorOld[i]);
unsigned int * value = (unsigned int*) _value;
dimension = *value;
init();
} }
}
inline unsigned int Logistic::getNumberOfParameters() {
return dimension;
} }

20
kernels/Logistic.hpp

@ -1,28 +1,20 @@
#ifndef LOGISTIC_HPP #ifndef LOGISTIC_HPP
#define LOGISTIC_HPP #define LOGISTIC_HPP
#include <cassert> #include "KernelBasicParameter.hpp"
#include "KernelBasicVector.hpp"
#include "../AttractorKernel.hpp" class Logistic : virtual public KernelBasicParameter, virtual public KernelBasicVector {
#include "BasicKernel.h" private:
class Logistic : public BasicKernel { void init();
unsigned int dimension;
void init();
public: public:
Logistic(); Logistic();
Logistic(const unsigned int dimension); Logistic(const unsigned int dimension);
virtual void operator()();
void iterate();
void * getProperty(const string identifier);
void setProperty(const string identifier, const void * value);
unsigned int getNumberOfParameters();
}; };

54
kernels/Lorenz3D.cpp

@ -1,37 +1,31 @@
#include "Lorenz3D.hpp" #include "Lorenz3D.hpp"
const static unsigned int dimension = 3; Lorenz3D::Lorenz3D():
const static unsigned int numberOfParameters = 4; KernelBasicParameter(4),
KernelBasicVector(3){
Lorenz3D::Lorenz3D() {
init(); init();
} }
void Lorenz3D::init() { void Lorenz3D::init() {
// allocation
myParameters = new double[numberOfParameters]; // setting some starting values
vectorNew = new double[dimension]; for ( unsigned int i = 0; i < myDimension; i++ ) {
vectorOld = new double[dimension];
// initialisation
assert(myParameters != NULL);
assert(vectorNew != NULL);
assert(vectorOld != NULL);
for ( unsigned int i = 0; i < numberOfParameters; i++ ) {
myParameters[i] = 0.0;
}
for ( unsigned int i = 0; i < dimension; i++ ) {
vectorNew[i] = vectorOld[i] = 1.0; vectorNew[i] = vectorOld[i] = 1.0;
} }
} }
// the main function // the main function
void Lorenz3D::iterate() { void Lorenz3D::operator()() {
swap(vectorNew, vectorOld);
std::swap(vectorNew, vectorOld);
vectorNew[0] = vectorOld[0] + parameters[0] * parameters[1] * (vectorOld[1] - vectorOld[0]);
vectorNew[1] = vectorOld[1] + parameters[0] * (vectorOld[0] * (parameters[2] - vectorOld[2]) - vectorOld[1]);
vectorNew[2] = vectorOld[2] + parameters[0] * (vectorOld[0] * vectorOld[1] - parameters[3] * vectorOld[2]);
vectorNew[0] = vectorOld[0] + myParameters[0] * myParameters[1] * (vectorOld[1] - vectorOld[0]);
vectorNew[1] = vectorOld[1] + myParameters[0] * (vectorOld[0] * (myParameters[2] - vectorOld[2]) - vectorOld[1]);
vectorNew[2] = vectorOld[2] + myParameters[0] * (vectorOld[0] * vectorOld[1] - myParameters[3] * vectorOld[2]);
} }
/* /*
@ -43,21 +37,3 @@ void Lorenz3D::iterate() {
break; break;
*/ */
// setters, getters, all i/o to other classes/objects
void * Lorenz3D::getProperty(const string identifier) {
if ( identifier == "dimension" ) {
unsigned int * _return = new unsigned int;
*_return = dimension;
return _return;
}
return NULL;
}
void Lorenz3D::setProperty(const string identifier, const void * value) {
return;
}
inline unsigned int Lorenz3D::getNumberOfParameters() {
return numberOfParameters;
}

21
kernels/Lorenz3D.hpp

@ -1,30 +1,19 @@
#ifndef LORENZ_HPP #ifndef LORENZ_HPP
#define LORENZ_HPP #define LORENZ_HPP
#include <iostream> #include "KernelBasicParameter.hpp"
#include <cstdlib> #include "KernelBasicVector.hpp"
#include <cassert>
#include <string>
using namespace std;
#include "../AttractorKernel.hpp" class Lorenz3D : virtual public KernelBasicParameter, virtual public KernelBasicVector {
#include "BasicKernel.h" private:
class Lorenz3D : public BasicKernel {
void init(); void init();
public: public:
Lorenz3D(); Lorenz3D();
Lorenz3D(const unsigned int dimensions);
void iterate();
void * getProperty(const string identifier); virtual void operator()();
void setProperty(const string identifier, const void * value);
unsigned int getNumberOfParameters();
}; };

90
kernels/Polynomial.cpp

@ -7,71 +7,49 @@
// //
#include "Polynomial.hpp" #include "Polynomial.hpp"
//#include <iostream>
using namespace std;
Polynomial::Polynomial(): Polynomial::Polynomial():
BasicKernel() { KernelBasicParameter(0),
dimension = 3; KernelBasicVector(3),
orde = 2; orde(2){
init(); init();
} }
Polynomial::Polynomial(const unsigned int dimension, const unsigned int orde): Polynomial::Polynomial(const unsigned int dimension, const unsigned int orde):
BasicKernel(), dimension(dimension), orde(orde) { KernelBasicParameter(0),
KernelBasicVector(dimension),
orde(orde) {
init(); init();
} }
void Polynomial::init() { void Polynomial::init() {
calculateNumberOfParameters(); const unsigned int number = calculateNumberOfParameters();
if ( myParameters != NULL ) { KernelBasicParameter::resetNumberOfParameters(number);
delete myParameters;
}
myParameters = new double[numberOfParameters];
if ( vectorNew != NULL ) {
delete vectorNew;
}
vectorNew = new double[dimension];
if ( vectorOld != NULL ) {
delete vectorOld;
}
vectorOld = new double[dimension];
assert(myParameters != NULL);
assert(vectorNew != NULL);
assert(vectorOld != NULL);
for ( unsigned int i = 0; i < numberOfParameters; i++ ) {
myParameters[i] = 0.0;
}
for ( unsigned int i = 0; i < dimension; i++ ) {
vectorNew[i] = vectorOld[i] = 0.0;
}
} }
void Polynomial::calculateNumberOfParameters() { unsigned int Polynomial::calculateNumberOfParameters() {
double n_coef = orde + 1; double n_coef = orde + 1;
for (unsigned int i = 2; i <= dimension; i++) { for (unsigned int i = 2; i <= myDimension; i++) {
n_coef = n_coef*(orde + i)/(i - 1); n_coef = n_coef*(orde + i)/(i - 1);
} }
numberOfParameters = (unsigned int) n_coef; const unsigned int output = (unsigned int) n_coef;
cout << numberOfParameters << endl; return output;
} }
void Polynomial::iterate() { void Polynomial::operator()() {
swap(vectorNew, vectorOld); std::swap(vectorNew, vectorOld);
unsigned int m = 0; unsigned int m = 0;
for ( unsigned int i = 0; i < dimension; i++ ) { for ( unsigned int i = 0; i < myDimension; i++ ) {
#ifdef HARDDEBUG #ifdef HARDDEBUG
cout << "Entering new dimension: " << i << " With m = " << m << endl; cout << "Entering new dimension: " << i << " With m = " << m << endl;
#endif #endif
vectorNew[i] = myParameters[m]; vectorNew[i] = parameters[m];
m++; m++;
recur(i, 0, 1, m); recur(i, 0, 1, m);
} }
@ -80,7 +58,7 @@ void Polynomial::iterate() {
void Polynomial::recur(unsigned int curr_dimension, unsigned int prev_i, unsigned int n, unsigned int& m, double prev_product) { void Polynomial::recur(unsigned int curr_dimension, unsigned int prev_i, unsigned int n, unsigned int& m, double prev_product) {
double product; double product;
for (unsigned int i = prev_i; i < dimension; i++) { for (unsigned int i = prev_i; i < myDimension; i++) {
#ifdef HARDDEBUG #ifdef HARDDEBUG
for ( unsigned int j = 0; j < n; j++ ) for ( unsigned int j = 0; j < n; j++ )
@ -89,7 +67,7 @@ void Polynomial::recur(unsigned int curr_dimension, unsigned int prev_i, unsigne
#endif #endif
product = prev_product * vectorOld[i]; product = prev_product * vectorOld[i];
vectorNew[curr_dimension] += myParameters[m] * product; vectorNew[curr_dimension] += parameters[m] * product;
m++; m++;
if (n < orde) { if (n < orde) {
recur(curr_dimension, i, n+1, m, product); recur(curr_dimension, i, n+1, m, product);
@ -97,33 +75,3 @@ void Polynomial::recur(unsigned int curr_dimension, unsigned int prev_i, unsigne
} }
} }
// setters, getters, all i/o to other classes/objects
void * Polynomial::getProperty(const string identifier) {
if ( identifier == "dimension" ) {
unsigned int * _return = new unsigned int;
*_return = dimension;
return _return;
} else if ( identifier == "orde" ) {
unsigned int * _return = new unsigned int;
*_return = orde;
return _return;
}
return NULL;
}
void Polynomial::setProperty(const string identifier, const void * _value) {
if ( identifier == "dimension" ) {
unsigned int * value = (unsigned int*) _value;
dimension = *value;
init();
} else if ( identifier == "orde" ) {
unsigned int * value = (unsigned int*) _value;
orde = *value;
init();
}
}
inline unsigned int Polynomial::getNumberOfParameters() {
return numberOfParameters;
}

21
kernels/Polynomial.hpp

@ -1,20 +1,16 @@
#ifndef POLYNOMIAL_HPP #ifndef POLYNOMIAL_HPP
#define POLYNOMIAL_HPP #define POLYNOMIAL_HPP
#include <cassert> #include "KernelBasicParameter.hpp"
#include <iostream> #include "KernelBasicVector.hpp"
#include "../AttractorKernel.hpp" class Polynomial : virtual public KernelBasicParameter, virtual public KernelBasicVector {
#include "BasicKernel.h" private:
class Polynomial : public BasicKernel {
unsigned int dimension;
unsigned int orde; unsigned int orde;
unsigned int numberOfParameters;
void init(); void init();
void calculateNumberOfParameters(); unsigned int calculateNumberOfParameters();
void recur(unsigned int curr_dimension, unsigned int prev_i, unsigned int n, unsigned int& m, double prev_product=1.0); void recur(unsigned int curr_dimension, unsigned int prev_i, unsigned int n, unsigned int& m, double prev_product=1.0);
public: public:
@ -22,12 +18,7 @@ public:
Polynomial(); Polynomial();
Polynomial(const unsigned int dimensions, const unsigned int orde); Polynomial(const unsigned int dimensions, const unsigned int orde);
virtual void operator()();
void iterate();
void * getProperty(const string identifier);
void setProperty(const string identifier, const void * value);
unsigned int getNumberOfParameters();
}; };

48
kernels/PolynomialA3D.cpp

@ -8,35 +8,22 @@
#include "PolynomialA3D.hpp" #include "PolynomialA3D.hpp"
const static unsigned int dimension = 3; PolynomialA3D::PolynomialA3D():
const static unsigned int numberOfParameters = 3; KernelBasicParameter(3),
KernelBasicVector(3){
PolynomialA3D::PolynomialA3D() {
init(); init();
} }
void PolynomialA3D::init() { void PolynomialA3D::init() {
myParameters = new double[numberOfParameters];
vectorNew = new double[dimension];
vectorOld = new double[dimension];
assert(myParameters != NULL);
assert(vectorNew != NULL);
assert(vectorOld != NULL);
for ( unsigned int i = 0; i < numberOfParameters; i++ ) {
myParameters[i] = 0.0;
}
for ( unsigned int i = 0; i < dimension; i++ ) {
vectorNew[i] = vectorOld[i] = 0.0;
}
} }
void PolynomialA3D::iterate() { void PolynomialA3D::operator()() {
swap(vectorNew, vectorOld); std::swap(vectorNew, vectorOld);
vectorNew[0] = myParameters[0] + vectorOld[1] - vectorOld[1]*vectorOld[2]; vectorNew[0] = parameters[0] + vectorOld[1] - vectorOld[1]*vectorOld[2];
vectorNew[1] = myParameters[1] + vectorOld[2] - vectorOld[2]*vectorOld[0]; vectorNew[1] = parameters[1] + vectorOld[2] - vectorOld[2]*vectorOld[0];
vectorNew[2] = myParameters[2] + vectorOld[0] - vectorOld[0]*vectorOld[1]; vectorNew[2] = parameters[2] + vectorOld[0] - vectorOld[0]*vectorOld[1];
} }
/* /*
N dimensional: N dimensional:
@ -44,22 +31,3 @@ N dimensional:
new_point[i] = param[i] + point[(i+1) % dim] - point[(i+1) % dim]*point[(i+2) % dim]; new_point[i] = param[i] + point[(i+1) % dim] - point[(i+1) % dim]*point[(i+2) % dim];
} }
*/ */
// setters, getters, all i/o to other classes/objects
void * PolynomialA3D::getProperty(const string identifier) {
if ( identifier == "dimension" ) {
unsigned int * _return = new unsigned int;
*_return = dimension;
return _return;
}
return NULL;
}
void PolynomialA3D::setProperty(const string identifier, const void * _value) {
}
inline unsigned int PolynomialA3D::getNumberOfParameters() {
return numberOfParameters;
}

17
kernels/PolynomialA3D.hpp

@ -1,13 +1,11 @@
#ifndef POLYNOMIALA3D_HPP #ifndef POLYNOMIALA3D_HPP
#define POLYNOMIALA3D_HPP #define POLYNOMIALA3D_HPP
#include <cassert> #include "KernelBasicParameter.hpp"
#include "KernelBasicVector.hpp"
#include "../AttractorKernel.hpp" class PolynomialA3D : virtual public KernelBasicParameter, virtual public KernelBasicVector {
#include "BasicKernel.h" private:
class PolynomialA3D : public BasicKernel {
// of course this can be seen as a subclasse of Polynomial
void init(); void init();
@ -15,12 +13,7 @@ public:
PolynomialA3D(); PolynomialA3D();
virtual void operator()();
void iterate();
void * getProperty(const string identifier);
void setProperty(const string identifier, const void * value);
unsigned int getNumberOfParameters();
}; };

57
kernels/Unravel3D.cpp

@ -1,62 +1,27 @@
#include "Unravel3D.hpp" #include "Unravel3D.hpp"
#include <cmath>
const static unsigned int dimension = 3; Unravel3D::Unravel3D():
const static unsigned int numberOfParameters = 7; KernelBasicParameter(7),
KernelBasicVector(3){
Unravel3D::Unravel3D(){
init();
} }
void Unravel3D::init() { void Unravel3D::operator()() {
// allocation std::swap(vectorNew, vectorOld);
myParameters = new double[numberOfParameters];
vectorNew = new double[dimension];
vectorOld = new double[dimension];
// initialisation vectorNew[0] = parameters[0]*(vectorOld[2] + parameters[1]);
assert(myParameters != NULL); vectorNew[1] = parameters[2]*(vectorOld[0] + parameters[3]);
assert(vectorNew != NULL); vectorNew[2] = parameters[4]*(vectorOld[1] + parameters[5]);
assert(vectorOld != NULL);
for ( unsigned int i = 0; i < numberOfParameters; i++ ) {
myParameters[i] = 0.0;
}
for ( unsigned int i = 0; i < dimension; i++ ) {
vectorNew[i] = vectorOld[i] = 0.0;
}
}
void Unravel3D::iterate() {
swap(vectorNew, vectorOld);
vectorNew[0] = myParameters[0]*(vectorOld[2] + myParameters[1]);
vectorNew[1] = myParameters[2]*(vectorOld[0] + myParameters[3]);
vectorNew[2] = myParameters[4]*(vectorOld[1] + myParameters[5]);
const double dist = vectorNew[0]*vectorNew[0] + vectorNew[1]*vectorNew[1] + vectorNew[2]*vectorNew[2]; const double dist = vectorNew[0]*vectorNew[0] + vectorNew[1]*vectorNew[1] + vectorNew[2]*vectorNew[2];
if ( dist > myParameters[6]*myParameters[6] ) { if ( dist > parameters[6]*parameters[6] ) {
const double sqrtDist = sqrt(dist); const double sqrtDist = sqrt(dist);
const double p = 1.0 - myParameters[6] * ( static_cast<int> ( sqrtDist / myParameters[6] ) + 1.0 ) / sqrtDist; const double p = 1.0 - parameters[6] * ( static_cast<int> ( sqrtDist / parameters[6] ) + 1.0 ) / sqrtDist;
vectorNew[0] *= p; vectorNew[0] *= p;
vectorNew[1] *= p; vectorNew[1] *= p;
vectorNew[2] *= p; vectorNew[2] *= p;
} }
} }
// setters, getters, all i/o to other classes/objects
void * Unravel3D::getProperty(const string identifier) {
if ( identifier == "dimension" ) {
unsigned int * _return = new unsigned int;
*_return = dimension;
return _return;
}
return NULL;
}
void Unravel3D::setProperty(const string identifier, const void * value) {
return;
}
inline unsigned int Unravel3D::getNumberOfParameters() {
return numberOfParameters;
}

23
kernels/Unravel3D.hpp

@ -1,31 +1,16 @@
#ifndef UNRAVEL_HPP #ifndef UNRAVEL_HPP
#define UNRAVEL_HPP #define UNRAVEL_HPP
#include <iostream> #include "KernelBasicParameter.hpp"
#include <cstdlib> #include "KernelBasicVector.hpp"
#include <cassert>
#include <string>
#include <cmath>
using namespace std;
#include "../AttractorKernel.hpp"
#include "BasicKernel.h"
class Unravel3D : public BasicKernel {
void init();
class Unravel3D : virtual public KernelBasicParameter, virtual public KernelBasicVector {
public: public:
Unravel3D(); Unravel3D();
Unravel3D(const unsigned int dimensions); Unravel3D(const unsigned int dimensions);
virtual void operator()();
void iterate();
void * getProperty(const string identifier);
void setProperty(const string identifier, const void * value);
unsigned int getNumberOfParameters();
}; };