cvrbfplane.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. By
00003 downloading, copying, installing or using the software you agree to this
00004 license. If you do not agree to this license, do not download, install, copy or
00005 use the software.
00006 
00007 Contributors License Agreement
00008 
00009 Copyright© 2007, Akhmed Umyarov. All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without modification,
00012 are permitted provided that the following conditions are met:
00013 - Redistributions of source code must retain the above copyright notice, this
00014 list of conditions and the following disclaimer.
00015 - Redistributions in binary form must reproduce the above copyright notice, this
00016 list of conditions and the following disclaimer in the documentation and/or
00017 other materials provided with the distribution.
00018 - The name of Contributor may not be used to endorse or promote products derived
00019 from this software without specific prior written permission.
00020 
00021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00022 ANY EXPRESS OR IMPLIED 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 CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
00025 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00027 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00029 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00030 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 All information provided related to future Intel products and plans is
00032 preliminary and subject to change at any time, without notice.
00033 *****************************************************************************/
00043 #include "cvrbfplane.h"
00044 #include "cvfastsigmoid.h"
00045 #include <iostream>
00046 #include <sstream>
00047 
00048 using namespace std;
00049 
00050 // Constructors/Destructors
00051 //  
00061 CvRBFPlane::CvRBFPlane  (std::string id, CvSize fmapsz, CvSize neurosz)
00062         : CvGenericPlane(id, fmapsz, neurosz) 
00063 {
00064         // Init weights for the neuron of RBF plane
00065         m_weight.resize( neurosz.height*neurosz.width );
00066 
00067 }
00068 
00069 CvRBFPlane::~CvRBFPlane ( ) 
00070 { 
00071 }
00072 
00073 //  
00074 // Methods
00075 //  
00076 
00082 CvMat * CvRBFPlane::fprop ()
00083 {
00084         assert( m_connected );
00085 
00086         if (!m_connected)
00087         {
00088 #ifdef DEBUG
00089                 cout << "CvRBFPlane::fprop(): Not connected!" << endl;
00090 #endif
00091                 return NULL;
00092         }
00093 
00094         for (int y=0; y<m_fmapsz.height; y++)
00095         {
00096                 for (int x=0; x<m_fmapsz.width; x++)
00097                 {
00098         
00099                         double sum = 0.0; 
00100                         int w = 0;
00101                         for (int i = 0; i < m_pplane.size(); i++)
00102                         {
00103                                 CvMat *fmap = m_pfmap[i];
00104                                 assert( cvGetSize(fmap).height >= y+m_neurosz.height
00105                                         && cvGetSize(fmap).width >= x+m_neurosz.width );
00106                                 
00107                                 for (int j=0; j<m_neurosz.height; j++)
00108                                 {
00109                                         for (int k=0; k<m_neurosz.width; k++)
00110                                         {
00111                                                 double dist = (m_weight[w++]-cvmGet(fmap, y+j, x+k));
00112                                                 sum += dist*dist;
00113                                         }
00114                                 }
00115                         }
00116 
00117                         // Sigmoid
00118                         double val = DQstdsigmoid(sum);
00119 
00120                         // Update the value at feature map
00121                         cvmSet(m_fmap,y,x,val);
00122                 }
00123         }
00124 
00125         return m_fmap;
00126 }
00127 
00128 
00137 string CvRBFPlane::toString ( ) 
00138 {
00139         ostringstream xml;
00140         xml << "\t<plane id=\"" << m_id << "\" type=\"rbf\" featuremapsize=\"" << m_fmapsz.width << "x" << m_fmapsz.height << "\" neuronsize=\"" << m_neurosz.width << "x" << m_neurosz.height << "\">" << endl;
00141 
00142         int windowsz = m_neurosz.height*m_neurosz.width;
00143         
00144         // Print weights
00145         for (int i=0; i <m_pplane.size(); i++)
00146         {
00147                 xml << "\t\t<connection to=\"" << m_pplane[i]->getid() << "\"> ";
00148                 for (int j=0;j<windowsz; j++)
00149                 {
00150                                 xml << m_weight[j+i*windowsz] << " ";
00151                 }
00152                 xml << "</connection>" << endl;
00153         }
00154         xml << "\t</plane>" << endl;
00155         
00156         return xml.str();
00157 }
00158 
00161 int CvRBFPlane::setweight(std::vector<double> &weights)
00162 {       
00163         // Check that the number of weights passed is sane
00164         if (weights.size() != m_neurosz.width*m_neurosz.height*m_pplane.size())
00165                 return 0;
00166 
00167         return CvGenericPlane::setweight(weights);
00168 }

Generated on Fri Aug 3 16:17:27 2007 for ConvNet by  doxygen 1.5.0