File: uncertainty_view.py

package info (click to toggle)
python-bumps 0.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 10,688 kB
  • sloc: python: 24,446; ansic: 4,973; cpp: 4,849; javascript: 639; xml: 493; makefile: 147; perl: 108; sh: 94
file content (100 lines) | stat: -rw-r--r-- 2,688 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
from __future__ import with_statement

from ..dream import views as dream_views
from ..dream import stats as dream_stats
from ..dream import varplot as dream_varplot
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_varplot.plot_vars(history.draw(), stats)
            pylab.draw()

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

    def fit_progress(self, problem, uncertainty_state, stats):
        if problem != self.model:
            return
        self.update((uncertainty_state, 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 fit_progress(self, problem, uncertainty_state):
        if problem != self.model:
            return
        self.update(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 fit_progress(self, problem, uncertainty_state):
        if problem != self.model:
            return
        self.plot_state = 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 update(self, problem, state):
        # TODO: Should happen in a separate process
        self.plot_state = errplot.calc_errors_from_state(problem, state)
        self.plot()

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