1
/* ====================================================================
2
* Copyright (c) 1995-2000 Carnegie Mellon University. All rights
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
12
* 2. Redistributions in binary form must reproduce the above copyright
13
* notice, this list of conditions and the following disclaimer in
14
* the documentation and/or other materials provided with the
17
* This work was supported in part by funding from the Defense Advanced
18
* Research Projects Agency and the National Science Foundation of the
19
* United States of America, and the CMU Sphinx Speech Consortium.
21
* THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
22
* ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
25
* NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
* ====================================================================
36
/*********************************************************************
41
* Read an ASCII model topology file. This file contains
42
* an adjacency matrix with non-zero elements for all
43
* allowable transitions where a row represents a source state
44
* and a column represents a sink state.
46
* If the adjacency matrix contains values that are all equal,
47
* the matrix can be normalized to obtain a uniform transition
51
* Eric H. Thayer (eht@cs.cmu.edu)
52
*********************************************************************/
54
/* try to put header files in local to global order to
55
try to flush out hidden dependencies */
56
#include <s3/topo_read.h>
58
#include <sphinxbase/pio.h>
59
#include <s3/common.h>
66
#define TOPO_FILE_VERSION "0.1"
68
/*********************************************************************
74
* This routine reads an ASCII transition matrix which may then be
75
* used to determine the topology of the models used in the system.
85
* S3_SUCCESS is returned upon successful completion
86
* S3_ERROR is returned upon an error condition
101
*********************************************************************/
103
topo_read(float32 ***tmat,
105
const char *topo_file_name)
109
lineiter_t *li = NULL;
114
assert(topo_file_name != NULL);
116
fp = fopen(topo_file_name, "r");
118
E_WARN_SYSTEM("Unable to open %s for reading\n", topo_file_name);
123
li = lineiter_start_clean(fp);
126
E_ERROR("EOF encounted while reading version number in %s!?\n", topo_file_name);
131
if (strcmp(li->buf, TOPO_FILE_VERSION) != 0) {
132
E_ERROR("Topo file version in %s is %s. Expected %s\n",
133
topo_file_name, li->buf, TOPO_FILE_VERSION);
138
li = lineiter_next(li);
140
E_ERROR("EOF encountered while reading n_state in %s!?\n", topo_file_name);
145
sscanf(li->buf, "%d\n", &n_state);
147
/* Support Request 1504066: robust reading of topo file in
164
topo_read will misread 1.0 into n_state as 1. And the
165
generated transition matrix will corrupt bw as well. This
166
problem is now fixed.
170
E_ERROR("n_state =1, if you are using a transition matrix with more than 1 state, this error might show that there is format issue in your input topology file. You are recommended to use perl/make_topology.pl to generate the topo file instead.\n");
174
out = (float **)ckd_calloc_2d(n_state-1, n_state, sizeof(float32));
176
for (i = 0; i < n_state-1; i++) {
178
for (j = 0; j < n_state; j++) {
179
fscanf(fp, "%f", &out[i][j]);
180
row_sum += out[i][j];
182
for (j = 0; j < n_state; j++) {
183
out[i][j] /= row_sum;
188
*n_state_pm = n_state;
202
* Log record. Maintained by RCS.
205
* Revision 1.4 2004/07/21 18:05:40 egouvea
206
* Changed the license terms to make it the same as sphinx2 and sphinx3.
208
* Revision 1.3 2001/04/05 20:02:31 awb
209
* *** empty log message ***
211
* Revision 1.2 2000/09/29 22:35:13 awb
212
* *** empty log message ***
214
* Revision 1.1 2000/09/24 21:38:31 awb
215
* *** empty log message ***
217
* Revision 1.1 97/03/17 15:01:49 eht