core/ica.hh
Go to the documentation of this file.
1 /* -*- mia-c++ -*-
2  *
3  * This file is part of MIA - a toolbox for medical image analysis
4  * Copyright (c) Leipzig, Madrid 1999-2013 Gert Wollny
5  *
6  * MIA is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with MIA; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef mia_core_ica_hh
22 #define mia_core_ica_hh
23 
24 #include <set>
25 #include <vector>
26 #include <mia/core/defines.hh>
27 #include <mia/core/slopevector.hh>
28 #include <itpp/signal/fastica.h>
29 #include <boost/concept/requires.hpp>
30 #include <boost/concept_check.hpp>
31 
32 
34 
42 public:
43 
45  typedef itpp::Vec<itpp::mat::value_type> itppvector;
49  CICAAnalysis(const itpp::mat& ic, const itpp::mat& mix, const std::vector<float>& mean );
50 
56  CICAAnalysis(size_t series_length, size_t slice_size);
57 
58 
59  ~CICAAnalysis();
60 
61 
63  typedef std::set<size_t> IndexSet;
64 
72  template <class Iterator>
73  BOOST_CONCEPT_REQUIRES(((::boost::ForwardIterator<Iterator>)),
74  (void))
75  set_row(size_t row, Iterator begin, Iterator end);
76 
77 
84  bool run(size_t nica, std::vector<std::vector<float> > guess);
85 
93  void run_auto(int max_ica, int min_ica, float corr_thresh=0.9);
94 
95 
97  std::vector<float> get_feature_row(size_t row)const;
98 
100  std::vector<float> get_mix_series(size_t row)const;
101 
103  std::vector<float> get_mix(size_t idx)const;
104 
111  std::vector<float> get_incomplete_mix(size_t idx, const IndexSet& skip)const;
112 
119  std::vector<float> get_partial_mix(size_t idx, const IndexSet& use)const;
120 
126  std::vector<float> get_delta_feature(const IndexSet& plus, const IndexSet& minus)const;
127 
133  void set_mixing_series(size_t index, const std::vector<float>& series);
134 
136  CSlopeColumns get_mixing_curves() const;
137 
144  void normalize_ICs();
145 
151  std::vector<float> normalize_Mix();
152 
153 
155  size_t get_ncomponents() const;
156 
161  void set_max_iterations(int n);
162 
167  void set_approach(int approach);
168 private:
169  void set_row(int row, const itppvector& buffer, double mean);
170 
171  struct CICAAnalysisImpl *impl;
172 
173 };
174 
176 template <class Iterator>
177 BOOST_CONCEPT_REQUIRES(((::boost::ForwardIterator<Iterator>)),
178  (void))
179 CICAAnalysis::set_row(size_t row, Iterator begin, Iterator end)
180 {
181  const size_t length = std::distance(begin, end);
182  itppvector buffer(length);
183  size_t idx = 0;
184  double mean = 0.0;
185 
186  while (begin != end)
187  mean += (buffer[idx++] = *begin++);
188  mean /= length;
189  for(size_t i = 0; i < length; ++i)
190  buffer[i] -= mean;
191  set_row(row, buffer, mean);
192 }
194 
196 
197 #endif