-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpositions.hpp
116 lines (98 loc) · 4.13 KB
/
positions.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* positions.hpp
*
* Created on: Sep 24, 2015
* Author: Joost Huizinga
*/
#ifndef MODULES_MISC_POSITIONS_HPP_
#define MODULES_MISC_POSITIONS_HPP_
//Boost include
#include <boost/spirit/include/karma.hpp>
//Sferes include
#include <sferes/dbg/dbg.hpp>
/********************************
* POSITIONS *
********************************/
template<typename Params>
inline void setPos(const float& x, const float& y, const float& z,
const float& x_vis, const float& y_vis, const float& z_vis, size_t& neuron_index){
Params::dnn::spatial::_x[neuron_index] = x;
Params::dnn::spatial::_y[neuron_index] = y;
Params::dnn::spatial::_z[neuron_index] = z;
Params::visualisation::_x[neuron_index] = x_vis;
Params::visualisation::_y[neuron_index] = -y_vis;
Params::visualisation::_z[neuron_index] = z_vis;
dbg::out(dbg::info, "neuronpos") << "index:" << neuron_index <<
" x: " << Params::dnn::spatial::_x[neuron_index] <<
" y: " << Params::dnn::spatial::_y[neuron_index] <<
" z: " << Params::dnn::spatial::_z[neuron_index] << std::endl;
++neuron_index;
}
template<typename Params>
inline void setPos(const float& x, const float& y, const float& z, size_t& neuron_index){
setPos<Params>(x, y, z, x, y, z, neuron_index);
}
template<typename Params>
inline void setPos(const float& x, const float& z, size_t& neuron_index){
setPos<Params>(x, 0, z, x, 0, z, neuron_index);
}
template<typename Params>
inline void setPos(const float& x, const float& z, const float& x_vis, const float& z_vis, size_t& neuron_index){
setPos<Params>(x, 0, z, x_vis, 0, z_vis, neuron_index);
}
template<typename Params>
void print_positions(){
//Print positions
float tolerance = 0.00001;
std::vector<float> x_values;
for(unsigned i=0; i<Params::dnn::spatial::x_size(); ++i){
x_values.push_back(Params::dnn::spatial::x(i));
}
std::vector<float> y_values;
for(unsigned i=0; i<Params::dnn::spatial::y_size(); ++i){
y_values.push_back(Params::dnn::spatial::y(i));
}
Range x_range = get_range(x_values, tolerance);
Range y_range = get_range(y_values, tolerance);
// std::cout << "x_range: " << x_range << std::endl;
// std::cout << "y_range: " << y_range << std::endl;
unsigned nb_x_bins = x_range.nb_of_bins(tolerance);
unsigned nb_y_bins = y_range.nb_of_bins(tolerance);
// std::cout << "Number of x bins: " << nb_x_bins << std::endl;
// std::cout << "Number of y bins: " << nb_y_bins << std::endl;
std::vector<std::vector<std::vector<unsigned> > > bins(nb_x_bins);
for(unsigned i=0; i<bins.size(); ++i){
bins[i].resize(nb_y_bins);
}
for(unsigned i=0; i<Params::dnn::spatial::x_size(); ++i){
unsigned x_bin_index = x_range.get_bin(Params::dnn::spatial::x(i), tolerance);
unsigned y_bin_index = y_range.get_bin(Params::dnn::spatial::y(i), tolerance);
// std::cout << "- point " << i << " placed in bin: " << x_bin_index << "," << y_bin_index << std::endl;
dbg::assertion(DBG_ASSERTION(x_bin_index < nb_x_bins));
dbg::assertion(DBG_ASSERTION(y_bin_index < nb_y_bins));
bins[x_bin_index][y_bin_index].push_back(i);
}
//Do the actual printing
using namespace boost::spirit::karma;
std::cout << " |";
for(float x=x_range.min; x<=x_range.max + tolerance; x+=x_range.step){
std::cout << format(right_align(5, ' ')[maxwidth(5)[float_]], x) << "|";
}
std::cout << std::endl;
for(int y=nb_y_bins-1; y>=0; --y){
float y_value = y_range.min + (y_range.step * y);
std::cout << format(right_align(5, ' ')[maxwidth(5)[float_]], y_value) << "|";
for(unsigned x=0; x<nb_x_bins; ++x){
dbg::assertion(DBG_ASSERTION(bins[x][y].size() < 2));
if(bins[x][y].size()==1){
unsigned neuron_id = bins[x][y][0];
std::cout << format(right_align(5, ' ')[maxwidth(5)[int_]], neuron_id) << "|";
} else {
std::cout << " |";
}
}
std::cout << std::endl;
}
std::cout << std::endl;
}
#endif /* MODULES_MISC_POSITIONS_HPP_ */