![]() |
GURLS++
2.0.00
C++ Implementation of GURLS Matlab Toolbox
|
00001 /* 00002 * The GURLS Package in C++ 00003 * 00004 * Copyright (C) 2011-1013, IIT@MIT Lab 00005 * All rights reserved. 00006 * 00007 * authors: 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_PRECISIONRECALL_H_ 00044 #define _GURLS_PRECISIONRECALL_H_ 00045 00046 #include "gurls++/perf.h" 00047 00048 #include "gurls++/utils.h" 00049 #include "gurls++/gvec.h" 00050 #include "gurls++/optmatrix.h" 00051 00052 namespace gurls { 00053 00059 template <typename T> 00060 class PerfPrecRec: public Performance<T>{ 00061 00062 public: 00075 GurlsOptionsList* execute(const gMat2D<T>& X, const gMat2D<T>& Y, const GurlsOptionsList& opt) throw(gException); 00076 }; 00077 00078 template<typename T> 00079 GurlsOptionsList* PerfPrecRec<T>::execute(const gMat2D<T>& /*X*/, const gMat2D<T>& Y, const GurlsOptionsList& opt) throw(gException) 00080 { 00081 const int rows = Y.rows(); 00082 const int cols = Y.cols(); 00083 00084 // if isfield (opt,'perf') 00085 // p = opt.perf; % lets not overwrite existing performance measures. 00086 // % unless they have the same name 00087 // end 00088 00089 GurlsOptionsList* perf; 00090 00091 if(opt.hasOpt("perf")) 00092 { 00093 GurlsOptionsList* tmp_opt = new GurlsOptionsList("tmp"); 00094 tmp_opt->copyOpt("perf", opt); 00095 00096 perf = GurlsOptionsList::dynacast(tmp_opt->getOpt("perf")); 00097 tmp_opt->removeOpt("perf", false); 00098 delete tmp_opt; 00099 00100 perf->removeOpt("ap"); 00101 perf->removeOpt("forho"); 00102 // perf->removeOpt("forplot"); 00103 } 00104 else 00105 perf = new GurlsOptionsList("perf"); 00106 00107 // y_true = y; 00108 const T* y_true = Y.getData(); 00109 00110 // y_pred = opt.pred; 00111 const gMat2D<T> &y_pred = opt.getOptValue<OptMatrix<gMat2D<T> > >("pred"); 00112 00113 gMat2D<T>* ap_mat = new gMat2D<T>(1, cols); 00114 T* ap = ap_mat->getData(); 00115 00116 T* work = new T[4*rows]; 00117 00118 // T = size(y,2); 00119 // for t = 1:T, 00120 for(int i=0; i<cols; ++i) 00121 { 00122 // p.ap(t) = precrec_driver(y_pred(:,t), y_true(:,t),0); 00123 // p.forho(t) = p.ap(t); 00124 00125 ap[i] = precrec_driver(y_pred.getData()+(i*rows), y_true+(i*rows), rows, work); 00126 00127 // p.forplot(t) = p.ap(t); 00128 } 00129 00130 delete [] work; 00131 00132 OptMatrix<gMat2D<T> >* ap_opt = new OptMatrix<gMat2D<T> >(*ap_mat); 00133 perf->addOpt("ap", ap_opt); 00134 00135 OptMatrix<gMat2D<T> >* forho_opt = new OptMatrix<gMat2D<T> >(*(new gMat2D<T>(*ap_mat))); 00136 perf->addOpt("forho", forho_opt); 00137 00138 // OptMatrix<gMat2D<T> >* forplot_opt = new OptMatrix<gMat2D<T> >(*(new gMat2D<T>(*ap_mat))); 00139 // perf->addOpt("forplot", forplot_opt); 00140 00141 return perf; 00142 } 00143 00144 } 00145 00146 #endif //_GURLS_PRECISIONRECALL_H_