From 8754bc20906b944c9f4f3bcf2958416059527e70 Mon Sep 17 00:00:00 2001 From: Mike Hughes Date: Thu, 8 Dec 2016 11:41:14 +0100 Subject: [PATCH] ENH we8there demos improved, bug fixed with display of topic top words in PrintTopics.py --- bnpy/viz/PrintTopics.py | 15 ++++++++---- ...-demo=mix_vb_single_run-model=mix+mult.py} | 1 + ...emo=mix_vb+proposals-model=dp_mix+mult.py} | 23 +++++++------------ ...pic_vb_single_run-model=hdp_topic+mult.py} | 0 ...opic_vb+proposals-model=hdp_topic+mult.py} | 0 setup.py | 2 +- 6 files changed, 20 insertions(+), 21 deletions(-) rename examples/06_we8there/{plot-demo=vb_single_run-model=mix+mult.py => plot-01-demo=mix_vb_single_run-model=mix+mult.py} (99%) rename examples/06_we8there/{plot-demo=vb+proposals-model=dp_mix+mult.py => plot-02-demo=mix_vb+proposals-model=dp_mix+mult.py} (78%) rename examples/06_we8there/{plot-demo=topic_model_vb_single_run-model=hdp_topic+mult.py => plot-03-demo=topic_vb_single_run-model=hdp_topic+mult.py} (100%) rename examples/06_we8there/{plot-demo=topic_model_vb+proposals-model=hdp_topic+mult.py => plot-04-demo=topic_vb+proposals-model=hdp_topic+mult.py} (100%) diff --git a/bnpy/viz/PrintTopics.py b/bnpy/viz/PrintTopics.py index 8c86366..0f24a89 100644 --- a/bnpy/viz/PrintTopics.py +++ b/bnpy/viz/PrintTopics.py @@ -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) @@ -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): diff --git a/examples/06_we8there/plot-demo=vb_single_run-model=mix+mult.py b/examples/06_we8there/plot-01-demo=mix_vb_single_run-model=mix+mult.py similarity index 99% rename from examples/06_we8there/plot-demo=vb_single_run-model=mix+mult.py rename to examples/06_we8there/plot-01-demo=mix_vb_single_run-model=mix+mult.py index ae86ac3..954b768 100644 --- a/examples/06_we8there/plot-demo=vb_single_run-model=mix+mult.py +++ b/examples/06_we8there/plot-01-demo=mix_vb_single_run-model=mix+mult.py @@ -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 diff --git a/examples/06_we8there/plot-demo=vb+proposals-model=dp_mix+mult.py b/examples/06_we8there/plot-02-demo=mix_vb+proposals-model=dp_mix+mult.py similarity index 78% rename from examples/06_we8there/plot-demo=vb+proposals-model=dp_mix+mult.py rename to examples/06_we8there/plot-02-demo=mix_vb+proposals-model=dp_mix+mult.py index e9422f8..1f40c58 100644 --- a/examples/06_we8there/plot-demo=vb+proposals-model=dp_mix+mult.py +++ b/examples/06_we8there/plot-02-demo=mix_vb+proposals-model=dp_mix+mult.py @@ -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, diff --git a/examples/06_we8there/plot-demo=topic_model_vb_single_run-model=hdp_topic+mult.py b/examples/06_we8there/plot-03-demo=topic_vb_single_run-model=hdp_topic+mult.py similarity index 100% rename from examples/06_we8there/plot-demo=topic_model_vb_single_run-model=hdp_topic+mult.py rename to examples/06_we8there/plot-03-demo=topic_vb_single_run-model=hdp_topic+mult.py diff --git a/examples/06_we8there/plot-demo=topic_model_vb+proposals-model=hdp_topic+mult.py b/examples/06_we8there/plot-04-demo=topic_vb+proposals-model=hdp_topic+mult.py similarity index 100% rename from examples/06_we8there/plot-demo=topic_model_vb+proposals-model=hdp_topic+mult.py rename to examples/06_we8there/plot-04-demo=topic_vb+proposals-model=hdp_topic+mult.py diff --git a/setup.py b/setup.py index 59654b5..93d8c49 100644 --- a/setup.py +++ b/setup.py @@ -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=(