25import matplotlib.colors
26from mpl_toolkits.axes_grid1
import make_axes_locatable
28from .densityPlot
import hide_xticklabels, hide_yticklabels
29from ..
import modelfitLib
31__all__ = (
"OptimizerDisplay", )
40 self.
gridgrid = parent.unitGrid * sample.get(parent.recorder.trust)
42 self.
gridgrid += sample.get(parent.recorder.parameters).reshape((1,)*parent.ndim + (parent.ndim,))
49 return self.
samplesample.get(getattr(self.
parentparent.recorder, name))
55 self.
parentparent.objective.fillObjectiveValueGrid(self.
gridgrid.reshape(-1, self.
parentparent.ndim),
65 self.
parentparent.recorder.fillObjectiveModelGrid(self.
samplesample,
66 self.
gridgrid.reshape(-1, self.
parentparent.ndim),
73 def __init__(self, history, model, objective, steps=11):
74 self.
recorderrecorder = modelfitLib.OptimizerHistoryRecorder(history.schema)
84 mgridArgs = (slice(-1.0, 1.0, steps*1j),) * self.
ndimndim
86 transposeArgs = tuple(
list(range(1, self.
ndimndim+1)) + [0])
87 self.
unitGridunitGrid = numpy.mgrid[mgridArgs].transpose(transposeArgs).copy()
89 for sample
in history:
90 if sample.get(self.
recorderrecorder.state) & modelfitLib.Optimizer.STATUS_STEP_REJECTED:
91 assert current
is not None
92 current.rejected.append(sample)
97 def plot(self, xDim, yDim, n=0):
114 self.
slice2dslice2d[self.
ii] = slice(
None)
115 self.
slice2dslice2d[self.
jj] = slice(
None)
117 self.
sliceXsliceX = [s//2
for s
in self.
parentparent.unitGrid.shape[:-1]]
118 self.
sliceXsliceX[self.
jj] = slice(
None)
120 self.
sliceYsliceY = [s//2
for s
in self.
parentparent.unitGrid.shape[:-1]]
121 self.
sliceYsliceY[self.
ii] = slice(
None)
124 x=numpy.array([iteration.sample.get(self.
xKeyxKey)
for iteration
in self.
parentparent.track]),
125 y=numpy.array([iteration.sample.get(self.
yKeyyKey)
for iteration
in self.
parentparent.track]),
126 z=numpy.array([iteration.sample.get(self.
zKeyzKey)
for iteration
in self.
parentparent.track]),
129 self.
figurefigure = matplotlib.pyplot.figure(f
"{xDim} vs {yDim}", figsize=(16, 8))
130 self.
figurefigure.subplots_adjust(left=0.025, right=0.975, bottom=0.08, top=0.95, wspace=0.12)
131 self.
axes3daxes3d = self.
figurefigure.add_subplot(1, 2, 1, projection=
'3d')
132 self.
axes3daxes3d.autoscale(
False)
138 self.
axes2daxes2d.autoscale(
False)
139 divider = make_axes_locatable(self.
axes2daxes2d)
140 self.
axesXaxesX = divider.append_axes(
"top", 1.5, pad=0.1, sharex=self.
axes2daxes2d)
141 self.
axesXaxesX.autoscale(
False, axis=
'x')
143 self.
axesYaxesY = divider.append_axes(
"right", 1.5, pad=0.1, sharey=self.
axes2daxes2d)
144 self.
axesYaxesY.autoscale(
False, axis=
'y')
158 return self.
_extent_extent[2:4]
165 current = self.
parentparent.track[self.
nn]
166 x = current.sample.get(self.
xKeyxKey)
167 y = current.sample.get(self.
yKeyyKey)
168 zMin1 = current.objectiveValues[self.
slice2dslice2d].
min()
169 zMax1 = current.objectiveValues[self.
slice2dslice2d].
max()
170 zMin2 = current.objectiveModel[self.
slice2dslice2d].
min()
171 zMax2 = current.objectiveModel[self.
slice2dslice2d].
max()
172 self.
setExtentsetExtent(x0=x - current.trust, x1=x + current.trust,
173 y0=y - current.trust, y1=y + current.trust,
174 z0=
min(zMin1, zMin2), z1=
max(zMax1, zMax2), lock=
False)
176 def setExtent(self, x0=None, x1=None, y0=None, y1=None, z0=None, z1=None, lock=True):
189 self.
_extent_extent = (x0, x1, y0, y1, z0, z1)
190 self.
_lock_lock = lock
199 def _clipZ(self, x, y, z):
202 mask = numpy.logical_or.reduce([x < self.
xlimxlim[0], x > self.
xlimxlim[1],
203 y < self.
ylimylim[0], y > self.
ylimylim[1],
204 z < self.
zlimzlim[0], z > self.
zlimzlim[1]],
208 return numpy.logical_not(mask).astype(int).sum() > 4
211 def _contour(self, axes, *args, **kwds):
212 self.
artistsartists.extend(axes.contour(*args, **kwds).collections)
215 kwds = dict(markeredgewidth=0, markerfacecolor=
'g', color=
'g', marker=
'o')
222 kwds = dict(markeredgewidth=0, markerfacecolor=
'r', color=
'r', marker=
'v')
223 current = self.
parentparent.track[self.
nn]
224 cx = current.sample.get(self.
xKeyxKey)
225 cy = current.sample.get(self.
yKeyyKey)
226 cz = current.sample.get(self.
zKeyzKey)
227 for r
in current.rejected:
228 x = [cx, r.get(self.
xKeyxKey)]
229 y = [cy, r.get(self.
yKeyyKey)]
230 z = [cz, r.get(self.
zKeyzKey)]
237 current = self.
parentparent.track[self.
nn]
240 x = current.grid[self.
slice2dslice2d + (self.
jj,)]
241 y = current.grid[self.
slice2dslice2d + (self.
ii,)]
242 z1 = current.objectiveValues[self.
slice2dslice2d].copy()
243 z2 = current.objectiveModel[self.
slice2dslice2d].copy()
244 norm = matplotlib.colors.Normalize(vmin=self.
zlimzlim[0], vmax=self.
zlimzlim[1])
246 self.
_contour_contour(self.
axes2daxes2d, x, y, z1, cmap=matplotlib.cm.spring, norm=norm)
247 self.
_contour_contour(self.
axes2daxes2d, x, y, z2, cmap=matplotlib.cm.winter, norm=norm)
250 if self.
_clipZ_clipZ(x, y, z1):
251 self.
_contour_contour(self.
axes3daxes3d, x, y, z1, cmap=matplotlib.cm.spring, norm=norm)
253 cmap=matplotlib.cm.spring, norm=norm,
254 linewidth=0, antialiased=1, alpha=0.5))
255 if self.
_clipZ_clipZ(x, y, z2):
256 self.
_contour_contour(self.
axes3daxes3d, x, y, z2, cmap=matplotlib.cm.winter, norm=norm)
258 cmap=matplotlib.cm.winter, norm=norm,
259 linewidth=0, antialiased=1, alpha=0.5))
263 current.objectiveValues[self.
sliceXsliceX],
'm-'))
265 current.objectiveModel[self.
sliceXsliceX],
'c-'))
267 current.grid[self.
sliceYsliceY + (self.
ii,)],
'm-'))
269 current.grid[self.
sliceYsliceY + (self.
ii,)],
'c-'))
273 if not self.
_lock_lock:
275 for artist
in self.
artistsartists:
284 self.
figurefigure.canvas.draw()
def __init__(self, history, model, objective, steps=11)
def plot(self, xDim, yDim, n=0)
def objectiveValues(self)
def __getattr__(self, name)
def __init__(self, parent, sample)
daf::base::PropertyList * list
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
def plot(mag, width, centers, clusterId, marker="o", markersize=2, markeredgewidth=0, ltype='-', magType="model", clear=True)
def hide_xticklabels(axes)
def hide_yticklabels(axes)