def write_current_matrix():
     f = open("%s/%s_%03d.v" % (temporary_directory(), self._debug_matrix_file, step), "w")
     x = v.reshape(len(self._p1.modules), len(self._p2.modules))
     for i in xrange(len(self._p1.modules)):
         for j in xrange(len(self._p2.modules)):
             f.write("%f " % x[i, j])
         f.write("\n")
     f.close()
Example #2
0
 def test_write_and_read_vistrail(self):
     self.assertTrue(get_api().new_vistrail())
     basic = self.get_basic_package()
     s1, s2 = self.create_modules(basic)
     fname = os.path.join(temporary_directory(), "test_write_read.vt")
     self.assertTrue(get_api().save_vistrail(fname))
     self.assertTrue(os.path.exists(fname))
     get_api().close_vistrail()
     self.assertTrue(get_api().open_vistrail(fname))
     self.assertEqual(get_api().controller.current_version, 4)
     get_api().close_vistrail()
    def solve(self):
        def write_debug_pipeline_positions(pipeline, mmap, f):
            f.write("%d %d\n" % (len(pipeline.modules), len(pipeline.connections)))
            for k, v in mmap.iteritems():
                f.write("%d %d\n" % (k, v))
            c = pipeline_centroid(pipeline)
            mn, mx = pipeline_bbox(pipeline)
            f.write("%f %f %f %f\n" % (mn.x, mn.y, mx.x, mx.y))
            for i, m in pipeline.modules.iteritems():
                nc = m.center - c
                f.write("%d %s %f %f\n" % (i, m.name, nc.x, nc.y))
            for i, c in pipeline.connections.iteritems():
                f.write("%d %d %d\n" % (i, c.sourceId, c.destinationId))

        if self._debug:
            out = open("%s/pipelines.txt" % temporary_directory(), "w")
            write_debug_pipeline_positions(self._p1, self._g1_vertex_map, out)
            write_debug_pipeline_positions(self._p2, self._g2_vertex_map, out)
            self.print_s8ys()

        self._debug_matrix_file = "input_matrix"
        r_in = self.solve_v(self._input_vertex_s8y)
        self._debug_matrix_file = "output_matrix"
        r_out = self.solve_v(self._output_vertex_s8y)
        r_in = r_in.reshape(len(self._p1.modules), len(self._p2.modules))
        r_out = r_out.reshape(len(self._p1.modules), len(self._p2.modules))

        s = r_in.sum(1)
        s[s == 0.0] = 1
        r_in /= s

        s = r_out.sum(1)
        s[s == 0.0] = 1
        r_out /= s

        r_combined = scipy.multiply(r_in, r_out)

        # Breaks ties on combined similarity
        r_in = r_in * 0.9 + r_combined * 0.1
        r_out = r_out * 0.9 + r_combined * 0.1

        if self._debug:
            print "== G1 =="
            for (k, v) in sorted(self._g1_vertex_map.iteritems(), key=operator.itemgetter(1)):
                print v, k, self._p1.modules[k].name
            print "== G2 =="
            for (k, v) in sorted(self._g2_vertex_map.iteritems(), key=operator.itemgetter(1)):
                print v, k, self._p2.modules[k].name

            print "input similarity"
            self.pm(r_in, digits=3)
            print "output similarity"
            self.pm(r_out, digits=3)
            print "combined similarity"
            self.pm(r_combined, digits=3)

        inputmap = dict(
            [
                (self._g1_vertex_map.inverse[ix], self._g2_vertex_map.inverse[v[0, 0]])
                for (ix, v) in enumerate(r_in.argmax(1))
            ]
        )
        outputmap = dict(
            [
                (self._g1_vertex_map.inverse[ix], self._g2_vertex_map.inverse[v[0, 0]])
                for (ix, v) in enumerate(r_out.argmax(1))
            ]
        )
        combinedmap = dict(
            [
                (self._g1_vertex_map.inverse[ix], self._g2_vertex_map.inverse[v[0, 0]])
                for (ix, v) in enumerate(r_combined.argmax(1))
            ]
        )
        #         print inputmap
        #         print outputmap
        return inputmap, outputmap, combinedmap