-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvalidate.cpp
More file actions
43 lines (40 loc) · 1 KB
/
Copy pathvalidate.cpp
File metadata and controls
43 lines (40 loc) · 1 KB
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
#include <string>
#include "utils.h"
#include <valarray>
#include <iostream>
#include <fstream>
#include <vector>
#include "mlp.h"
#ifndef MYDEFS_H
#define MYDEFS_H
#include "mydefs.h"
#endif
#include "matops.h"
#include "fortran.h"
// Perform validation of an MLP using MSE criterion. This should probably be moved into the MLP class.
// Maybe next version after moving matops to BOOST.
double validate(MLP* X,string val_fname)
{
double E=0;
int N=X->N,Nh=X->Nh,M=X->M,i,num_patterns=0;
valarray<double> x(N+1),O(Nh),net(Nh),y(M),e(M),t(M);
ifstream tstfile(val_fname.c_str());
while (!tstfile.eof())
{
for (i=0;i<N;i++)
tstfile >> x[i];
x[N]=1.;
if (!tstfile.eof())
for (i = 0; i < M; i++)
tstfile >> t[i];
else
break;
num_patterns++;
y=X->process_pattern(x,net,O);
e=t-y;
E += (e*e).sum();
}
tstfile.close();
cout << "Validation patterns processed: " << num_patterns << endl;
return(E/num_patterns);
}