Exemplo n.º 1
0
        sigma2 = 50

    #Double Swiss Roll
    elif dataset == 'swiss':
        n_nbrs      = 3
        n_clusters  = 48
        n_labeled   = 24
        inner_dim   = 1
        gamma       = 1e-2
        n_data_per_anchor = 200
        # heuristics: keep m = O(n/d)
        algs = ["ap", "ac", "nn", "pvm", "apg"]
        sigma2 = 1

    data = {
            "swiss"  : manifold_generator.double_swiss_roll(n_samples=1000,  var=.8),
            "usps"   : manifold_generator.usps(),
            "letter" : manifold_generator.letter(),
            "mnist"  : manifold_generator.mnist()
            }

    model = {
            "ap" : (
                anchor_points.AnchorPoints(n_clusters, n_nbrs),
                (gamma, )),
            "ac" : (
                anchor_clouds.AnchorClouds(inner_dim, n_clusters, n_data_per_anchor, n_nbrs),
                (gamma, )),
            "nn" : (
                nearest_neighbors.NearestNeighbors(k=1),
                ()),
Exemplo n.º 2
0
        s2 = s**2

        # initialize ppca parameters
        self.sigma2 = ( np.linalg.norm(U, 'fro')**2/m - s2.sum() ) / (p - self.inner_dim)
        self.a = a

        self.W = Phi * np.sqrt(s2 - self.sigma2) 
        self.det_sqrt = np.prod(np.sqrt(s2 + self.sigma2))

        try:
            self.M = np.linalg.inv(self.W.T.dot(self.W) + self.sigma2*np.eye(self.inner_dim))
        except np.linalg.LinAlgError:
            print "singular anchor"

    def log_ppca_density(self, x):
        u = x - self.a
        Wtu = self.W.T.dot(u)
        return -0.5*(u.dot(u) - Wtu.T.dot(self.M).dot(Wtu))/self.sigma2 - np.log(self.det_sqrt)

if __name__ == '__main__':
    np.random.seed(1267)

    n_anchors = 32
    n_data_per_anchor = 20
    n_anchor_per_data = 3
    inner_dim = 1
    X, _, _ = manifold_generator.double_swiss_roll(n_samples=300, var=.75)
    A, Z = anchor_clouds(X, 1, n_anchors, n_data_per_anchor, n_anchor_per_data)

    tools.visualize_edges(X, A, Z, 1e-12)