Ejemplo n.º 1
0
 def BTdot(self, uin):
     """Compute B^T.uin as a np.array
     uin must be a np.array"""
     isarray(uin)
     u = Function(self.V)
     out = u.vector()
     for ii, bb in enumerate(self.B):
         out += bb*uin[ii]
     return out.array()
Ejemplo n.º 2
0
 def apply_noise(self, uin):
     """Apply Gaussian noise to np.array of data.
     noisepercent = 0.02 => 2% noise level, i.e.,
     || u - ud || / || ud || = || noise || / || ud || = 0.02"""
     isarray(uin)
     noisevect = randn(len(uin))
     # Get norm of entire random vector:
     if self.mycomm == None: normrand = norm(noisevect)
     else:
         normrand = sqrt(MPI.sum(self.mycomm, norm(noisevect)**2))
     noisevect /= normrand
     # Get norm of entire vector ud (not just local part):
     if self.mycomm == None: normud = norm(uin)
     else:
         normud = sqrt(MPI.sum(self.mycomm, norm(uin)**2))
     noisevect *= self.noisepercent * normud
     objnoise_glob = (self.noisepercent * normud)**2
     UDnoise = uin + noisevect
     return UDnoise, objnoise_glob
Ejemplo n.º 3
0
 def BTdotvec(self, uin, outvect):
     """ Compute B^T.uin """
     isarray(uin)
     outvect.zero()
     for ii, bb in enumerate(self.B):
         outvect += bb*uin[ii]