Skip to content

Commit 6e6c820

Browse files
committed
convert tutorials to Filter.filter
1 parent 2e63e58 commit 6e6c820

File tree

3 files changed

+20
-32
lines changed

3 files changed

+20
-32
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ This example demonstrates how to create a graph, a filter and analyse a signal o
3939
>>> from pygsp import graphs, filters
4040
>>> G = graphs.Logo()
4141
>>> f = filters.Heat(G)
42-
>>> Sl = f.analysis(G.L.todense(), method='chebyshev')
42+
>>> Sl = f.filter(G.L.todense(), method='chebyshev')
4343

4444
Features
4545
--------

doc/tutorials/intro.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ As in classical signal processing, the Fourier transform plays a central role
134134
in graph signal processing. Getting the Fourier basis is however
135135
computationally intensive as it needs to fully diagonalize the Laplacian. While
136136
it can be used to filter signals on graphs, a better alternative is to use one
137-
of the fast approximations (see :meth:`pygsp.filters.Filter.analysis`). Let's
137+
of the fast approximations (see :meth:`pygsp.filters.Filter.filter`). Let's
138138
compute it nonetheless to visualize the eigenvectors of the Laplacian.
139139
Analogous to classical Fourier analysis, they look like sinuses on the graph.
140140
Let's plot the second and third eigenvectors (the first is constant). Those are
@@ -225,7 +225,7 @@ low-pass filter.
225225
.. plot::
226226
:context: close-figs
227227

228-
>>> s2 = g.analysis(s)
228+
>>> s2 = g.filter(s)
229229
>>>
230230
>>> fig, axes = plt.subplots(1, 2, figsize=(10, 3))
231231
>>> G.plot_signal(s, vertex_size=30, ax=axes[0])

doc/tutorials/wavelet.rst

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ results using wavelets.
3333
:meth:`pygsp.graphs.Graph.compute_fourier_basis`, but this would take some
3434
time, and can be avoided with a Chebychev polynomials approximation to
3535
graph filtering. See the documentation of the
36-
:meth:`pygsp.filters.Filter.analysis` filtering function and
36+
:meth:`pygsp.filters.Filter.filter` filtering function and
3737
:cite:`hammond2011wavelets` for details on how it is down.
3838

3939
Simple filtering: heat diffusion
@@ -56,17 +56,16 @@ vertex 20. That signal is our heat source.
5656
:context: close-figs
5757

5858
>>> s = np.zeros(G.N)
59-
>>> delta = 20
60-
>>> s[delta] = 1
59+
>>> DELTA = 20
60+
>>> s[DELTA] = 1
6161

6262
We can now simulate heat diffusion by filtering our signal `s` with each of our
6363
heat kernels.
6464

6565
.. plot::
6666
:context: close-figs
6767

68-
>>> s = g.analysis(s, method='chebyshev')
69-
>>> s = utils.vec2mat(s, g.Nf)
68+
>>> s = g.filter(s, method='chebyshev')
7069

7170
And finally plot the filtered signal showing heat diffusion at different
7271
scales.
@@ -77,7 +76,7 @@ scales.
7776
>>> fig = plt.figure(figsize=(10, 3))
7877
>>> for i in range(g.Nf):
7978
... ax = fig.add_subplot(1, g.Nf, i+1, projection='3d')
80-
... G.plot_signal(s[:, i], vertex_size=20, colorbar=False, ax=ax)
79+
... G.plot_signal(s[:, 0, i], colorbar=False, ax=ax)
8180
... title = r'Heat diffusion, $\tau={}$'.format(taus[i])
8281
... ax.set_title(title) #doctest:+SKIP
8382
... ax.set_axis_off()
@@ -117,29 +116,19 @@ Then plot the frequency response of those filters.
117116
bank with :class:`pygsp.filters.WarpedTranslates` or by using another
118117
filter bank like :class:`pygsp.filters.Itersine`.
119118

120-
We can visualize the filtering by one atom as we did with the heat kernel, by
121-
filtering a Kronecker delta placed at one specific vertex.
119+
We can visualize the atoms as we did with the heat kernel, by filtering
120+
a Kronecker delta placed at one specific vertex.
122121

123122
.. plot::
124123
:context: close-figs
125124

126-
>>> s = np.zeros((G.N * g.Nf, g.Nf))
127-
>>> s[delta] = 1
128-
>>> for i in range(g.Nf):
129-
... s[delta + i * G.N, i] = 1
130-
>>> s = g.synthesis(s)
125+
>>> s = g.localize(DELTA)
131126
>>>
132-
>>> fig = plt.figure(figsize=(10, 7))
133-
>>> for i in range(4):
134-
...
135-
... # Clip the signal.
136-
... mu = np.mean(s[:, i])
137-
... sigma = np.std(s[:, i])
138-
... limits = [mu-4*sigma, mu+4*sigma]
139-
...
140-
... ax = fig.add_subplot(2, 2, i+1, projection='3d')
141-
... G.plot_signal(s[:, i], vertex_size=20, limits=limits, ax=ax)
142-
... ax.set_title('Wavelet {}'.format(i+1)) # doctest:+SKIP
127+
>>> fig = plt.figure(figsize=(10, 2.5))
128+
>>> for i in range(3):
129+
... ax = fig.add_subplot(1, 3, i+1, projection='3d')
130+
... G.plot_signal(s[:, 0, i], ax=ax)
131+
... ax.set_title('Wavelet {}'.format(i+1)) #doctest:+SKIP
143132
... ax.set_axis_off()
144133
>>> fig.tight_layout() # doctest:+SKIP
145134

@@ -160,16 +149,15 @@ which describes variation along the 3 coordinates.
160149
:context: close-figs
161150

162151
>>> s = G.coords
163-
>>> s = g.analysis(s)
164-
>>> s = utils.vec2mat(s, g.Nf)
152+
>>> s = g.filter(s)
165153

166154
The curvature is then estimated by taking the :math:`\ell_1` or :math:`\ell_2`
167-
norm of the filtered signal.
155+
norm across the 3D position.
168156

169157
.. plot::
170158
:context: close-figs
171159

172-
>>> s = np.linalg.norm(s, ord=2, axis=2)
160+
>>> s = np.linalg.norm(s, ord=2, axis=1)
173161

174162
Let's finally plot the result to observe that we indeed have a measure of the
175163
curvature at different scales.
@@ -180,7 +168,7 @@ curvature at different scales.
180168
>>> fig = plt.figure(figsize=(10, 7))
181169
>>> for i in range(4):
182170
... ax = fig.add_subplot(2, 2, i+1, projection='3d')
183-
... G.plot_signal(s[:, i], vertex_size=20, ax=ax)
171+
... G.plot_signal(s[:, i], ax=ax)
184172
... title = 'Curvature estimation (scale {})'.format(i+1)
185173
... ax.set_title(title) # doctest:+SKIP
186174
... ax.set_axis_off()

0 commit comments

Comments
 (0)