/* mlp.cpp - implement definitions of mlp.h Copyright (C) 2010 Rui Rodrigues This software is released under the terms of the GNU General Public License (http://www.gnu.org/copyleft/gpl.html). */ #include "mlp.h" #include mlp::mlp(unsigned Numhidlayers, vector& Dimlayers){ if (Numhidlayers!=Dimlayers.size()-2) throw (const char*) "numlayers and dimlayers don t agree on two argument constructor!"; numhidlayers=Numhidlayers; dimlayers=Dimlayers; //buid dimmatrices dimmatrices=vector(2*(numhidlayers+1)); for(unsigned i=0;i< numhidlayers+1;++i){ dimmatrices[2*i]=dimlayers[i]+1;//includes bias dimmatrices[2*i+1]=dimlayers[i+1]; } //build mlpmatrix mlpmatrix=vector(numhidlayers+1); for(unsigned i=0;i& Dimlayers,vector& Mlpmatrix){ init(Numhidlayers,Dimlayers,Mlpmatrix); } mlp::mlp(const mlp& mlp_other){ init(mlp_other.numhidlayers,mlp_other.dimlayers,mlp_other.mlpmatrix); } mlp::~mlp(){ for(unsigned i=0;isize) throw (const char*) "mlp-matrices dimensions and vector size are not compatible!"; else{ unsigned start=0; for(unsigned i=0;i nrows(num_matrices), ncols(num_matrices); for(unsigned i=0;i& Dimlayers, const vector& mlpmatrix){ if (Numhidlayers!=Dimlayers.size()-2) throw (const char*) "numlayers and dimlayers don t agree!"; unsigned nrows,ncols; for(unsigned i=0;isize1; ncols=mlpmatrix[i]->size2; if((nrows!=Dimlayers[i]+1)||(ncols!=Dimlayers[i+1])) throw (const char*) "dimlayers and mlpmatrix dimensions don t agre don t agree!"; } } void mlp::init(const unsigned Numhidlayers,const vector& Dimlayers, const vector& Mlpmatrix){ checkinitialdatacompatibility( Numhidlayers, Dimlayers, Mlpmatrix); numhidlayers=Numhidlayers; dimlayers=Dimlayers; //buid dimmatrices dimmatrices=vector(2*(numhidlayers+1)); for(unsigned i=0;i< numhidlayers+1;++i){ dimmatrices[2*i]=dimlayers[i]+1;//includes bias dimmatrices[2*i+1]=dimlayers[i+1]; } //build mlpmatrix coping data from Mlpmatrix mlpmatrix=vector(numhidlayers+1); for(unsigned i=0;i