29 static const float kMinInputRange = 1e-6f;
40 template <
typename Type>
bool FeedForward(
const Type *inputs,
45 template <
typename Type>
bool GetNetOutput(
const Type *inputs,
111 neurons_[node].
Clear();
115 template<
class ReadBuffType>
bool ReadBinary(ReadBuffType *input_buff) {
119 unsigned int read_val;
120 unsigned int auto_encode;
122 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
125 if (read_val != kNetSignature) {
128 if (input_buff->Read(&auto_encode,
sizeof(auto_encode)) !=
129 sizeof(auto_encode)) {
132 auto_encoder_ = auto_encode;
134 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
137 neuron_cnt_ = read_val;
138 if (neuron_cnt_ <= 0) {
144 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
152 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
161 neurons_[idx].
set_id(idx);
165 }
else if (idx >= (neuron_cnt_ - out_cnt_)) {
172 for (
int node_idx = 0; node_idx <
neuron_cnt_; node_idx++) {
174 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
178 int fan_out_cnt = read_val;
179 for (
int fan_out_idx = 0; fan_out_idx < fan_out_cnt; fan_out_idx++) {
181 if (input_buff->Read(&read_val,
sizeof(read_val)) !=
sizeof(read_val)) {
191 for (
int node_idx = 0; node_idx <
neuron_cnt_; node_idx++) {
193 if (!neurons_[node_idx].
ReadBinary(input_buff)) {
198 inputs_mean_.resize(in_cnt_);
199 inputs_std_dev_.resize(in_cnt_);
200 inputs_min_.resize(in_cnt_);
201 inputs_max_.resize(in_cnt_);
203 if (input_buff->Read(&(inputs_mean_.front()),
204 sizeof(inputs_mean_[0]) *
in_cnt_) !=
205 sizeof(inputs_mean_[0]) *
in_cnt_) {
208 if (input_buff->Read(&(inputs_std_dev_.front()),
209 sizeof(inputs_std_dev_[0]) *
in_cnt_) !=
210 sizeof(inputs_std_dev_[0]) *
in_cnt_) {
213 if (input_buff->Read(&(inputs_min_.front()),
214 sizeof(inputs_min_[0]) *
in_cnt_) !=
215 sizeof(inputs_min_[0]) *
in_cnt_) {
218 if (input_buff->Read(&(inputs_max_.front()),
219 sizeof(inputs_max_[0]) *
in_cnt_) !=
220 sizeof(inputs_max_[0]) *
in_cnt_) {
252 #endif // NEURAL_NET_H__ void set_node_type(NeuronTypes type)
bool SetConnection(int from, int to)
static NeuralNet * FromFile(const string file_name)
static NeuralNet * FromInputBuffer(InputFileBuffer *ib)
bool FeedForward(const Type *inputs, Type *outputs)
vector< float > inputs_max_
bool FastFeedForward(const Type *inputs, Type *outputs)
bool FastGetNetOutput(const Type *inputs, int output_id, Type *output)
vector< vector< float > * > wts_vec_
static const int kWgtChunkSize
bool GetNetOutput(const Type *inputs, int output_id, Type *output)
vector< float > inputs_min_
bool ReadBinary(ReadBuffType *input_buff)
vector< float > inputs_std_dev_
static const unsigned int kNetSignature
vector< float > inputs_mean_
float * AllocWgt(int wgt_cnt)
vector< Node > fast_nodes_