Paradiseo-eo sources added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
bc1f453978
commit
c3aec878e5
3609 changed files with 342772 additions and 0 deletions
155
trunk/paradiseo-eo/doc/html/l2_8h-source.html
Normal file
155
trunk/paradiseo-eo/doc/html/l2_8h-source.html
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
|
||||
<title>EO: l2.h Source File</title>
|
||||
<link href="doxygen.css" rel="stylesheet" type="text/css">
|
||||
</head><body>
|
||||
<!-- Generated by Doxygen 1.3.9.1 -->
|
||||
<div class="qindex"> <form class="search" action="search.php" method="get">
|
||||
<a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="pages.html">Related Pages</a> | <span class="search"><u>S</u>earch for <input class="search" type="text" name="query" value="" size="20" accesskey="s"/></span></form></div>
|
||||
<div class="nav">
|
||||
<a class="el" href="dir_000020.html">app</a> / <a class="el" href="dir_000023.html">gprop</a></div>
|
||||
<h1>l2.h</h1><div class="fragment"><pre class="fragment">00001 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00002 <span class="comment">// l2.h</span>
|
||||
00003 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00004
|
||||
00005 <span class="preprocessor">#ifndef l2_h</span>
|
||||
00006 <span class="preprocessor"></span><span class="preprocessor">#define l2_h</span>
|
||||
00007 <span class="preprocessor"></span>
|
||||
00008 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00009
|
||||
00010 <span class="preprocessor">#include <math.h></span> <span class="comment">// log</span>
|
||||
00011 <span class="preprocessor">#include <qp.h></span> <span class="comment">// neuron layer net set</span>
|
||||
00012
|
||||
00013 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00014
|
||||
00015 <span class="keyword">namespace </span>l2
|
||||
00016 {
|
||||
00017 <span class="comment">//---------------------------------------------------------------------------</span>
|
||||
00018 <span class="comment">// useful typedefs</span>
|
||||
00019 <span class="comment">//---------------------------------------------------------------------------</span>
|
||||
00020
|
||||
00021 <span class="keyword">using</span> qp::real;
|
||||
00022 <span class="keyword">using</span> qp::vector;
|
||||
00023 <span class="keyword">using</span> qp::max_real;
|
||||
00024 <span class="keyword">using</span> qp::min_real;
|
||||
00025 <span class="keyword">using</span> qp::set;
|
||||
00026 <span class="keyword">using</span> qp::neuron;
|
||||
00027 <span class="keyword">using</span> qp::layer;
|
||||
00028
|
||||
00029 <span class="comment">//---------------------------------------------------------------------------</span>
|
||||
00030 <span class="comment">// error</span>
|
||||
00031 <span class="comment">//---------------------------------------------------------------------------</span>
|
||||
00032
|
||||
00033 real error(<span class="keyword">const</span> mlp::net& net, <span class="keyword">const</span> set& ts)
|
||||
00034 {
|
||||
00035 real error_ = 0.0;
|
||||
00036
|
||||
00037 <span class="keywordflow">for</span> (set::const_iterator s = ts.begin(); s != ts.end(); ++s)
|
||||
00038 {
|
||||
00039 vector out = net(s->input);
|
||||
00040
|
||||
00041 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i < out.size(); ++i)
|
||||
00042 {
|
||||
00043 real target = s->output[i];
|
||||
00044 real value = out[i];
|
||||
00045 error_ -= target * log(value + min_real) +
|
||||
00046 (1.0 - target) * log(1.0 - value + min_real);
|
||||
00047 }
|
||||
00048 }
|
||||
00049
|
||||
00050 <span class="keywordflow">return</span> error_;
|
||||
00051 }
|
||||
00052
|
||||
00053 <span class="comment">//-------------------------------------------------------------------------</span>
|
||||
00054 <span class="comment">// l2</span>
|
||||
00055 <span class="comment">//-------------------------------------------------------------------------</span>
|
||||
00056
|
||||
00057 <span class="keyword">class </span>net: <span class="keyword">public</span> qp::net
|
||||
00058 {
|
||||
00059 <span class="keyword">public</span>:
|
||||
00060 net(mlp::net& n): qp::net(n) {}
|
||||
00061
|
||||
00062 real error(<span class="keyword">const</span> set& ts)
|
||||
00063 {
|
||||
00064 real error_ = 0;
|
||||
00065
|
||||
00066 <span class="keywordflow">for</span> (set::const_iterator s = ts.begin(); s != ts.end(); ++s)
|
||||
00067 {
|
||||
00068 forward(s->input);
|
||||
00069 error_ -= backward(s->input, s->output);
|
||||
00070 }
|
||||
00071
|
||||
00072 <span class="keywordflow">return</span> error_;
|
||||
00073 }
|
||||
00074
|
||||
00075 <span class="keyword">private</span>:
|
||||
00076 real backward(<span class="keyword">const</span> vector& input, <span class="keyword">const</span> vector& output)
|
||||
00077 {
|
||||
00078 reverse_iterator current_layer = rbegin();
|
||||
00079 reverse_iterator backward_layer = current_layer + 1;
|
||||
00080 real error_ = 0;
|
||||
00081
|
||||
00082 <span class="comment">// output layer</span>
|
||||
00083 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> j = 0; j < current_layer->size(); ++j)
|
||||
00084 {
|
||||
00085 neuron& n = (*current_layer)[j];
|
||||
00086 real out = output[j];
|
||||
00087 n.ndelta += n.delta = (out - n.out) /
|
||||
00088 (n.out * (1.0 - n.out) + min_real) * n.out * (1.0 - n.out);
|
||||
00089
|
||||
00090 <span class="keywordflow">if</span> (size() == 1) <span class="comment">// monolayer</span>
|
||||
00091 n.dxo += n.delta * input;
|
||||
00092 <span class="keywordflow">else</span> <span class="comment">// multilayer</span>
|
||||
00093 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> k = 0; k < n.dxo.size(); ++k)
|
||||
00094 n.dxo[k] += n.delta * (*backward_layer)[k].out;
|
||||
00095
|
||||
00096 error_ += out * log(n.out + min_real) +
|
||||
00097 (1.0 - out) * log(1.0 - n.out + min_real);
|
||||
00098 }
|
||||
00099
|
||||
00100 <span class="comment">// hidden layers</span>
|
||||
00101 <span class="keywordflow">while</span> (++current_layer != rend())
|
||||
00102 {
|
||||
00103 reverse_iterator forward_layer = current_layer - 1;
|
||||
00104 reverse_iterator backward_layer = current_layer + 1;
|
||||
00105
|
||||
00106 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> j = 0; j < current_layer->size(); ++j)
|
||||
00107 {
|
||||
00108 neuron& n = (*current_layer)[j];
|
||||
00109 real sum = 0;
|
||||
00110 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> k = 0; k < forward_layer->size(); ++k)
|
||||
00111 {
|
||||
00112 neuron& nf = (*forward_layer)[k];
|
||||
00113 sum += nf.delta * (nf.n->weight[j] + nf.dweight1[j]);
|
||||
00114 }
|
||||
00115 n.delta = n.out * (1.0 - n.out) * sum;
|
||||
00116 n.ndelta += n.delta;
|
||||
00117
|
||||
00118 <span class="keywordflow">if</span> (backward_layer == rend()) <span class="comment">// first hidden layer</span>
|
||||
00119 n.dxo += n.delta * input;
|
||||
00120 <span class="keywordflow">else</span> <span class="comment">// rest of hidden layers</span>
|
||||
00121 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> k = 0; k < n.dxo.size(); ++k)
|
||||
00122 n.dxo[k] += n.delta * (*backward_layer)[k].out;
|
||||
00123 }
|
||||
00124 }
|
||||
00125
|
||||
00126 <span class="keywordflow">return</span> error_;
|
||||
00127 }
|
||||
00128 };
|
||||
00129
|
||||
00130 <span class="comment">//---------------------------------------------------------------------------</span>
|
||||
00131
|
||||
00132 } <span class="comment">// namespace l2</span>
|
||||
00133
|
||||
00134 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00135
|
||||
00136 <span class="preprocessor">#endif // l2_h</span>
|
||||
00137 <span class="preprocessor"></span>
|
||||
00138 <span class="comment">// Local Variables: </span>
|
||||
00139 <span class="comment">// mode:C++ </span>
|
||||
00140 <span class="comment">// End:</span>
|
||||
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Oct 19 05:06:40 2006 for EO by
|
||||
<a href="http://www.doxygen.org/index.html">
|
||||
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.3.9.1 </small></address>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue