00001 #include <string>
00002 #include <memory>
00003
00004 #include "Individual.hpp"
00005 #include "Mlp.hpp"
00006 #include "Dataset.hpp"
00007 #include "MlpObjectives.hpp"
00008
00009 using namespace std;
00010
00011 #ifndef MLPINDIVIDUAL_HPP_
00012 #define MLPINDIVIDUAL_HPP_
00013
00014 class MlpIndividual;
00015
00016
00018 class MlpBackpropUnaryOperator{
00019 private:
00020 size_t _iters;
00021 double _step;
00022 double _preErr;
00023 double _incRat;
00024 double _decRat;
00025 vector<double> _classweights;
00026 double _sswpen;
00027 bool _rerandomize;
00028 bool _applyssw;
00029 bool _mee;
00030 public:
00031 MlpBackpropUnaryOperator(size_t iters, double step, const vector<double> & classweights, bool rerandomize, bool applyssw, bool mee);
00032 void operate(MlpIndividual & mi, mt19937 * mt);
00033 };
00034
00036 class MlpIndividual : public Individual {
00037 friend class MlpBackpropUnaryOperator;
00038 private:
00039 unique_ptr<jymlp::Mlp> mlp;
00040 shared_ptr<Dataset> ds;
00041 MlpObjKind objkind;
00043
00044 unique_ptr<MlpBackpropUnaryOperator> improver;
00045 protected:
00046 void impl_from_stream(istream& repr);
00047 void impl_to_stream(ostream& repr);
00048
00049
00051 void crossWith(MlpIndividual &other);
00052 public:
00054 MlpIndividual();
00055
00060 MlpIndividual(const MlpObjectives& mobj, unique_ptr<jymlp::Mlp> imlp, shared_ptr<Dataset> ids);
00061
00062
00063 MlpIndividual(const MlpIndividual & original);
00064
00065 virtual ~MlpIndividual();
00066
00067 virtual void addUnaryOperator(unique_ptr<MlpBackpropUnaryOperator> uop);
00068
00069 virtual Individual * clone();
00070
00071 virtual void evaluate();
00072
00073 virtual void mutate();
00074
00075 virtual void improve(mt19937 * mt);
00076
00077 virtual vector<double> getTrace();
00078
00079 virtual pair<unique_ptr<Individual>,unique_ptr<Individual> >
00080 crossWith(Individual & other);
00081
00082
00083 };
00084
00085 class MlpIndividualReader : public IndividualReader{
00086 public:
00087 virtual Individual * fromStream(istream & ist) const;
00088 };
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099 #endif
00100