Exemplo n.º 1
0
def generate_signal():

    rng = np.random.RandomState(seed = 1024)
    s = (2**3)*rng.randn(fs*10).astype(float_cpu(), copy=False)
    vad = np.zeros((len(s),), dtype=bool)
    vad[2*fs:8*fs] = True
    s += (2**12)*vad.astype(dtype=float_cpu())*np.sign(s)
    vad = vad[::160]
    #s = rng.randn(fs*10).astype(float_cpu(), copy=False)
    return s, vad
Exemplo n.º 2
0
def generate_features():

    rng = np.random.RandomState(seed=1024)
    x = rng.randn(10, 2).astype(float_cpu(), copy=False)
    vad = np.zeros((10, ), dtype='bool')
    vad[4:8] = 1
    return x, vad
Exemplo n.º 3
0
def generate_features():

    rng = np.random.RandomState(seed=1024)
    x = rng.randn(60 * 100, 2).astype(float_cpu(), copy=False)
    x *= rng.rand(60 * 100, 1)

    return x
Exemplo n.º 4
0
def to_sparse(r, num_comp):
    index = np.argsort(r, axis=1)[:, -num_comp:]
    r_sparse = np.zeros((r.shape[0], num_comp), dtype=float_cpu())
    for i, index_i in enumerate(index):
        r_sparse[i] = r[i, index_i]
    r_sparse = r_sparse / np.sum(r_sparse, axis=-1, keepdims=True)
    return r_sparse, index
def combine_diar_scores(ndx, orig_seg, subseg_scores):

    scores = np.zeros(ndx.trial_mask.shape, dtype=float_cpu())
    for j in xrange(len(ndx.seg_set)):
        idx = orig_seg == ndx.seg_set[j]
        subseg_scores_j = subseg_scores[:, idx]
        scores_j = np.max(subseg_scores_j, axis=1)
        scores[:,j] = scores_j

    return scores
Exemplo n.º 6
0
def gen_signals(num_signals=3):
    rng = np.random.RandomState(seed=1)
    s = []
    keys = []
    for i in xrange(num_signals):
        s_i = rng.randn(fs)
        s_i = ((2**15 - 1) / np.max(np.abs(s_i)) * s_i).astype('int32').astype(
            float_cpu())
        s.append(s_i)
        keys.append('s%d' % i)

    return keys, s
Exemplo n.º 7
0
def eval_elbo(seq_file, file_list, model_file, preproc_file, output_file,
              ubm_type, **kwargs):

    sr_args = SR.filter_eval_args(**kwargs)

    if preproc_file is not None:
        preproc = TransformList.load(preproc_file)
    else:
        preproc = None

    sr = SR(seq_file,
            file_list,
            batch_size=1,
            shuffle_seqs=False,
            preproc=preproc,
            **sr_args)

    t1 = time.time()

    if ubm_type == 'diag-gmm':
        model = DiagGMM.load(model_file)
    else:
        model = DiagGMM.load_from_kaldi(model_file)
    model.initialize()

    elbo = np.zeros((sr.num_seqs, ), dtype=float_cpu())
    num_frames = np.zeros((sr.num_seqs, ), dtype=int)
    keys = []
    for i in xrange(sr.num_seqs):
        x, key = sr.read_next_seq()
        keys.append(key)
        elbo[i] = model.elbo(x)
        num_frames[i] = x.shape[0]

    num_total_frames = np.sum(num_frames)
    total_elbo = np.sum(elbo)
    total_elbo_norm = total_elbo / num_total_frames
    logging.info('Extract elapsed time: %.2f' % (time.time() - t1))
    s = 'Total ELBO: %f\nELBO_NORM %f' % (total_elbo, total_elbo_norm)
    logging.info(s)

    with open(output_file, 'w') as f:
        f.write(s)
Exemplo n.º 8
0
def generate_signal():

    rng = np.random.RandomState(seed=1024)
    s = (2**10) * rng.randn(fs * 10).astype(float_cpu(), copy=False)
    #s = rng.randn(fs*10).astype(float_cpu(), copy=False)
    return s
Exemplo n.º 9
0
def to_dense(r_sparse, index, num_comp):
    r = np.zeros((r_sparse.shape[0], num_comp), dtype=float_cpu())
    for i in xrange(r_sparse.shape[0]):
        r[i, index[i]] = r_sparse[i]

    return r