#include <nnlayer.h>
Inheritance diagram for NNLayer:
Public Types | |
typedef std::vector< REAL > | WVEC |
weight vector | |
typedef std::vector< REAL > | DVEC |
derivative vector | |
Public Member Functions | |
NNLayer (UINT n_in=0, UINT n_unit=0) | |
NNLayer (std::istream &is) | |
virtual const id_t & | id () const |
virtual NNLayer * | create () const |
Create a new object using the default constructor. | |
virtual NNLayer * | clone () const |
Create a new object by replicating itself. | |
UINT | size () const |
void | set_weight_range (REAL min, REAL max) |
const WVEC & | weight () const |
void | set_weight (const WVEC &) |
const WVEC & | gradient () const |
void | clear_gradient () |
virtual void | initialize () |
Initialize the model for training. | |
virtual REAL | train () |
Train with preset data set and sample weight. | |
virtual Output | operator() (const Input &x) const |
void | feed_forward (const Input &, Output &) const |
void | back_propagate (const Input &, const DVEC &, DVEC &) |
Protected Member Functions | |
virtual REAL | sigmoid (REAL) const |
virtual REAL | sigmoid_deriv (REAL) const |
virtual bool | serialize (std::ostream &, ver_list &) const |
virtual bool | unserialize (std::istream &, ver_list &, const id_t &=empty_id) |
Protected Attributes | |
REAL | w_min |
REAL | w_max |
WVEC | w |
weights and thresholds | |
WVEC | dw |
deravatives: w -= lr * dw | |
DVEC | sig_der |
This class simulates a layer of neurons.
Here's usage information.
Here's some details.
Say, we have n neurons and m inputs. The output from the neuron is
where is the weighted sum of inputs,
, and
is sort of the threshold. feed_forward() does this calculation and saves
for future use.
The ``chain rule'' for back-propagation says the derative w.r.t. the input x can be calculated from that to the output y. Define
We have
These equations consitute the essense of back_propagate().
Modifying sigmoid() (which computes ) and sigmoid_deriv() (which computes
) is usually enough to get a different type of layer.
Definition at line 53 of file nnlayer.h.
|
derivative vector
|
|
weight vector
|
|
Definition at line 16 of file nnlayer.cpp. References quick_tanh_setup(). Referenced by NNLayer::clone(), and NNLayer::create(). |
|
|
|
Definition at line 93 of file nnlayer.cpp. References LearnModel::_n_in, LearnModel::_n_out, NNLayer::dw, LearnModel::n_input(), LearnModel::n_output(), NNLayer::sig_der, and NNLayer::w. |
|
Definition at line 58 of file nnlayer.cpp. References NNLayer::dw. Referenced by NNLayer::initialize(). |
|
Create a new object by replicating itself.
return new Derived(*this);
Implements LearnModel. Definition at line 72 of file nnlayer.h. References NNLayer::NNLayer(). Referenced by FeedForwardNN::add_top(). |
|
Create a new object using the default constructor. The code for a derived class Derived is always return new Derived(); Implements LearnModel. Definition at line 71 of file nnlayer.h. References NNLayer::NNLayer(). |
|
Definition at line 78 of file nnlayer.cpp. References LearnModel::_n_in, LearnModel::_n_out, lemga::op::inner_product(), LearnModel::n_input(), LearnModel::n_output(), NNLayer::sig_der, NNLayer::sigmoid(), NNLayer::sigmoid_deriv(), and NNLayer::w. Referenced by NNLayer::operator()(). |
|
Definition at line 83 of file nnlayer.h. References NNLayer::dw. |
|
Implements Object. |
|
Initialize the model for training.
Reimplemented from LearnModel. Definition at line 62 of file nnlayer.cpp. References NNLayer::clear_gradient(), randu, NNLayer::w, NNLayer::w_max, and NNLayer::w_min. |
|
Implements LearnModel. Definition at line 88 of file nnlayer.h. References NNLayer::feed_forward(), and LearnModel::n_output(). |
|
Reimplemented from LearnModel. Definition at line 23 of file nnlayer.cpp. References LearnModel::_n_in, LearnModel::_n_out, SERIALIZE_PARENT, NNLayer::w, NNLayer::w_max, and NNLayer::w_min. |
|
Definition at line 53 of file nnlayer.cpp. References LearnModel::_n_in, LearnModel::_n_out, and NNLayer::w. |
|
Definition at line 76 of file nnlayer.h. References NNLayer::w_max, and NNLayer::w_min. |
|
Definition at line 68 of file nnlayer.cpp. References quick_tanh(). Referenced by NNLayer::feed_forward(). |
|
Definition at line 73 of file nnlayer.cpp. References quick_tanh(). Referenced by NNLayer::feed_forward(). |
|
Definition at line 74 of file nnlayer.h. References LearnModel::n_output(). |
|
Train with preset data set and sample weight.
Implements LearnModel. Definition at line 87 of file nnlayer.h. References OBJ_FUNC_UNDEFINED. |
|
Reimplemented from LearnModel. Definition at line 35 of file nnlayer.cpp. References LearnModel::_n_in, LearnModel::_n_out, NNLayer::dw, Object::empty_id, NNLayer::sig_der, UNSERIALIZE_PARENT, NNLayer::w, NNLayer::w_max, and NNLayer::w_min. |
|
Definition at line 80 of file nnlayer.h. References NNLayer::w. |
|
deravatives: w -= lr * dw
Definition at line 63 of file nnlayer.h. Referenced by NNLayer::back_propagate(), NNLayer::clear_gradient(), NNLayer::gradient(), and NNLayer::unserialize(). |
|
Definition at line 64 of file nnlayer.h. Referenced by NNLayer::back_propagate(), NNLayer::feed_forward(), and NNLayer::unserialize(). |
|
weights and thresholds
Definition at line 62 of file nnlayer.h. Referenced by NNLayer::back_propagate(), NNLayer::feed_forward(), NNLayer::initialize(), NNLayer::serialize(), NNLayer::set_weight(), NNLayer::unserialize(), and NNLayer::weight(). |
|
Definition at line 61 of file nnlayer.h. Referenced by NNLayer::initialize(), NNLayer::serialize(), NNLayer::set_weight_range(), and NNLayer::unserialize(). |
|
Definition at line 61 of file nnlayer.h. Referenced by NNLayer::initialize(), NNLayer::serialize(), NNLayer::set_weight_range(), and NNLayer::unserialize(). |