Skip to content

Commit

Permalink
ENH we8there demos improved, bug fixed with display of topic top word…
Browse files Browse the repository at this point in the history
…s in PrintTopics.py
  • Loading branch information
michaelchughes committed Dec 8, 2016
1 parent 2d2f6d4 commit 8754bc2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
15 changes: 10 additions & 5 deletions bnpy/viz/PrintTopics.py
Expand Up @@ -253,6 +253,11 @@ def plotCompsFromWordCounts(
fig_h, ax_list = pylab.subplots(
nrows=nrows, ncols=ncols,
figsize=(ncols * W, nrows * H))
if isinstance(ax_list, np.ndarray):
ax_list = ax_list.flatten().tolist()
assert isinstance(ax_list, list)
n_images_viewable = len(ax_list)
n_images_to_plot = len(compListToPlot)

for plotID, compID in enumerate(compListToPlot):
cur_ax_h = ax_list[plotID] #pylab.subplot(nrows, ncols, plotID + 1)
Expand All @@ -278,11 +283,11 @@ def plotCompsFromWordCounts(
if xlabels is not None:
if len(xlabels) > 0:
cur_ax_h.set_xlabel(xlabels[plotID], fontsize=11)
# Disable empty plots!
#for kdel in xrange(plotID + 2, nrows * ncols + 1):
# aH = pylab.subplot(nrows, ncols, kdel)
# aH.axis('off')
# Fix margins between subplots

# Disable empty plots
for k, ax_h in enumerate(ax_list[n_images_to_plot:]):
ax_h.axis('off')

return figH, ax_list

def count2str(val, width=4, minVal=0.01, **kwargs):
Expand Down
Expand Up @@ -28,6 +28,7 @@
doc_ids = np.flatnonzero(
dataset.getDocTypeCountMatrix().sum(axis=1) >= 20)
dataset = dataset.make_subset(docMask=doc_ids, doTrackFullSize=False)

###############################################################################
#
# Make a simple plot of the raw data
Expand Down
Expand Up @@ -39,38 +39,31 @@

###############################################################################
#
# Train with VB algorithm
# -----------------------
# Train with birth and merge proposals
# ------------------------------------
#
# Take the best of 1 initializations
#
# Ideally, we'd run this longer, but this is convenient for rapid inspection.

merge_kwargs = dict(
m_startLap=10,
m_startLap=5,
m_pair_ranking_procedure='elbo',
m_pair_ranking_direction='descending',
m_pair_ranking_do_exclude_by_thr=1,
m_pair_ranking_exclusion_thr=-0.0005,
)
'''
trained_model, info_dict = bnpy.run(
dataset, 'DPMixtureModel', 'Mult', 'memoVB',
output_path='/tmp/we8there/helloworld-model=dp_mix+mult-K=30/',
nLap=1000, convergeThr=0.0001, nTask=1, nBatch=1,
K=30, initname='bregmankmeans+lam1+iter1',
gamma0=50.0, lam=0.1,
moves='birth,merge,shuffle',
b_startLap=2, b_Kfresh=5, b_stopLap=10,
**merge_kwargs)
'''

trained_model, info_dict = bnpy.run(
dataset, 'DPMixtureModel', 'Mult', 'memoVB',
output_path='/tmp/we8there/helloworld-model=dp_mix+mult-K=30/',
nLap=1000, convergeThr=0.0001, nTask=1, nBatch=1,
nLap=15, convergeThr=0.0001, nTask=1, nBatch=1,
K=30, initname='bregmankmeans+lam1+iter1',
gamma0=50.0, lam=0.1,
moves='birth,merge,shuffle',
b_startLap=2, b_Kfresh=5, b_stopLap=10,
**merge_kwargs)

bnpy.viz.PrintTopics.plotCompsFromHModel(
trained_model,
vocabList=dataset.vocabList,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -177,7 +177,7 @@ def make_list_of_datasets_specs():
# Main function
setup(
name="bnpy",
version="0.1.4",
version="0.1.5",
author="Michael C. Hughes",
author_email="mike@michaelchughes.com",
description=(
Expand Down

0 comments on commit 8754bc2

Please sign in to comment.