Commit f9ba2f57 authored by Jay's avatar Jay
Browse files

Updated for markkov testing and to allow loading when some information is missing

parent 6f655e2e
Loading
Loading
Loading
Loading
−47.1 KiB

File deleted.

+65.4 KiB

File added.

No diff preview for this file type.

+6 −2
Original line number Diff line number Diff line
@@ -55,14 +55,18 @@ class Edge(dict, MutableMapping):
        d = self.__dict__
        o = other.__dict__
        for k, v in d.items():
            if isinstance(v, pd.DataFrame):
            # If the attribute key is missing they can not be equal
            if not k in o.keys():
                    print(o)
                eq = False
                return eq

            if isinstance(v, pd.DataFrame):
                if not v.equals(o[k]):
                    eq = False
            elif isinstance(v, np.ndarray):
                if not v.all() == o[k].all():
                    eq = False
                    
        return eq

    @property
+9 −13
Original line number Diff line number Diff line
@@ -7,24 +7,20 @@ from .. import markov_cluster

from autocnet.examples import get_path
from autocnet.graph.network import CandidateGraph

from autocnet.io.network import load

class TestMarkovCluster(unittest.TestCase):

    def setUp(self):
        pass
        #TODO: These tests need to load a graph from the new zip
        #self.g = CandidateGraph.from_graph(get_path('sixty_four_apollo.graph'))
        self.g = load(get_path('sixty_four_apollo.proj'))

    def test_mcl_from_network(self):
        pass
        #self.g.compute_clusters(inflate_factor=15)
        #self.assertIsInstance(self.g.clusters, dict)
        #self.assertEqual(len(self.g.clusters), 14)
        self.g.compute_clusters(inflate_factor=15)
        self.assertIsInstance(self.g.clusters, dict)
        self.assertEqual(len(self.g.clusters), 14)

    def test_mcl_from_adj_matrix(self):
        pass
        #arr = np.array(nx.adjacency_matrix(self.g).todense())
        #flow, clusters = markov_cluster.mcl(arr)
        #self.assertIsInstance(clusters, dict)
        #self.assertEqual(len(clusters), 3)
        arr = np.array(nx.adjacency_matrix(self.g).todense())
        flow, clusters = markov_cluster.mcl(arr)
        self.assertIsInstance(clusters, dict)
        self.assertEqual(len(clusters), 3)
+6 −1
Original line number Diff line number Diff line
@@ -102,8 +102,11 @@ def load(projectname):
        for d in data['nodes']:
            n = Node(image_name=d['image_name'], image_path=d['image_path'], node_id=d['id'])
            n['hash'] = d['hash']
            try:
                # Load the byte stream for the nested npz file into memory and then unpack
                n.load_features(BytesIO(pzip.read('{}.npz'.format(d['id']))))
            except:
                pass  # The node does not have features to load.
            cg.add_node(d['node_id'])
            cg.node[d['node_id']] = n
        for e in data['links']:
@@ -113,10 +116,12 @@ def load(projectname):
            edge.destination = cg.node[e['target']]
            edge['fundamental_matrix'] = e['fundamental_matrix']
            edge['weights'] = e['weights']
            try:
                nzf = np.load(BytesIO(pzip.read('{}_{}.npz'.format(e['source'], e['target']))))

                edge._masks = pd.DataFrame(nzf['_masks'], index=nzf['_masks_idx'], columns=nzf['_masks_columns'])
                edge.matches = pd.DataFrame(nzf['matches'], index=nzf['matches_idx'], columns=nzf['matches_columns'])
            except:
                pass
            # Add a mock edge
            cg.edge[e['source']][e['target']] = edge

Loading