tensorflow / probability

Probabilistic reasoning and statistical analysis in TensorFlow
https://www.tensorflow.org/probability/
Apache License 2.0
4.26k stars 1.1k forks source link

Implementing MultivariateNormalFullCovariance for parameter estimation #1279

Open rballachay opened 3 years ago

rballachay commented 3 years ago

I have had success using the following model to parameterize a 2-coefficient function with linearly-combined input/output data from that system. I would like to create a 2-dimensional confidence region (ellipse) instead of having two independent normal distributions (requiring conversion to a covariance-inclusive model). I have tried using similar syntax, increasing the 'scalar' array to a k x k 'covariance' matrix, but I haven't had any luck. Does anybody have any ideas about how I can expand my model to parameterize a 2D normal distribution instead of two independent normals? Would be greatly appreciated. Thanks.

def mutable_model_nomulti(self): "Probabilistic model for SISO data" negloglik = lambda y, rv_y: -rv_y.log_prob(y[:]) model = tf.keras.Sequential([ tf.keras.layers.LSTM(100, activation='tanh', input_shape=(None, 1)), tfp.layers.DenseVariational(41,Model.posterior_mean_field,Model.prior_trainable,activation='linear',kl_weight=1/100), tfp.layers.DistributionLambda(lambda t: tfd.Normal(loc = t[..., :2], scale = (1e-3 + tf.math.softplus(0.1 t[...,2:])),)),]) model.compile(optimizer='adam', loss=negloglik,metrics=[Model.coeff_determination]) return model

davmre commented 3 years ago

Have you tried https://www.tensorflow.org/probability/api_docs/python/tfp/layers/MultivariateNormalTriL ?

On Mon, Mar 22, 2021 at 11:32 AM rballachay @.***> wrote:

I have had success using the following model to parameterize a 2-coefficient function with linearly-combined input/output data from that system. I would like to create a 2-dimensional confidence region (ellipse) instead of having two independent normal distributions (requiring conversion to a covariance-inclusive model). I have tried using similar syntax, increasing the 'scalar' array to a k x k 'covariance' matrix, but I haven't had any luck. Does anybody have any ideas about how I can expand my model to parameterize a 2D normal distribution instead of two independent normals? Would be greatly appreciated. Thanks.

def mutable_model_nomulti(self): "Probabilistic model for SISO data" negloglik = lambda y, rv_y: -rv_y.log_prob(y[:]) model = tf.keras.Sequential([ tf.keras.layers.LSTM(100, activation='tanh', input_shape=(None, 1)),

tfp.layers.DenseVariational(41,Model.posterior_mean_field,Model.prior_trainable,activation='linear',kl_weight=1/100), tfp.layers.DistributionLambda(lambda t: tfd.Normal(loc = t[..., :2], scale = (1e-3 + tf.math.softplus(0.1 t[...,2:])),)),]) model.compile(optimizer='adam', loss=negloglik,metrics=[Model.coeff_determination]) return model

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/tensorflow/probability/issues/1279, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHSFCSMLTRMAYD2NMAT7ADTE6EM7ANCNFSM4ZTVBWJQ .