Tesseract
3.02
|
#include <neuron.h>
Public Types | |
enum | NeuronTypes { Unknown = 0, Input, Hidden, Output } |
Public Member Functions | |
Neuron () | |
~Neuron () | |
void | Clear () |
template<class BuffType > | |
bool | ReadBinary (BuffType *input_buff) |
void | AddFromConnection (Neuron *neuron_vec, float *wts_offset, int from_cnt) |
void | set_node_type (NeuronTypes type) |
void | FeedForward () |
float | output () const |
void | set_output (float out_val) |
int | id () const |
int | fan_in_cnt () const |
Neuron * | fan_in (int idx) const |
float | fan_in_wts (int idx) const |
void | set_id (int id) |
float | bias () const |
Neuron::NeuronTypes | node_type () const |
Static Public Member Functions | |
static float | Sigmoid (float activation) |
Protected Member Functions | |
void | Init () |
Protected Attributes | |
NeuronTypes | node_type_ |
int | id_ |
float | bias_ |
float | activation_ |
float | output_ |
vector< Neuron * > | fan_in_ |
vector< float * > | fan_in_weights_ |
bool | frwd_dirty_ |
Static Protected Attributes | |
static const float | kSigmoidTable [] |
tesseract::Neuron::Neuron | ( | ) |
Definition at line 17 of file neuron.cpp.
{ Init(); }
tesseract::Neuron::~Neuron | ( | ) |
Definition at line 22 of file neuron.cpp.
{ }
void tesseract::Neuron::AddFromConnection | ( | Neuron * | neuron_vec, |
float * | wts_offset, | ||
int | from_cnt | ||
) |
Definition at line 74 of file neuron.cpp.
{ for (int in = 0; in < from_cnt; in++) { fan_in_.push_back(neurons + in); fan_in_weights_.push_back(wts_offset + in); } }
float tesseract::Neuron::bias | ( | ) | const [inline] |
void tesseract::Neuron::Clear | ( | ) | [inline] |
Definition at line 37 of file neuron.h.
{ frwd_dirty_ = true; }
Neuron* tesseract::Neuron::fan_in | ( | int | idx | ) | const [inline] |
int tesseract::Neuron::fan_in_cnt | ( | ) | const [inline] |
float tesseract::Neuron::fan_in_wts | ( | int | idx | ) | const [inline] |
Definition at line 108 of file neuron.h.
{ return *(fan_in_weights_[idx]); }
void tesseract::Neuron::FeedForward | ( | ) |
Definition at line 39 of file neuron.cpp.
{ if (!frwd_dirty_ ) { return; } // nothing to do for input nodes: just pass the input to the o/p // otherwise, pull the output of all fan-in neurons if (node_type_ != Input) { int fan_in_cnt = fan_in_.size(); // sum out the activation activation_ = -bias_; for (int in = 0; in < fan_in_cnt; in++) { if (fan_in_[in]->frwd_dirty_) { fan_in_[in]->FeedForward(); } activation_ += ((*(fan_in_weights_[in])) * fan_in_[in]->output_); } // sigmoid it output_ = Sigmoid(activation_); } frwd_dirty_ = false; }
int tesseract::Neuron::id | ( | ) | const [inline] |
void tesseract::Neuron::Init | ( | ) | [protected] |
Definition at line 26 of file neuron.cpp.
{ id_ = -1; frwd_dirty_ = false; fan_in_.clear(); fan_in_weights_.clear(); activation_ = 0.0f; output_ = 0.0f; bias_ = 0.0f; node_type_ = Unknown; }
Neuron::NeuronTypes tesseract::Neuron::node_type | ( | ) | const [inline] |
Definition at line 117 of file neuron.h.
{ return node_type_; }
float tesseract::Neuron::output | ( | ) | const [inline] |
template bool tesseract::Neuron::ReadBinary | ( | BuffType * | input_buff | ) | [inline] |
Definition at line 42 of file neuron.h.
{ float val; if (input_buff->Read(&val, sizeof(val)) != sizeof(val)) { return false; } // input nodes should have no biases if (node_type_ == Input) { bias_ = kInputNodeBias; } else { bias_ = val; } // read fanin count int fan_in_cnt; if (input_buff->Read(&fan_in_cnt, sizeof(fan_in_cnt)) != sizeof(fan_in_cnt)) { return false; } // validate fan-in cnt if (fan_in_cnt != fan_in_.size()) { return false; } // read the weights for (int in = 0; in < fan_in_cnt; in++) { if (input_buff->Read(&val, sizeof(val)) != sizeof(val)) { return false; } *(fan_in_weights_[in]) = val; } return true; }
void tesseract::Neuron::set_id | ( | int | id | ) | [inline] |
void tesseract::Neuron::set_node_type | ( | NeuronTypes | type | ) |
Definition at line 62 of file neuron.cpp.
{ node_type_ = Type; }
void tesseract::Neuron::set_output | ( | float | out_val | ) | [inline] |
float tesseract::Neuron::Sigmoid | ( | float | activation | ) | [static] |
Definition at line 85 of file neuron.cpp.
{ if (activation <= -10.0f) { return 0.0f; } else if (activation >= 10.0f) { return 1.0f; } else { return kSigmoidTable[static_cast<int>(100 * (activation + 10.0))]; } }
float tesseract::Neuron::activation_ [protected] |
float tesseract::Neuron::bias_ [protected] |
vector<Neuron *> tesseract::Neuron::fan_in_ [protected] |
vector<float *> tesseract::Neuron::fan_in_weights_ [protected] |
bool tesseract::Neuron::frwd_dirty_ [protected] |
int tesseract::Neuron::id_ [protected] |
const float tesseract::Neuron::kSigmoidTable [static, protected] |
NeuronTypes tesseract::Neuron::node_type_ [protected] |
float tesseract::Neuron::output_ [protected] |