|
@ -1,9 +1,10 @@ |
|
|
|
|
|
#include "../Logger.hpp" |
|
|
#include "Normalizer.hpp" |
|
|
#include "Normalizer.hpp" |
|
|
|
|
|
|
|
|
#pragma mark - |
|
|
#pragma mark - |
|
|
#pragma mark memory |
|
|
#pragma mark memory |
|
|
|
|
|
|
|
|
Normalizer::Normalizer(unsigned int dimension) : Projector(dimension, dimension) { |
|
|
Normalizer::Normalizer(unsigned int dimension) : Projector(dimension, dimension), factor(1) { |
|
|
ready = false; |
|
|
ready = false; |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
@ -12,16 +13,20 @@ Normalizer::Normalizer(unsigned int dimension) : Projector(dimension, dimension) |
|
|
LogError("Couldn't construct Normalizer (Projector): %s\n", e.what()); |
|
|
LogError("Couldn't construct Normalizer (Projector): %s\n", e.what()); |
|
|
deallocate(); |
|
|
deallocate(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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() { |
|
|
Normalizer::~Normalizer() { |
|
|
//dtor
|
|
|
deallocate(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Normalizer::allocate(){ |
|
|
void Normalizer::allocate(){ |
|
|
range_min = new double[outputDimension]; |
|
|
range_min = new double[outputDimension]; |
|
|
range_max = new double[outputDimension]; |
|
|
range_max = new double[outputDimension]; |
|
|
offset = new double[outputDimension] |
|
|
offset = new double[outputDimension]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Normalizer::deallocate(){ |
|
|
void Normalizer::deallocate(){ |
|
@ -37,9 +42,9 @@ void Normalizer::deallocate(){ |
|
|
#pragma mark plot |
|
|
#pragma mark plot |
|
|
|
|
|
|
|
|
void Normalizer::project(const double * point) { |
|
|
void Normalizer::project(const double * point) { |
|
|
|
|
|
for ( unsigned int i = 0; i < inputDimension; ++i ) { |
|
|
projectedPoint[0] = point[0]*factor + offset[0]; |
|
|
projectedPoint[0] = point[0]*factor + offset[0]; |
|
|
projectedPoint[1] = point[1]*factor + offset[1]; |
|
|
} |
|
|
projectedPoint[2] = point[2]*factor + offset[2]; |
|
|
|
|
|
|
|
|
|
|
|
if(!ready){ |
|
|
if(!ready){ |
|
|
static unsigned int state = 0; |
|
|
static unsigned int state = 0; |
|
@ -47,9 +52,8 @@ void Normalizer::project(const double * point) { |
|
|
switch(state) { |
|
|
switch(state) { |
|
|
case 0: |
|
|
case 0: |
|
|
init_range(); |
|
|
init_range(); |
|
|
state = kUpdate; |
|
|
|
|
|
break; |
|
|
break; |
|
|
case 20000: |
|
|
case 500000: |
|
|
finish_range(); |
|
|
finish_range(); |
|
|
ready = true; |
|
|
ready = true; |
|
|
break; |
|
|
break; |
|
@ -57,31 +61,33 @@ void Normalizer::project(const double * point) { |
|
|
update_range(); |
|
|
update_range(); |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
++state; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#pragma mark - |
|
|
#pragma mark - |
|
|
#pragma mark setting up |
|
|
#pragma mark setting up |
|
|
|
|
|
|
|
|
void Projector::init_range() { |
|
|
void Normalizer::init_range() { |
|
|
for ( unsigned int i = 0; i < intern_dim; i++ ) { |
|
|
for ( unsigned int i = 0; i < outputDimension; i++ ) { |
|
|
range_min[i] = range_max[i] = project_point[i]; |
|
|
range_min[i] = range_max[i] = projectedPoint[i]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Projector::update_range() { |
|
|
void Normalizer::update_range() { |
|
|
for ( unsigned int i = 0; i < intern_dim; i++ ) { |
|
|
for ( unsigned int i = 0; i < outputDimension; i++ ) { |
|
|
if ( project_point[i] < range_min[i] ) { |
|
|
if ( projectedPoint[i] < range_min[i] ) { |
|
|
range_min[i] = project_point[i]; |
|
|
range_min[i] = projectedPoint[i]; |
|
|
} else if ( project_point[i] > range_max[i] ) { |
|
|
} else if ( projectedPoint[i] > range_max[i] ) { |
|
|
range_max[i] = project_point[i]; |
|
|
range_max[i] = projectedPoint[i]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Projector::finish_range() { |
|
|
void Normalizer::finish_range() { |
|
|
factor = 2.0 / (range_max[0] - range_min[0]); |
|
|
factor = 2.0 / (range_max[0] - range_min[0]); |
|
|
for ( unsigned int i = 1; i < intern_dim; i++ ) { |
|
|
for ( unsigned int i = 1; i < outputDimension; i++ ) { |
|
|
double dist = range_max[i] - range_min[i]; |
|
|
double dist = range_max[i] - range_min[i]; |
|
|
if ( factor * dist > 2.0 ) { |
|
|
if ( factor * dist > 2.0 ) { |
|
|
factor = 2.0 / dist; |
|
|
factor = 2.0 / dist; |
|
@ -90,7 +96,7 @@ void Projector::finish_range() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for ( unsigned int i = 0; i < intern_dim; i++ ) { |
|
|
for ( unsigned int i = 0; i < outputDimension; i++ ) { |
|
|
offset[i] = -0.5*factor*(range_min[i] + range_max[i]); |
|
|
offset[i] = -0.5*factor*(range_min[i] + range_max[i]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|