def define_model(data):
    # Builds model object
    n = len(data)
    variable_names = ['g', 'sigma_g', 'p_type', 'T']
    known_params = {'sigma_z_g': sigma_z_g}
    hyper_params = {'prior_mu_g': 0*ones(n),
                    'prior_cov_g': 100*eye(n),
                    'alpha_type': (1., 1.),
                    'a_g': 3.,
                    'b_g': 1.}
    priors = {'sigma_g': stats.invgamma(hyper_params['a_g'], scale=hyper_params['b_g']),
              'p_type': dirichlet(hyper_params['alpha_type']),
              'T': iid_dist(categorical((1., 1.)), n),
              'g': mvnorm(hyper_params['prior_mu_g'], hyper_params['prior_cov_g'])}
    #initials = {'g': g[:n],
    #            'sigma_g': sigma_g}
    FCP_samplers = {'g': ground_height_step(),
                    'p_type': p_type_step(),
                    'T': type_step(),
                    'sigma_g': sigma_ground_step()}

    model = Model()
    model.set_variable_names(variable_names)
    model.set_known_params(known_params)
    model.set_hyper_params(hyper_params)
    model.set_priors(priors)
    #model.set_initials(initials)
    model.set_FCP_samplers(FCP_samplers)
    model.set_data(data)

    return model
def define_model(data):
    # Builds model object
    n = len(data)
    z = data.get('z')
    variable_names = ['surfaces', 'T', 'p_type', 'sigma_g', 'sigma_h']
    known_params = {
        'sigma_z_g': sigma_z_g,
        'sigma_z_h': sigma_z_h,
        'mu_h': mu_h,
        'phi': phi
    }
    hyper_params = {
        'alpha_type': array((1., 1., 1.)),
        'prior_mu_g': -25. + zeros(n),
        'prior_cov_g': 100. * eye(n),
        'prior_mu_h': 30. + zeros(n),
        'prior_cov_h': 100. * eye(n),
        'a_g': 11,
        'b_g': .1,
        'a_h': 11,
        'b_h': 40
    }
    initials = {
        'surfaces': [-25, 30] * ones((n, 2)),
        'sigma_g': .1,
        'sigma_h': 1,
        'T': array([(0 if abs(z[i] + 25) > 1 else 1) for i in xrange(n)])
    }
    #initials = {'sigma_g': sigma_g,
    #            'sigma_h': sigma_h,
    #            'T': T[:n],
    #            'g': g[:n],
    #            'h': h[:n]}
    priors = {
        'p_type': dirichlet(hyper_params['alpha_type']),
        'sigma_g': stats.invgamma(hyper_params['a_g'],
                                  scale=hyper_params['b_g']),
        'sigma_h': stats.invgamma(hyper_params['a_h'],
                                  scale=hyper_params['b_h']),
        'T': iid_dist(categorical(hyper_params['alpha_type']), n)
    }
    FCP_samplers = {
        'p_type': p_type_step(),
        'surfaces': surfaces_step(),
        'sigma_g': sigma_ground_step(),
        'sigma_h': sigma_height_step(),
        'T': type_step()
    }

    model = Model()
    model.set_variable_names(variable_names)
    model.set_known_params(known_params)
    model.set_hyper_params(hyper_params)
    model.set_priors(priors)
    model.set_initials(initials)
    model.set_FCP_samplers(FCP_samplers)
    model.set_data(data)

    return model
def define_model(data):
    # Builds model object
    m = 3
    n_points = len(data)
    n_shots = len(set(data['shot_id']))
    variable_names = ['g', 'h', 'T', 'p_type', 'sigma_g', 'sigma_h']
    known_params = {'sigma_z_g': sigma_z_g,
                    'sigma_z_h': sigma_z_h,
                    'mu_h': mu_h,
                    'phi': phi}
    hyper_params = {'alpha_type': array((0, 1., 1.)),
                    'prior_mu_g': -25.+zeros(n_shots),
                    'prior_cov_g': 100.*eye(n_shots),
                    'prior_mu_h': 30.+zeros(n_shots),
                    'prior_cov_h': 100.*eye(n_shots),
                    'a_g': 6,
                    'b_g': 1,
                    'a_h': 6,
                    'b_h': 1}
    initials = {}
    #initials = {'sigma_g': sigma_g,
    #            'sigma_h': sigma_h,
    #            'T': T[:n_shots],
    #            'g': g[:n_shots],
    #            'h': h[:n_shots]}
    priors = {'p_type': dirichlet(hyper_params['alpha_type']),
              'sigma_g': stats.invgamma(hyper_params['a_g'], scale=hyper_params['b_g']),
              'sigma_h': stats.invgamma(hyper_params['a_h'], scale=hyper_params['b_h']),
              'g': mvnorm(hyper_params['prior_mu_g'], hyper_params['prior_cov_g']),
              'h': mvnorm(hyper_params['prior_mu_h'], hyper_params['prior_cov_h']),
              'T': iid_dist(categorical(hyper_params['alpha_type']/sum(hyper_params['alpha_type'])), n_points)}
    FCP_samplers = {'p_type': p_type_step(),
                    'g': ground_height_step(),
                    'h': canopy_height_step(),
                    'sigma_g': sigma_ground_step(),
                    'sigma_h': sigma_height_step(),
                    'T': type_step()}

    model = Model()
    model.set_variable_names(variable_names)
    model.set_known_params(known_params)
    model.set_hyper_params(hyper_params)
    model.set_priors(priors)
    model.set_initials(initials)
    model.set_FCP_samplers(FCP_samplers)
    model.set_data(data)

    return model
def define_model(data):
    # Builds model object
    n = len(data)
    z = data.get('z')
    variable_names = ['surfaces', 'T', 'p_type', 'sigma_g', 'sigma_h']
    known_params = {'sigma_z_g': sigma_z_g,
                    'sigma_z_h': sigma_z_h,
                    'mu_h': mu_h,
                    'phi': phi}
    hyper_params = {'alpha_type': array((1., 1., 1.)),
                    'prior_mu_g': -25.+zeros(n),
                    'prior_cov_g': 100.*eye(n),
                    'prior_mu_h': 30.+zeros(n),
                    'prior_cov_h': 100.*eye(n),
                    'a_g': 11,
                    'b_g': .1,
                    'a_h': 11,
                    'b_h': 40}
    initials = {'surfaces': [-25, 30]*ones((n,2)),
                'sigma_g': .1,
                'sigma_h': 1,
                'T': array([(0 if abs(z[i]+25)>1 else 1) for i in xrange(n)])}
    #initials = {'sigma_g': sigma_g,
    #            'sigma_h': sigma_h,
    #            'T': T[:n],
    #            'g': g[:n],
    #            'h': h[:n]}
    priors = {'p_type': dirichlet(hyper_params['alpha_type']),
              'sigma_g': stats.invgamma(hyper_params['a_g'], scale=hyper_params['b_g']),
              'sigma_h': stats.invgamma(hyper_params['a_h'], scale=hyper_params['b_h']),
              'T': iid_dist(categorical(hyper_params['alpha_type']), n)}
    FCP_samplers = {'p_type': p_type_step(),
                    'surfaces': surfaces_step(),
                    'sigma_g': sigma_ground_step(),
                    'sigma_h': sigma_height_step(),
                    'T': type_step()}

    model = Model()
    model.set_variable_names(variable_names)
    model.set_known_params(known_params)
    model.set_hyper_params(hyper_params)
    model.set_priors(priors)
    model.set_initials(initials)
    model.set_FCP_samplers(FCP_samplers)
    model.set_data(data)

    return model
Esempio n. 5
0
def define_model(data):
    # Builds model object
    n = len(data)
    variable_names = ['g', 'sigma_g', 'p_type', 'T']
    known_params = {'sigma_z_g': sigma_z_g}
    hyper_params = {
        'prior_mu_g': 0 * ones(n),
        'prior_cov_g': 100 * eye(n),
        'alpha_type': (1., 1.),
        'a_g': 3.,
        'b_g': 1.
    }
    priors = {
        'sigma_g': stats.invgamma(hyper_params['a_g'],
                                  scale=hyper_params['b_g']),
        'p_type': dirichlet(hyper_params['alpha_type']),
        'T': iid_dist(categorical((1., 1.)), n),
        'g': mvnorm(hyper_params['prior_mu_g'], hyper_params['prior_cov_g'])
    }
    #initials = {'g': g[:n],
    #            'sigma_g': sigma_g}
    FCP_samplers = {
        'g': ground_height_step(),
        'p_type': p_type_step(),
        'T': type_step(),
        'sigma_g': sigma_ground_step()
    }

    model = Model()
    model.set_variable_names(variable_names)
    model.set_known_params(known_params)
    model.set_hyper_params(hyper_params)
    model.set_priors(priors)
    #model.set_initials(initials)
    model.set_FCP_samplers(FCP_samplers)
    model.set_data(data)

    return model
 def sample(self, model, evidence):
     alpha_type = model.hyper_params['alpha_type']
     T = evidence['T']
     m = len(alpha_type)
     return dirichlet(alpha_type + array([sum(T == i)
                                          for i in xrange(m)])).rvs()
 def sample(self, model, evidence):
     alpha_type = model.hyper_params['alpha_type']
     T = evidence['T']
     m = len(alpha_type)
     return dirichlet(alpha_type + array([sum(T==i) for i in xrange(m)])).rvs()
def define_model(data):
    # Builds model object
    # Known values from simulation (can use to initialize sampler/skip burn-in)
    p = pickle.load(open('../data/sims/simulation_delta_0.pkl', 'rb'))
    g = p['g']
    h = p['h']
    T = p['T']
    sigma_g = p['sigma_g']
    sigma_h = p['sigma_h']
    # Also needed for known parameters (so load the right pkl dummy!)
    phi = p['phi']
    mu_h = p['mu_h']
    sigma_z_g = p['sigma_z_g']
    sigma_z_h = p['sigma_z_h']

    n = len(data)
    z = data.get('z')
    variable_names = ['g', 'h', 'T', 'p_type', 'sigma_g', 'sigma_h']
    known_params = {'sigma_z_g': sigma_z_g,
                    'sigma_z_h': sigma_z_h,
                    'mu_h': mu_h,
                    'phi': phi}
    hyper_params = {'alpha_type': array((1., 1., 1.)),
                    'prior_mu_g': -25.+zeros(n),
                    'prior_cov_g': 100.*eye(n),
                    'prior_mu_h': 30.+zeros(n),
                    'prior_cov_h': 100.*eye(n),
                    'a_g': 11,
                    'b_g': .1,
                    'a_h': 11,
                    'b_h': 40}
    #initials = {'g': -25+zeros(n),
    #            'sigma_g': .1,
    #            'sigma_h': 1,
    #            'T': array([(0 if abs(z[i]+25)>1 else 1) for i in xrange(n)])}
    initials = {'sigma_g': sigma_g,
                'sigma_h': sigma_h,
                'p_type': array((0, .5, .5)),
                'T': T[:n],
                'g': g[:n],
                'h': h[:n]}
    priors = {'p_type': dirichlet(hyper_params['alpha_type']),
              'sigma_g': stats.invgamma(hyper_params['a_g'], scale=hyper_params['b_g']),
              'sigma_h': stats.invgamma(hyper_params['a_h'], scale=hyper_params['b_h']),
              'g': mvnorm(hyper_params['prior_mu_g'], hyper_params['prior_cov_g']),
              'h': mvnorm(hyper_params['prior_mu_h'], hyper_params['prior_cov_h']),
              'T': iid_dist(categorical(hyper_params['alpha_type']), n)}
    FCP_samplers = {'p_type': p_type_step(),
                    'g': ground_height_step(),
                    'h': canopy_height_step(),
                    'sigma_g': sigma_ground_step(),
                    'sigma_h': sigma_height_step(),
                    'T': type_step()}

    model = Model()
    model.set_variable_names(variable_names)
    model.set_known_params(known_params)
    model.set_hyper_params(hyper_params)
    model.set_priors(priors)
    model.set_initials(initials)
    model.set_FCP_samplers(FCP_samplers)
    model.set_data(data)

    return model
Esempio n. 9
0
def define_model(data):
    # Builds model object
    # Known values from simulation (can use to initialize sampler/skip burn-in)
    p = pickle.load(open('../data/sims/simulation_delta_0.pkl', 'rb'))
    g = p['g']
    h = p['h']
    T = p['T']
    sigma_g = p['sigma_g']
    sigma_h = p['sigma_h']
    # Also needed for known parameters (so load the right pkl dummy!)
    phi = p['phi']
    mu_h = p['mu_h']
    sigma_z_g = p['sigma_z_g']
    sigma_z_h = p['sigma_z_h']

    n = len(data)
    z = data.get('z')
    variable_names = ['g', 'h', 'T', 'p_type', 'sigma_g', 'sigma_h']
    known_params = {
        'sigma_z_g': sigma_z_g,
        'sigma_z_h': sigma_z_h,
        'mu_h': mu_h,
        'phi': phi
    }
    hyper_params = {
        'alpha_type': array((1., 1., 1.)),
        'prior_mu_g': -25. + zeros(n),
        'prior_cov_g': 100. * eye(n),
        'prior_mu_h': 30. + zeros(n),
        'prior_cov_h': 100. * eye(n),
        'a_g': 11,
        'b_g': .1,
        'a_h': 11,
        'b_h': 40
    }
    #initials = {'g': -25+zeros(n),
    #            'sigma_g': .1,
    #            'sigma_h': 1,
    #            'T': array([(0 if abs(z[i]+25)>1 else 1) for i in xrange(n)])}
    initials = {
        'sigma_g': sigma_g,
        'sigma_h': sigma_h,
        'p_type': array((0, .5, .5)),
        'T': T[:n],
        'g': g[:n],
        'h': h[:n]
    }
    priors = {
        'p_type': dirichlet(hyper_params['alpha_type']),
        'sigma_g': stats.invgamma(hyper_params['a_g'],
                                  scale=hyper_params['b_g']),
        'sigma_h': stats.invgamma(hyper_params['a_h'],
                                  scale=hyper_params['b_h']),
        'g': mvnorm(hyper_params['prior_mu_g'], hyper_params['prior_cov_g']),
        'h': mvnorm(hyper_params['prior_mu_h'], hyper_params['prior_cov_h']),
        'T': iid_dist(categorical(hyper_params['alpha_type']), n)
    }
    FCP_samplers = {
        'p_type': p_type_step(),
        'g': ground_height_step(),
        'h': canopy_height_step(),
        'sigma_g': sigma_ground_step(),
        'sigma_h': sigma_height_step(),
        'T': type_step()
    }

    model = Model()
    model.set_variable_names(variable_names)
    model.set_known_params(known_params)
    model.set_hyper_params(hyper_params)
    model.set_priors(priors)
    model.set_initials(initials)
    model.set_FCP_samplers(FCP_samplers)
    model.set_data(data)

    return model
Esempio n. 10
0
def define_model(data):
    # Builds model object
    m = 3
    n_points = len(data)
    n_shots = len(set(data['shot_id']))
    variable_names = ['g', 'h', 'T', 'p_type', 'sigma_g', 'sigma_h']
    known_params = {
        'sigma_z_g': sigma_z_g,
        'sigma_z_h': sigma_z_h,
        'mu_h': mu_h,
        'phi': phi
    }
    hyper_params = {
        'alpha_type': array((0, 1., 1.)),
        'prior_mu_g': -25. + zeros(n_shots),
        'prior_cov_g': 100. * eye(n_shots),
        'prior_mu_h': 30. + zeros(n_shots),
        'prior_cov_h': 100. * eye(n_shots),
        'a_g': 6,
        'b_g': 1,
        'a_h': 6,
        'b_h': 1
    }
    initials = {}
    #initials = {'sigma_g': sigma_g,
    #            'sigma_h': sigma_h,
    #            'T': T[:n_shots],
    #            'g': g[:n_shots],
    #            'h': h[:n_shots]}
    priors = {
        'p_type':
        dirichlet(hyper_params['alpha_type']),
        'sigma_g':
        stats.invgamma(hyper_params['a_g'], scale=hyper_params['b_g']),
        'sigma_h':
        stats.invgamma(hyper_params['a_h'], scale=hyper_params['b_h']),
        'g':
        mvnorm(hyper_params['prior_mu_g'], hyper_params['prior_cov_g']),
        'h':
        mvnorm(hyper_params['prior_mu_h'], hyper_params['prior_cov_h']),
        'T':
        iid_dist(
            categorical(hyper_params['alpha_type'] /
                        sum(hyper_params['alpha_type'])), n_points)
    }
    FCP_samplers = {
        'p_type': p_type_step(),
        'g': ground_height_step(),
        'h': canopy_height_step(),
        'sigma_g': sigma_ground_step(),
        'sigma_h': sigma_height_step(),
        'T': type_step()
    }

    model = Model()
    model.set_variable_names(variable_names)
    model.set_known_params(known_params)
    model.set_hyper_params(hyper_params)
    model.set_priors(priors)
    model.set_initials(initials)
    model.set_FCP_samplers(FCP_samplers)
    model.set_data(data)

    return model