File: uncertainty_view.py

package info (click to toggle)
python-bumps 0.7.11-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,264 kB
  • sloc: python: 22,226; ansic: 4,973; cpp: 4,849; xml: 493; makefile: 163; perl: 108; sh: 101
file content (101 lines) | stat: -rw-r--r-- 2,681 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from __future__ import with_statement

from ..dream import views as dream_views
from ..dream import stats as dream_stats
from .. import errplot
from .plot_view import PlotView


class UncertaintyView(PlotView):
    title = "Uncertainty"

    def plot(self):
        if not self.plot_state:
            return
        history, stats = self.plot_state
        with self.pylab_interface as pylab:
            pylab.clf()
            dream_views.plot_vars(history.draw(), stats)
            pylab.draw()

    def update(self, state):
        self.plot_state = state
        self.plot()

    def OnFitProgress(self, event):
        if event.problem != self.model:
            return
        history = event.uncertainty_state
        stats = dream_stats.var_stats(history.draw())
        self.update((history,stats))


class CorrelationView(PlotView):
    title = "Correlations"

    def plot(self):
        if not self.plot_state:
            return
        # suppress correlation plot if too many variables
        if self.plot_state.Nvar > 15:
            return
        history = self.plot_state
        with self.pylab_interface as pylab:
            pylab.clf()
            dream_views.plot_corrmatrix(history.draw())
            pylab.draw()

    def update(self, state):
        self.plot_state = state
        self.plot()

    def OnFitProgress(self, event):
        if event.problem != self.model:
            return
        self.update(event.uncertainty_state)


class TraceView(PlotView):
    title = "Parameter Trace"

    def plot(self):
        if not self.plot_state:
            return
        history = self.plot_state
        with self.pylab_interface as pylab:
            pylab.clf()
            dream_views.plot_trace(history)
            pylab.draw()

    def update(self, state):
        self.plot_state = state
        self.plot()

    def OnFitProgress(self, event):
        if event.problem != self.model:
            return
        self.plot_state = event.uncertainty_state
        self.plot()


class ModelErrorView(PlotView):
    title = "Model Uncertainty"

    def plot(self):
        if not self.plot_state:
            return
        with self.pylab_interface as pylab:
            pylab.clf()
            # Won't get here if plot_state is None
            errplot.show_errors(self.plot_state)
            pylab.draw()

    def OnFitProgress(self, event):
        if event.problem != self.model:
            return
        self.update(event.problem, event.uncertainty_state)

    def update(self, problem, state):
        # Should happen in a separate process
        self.plot_state = errplot.calc_errors_from_state(problem, state)
        self.plot()