Edinburgh Speech Tools
2.4-release
Loading...
Searching...
No Matches
ols_test_main.cc
1
/*************************************************************************/
2
/* */
3
/* Centre for Speech Technology Research */
4
/* University of Edinburgh, UK */
5
/* Copyright (c) 1998 */
6
/* All Rights Reserved. */
7
/* */
8
/* Permission is hereby granted, free of charge, to use and distribute */
9
/* this software and its documentation without restriction, including */
10
/* without limitation the rights to use, copy, modify, merge, publish, */
11
/* distribute, sublicense, and/or sell copies of this work, and to */
12
/* permit persons to whom this work is furnished to do so, subject to */
13
/* the following conditions: */
14
/* 1. The code must retain the above copyright notice, this list of */
15
/* conditions and the following disclaimer. */
16
/* 2. Any modifications must be clearly marked as such. */
17
/* 3. Original authors' names are not deleted. */
18
/* 4. The authors' names are not used to endorse or promote products */
19
/* derived from this software without specific prior written */
20
/* permission. */
21
/* */
22
/* THE UNIVERSITY OF EDINBURGH AND THE CONTRIBUTORS TO THIS WORK */
23
/* DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING */
24
/* ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT */
25
/* SHALL THE UNIVERSITY OF EDINBURGH NOR THE CONTRIBUTORS BE LIABLE */
26
/* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES */
27
/* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN */
28
/* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, */
29
/* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF */
30
/* THIS SOFTWARE. */
31
/* */
32
/*************************************************************************/
33
/* Author : Alan W Black */
34
/* Date : January 1998 */
35
/*-----------------------------------------------------------------------*/
36
/* A program for testing a OLS */
37
/* */
38
/*=======================================================================*/
39
#include <cstdlib>
40
#include <iostream>
41
#include <fstream>
42
#include <cstring>
43
#include "EST_Wagon.h"
44
#include "EST_cutils.h"
45
#include "EST_multistats.h"
46
#include "EST_Token.h"
47
#include "EST_cmd_line.h"
48
49
static
int
ols_test_main(
int
argc
,
char
**
argv
);
50
static
void
load_ols_data(
EST_FMatrix
&X,
EST_FMatrix
&
Y
,
WDataSet
&d);
51
52
/** @name <command>ols_test</command> <emphasis>Test linear regression model</emphasis>
53
@id ols-test-manual
54
* @toc
55
*/
56
57
//@{
58
59
60
/**@name Synopsis
61
*/
62
//@{
63
64
//@synopsis
65
66
/**
67
*/
68
69
//@}
70
71
/**@name OPTIONS
72
*/
73
//@{
74
75
//@options
76
77
//@}
78
79
80
int
main(
int
argc
,
char
**
argv
)
81
{
82
83
ols_test_main(
argc
,
argv
);
84
85
exit
(0);
86
return
0;
87
}
88
89
static
int
ols_test_main(
int
argc
,
char
**
argv
)
90
{
91
// Top level function sets up data and creates a tree
92
EST_Option
al
;
93
EST_StrList
files
;
94
EST_FMatrix
X,
Y
,
coeffs
;
95
WDataSet
dataset
;
96
EST_String
outfile;
97
98
parse_command_line
99
(
argc
,
argv
,
100
EST_String
(
"[options]\n"
)+
101
"ols_test <options>\n"
+
102
"program to test OLS on data\n"
+
103
"-desc <ifile> Field description file\n"
+
104
"-data <ifile> Datafile, one vector per line\n"
+
105
"-coeffs <ifile> File containing OLS coefficients\n"
+
106
"-predict Predict for each vector returning value\n"
+
107
"-o <ofile> File to save output in\n"
,
108
files
,
al
);
109
110
siod_init();
111
112
if
(
al
.present(
"-desc"
))
113
{
114
dataset
.load_description(
al
.val(
"-desc"
),NIL);
115
}
116
else
117
{
118
cerr
<<
argv
[0] <<
": no description file specified"
<<
endl
;
119
exit
(-1);
120
}
121
122
if
(
coeffs
.load(
al
.val(
"-coeffs"
)) != format_ok)
123
{
124
cerr
<<
argv
[0] <<
": no coefficients file specified"
<<
endl
;
125
exit
(-1);
126
}
127
128
if
(
al
.present(
"-data"
))
129
wgn_load_dataset(
dataset
,
al
.val(
"-data"
));
130
else
131
{
132
cerr
<<
argv
[0] <<
": no data file specified"
<<
endl
;
133
exit
(-1);
134
}
135
136
if
(
al
.present(
"-o"
))
137
outfile =
al
.val(
"-o"
);
138
else
139
outfile =
"-"
;
140
141
EST_FMatrix
pred
;
142
float
cor
,
rmse
;
143
144
load_ols_data(X,
Y
,
dataset
);
145
ols_apply(X,
coeffs
,
pred
);
146
if
(ols_test(
Y
,
pred
,
cor
,
rmse
))
147
printf
(
";; RMSE %f Correlation is %f\n"
,
rmse
,
cor
);
148
else
149
printf
(
";; varation too small RMSE %f but no correlation\n"
,
rmse
);
150
if
(
al
.present(
"-o"
) ||
al
.present(
"-predict"
))
151
pred
.save(outfile);
152
153
return
0;
154
}
155
156
static
void
load_ols_data(
EST_FMatrix
&X,
EST_FMatrix
&
Y
,
WDataSet
&d)
157
{
158
EST_Litem
*p;
159
int
n,
m
;
160
161
X.resize(d.length(),d.width());
162
Y
.resize(d.length(),1);
163
164
for
(n=0,p=d.head(); p != 0; p=p->next(),n++)
165
{
166
Y
(n,0) = d(p)->get_flt_val(0);
167
X(n,0) = 1;
168
for
(
m
=1;
m
< d.width();
m
++)
169
X(n,
m
) = d(p)->get_flt_val(
m
);
170
}
171
172
}
EST_FMatrix
Definition
EST_FMatrix.h:56
EST_Hash_Pair
Definition
EST_THash.h:75
EST_Option
Definition
EST_Option.h:50
EST_String
Definition
EST_String.h:70
EST_TList
Definition
EST_TList.h:109
EST_UItem
Definition
EST_UList.h:51
WDataSet
Definition
EST_Wagon.h:86
main
ols_test_main.cc
Generated on Fri Sep 20 2024 04:19:10 for Edinburgh Speech Tools by
1.9.8