2
# This file is part of TensorToolbox.
4
# TensorToolbox is free software: you can redistribute it and/or modify
5
# it under the terms of the LGNU Lesser General Public License as published by
6
# the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
9
# TensorToolbox is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# LGNU Lesser General Public License for more details.
14
# You should have received a copy of the LGNU Lesser General Public License
15
# along with TensorToolbox. If not, see <http://www.gnu.org/licenses/>.
18
# Copyright (C) 2014-2015 The Technical University of Denmark
19
# Scientific Computing Section
20
# Department of Applied Mathematics and Computer Science
22
# Author: Daniele Bigoni
26
# Construct two nested grids to exemplify the capabilities of the
32
import matplotlib.pyplot as plt
33
import TensorToolbox as TT
36
x_fine = np.linspace(-1,1,7)
40
return np.max(X) * params['k']
42
TW = TT.TensorWrapper( f, [ x_fine ]*d, params, dtype=float )
44
x_coarse = np.linspace(-1,1,4)
45
TW.set_view( 'coarse', [x_coarse]*d )
47
TW.set_active_view('full')
50
TW.set_active_view('coarse')
53
grid_coarse = np.array( list( itertools.product( *([x_coarse]*d) ) ) )
54
grid_fine = np.array( list( itertools.product( *([x_fine]*d) ) ) )
56
fill_idxs = np.array(TW.get_fill_idxs())
57
grid_fine_fill = np.vstack( [x_fine[fill_idxs[:,0]], x_fine[fill_idxs[:,1]]] ).T
58
grid_coarse_fill = np.array( [ grid_fine_fill[i,:] for i in xrange(TW.get_fill_level()) if (grid_fine_fill[i,0] in x_coarse and grid_fine_fill[i,1] in x_coarse) ] )
60
fig = plt.figure(figsize=(16,5))
61
ax = fig.add_subplot(131)
62
ax.plot( grid_fine[:,0], grid_fine[:,1], 'o', markeredgecolor='k', markeredgewidth=1.5, markerfacecolor='w', label='global' )
63
ax.plot( grid_fine_fill[:,0], grid_fine_fill[:,1], 'o', markeredgecolor='k', markeredgewidth=1.5, markerfacecolor='k', label='eval' )
67
ax = fig.add_subplot(132)
68
ax.plot( grid_fine[:,0], grid_fine[:,1], 'o', markeredgecolor='b', markeredgewidth=1.5, markerfacecolor='w', label='full')
69
ax.plot( grid_fine_fill[:,0], grid_fine_fill[:,1], 'o', markeredgecolor='k', markeredgewidth=1.5, markerfacecolor='k', label='eval' )
73
ax = fig.add_subplot(133)
74
ax.plot( grid_coarse[:,0], grid_coarse[:,1], 'o', markeredgecolor='r', markeredgewidth=1.5, markerfacecolor='w', label='coarse')
75
ax.plot( grid_coarse_fill[:,0], grid_coarse_fill[:,1], 'o', markeredgecolor='k', markeredgewidth=1.5, markerfacecolor='k', label='eval' )
83
# Quantics extension of the full view
85
TW.set_active_view('full')
87
plt.figure(figsize=(12,5))
89
plt.imshow(TW[:,:],interpolation='none')
90
plt.title('No extension')
92
TW.set_active_view('full')
96
plt.imshow(TW[:,:],interpolation='none')
97
plt.title('Quantics extension')
104
TW.set_active_view('full')
106
plt.figure(figsize=(12,4))
107
plt.imshow(TW[:,:], interpolation='none')
108
plt.title('Reshaped')
113
TW.reshape([2,2,2,2,2,2])