summaryrefslogtreecommitdiffstats
path: root/Master/Modellbildung_und_Simulation/Aufgabenblatt3/MLP/src/MLP.h
blob: fdb32a3a310e5618ce2d3c10b3a098757cc0ba31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * MLP.h
 *
 *  Created on: 09.06.2011
 *      Author: sven
 */

#ifndef MLP_H_
#define MLP_H_

#include "MLPConfig.h"
#include <boost/thread.hpp> 

typedef vector<double> Activity;
typedef vector<double> Delta;
typedef vector<double> Pattern;
typedef vector<double> Target;
typedef vector<double> Output;

struct Trainingpair {
    Pattern mPattern;
    Target mTarget;
};

typedef vector<Trainingpair> Traindata;

class MLP {
public:
	MLP(const MLPConfig&);
	virtual ~MLP();
    void train(const Traindata&, const Traindata&, const uint32_t, const std::string&);
    void propagate(const Pattern&, Output& result);
    void stop();

private:
	uint32_t mStartHidden;
	uint32_t mStartOutput;
	uint32_t mNoNeuron;
	Weights mWeights;
	Activity mActivity;
	Delta mDelta;
	Weights mDeltaWeights;
	Weights mOldUpdate;
	double mMomentum;
	double mLernrate;
	const MLPConfig& mConfig;
	double mOldError;
	Weights mOldWeights;
	bool mTrainSuccess;
    bool mDoStop;
    boost::mutex mMutex;

    double sigmoid(const double&);
    void propagate(const Pattern&);
    void back_propagate(const Target&);
    void update_weight();
    void reset_delta();
    double validate(const Traindata&);
    void dump();
    void writeWeightsToFile(const string&, const Weights&);
    bool isStop();
};

#endif /* MLP_H_ */