Ejemplo n.º 1
0
        with tf.variable_scope(country):
            aux = tf.concat([global_inf.output, variation[tf.newaxis]],
                            axis=-1)
            individ_variation = DFlow([
                NVPFlow((VAR_DIM * 2 + 1) * VAR_DIM,
                        name='nvp_{}'.format(i),
                        aux_vars=aux) for i in range(6)
            ],
                                      init_sigma=0.01)

            ind = individ_variation.output[0] + global_inf.output[0]
            indivs[country] = ind

            tf.add_to_collection('logdensities', individ_variation.logdens)
            tf.add_to_collection('priors',
                                 individ_variation_prior.logdens(ind))
        model = STACmodel(data,
                          mu=ind[tf.newaxis],
                          name='{}_model'.format(country),
                          var_dim=VAR_DIM,
                          current_year=current_year)
        models.append(model)

graph = tf.get_default_graph()

prior = tf.reduce_sum([model.priors for model in models]) + tf.reduce_sum(
    graph.get_collection('priors'))

logdensity = tf.reduce_sum([model.logdensities
                            for model in models]) + tf.reduce_sum(
                                graph.get_collection('logdensities'))
Ejemplo n.º 2
0
                       dtype=floatX,
                       reuse=tf.AUTO_REUSE):
    for country, data in country_data.items():
        with tf.variable_scope(country):
            individ_variation = DFlow([
                NVPFlow((VAR_DIM * 2 + 1) * VAR_DIM,
                        name='nvp_{}'.format(i),
                        aux_vars=global_inf.output) for i in range(6)
            ],
                                      init_sigma=0.01)

            ind = individ_variation.output[0]
            indivs[country] = ind

            indiv_logdens.append(individ_variation.logdens)
            indiv_priors.append(individ_variation_prior.logdens(ind))

        model = VARmodel(data,
                         name='{}_model'.format(country),
                         var_dim=VAR_DIM,
                         mu=ind[tf.newaxis],
                         current_year=current_year)
        models.append(model)

graph = tf.get_default_graph()

prior = tf.reduce_sum([model.priors for model in models
                       ]) + tf.reduce_sum(indiv_priors) + tf.reduce_sum(
                           graph.get_collection('priors'))

logdensity = tf.reduce_sum([model.logdensities for model in models