Example #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()