def read(self, path): self.mdef = s3mdef.open(os.path.join(path, "mdef")) self.mean = s3gau.open(os.path.join(path, "means")) self.var = s3gau.open(os.path.join(path, "variances")) self.mixw = s3mixw.open(os.path.join(path, "mixture_weights")) self.tmat = s3tmat.open(os.path.join(path, "transition_matrices")) # Normalize transition matrices and mixture weights for t in range(0, len(self.tmat)): self.tmat[t] = (self.tmat[t].T / self.tmat[t].sum(1)).T for t in range(0, len(self.mixw)): self.mixw[t] = (self.mixw[t].T / self.mixw[t].sum(1)).T.clip(self.mwfloor, 1.0) # Floor variances and precompute normalizing and inverse variance terms self.norm = numpy.empty((len(self.var), len(self.var[0]), len(self.var[0][0])),'d') for m,mgau in enumerate(self.var): for f,feat in enumerate(mgau): fvar = feat.clip(self.varfloor, numpy.inf) # log of 1/sqrt((2*pi)^N * det(var)) det = numpy.log(fvar).sum(1) lrd = -0.5 * (det + numpy.log(2 * numpy.pi) * feat.shape[1]) self.norm[m,f] = lrd # "Invert" variances feat[:] = (1 / (fvar * 2)) # Construct senone to codebook mapping if os.access(os.path.join(path, "senmgau"), os.F_OK): self.senmgau = s3file.S3File(os.path.join(path, "senmgau")).read1d() elif len(self.mean) == 1: self.senmgau = numpy.ones(len(self.mixw)) else: self.senmgau = numpy.arange(0, len(self.mixw)) self.senscr = numpy.ones(len(self.mixw)) * WORSTSCORE
sys.argv[0]) try: opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) except getopt.GetoptError: usage() sys.exit(2) if len(args) < 3: usage() sys.exit(2) ldafn = None for o, a in opts: if o in ('-h', '--help'): usage() sys.exit() outmean = 'means.cmllr' outvar = 'variances.cmllr' inmean = s3gau.open(args[0]) invar = s3gau.open(args[1]) mdef = s3mdef.open(args[2]) accumdirs = args[3:] stats = s3gaucnt.accumdirs_full(accumdirs) Ws = estimate_cmllr(stats, inmean, invar, mdef) write_mllr(open("cmllr_matrix", "w"), Ws) Wp = solve_transform(Ws) param = solve_mllr(Wp, inmean, invar, mdef) om = s3gau.open(outmean, "wb") om.writeall(param[0]) om = s3gau.open(outvar, "wb") om.writeall(param[1])
try: opts, args = getopt.getopt(sys.argv[1:], "h", ["help"]) except getopt.GetoptError: usage() sys.exit(2) if len(args) < 3: usage() sys.exit(2) ldafn = None for o, a in opts: if o in ('-h', '--help'): usage() sys.exit() outmean = 'means.cmllr' outvar = 'variances.cmllr' print 'begin' inmean = s3gau.open(args[0]) invar = s3gau.open(args[1]) mdef = s3mdef.open(args[2]) accumdirs = args[3:] stats = s3gaucnt.accumdirs(accumdirs) Ws = estimate_cmllr(stats, inmean, invar, mdef) Wp = solve_transform(Ws) write_mllr(sys.stdout, Wp) param = solve_mllr(Wp, inmean, invar, mdef) om = s3gau.open(outmean,"wb") om.writeall(param[0]) om = s3gau.open(outvar,"wb") om.writeall(param[1]) print 'end'