Exemple #1
0
    def test_write_on_file(self):
        K = 10

        # Output population
        pp = get_population()
        fout = open('pp.csv', 'w')
        fout.write('x,y,label\n')
        for x, y in pp:
            fout.write('%f,%f,k\n' % (x, y))
        fout.close()

        # Output MDS samples
        lin = Linear(self.dist_func, K = K)
        lin.update(pp)
        sampled = lin.get_sampled()
        fout = open('mcs.csv', 'w')
        fout.write('x,y,label\n')
        for x, y in sampled:
            fout.write('%f,%f,b\n' % (x, y))
        fout.close()

        # Output random samples
        random.seed(1)
        sampled = random.sample(pp, K)
        fout = open('random.csv', 'w')
        fout.write('x,y,label\n')
        for x, y in sampled:
            fout.write('%f,%f,g\n' % (x, y))
        fout.close()

        # Ouptut k means samples
        kmedoids = KMedoids(self.dist_func, K)
        sampled = kmedoids.sample(pp)
        fout = open('kmedoids.csv', 'w')
        fout.write('x,y,label\n')
        for x, y in sampled:
            fout.write('%f,%f,r\n' % (x, y))
        fout.close()
Exemple #2
0
    def _test_linear(self):
        K = 10

        pp = get_population()
        lin = Linear(self.dist_func, K = K)
        for i in range(1):
            lin.update(pp)

        x, y = zip(*pp)
        plt.scatter(x, y, s=1, c='b')

        sampled = lin.get_sampled()
        x, y = zip(*sampled)
        plt.scatter(x, y, s=3000, c='r', alpha=0.2)

        #x, y = zip(*random.sample(pp, K))
        #plt.scatter(x, y, s=3000, c='g', alpha=0.2)

        #kmedoids = KMedoids(self.dist_func, K)
        #x, y = zip(*kmedoids.sample(pp))
        #plt.scatter(x, y, s=3000, c='b', alpha=0.2)

        plt.show()