Tesseract 3.02

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
tesseract::Neuron Class Reference

`#include <neuron.h>`

List of all members.

## 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 []

## Detailed Description

Definition at line 24 of file neuron.h.

## Member Enumeration Documentation

enum tesseract::Neuron::NeuronTypes

Enumerator:

  Unknown |
  Input |
  Hidden |
  Output |

Definition at line 27 of file neuron.h.

{
Unknown = 0,
Input,
Hidden,
Output
};

## Constructor & Destructor Documentation

tesseract::Neuron::Neuron | ( |  | ) |

Definition at line 17 of file neuron.cpp.

{
Init();
}

tesseract::Neuron::~Neuron | ( |  | ) |

Definition at line 22 of file neuron.cpp.

{
}

## Member Function Documentation

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

Definition at line 114 of file neuron.h.

{
return bias_;
}

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

Definition at line 105 of file neuron.h.

{
return fan_in_[idx];
}

int tesseract::Neuron::fan_in_cnt | ( |  | ) | const
| inline

Definition at line 102 of file neuron.h.

{
return fan_in_.size();
}

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

Definition at line 99 of file neuron.h.

{
return id_;
}

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

Definition at line 93 of file neuron.h.

{
return output_;
}
template<class BuffType >

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

Definition at line 111 of file neuron.h.

{
id_ = id;
}

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

Definition at line 96 of file neuron.h.

{
output_ = out_val;
}

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))];
}
}

## Member Data Documentation

float tesseract::Neuron::activation_
| protected

Definition at line 129 of file neuron.h.

float tesseract::Neuron::bias_
| protected

Definition at line 127 of file neuron.h.

vector<Neuron *> tesseract::Neuron::fan_in_
| protected

Definition at line 133 of file neuron.h.

vector<float *> tesseract::Neuron::fan_in_weights_
| protected

Definition at line 135 of file neuron.h.

bool tesseract::Neuron::frwd_dirty_
| protected

Definition at line 141 of file neuron.h.

int tesseract::Neuron::id_
| protected

Definition at line 125 of file neuron.h.

const float tesseract::Neuron::kSigmoidTable
| static protected

Definition at line 138 of file neuron.h.

NeuronTypes tesseract::Neuron::node_type_
| protected

Definition at line 123 of file neuron.h.

float tesseract::Neuron::output_
| protected

Definition at line 131 of file neuron.h.

The documentation for this class was generated from the following files:

- /mnt/data/src/tesseract-ocr/neural_networks/runtime/neuron.h
- /mnt/data/src/tesseract-ocr/neural_networks/runtime/neuron.cpp
- /mnt/data/src/tesseract-ocr/neural_networks/runtime/sigmoid_table.cpp