probing.py 598 Bytes
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1
import nifty4 as ift
Martin Reinecke's avatar
Martin Reinecke committed
2
import numpy as np
Theo Steininger's avatar
Theo Steininger committed
3

Martin Reinecke's avatar
Martin Reinecke committed
4
np.random.seed(42)
Theo Steininger's avatar
Theo Steininger committed
5

Martin Reinecke's avatar
Martin Reinecke committed
6

Martin Reinecke's avatar
Martin Reinecke committed
7
class DiagonalProber(ift.DiagonalProberMixin, ift.Prober):
Theo Steininger's avatar
Theo Steininger committed
8 9 10
    pass


Martin Reinecke's avatar
Martin Reinecke committed
11
class MultiProber(ift.DiagonalProberMixin, ift.TraceProberMixin, ift.Prober):
Theo Steininger's avatar
Theo Steininger committed
12 13 14
    pass


Martin Reinecke's avatar
Martin Reinecke committed
15
x = ift.RGSpace((8, 8))
Theo Steininger's avatar
Theo Steininger committed
16

Martin Reinecke's avatar
Martin Reinecke committed
17
f = ift.Field.from_random(domain=x, random_type='normal')
Martin Reinecke's avatar
Martin Reinecke committed
18
diagOp = ift.DiagonalOperator(f)
Theo Steininger's avatar
Theo Steininger committed
19 20 21

diagProber = DiagonalProber(domain=x)
diagProber(diagOp)
Martin Reinecke's avatar
Martin Reinecke committed
22
ift.dobj.mprint((f - diagProber.diagonal).norm())
Theo Steininger's avatar
Theo Steininger committed
23 24 25

multiProber = MultiProber(domain=x)
multiProber(diagOp)
Martin Reinecke's avatar
Martin Reinecke committed
26 27
ift.dobj.mprint((f - multiProber.diagonal).norm())
ift.dobj.mprint(f.sum() - multiProber.trace)