GURLS++  2.0.00
C++ Implementation of GURLS Matlab Toolbox
optimization.h
00001 /*
00002   * The GURLS Package in C++
00003   *
00004   * Copyright (C) 2011-1013, IIT@MIT Lab
00005   * All rights reserved.
00006   *
00007  * author:  M. Santoro
00008  * email:   msantoro@mit.edu
00009  * website: http://cbcl.mit.edu/IIT@MIT/IIT@MIT.html
00010   *
00011   * Redistribution and use in source and binary forms, with or without
00012   * modification, are permitted provided that the following conditions
00013   * are met:
00014   *
00015   *     * Redistributions of source code must retain the above
00016   *       copyright notice, this list of conditions and the following
00017   *       disclaimer.
00018   *     * Redistributions in binary form must reproduce the above
00019   *       copyright notice, this list of conditions and the following
00020   *       disclaimer in the documentation and/or other materials
00021   *       provided with the distribution.
00022   *     * Neither the name(s) of the copyright holders nor the names
00023   *       of its contributors or of the Massacusetts Institute of
00024   *       Technology or of the Italian Institute of Technology may be
00025   *       used to endorse or promote products derived from this software
00026   *       without specific prior written permission.
00027   *
00028   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00031   * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00032   * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00033   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00034   * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00035   * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00036   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00037   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00038   * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00039   * POSSIBILITY OF SUCH DAMAGE.
00040   */
00041 
00042 
00043 #ifndef _GURLS_OPTIMIZATION_H_
00044 #define _GURLS_OPTIMIZATION_H_
00045 
00046 #include <iostream>
00047 #include <cmath>
00048 #include <algorithm>
00049 #include <map>
00050 #include <string>
00051 
00052 #include "gurls++/options.h"
00053 #include "gurls++/optlist.h"
00054 #include "gurls++/gmat2d.h"
00055 #include "gurls++/gvec.h"
00056 #include "gurls++/gmath.h"
00057 #include "gurls++/exceptions.h"
00058 
00059 namespace gurls
00060 {
00061 
00062 template <typename T>
00063 class RLSAuto;
00064 
00065 template <typename T>
00066 class RLSPrimal;
00067 
00068 template <typename T>
00069 class RLSPrimalr;
00070 
00071 template <typename T>
00072 class RLSDual;
00073 
00074 template <typename T>
00075 class RLSDualr;
00076 
00077 template <typename T>
00078 class RLSPegasos;
00079 
00080 template <typename T>
00081 class RLSGPRegr;
00082 
00083 template <typename T>
00084 class RLSPrimalRecInit;
00085 
00086 template <typename T>
00087 class RLSPrimalRecUpdate;
00088 
00089 template <typename T>
00090 class RLSRandFeats;
00091 
00097 class BadOptimizerCreation : public gException
00098 {
00099 public:
00100 
00104     BadOptimizerCreation(std::string type): gException("Cannot create type " + type) {}
00105 };
00106 
00110 template <typename T>
00111 class Optimizer
00112 {
00113 public:
00114 
00122     virtual GurlsOptionsList* execute(const gMat2D<T>& X, const gMat2D<T>& Y, const GurlsOptionsList& opt) = 0;
00123 
00130     static Optimizer<T>* factory(const std::string& id) throw(BadOptimizerCreation)
00131     {
00132       if(id == "rlsauto")
00133         return new RLSAuto<T>;
00134       if(id == "rlsprimal")
00135         return new RLSPrimal<T>;
00136       if(id == "rlsprimalr")
00137         return new RLSPrimalr<T>;
00138       if(id == "rlsdual")
00139         return new RLSDual<T>;
00140       if(id == "rlsdualr")
00141         return new RLSDualr<T>;
00142       if(id == "rlspegasos")
00143         return new RLSPegasos<T>;
00144       if(id == "rlsgpregr")
00145         return new RLSGPRegr<T>;
00146       if(id == "rlsprimalrecinit")
00147         return new RLSPrimalRecInit<T>;
00148       if(id == "rlsprimalrecupdate")
00149         return new RLSPrimalRecUpdate<T>;
00150       if(id == "rlsrandfeats")
00151         return new RLSRandFeats<T>;
00152 
00153         throw BadOptimizerCreation(id);
00154     }
00155 };
00156 
00157 }
00158 #endif // _GURLS_OPTIMIZATION_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends