spkit.graph_filter_adj

spkit.graph_filter_adj(X, AdjM, V=None, ftype='mean', exclude_self=False, sort_with_dist=False, default_value=nan)

Graph Filtering with Adjacency Matrix

Graph Filtering with Adjacency Matrix

A value of a vertice (node) is refined by value of connect vertices (nodes) defined in Adjacency Matrix

The refinement could be - mean, media, standard deviation or any custom operation passed to function as ftype Commonly a filter operation could be permutation invariant, such as np.mean, np.median, np.std, However for custom operation passed as function ftype, values can be passed in sorted order by turning sort_with_dist=True

Parameters:
X: 1d-array (n,)
  • values of vertices iof graph

AdjM: array - shape (n,n), binary [0,1]
  • Adjacency Matrix with 0s and 1s

  • 0 mena not connected, 1 means connected

V: array - shape (n,d), default=None
  • location of vertices in d-dimensional sapce

  • for 3D Geomartry, (n,3)

  • used if sort_with_dist is True

ftype: str, or Callable, default=’mean’
  • filter operation, {‘mean’,’median’,’std’,’min’,’max’} or any numpy operation as str = ‘np.newfun’

  • using ‘mean’ , value of vertices is refined with average of neibours defined by distance d.

  • if ftype is callable, make sure it return single value given neigbours values

exclude_self: bool, default=False,
  • if True, while refining/filtering the value of the vertice, value of itself if excluded.

default_value: float, default=np.nan
  • default value to start with.

  • In case of no neibours and excluding itself, vertices will have this value.

sort_with_dist:bool, default=False
  • if True, values passed to filter are sorted in order of smallest distance to largest

  • in case of permutation variant filter, this could be used.

  • it adds extra computations, so turn it off, if not useful.

Returns:
Y: 1d-array of same size as X
  • refined/filtered values

See also

spkit

Home

Notes

  • This function ..

Examples

#sp.graph_filter_adj
import numpy as np
import matplotlib.pyplot as plt
import spkit as sp

V = sp.geometry.get_ellipsoid(n1=50, n2=50, rx=1, ry=2, rz=1,)
V += 0.01*np.random.randn(V.shape[0],V.shape[1])

X = sp.create_signal_1d(V.shape[0],bipolar=False,sg_winlen=21,sg_polyorder=2,seed=1)
X += 0.1*np.random.randn(X.shape[0]) 

AdjM1, _  = sp.geometry.get_adjacency_matrix_kNN(V, K=5)
AdjM2, _  = sp.geometry.get_adjacency_matrix_kNN(V, K=21)
AdjM3, _  = sp.geometry.get_adjacency_matrix_kNN(V, K=31)

Y1 = sp.graph_filter_adj(X,AdjM1,ftype='mean',exclude_self=False)
Y2 = sp.graph_filter_adj(X,AdjM2,ftype='mean',exclude_self=False)
Y3 = sp.graph_filter_adj(X,AdjM3,ftype='mean',exclude_self=False)

fig, ax = plt.subplots(1,4,subplot_kw={"projection": "3d"},figsize=(15,7))

Ys =[X, Y1, Y2, Y3]
TITLEs = ['raw', r'$K=5$',r'$K=21$', r'$K=31$']
for i in range(4):
    ax[i].scatter3D(V[:,0], V[:,1], V[:,2], c=Ys[i], cmap='jet',s=10)
    ax[i].axis('off')
    ax[i].view_init(elev=60, azim=45, roll=15)
    ax[i].set_xlim([-1,1])
    ax[i].set_ylim([-2,2])
    ax[i].set_zlim([-1,1])
    ax[i].set_title(TITLEs[i])

plt.subplots_adjust(hspace=0,wspace=0)
plt.show()
../../_images/spkit-graph_filter_adj-1.png