probing.py 651 Bytes
Newer Older
Theo Steininger's avatar
Theo Steininger committed
1
2
# -*- coding: utf-8 -*-

Martin Reinecke's avatar
Martin Reinecke committed
3
from __future__ import print_function
Martin Reinecke's avatar
Martin Reinecke committed
4
5
import nifty2go as ift
import numpy as np
Theo Steininger's avatar
Theo Steininger committed
6

Martin Reinecke's avatar
Martin Reinecke committed
7
np.random.seed(42)
Theo Steininger's avatar
Theo Steininger committed
8

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


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


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

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

diagProber = DiagonalProber(domain=x)
diagProber(diagOp)
Martin Reinecke's avatar
Martin Reinecke committed
24
print((f - diagProber.diagonal).norm())
Theo Steininger's avatar
Theo Steininger committed
25
26
27

multiProber = MultiProber(domain=x)
multiProber(diagOp)
Martin Reinecke's avatar
Martin Reinecke committed
28
29
print((f - multiProber.diagonal).norm())
print(f.sum() - multiProber.trace)