LIBRCSC Docs
Documentation for HELIOS's BASE LIBRCSC library for RoboCup 2D Simulation League.
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros
rbf.h
Go to the documentation of this file.
1// -*-c++-*-
2
8/*
9 *Copyright:
10
11 Copyright (C) Hidehisa AKIYAMA
12
13 This code is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 3 of the License, or (at your option) any later version.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
27 *EndCopyright:
28 */
29
31
32#ifndef RCSC_ANN_RBF_H
33#define RCSC_ANN_RBF_H
34
35#include <boost/array.hpp>
36
37#include <vector>
38#include <iostream>
39#include <cmath>
40
41namespace rcsc {
42
44
50public:
51
53 typedef std::vector< double > input_vector;
55 typedef std::vector< double > output_vector;
56
61 struct Unit {
63
66
67 double sigma_;
68 double delta_sigma_;
69
70 private:
71 // not used
72 Unit() = delete;
73
74 public:
80 Unit( std::size_t input_dim,
81 std::size_t output_dim );
82
89 void randomize( const double & min_weight,
90 const double & max_weight,
91 const double & initial_sigma );
92
98 double dist2( const input_vector & input ) const
99 {
100 const std::size_t INPUT = input.size();
101 if ( INPUT != center_.size() )
102 {
103 return 0.0;
104 }
105
106 double d2 = 0.0;
107 for ( std::size_t i = 0; i < INPUT; ++i )
108 {
109 d2 += std::pow( center_[i] - input[i], 2 );
110 }
111 return d2;
112 }
113
119 double dist( const input_vector & input ) const
120 {
121 return std::sqrt( dist2( input ) );
122 }
123
128 double calc( const input_vector & input ) const
129 {
130 return std::exp( - dist2( input ) / ( 2.0 * sigma_ * sigma_ ) );
131 }
132 };
133
134private:
135
136 const std::size_t M_input_dim;
137 const std::size_t M_output_dim;
138
139 double M_eta;
140 double M_alpha;
141 double M_min_weight;
142 double M_max_weight;
143 double M_initial_sigma;
144
145 std::vector< Unit > M_units;
146
147 // not used
148 RBFNetwork() = delete;
149
150public:
151
157 RBFNetwork( const std::size_t input_dim,
158 const std::size_t output_dim );
159
165 void setLearningRate( const double & eta,
166 const double & alpha )
167 {
168 M_eta = eta;
169 M_alpha = alpha;
170 }
171
177 void setWeightRange( const double & min_weight,
178 const double & max_weight )
179 {
180 M_min_weight = min_weight;
181 M_max_weight = max_weight;
182 }
183
187 void setInitialSigma( const double & initial_sigma )
188 {
189 M_initial_sigma = initial_sigma;
190 }
191
196 const
197 std::vector< Unit > & units() const
198 {
199 return M_units;
200 }
201
206 void addCenter( const input_vector & center );
207
213 void propagate( const input_vector & input,
214 output_vector & output ) const;
215
222 double train( const input_vector & input,
223 const output_vector & teacher );
224
230 bool read( std::istream & is );
231
237 std::ostream & print( std::ostream & os ) const;
238
244 std::ostream & printUnits( std::ostream & os ) const;
245
246};
247
248}
249
250#endif
Radial Basis Function Network.
Definition: rbf.h:49
std::ostream & print(std::ostream &os) const
write network structure to an output stream
std::ostream & printUnits(std::ostream &os) const
write detailed unit information
void setLearningRate(const double &eta, const double &alpha)
set learning rate
Definition: rbf.h:165
void setInitialSigma(const double &initial_sigma)
set basis function's initial sigma
Definition: rbf.h:187
RBFNetwork(const std::size_t input_dim, const std::size_t output_dim)
all weight is initialized by 0. default sigma = 100.0
void propagate(const input_vector &input, output_vector &output) const
calculate output value
void setWeightRange(const double &min_weight, const double &max_weight)
set connection weight range
Definition: rbf.h:177
void addCenter(const input_vector &center)
add new center point
double train(const input_vector &input, const output_vector &teacher)
train the connection weight
std::vector< double > output_vector
typedef of the output value container
Definition: rbf.h:55
std::vector< double > input_vector
typedef of the input value container
Definition: rbf.h:53
const std::vector< Unit > & units() const
get the unit container
Definition: rbf.h:197
bool read(std::istream &is)
read network structure from an input stream
radial basis function unit
Definition: rbf.h:61
input_vector center_
center point of this unit
Definition: rbf.h:62
void randomize(const double &min_weight, const double &max_weight, const double &initial_sigma)
set unit parameter randomly
double sigma_
function parameter. this value must be >0
Definition: rbf.h:67
output_vector weights_
weights to output
Definition: rbf.h:64
double dist(const input_vector &input) const
calculate distance from the input vector
Definition: rbf.h:119
Unit(std::size_t input_dim, std::size_t output_dim)
all weight is initialized by 0. default sigma = 100.0
double calc(const input_vector &input) const
calculate output value for the input
Definition: rbf.h:128
output_vector delta_weights_
delta of weights
Definition: rbf.h:65
double dist2(const input_vector &input) const
calculate distance from the input vector
Definition: rbf.h:98
double delta_sigma_
delta of sigma
Definition: rbf.h:68