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. 29
      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. 18
      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"
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() {
myAttractor = new Lorenz3D();
// TODO: add default parameters
}
Attractor::Attractor(const char* const fileName) {
cout << "Reading file " << fileName << "..." << endl;
// opening file
std::cout << "Reading file " << fileName << "..." << std::endl;
stfu::node system;
system.read(fileName);
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++ ) {
attractorType[i] = tolower(attractorType[i]);
}
const unsigned int dimension = atoi(attractorDimension.c_str());
cout << " Formula: " << attractorType << endl;
cout << " Dimensions: " << dimension << endl;
std::cout << " Formula: " << attractorType << std::endl;
std::cout << " Dimensions: " << dimension << std::endl;
// depending on type, make the formula object
if ( attractorType == "lorenz" ){
if ( dimension == 3 ) {
myAttractor = new Lorenz3D();
} else {
cerr << "something wrong";
std::cerr << "something wrong";
exit(37);
}
} 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());
cout << " Orde: " << orde << endl;
std::cout << " Orde: " << orde << std::endl;
myAttractor = new Polynomial(dimension, orde);
} else if ( attractorType == "polynomial a" ) {
if ( dimension == 3 ) {
myAttractor = new PolynomialA3D();
} else {
cerr << "something wrong";
std::cerr << "something wrong";
exit(37);
}
} else if ( attractorType == "logistic" ) {
@ -51,26 +69,29 @@ Attractor::Attractor(const char* const fileName) {
if ( dimension == 3 ) {
myAttractor = new Unravel3D();
} else {
cerr << "somtheing wrong";
std::cerr << "somtheing wrong";
exit(37);
}
} else {
cout << "'" << attractorType << "' not recognized" << endl;
std::cout << "'" << attractorType << "' not recognized" << std::endl;
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++ ) {
stfu::node attractorParameters = attractor.getChild("parameters");
parameters[i] = atof(attractorParameters.getValue(i).c_str());
cout << " Parameter " << i << " set to " << parameters[i] << ", ";
(*myAttractor)[i] = atof(attractorParameters.getValue(i).c_str());
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() {
// stabilize attractor
for ( unsigned int i = 0; i < 100000; i++ ) {
@ -78,11 +99,9 @@ void Attractor::init_range() {
}
// initialize projectors with dimension and first point
const unsigned int* dim = (unsigned int*)myAttractor->getProperty("dimension");
const unsigned int dimension = *dim;
delete dim;
const unsigned int dimension = myAttractor->dimension();
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)->intern_dim = 2;
(*it)->init(point);
@ -92,11 +111,11 @@ void Attractor::init_range() {
for ( unsigned int i = 0; i < 100000; i++ ) {
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);
}
}
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();
}
@ -129,11 +148,11 @@ bool Attractor::is_chaos() {
}
void Attractor::iterate() {
myAttractor->iterate();
(*myAttractor)();
}
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();
(*it)->plot(point);
}
@ -144,13 +163,11 @@ void Attractor::plot() {
IO & control
*/
void Attractor::output() {
const unsigned int* dim = (unsigned int*)myAttractor->getProperty("dimension");
const unsigned int dimension = *dim;
delete dim;
const unsigned int dimension = myAttractor->dimension();
const double * point = myAttractor->vector();
for ( unsigned int i = 0; i < dimension; i++ ) {
cout << point[i] << " ";
std::cout << point[i] << " ";
}
cout << endl;
std::cout << std::endl;
}

29
Attractor.hpp

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

29
AttractorKernel.hpp

@ -2,33 +2,32 @@
#define ATTRACTORKERNEL_HPP
#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
// if you want to use other types, use the properties
virtual double& parameter(const unsigned int index) = 0;
virtual double*& parameters() = 0;
virtual double & operator[](const unsigned int index) = 0;
virtual double const & operator[](const unsigned int index) const = 0;
virtual unsigned int getNumberOfParameters() = 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;
virtual unsigned int numberOfParameters() const = 0;
// iterate his formula
// 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 * & previousVector() = 0;
virtual unsigned int dimension() const = 0;
};
#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"
Logistic::Logistic():
BasicKernel() {
dimension = 3;
KernelBasicParameter(3),
KernelBasicVector(3) {
init();
}
Logistic::Logistic(const unsigned int dimension):
BasicKernel(), dimension(dimension) {
KernelBasicParameter(dimension),
KernelBasicVector(dimension) {
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);
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++ ) {
// setting some starting values
for ( unsigned int i = 0; i < myDimension; i++ ) {
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
void * Logistic::getProperty(const string identifier) {
if ( identifier == "dimension" ) {
unsigned int * _return = new unsigned int;
*_return = dimension;
return _return;
}
return NULL;
}
std::swap(vectorNew, vectorOld);
void Logistic::setProperty(const string identifier, const void * _value) {
if ( identifier == "dimension" ) {
unsigned int * value = (unsigned int*) _value;
dimension = *value;
init();
for ( unsigned int i = 0; i < myDimension; i++ ) {
vectorNew[i] = parameters[i]*vectorOld[i]*(1.0 - vectorOld[i]);
}
}
inline unsigned int Logistic::getNumberOfParameters() {
return dimension;
}

18
kernels/Logistic.hpp

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

54
kernels/Lorenz3D.cpp

@ -1,37 +1,31 @@
#include "Lorenz3D.hpp"
const static unsigned int dimension = 3;
const static unsigned int numberOfParameters = 4;
Lorenz3D::Lorenz3D():
KernelBasicParameter(4),
KernelBasicVector(3){
Lorenz3D::Lorenz3D() {
init();
}
void Lorenz3D::init() {
// allocation
myParameters = new double[numberOfParameters];
vectorNew = new double[dimension];
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++ ) {
// setting some starting values
for ( unsigned int i = 0; i < myDimension; i++ ) {
vectorNew[i] = vectorOld[i] = 1.0;
}
}
// the main function
void Lorenz3D::iterate() {
swap(vectorNew, vectorOld);
void Lorenz3D::operator()() {
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;
*/
// 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
#define LORENZ_HPP
#include <iostream>
#include <cstdlib>
#include <cassert>
#include <string>
using namespace std;
#include "KernelBasicParameter.hpp"
#include "KernelBasicVector.hpp"
#include "../AttractorKernel.hpp"
#include "BasicKernel.h"
class Lorenz3D : public BasicKernel {
class Lorenz3D : virtual public KernelBasicParameter, virtual public KernelBasicVector {
private:
void init();
public:
Lorenz3D();
Lorenz3D(const unsigned int dimensions);
void iterate();
void * getProperty(const string identifier);
void setProperty(const string identifier, const void * value);
unsigned int getNumberOfParameters();
virtual void operator()();
};

90
kernels/Polynomial.cpp

@ -7,71 +7,49 @@
//
#include "Polynomial.hpp"
using namespace std;
//#include <iostream>
Polynomial::Polynomial():
BasicKernel() {
dimension = 3;
orde = 2;
KernelBasicParameter(0),
KernelBasicVector(3),
orde(2){
init();
}
Polynomial::Polynomial(const unsigned int dimension, const unsigned int orde):
BasicKernel(), dimension(dimension), orde(orde) {
KernelBasicParameter(0),
KernelBasicVector(dimension),
orde(orde) {
init();
}
void Polynomial::init() {
calculateNumberOfParameters();
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);
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;
}
const unsigned int number = calculateNumberOfParameters();
KernelBasicParameter::resetNumberOfParameters(number);
}
void Polynomial::calculateNumberOfParameters() {
unsigned int Polynomial::calculateNumberOfParameters() {
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);
}
numberOfParameters = (unsigned int) n_coef;
cout << numberOfParameters << endl;
const unsigned int output = (unsigned int) n_coef;
return output;
}
void Polynomial::iterate() {
swap(vectorNew, vectorOld);
void Polynomial::operator()() {
std::swap(vectorNew, vectorOld);
unsigned int m = 0;
for ( unsigned int i = 0; i < dimension; i++ ) {
for ( unsigned int i = 0; i < myDimension; i++ ) {
#ifdef HARDDEBUG
cout << "Entering new dimension: " << i << " With m = " << m << endl;
#endif
vectorNew[i] = myParameters[m];
vectorNew[i] = parameters[m];
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) {
double product;
for (unsigned int i = prev_i; i < dimension; i++) {
for (unsigned int i = prev_i; i < myDimension; i++) {
#ifdef HARDDEBUG
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
product = prev_product * vectorOld[i];
vectorNew[curr_dimension] += myParameters[m] * product;
vectorNew[curr_dimension] += parameters[m] * product;
m++;
if (n < orde) {
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
#define POLYNOMIAL_HPP
#include <cassert>
#include <iostream>
#include "KernelBasicParameter.hpp"
#include "KernelBasicVector.hpp"
#include "../AttractorKernel.hpp"
#include "BasicKernel.h"
class Polynomial : virtual public KernelBasicParameter, virtual public KernelBasicVector {
private:
class Polynomial : public BasicKernel {
unsigned int dimension;
unsigned int orde;
unsigned int numberOfParameters;
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);
public:
@ -22,12 +18,7 @@ public:
Polynomial();
Polynomial(const unsigned int dimensions, const unsigned int orde);
void iterate();
void * getProperty(const string identifier);
void setProperty(const string identifier, const void * value);
unsigned int getNumberOfParameters();
virtual void operator()();
};

48
kernels/PolynomialA3D.cpp

@ -8,35 +8,22 @@
#include "PolynomialA3D.hpp"
const static unsigned int dimension = 3;
const static unsigned int numberOfParameters = 3;
PolynomialA3D::PolynomialA3D() {
PolynomialA3D::PolynomialA3D():
KernelBasicParameter(3),
KernelBasicVector(3){
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() {
swap(vectorNew, vectorOld);
void PolynomialA3D::operator()() {
std::swap(vectorNew, vectorOld);
vectorNew[0] = myParameters[0] + vectorOld[1] - vectorOld[1]*vectorOld[2];
vectorNew[1] = myParameters[1] + vectorOld[2] - vectorOld[2]*vectorOld[0];
vectorNew[2] = myParameters[2] + vectorOld[0] - vectorOld[0]*vectorOld[1];
vectorNew[0] = parameters[0] + vectorOld[1] - vectorOld[1]*vectorOld[2];
vectorNew[1] = parameters[1] + vectorOld[2] - vectorOld[2]*vectorOld[0];
vectorNew[2] = parameters[2] + vectorOld[0] - vectorOld[0]*vectorOld[1];
}
/*
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];
}
*/
// 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
#define POLYNOMIALA3D_HPP
#include <cassert>
#include "KernelBasicParameter.hpp"
#include "KernelBasicVector.hpp"
#include "../AttractorKernel.hpp"
#include "BasicKernel.h"
class PolynomialA3D : public BasicKernel {
// of course this can be seen as a subclasse of Polynomial
class PolynomialA3D : virtual public KernelBasicParameter, virtual public KernelBasicVector {
private:
void init();
@ -15,12 +13,7 @@ public:
PolynomialA3D();
void iterate();
void * getProperty(const string identifier);
void setProperty(const string identifier, const void * value);
unsigned int getNumberOfParameters();
virtual void operator()();
};

57
kernels/Unravel3D.cpp

@ -1,62 +1,27 @@
#include "Unravel3D.hpp"
#include <cmath>
const static unsigned int dimension = 3;
const static unsigned int numberOfParameters = 7;
Unravel3D::Unravel3D():
KernelBasicParameter(7),
KernelBasicVector(3){
Unravel3D::Unravel3D(){
init();
}
void Unravel3D::init() {
// allocation
myParameters = new double[numberOfParameters];
vectorNew = new double[dimension];
vectorOld = new double[dimension];
void Unravel3D::operator()() {
std::swap(vectorNew, vectorOld);
// 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] = 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]);
vectorNew[0] = parameters[0]*(vectorOld[2] + parameters[1]);
vectorNew[1] = parameters[2]*(vectorOld[0] + parameters[3]);
vectorNew[2] = parameters[4]*(vectorOld[1] + parameters[5]);
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 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[1] *= 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
#define UNRAVEL_HPP
#include <iostream>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cmath>
using namespace std;
#include "../AttractorKernel.hpp"
#include "BasicKernel.h"
class Unravel3D : public BasicKernel {
void init();
#include "KernelBasicParameter.hpp"
#include "KernelBasicVector.hpp"
class Unravel3D : virtual public KernelBasicParameter, virtual public KernelBasicVector {
public:
Unravel3D();
Unravel3D(const unsigned int dimensions);
void iterate();
void * getProperty(const string identifier);
void setProperty(const string identifier, const void * value);
unsigned int getNumberOfParameters();
virtual void operator()();
};