~ubuntu-branches/ubuntu/utopic/sphinxtrain/utopic

« back to all changes in this revision

Viewing changes to scripts/05.vector_quantize/kmeans.pl

  • Committer: Package Import Robot
  • Author(s): Samuel Thibault
  • Date: 2013-01-02 04:10:21 UTC
  • Revision ID: package-import@ubuntu.com-20130102041021-ynsizmz33fx02hea
Tags: upstream-1.0.8
ImportĀ upstreamĀ versionĀ 1.0.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
## ====================================================================
 
3
##
 
4
## Copyright (c) 1996-2000 Carnegie Mellon University.  All rights 
 
5
## reserved.
 
6
##
 
7
## Redistribution and use in source and binary forms, with or without
 
8
## modification, are permitted provided that the following conditions
 
9
## are met:
 
10
##
 
11
## 1. Redistributions of source code must retain the above copyright
 
12
##    notice, this list of conditions and the following disclaimer. 
 
13
##
 
14
## 2. Redistributions in binary form must reproduce the above copyright
 
15
##    notice, this list of conditions and the following disclaimer in
 
16
##    the documentation and/or other materials provided with the
 
17
##    distribution.
 
18
##
 
19
## 3. The names "Sphinx" and "Carnegie Mellon" must not be used to
 
20
##    endorse or promote products derived from this software without
 
21
##    prior written permission. To obtain permission, contact 
 
22
##    sphinx@cs.cmu.edu.
 
23
##
 
24
## 4. Redistributions of any form whatsoever must retain the following
 
25
##    acknowledgment:
 
26
##    "This product includes software developed by Carnegie
 
27
##    Mellon University (http://www.speech.cs.cmu.edu/)."
 
28
##
 
29
## THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND 
 
30
## ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
 
31
## THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 
32
## PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
 
33
## NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
34
## SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
 
35
## LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 
36
## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 
37
## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
 
38
## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 
39
## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
40
##
 
41
## ====================================================================
 
42
##
 
43
## Author: Ricky Houghton 
 
44
##
 
45
 
 
46
use strict;
 
47
use File::Basename;
 
48
use File::Spec::Functions;
 
49
use lib catdir(dirname($0), updir(), 'lib');
 
50
use SphinxTrain::Config;
 
51
use SphinxTrain::Util;
 
52
 
 
53
#***************************************************************************
 
54
# Script to find the VQ codebooks for the training set.
 
55
# The codewords in the codebook will be used later as the means of
 
56
# clusters for the Discrete HMMs.
 
57
#***************************************************************************
 
58
 
 
59
#TODO - Finish usage
 
60
#print "Usage: $0\n";
 
61
 
 
62
my ($hmmdir,$outhmm,$segdmpdir,$dumpfile,$logfile);
 
63
 
 
64
$| = 1; # Turn on autoflushing
 
65
 
 
66
my $mllt_file = catfile($ST::CFG_MODEL_DIR, "${ST::CFG_EXPTNAME}.mllt");
 
67
my $model_type = 'ci';
 
68
 
 
69
# Definitions
 
70
$hmmdir = "$ST::CFG_BASE_DIR/model_parameters";
 
71
mkdir ($hmmdir,0777);
 
72
 
 
73
$outhmm  = "$hmmdir/${ST::CFG_EXPTNAME}.${model_type}_${ST::CFG_DIRLABEL}_flatinitial";
 
74
mkdir ($outhmm,0777);
 
75
 
 
76
$segdmpdir = "$ST::CFG_BWACCUM_DIR/${ST::CFG_EXPTNAME}_buff_1";
 
77
mkdir ($segdmpdir,0777);
 
78
 
 
79
$dumpfile = "$segdmpdir/${ST::CFG_EXPTNAME}.dmp";
 
80
 
 
81
my $logdir = "$ST::CFG_LOG_DIR/05.vector_quantize";
 
82
mkdir ($logdir,0777);
 
83
$logfile = "$logdir/${ST::CFG_EXPTNAME}.kmeans.log";
 
84
 
 
85
$| = 1;
 
86
 
 
87
my @feat_args;
 
88
if (defined($ST::CFG_SVSPEC)){
 
89
    @feat_args = (-svspec =>$ST::CFG_SVSPEC);
 
90
}
 
91
if (-r $mllt_file) {
 
92
    push(@feat_args,
 
93
         -lda => $mllt_file,
 
94
         -ldadim => $ST::CFG_LDA_DIMENSION);
 
95
}
 
96
 
 
97
exit RunTool('kmeans_init', $logfile, 0,
 
98
             -gthobj => 'single',
 
99
             -stride => 1,
 
100
             -ntrial => 1,
 
101
             -minratio => 0.001,
 
102
             -ndensity => $ST::CFG_INITIAL_NUM_DENSITIES,
 
103
             -meanfn => "$outhmm/means",
 
104
             -varfn => "$outhmm/variances",
 
105
             -fullvar => $ST::CFG_FULLVAR,
 
106
             -reest => 'no',
 
107
             -segdmpdirs => $segdmpdir,
 
108
             -segdmpfn => $dumpfile,
 
109
             -ceplen => $ST::CFG_VECTOR_LENGTH,
 
110
             -feat => $ST::CFG_FEATURE,
 
111
             @feat_args,
 
112
             -agc => $ST::CFG_AGC,
 
113
             -cmn => $ST::CFG_CMN,
 
114
             -varnorm => $ST::CFG_VARNORM);