Esempio n. 1
0
    def test_random_matrix(self):
        data = np.trunc(5 + 10 * np.random.rand(10, 3))

        neighbors = 2
        epsilon = 5.
        to_dimension = 2

        d = Displayer(title="Isomap algorithms comparison") \
            .load(title="Canonical data set.", data=data)

        start = time()
        result = manifold.Isomap(neighbors, to_dimension).fit_transform(data)
        elapsed = time() - start

        d.load(title="SKLearn's Isomap with %i neighbors, taking %.1fs." % (neighbors, elapsed),
               data=result)

        start = time()
        result = algorithms.Isomap(nearest_method='e', e=epsilon, n_components=to_dimension) \
            .transform(data)
        elapsed = time() - start

        d.load(title="My E-Isomap with epsilon %i, taking %.1fs." % (epsilon, elapsed),
               data=result)

        start = time()
        result = algorithms.Isomap(k=neighbors, n_components=to_dimension) \
            .transform(data)
        elapsed = time() - start

        d.load(title="My K-Isomap with %i neighbors, taking %.1fs." % (neighbors, elapsed),
               data=result)

        d.show()
Esempio n. 2
0
    def test_swiss_roll(self):
        samples = 1000
        neighbors = 10
        n_components = 2

        data, c = datasets.make_swiss_roll(n_samples=samples, random_state=0)
        displayer = Displayer(title="Isomap algorithms comparison") \
            .load(title="Swiss roll from %i samples." % (samples,), data=data, color=c)

        start = time()
        result = manifold.Isomap(neighbors, n_components).fit_transform(data)
        elapsed = time() - start

        displayer \
            .load(
                title="SKLearn's Isomap with %i neighbors, taking %.1fs." % (neighbors, elapsed),
                data=result,
                color=c)

        start = time()
        result = Isomap(k=neighbors, n_components=n_components).transform(data)
        elapsed = time() - start

        displayer \
            .load(
                title="Isomap with %i neighbors, taking %.1fs" % (neighbors, elapsed),
                data=result,
                color=c)
        displayer.show()
Esempio n. 3
0
    def test_canonical_data(self):
        data = np.array([
            [0, 0, 0],
            [1, 0, 0],
            [1, 1, 0],
            [1, 1, 1],
        ])

        c = np.array([0, 0, 1, 1])

        neighbors = 2
        epsilon = 1.5
        to_dimension = 2

        d = Displayer(title="Isomap algorithms comparison") \
            .load(title="Canonical data set.", data=data, color=c)

        start = time()
        result = manifold.Isomap(neighbors, to_dimension).fit_transform(data)
        elapsed = time() - start

        d.load(title="SKLearn's Isomap with %i neighbors, taking %.1fs." % (neighbors, elapsed),
               data=result,
               color=c)

        start = time()
        result = algorithms.Isomap(nearest_method='e', e=epsilon, n_components=to_dimension) \
            .transform(data)
        elapsed = time() - start

        d.load(title="My E-Isomap with epsilon %i, taking %.1fs." % (epsilon, elapsed),
               data=result,
               color=c)

        start = time()
        result = algorithms.Isomap(k=neighbors, n_components=to_dimension) \
            .transform(data)
        elapsed = time() - start

        d.load(title="My K-Isomap with %i neighbors, taking %.1fs." % (neighbors, elapsed),
               data=result,
               color=c)

        d.show()
Esempio n. 4
0
    def test_swiss_roll(self):
        samples = 1000
        neighbors = 10
        epsilon = 5
        to_dimension = 2

        data, c = datasets.make_swiss_roll(n_samples=samples, random_state=0)
        displayer = Displayer(title="Isomap algorithms comparison") \
            .load(title="Swiss roll from %i samples." % (samples,), data=data, color=c)

        start = time()
        result = manifold.Isomap(neighbors, to_dimension,
                                 path_method='D').fit_transform(data)
        elapsed = time() - start

        displayer \
            .load(
                title="SKLearn's Isomap (%i neighbors, dijkstra, taking %.1fs)" % (neighbors, elapsed),
                data=result,
                color=c)

        start = time()
        result = manifold.Isomap(neighbors, to_dimension,
                                 path_method='FW').fit_transform(data)
        elapsed = time() - start

        displayer \
            .load(
                title="SKLearn's Isomap (%i neighbors, floyd-warshall, taking %.1fs)" % (neighbors, elapsed),
                data=result,
                color=c)

        start = time()
        result = algorithms \
            .Isomap(nearest_method='e', e=epsilon, n_components=to_dimension) \
            .transform(data)
        elapsed = time() - start

        displayer.load(title="E-Isomap (epsilon=%i, dijkstra, %.1fs)" %
                       (epsilon, elapsed),
                       data=result,
                       color=c)

        start = time()
        result = algorithms \
            .Isomap(nearest_method='e', shortest_path_method='fw', e=epsilon, n_components=to_dimension) \
            .transform(data)
        elapsed = time() - start

        displayer.load(title="E-Isomap (epsilon=%i, floyd-warshall, %.1fs)" %
                       (epsilon, elapsed),
                       data=result,
                       color=c)

        start = time()
        result = algorithms \
            .Isomap(k=neighbors, n_components=to_dimension) \
            .transform(data)
        elapsed = time() - start

        displayer.load(title="K-Isomap (%i neighbors, dijkstra, %.1fs)" %
                       (neighbors, elapsed),
                       data=result,
                       color=c)

        start = time()
        result = algorithms \
            .Isomap(k=neighbors, n_components=to_dimension, shortest_path_method='fw') \
            .transform(data)
        elapsed = time() - start

        displayer.load(title="K-Isomap (%i neighbors, floyd-warshall, %.1fs)" %
                       (neighbors, elapsed),
                       data=result,
                       color=c)

        displayer.show()