GURLS++  2.0.00
C++ Implementation of GURLS Matlab Toolbox
dual.h
00001 /*
00002  * The GURLS Package in C++
00003  *
00004  * Copyright (C) 2011-1013, Matteo Santoro
00005  * All rights reserved.
00006  *
00007  * author:  M. Santoro
00008  * email:   matteo.santoro@gmail.com
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted provided that the following conditions
00012  * are met:
00013  *
00014  *     * Redistributions of source code must retain the above
00015  *       copyright notice, this list of conditions and the following
00016  *       disclaimer.
00017  *     * Redistributions in binary form must reproduce the above
00018  *       copyright notice, this list of conditions and the following
00019  *       disclaimer in the documentation and/or other materials
00020  *       provided with the distribution.
00021  *     * Neither the name(s) of the copyright holders nor the names
00022  *       of its contributors or of the Massacusetts Institute of
00023  *       Technology or of the Italian Institute of Technology may be
00024  *       used to endorse or promote products derived from this software
00025  *       without specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00028  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00029  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00030  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00031  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00032  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00033  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00034  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00036  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00037  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00038  * POSSIBILITY OF SUCH DAMAGE.
00039  */
00040 
00041 
00042 #ifndef _GURLS_DUAL_H
00043 #define _GURLS_DUAL_H
00044 
00045 #include <cstdio>
00046 #include <cstring>
00047 #include <iostream>
00048 #include <cmath>
00049 #include <algorithm>
00050 
00051 #include "gurls++/gmath.h"
00052 #include "gurls++/options.h"
00053 #include "gurls++/optlist.h"
00054 
00055 #include "gurls++/pred.h"
00056 #include "gurls++/primal.h"
00057 
00058 
00059 namespace gurls {
00060 
00066 template <typename T>
00067 class PredDual: public Prediction<T> {
00068 
00069 public:
00081     OptMatrix<gMat2D<T> >* execute( const gMat2D<T>& X, const gMat2D<T>& Y, const GurlsOptionsList& opt);
00082 };
00083 
00084 template <typename T>
00085 OptMatrix<gMat2D<T> >* PredDual<T>::execute(const gMat2D<T>& X, const gMat2D<T>& Y, const GurlsOptionsList& opt)
00086 {
00087     if(opt.hasOpt("kernel"))
00088     {
00089         if(opt.getOptValue<OptString>("kernel.type") == "linear")
00090         {
00091             PredPrimal<T> pred;
00092             return pred.execute(X, Y, opt);
00093         }
00094     }
00095 
00096     const gMat2D<T> &K = opt.getOptValue<OptMatrix<gMat2D<T> > >("predkernel.K");
00097     const gMat2D<T> &C = opt.getOptValue<OptMatrix<gMat2D<T> > >("optimizer.C");
00098 
00099     gMat2D<T>* Z = new gMat2D<T>(K.rows(), C.cols());
00100 
00101 
00102     dot(K.getData(), C.getData(), Z->getData(), K.rows(), K.cols(), C.rows(), C.cols(), Z->rows(), Z->cols(), CblasNoTrans, CblasNoTrans, CblasColMajor);
00103 
00104     return new OptMatrix<gMat2D<T> >(*Z);
00105 }
00106 
00107 }
00108 
00109 #endif // _GURLS_DUAL_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends