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 
37 
39 {
40 public:
41 
45  enum EApproach {
48  appr_unknown
49  };
50 
51  typedef std::unique_ptr<CIndepCompAnalysis> Pointer;
52 
54  typedef std::set<unsigned int> IndexSet;
55 
56  virtual ~CIndepCompAnalysis();
57 
65  template <class Iterator>
66  BOOST_CONCEPT_REQUIRES(((::boost::ForwardIterator<Iterator>)),
67  (void))
68  set_row(unsigned row, Iterator begin, Iterator end);
69 
70 
71  virtual void initialize(unsigned int series_length, unsigned int slice_size) = 0;
78  virtual bool run(unsigned int nica, std::vector<std::vector<float> > guess) = 0;
79 
81  virtual std::vector<float> get_feature_row(unsigned int row)const = 0;
82 
84  virtual std::vector<float> get_mix_series(unsigned int row)const = 0;
85 
87  virtual std::vector<float> get_mix(unsigned int idx)const = 0;
88 
95  virtual std::vector<float> get_incomplete_mix(unsigned int idx, const IndexSet& skip)const = 0;
96 
103  virtual std::vector<float> get_partial_mix(unsigned int idx, const IndexSet& use)const = 0;
104 
110  virtual std::vector<float> get_delta_feature(const IndexSet& plus, const IndexSet& minus)const = 0;
111 
117  virtual void set_mixing_series(unsigned int index, const std::vector<float>& series) = 0;
118 
120  virtual CSlopeColumns get_mixing_curves() const = 0;
121 
128  virtual void normalize_ICs() = 0;
129 
135  virtual std::vector<float> normalize_Mix() = 0;
136 
137 
139  virtual unsigned int get_ncomponents() const = 0;
140 
145  virtual void set_max_iterations(int n) = 0;
146 
151  virtual void set_approach(EApproach approach) = 0;
152 
153  virtual void set_deterministic_seed(int seed) = 0;
154 private:
155  virtual void set_row_internal(unsigned row, const std::vector<double>& buffer, double mean) = 0;
156 
157 };
158 
160 
161 
163 public:
164  static const char *data_descr;
165  static const char *type_descr;
166 
169 
171  virtual ~CIndepCompAnalysisFactory();
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 
185 typedef THandlerSingleton<TFactoryPluginHandler<CIndepCompAnalysisFactoryPlugin> >
187 
188 
189 template<> const char * const
191 
193 
197 
198 
199 
200 inline PIndepCompAnalysisFactory produce_ica_factory(const std::string& descr)
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  mean /= length;
221  for(unsigned int i = 0; i < length; ++i)
222  buffer[i] -= mean;
223  set_row_internal(row, buffer, mean);
224 }
226 
227 }
228 
229 #endif // CICAANALYSISBASE_HH
static const char * data_descr
Definition: core/ica.hh:164
the singleton that a plug-in handler really is
Definition: handler.hh:157
void set_row(unsigned row, Iterator begin, Iterator end)
CIndepCompAnalysisFactory plugin_type
Definition: core/ica.hh:167
std::shared_ptr< CIndepCompAnalysisFactory > PIndepCompAnalysisFactory
Definition: core/ica.hh:182
class EXPORT_CORE CMeans private
CIndepCompAnalysis::Pointer PIndepCompAnalysis
Definition: core/ica.hh:159
PIndepCompAnalysisFactory produce_ica_factory(const std::string &descr)
Definition: core/ica.hh:200
static const char * type_descr
Definition: core/ica.hh:165
#define FACTORY_TRAIT(F)
This is tha base of all plugins that create "things", like filters, cost functions time step operator...
Definition: factory.hh:49
#define EXPORT_CORE
Macro to manage Visual C++ style dllimport/dllexport.
Definition: defines.hh:101
The base class for all plug-in created object.
Definition: product_base.hh:40
static const T & instance()
the Base class for all plugn handlers that deal with factory plugins.
Definition: factory.hh:93
std::vector< std::vector< float > > CSlopeColumns
class to store the ICA weight matrix
Definition: slopevector.hh:33
std::unique_ptr< CIndepCompAnalysis > Pointer
Definition: core/ica.hh:51
CIndepCompAnalysisFactory plugin_data
Definition: core/ica.hh:168
std::set< unsigned int > IndexSet
defines a set of indices used for mixing
Definition: core/ica.hh:54
The basic template of all plugin handlers.
Definition: handler.hh:56