Commit 3e4c4be1 authored by FPoupon's avatar FPoupon
Browse files

add methods for optimized data structure

parent 3e67e5c4
......@@ -2,7 +2,7 @@
#define _gkg_processing_machinelearning_MachineLearningData_h_
#include <gkg-core-cppext/StdInt.h>
#include <gkg-processing-container/Volume.h>
#include <vector>
......@@ -32,6 +32,11 @@ class MachineLearningData
const Volume< M >& mask,
const std::vector< uint8_t >& selectedRank,
MachineLearningScaler& scaler );
template < class T >
MachineLearningData( const Volume< T >& volume,
const std::vector< Vector3d< int32_t > >& sites,
const std::vector< int16_t >& selectedRank,
MachineLearningScaler& scaler );
virtual ~MachineLearningData();
int32_t getMeasureCount() const;
......
......@@ -16,10 +16,10 @@
template < class T, class M >
inline
gkg::MachineLearningData::MachineLearningData(
const gkg::Volume< T >& volume,
const gkg::Volume< M >& mask,
const std::vector< uint8_t >& selectedRank,
gkg::MachineLearningScaler& scaler )
const gkg::Volume< T >& volume,
const gkg::Volume< M >& mask,
const std::vector< uint8_t >& selectedRank,
gkg::MachineLearningScaler& scaler )
{
try
......@@ -81,8 +81,7 @@ gkg::MachineLearningData::MachineLearningData(
if ( mask( x, y, z ) )
{
data( row, column ) = double( volume( x, y, z, t ) );
column++;
data( row, column++ ) = double( volume( x, y, z, t ) );
}
......@@ -115,4 +114,58 @@ gkg::MachineLearningData::MachineLearningData(
}
template < class T >
inline
gkg::MachineLearningData::MachineLearningData(
const gkg::Volume< T >& volume,
const std::vector< gkg::Vector3d< int32_t > >& sites,
const std::vector< int16_t >& selectedRank,
gkg::MachineLearningScaler& scaler )
{
try
{
gkg::Matrix data( selectedRank.size(), sites.size() );
std::vector< int16_t >::const_iterator
t = selectedRank.begin(),
te = selectedRank.end();
std::vector< gkg::Vector3d< int32_t > >::const_iterator
s, se = sites.end();
int32_t row = 0;
while ( t != te )
{
int32_t column = 0;
s = sites.begin();
while ( s != se )
{
data( row, column++ ) = double( volume( *s, *t ) );
++s;
}
++row;
++t;
}
scaler.scale( data );
_machineLearningDataImplementation =
gkg::MachineLearningSelector::getInstance().getImplementationFactory()->
createMachineLearningDataImplementation( this, data );
}
GKG_CATCH( "template < class T > inline "
"gkg::MachineLearningData::MachineLearningData( "
"const gkg::Volume< T >& volume, "
"std::vector< gkg::Vector3d< int32_t > >& sites, "
"const std::vector< int16_t >& selectedRank, "
"gkg::MachineLearningScaler& scaler )" );
}
#endif
......@@ -32,6 +32,45 @@ gkg::MachineLearningProblem::MachineLearningProblem(
}
gkg::MachineLearningProblem::MachineLearningProblem(
gkg::RCPointer< gkg::MachineLearningData > machineLearningData,
const std::vector< double >& inLabels )
: _machineLearningData( machineLearningData )
{
try
{
gkg::Vector labels( inLabels.size() );
std::vector< double >::const_iterator
l = inLabels.begin(),
le = inLabels.end();
int32_t k = 0;
while ( l != le )
{
labels( k++ ) = *l;
++l;
}
_machineLearningProblemImplementation =
gkg::MachineLearningSelector::getInstance().getImplementationFactory()->
createMachineLearningProblemImplementation(
this,
*_machineLearningData,
labels );
}
GKG_CATCH( "gkg::MachineLearningProblem::MachineLearningProblem( "
"gkg::RCPointer< gkg::MachineLearningData > machineLearningData, "
"gkg::Vector& labels, "
"const std::vector< uint8_t >& selectedLabels )" );
}
gkg::MachineLearningProblem::MachineLearningProblem(
gkg::RCPointer< gkg::MachineLearningData > machineLearningData,
gkg::Vector& inLabels,
......
......@@ -25,6 +25,9 @@ class MachineLearningProblem
MachineLearningProblem(
RCPointer< MachineLearningData > machineLearningData,
Vector& labels );
MachineLearningProblem(
RCPointer< MachineLearningData > machineLearningData,
const std::vector< double >& labels );
MachineLearningProblem(
RCPointer< MachineLearningData > machineLearningData,
Vector& labels,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment