My Project
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-2017 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 
22 #ifndef mia_core_ICAANALYSISBASE_HH
23 #define mia_core_ICAANALYSISBASE_HH
24 
25 #include <memory>
26 #include <set>
27 #include <boost/concept/requires.hpp>
28 #include <boost/concept_check.hpp>
29 
30 #include <mia/core/defines.hh>
31 #include <mia/core/slopevector.hh>
32 #include <mia/core/factory.hh>
33 
34 namespace mia
35 {
36 
38 {
39 public:
40 
44  enum EApproach {
47  appr_unknown
48  };
49 
50  typedef std::unique_ptr<CIndepCompAnalysis> Pointer;
51 
53  typedef std::set<unsigned int> IndexSet;
54 
56 
64  template <class Iterator>
65  BOOST_CONCEPT_REQUIRES(((::boost::ForwardIterator<Iterator>)),
66  (void))
67  set_row(unsigned row, Iterator begin, Iterator end);
68 
69 
70  virtual void initialize(unsigned int series_length, unsigned int slice_size) = 0;
77  virtual bool run(unsigned int nica, std::vector<std::vector<float>> guess) = 0;
78 
80  virtual std::vector<float> get_feature_row(unsigned int row)const = 0;
81 
83  virtual std::vector<float> get_mix_series(unsigned int row)const = 0;
84 
86  virtual std::vector<float> get_mix(unsigned int idx)const = 0;
87 
94  virtual std::vector<float> get_incomplete_mix(unsigned int idx, const IndexSet& skip)const = 0;
95 
102  virtual std::vector<float> get_partial_mix(unsigned int idx, const IndexSet& use)const = 0;
103 
109  virtual std::vector<float> get_delta_feature(const IndexSet& plus, const IndexSet& minus)const = 0;
110 
116  virtual void set_mixing_series(unsigned int index, const std::vector<float>& series) = 0;
117 
119  virtual CSlopeColumns get_mixing_curves() const = 0;
120 
127  virtual void normalize_ICs() = 0;
128 
134  virtual std::vector<float> normalize_Mix() = 0;
135 
136 
138  virtual unsigned int get_ncomponents() const = 0;
139 
144  virtual void set_max_iterations(int n) = 0;
145 
150  virtual void set_approach(EApproach approach) = 0;
151 
152  virtual void set_deterministic_seed(int seed) = 0;
153 private:
154  virtual void set_row_internal(unsigned row, const std::vector<double>& buffer, double mean) = 0;
155 
156 };
157 
159 
160 
162 {
163 public:
164  static const char *data_descr;
165  static const char *type_descr;
166 
169 
172  void set_deterministic_seed(int seed);
173  CIndepCompAnalysis *create() const __attribute__((warn_unused_result));
174 private:
175  virtual CIndepCompAnalysis *do_create() const __attribute__((warn_unused_result)) = 0;
176  int m_deterministic_seed;
177 };
178 
179 
181 
183 
187 
188 
189 template<> const char *const
191 
193 
197 
198 
199 
201 {
202  return CIndepCompAnalysisFactoryPluginHandler::instance().produce(descr);
203 }
204 
205 
206 
208 template <class Iterator>
209 BOOST_CONCEPT_REQUIRES(((::boost::ForwardIterator<Iterator>)),
210  (void))
211 CIndepCompAnalysis::set_row(unsigned row, Iterator begin, Iterator end)
212 {
213  const unsigned int length = std::distance(begin, end);
214  std::vector<double> buffer(length);
215  unsigned int idx = 0;
216  double mean = 0.0;
217 
218  while (begin != end)
219  mean += (buffer[idx++] = *begin++);
220 
221  mean /= length;
222 
223  for (unsigned int i = 0; i < length; ++i)
224  buffer[i] -= mean;
225 
226  set_row_internal(row, buffer, mean);
227 }
229 
230 }
231 
232 #endif // CICAANALYSISBASE_HH
CSlopeColumns
std::vector< std::vector< float > > CSlopeColumns
class to store the ICA weight matrix
Definition: slopevector.hh:33
THandlerSingleton::instance
static const T & instance()
factory.hh
mia::CIndepCompAnalysis
Definition: core/ica.hh:38
slopevector.hh
mia::CIndepCompAnalysis::set_row
void set_row(unsigned row, Iterator begin, Iterator end)
THandlerSingleton
the singleton that a plug-in handler really is
Definition: handler.hh:159
mia::CIndepCompAnalysisFactory::type_descr
static const char * type_descr
Definition: core/ica.hh:165
mia::CIndepCompAnalysisFactory::CIndepCompAnalysisFactory
CIndepCompAnalysisFactory()
mia::CIndepCompAnalysisFactory::~CIndepCompAnalysisFactory
virtual ~CIndepCompAnalysisFactory()
TPluginHandler
The basic template of all plugin handlers.
Definition: handler.hh:57
mia::CIndepCompAnalysis::appr_symm
@ appr_symm
Definition: core/ica.hh:46
mia::CIndepCompAnalysisFactory::plugin_data
CIndepCompAnalysisFactory plugin_data
Definition: core/ica.hh:168
mia::CIndepCompAnalysisFactory::plugin_type
CIndepCompAnalysisFactory plugin_type
Definition: core/ica.hh:167
CProductBase
The base class for all plug-in created object.
Definition: product_base.hh:41
mia::produce_ica_factory
PIndepCompAnalysisFactory produce_ica_factory(const std::string &descr)
Definition: core/ica.hh:200
mia::CIndepCompAnalysis::EApproach
EApproach
Definition: core/ica.hh:44
mia::CIndepCompAnalysisFactory::create
CIndepCompAnalysis * create() const __attribute__((warn_unused_result))
TFactoryPluginHandler
the Base class for all plugn handlers that deal with factory plugins.
Definition: factory.hh:95
mia::CIndepCompAnalysisFactory::set_deterministic_seed
void set_deterministic_seed(int seed)
EXPORT_CORE
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:101
mia::CIndepCompAnalysisFactory
Definition: core/ica.hh:162
mia::CIndepCompAnalysisFactory::data_descr
static const char * data_descr
Definition: core/ica.hh:164
mia::PIndepCompAnalysis
CIndepCompAnalysis::Pointer PIndepCompAnalysis
Definition: core/ica.hh:158
FACTORY_TRAIT
#define FACTORY_TRAIT(F)
Definition: factory_trait.hh:69
std
Definition: gsl_iterator.hh:324
mia::CIndepCompAnalysis::Pointer
std::unique_ptr< CIndepCompAnalysis > Pointer
Definition: core/ica.hh:50
mia::PIndepCompAnalysisFactory
std::shared_ptr< CIndepCompAnalysisFactory > PIndepCompAnalysisFactory
Definition: core/ica.hh:182
mia::CIndepCompAnalysis::IndexSet
std::set< unsigned int > IndexSet
defines a set of indices used for mixing
Definition: core/ica.hh:53
private
class EXPORT_CORE CMeans private
mia
Definition: convergence_measure.hh:31
defines.hh
mia::CIndepCompAnalysis::appr_defl
@ appr_defl
Definition: core/ica.hh:45
mia::CIndepCompAnalysis::~CIndepCompAnalysis
virtual ~CIndepCompAnalysis()
TFactory
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Definition: factory.hh:51