Commit d24cc30b authored by Martin Reinecke's avatar Martin Reinecke

more MPI fixes

parent ab8ac790
...@@ -14,7 +14,7 @@ def make_chess_mask(): ...@@ -14,7 +14,7 @@ def make_chess_mask():
def make_random_mask(): def make_random_mask():
mask = ift.from_random('pm1', position_space) mask = ift.from_random('pm1', position_space)
mask = (mask+1)/2 mask = (mask+1)/2
return mask.val return mask.to_global_data()
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -21,40 +21,40 @@ class PointSources(Model): ...@@ -21,40 +21,40 @@ class PointSources(Model):
@property @property
@memo @memo
def value(self): def value(self):
points = self.position['points'].to_global_data() points = self.position['points'].local_data
points = np.clip(points, None, 8.2) points = np.clip(points, None, 8.2)
points = Field(self.position['points'].domain, points) points = Field.from_local_data(self.position['points'].domain, points)
return self.IG(points, self._alpha, self._q) return self.IG(points, self._alpha, self._q)
@property @property
@memo @memo
def gradient(self): def gradient(self):
u = self.position['points'] u = self.position['points'].local_data
inner = norm.pdf(u.val) inner = norm.pdf(u)
outer_inv = invgamma.pdf(invgamma.ppf(norm.cdf(u.val), outer_inv = invgamma.pdf(invgamma.ppf(norm.cdf(u),
self._alpha, self._alpha,
scale=self._q), scale=self._q),
self._alpha, scale=self._q) self._alpha, scale=self._q)
# FIXME # FIXME
outer_inv = np.clip(outer_inv, 1e-20, None) outer_inv = np.clip(outer_inv, 1e-20, None)
outer = 1/outer_inv outer = 1/outer_inv
grad = Field(u.domain, val=inner*outer) grad = Field.from_local_data(u.domain, inner*outer)
grad = makeOp(MultiField({'points': grad})) grad = makeOp(MultiField({'points': grad}))
return SelectionOperator(grad.target, 'points')*grad return SelectionOperator(grad.target, 'points')*grad
@staticmethod @staticmethod
def IG(field, alpha, q): def IG(field, alpha, q):
foo = invgamma.ppf(norm.cdf(field.val), alpha, scale=q) foo = invgamma.ppf(norm.cdf(field.local_data), alpha, scale=q)
return Field(field.domain, val=foo) return Field.from_local_data(field.domain, foo)
@staticmethod @staticmethod
def IG_prime(field, alpha, q): def IG_prime(field, alpha, q):
inner = norm.pdf(field.val) inner = norm.pdf(field.local_data)
outer = invgamma.pdf(invgamma.ppf(norm.cdf(field.val), alpha, scale=q), alpha, scale=q) outer = invgamma.pdf(invgamma.ppf(norm.cdf(field.local_data), alpha, scale=q), alpha, scale=q)
# # FIXME # # FIXME
# outer = np.clip(outer, 1e-20, None) # outer = np.clip(outer, 1e-20, None)
outer = 1/outer outer = 1/outer
return Field(field.domain, val=inner*outer) return Field.from_local_data(field.domain, inner*outer)
@staticmethod @staticmethod
def inverseIG(u, alpha, q): def inverseIG(u, alpha, q):
......
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