def UpdatePointLabel(self, mDataDict):
"""Updates the pointLabel point on screen with data contained in
mDataDict.
mDataDict will be passed to your function set by
SetPointLabelFunc. It can contain anything you
want to display on the screen at the scaledXY point
you specify.
This function can be called from parent window with onClick,
onMotion events etc.
"""
if self.last_PointLabel != None:
# compare pointXY
if np.sometrue(mDataDict["pointXY"] != self.last_PointLabel["pointXY"]):
# closest changed
self._drawPointLabel(self.last_PointLabel) # erase old
self._drawPointLabel(mDataDict) # plot new
else:
# just plot new with no erase
self._drawPointLabel(mDataDict) # plot new
# save for next erase
self.last_PointLabel = mDataDict
# event handlers **********************************
python类sometrue()的实例源码
def test_fail(self):
z = np.array([-1, 0, 1])
res = iscomplex(z)
assert_(not np.sometrue(res, axis=0))
def test_nd(self):
y1 = [[0, 0, 0], [0, 1, 0], [1, 1, 0]]
assert_(np.any(y1))
assert_array_equal(np.sometrue(y1, axis=0), [1, 1, 0])
assert_array_equal(np.sometrue(y1, axis=1), [0, 1, 1])
def test_fail(self):
z = np.array([-1, 0, 1])
res = iscomplex(z)
assert_(not np.sometrue(res, axis=0))
def test_nd(self):
y1 = [[0, 0, 0], [0, 1, 0], [1, 1, 0]]
assert_(np.any(y1))
assert_array_equal(np.sometrue(y1, axis=0), [1, 1, 0])
assert_array_equal(np.sometrue(y1, axis=1), [0, 1, 1])
def test_fail(self):
z = np.array([-1, 0, 1])
res = iscomplex(z)
assert_(not np.sometrue(res, axis=0))
def test_nd(self):
y1 = [[0, 0, 0], [0, 1, 0], [1, 1, 0]]
assert_(np.any(y1))
assert_array_equal(np.sometrue(y1, axis=0), [1, 1, 0])
assert_array_equal(np.sometrue(y1, axis=1), [0, 1, 1])
def test_fail(self):
z = np.array([-1, 0, 1])
res = iscomplex(z)
assert_(not np.sometrue(res, axis=0))
def test_nd(self):
y1 = [[0, 0, 0], [0, 1, 0], [1, 1, 0]]
assert_(np.any(y1))
assert_array_equal(np.sometrue(y1, axis=0), [1, 1, 0])
assert_array_equal(np.sometrue(y1, axis=1), [0, 1, 1])
def test_fail(self):
z = np.array([-1, 0, 1])
res = iscomplex(z)
assert_(not np.sometrue(res, axis=0))
def test_nd(self):
y1 = [[0, 0, 0], [0, 1, 0], [1, 1, 0]]
assert_(np.any(y1))
assert_array_equal(np.sometrue(y1, axis=0), [1, 1, 0])
assert_array_equal(np.sometrue(y1, axis=1), [0, 1, 1])
def test_fail(self):
z = np.array([-1, 0, 1])
res = iscomplex(z)
assert_(not np.sometrue(res, axis=0))
def test_nd(self):
y1 = [[0, 0, 0], [0, 1, 0], [1, 1, 0]]
assert_(np.any(y1))
assert_array_equal(np.sometrue(y1, axis=0), [1, 1, 0])
assert_array_equal(np.sometrue(y1, axis=1), [0, 1, 1])
def adjustHigherOrder(self, evidence, order, maximumDiscount):
def criterion(discount):
disc = tuple(num.maximum(0.0, discount))
sm = self.modelFactory.sequenceModel(evidence, disc)
ll = self.develSample.logLik(sm, self.shallUseMaximumApproximation)
crit = - ll \
- sum(num.minimum(discount, 0)) \
+ sum(num.maximum(discount - maximumDiscount, 0))
print discount, ll, crit # TESTING
return crit
initialGuess = self.discounts[-1]
firstDirection = None
if initialGuess is None:
initialGuess = 0.1 * num.arange(1, order+2, dtype=num.float64)
elif len(initialGuess) < order+1:
oldGuess = initialGuess
oldSize = len(initialGuess)
initialGuess = num.zeros(order+1, dtype=num.float64)
initialGuess[:oldSize] = oldGuess
initialGuess[oldSize:] = oldGuess[-1]
elif len(initialGuess) > order+1:
initialGuess = initialGuess[:order+1]
else:
previous = self.discounts[-2]
if previous is not None and len(previous) == order+1:
firstDirection = initialGuess - previous
if not num.sometrue(num.abs(firstDirection) > 1e-4):
firstDirection = None
directions = num.identity(order+1, dtype=num.float64)
directions = directions[::-1]
if firstDirection is not None:
directions = num.concatenate((firstDirection[num.newaxis,:], directions))
directions *= 0.1
print directions # TESTING
discount, ll = Minimization.directionSetMinimization(
criterion, initialGuess, directions, tolerance=1e-4)
discount = num.maximum(0.0, discount)
return discount, -ll