Commit d24cc30b authored by Martin Reinecke's avatar Martin Reinecke

more MPI fixes

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