~daniele-bigoni/tensortoolbox/tt-docs

« back to all changes in this revision

Viewing changes to Development/Examples/ReweightedTT/test2D.py

  • Committer: Daniele Bigoni
  • Date: 2015-01-19 11:10:20 UTC
  • Revision ID: dabi@dtu.dk-20150119111020-p0uckg4ab3xqzf47
merged with research

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
# and run the Quantics TTdmrg to approximate the constant function f=1
10
10
# w.r.t. the measure
11
11
 
12
 
N = 15 # Power of 2 for now
 
12
STORE_FIG = True
 
13
FORMATS = ['pdf','png','eps']
 
14
 
 
15
N = 31 # Power of 2 for now
13
16
P = S1D.Poly1D(S1D.HERMITEP_PROB,None)
14
17
(x,w) = P.Quadrature(N)
15
18
 
16
19
W = np.outer(w,w)
17
 
# def f(x): return 1.
18
 
def f(x): return 1000. * np.exp(-npla.norm(x-5.)/(2*0.1**2.) )
 
20
def f(x): return 1.
 
21
# def f(x): return 1. + 1. * np.exp(-npla.norm(x-2.)/(2*1.**2.) )
 
22
# def f(x): return (x[0]-5.)**2. + (x[1]-5.)**2.
19
23
 
20
24
 
21
25
def fW(X,params): 
31
35
              surrogateONOFF=True, surrogate_type=TT.PROJECTION, orders=[N]*2)
32
36
WTT.build()
33
37
 
34
 
print "Fill level: %d/%d" % (WTT.TW.get_fill_level(), N**2)
 
38
FTT = TT.SQTT(fW, grids, params, marshal_f=False,
 
39
              eps=1e-8,
 
40
              surrogateONOFF=True, surrogate_type=TT.PROJECTION, orders=[N]*2)
 
41
FTT.build()
 
42
 
 
43
print "Fill level fW: %d/%d" % (WTT.TW.get_fill_level(), (N+1)**2)
 
44
print "Fill level f: %d/%d" % (FTT.TW.get_fill_level(), (N+1)**2)
35
45
 
36
46
fill_idxs = np.array(WTT.TW.get_fill_idxs())
37
47
plt.figure()
38
48
plt.scatter(x[fill_idxs[:,0]],x[fill_idxs[:,1]])
39
 
plt.title("Filled idxs")
 
49
plt.title("Filled idxs - fW")
40
50
plt.show(block=False)
41
51
 
42
52
used_idxs = WTT.generic_approx[0].get_ttdmrg_eval_idxs()
43
53
plt.figure()
44
54
plt.scatter(x[used_idxs[:,0]],x[used_idxs[:,1]],c='r')
45
 
plt.title("Final idxs")
 
55
plt.title("Final idxs - fW")
 
56
plt.show(block=False)
 
57
 
 
58
fill_idxs = np.array(FTT.TW.get_fill_idxs())
 
59
plt.figure()
 
60
plt.scatter(x[fill_idxs[:,0]],x[fill_idxs[:,1]])
 
61
plt.title("Filled idxs - f")
 
62
plt.show(block=False)
 
63
 
 
64
used_idxs = FTT.generic_approx[0].get_ttdmrg_eval_idxs()
 
65
plt.figure()
 
66
plt.scatter(x[used_idxs[:,0]],x[used_idxs[:,1]],c='r')
 
67
plt.title("Final idxs - f")
46
68
plt.show(block=False)
47
69
 
48
70
F = np.zeros((N+1,N+1))
57
79
X,Y = np.meshgrid(x,x)
58
80
 
59
81
plt.figure()
60
 
plt.contourf(X,Y,F)
 
82
plt.contourf(X,Y,F,30)
61
83
plt.title("f")
62
84
plt.colorbar()
63
85
plt.show(block=False)
64
86
 
65
87
plt.figure()
66
 
plt.contourf(X,Y,FW)
 
88
plt.contourf(X,Y,FW,30)
67
89
plt.title("fW")
68
90
plt.colorbar()
69
91
plt.show(block=False)
70
92
 
71
 
plt.figure()
72
 
plt.contourf(X,Y,np.log10(F))
73
 
plt.title("log10(f)")
74
 
plt.colorbar()
75
 
plt.show(block=False)
 
93
# plt.figure()
 
94
# plt.contourf(X,Y,np.log10(F))
 
95
# plt.title("log10(f)")
 
96
# plt.colorbar()
 
97
# plt.show(block=False)
76
98
 
77
 
plt.figure()
78
 
plt.contourf(X,Y,np.log10(FW))
79
 
plt.title("log10(fW)")
80
 
plt.colorbar()
81
 
plt.show(block=False)
 
99
# plt.figure()
 
100
# plt.contourf(X,Y,np.log10(FW))
 
101
# plt.title("log10(fW)")
 
102
# plt.colorbar()
 
103
# plt.show(block=False)