My old project for strange attractors
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

103 lines
2.1 KiB

14 years ago
#include "../Logger.hpp"
#include "Normalizer.hpp"
#pragma mark -
#pragma mark memory
14 years ago
Normalizer::Normalizer(unsigned int dimension) : Projector(dimension, dimension), factor(1) {
ready = false;
try {
allocate();
14 years ago
} catch(std::exception& e) {
LogError("Couldn't construct Normalizer (Projector): %s\n", e.what());
deallocate();
}
14 years ago
std::fill_n(range_min, outputDimension, 0.0);
std::fill_n(range_max, outputDimension, 0.0);
std::fill_n(offset, outputDimension, 0.0);
}
Normalizer::~Normalizer() {
14 years ago
deallocate();
}
14 years ago
void Normalizer::allocate() {
range_min = new double[outputDimension];
range_max = new double[outputDimension];
14 years ago
offset = new double[outputDimension];
}
14 years ago
void Normalizer::deallocate() {
delete[] range_min;
range_min = 0;
delete[] range_max;
range_max = 0;
delete[] offset;
offset = 0;
}
#pragma mark -
#pragma mark plot
14 years ago
void Normalizer::project(const double* point) {
for(unsigned int i = 0; i < inputDimension; ++i) {
projectedPoint[i] = point[i]*factor + offset[i];
14 years ago
}
14 years ago
if(!ready) {
static unsigned int state = 0;
switch(state) {
case 0:
init_range();
break;
case 1000000:
finish_range();
ready = true;
break;
default:
update_range();
break;
}
14 years ago
++state;
}
}
#pragma mark -
#pragma mark setting up
14 years ago
void Normalizer::init_range() {
14 years ago
for(unsigned int i = 0; i < outputDimension; i++) {
14 years ago
range_min[i] = range_max[i] = projectedPoint[i];
}
}
14 years ago
void Normalizer::update_range() {
14 years ago
for(unsigned int i = 0; i < outputDimension; i++) {
if(projectedPoint[i] < range_min[i]) {
14 years ago
range_min[i] = projectedPoint[i];
14 years ago
} else if(projectedPoint[i] > range_max[i]) {
14 years ago
range_max[i] = projectedPoint[i];
}
}
}
14 years ago
void Normalizer::finish_range() {
factor = 1.0 / (range_max[0] - range_min[0]);
14 years ago
for(unsigned int i = 1; i < outputDimension; i++) {
double dist = range_max[i] - range_min[i];
if(factor * dist > 1.0) {
factor = 1.0 / dist;
//teh_size = canvas->size[i];
LogDebug("Crap for dimension %d\n", i);
}
}
14 years ago
for(unsigned int i = 0; i < outputDimension; i++) {
offset[i] = -0.5*factor*(range_min[i] + range_max[i]);
}
}