Beispiel #1
0
def mvnpdf(data, means, covs):
    '''
    Compute multivariate normal log pdf

    Parameters
    ----------

    Returns
    -------

    '''
    logdets = [np.log(np.linalg.det(c)) for c in covs]
    ichol_sigmas = [inv(chol(c)) for c in covs]

    packed_params = util.pack_params(means, ichol_sigmas, logdets)
    packed_data = util.pad_data(data)
    return testmod.mvn_call(packed_data, packed_params, data.shape[1])
Beispiel #2
0
def mvnpdf(data, means, covs):
    '''
    Compute multivariate normal log pdf

    Parameters
    ----------

    Returns
    -------

    '''
    logdets = [np.log(np.linalg.det(c)) for c in covs]
    ichol_sigmas = [inv(chol(c)) for c in covs]

    packed_params = util.pack_params(means, ichol_sigmas, logdets)
    packed_data = util.pad_data(data)
    return testmod.mvn_call(packed_data, packed_params,
                            data.shape[1])
Beispiel #3
0
MAX_WORD_LENGTH = config.word_length
wl = MAX_WORD_LENGTH

train_char, sl, wl = gen_data(texts, 0, wl, index_char)
val_char, sl, wl = gen_data(val_texts, sl, wl, index_char)
test_char, sl, wl = gen_data(test_texts, sl, wl, index_char)

MAX_SEQUENCE_LENGTH = sl

if MAX_SEQUENCE_LENGTH % 2 == 1:
    MAX_SEQUENCE_LENGTH += 1
print(MAX_WORD_LENGTH)
print(MAX_SEQUENCE_LENGTH)

train_data_char = pad_data(train_char, MAX_SEQUENCE_LENGTH, MAX_WORD_LENGTH)
val_data_char = pad_data(val_char, MAX_SEQUENCE_LENGTH, MAX_WORD_LENGTH)
test_data_char = pad_data(test_char, MAX_SEQUENCE_LENGTH, MAX_WORD_LENGTH)

# print(np.shape(train_char))

labels = pad_label(labels, MAX_SEQUENCE_LENGTH)
val_labels = pad_label(val_labels, MAX_SEQUENCE_LENGTH)
test_labels = pad_label(test_labels, MAX_SEQUENCE_LENGTH)

num_chars = len(index_char)

model_char = Sequential()
# embedding shape (None/word num in a sent, max_char_num_in_word, char_emb_dim)
model_char.add(
    Embedding(input_dim=num_chars,
Beispiel #4
0
    print cpu_speed / gpu_speed


if __name__ == '__main__':
    testmod.set_device(0)

    n = 1e3
    k = 16

    data = randn(n, k).astype(np.float32)
    mean = randn(k)
    cov = np.array(util.random_cov(k), dtype=np.float32)

    j = 32

    padded_data = util.pad_data(data)

    chol_sigma = chol(cov)
    ichol_sigma = L.inv(chol_sigma)
    logdet = np.log(np.linalg.det(cov))

    means = (mean, ) * j
    covs = (ichol_sigma, ) * j
    logdets = (logdet, ) * j

    packed_params = util.pack_params(means, covs, logdets)

    cpu_func = lambda: testmod.cpu_mvnpdf(padded_data, packed_params, k
                                          ).squeeze()
    gpu_func = lambda: testmod._mvnpdf(padded_data, packed_params, k).squeeze()
Beispiel #5
0
    print 'GPU speed: %.3f' % (gpu_speed * 1000)
    print cpu_speed / gpu_speed

if __name__ == '__main__':
    testmod.set_device(0)

    n = 1e3
    k = 16

    data = randn(n, k).astype(np.float32)
    mean = randn(k)
    cov = np.array(util.random_cov(k), dtype=np.float32)

    j = 32

    padded_data = util.pad_data(data)

    chol_sigma = chol(cov)
    ichol_sigma = L.inv(chol_sigma)
    logdet = np.log(np.linalg.det(cov))

    means = (mean,) * j
    covs = (ichol_sigma,) * j
    logdets = (logdet,) * j

    packed_params = util.pack_params(means, covs, logdets)

    cpu_func = lambda: testmod.cpu_mvnpdf(padded_data, packed_params, k).squeeze()
    gpu_func = lambda: testmod._mvnpdf(padded_data, packed_params, k).squeeze()

    print cpu_func()