20 static const float kMinInputRange = 1e-6f;
31 template <
typename Type>
bool FeedForward(
const Type *inputs,
36 template <
typename Type>
bool GetNetOutput(
const Type *inputs,
102 neurons_[node].
Clear();
106 template<
class ReadBuffType>
bool ReadBinary(ReadBuffType *input_buff) {
110 unsigned int read_val;
111 unsigned int auto_encode;
113 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
116 if (read_val != kNetSignature) {
119 if (input_buff->Read(&auto_encode,
sizeof(auto_encode)) !=
120 sizeof(auto_encode)) {
123 auto_encoder_ = auto_encode;
125 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
128 neuron_cnt_ = read_val;
129 if (neuron_cnt_ <= 0) {
134 if (neurons_ ==
NULL) {
138 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
146 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
155 neurons_[idx].
set_id(idx);
159 }
else if (idx >= (neuron_cnt_ - out_cnt_)) {
166 for (
int node_idx = 0; node_idx <
neuron_cnt_; node_idx++) {
168 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
172 int fan_out_cnt = read_val;
173 for (
int fan_out_idx = 0; fan_out_idx < fan_out_cnt; fan_out_idx++) {
175 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
185 for (
int node_idx = 0; node_idx <
neuron_cnt_; node_idx++) {
187 if (!neurons_[node_idx].
ReadBinary(input_buff)) {
192 inputs_mean_.resize(in_cnt_);
193 inputs_std_dev_.resize(in_cnt_);
194 inputs_min_.resize(in_cnt_);
195 inputs_max_.resize(in_cnt_);
197 if (input_buff->Read(&(inputs_mean_.front()),
198 sizeof(inputs_mean_[0]) *
in_cnt_) !=
199 sizeof(inputs_mean_[0]) *
in_cnt_) {
202 if (input_buff->Read(&(inputs_std_dev_.front()),
203 sizeof(inputs_std_dev_[0]) *
in_cnt_) !=
204 sizeof(inputs_std_dev_[0]) *
in_cnt_) {
207 if (input_buff->Read(&(inputs_min_.front()),
208 sizeof(inputs_min_[0]) *
in_cnt_) !=
209 sizeof(inputs_min_[0]) *
in_cnt_) {
212 if (input_buff->Read(&(inputs_max_.front()),
213 sizeof(inputs_max_[0]) *
in_cnt_) !=
214 sizeof(inputs_max_[0]) *
in_cnt_) {
246 #endif // NEURAL_NET_H__
static NeuralNet * FromInputBuffer(InputFileBuffer *ib)
static const int kWgtChunkSize
vector< float > inputs_min_
float * AllocWgt(int wgt_cnt)
bool ReadBinary(ReadBuffType *input_buff)
bool FastFeedForward(const Type *inputs, Type *outputs)
bool FastGetNetOutput(const Type *inputs, int output_id, Type *output)
bool GetNetOutput(const Type *inputs, int output_id, Type *output)
vector< float > inputs_mean_
bool FeedForward(const Type *inputs, Type *outputs)
vector< float > inputs_std_dev_
vector< Node > fast_nodes_
static const unsigned int kNetSignature
vector< float > inputs_max_
void set_node_type(NeuronTypes type)
vector< vector< float > * > wts_vec_
bool SetConnection(int from, int to)
static NeuralNet * FromFile(const string file_name)