Commit 39b107b5 authored by Jonas Šukys's avatar Jonas Šukys 💬

Improvements in fitscore computation and plotting.

parent f2a7e326
......@@ -1432,15 +1432,23 @@ class MatPlotLib (object):
if self.replicates:
pylab.title ('dataset %s' % name)
# L_lower = numpy.empty (len (self.indices))
# L_upper = numpy.empty (len (self.indices))
lower = numpy.empty (len (self.indices))
upper = numpy.empty (len (self.indices))
fitscore = numpy.empty (len (self.indices))
for index, batch in enumerate (self.indices):
if self.replicates:
fitscore [index] = numpy.nanmean ([self.infos [index] ['infos'] [chain] ['infos'] [name] ['fitscore'] for chain in range (self.chains) if self.infos [index] ['infos'] [chain] is not None])
likelihoods = [chaininfo ['evaluations'] [name] if chaininfo is not None else float ('nan') for chaininfo in self.infos [index] ['infos']]
chain = numpy.nanargmax (likelihoods)
fitscores = [chaininfo ['infos'] [name] ['fitscore'] if chaininfo is not None else float ('nan') for chaininfo in self.infos [index] ['infos']]
fitscore [index] = fitscores [chain]
else:
fitscore [index] = numpy.nanmean ([self.infos [index] ['infos'] [chain] ['fitscore'] for chain in range (self.chains) if self.infos [index] ['infos'] [chain] is not None])
likelihoods = self.infos [index] ['likelihoods']
chain = numpy.nanargmax (likelihoods)
fitscores = [chaininfo ['fitscore'] if chaininfo is not None else float ('nan') for chaininfo in self.infos [index] ['infos']]
fitscore [index] = fitscores [chain]
upper [index] = numpy.nanmax (fitscores)
lower [index] = numpy.nanmin (fitscores)
if self.replicates:
threshold = self.sampler.likelihood.likelihood.threshold
......@@ -1448,18 +1456,19 @@ class MatPlotLib (object):
threshold = self.sampler.likelihood.threshold
# if numpy.all (fitscore < 0):
pylab.semilogy (self.indices, -fitscore, linewidth=2, color=palette ['fitscore'], alpha=0.9)
pylab.ylabel ("negative fitscore")
pylab.axhline (-threshold, color='forestgreen', linestyle='--', lw=5, alpha=0.9)
if scientific:
pylab.gca().ticklabel_format (axis='x', style='sci', scilimits=(-2, 2))
# pylab.semilogy (self.indices, -fitscore, linewidth=2, color=palette ['fitscore'], alpha=0.9)
# pylab.ylabel ("negative fitscore")
# pylab.axhline (-threshold, color='forestgreen', linestyle='--', lw=5, alpha=0.9)
# if scientific:
# pylab.gca().ticklabel_format (axis='x', style='sci', scilimits=(-2, 2))
# else:
# pylab.plot (self.indices, fitscore, linewidth=2, color=palette ['fitscore'], alpha=0.9)
# pylab.ylabel ("fitscore")
# pylab.axhline (threshold, color='forestgreen', linestyle='--', lw=5, alpha=0.9)
# if scientific:
# pylab.gca().ticklabel_format (axis='both', style='sci', scilimits=(-2, 2))
self.line_and_range (self.indices, lower, fitscore, upper, merged=0, linewidth=2, color=palette ['fitscore'])
# pylab.plot (self.indices, fitscore, linewidth=2, color=palette ['fitscore'], alpha=0.9)
pylab.ylabel ("fitscore")
pylab.axhline (threshold, color='forestgreen', linestyle='--', lw=5, alpha=0.9)
if scientific:
pylab.gca().ticklabel_format (axis='both', style='sci', scilimits=(-2, 2))
pylab.xlabel("sample batch")
......@@ -1469,7 +1478,10 @@ class MatPlotLib (object):
caption = """\
Fitscores accross multiple concurrent chains of the sampler%(replicates)s.
Fitscore is the log of the average (over snapshots and particles)
normalized (with respect to maximum pdf and the dimensions of the observations) posterior errors.
normalized (with respect to maximum pdf value and the dimensions of the observations) posterior errors.
The solid line indicates the fitscore of the chain with the maximum likelihood estimate,
and the semi-transparent spreads indicate the minimum and the maximum fitscores
accross multiple concurrent chains of the sampler.
The dashed green line indicates the threshold set in the adaptive PF likelihood.
""" % args
self.save (figname (save, suffix="fitscores" + suffix), caption)
......
......@@ -144,10 +144,9 @@ class Sampler (object):
# for replicates likelihoods, return a dictionary with associated likelihood estimates across chains
if self.likelihood.name == 'Replicates':
likelihoods = {}
chaininfos = [chaininfo for chaininfo in info ["infos"] if chaininfo is not None]
names = self.likelihood.names
for name in names:
likelihoods [name] = [chaininfo ['evaluations'] [name] for chaininfo in chaininfos]
likelihoods [name] = [chaininfo ['evaluations'] [name] if chaininfo is not None else float ('nan') for chaininfo in info ["infos"]]
feedbacks = [likelihood.feedback (likelihoods) for likelihood in self.likelihoods]
args = {name : numpy.nanargmax (likelihoods [name]) for name in names}
feedback = {name : feedbacks [args [name]] [name] for name in names}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment