/ru/experimental/nnetwork.h
https://bitbucket.org/VladimirL/robotutils · C Header · 87 lines · 58 code · 17 blank · 12 comment · 2 complexity · 07d981284081ada2ef9a5b5caba09d12 MD5 · raw file
- #ifndef NLAYER_H
- #define NLAYER_H
- #include <stdlib.h>
- #include <vector>
- #include <cmath>
- #include <QDebug>
- #include <QString>
- using namespace std;
- const double sigma_a = -2.0; // -a
- //const double speed = 1.0;
- //! ?????????????? ? ????????? 0..1
- inline double normalize(double val, double min, double max)
- {
- if (val>max) val=max;
- if (val<min) val=min;
- return ((val-min)/(max-min));
- }
- //! ???????? ??????????????
- inline double denormalize(double val, double min, double max)
- {
- return (val*(max-min) + min);
- }
- //! ????????? ?????? ??? ?????????? ?????????
- class Dataset
- {
- public:
- Dataset(int rows, int cols);
- ~Dataset();
- int rows;
- int cols;
- int row_width; // ?????? ?????? ? ?????????
- double *data;
- };
- //! ???? ????????
- class NLayer
- {
- public:
- NLayer(int percept_count, NLayer *previous_layer = NULL);
- NLayer(const NLayer& layer); // prev_layer ?????????? ?????!
- ~NLayer();
- double *weights; // ???????? ?????. ????????? = b, ??? ???? xn = +1
- int percept_cnt; // ?????????? ????????
- int weights_cnt; // ????? ?????????? ?????
- double *values; // ???????? ???????? ????????
- double *temp_val; // ????????? ???????? ???????. ??? ????????? ????????
- NLayer *prev_layer; // ?????????? ????. NULL - ???????
- int activation_func; // 0 - ?????????????, 1 - ???????
- };
- //!< ????????? ????
- class NNetwork
- {
- public:
- //! ?????????? ???????? ?? ??????? ????, ?????? ?????????? ???????? ? ??????? ?????, ?????????? ???????? ? ???????? ????
- NNetwork(int inputs, vector<int> hidden_layers, int outputs);
- NNetwork(const NNetwork& nn); //! ???????????
- ~NNetwork();
- //! ?????????? ???????? ???????? ????
- vector<double> calc_output(vector<double>& input);
- //! ??????? ????????? (???? ????????)
- void train(const Dataset &dataset, double speed);
- //! ?????? ?????????????
- void dumpCoeff();
- //! ????????? ????????? ????????????? ???? (??? ????????????? ?????????)
- void mutate(double amp, int freq);
- protected:
- void updateState();
- // ????
- vector<NLayer*> layers;
- };
- #endif // NLAYER_H