mi024

College project master 1 "Projet IAD"
git clone https://esimon.eu/repos/mi024.git
Log | Files | Refs | README

commit ed1425560d7afef27815068a304756f2b5af32bd
parent 69f35ff0382a5fbdfdfc4dbbce299e23f720fcb6
Author: Étienne Simon <etienne.jl.simon@gmail.com>
Date:   Mon,  6 May 2013 03:35:33 +0200

Add more criterion/module to the factories.

Diffstat:
Msrc/factory.cpp | 67++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 50 insertions(+), 17 deletions(-)

diff --git a/src/factory.cpp b/src/factory.cpp @@ -21,21 +21,17 @@ #include <nmlp/criterions/CPUSquareLoss.h> #include <nmlp/criterions/GPUHingeLoss.h> #include <nmlp/criterions/GPUSquareLoss.h> -#include <nmlp/modules/CPUConcatenation.h> #include <nmlp/modules/CPUIdentity.h> #include <nmlp/modules/CPULinear.h> #include <nmlp/modules/CPULogistic.h> #include <nmlp/modules/CPUPositiveShrink.h> #include <nmlp/modules/CPUSparseLinear.h> #include <nmlp/modules/CPUTanH.h> -#include <nmlp/modules/CPUUnique.h> #include <nmlp/modules/GPUIdentity.h> #include <nmlp/modules/GPULinear.h> #include <nmlp/modules/GPUPositiveShrink.h> #include <nmlp/modules/GPUTanH.h> -#include <nmlp/modules/GPUUnique.h> #include <nmlp/modules/SequentialModule.h> -#include <nmlp/modules/TableModule.h> #include "factory.hpp" @@ -45,7 +41,7 @@ boost::shared_ptr<SequentialModule> interactive_module_factory(std::istream &in, std::string type; while(out << "Module? ", in >> type, type!="end"){ - if(type=="CPULinear"){ + if(type=="CPULinear" || type=="CPUSparseLinear" || type=="GPULinear"){ std::size_t is=input_size; out << "Output size? "; in >> input_size; @@ -53,12 +49,29 @@ boost::shared_ptr<SequentialModule> interactive_module_factory(std::istream &in, double variance; in >> variance; - boost::shared_ptr<CPULinear> p=boost::make_shared<CPULinear>(is, input_size); - p->randomize(variance); - module->addModule(p); + if(type=="CPULinear"){ + boost::shared_ptr<CPULinear> p=boost::make_shared<CPULinear>(is, input_size); + p->randomize(variance); + module->addModule(p); + } else if(type=="CPUSparseLinear"){ + boost::shared_ptr<CPUSparseLinear> p=boost::make_shared<CPUSparseLinear>(is, input_size); + p->randomize(variance); + module->addModule(p); + } else if(type=="GPULinear"){ + boost::shared_ptr<GPULinear> p=boost::make_shared<GPULinear>(is, input_size); + p->randomize(variance); + module->addModule(p); + } } - else if(type=="CPULogistic") module->addModule(boost::make_shared<CPULogistic>(input_size)); - else if(type=="CPUTanH") module->addModule(boost::make_shared<CPUTanH>(input_size)); + else if(type=="CPUIdentity") module->addModule(boost::make_shared<CPUIdentity>(input_size)); + else if(type=="CPULogistic") module->addModule(boost::make_shared<CPULogistic>(input_size)); + else if(type=="CPUTanH") module->addModule(boost::make_shared<CPUTanH>(input_size)); + else if(type=="CPUPositiveShrink") module->addModule(boost::make_shared<CPUPositiveShrink>(input_size)); + else if(type=="GPUIdentity") module->addModule(boost::make_shared<GPUIdentity>(input_size)); + else if(type=="GPULogistic") module->addModule(boost::make_shared<GPULogistic>(input_size)); + else if(type=="GPUTanH") module->addModule(boost::make_shared<GPUTanH>(input_size)); + else if(type=="GPUPositiveShrink") module->addModule(boost::make_shared<GPUPositiveShrink>(input_size)); + else out << "Unknown module name.\n"; } @@ -80,7 +93,7 @@ boost::shared_ptr<SequentialModule> detached_module_factory(boost::program_optio std::vector<float>::const_iterator variance_it=variances.begin(); for(; module_it!=modules_str.end(); ++module_it){ - if(*module_it=="CPULinear"){ + if(*module_it=="CPULinear" || *module_it=="CPUSparseLinear" || *module_it=="GPULinear"){ if(size_it==sizes.end()) throw std::runtime_error("Missing a size value in configuration file"); if(variance_it==variances.end()) @@ -88,12 +101,29 @@ boost::shared_ptr<SequentialModule> detached_module_factory(boost::program_optio std::size_t is=input_size; input_size=*size_it++; - boost::shared_ptr<CPULinear> p=boost::make_shared<CPULinear>(is, input_size); - p->randomize(*variance_it++); - module->addModule(p); + + if(*module_it=="CPULinear"){ + boost::shared_ptr<CPULinear> p=boost::make_shared<CPULinear>(is, input_size); + p->randomize(*variance_it++); + module->addModule(p); + } else if(*module_it=="CPUSparseLinear"){ + boost::shared_ptr<CPUSparseLinear> p=boost::make_shared<CPUSparseLinear>(is, input_size); + p->randomize(*variance_it++); + module->addModule(p); + } else if(*module_it=="GPULinear"){ + boost::shared_ptr<GPULinear> p=boost::make_shared<GPULinear>(is, input_size); + p->randomize(*variance_it++); + module->addModule(p); + } } - else if(*module_it=="CPULogistic") module->addModule(boost::make_shared<CPULogistic>(input_size)); - else if(*module_it=="CPUTanH") module->addModule(boost::make_shared<CPUTanH>(input_size)); + else if(*module_it=="CPUIdentity") module->addModule(boost::make_shared<CPUIdentity>(input_size)); + else if(*module_it=="CPULogistic") module->addModule(boost::make_shared<CPULogistic>(input_size)); + else if(*module_it=="CPUTanH") module->addModule(boost::make_shared<CPUTanH>(input_size)); + else if(*module_it=="CPUPositiveShrink") module->addModule(boost::make_shared<CPUPositiveShrink>(input_size)); + else if(*module_it=="GPUIdentity") module->addModule(boost::make_shared<GPUIdentity>(input_size)); + else if(*module_it=="GPULogistic") module->addModule(boost::make_shared<GPULogistic>(input_size)); + else if(*module_it=="GPUTanH") module->addModule(boost::make_shared<GPUTanH>(input_size)); + else if(*module_it=="GPUPositiveShrink") module->addModule(boost::make_shared<GPUPositiveShrink>(input_size)); else throw std::runtime_error("Unknown module name in configuration file"); } @@ -107,7 +137,10 @@ boost::shared_ptr<SequentialModule> detached_module_factory(boost::program_optio boost::shared_ptr<Criterion> criterion_factory(std::string const &name, std::size_t size){ if(name=="CPUSquareLoss") return boost::make_shared<CPUSquareLoss>(size); - + if(name=="CPUHingeLoss") return boost::make_shared<CPUHingeLoss>(size); + if(name=="CPUMaxLoss") return boost::make_shared<CPUMaxLoss>(); + if(name=="GPUSquareLoss") return boost::make_shared<GPUSquareLoss>(size); + if(name=="GPUHingeLoss") return boost::make_shared<GPUHingeLoss>(size); throw std::runtime_error("Criterion factory called on an unknown identifier"); }