libeblearn
|
00001 /*************************************************************************** 00002 * Copyright (C) 2011 by Yann LeCun and Pierre Sermanet * 00003 * yann@cs.nyu.edu, pierre.sermanet@gmail.com * 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Redistribution under a license not approved by the Open Source 00014 * Initiative (http://www.opensource.org) must display the 00015 * following acknowledgement in all advertising material: 00016 * This product includes software developed at the Courant 00017 * Institute of Mathematical Sciences (http://cims.nyu.edu). 00018 * * The names of the authors may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00023 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY 00025 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00026 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00028 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00029 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 ***************************************************************************/ 00032 00033 #ifndef EBL_NORMALIZATION_H_ 00034 #define EBL_NORMALIZATION_H_ 00035 00036 #include "ebl_defines.h" 00037 #include "libidx.h" 00038 #include "ebl_states.h" 00039 #include "ebl_basic.h" 00040 #include "ebl_arch.h" 00041 #include "ebl_nonlinearity.h" 00042 00043 namespace ebl { 00044 00047 template <typename T, class Tstate = bbstate_idx<T> > 00048 class divisive_norm_module : public module_1_1<T, Tstate> { 00049 public: 00058 divisive_norm_module(idxdim &kerdim, int nf, bool mirror = false, 00059 bool threshold = true, parameter<T,Tstate> *p = NULL, 00060 const char *name = "divisive_norm", 00061 bool across_features = true, double cgauss = 2.0, 00062 bool fsum_div = false, float fsum_split = 1.0, 00063 double epsilon = 1e-6); 00065 virtual ~divisive_norm_module(); 00067 virtual void fprop(Tstate &in, Tstate &out); 00069 virtual void bprop(Tstate &in, Tstate &out); 00071 virtual void bbprop(Tstate &in, Tstate &out); 00074 virtual void dump_fprop(Tstate &in, Tstate &out); 00078 virtual divisive_norm_module<T,Tstate>* copy(parameter<T,Tstate> *p = NULL); 00083 virtual bool optimize_fprop(Tstate &in, Tstate &out); 00085 virtual std::string describe(); 00086 00087 // friends 00088 friend class divisive_norm_module_gui; 00089 friend class contrast_norm_module_gui; 00090 template <typename T1, class Tstate1> friend class contrast_norm_module; 00091 00092 // members //////////////////////////////////////////////////////// 00093 public: 00094 bool mirror; 00095 protected: 00096 parameter<T,Tstate> *param; 00097 layers<T, Tstate> convvar; 00098 power_module<T,Tstate> sqrtmod; 00099 power_module<T,Tstate> invmod; 00100 power_module<T,Tstate> sqmod; 00101 thres_module<T,Tstate> thres; 00102 mul_module<T,Tstate> mcw; 00103 convolution_module<T,Tstate> *divconv; 00104 module_1_1<T,Tstate> *padding; 00105 idx<T> w; 00106 Tstate insq, invar, instd, thstd, invstd; 00107 bool threshold; 00108 int nfeatures; 00109 idxdim kerdim; 00110 bool across_features; 00111 double epsilon; 00112 }; 00113 00118 template <typename T, class Tstate = bbstate_idx<T> > 00119 class subtractive_norm_module : public module_1_1<T, Tstate> { 00120 public: 00131 subtractive_norm_module(idxdim &kerdim, int nf, bool mirror = false, 00132 bool global_norm = false, 00133 parameter<T,Tstate> *p = NULL, 00134 const char *name = "subtractive_norm", 00135 bool across_features = true, 00136 double cgauss = 2.0, bool fsum_div = false, 00137 float fsum_split = 1.0); 00139 virtual ~subtractive_norm_module(); 00141 virtual void fprop(Tstate &in, Tstate &out); 00143 virtual void bprop(Tstate &in, Tstate &out); 00145 virtual void bbprop(Tstate &in, Tstate &out); 00148 virtual void dump_fprop(Tstate &in, Tstate &out); 00152 virtual subtractive_norm_module<T,Tstate>* 00153 copy(parameter<T,Tstate> *p = NULL); 00158 virtual bool optimize_fprop(Tstate &in, Tstate &out); 00160 virtual std::string describe(); 00161 00162 // friends 00163 friend class contrast_norm_module_gui; 00164 template <typename T1, class Tstate1> friend class contrast_norm_module; 00165 00166 // members //////////////////////////////////////////////////////// 00167 protected: 00168 parameter<T,Tstate> *param; 00169 layers<T, Tstate> convmean; 00170 convolution_module<T,Tstate> *meanconv; 00171 module_1_1<T,Tstate> *padding; 00172 idx<T> w; 00173 diff_module<T,Tstate> difmod; 00174 Tstate inmean; 00175 bool global_norm; 00176 int nfeatures; 00177 idxdim kerdim; 00178 bool across_features; 00179 bool mirror; 00180 }; 00181 00186 template <typename T, class Tstate = bbstate_idx<T> > 00187 class contrast_norm_module : public module_1_1<T,Tstate> { 00188 public: 00199 contrast_norm_module(idxdim &kerdim, int nf, bool mirror = false, 00200 bool threshold = true, bool global_norm = false, 00201 parameter<T,Tstate> *p = NULL, 00202 const char *name = "contrast_norm", 00203 bool across_features = true, bool learn_mean = false, 00204 double cnorm = 2.0, bool fsum_div = false, 00205 float fsum_split = 1.0, double epsilon = 1e-6); 00207 virtual ~contrast_norm_module(); 00209 virtual void fprop(Tstate &in, Tstate &out); 00211 virtual void bprop(Tstate &in, Tstate &out); 00213 virtual void bbprop(Tstate &in, Tstate &out); 00216 virtual void dump_fprop(Tstate &in, Tstate &out); 00220 virtual contrast_norm_module<T,Tstate>* copy(parameter<T,Tstate> *p = NULL); 00225 virtual bool optimize_fprop(Tstate &in, Tstate &out); 00227 virtual std::string describe(); 00228 00229 // friends 00230 friend class contrast_norm_module_gui; 00231 00232 // members //////////////////////////////////////////////////////// 00233 protected: 00234 subtractive_norm_module<T, Tstate> subnorm; 00235 divisive_norm_module<T, Tstate> divnorm; 00236 Tstate tmp; 00237 bool global_norm; 00238 bool learn_mean; 00239 }; 00240 00242 // laplacian_module 00246 template <typename T, class Tstate = bbstate_idx<T> > 00247 class laplacian_module : public module_1_1<T, Tstate> { 00248 public: 00253 laplacian_module(int nf, bool mirror = false, bool global_norm = false, 00254 const char *name = "laplacian_module"); 00256 virtual ~laplacian_module(); 00258 virtual void fprop(Tstate &in, Tstate &out); 00260 virtual laplacian_module<T,Tstate>* copy(); 00262 virtual std::string describe(); 00263 00264 // members //////////////////////////////////////////////////////// 00265 private: 00266 bool mirror; 00267 convolution_module<T,Tstate> *conv; 00268 module_1_1<T,Tstate> *pad; 00269 diff_module<T,Tstate> diff; 00270 Tstate padded, filtered; 00271 parameter<T,Tstate> param; 00272 idx<T> filter; 00273 bool global_norm; 00274 int nfeatures; 00275 idxdim kerdim; 00276 }; 00277 00278 } // namespace ebl { 00279 00280 #include "ebl_normalization.hpp" 00281 00282 #endif /* EBL_NORMALIZATION_H_ */