Пример #1
0
def map(prob, modulename = 'model' ):
    try:
        mystr = "from " + modulename + " import model"
        exec(mystr)
    except:
        print 'cannot import', modulename
    M = MAP( model(prob) )
    M.fit()
    return M
Пример #2
0
def map(prob, modulename='model'):
    try:
        mystr = "from " + modulename + " import model"
        exec(mystr)
    except:
        print('cannot import', modulename)
    M = MAP(model(prob))
    M.fit()
    return M
Пример #3
0
    def sample(self,
               model,
               mapstart=False,
               step_methods=None,
               iters=80000,
               burn=20000,
               num_chains=4,
               doplot=True,
               showplots=False,
               force=False,
               progress_bar=False):

        print('MCMC for %s' % self.name)

        if self.is_done():
            if not force:
                print('\tAlready done, skipping...')
                return self.db_file
            else:
                print(
                    '\tWARNING: recomputing, there might be spurious files from previous runs...'
                )  # Not a good idea
        # Let's graph the model
        graph = pymc.graph.dag(pymc.Model(model),
                               name=self.name,
                               path=self.model_dir)
        graph.write_png(op.join(self.model_dir, self.name + '.png'))

        start = time.time()

        if mapstart:
            # See http://stronginference.com/post/burn-in-and-other-mcmc-folklore
            # BUT WARNING, WOULD THIS MAKE MULTIPLE CHAIN START BE OVERLY CORRELATED?
            try:
                from pymc import MAP
                print('\tFinding MAP estimates...')
                M = MAP(model)
                M.fit()
                model = M.variables
                print('\tMAP estimates found...')
            except Exception, e:
                print('\tMAP Failed...', str(e))
Пример #4
0
from matplotlib import pylab as plt
import dive_model
import no_ba_model
import asocial_model
import pymc
from pymc import MCMC, MAP
from pymc.Matplot import plot as mcplot


MASOC = MAP(asocial_model)
MASOC.fit(method="fmin", iterlim=100000, tol=0.000001)
print(MASOC.AIC)
print(MASOC.BIC)

MNOBA = MAP(no_ba_model)
MNOBA.fit(method="fmin", iterlim=100000, tol=0.000001)
print(MNOBA.AIC)
print(MNOBA.BIC)
print(MNOBA.dist.value)
print(MNOBA.lag.value)
print(MNOBA.intrinsic_rate.value)
print(MNOBA.social_rate.value)

MFULL = MAP(dive_model)
MFULL.fit(method="fmin", iterlim=100000, tol=0.000001)
print(MFULL.AIC)
print(MFULL.BIC)
print(MFULL.dist.value)
print(MFULL.lag.value)
print(MFULL.blind_angle.value)
print(MFULL.intrinsic_rate.value)
Пример #5
0
import corRandomWalk
import environment
import constantModel
import constantModelAlign

import networkModel
#import hybridModel
#import hybridModelv2
import pymc
from pymc import MAP
from pymc.Matplot import plot as mcplot


import networkModel

NM = MAP(networkModel)
NM.fit(method ='fmin', iterlim=100000, tol=.000001)
print(NM.AIC)
print(NM.BIC)

#print(NM.decay_exponent.value)
print(NM.interaction_length.value)
print(NM.interaction_angle.value)
#
#import decayModelAlign
#
#DMA = MAP(decayModelAlign)
#DMA.fit(method ='fmin', iterlim=100000, tol=.000001)
#print(DMA.AIC)
#print(DMA.BIC)
#
Пример #6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Yuki Furuta <*****@*****.**>

import numpy as np
from pymc import Dirichlet, Categorical, MAP, Model


if __name__ == '__main__':
    alpha = np.array([30.,25.,20.,25.])
    prob_dist = Dirichlet('prob_dist', alpha)

    exp_data = np.array([1,1,3,2,2,1,0])

    f_x = Categorical("cat", prob_dist, value=exp_data, observed=True)

    model = Model({'f_x': f_x,
                   'prob_dist': prob_dist
                   })
    m = MAP(model)
    m.fit()

    print m.prob_dist.value