Exemplo n.º 1
0
            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
                            ]) + tf.reduce_sum(indiv_logdens) + tf.reduce_sum(
                                graph.get_collection('logdensities'))

kl = logdensity - prior
Exemplo n.º 2
0
country_data = {c: d for c, d in zip(ccodes, datas)}

#BUILDING the model

current_year = tf.placeholder(tf.float32, shape=(), name='current_year')
tf.summary.scalar('current_year', current_year)

models = []

with tf.variable_scope(tf.get_variable_scope(),
                       dtype=floatX,
                       reuse=tf.AUTO_REUSE):
    for country, data in country_data.items():
        model = VARmodel(data,
                         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])

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

kl = logdensity - prior
kl /= 36 * 200 * 4

kls = tf.summary.scalar('KLd', kl)
summary = tf.summary.merge_all()