00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00043 #include "cvrbfplane.h"
00044 #include "cvfastsigmoid.h"
00045 #include <iostream>
00046 #include <sstream>
00047
00048 using namespace std;
00049
00050
00051
00061 CvRBFPlane::CvRBFPlane (std::string id, CvSize fmapsz, CvSize neurosz)
00062 : CvGenericPlane(id, fmapsz, neurosz)
00063 {
00064
00065 m_weight.resize( neurosz.height*neurosz.width );
00066
00067 }
00068
00069 CvRBFPlane::~CvRBFPlane ( )
00070 {
00071 }
00072
00073
00074
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
00118 double val = DQstdsigmoid(sum);
00119
00120
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
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
00164 if (weights.size() != m_neurosz.width*m_neurosz.height*m_pplane.size())
00165 return 0;
00166
00167 return CvGenericPlane::setweight(weights);
00168 }