コード例 #1
0
ファイル: davidsensornet.py プロジェクト: epfl-lts2/pygsp
    def __init__(self, N=64, seed=None, **kwargs):

        self.seed = seed

        if N == 64:
            data = utils.loadmat('pointclouds/david64')
            assert data['N'][0, 0] == N
            W = data['W']
            coords = data['coords']

        elif N == 500:
            data = utils.loadmat('pointclouds/david500')
            assert data['N'][0, 0] == N
            W = data['W']
            coords = data['coords']

        else:
            coords = np.random.RandomState(seed).rand(N, 2)

            target_dist_cutoff = -0.125 * N / 436.075 + 0.2183
            T = 0.6
            s = np.sqrt(-target_dist_cutoff**2/(2*np.log(T)))
            d = utils.distanz(coords.T)
            W = np.exp(-np.power(d, 2)/(2.*s**2))
            W[W < T] = 0
            W[np.diag_indices(N)] = 0

        plotting = {"limits": [0, 1, 0, 1]}

        super(DavidSensorNet, self).__init__(W, coords=coords,
                                             plotting=plotting, **kwargs)
コード例 #2
0
ファイル: davidsensornet.py プロジェクト: zj15001/pygsp
    def __init__(self, N=64, seed=None, **kwargs):

        self.seed = seed

        if N == 64:
            data = utils.loadmat('pointclouds/david64')
            assert data['N'][0, 0] == N
            W = data['W']
            coords = data['coords']

        elif N == 500:
            data = utils.loadmat('pointclouds/david500')
            assert data['N'][0, 0] == N
            W = data['W']
            coords = data['coords']

        else:
            coords = np.random.RandomState(seed).rand(N, 2)

            target_dist_cutoff = -0.125 * N / 436.075 + 0.2183
            T = 0.6
            s = np.sqrt(-target_dist_cutoff**2 / (2 * np.log(T)))
            d = utils.distanz(coords.T)
            W = np.exp(-np.power(d, 2) / (2. * s**2))
            W[W < T] = 0
            W[np.diag_indices(N)] = 0

        plotting = {"limits": [0, 1, 0, 1]}

        super(DavidSensorNet, self).__init__(W,
                                             coords=coords,
                                             plotting=plotting,
                                             **kwargs)
コード例 #3
0
ファイル: davidsensornet.py プロジェクト: wangg12/pygsp
    def __init__(self, N=64):
        if N == 64:
            david64 = PointsCloud("david64")
            W = david64.W
            coords = david64.coords

        elif N == 500:
            david500 = PointsCloud("david500")
            W = david500.W
            coords = david500.coords

        else:
            coords = np.random.rand(N, 2)

            target_dist_cutoff = -0.125 * N / 436.075 + 0.2183
            T = 0.6
            s = np.sqrt(-target_dist_cutoff**2/(2*np.log(T)))
            d = distanz(coords.T)
            W = np.exp(-np.power(d, 2)/(2.*s**2))
            W[W < T] = 0
            W[np.diag_indices(N)] = 0

        plotting = {"limits": [0, 1, 0, 1]}

        super(DavidSensorNet, self).__init__(W=W, gtype='davidsensornet',
                                             coords=coords, plotting=plotting)
コード例 #4
0
    def __init__(self, N=400, a=1, b=4, dim=3, thresh=1e-6, s=None,
                 noise=False, srtype='uniform', seed=None, **kwargs):

        if s is None:
            s = np.sqrt(2. / N)

        self.a = a
        self.b = b
        self.dim = dim
        self.thresh = thresh
        self.s = s
        self.noise = noise
        self.srtype = srtype
        self.seed = seed

        rng = np.random.default_rng(seed)
        y1 = rng.uniform(size=N)
        y2 = rng.uniform(size=N)

        if srtype == 'uniform':
            tt = np.sqrt((b * b - a * a) * y1 + a * a)
        elif srtype == 'classic':
            tt = (b - a) * y1 + a
        tt *= np.pi

        if dim == 2:
            x = np.array((tt * np.cos(tt), tt * np.sin(tt)))
        elif dim == 3:
            x = np.array((tt * np.cos(tt), 21 * y2, tt * np.sin(tt)))

        if noise:
            x += rng.normal(size=x.shape)

        self.x = x
        self.dim = dim

        coords = utils.rescale_center(x)
        dist = utils.distanz(coords)
        W = np.exp(-np.power(dist, 2) / (2. * s**2))
        W -= np.diag(np.diag(W))
        W[W < thresh] = 0

        plotting = {
            'vertex_size': 60,
            'limits': np.array([-1, 1, -1, 1, -1, 1]),
            'elevation': 15,
            'azimuth': -90,
            'distance': 7,
        }

        super(SwissRoll, self).__init__(W, coords=coords.T,
                                        plotting=plotting,
                                        **kwargs)
コード例 #5
0
ファイル: swissroll.py プロジェクト: epfl-lts2/pygsp
    def __init__(self, N=400, a=1, b=4, dim=3, thresh=1e-6, s=None,
                 noise=False, srtype='uniform', seed=None, **kwargs):

        if s is None:
            s = np.sqrt(2. / N)

        self.a = a
        self.b = b
        self.dim = dim
        self.thresh = thresh
        self.s = s
        self.noise = noise
        self.srtype = srtype
        self.seed = seed

        rs = np.random.RandomState(seed)
        y1 = rs.rand(N)
        y2 = rs.rand(N)

        if srtype == 'uniform':
            tt = np.sqrt((b * b - a * a) * y1 + a * a)
        elif srtype == 'classic':
            tt = (b - a) * y1 + a
        tt *= np.pi

        if dim == 2:
            x = np.array((tt * np.cos(tt), tt * np.sin(tt)))
        elif dim == 3:
            x = np.array((tt * np.cos(tt), 21 * y2, tt * np.sin(tt)))

        if noise:
            x += rs.randn(*x.shape)

        self.x = x
        self.dim = dim

        coords = utils.rescale_center(x)
        dist = utils.distanz(coords)
        W = np.exp(-np.power(dist, 2) / (2. * s**2))
        W -= np.diag(np.diag(W))
        W[W < thresh] = 0

        plotting = {
            'vertex_size': 60,
            'limits': np.array([-1, 1, -1, 1, -1, 1]),
            'elevation': 15,
            'azimuth': -90,
            'distance': 7,
        }

        super(SwissRoll, self).__init__(W, coords=coords.T,
                                        plotting=plotting,
                                        **kwargs)
コード例 #6
0
    def __init__(self, N=400, a=1, b=4, dim=3, thresh=1e-6, s=None,
                 noise=False, srtype='uniform', seed=None, **kwargs):

        if s is None:
            s = np.sqrt(2. / N)

        rs = np.random.RandomState(seed)
        y1 = rs.rand(N)
        y2 = rs.rand(N)

        if srtype == 'uniform':
            tt = np.sqrt((b * b - a * a) * y1 + a * a)
        elif srtype == 'classic':
            tt = (b - a) * y1 + a
        tt *= np.pi

        if dim == 2:
            x = np.array((tt * np.cos(tt), tt * np.sin(tt)))
        elif dim == 3:
            x = np.array((tt * np.cos(tt), 21 * y2, tt * np.sin(tt)))

        if noise:
            x += rs.randn(*x.shape)

        self.x = x
        self.dim = dim

        coords = utils.rescale_center(x)
        dist = utils.distanz(coords)
        W = np.exp(-np.power(dist, 2) / (2. * s**2))
        W -= np.diag(np.diag(W))
        W[W < thresh] = 0

        plotting = {
            'vertex_size': 60,
            'limits': np.array([-1, 1, -1, 1, -1, 1]),
            'elevation': 15,
            'azimuth': -90,
            'distance': 7,
        }
        gtype = 'swiss roll {}'.format(srtype)

        super(SwissRoll, self).__init__(W=W, coords=coords.T,
                                        plotting=plotting, gtype=gtype,
                                        **kwargs)
コード例 #7
0
    def _create_weight_matrix(self, N, distributed, regular, param_Nc):
        XCoords = np.zeros((N, 1))
        YCoords = np.zeros((N, 1))

        rs = np.random.RandomState(self.seed)

        if distributed:
            mdim = int(np.ceil(np.sqrt(N)))
            for i in range(mdim):
                for j in range(mdim):
                    if i * mdim + j < N:
                        XCoords[i * mdim + j] = np.array(
                            (i + rs.rand()) / mdim)
                        YCoords[i * mdim + j] = np.array(
                            (j + rs.rand()) / mdim)

        # take random coordinates in a 1 by 1 square
        else:
            XCoords = rs.rand(N, 1)
            YCoords = rs.rand(N, 1)

        coords = np.concatenate((XCoords, YCoords), axis=1)

        # Compute the distanz between all the points
        target_dist_cutoff = 2 * N**(-0.5)
        T = 0.6
        s = np.sqrt(-target_dist_cutoff**2 / (2 * np.log(T)))
        d = utils.distanz(x=coords.T)
        W = np.exp(-d**2 / (2. * s**2))
        W -= np.diag(np.diag(W))

        if regular:
            W = self._get_nc_connection(W, param_Nc)

        else:
            W2 = self._get_nc_connection(W, param_Nc)
            W = np.where(W < T, 0, W)
            W = np.where(W2 > 0, W2, W)

        W = sparse.csc_matrix(W)
        return W, coords
コード例 #8
0
ファイル: swissroll.py プロジェクト: wangg12/pygsp
    def __init__(self, N=400, a=1, b=4, dim=3, thresh=1e-6, s=None,
                 noise=False, srtype='uniform'):

        if s is None:
            s = sqrt(2./N)

        y1 = np.random.rand(N)
        y2 = np.random.rand(N)

        if srtype == 'uniform':
            tt = np.sqrt((b * b - a * a) * y1 + a * a)
        elif srtype == 'classic':
            tt = (b - a) * y1 + a
        tt *= pi

        if dim == 2:
            x = np.array((tt*np.cos(tt), tt * np.sin(tt)))
        elif dim == 3:
            x = np.array((tt*np.cos(tt), 21 * y2, tt * np.sin(tt)))

        if noise:
            x += np.random.randn(*x.shape)

        self.x = x
        self.dim = dim

        dist = distanz(coords)
        W = np.exp(-np.power(dist, 2) / (2. * s**2))
        W -= np.diag(np.diag(W))
        W[W < thresh] = 0

        coords = self.rescale_center(x)
        plotting = {'limits': np.array([-1, 1, -1, 1, -1, 1])}
        gtype = 'swiss roll {}'.format(srtype)

        super(SwissRoll, self).__init__(W=W, coords=coords.T,
                                        plotting=plotting, gtype=gtype)
コード例 #9
0
ファイル: sensor.py プロジェクト: wangg12/pygsp
    def create_weight_matrix(self, N, param_distribute, param_regular, param_Nc):
        XCoords = np.zeros((N, 1))
        YCoords = np.zeros((N, 1))

        if param_distribute:
            mdim = int(ceil(sqrt(N)))
            for i in range(mdim):
                for j in range(mdim):
                    if i*mdim + j < N:
                        XCoords[i*mdim + j] = np.array((i + np.random.rand()) / mdim)
                        YCoords[i*mdim + j] = np.array((j + np.random.rand()) / mdim)

        # take random coordinates in a 1 by 1 square
        else:
            XCoords = np.random.rand(N, 1)
            YCoords = np.random.rand(N, 1)

        coords = np.concatenate((XCoords, YCoords), axis=1)

        # Compute the distanz between all the points
        target_dist_cutoff = 2*N**(-0.5)
        T = 0.6
        s = sqrt(-target_dist_cutoff**2/(2*log(T)))
        d = distanz(x=coords.T)
        W = np.exp(-d**2/(2.*s**2))
        W -= np.diag(np.diag(W))

        if param_regular:
            W = self.get_nc_connection(W, param_Nc)

        else:
            W2 = self.get_nc_connection(W, param_Nc)
            W = np.where(W < T, 0, W)
            W = np.where(W2 > 0, W2, W)

        W = sparse.csc_matrix(W)
        return W, coords
コード例 #10
0
 def test_distanz(x, y):
     # TODO test with matlab to compare
     self.assertEqual(utils.distanz(x, y))
コード例 #11
0
ファイル: test_utils.py プロジェクト: wangg12/pygsp
 def test_distanz(x, y):
     # TODO test with matlab to compare
     self.assertEqual(utils.distanz(x, y))