x161.html

来自「一个功能强大的神经网络分析程序」· HTML 代码 · 共 238 行

HTML
238
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><HTML><HEAD><TITLE>Training and Testing</TITLE><link href="../style.css" rel="stylesheet" type="text/css"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINKREL="HOME"TITLE="Fast Artificial Neural Network Library"HREF="index.html"><LINKREL="UP"TITLE="Advanced Usage"HREF="c104.html"><LINKREL="PREVIOUS"TITLE="Understanding the Error Value"HREF="x148.html"><LINKREL="NEXT"TITLE="Avoid Over-Fitting"HREF="x181.html"></HEAD><BODYCLASS="section"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">Fast Artificial Neural Network Library</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="x148.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom">Chapter 2. Advanced Usage</TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="x181.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><DIVCLASS="section"><H1CLASS="section"><ANAME="adv.train_test">2.4. Training and Testing</A></H1><P>&#13;        Normally it will be sufficient to use the <AHREF="r806.html"><CODECLASS="function">fann_train_on_file</CODE></A> training function, but	sometimes you want to have more control and you will have to write a custom training loop. This could be because you would like another stop criteria,	or because you would like to adjust some of the parameters during training. Another stop criteria than the value of the combined mean square error could	be that each of the training pairs should have a mean square error lower than a given value.      </P><DIVCLASS="example"><ANAME="example.train_on_file_internals"></A><P><B>Example 2-1. 	  The internals of the <CODECLASS="function">fann_train_on_file</CODE> function, without writing the status line.	</B></P><PRECLASS="programlisting">&#13;struct fann_train_data *data = fann_read_train_from_file(filename);for(i = 1 ; i &#60;= max_epochs ; i++) {  fann_reset_MSE(ann);  for (j = 0 ; j != data-&#62;num_data ; j++) {    fann_train(ann, data-&#62;input[j], data-&#62;output[j]);  }  if ( fann_get_MSE(ann) &#60; desired_error ) {    break;  }}fann_destroy_train(data);        </PRE></DIV><P>&#13;	This piece of code introduces the <AHREF="r536.html"><CODECLASS="function">fann_train</CODE></A> function, which trains the ANN for one iteration	with one pair of inputs and outputs and also updates the mean square error. The	<AHREF="r1837.html"><SPANCLASS="type">fann_train_data</SPAN></A> structure is also introduced, this structure is a container for the	training data in the file described in figure 10. The structure can be used to train the ANN, but it can also be used to test the ANN with data which it	has not been trained with.      </P><DIVCLASS="example"><ANAME="example.calc_mse"></A><P><B>Example 2-2. Test all of the data in a file and calculates the mean square error.</B></P><PRECLASS="programlisting">&#13;struct fann_train_data *data = fann_read_train_from_file(filename);fann_reset_MSE(ann);for(i = 0 ; i != data-&#62;num_data ; i++ ) {  fann_test(ann, data-&#62;input[i], data-&#62;output[i]);}printf("Mean Square Error: %f\n", fann_get_MSE(ann));fann_destroy_train(data);	</PRE></DIV><P>&#13;	This piece of code introduces another useful function: <AHREF="r557.html"><CODECLASS="function">fann_test</CODE></A> function, which takes an input	array and a desired output array as the parameters and returns the calculated output. It also updates the mean square error.      </P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="x148.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="index.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="x181.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Understanding the Error Value</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="c104.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Avoid Over-Fitting</TD></TR></TABLE></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?