# Using custom log probability for custom model

**URL:** <https://discourse.edwardlib.org/t/using-custom-log-probability-for-custom-model/470>\
**Category:** General\
**Created:** [November 3, 2017, 6:09pm UTC](https://discourse.edwardlib.org/t/using-custom-log-probability-for-custom-model/470 "2017-11-03T18:09:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaivardhankapoor](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.edwardlib.org/jaivardhankapoor/32/165_2.png) [@jaivardhankapoor](https://discourse.edwardlib.org/u/jaivardhankapoor)\
**Post date:** [November 3, 2017, 6:09pm UTC](https://discourse.edwardlib.org/t/using-custom-log-probability-for-custom-model/470/1 "2017-11-03T18:09:49Z")

</div>

Hi all,  
I am working on a model that uses a custom point process, and I need to pass some tf variables and Edward distributions, and get a log probability in return to train upon it using KL methods. I do not need to sample from the stochastic process, but just need its log likelihood for training. How do I add that functionality in the class code? I used the function `_log_prob` to return the log likelihood, but it doesn’t seem to work.

---

<div class="post-metadata">

**Author:** ![cshenton](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.edwardlib.org/cshenton/32/99_2.png) [@cshenton](https://discourse.edwardlib.org/u/cshenton)\
**Post date:** [November 7, 2017, 2:30am UTC](https://discourse.edwardlib.org/t/using-custom-log-probability-for-custom-model/470/2 "2017-11-07T02:30:49Z")

</div>

So it sounds like the final step in your model is a custom probability distribution, rather than one of the built in tf ones that edward alias into `RandomVariable`s.

In that case, you’ll need to subclass `tf.Distribution` and implement both `_sample_n` and `_log_prob`, then use that to create a `RandomVariable` class. Even though you’re not sampling from it, Edward needs `sample` to create a tensor representation of the distribution, which it uses for inference.

Hard to be more specific without a code sample though.

---

<div class="post-metadata">

**Author:** ![jaivardhankapoor](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.edwardlib.org/jaivardhankapoor/32/165_2.png) [@jaivardhankapoor](https://discourse.edwardlib.org/u/jaivardhankapoor)\
**Post date:** [November 9, 2017, 11:34am UTC](https://discourse.edwardlib.org/t/using-custom-log-probability-for-custom-model/470/3 "2017-11-09T11:34:19Z")

</div>

Thank you for replying! It seems that I was naive to just implement an overloading function for `_log_prob` in the edward custom RV class. The log probability is the only value I need for training, and all the variables used in it are essentially either tensors or Edward distributions, which are passed int the ` __init__ ` function in my class. I used Edward only to refrain from hardcoding VB updates for the graphical model. I guess I will have to write a custom TF class for the process anyway, if that is what you meant to say?
