Skip to content

Commit

Permalink
rudimentary joint pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasheinrich authored and matthewfeickert committed Sep 9, 2019
1 parent 6887846 commit ca8c196
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/pyhf/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,7 @@ def logpdf(self, auxdata, pars):
tensorlib, _ = get_backend()
normal = self.constraints_gaussian.logpdf(auxdata, pars)
poisson = self.constraints_poisson.logpdf(auxdata, pars)
if self.batch_size is None:
return normal + poisson
terms = tensorlib.stack([normal, poisson])
return tensorlib.sum(terms, axis=0)
return prob.joint_logpdf([normal, poisson])


class _MainModel(object):
Expand Down Expand Up @@ -548,10 +545,13 @@ def logpdf(self, pars, data):
mainpdf = self.main_model.logpdf(actual_data, pars)
constraint = self.constraint_model.logpdf(aux_data, pars)

result = tensorlib.sum(tensorlib.stack([mainpdf, constraint]), axis=0)
if not self.batch_size:
result = prob.joint_logpdf([mainpdf, constraint])

if (
not self.batch_size
): # force to be not scalar, should we changed with #522
return tensorlib.reshape(result, (1,))
return tensorlib.astensor(result)
return result
except:
log.error(
'eval failed for data {} pars: {}'.format(
Expand Down
7 changes: 7 additions & 0 deletions src/pyhf/probability.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ def log_prob(self, value):
result = self._pdf.log_prob(value)
result = tensorlib.sum(result, axis=-1)
return result


def joint_logpdf(terms):
tensorlib, _ = get_backend()
terms = tensorlib.stack(terms)
result = tensorlib.sum(terms, axis=0)
return result

0 comments on commit ca8c196

Please sign in to comment.