-
Notifications
You must be signed in to change notification settings - Fork 1
/
CreateDataSet.html
172 lines (170 loc) · 12.7 KB
/
CreateDataSet.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.4"/>
<title>OpenANN: Creating a data set</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
$(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectlogo"><img alt="Logo" src="openann-logo-small.png"/></td>
<td style="padding-left: 0.5em;">
<div id="projectname">OpenANN
 <span id="projectnumber">1.1.0</span>
</div>
<div id="projectbrief">An open source library for artificial neural networks.</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.4 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li>
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark"> </span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(11)"><span class="SelectionMark"> </span>Pages</a></div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Creating a data set </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>In order to train a neural network, we need a training set consisting of <img class="formulaInl" alt="$ N $" src="form_16.png"/> inputs <img class="formulaInl" alt="$ x_n $" src="form_67.png"/> and outputs <img class="formulaInl" alt="$ y_n $" src="form_68.png"/> of an underlying unknown function <img class="formulaInl" alt="$ f $" src="form_69.png"/> we want to approximate.</p>
<p>There are two ways to pass a data set to the neural network:</p>
<ul>
<li>You can arrange your data in matrices.</li>
<li>You can subclass the abstract class <a class="el" href="classOpenANN_1_1DataSet.html" title="Data set interface. ">OpenANN::DataSet</a> and create an object of it.</li>
</ul>
<h1><a class="anchor" id="MatrixDataSet"></a>
Arranging data in matrices</h1>
<div class="fragment"><div class="line"><span class="keyword">using namespace </span>OpenANN;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> <a class="code" href="dpb_8cpp.html#a3c04138a5bfe5d72780bb7e82a18e627">main</a>()</div>
<div class="line">{</div>
<div class="line"> <span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code" href="namespacexor.html#ae621cb60e5c26909dc63d15b8e2581f2">N</a> = 10; <span class="comment">// data set size</span></div>
<div class="line"> <span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code" href="namespacexor.html#a21eb70b6837c851a5d894fc14d70061d">D</a> = 2; <span class="comment">// input space dimension</span></div>
<div class="line"> <span class="keyword">const</span> <span class="keywordtype">int</span> <a class="code" href="namespacexor.html#ab73b6ca720ab108b41e49bae0711e652">F</a> = 1; <span class="comment">// output space dimension</span></div>
<div class="line"> <span class="comment">// here we generate a random data set</span></div>
<div class="line"> Eigen::MatrixXf <a class="code" href="namespacesine.html#a480b21bfa9a8de67d85f8b3c5c471d3c">X</a> = Eigen::MatrixXf::Random(N, D);</div>
<div class="line"> Eigen::MatrixXf <a class="code" href="namespacesine.html#a5eec15d136977d47b133c067fb2d761a">T</a> = Eigen::MatrixXf::Random(N, F);</div>
<div class="line"> <span class="comment">// We could e. g. get the input vector x_n with X.row(n-1).</span></div>
<div class="line"> <span class="comment">// Now we can train the neural network:</span></div>
<div class="line"> <a class="code" href="classOpenANN_1_1Net.html" title="Feedforward multilayer neural network. ">Net</a> <a class="code" href="agent_8cpp.html#a474ff98ad9b3a9eb55cfd3c3d4ec5e38">net</a>;</div>
<div class="line"> ... <span class="comment">// initialize net</span></div>
<div class="line"> mlp.<a class="code" href="classOpenANN_1_1Learner.html#a24c588e03b847fc0479a681c77127cb4" title="Set training set. ">trainingSet</a>(X, T);</div>
<div class="line"> <a class="code" href="classOpenANN_1_1StoppingCriteria.html" title="Stopping criteria for optimization algorithms. ">StoppingCriteria</a> <a class="code" href="namespacesine.html#a5d8451dc96d4f2326024d9b8c7bad74f">stop</a>;</div>
<div class="line"> ... <span class="comment">// set stopping criteria</span></div>
<div class="line"> <a class="code" href="namespaceOpenANN.html#a5fcdd987e4be42f5de6109e26c9691a5" title="Train a feedforward neural network supervised. ">train</a>(net, <span class="stringliteral">"LMA"</span>, SSE, stop);</div>
<div class="line">}</div>
</div><!-- fragment --><h1><a class="anchor" id="CustomDataSet"></a>
Subclassing OpenANN::DataSet</h1>
<div class="fragment"><div class="line"><span class="keyword">using namespace </span>OpenANN;</div>
<div class="line"></div>
<div class="line"><span class="keyword">class </span>MyDataSet : <span class="keyword">public</span> <a class="code" href="classOpenANN_1_1DataSet.html" title="Data set interface. ">DataSet</a></div>
<div class="line">{</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line"> MyDataSet(...)</div>
<div class="line"> {</div>
<div class="line"> ...</div>
<div class="line"> }</div>
<div class="line"> <span class="keyword">virtual</span> MyDataSet()</div>
<div class="line"> {</div>
<div class="line"> ...</div>
<div class="line"> }</div>
<div class="line"> <span class="keyword">virtual</span> <span class="keywordtype">int</span> samples()</div>
<div class="line"> {</div>
<div class="line"> <span class="comment">// return size of the data set here</span></div>
<div class="line"> }</div>
<div class="line"> <span class="keyword">virtual</span> <span class="keywordtype">int</span> inputs()</div>
<div class="line"> {</div>
<div class="line"> <span class="comment">// return input space dimension</span></div>
<div class="line"> }</div>
<div class="line"> <span class="keyword">virtual</span> <span class="keywordtype">int</span> outputs()</div>
<div class="line"> {</div>
<div class="line"> <span class="comment">// return output space dimension</span></div>
<div class="line"> }</div>
<div class="line"> <span class="keyword">virtual</span> Eigen::VectorXd& getInstance(<span class="keywordtype">int</span> i)</div>
<div class="line"> {</div>
<div class="line"> <span class="comment">// return the i-th instance (x_i)</span></div>
<div class="line"> }</div>
<div class="line"> <span class="keyword">virtual</span> Eigen::VectorXd& getTarget(<span class="keywordtype">int</span> i);</div>
<div class="line"> {</div>
<div class="line"> <span class="comment">// return the desired output for the i-th instance (y_i)</span></div>
<div class="line"> }</div>
<div class="line"> <span class="keyword">virtual</span> <span class="keywordtype">void</span> finishIteration(<a class="code" href="classOpenANN_1_1Learner.html" title="Common base class of all learning algorithms. ">Learner</a>& learner)</div>
<div class="line"> {</div>
<div class="line"> <span class="comment">// Here you can place code that will be executed after every iteration</span></div>
<div class="line"> <span class="comment">// of the optimization algorithm during the training phase. You could</span></div>
<div class="line"> <span class="comment">// e. g. print the confusion matrix, error on a test set, etc.</span></div>
<div class="line"> }</div>
<div class="line">};</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> <a class="code" href="dpb_8cpp.html#a3c04138a5bfe5d72780bb7e82a18e627">main</a>()</div>
<div class="line">{</div>
<div class="line"> MyDataSet dataSet = ...; <span class="comment">// create a data set</span></div>
<div class="line"> <span class="comment">// Now we can train the neural network:</span></div>
<div class="line"> <a class="code" href="classOpenANN_1_1Net.html" title="Feedforward multilayer neural network. ">Net</a> <a class="code" href="agent_8cpp.html#a474ff98ad9b3a9eb55cfd3c3d4ec5e38">net</a>;</div>
<div class="line"> ... <span class="comment">// initialize net</span></div>
<div class="line"> net.<a class="code" href="classOpenANN_1_1Learner.html#a24c588e03b847fc0479a681c77127cb4" title="Set training set. ">trainingSet</a>(dataSet);</div>
<div class="line"> <a class="code" href="classOpenANN_1_1StoppingCriteria.html" title="Stopping criteria for optimization algorithms. ">StoppingCriteria</a> <a class="code" href="namespacesine.html#a5d8451dc96d4f2326024d9b8c7bad74f">stop</a>;</div>
<div class="line"> ... <span class="comment">// set stopping criteria</span></div>
<div class="line"> <a class="code" href="namespaceOpenANN.html#a5fcdd987e4be42f5de6109e26c9691a5" title="Train a feedforward neural network supervised. ">train</a>(net, <span class="stringliteral">"LMA"</span>, SSE, stop);</div>
<div class="line">}</div>
</div><!-- fragment --> </div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Jul 9 2014 08:57:52 for OpenANN by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.4
</small></address>
</body>
</html>