OpenNN  2.2
Open Neural Networks Library
probabilistic_layer.h
1 /****************************************************************************************************************/
2 /* */
3 /* OpenNN: Open Neural Networks Library */
4 /* www.artelnics.com/opennn */
5 /* */
6 /* P R O B A B I L I S T I C L A Y E R C L A S S H E A D E R */
7 /* */
8 /* Roberto Lopez */
9 /* Artelnics - Making intelligent use of data */
11 /* */
12 /****************************************************************************************************************/
13 
14 #ifndef __PROBABILISTICLAYER_H__
15 #define __PROBABILISTICLAYER_H__
16 
17 // System includes
18 
19 #include <cmath>
20 #include <cstdlib>
21 #include <fstream>
22 #include <iostream>
23 #include <string>
24 #include <sstream>
25 
26 // OpenNN includes
27 
28 #include "vector.h"
29 #include "matrix.h"
30 
31 // TinyXml includes
32 
33 #include "../tinyxml2/tinyxml2.h"
34 
35 namespace OpenNN
36 {
37 
41 
43 {
44 
45 public:
46 
47  // DEFAULT CONSTRUCTOR
48 
49  explicit ProbabilisticLayer(void);
50 
51  // PROBABILISTIC NEURONS NUMBER CONSTRUCTOR
52 
53  explicit ProbabilisticLayer(const size_t&);
54 
55  // COPY CONSTRUCTOR
56 
58 
59  // DESTRUCTOR
60 
61  virtual ~ProbabilisticLayer(void);
62 
63  // ASSIGNMENT OPERATOR
64 
66 
67  // EQUAL TO OPERATOR
68 
69  bool operator == (const ProbabilisticLayer&) const;
70 
71  // ENUMERATIONS
72 
74 
75  enum ProbabilisticMethod{Competitive, Softmax, NoProbabilistic};
76 
77  // GET METHODS
78 
79  const size_t& get_probabilistic_neurons_number(void) const;
80 
81  // Probabilistic processing
82 
84  std::string write_probabilistic_method(void) const;
85  std::string write_probabilistic_method_text(void) const;
86 
87  // Display messages
88 
89  const bool& get_display(void) const;
90 
91  // SET METHODS
92 
93  void set(void);
94  void set(const size_t&);
95  void set(const ProbabilisticLayer&);
96 
97  void set_probabilistic_neurons_number(const size_t&);
98 
100  void set_probabilistic_method(const std::string&);
101 
102  virtual void set_default(void);
103 
104  // Display messages
105 
106  void set_display(const bool&);
107 
108  // Pruning and growing
109 
110  void prune_probabilistic_neuron(void);
111 
112  // Initialization methods
113 
114  void initialize_random(void);
115 
116  // Probabilistic post-processing
117 
121 
125 
129 
133 
134  // Expression methods
135 
136  std::string write_competitive_expression(const Vector<std::string>&, const Vector<std::string>&) const;
137  std::string write_softmax_expression(const Vector<std::string>&, const Vector<std::string>&) const;
139 
140  std::string write_expression(const Vector<std::string>&, const Vector<std::string>&) const;
141 
142  // Serialization methods
143 
144  std::string to_string(void) const;
145 
146  virtual tinyxml2::XMLDocument* to_XML(void) const;
147  virtual void from_XML(const tinyxml2::XMLDocument&);
148 
149 protected:
150 
151  // MEMBERS
152 
154 
156 
158 
160 
162 
163  bool display;
164 };
165 
166 }
167 
168 #endif
169 
170 
171 // OpenNN: Open Neural Networks Library.
172 // Copyright (c) 2005-2015 Roberto Lopez.
173 //
174 // This library is free software; you can redistribute it and/or
175 // modify it under the terms of the GNU Lesser General Public
176 // License as published by the Free Software Foundation; either
177 // version 2.1 of the License, or any later version.
178 //
179 // This library is distributed in the hope that it will be useful,
180 // but WITHOUT ANY WARRANTY; without even the implied warranty of
181 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
182 // Lesser General Public License for more details.
183 
184 // You should have received a copy of the GNU Lesser General Public
185 // License along with this library; if not, write to the Free Software
186 
187 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
188 
std::string write_competitive_expression(const Vector< std::string > &, const Vector< std::string > &) const
Vector< Matrix< double > > calculate_no_probabilistic_Hessian_form(const Vector< double > &) const
std::string write_softmax_expression(const Vector< std::string > &, const Vector< std::string > &) const
ProbabilisticMethod probabilistic_method
Probabilistic processing method.
bool operator==(const ProbabilisticLayer &) const
Vector< Matrix< double > > calculate_Hessian_form(const Vector< double > &) const
const ProbabilisticMethod & get_probabilistic_method(void) const
bool display
Display messages to screen.
std::string write_probabilistic_method(void) const
std::string write_no_probabilistic_expression(const Vector< std::string > &, const Vector< std::string > &) const
std::string to_string(void) const
Returns a string representation of the current probabilistic layer object.
Vector< double > calculate_outputs(const Vector< double > &) const
Matrix< double > calculate_no_probabilistic_Jacobian(const Vector< double > &) const
virtual tinyxml2::XMLDocument * to_XML(void) const
size_t probabilistic_neurons_number
Number of probabilistic neurons in the layer.
void initialize_random(void)
Initializes at random the probabilistic method.
const size_t & get_probabilistic_neurons_number(void) const
Returns the number of probabilistic neurons in the layer.
Vector< double > calculate_competitive_output(const Vector< double > &) const
void set_probabilistic_method(const ProbabilisticMethod &)
ProbabilisticLayer & operator=(const ProbabilisticLayer &)
std::string write_probabilistic_method_text(void) const
const bool & get_display(void) const
void set_probabilistic_neurons_number(const size_t &)
virtual void from_XML(const tinyxml2::XMLDocument &)
Vector< double > calculate_no_probabilistic_output(const Vector< double > &) const
Matrix< double > calculate_softmax_Jacobian(const Vector< double > &) const
std::string write_expression(const Vector< std::string > &, const Vector< std::string > &) const
Vector< double > calculate_softmax_output(const Vector< double > &) const
Vector< Matrix< double > > calculate_competitive_Hessian_form(const Vector< double > &) const
This method throws an exception, since the competitive function is not derivable. ...
ProbabilisticMethod
Enumeration of available methods for interpreting variables as probabilities.
Vector< Matrix< double > > calculate_softmax_Hessian_form(const Vector< double > &) const
Matrix< double > calculate_Jacobian(const Vector< double > &) const
Matrix< double > calculate_competitive_Jacobian(const Vector< double > &) const
This method throws an exception, since the competitive function is not derivable. ...