Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- === added file 'CMakeLists.txt'
- --- CMakeLists.txt 1970-01-01 00:00:00 +0000
- +++ CMakeLists.txt 2011-05-04 22:56:26 +0000
- @@ -0,0 +1,28 @@
- +# poner nombre proyecto y lenguaje
- +# estas 3 lineas consideralas obligatorias
- +# CXX es el lenguaje -> C++
- +PROJECT( DECORATOR CXX )
- +CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
- +CMAKE_POLICY(VERSION 2.6)
- +
- +# nombre archivo salida, se guarda en la variable NAME_OUTPUT
- +SET(NAME_OUTPUT main)
- +
- +# busca todos los archivos C++ del directorio actual (junto al CMakeLists.txt)
- +# y los guarda en la variable FICHEROS
- +AUX_SOURCE_DIRECTORY(${CMAKE_SOURCE_DIR} FICHEROS)
- +
- +# directorios donde se van a encontrar las librearias compartidas o estaticas
- +LINK_DIRECTORIES(${CMAKE_SOURCE_DIR})
- +
- +# crear un ejecutable con el nombre de la variable
- +ADD_EXECUTABLE(${NAME_OUTPUT} ${FICHEROS})
- +
- +# linkado de librerias. por ejemplo (los 2 serian igual de válidos):
- +# TARGET_LINK_LIBRARIES(${NAME_OUTPUT} OgreMain)
- +# TARGET_LINK_LIBRARIES(${NAME_OUTPUT} -lOgreMain)
- +TARGET_LINK_LIBRARIES(${NAME_OUTPUT})
- +
- +# para generar todo:
- +# cmake . // genera los makefiles
- +# make // ya sabes :D
- === added file 'NNPrerequisitos.h'
- --- NNPrerequisitos.h 1970-01-01 00:00:00 +0000
- +++ NNPrerequisitos.h 2011-05-04 22:56:26 +0000
- @@ -0,0 +1,16 @@
- +#ifndef NNPrerequisitos
- +#define NNPrerequisitos
- +
- +#include <fstream>
- +#include <vector>
- +#include <string>
- +#include <cstring>
- +#include <cstdlib>
- +
- +class dataEntry;
- +class trainingDataSet;
- +class dataReader;
- +class neuralNetwork;
- +class neuralNetworkTrainer;
- +
- +#endif
- === modified file 'dataReader.cpp'
- --- dataReader.cpp 2011-05-04 22:54:25 +0000
- +++ dataReader.cpp 2011-05-04 22:56:26 +0000
- @@ -43,11 +43,11 @@
- //read data
- while ( !inputFile.eof() )
- {
- - getline(inputFile, line);
- + getline(inputFile, line);
- //process line
- if (line.length() > 2 ) processLine(line);
- - }
- + }
- //shuffle data
- //random_shuffle(data.begin(), data.end());
- @@ -87,7 +87,7 @@
- double* pattern = new double[nInputs];
- double* target = new double[nTargets];
- - //store inputs
- + //store inputs
- char* cstr = new char[line.size()+1];
- char* t;
- strcpy(cstr, line.c_str());
- === modified file 'dataReader.h'
- --- dataReader.h 2011-05-04 22:54:25 +0000
- +++ dataReader.h 2011-05-04 22:56:26 +0000
- @@ -8,9 +8,7 @@
- #ifndef _DATAREADER
- #define _DATAREADER
- -//include standard header files
- -#include <vector>
- -#include <string>
- +#include "NNPrerequisitos.h"
- /*******************************************************************
- * stores a data item
- @@ -26,7 +24,7 @@
- dataEntry(double* p, double* t): pattern(p), target(t) {}
- - ~dataEntry()
- + virtual ~dataEntry()
- {
- delete[] pattern;
- delete[] target;
- @@ -46,6 +44,7 @@
- std::vector<dataEntry*> validationSet;
- trainingDataSet(){}
- + virtual ~trainingDataSet(){}
- void clear()
- {
- @@ -91,7 +90,7 @@
- public:
- dataReader(): creationApproach(NONE), numTrainingSets(-1) {}
- - ~dataReader();
- + virtual ~dataReader();
- bool loadDataFile( const char* filename, int nI, int nT );
- void setCreationApproach( int approach, double param1 = -1, double param2 = -1 );
- === modified file 'main.cpp'
- --- main.cpp 2011-05-04 22:54:25 +0000
- +++ main.cpp 2011-05-04 22:56:26 +0000
- @@ -10,13 +10,14 @@
- #include <ctime>
- //custom includes
- +#include "dataReader.h"
- #include "neuralNetwork.h"
- #include "neuralNetworkTrainer.h"
- //use standard namespace
- using namespace std;
- -void main()
- +int main()
- {
- //seed random number generator
- srand( (unsigned int) time(0) );
- @@ -45,5 +46,7 @@
- nn.saveWeights("weights.csv");
- cout << endl << endl << "-- END OF PROGRAM --" << endl;
- - char c; cin >> c;
- + //char c; cin >> c;
- +
- + return 0;
- }
- === modified file 'neuralNetwork.cpp'
- --- neuralNetwork.cpp 2011-05-04 22:54:25 +0000
- +++ neuralNetwork.cpp 2011-05-04 22:56:26 +0000
- @@ -1,12 +1,14 @@
- +#include "neuralNetwork.h"
- +
- +#include "dataReader.h"
- +#include "neuralNetworkTrainer.h"
- +
- //standard includes
- #include <iostream>
- #include <vector>
- #include <fstream>
- #include <math.h>
- -//include definition file
- -#include "neuralNetwork.h"
- -
- using namespace std;
- /*******************************************************************
- @@ -72,7 +74,7 @@
- /*******************************************************************
- * Load Neuron Weights
- ********************************************************************/
- -bool neuralNetwork::loadWeights(char* filename)
- +bool neuralNetwork::loadWeights(const char* filename)
- {
- //open file for reading
- fstream inputFile;
- @@ -163,7 +165,7 @@
- /*******************************************************************
- * Save Neuron Weights
- ********************************************************************/
- -bool neuralNetwork::saveWeights(char* filename)
- +bool neuralNetwork::saveWeights(const char* filename)
- {
- //open file for reading
- fstream outputFile;
- @@ -314,15 +316,6 @@
- return 1/(1+exp(-x));
- }
- /*******************************************************************
- -* Output Clamping
- -********************************************************************/
- -inline int neuralNetwork::clampOutput( double x )
- -{
- - if ( x < 0.1 ) return 0;
- - else if ( x > 0.9 ) return 1;
- - else return -1;
- -}
- -/*******************************************************************
- * Feed Forward Operation
- ********************************************************************/
- void neuralNetwork::feedForward(double* pattern)
- === modified file 'neuralNetwork.h'
- --- neuralNetwork.h 2011-05-04 22:54:25 +0000
- +++ neuralNetwork.h 2011-05-04 22:56:26 +0000
- @@ -8,15 +8,13 @@
- #ifndef NNetwork
- #define NNetwork
- -#include "dataReader.h"
- -
- -class neuralNetworkTrainer;
- +#include "NNPrerequisitos.h"
- class neuralNetwork
- {
- //class members
- //--------------------------------------------------------------------------------------------
- -private:
- +public:
- //number of neurons
- int nInput, nHidden, nOutput;
- @@ -32,7 +30,7 @@
- //Friends
- //--------------------------------------------------------------------------------------------
- - friend neuralNetworkTrainer;
- + //friend neuralNetworkTrainer;
- //public methods
- //--------------------------------------------------------------------------------------------
- @@ -41,11 +39,11 @@
- //constructor & destructor
- neuralNetwork(int numInput, int numHidden, int numOutput);
- - ~neuralNetwork();
- + virtual ~neuralNetwork();
- //weight operations
- - bool loadWeights(char* inputFilename);
- - bool saveWeights(char* outputFilename);
- + bool loadWeights(const char* inputFilename);
- + bool saveWeights(const char* outputFilename);
- int* feedForwardPattern( double* pattern );
- double getSetAccuracy( std::vector<dataEntry*>& set );
- double getSetMSE( std::vector<dataEntry*>& set );
- @@ -53,11 +51,18 @@
- //private methods
- //--------------------------------------------------------------------------------------------
- -private:
- +public:
- void initializeWeights();
- inline double activationFunction( double x );
- - inline int clampOutput( double x );
- +
- + inline int clampOutput( double x )
- + {
- + if ( x < 0.1 ) return 0;
- + else if ( x > 0.9 ) return 1;
- + else return -1;
- + }
- +
- void feedForward( double* pattern );
- };
- === modified file 'neuralNetworkTrainer.cpp'
- --- neuralNetworkTrainer.cpp 2011-05-04 22:54:25 +0000
- +++ neuralNetworkTrainer.cpp 2011-05-04 22:56:26 +0000
- @@ -1,11 +1,13 @@
- +#include "neuralNetworkTrainer.h"
- +
- +#include "dataReader.h"
- +#include "neuralNetwork.h"
- +
- //standard includes
- #include <iostream>
- #include <fstream>
- #include <math.h>
- -//include definition file
- -#include "neuralNetworkTrainer.h"
- -
- using namespace std;
- /*******************************************************************
- @@ -50,6 +52,13 @@
- for ( int i=0; i <= NN->nOutput; i++ ) outputErrorGradients[i] = 0;
- }
- +/*******************************************************************
- +* Destructor
- +********************************************************************/
- +neuralNetworkTrainer::~neuralNetworkTrainer()
- +{
- +
- +}
- /*******************************************************************
- * Set training parameters
- === modified file 'neuralNetworkTrainer.h'
- --- neuralNetworkTrainer.h 2011-05-04 22:54:25 +0000
- +++ neuralNetworkTrainer.h 2011-05-04 22:56:26 +0000
- @@ -8,12 +8,7 @@
- #ifndef NNetworkTrainer
- #define NNetworkTrainer
- -//standard includes
- -#include <fstream>
- -#include <vector>
- -
- -//neural network header
- -#include "neuralNetwork.h"
- +#include "NNPrerequisitos.h"
- //Constant Defaults!
- #define LEARNING_RATE 0.001
- @@ -76,6 +71,8 @@
- public:
- neuralNetworkTrainer( neuralNetwork* untrainedNetwork );
- + virtual ~neuralNetworkTrainer();
- +
- void setTrainingParameters( double lR, double m, bool batch );
- void setStoppingConditions( int mEpochs, double dAccuracy);
- void useBatchLearning( bool flag ){ useBatch = flag; }
- @@ -94,4 +91,4 @@
- };
- -#endif
- \ No newline at end of file
- +#endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement