Beispiel #1
0
def test_decode_continuous_with_priors():
    """Acceptance test of continuous image-based decoding with topic priors.
    """
    model_file = join(get_test_data_path(), 'gclda_model.pkl')
    continuous_file = join(get_test_data_path(), 'continuous.nii.gz')
    model = Model.load(model_file)
    _, priors = decode_continuous(model, continuous_file)
    decoded_df, _ = decode_continuous(model,
                                      continuous_file,
                                      topic_priors=priors)
    assert decoded_df.shape[0] == model.n_word_labels
Beispiel #2
0
def test_decode_continuous_from_file():
    """Acceptance test of continuous image-based decoding with str input.
    """
    model_file = join(get_test_data_path(), 'gclda_model.pkl')
    continuous_file = join(get_test_data_path(), 'continuous.nii.gz')
    model = Model.load(model_file)
    decoded_df, _ = decode_continuous(model, continuous_file)
    assert decoded_df.shape[0] == model.n_word_labels
model = Model.load(model_file)

###############################################################################
# Read in image to decode
# --------------------------------------
file_to_decode = '../data/faces_specificity_z.nii.gz'
img_to_decode = nib.load(file_to_decode)
fig = plotting.plot_stat_map(img_to_decode,
                             display_mode='z',
                             threshold=3.290527,
                             cut_coords=[-28, -4, 20, 50])

###############################################################################
# Decode image
# -------------
df, topic_weights = decode_continuous(model, img_to_decode)

###############################################################################
# Get associated terms
# ---------------------
df = df.sort_values(by='Weight', ascending=False)
print(df.head(10))

###############################################################################
# Plot topic weights
# ------------------
fig2, ax2 = plt.subplots()
ax2.plot(topic_weights)
ax2.set_xlabel('Topic #')
ax2.set_ylabel('Weight')
fig2.show()
Beispiel #4
0
text = 'faces and faces and faces face the other faces against facial discrimination'
_, prior = encode(model, text)

###############################################################################
# Read in image to decode
# --------------------------------------
file_to_decode = '../data/faces_specificity_z.nii.gz'
img_to_decode = nib.load(file_to_decode)
fig = plotting.plot_stat_map(img_to_decode, display_mode='z',
                             threshold=3.290527,
                             cut_coords=[-28, -4, 20, 50])

###############################################################################
# Decode image without prior
# --------------------------
_, posterior1 = decode_continuous(model, img_to_decode)

# max-normalize and sort for visualization
posterior1 = posterior1 / np.min(posterior1)
sorter = posterior1.argsort()
posterior1 = posterior1[sorter]

###############################################################################
# Decode image with weak prior
# -----------------------------
_, posterior2 = decode_continuous(model, img_to_decode, topic_priors=prior, prior_weight=0.01)

# max-normalize and sort for visualization
posterior2 = posterior2 / np.min(posterior2)
posterior2 = posterior2[sorter]