1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
23
//---------------------------------------------------------------------------
25
#ifndef WGAUSSPROCESS_TEST_H
26
#define WGAUSSPROCESS_TEST_H
30
#include <cxxtest/TestSuite.h>
32
#include "core/common/datastructures/WFiber.h"
33
#include "core/common/WLogger.h"
34
#include "core/dataHandler/WDataSetDTI.h"
35
#include "core/dataHandler/WDataSetFiberVector.h"
36
#include "../WGaussProcess.h"
39
* Testsuite for the Gaussian process class.
41
class WGaussProcessTest : public CxxTest::TestSuite
45
* If the point for the mean function is outside of the environment with distance R the mean
46
* should equals to zero.
48
void testMeanFunctionOutsideOf_R_Environment( void )
50
WGaussProcess p( m_tractID, m_tracts, m_emptyDTIDataSet );
51
TS_ASSERT_DELTA( p.mean( WPosition( -( p.m_R + wlimits::DBL_EPS ), 0.0, 0.0 ) ), 0.0, wlimits::DBL_EPS );
55
* Inside of the R environment there shall be values unequal to zero. (-p.m_R + EPS would be not change the mean value
56
* significantly, we have to go a little more inside the kernel!)
58
void testMeanFunctionInsideOf_R_Environment( void )
60
WGaussProcess p( m_tractID, m_tracts, m_emptyDTIDataSet );
61
TS_ASSERT( std::abs( p.mean( WPosition( -p.m_R + 1.0e-7, 0.0, 0.0 ) ) ) > wlimits::DBL_EPS );
65
* Inside of the R environment the values should be monoton increasing in direction to the tract
68
void testMeanFunctionMonotonyIn_R_Environment( void )
70
WGaussProcess p( m_tractID, m_tracts, m_emptyDTIDataSet );
71
TS_ASSERT( std::abs( p.mean( WPosition( -p.m_R + 1.0e-8, 0.0, 0.0 ) ) ) >
72
p.mean( WPosition( -p.m_R + 0.5e-8, 0.0, 0.0 ) ) );
76
* The mean value on the sample point is the maximum level set.
78
void testMeanFunctionOnSamplePoint( void )
80
WGaussProcess p( m_tractID, m_tracts, m_emptyDTIDataSet );
81
TS_ASSERT_DELTA( p.mean( WPosition( 0.0, 0.0, 0.0 ) ), p.m_maxLevel, 2 * wlimits::DBL_EPS );
84
// void testMeanFunctionOnSegmentButNotOnSamplePoint( void )
86
// WGaussProcess p( m_tract, m_emptyDTIDataSet );
87
// TS_ASSERT_DELTA( p.mean( WPosition( 0.4, 0.4, 0.0 ) ), p.m_maxLevel, wlimits::DBL_EPS );
91
* Non overlapping processes should return 0.0 as inner product.
93
void testInnerProductOnNonOverlappingIndicatorFunctions( void )
95
WGaussProcess p1( 0, m_tracts, m_emptyDTIDataSet );
96
WGaussProcess p2( 1, m_tracts, m_emptyDTIDataSet );
97
TS_ASSERT_DELTA( gauss::innerProduct( p1, p2 ), 0.0, wlimits::DBL_EPS );
101
* Its hard to find an example where the integral over the spheres is exactly determined, incase
102
* of an overlap and no full overlap. Hence we take a tract with many points where almost 50
103
* percent will overlap. When increasing the number of points the innerproduct should converge.
105
void testPartialOverlapWith10Points( void )
107
boost::shared_ptr< std::vector< WFiber > > tracts( new std::vector< WFiber > );
109
for( size_t i = 0; i < 10; ++i )
111
tract.push_back( WPosition( static_cast< double >( i ), 0.0, 0.0 ) );
113
tracts->push_back( tract );
115
for( size_t i = 0; i < 5; ++i )
117
tract.push_back( WPosition( static_cast< double >( i ), 0.0, 0.0 ) );
119
for( size_t i = 1; i < 6; ++i )
121
tract.push_back( WPosition( 4.0, static_cast< double >( i ), 0.0 ) );
123
tracts->push_back( tract );
124
boost::shared_ptr< WDataSetFiberVector > fvDS( new WDataSetFiberVector( tracts ) );
126
WGaussProcess p1( 0, fvDS->toWDataSetFibers(), m_emptyDTIDataSet );
127
WGaussProcess p2( 1, fvDS->toWDataSetFibers(), m_emptyDTIDataSet );
128
double overlap = gauss::innerProduct( p1, p2 ) / ( std::sqrt( gauss::innerProduct( p1, p1 ) ) * std::sqrt( gauss::innerProduct( p2, p2 ) ) );
129
TS_ASSERT_DELTA( overlap, 0.5687, 0.003 );
133
* This is to test the converge nearly to 50 percent and should always be better than with just
136
void testPartialOverlapWith100Points( void )
138
boost::shared_ptr< std::vector< WFiber > > tracts( new std::vector< WFiber > );
140
for( size_t i = 0; i < 100; ++i )
142
tract.push_back( WPosition( static_cast< double >( i ), 0.0, 0.0 ) );
144
tracts->push_back( tract );
146
for( size_t i = 0; i < 50; ++i )
148
tract.push_back( WPosition( static_cast< double >( i ), 0.0, 0.0 ) );
150
for( size_t i = 1; i < 51; ++i )
152
tract.push_back( WPosition( 49.0, static_cast< double >( i ), 0.0 ) );
154
tracts->push_back( tract );
155
boost::shared_ptr< WDataSetFiberVector > fvDS( new WDataSetFiberVector( tracts ) );
157
WGaussProcess p1( 0, fvDS->toWDataSetFibers(), m_emptyDTIDataSet );
158
WGaussProcess p2( 1, fvDS->toWDataSetFibers(), m_emptyDTIDataSet );
159
double overlap = gauss::innerProduct( p1, p2 ) / ( std::sqrt( gauss::innerProduct( p1, p1 ) ) * std::sqrt( gauss::innerProduct( p2, p2 ) ) );
160
TS_ASSERT_DELTA( overlap, 0.5065, 0.003 );
163
// TODO(math): This is just about to understand what the outcome of small tracts along long tracts in terms of Gaussian process similarity is, and
164
// can be removed when I understood this to full extent.
166
// void testSmallTractAlongLongTract( void )
168
// boost::shared_ptr< std::vector< WFiber > > tracts( new std::vector< WFiber > );
170
// for( size_t i = 0; i < 1000; ++i )
172
// tract.push_back( WPosition( static_cast< double >( i ), 0.0, 0.0 ) );
174
// tracts->push_back( tract );
176
// for( size_t i = 20; i < 25; ++i )
178
// tract.push_back( WPosition( static_cast< double >( i ), 0.0, 0.0 ) );
180
// tracts->push_back( tract );
181
// boost::shared_ptr< WDataSetFiberVector > fvDS( new WDataSetFiberVector( tracts ) );
183
// WGaussProcess p1( 0, fvDS->toWDataSetFibers(), m_emptyDTIDataSet );
184
// WGaussProcess p2( 1, fvDS->toWDataSetFibers(), m_emptyDTIDataSet );
185
// std::cout << gauss::innerProduct( p1, p2 ) << std::endl;
186
// std::cout << std::sqrt( gauss::innerProduct( p1, p1 ) ) << " " << std::sqrt( gauss::innerProduct( p2, p2 ) ) << std::endl;
187
// double overlap = gauss::innerProduct( p1, p2 ) / ( std::sqrt( gauss::innerProduct( p1, p1 ) ) * std::sqrt( gauss::innerProduct( p2, p2 ) ) );
188
// TS_ASSERT_DELTA( overlap, 0.501, 0.003 );
193
* SetUp test environment.
198
float dataArray[6] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }; // NOLINT array init list
199
boost::shared_ptr< std::vector< float > > data( new std::vector< float >( &dataArray[0],
200
&dataArray[0] + sizeof( dataArray ) / sizeof( float ) ) );
201
boost::shared_ptr< WValueSetBase > newValueSet( new WValueSet< float >( 1, 6, data, W_DT_FLOAT ) );
202
boost::shared_ptr< WGrid > newGrid( new WGridRegular3D( 1, 1, 1 ) );
203
m_emptyDTIDataSet = boost::shared_ptr< WDataSetDTI >( new WDataSetDTI( newValueSet, newGrid ) );
205
boost::shared_ptr< std::vector< WFiber > > tracts( new std::vector< WFiber > );
207
tract0.push_back( WPosition( 0.0, 0.0, 0.0 ) );
208
tract0.push_back( WPosition( 1.0, 1.0, 0.0 ) );
209
tract0.push_back( WPosition( 1.0, 2.0, 0.0 ) );
210
tract0.push_back( WPosition( 2.0, 2.0, 0.0 ) );
211
tracts->push_back( tract0 );
213
tract1.push_back( WPosition( 2.0 + 2.0 * sqrt( 8.0 ), 2.0, 0.0 ) );
214
tract1.push_back( WPosition( 2.0 + 2.0 * sqrt( 8.0 ) + 1.0, 2.0, 0.0 ) );
215
tracts->push_back( tract1 );
216
boost::shared_ptr< WDataSetFiberVector > fvDS( new WDataSetFiberVector( tracts ) );
217
m_tracts = fvDS->toWDataSetFibers();
223
* Clean up everything.
225
void tearDown( void )
228
m_emptyDTIDataSet.reset();
235
boost::shared_ptr< WDataSetDTI > m_emptyDTIDataSet;
238
* Dummy tract dataset for Gaussian process generation.
240
boost::shared_ptr< WDataSetFibers > m_tracts;
248
#endif // WGAUSSPROCESS_TEST_H