<commit_before>"""
The DisasterMCMC example.

"""
from __future__ import with_statement
from numpy.testing import *
from pymc import MCMC, database
from pymc.examples import disaster_model
import nose,  warnings, os

PLOT=True
try:
    from pymc.Matplot import plot, autocorrelation
except:
    PLOT=False
    pass


DIR = 'testresults/'


class test_MCMC(TestCase):

    # Instantiate samplers
    M = MCMC(disaster_model, db='pickle')

    # Sample
    M.sample(4000,2000,verbose=0, progress_bar=False)
    M.db.close()
    def test_instantiation(self):

        # Check stochastic arrays
        assert_equal(len(self.M.stochastics), 3)
        assert_equal(len(self.M.observed_stochastics),1)
        assert_array_equal(self.M.disasters.value, disaster_model.disasters_array)

    def test_plot(self):
        if not PLOT:
            raise nose.SkipTest

        # Plot samples
        plot(self.M.early_mean, path=DIR, verbose=0)

    def test_autocorrelation(self):
        if not PLOT:
            raise nose.SkipTest

        # Plot samples
        autocorrelation(self.M.early_mean, path=DIR,  verbose=0)

    def test_stats(self):
        S = self.M.early_mean.stats()
        self.M.stats()

    def test_stats_after_reload(self):
        db = database.pickle.load('MCMC.pickle')
        M2 = MCMC(disaster_model, db=db)
        M2.stats()
        db.close()
        os.remove('MCMC.pickle')


if __name__ == '__main__':
    
    original_filters = warnings.filters[:]
    warnings.simplefilter("ignore")
    try:
        import nose
        nose.runmodule()
    finally:
        warnings.filters = original_filters
    
    # TODO: Restore in 2.2    
    # with warnings.catch_warnings():
    #         warnings.simplefilter('ignore',  FutureWarning)
    #         nose.runmodule()
    
<commit_msg>Added test for very small MCMC runs<commit_after>"""
The DisasterMCMC example.

"""
from __future__ import with_statement
from numpy.testing import *
from pymc import MCMC, database
from pymc.examples import disaster_model
import nose,  warnings, os

PLOT=True
try:
    from pymc.Matplot import plot, autocorrelation
except:
    PLOT=False
    pass


DIR = 'testresults/'

class test_tiny_MCMC(TestCase):

    # Instantiate samplers
    M = MCMC(disaster_model)

    # Sample
    M.sample(10, progress_bar=False)

    def test_plot(self):

        if not PLOT:
            raise nose.SkipTest

        # Plot samples
        plot(M)


class test_MCMC(TestCase):

    # Instantiate samplers
    M = MCMC(disaster_model, db='pickle')

    # Sample
    M.sample(4000,2000,verbose=0, progress_bar=False)
    M.db.close()
    def test_instantiation(self):

        # Check stochastic arrays
        assert_equal(len(self.M.stochastics), 3)
        assert_equal(len(self.M.observed_stochastics),1)
        assert_array_equal(self.M.disasters.value, disaster_model.disasters_array)

    def test_plot(self):
        if not PLOT:
            raise nose.SkipTest

        # Plot samples
        plot(self.M.early_mean, path=DIR, verbose=0)

    def test_autocorrelation(self):
        if not PLOT:
            raise nose.SkipTest

        # Plot samples
        autocorrelation(self.M.early_mean, path=DIR,  verbose=0)

    def test_stats(self):
        S = self.M.early_mean.stats()
        self.M.stats()

    def test_stats_after_reload(self):
        db = database.pickle.load('MCMC.pickle')
        M2 = MCMC(disaster_model, db=db)
        M2.stats()
        db.close()
        os.remove('MCMC.pickle')


if __name__ == '__main__':
    
    original_filters = warnings.filters[:]
    warnings.simplefilter("ignore")
    try:
        import nose
        nose.runmodule()
    finally:
        warnings.filters = original_filters
    
    # TODO: Restore in 2.2    
    # with warnings.catch_warnings():
    #         warnings.simplefilter('ignore',  FutureWarning)
    #         nose.runmodule()
    

{'fraction_non_alphanumeric': 0.10007678525723061, 'fraction_numerical': 0.009214230867673407, 'mean_word_length': 2.5591985428051003, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7533119', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1253, 'n_words': 261}