~ubuntu-branches/ubuntu/precise/openwalnut/precise

« back to all changes in this revision

Viewing changes to src/modules/gaussProcesses/test/WGaussProcess_test.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Eichelbaum
  • Date: 2011-06-21 10:26:54 UTC
  • Revision ID: james.westby@ubuntu.com-20110621102654-rq0zf436q949biih
Tags: upstream-1.2.5
ImportĀ upstreamĀ versionĀ 1.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//---------------------------------------------------------------------------
 
2
//
 
3
// Project: OpenWalnut ( http://www.openwalnut.org )
 
4
//
 
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
 
6
// For more information see http://www.openwalnut.org/copying
 
7
//
 
8
// This file is part of OpenWalnut.
 
9
//
 
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.
 
14
//
 
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.
 
19
//
 
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/>.
 
22
//
 
23
//---------------------------------------------------------------------------
 
24
 
 
25
#ifndef WGAUSSPROCESS_TEST_H
 
26
#define WGAUSSPROCESS_TEST_H
 
27
 
 
28
#include <vector>
 
29
 
 
30
#include <cxxtest/TestSuite.h>
 
31
 
 
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"
 
37
 
 
38
/**
 
39
 * Testsuite for the Gaussian process class.
 
40
 */
 
41
class WGaussProcessTest : public CxxTest::TestSuite
 
42
{
 
43
public:
 
44
    /**
 
45
     * If the point for the mean function is outside of the environment with distance R the mean
 
46
     * should equals to zero.
 
47
     */
 
48
    void testMeanFunctionOutsideOf_R_Environment( void )
 
49
    {
 
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 );
 
52
    }
 
53
 
 
54
    /**
 
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!)
 
57
     */
 
58
    void testMeanFunctionInsideOf_R_Environment( void )
 
59
    {
 
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 );
 
62
    }
 
63
 
 
64
    /**
 
65
     * Inside of the R environment the values should be monoton increasing in direction to the tract
 
66
     * segements.
 
67
     */
 
68
    void testMeanFunctionMonotonyIn_R_Environment( void )
 
69
    {
 
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 ) ) );
 
73
    }
 
74
 
 
75
    /**
 
76
     * The mean value on the sample point is the maximum level set.
 
77
     */
 
78
    void testMeanFunctionOnSamplePoint( void )
 
79
    {
 
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 );
 
82
    }
 
83
 
 
84
//    void testMeanFunctionOnSegmentButNotOnSamplePoint( void )
 
85
//    {
 
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 );
 
88
//    }
 
89
 
 
90
    /**
 
91
     * Non overlapping processes should return 0.0 as inner product.
 
92
     */
 
93
    void testInnerProductOnNonOverlappingIndicatorFunctions( void )
 
94
    {
 
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 );
 
98
    }
 
99
 
 
100
    /**
 
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.
 
104
     */
 
105
    void testPartialOverlapWith10Points( void )
 
106
    {
 
107
        boost::shared_ptr< std::vector< WFiber > > tracts( new std::vector< WFiber > );
 
108
        WFiber tract;
 
109
        for( size_t i = 0; i < 10; ++i )
 
110
        {
 
111
            tract.push_back( WPosition( static_cast< double >( i ), 0.0, 0.0 ) );
 
112
        }
 
113
        tracts->push_back( tract );
 
114
        tract.clear();
 
115
        for( size_t i = 0; i < 5; ++i )
 
116
        {
 
117
            tract.push_back( WPosition( static_cast< double >( i ), 0.0, 0.0 ) );
 
118
        }
 
119
        for( size_t i = 1; i < 6; ++i )
 
120
        {
 
121
            tract.push_back( WPosition( 4.0, static_cast< double >( i ), 0.0 ) );
 
122
        }
 
123
        tracts->push_back( tract );
 
124
        boost::shared_ptr< WDataSetFiberVector > fvDS( new WDataSetFiberVector( tracts ) );
 
125
 
 
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 );
 
130
    }
 
131
 
 
132
    /**
 
133
     * This is to test the converge nearly to 50 percent and should always be better than with just
 
134
     * 100 points.
 
135
     */
 
136
    void testPartialOverlapWith100Points( void )
 
137
    {
 
138
        boost::shared_ptr< std::vector< WFiber > > tracts( new std::vector< WFiber > );
 
139
        WFiber tract;
 
140
        for( size_t i = 0; i < 100; ++i )
 
141
        {
 
142
            tract.push_back( WPosition( static_cast< double >( i ), 0.0, 0.0 ) );
 
143
        }
 
144
        tracts->push_back( tract );
 
145
        tract.clear();
 
146
        for( size_t i = 0; i < 50; ++i )
 
147
        {
 
148
            tract.push_back( WPosition( static_cast< double >( i ), 0.0, 0.0 ) );
 
149
        }
 
150
        for( size_t i = 1; i < 51; ++i )
 
151
        {
 
152
            tract.push_back( WPosition( 49.0, static_cast< double >( i ), 0.0 ) );
 
153
        }
 
154
        tracts->push_back( tract );
 
155
        boost::shared_ptr< WDataSetFiberVector > fvDS( new WDataSetFiberVector( tracts ) );
 
156
 
 
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 );
 
161
    }
 
162
 
 
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.
 
165
//
 
166
//    void testSmallTractAlongLongTract( void )
 
167
//    {
 
168
//        boost::shared_ptr< std::vector< WFiber > > tracts( new std::vector< WFiber > );
 
169
//        WFiber tract;
 
170
//        for( size_t i = 0; i < 1000; ++i )
 
171
//        {
 
172
//            tract.push_back( WPosition( static_cast< double >( i ), 0.0, 0.0 ) );
 
173
//        }
 
174
//        tracts->push_back( tract );
 
175
//        tract.clear();
 
176
//        for( size_t i = 20; i < 25; ++i )
 
177
//        {
 
178
//            tract.push_back( WPosition( static_cast< double >( i ), 0.0, 0.0 ) );
 
179
//        }
 
180
//        tracts->push_back( tract );
 
181
//        boost::shared_ptr< WDataSetFiberVector > fvDS( new WDataSetFiberVector( tracts ) );
 
182
//
 
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 );
 
189
//    }
 
190
 
 
191
protected:
 
192
    /**
 
193
     * SetUp test environment.
 
194
     */
 
195
    void setUp( void )
 
196
    {
 
197
        WLogger::startup();
 
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 ) );
 
204
 
 
205
        boost::shared_ptr< std::vector< WFiber > > tracts( new std::vector< WFiber > );
 
206
        WFiber tract0;
 
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 );
 
212
        WFiber tract1;
 
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();
 
218
 
 
219
        m_tractID = 0;
 
220
    }
 
221
 
 
222
    /**
 
223
     * Clean up everything.
 
224
     */
 
225
    void tearDown( void )
 
226
    {
 
227
        m_tracts.reset();
 
228
        m_emptyDTIDataSet.reset();
 
229
    }
 
230
 
 
231
private:
 
232
    /**
 
233
     * Dummy DTI dataset.
 
234
     */
 
235
    boost::shared_ptr< WDataSetDTI > m_emptyDTIDataSet;
 
236
 
 
237
    /**
 
238
     * Dummy tract dataset for Gaussian process generation.
 
239
     */
 
240
    boost::shared_ptr< WDataSetFibers > m_tracts;
 
241
 
 
242
    /**
 
243
     * A single tract id;
 
244
     */
 
245
    size_t m_tractID;
 
246
};
 
247
 
 
248
#endif  // WGAUSSPROCESS_TEST_H