From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../Aufgabenblatt3/MLP/src/MLP.cpp | 312 ++++++++++++++++ .../Aufgabenblatt3/MLP/src/MLP.h | 64 ++++ .../Aufgabenblatt3/MLP/src/MLPConfig.cpp | 223 ++++++++++++ .../Aufgabenblatt3/MLP/src/MLPConfig.h | 164 +++++++++ .../Aufgabenblatt3/MLP/src/main.cpp | 401 +++++++++++++++++++++ 5 files changed, 1164 insertions(+) create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt3/MLP/src/MLP.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt3/MLP/src/MLP.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt3/MLP/src/MLPConfig.cpp create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt3/MLP/src/MLPConfig.h create mode 100644 Master/Modellbildung_und_Simulation/Aufgabenblatt3/MLP/src/main.cpp (limited to 'Master/Modellbildung_und_Simulation/Aufgabenblatt3/MLP/src') diff --git a/Master/Modellbildung_und_Simulation/Aufgabenblatt3/MLP/src/MLP.cpp b/Master/Modellbildung_und_Simulation/Aufgabenblatt3/MLP/src/MLP.cpp new file mode 100644 index 0000000..e7abe3b --- /dev/null +++ b/Master/Modellbildung_und_Simulation/Aufgabenblatt3/MLP/src/MLP.cpp @@ -0,0 +1,312 @@ +/* + * MLP.cpp + * + * Created on: 09.06.2011 + * Author: sven + */ +#include +#include +#include +#include +#include +#include +#include +#include "MLP.h" + +MLP::MLP(const MLPConfig& mlpConf) +:mStartHidden(1+mlpConf.getNumInputNeurons()),mStartOutput(mStartHidden+mlpConf.getNumHiddenNeurons()) +,mNoNeuron(mStartOutput + mlpConf.getNumOutputNeurons()) +,mActivity(mNoNeuron), mDelta(mNoNeuron) +,mMomentum(mlpConf.getMomentum()) +,mLernrate(mlpConf.getLernrate()),mConfig(mlpConf),mTrainSuccess(false),mDoStop(false) +{ + mWeights = mlpConf.getWeights(); + for (uint32_t i = 0; i < mNoNeuron ; i++) { + mDeltaWeights.push_back(vector(mNoNeuron)); + mOldUpdate.push_back(vector(mNoNeuron)); + } + // Bias neuron is always on + mActivity.at(0) = 1.0; +} + +MLP::~MLP() +{ + +} + +void MLP::dump() +{ + int width = 12; + int prec = 8; + cout << "============ MLP config==========" << endl; + cout << "start hidden: " << mStartHidden << endl; + cout << "start output: " << mStartOutput << endl; + cout << "no neuron: " << mNoNeuron << endl; + + cout << "Weights:" << endl; + BOOST_FOREACH(vector i, mWeights) + { + BOOST_FOREACH(double w, i) + { + cout << setw(width) << fixed << setprecision(prec) << w; + } + cout << endl; + } + cout << "Deltaweights:" << endl; + BOOST_FOREACH(vector i, mDeltaWeights) + { + BOOST_FOREACH(double w, i) + { + cout << setw(width) << setprecision(prec) << w; + } + cout << endl; + } + cout << "OldUpdate:" << endl; + BOOST_FOREACH(vector i, mOldUpdate) + { + BOOST_FOREACH(double w, i) + { + cout << setw(width) << setprecision(prec) << w; + } + cout << endl; + } + cout << "Activity:" << endl; + BOOST_FOREACH(double w, mActivity) + { + cout << setw(width) << setprecision(prec) << w; + } + cout << endl; + cout << "=================================" << endl; +} + +double MLP::sigmoid(const double& a) +{ + double res = 0.0; + res = 1.0 / (1.0 + exp(-a) ); + return res; +} + +void MLP::propagate(const Pattern& pattern) +{ + uint32_t i,j; + double activation = 0.0; + if (pattern.size() != (mStartHidden - 1) ) { + cerr << "Pattern does not match input neurons: " << pattern.size() << " != " << (mStartHidden - 1) << endl; + exit(1); + } + for (i=1 ; i < mStartHidden ; i++) { + mActivity.at(i) = pattern.at(i - 1); + } + for (i=mStartHidden ; i