# Help understanding log\_prob and defining the right loss function with tensorflow probability

**URL:** <https://discuss.ai.google.dev/t/help-understanding-log-prob-and-defining-the-right-loss-function-with-tensorflow-probability/30383>\
**Category:** General Discussion\
**Tags:** tf-probability, help\_request\
**Created:** [April 25, 2022, 1:15am UTC](https://discuss.ai.google.dev/t/help-understanding-log-prob-and-defining-the-right-loss-function-with-tensorflow-probability/30383 "2022-04-25T01:15:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![P11](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/p11/32/10396_2.png) [@P11](https://discuss.ai.google.dev/u/P11)\
**Post date:** [April 25, 2022, 1:15am UTC](https://discuss.ai.google.dev/t/help-understanding-log-prob-and-defining-the-right-loss-function-with-tensorflow-probability/30383/1 "2022-04-25T01:15:35Z")

</div>

Hi everyone, i have (very) recently started using tensorflow and i am facing some issue with tensorflow probability and i hope you guys can give me an hand.  
basically i have set up a very small fcnn bayesian network for regression

```auto
from tensorflow.keras.layers import Dropout

from tensorflow.keras.layers import Input

from tensorflow.keras.layers import Dense

 

from tensorflow.keras.models import Model

from tensorflow.keras.optimizers import Adam

def NLL(y, distr): 

  return -distr.log_prob(y) 

inputs = Input(shape=(1,))

hidden = Dense(200,activation="relu")(inputs)

hidden = Dropout(0.1)(hidden, training=True)

hidden = Dense(200,activation="relu")(hidden)

hidden = Dropout(0.1)(hidden, training=True)

hidden = Dense(200,activation="relu")(hidden)

hidden = Dropout(0.1)(hidden, training=True)

params_mc = Dense(2)(hidden)

dist_mc = tfp.layers.DistributionLambda(normal_exp, name='normal_exp')(params_mc) 

model_mc = Model(inputs=inputs, outputs=dist_mc)

model_mc.compile(Adam(learning_rate=0.004), loss=NLL)

```

the network works and the results are good but the problem is that my data are not independent from each other but correlated while the network links the output distribution to the loss function through -distr.log\_prob . Is it possible to set a loss function that does not depend from the output distribution? I have a covariance matrix and i would like to use the log likelihood of a multivariate gaussian as a loss function while leaving untouched the output layer ( for predicting mean and variance ). In case it is not possible, how can i predict the entire covariance matrix?
