In: Computer Science
Create a basic functioning Deep Belief Network coding using C++ or MATLAB.
// NeuralNetwork.hpp
#include <eigen3/Eigen/Eigen>
#include <iostream>
#include <vector>
// use typedefs for future ease for changing data types like :
float to double
typedef float Scalar;
typedef Eigen::MatrixXf Matrix;
typedef Eigen::RowVectorXf RowVector;
typedef Eigen::VectorXf ColVector;
// neural network implementation class!
class NeuralNetwork {
public:
// constructor
NeuralNetwork(std::vector<uint> topology, Scalar
learningRate = Scalar(0.005));
// function for forward propagation of data
void propagateForward(RowVector& input);
// function for backward propagation of errors made
by neurons
void propagateBackward(RowVector& output);
// function to calculate errors made by neurons in
each layer
void calcErrors(RowVector& output);
// function to update the weights of
connections
void updateWeights();
// function to train the neural network give an
array of data points
void train(std::vector<RowVector*> data);
// storage objects for working of neural
network
/*
use pointers when using
std::vector<Class> as std::vector<Class> calls
destructor of
Class as soon as it is pushed back!
when we use pointers it can't do that, besides
it also makes our neural network
class less heavy!! It would be nice if you can use
smart pointers instead of usual
ones like this
*/
std::vector<RowVector*> neuronLayers; // stores
the different layers of out network
std::vector<RowVector*> cacheLayers; // stores
the unactivated (activation fn not yet applied) values of
layers
std::vector<RowVector*> deltas; // stores the
error contribution of each neurons
std::vector<Matrix*> weights; // the connection
weights itself
Scalar learningRate;
};
Code: Constructor for the Neural Network Class
filter_none
edit
play_arrow
brightness_4
|
Code: Feed Forward Algorithm
filter_none
brightness_4
Calculating Errors: filter_none brightness_4
Code: Updating the weights filter_none brightness_4
Backpropagation Algorithm: filter_none brightness_4
Code: Activation Function filter_none brightness_4
Code: Training neural network filter_none brightness_4
Code: Loading data filter_none brightness_4
The user can read csv files using this code and paste this in the neural network class but be careful, the declarations and definitions must be kept in separate files (NeuralNetwork.cpp and NeuralNetwork.h). Save all the files and be with me for a few minutes! Code: Generate Some Noise i.e. training data filter_none edit play_arrow brightness_4
Code: Implementation of the neural network. filter_none brightness_4
|
note: plzzz don't give dislike.....plzzz comment if you have any problem i will try to solve your problem.....plzzz give thumbs up i am in need....