libeblearngui
|
00001 /*************************************************************************** 00002 * Copyright (C) 2009 by Pierre Sermanet * 00003 * 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 ELB_BASIC_GUI_HPP_ 00034 #define ELB_BASIC_GUI_HPP_ 00035 00036 using namespace std; 00037 00038 #define MAXWIDTH 1000 00039 00040 namespace ebl { 00041 00043 // linear_module 00044 00045 #define LINEAR_MODULE_GUI(dname, op, T, state) \ 00046 template <typename T, class Tstate> \ 00047 void linear_module_gui::dname(linear_module<T,Tstate> &nn, \ 00048 Tstate &in, Tstate &out, \ 00049 uint &h0, uint &w0, \ 00050 double zoom, T vmin, T vmax, \ 00051 bool show_out) { \ 00052 /* run it */ \ 00053 nn.op(in, out); \ 00054 uint h = h0, w = w0; \ 00055 /* display text */ \ 00056 gui << gui_only() << at(h, w) << nn.name() << " in:" << in.T; \ 00057 w += 150; \ 00058 zoom *= 3; \ 00059 /* display inputs */ \ 00060 idx_bloop1(m, in.T, T) { \ 00061 if (w - w0 < MAXWIDTH) { \ 00062 draw_matrix(m, h, w, zoom, zoom, vmin, vmax); \ 00063 w += (uint) (m.dim(1) * zoom + 1); \ 00064 } \ 00065 } \ 00066 h0 += (uint) (std::max((uint) 10, (uint) (m.dim(0) * zoom + 1))); \ 00067 } 00068 00069 LINEAR_MODULE_GUI(display_fprop, fprop, x, fstate_idx) 00070 LINEAR_MODULE_GUI(display_bprop, bprop, dx, bstate_idx) 00071 LINEAR_MODULE_GUI(display_bbprop, bbprop, ddx, bbstate_idx) 00072 00074 // convolution_module 00075 00076 #define CONVOLUTION_MODULE_GUI(dname, op, T, state) \ 00077 template <typename T, class Tstate> \ 00078 void convolution_module_gui::dname(convolution_module<T,Tstate> &nn, \ 00079 uint &h0, uint &w0, double zoom, \ 00080 T vmin, T vmax, bool show_out) { \ 00081 uint h = h0, w = w0; \ 00082 vmin = 0; vmax = 0; \ 00083 /* display kernels text */ \ 00084 gui << gui_only() << at(h, w) << "kernels:" << nn.kernel.T \ 00085 << " min " << idx_min(nn.kernel.T) << " max " << idx_max(nn.kernel.T); \ 00086 w += 150; \ 00087 /* display kernels */ \ 00088 /* zoom *= 4; */ \ 00089 idx_bloop1(mk, nn.kernel.T, T) { \ 00090 if (w - w0 < MAXWIDTH) { \ 00091 draw_matrix(mk, h, w, zoom, zoom, vmin, vmax); \ 00092 w += (uint) (mk.dim(1) * zoom + 1); \ 00093 } \ 00094 } \ 00095 h0 += (uint) (std::max((uint) 10, (uint) (mk.dim(0) * zoom + 1))); \ 00096 } 00097 00098 CONVOLUTION_MODULE_GUI(display_fprop, fprop, x, fstate_idx) 00099 CONVOLUTION_MODULE_GUI(display_bprop, bprop, dx, bstate_idx) 00100 CONVOLUTION_MODULE_GUI(display_bbprop, bbprop, ddx, bbstate_idx) 00101 00103 // subsampling_module 00104 00105 #define SUBSAMPLING_MODULE_GUI(dname, op, T, state) \ 00106 template <typename T, class Tstate> \ 00107 void subsampling_module_gui::dname(subsampling_module<T,Tstate> &nn, \ 00108 Tstate &in, Tstate &out, uint &h0, \ 00109 uint &w0, double zoom, T vmin, T vmax, \ 00110 bool show_out) { \ 00111 /* run it */ \ 00112 nn.op(in, out); \ 00113 uint h = h0, w = w0; \ 00114 /* display input text */ \ 00115 gui << gui_only() << at(h, w) << nn.name() << " in:" << in.T; \ 00116 gui << at(h + 15, w) << "in min:" << idx_min(in.T); \ 00117 gui << at(h + 30, w) << "in max:" << idx_max(in.T); \ 00118 w += 150; \ 00119 /* display inputs */ \ 00120 idx_bloop1(m, in.T, T) { \ 00121 if (w - w0 < MAXWIDTH) { \ 00122 draw_matrix(m, h, w, zoom, zoom, vmin, vmax); \ 00123 w += (uint) (m.dim(1) * zoom + 1); \ 00124 } \ 00125 } \ 00126 h0 += (uint) (m.dim(0) * zoom + 1); \ 00127 w = w0; \ 00128 h = h0; \ 00129 /* display kernels text */ \ 00130 gui << gui_only()<< at(h, w) << "kernels:" << nn.sub.T.dim(0); \ 00131 gui << "x" << in.T.dim(1) / nn.sub.T.dim(1); \ 00132 gui << "x" << in.T.dim(2) / nn.sub.T.dim(2); \ 00133 gui << at(h + 15, w) << "coeff min:" << idx_min(nn.coeff.T); \ 00134 gui << at(h + 30, w) << "coeff max:" << idx_max(nn.coeff.T); \ 00135 w += 150; \ 00136 h0 += 45; \ 00137 } 00138 00139 SUBSAMPLING_MODULE_GUI(display_fprop, fprop, x, fstate_idx) 00140 SUBSAMPLING_MODULE_GUI(display_bprop, bprop, dx, bstate_idx) 00141 SUBSAMPLING_MODULE_GUI(display_bbprop, bbprop, ddx, bbstate_idx) 00142 00143 } 00144 00145 #endif /* ELB_BASIC_GUI_HPP_ */