Cypress  1.0
C++ Spiking Neural Network Simulation Framework
transformation_util.hpp
Go to the documentation of this file.
1 /*
2  * Cypress -- C++ Spiking Neural Network Simulation Framework
3  * Copyright (C) 2016 Andreas Stöckel
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
27 #ifndef CYPRESS_CORE_TRANSFORMATION_UTIL_HPP
28 #define CYPRESS_CORE_TRANSFORMATION_UTIL_HPP
29 
30 #include <cypress/core/network.hpp>
32 
33 namespace cypress {
38 template <typename SourceType, typename TargetType>
40 protected:
41  const NeuronType *src_type() { return &SourceType::inst(); }
42  const NeuronType *tar_type() { return &TargetType::inst(); }
43 
45  TransformationAuxData &) override
46  {
47  NetworkBase tar = src.clone();
48  for (size_t i = 0; i < src.population_count(); i++) {
49  auto src_data = src.population_data(i);
50  if (src_data->type() == src_type()) {
51  // Fetch the pointer at the source data
52  auto tar_data = tar.population_data(i);
53 
54  // Create a new PopulationData instance without the source data
55  // and adapted target type at the pointer location
56  const size_t size = src_data->size();
57  *tar_data = PopulationData(size, tar_type(), src_data->name());
58 
59  // Initialize the parameters and signals of the new population
60  NeuronParameters(tar_data, 0, size) =
61  typename TargetType::Parameters();
62  NeuronSignals(tar_data, 0, size) =
63  typename TargetType::Signals();
64 
65  // Fetch the source and target population
66  auto src_pop = Population<SourceType>(PopulationBase(src, i));
67  auto tar_pop = Population<TargetType>(PopulationBase(tar, i));
68 
69  // Perform the parameter transformation -- only perform the
70  // parameter transformation once in case the parameters are
71  // homogeneous -- otherwise iterate over each individual neuron
72  if (src_data->homogeneous_parameters() &&
73  !do_dehomogenise_parameters(src_pop.parameters())) {
74  do_transform_parameters(src_pop.parameters(),
75  tar_pop.parameters());
76  }
77  else {
78  for (size_t j = 0; j < src_pop.size(); j++) {
79  do_transform_parameters(src_pop[j].parameters(),
80  tar_pop[j].parameters());
81  }
82  }
83 
84  // Similarly to above, transform the record flags
85  if (src_data->homogeneous_record()) {
86  do_transform_signals(src_pop.signals(), tar_pop.signals());
87  }
88  else {
89  for (size_t j = 0; j < src_pop.size(); j++) {
90  do_transform_signals(src_pop[j].signals(),
91  tar_pop[j].signals());
92  }
93  }
94  }
95  }
96  return tar;
97  }
98 
99  virtual void do_transform_parameters(
100  const typename SourceType::Parameters &src,
101  typename TargetType::Parameters tar) = 0;
102 
104  const typename SourceType::Parameters &)
105  {
106  return false;
107  }
108 
109  virtual void do_transform_signals(const typename SourceType::Signals &src,
110  typename TargetType::Signals tar) = 0;
111 
112 public:
114 };
115 }
116 
117 #endif /* CYPRESS_CORE_TRANSFORMATION_UTIL_HPP */
Definition: neurons_base.hpp:54
virtual bool do_dehomogenise_parameters(const typename SourceType::Parameters &)
Definition: transformation_util.hpp:103
Definition: transformation.hpp:90
virtual void do_transform_signals(const typename SourceType::Signals &src, typename TargetType::Signals tar)=0
size_t population_count() const
std::shared_ptr< PopulationData > population_data(PopulationIndex pid)
Definition: data.hpp:94
Definition: transformation.hpp:77
const T::Signals signals() const
Definition: network_mixins.hpp:253
Definition: network.hpp:50
Definition: neurons_base.hpp:151
const NeuronType * tar_type()
Definition: transformation_util.hpp:42
NetworkBase clone() const
virtual void do_transform_parameters(const typename SourceType::Parameters &src, typename TargetType::Parameters tar)=0
const std::string name
Definition: neurons_base.hpp:86
virtual ~NeuronTypeTransformation()
Definition: transformation_util.hpp:113
NetworkBase do_transform(const NetworkBase &src, TransformationAuxData &) override
Definition: transformation_util.hpp:44
Definition: network_base.hpp:116
Definition: network_base_objects.hpp:53
const T::Parameters parameters() const
Definition: network_mixins.hpp:240
Definition: brainscales_lib.hpp:39
Definition: transformation_util.hpp:39
const NeuronType * src_type()
Definition: transformation_util.hpp:41
Definition: neurons_base.hpp:322