def test_dist_stitcher2(self): """ Test dist stitch with only 2 common nodes - not enough. """ src = self.setup_positions([[0, 1, 3, 4]]) dst = self.setup_positions([[0, 1, 2, 5, 6]]) self.transform(src, s_i=1) #transform src positions stitcher = DistStitcher() stitcher.stitch(dst, src) self.assertTrue(len(dst)==2, 'Wrong number of subclusters.') rms = get_rms(self.test_cluster, dst) self.assertFalse(rms<0.001, 'Stitching was too good.') # with align rms should be ok rms_align = get_rms(self.test_cluster, dst, align=True) self.assertTrue(rms_align<0.001, 'Stitching was not good enough.')
def test_dist_stitcher2(self): """ Test dist stitch with only 2 common nodes - not enough. """ src = self.setup_positions([[0, 1, 3, 4]]) dst = self.setup_positions([[0, 1, 2, 5, 6]]) self.transform(src, s_i=1) #transform src positions stitcher = DistStitcher() stitcher.stitch(dst, src) self.assertTrue(len(dst) == 2, 'Wrong number of subclusters.') rms = get_rms(self.test_cluster, dst) self.assertFalse(rms < 0.001, 'Stitching was too good.') # with align rms should be ok rms_align = get_rms(self.test_cluster, dst, align=True) self.assertTrue(rms_align < 0.001, 'Stitching was not good enough.')
def draw_propagation_errors(self, locKey, net): SCALE_FACTOR = 0.6 if not net: net = self.net if any([not locKey in node.memory for node in net.nodes()]): self.propagation_error_collection = [] self.ini_error_collection = [] return rms = {"iniRms": {}, "stitchRms": {}} for node in net.nodes(): rms["iniRms"][node] = get_rms(self.net.pos, (node.memory["iniLocs"]), True) * SCALE_FACTOR rms["stitchRms"][node] = get_rms(self.net.pos, node.memory[locKey], True) * SCALE_FACTOR self.propagation_error_collection = self.draw_nodes(net=net, node_colors="g", node_radius=rms["stitchRms"]) self.ini_error_collection = self.draw_nodes(net=net, node_colors="b", node_radius=rms["iniRms"])
def on_actionShowLocalizedSubclusters_triggered(self): if len(self.ui.nodeInspector.selectedIndexes()) == 1: qModelIndex = self.ui.nodeInspector.selectedIndexes()[0] treeItem = qModelIndex.internalPointer() assert(isinstance(treeItem.itemDataValue, Positions)) estimated = deepcopy(treeItem.itemDataValue) estimatedsub = estimated.subclusters[0] # rotate, translate and optionally scale # w.r.t. original positions (pos) align_clusters(Positions.create(self.net.pos), estimated, True) net = self.net.subnetwork(estimatedsub.keys(), pos=estimatedsub) self.draw_network(net=net, drawMessages=False) edge_pos = numpy.asarray([(self.net.pos[node], estimatedsub[node][:2]) for node in net]) error_collection = LineCollection(edge_pos, colors='r') self.axes.add_collection(error_collection) rms = get_rms(self.net.pos, estimated, scale=False) self.update_log('rms = %.3f' % rms) self.update_log('localized = %.2f%% (%d/%d)' % (len(estimatedsub) * 1. / len(self.net.pos) * 100, len(estimatedsub), len(self.net.pos)))
def on_actionShowLocalizedSubclusters_triggered(self): if len(self.ui.nodeInspector.selectedIndexes()) == 1: qModelIndex = self.ui.nodeInspector.selectedIndexes()[0] treeItem = qModelIndex.internalPointer() assert (isinstance(treeItem.itemDataValue, Positions)) estimated = deepcopy(treeItem.itemDataValue) estimatedsub = estimated.subclusters[0] # rotate, translate and optionally scale # w.r.t. original positions (pos) align_clusters(Positions.create(self.net.pos), estimated, True) net = self.net.subnetwork(estimatedsub.keys(), pos=estimatedsub) self.draw_network(net=net, drawMessages=False) edge_pos = numpy.asarray([ (self.net.pos[node], estimatedsub[node][:2]) for node in net ]) error_collection = LineCollection(edge_pos, colors='r') self.axes.add_collection(error_collection) rms = get_rms(self.net.pos, estimated, scale=False) self.update_log('rms = %.3f' % rms) self.update_log('localized = %.2f%% (%d/%d)' % (len(estimatedsub) * 1. / len(self.net.pos) * 100, len(estimatedsub), len(self.net.pos)))
def test_dist_stitcher(self): src = self.setup_positions([[0, 1, 2, 3, 4]]) dst = self.setup_positions([[0, 1, 2, 5, 6]]) self.transform(src, s_i=1) stitcher = DistStitcher() stitcher.stitch(dst, src) self.assertTrue(len(dst) == 1, 'Wrong number of subclusters.') rms = get_rms(self.test_cluster, dst) self.assertTrue(rms < 0.001, 'Stitching was not good enough.')
def test_dist_stitcher(self): src = self.setup_positions([[0, 1, 2, 3, 4]]) dst = self.setup_positions([[0, 1, 2, 5, 6]]) self.transform(src, s_i=1) stitcher = DistStitcher() stitcher.stitch(dst, src) self.assertTrue(len(dst)==1, 'Wrong number of subclusters.') rms = get_rms(self.test_cluster, dst) self.assertTrue(rms<0.001, 'Stitching was not good enough.')
def draw_propagation_errors(self, locKey, net): SCALE_FACTOR = 0.6 if not net: net = self.net if any([not locKey in node.memory for node in net.nodes()]): self.propagation_error_collection = [] self.ini_error_collection = [] return rms = {'iniRms': {}, 'stitchRms': {}} for node in net.nodes(): rms['iniRms'][node] = get_rms(self.net.pos, (node.memory['iniLocs']), True) * \ SCALE_FACTOR rms['stitchRms'][node] = get_rms(self.net.pos, node.memory[locKey], True) * SCALE_FACTOR self.propagation_error_collection = \ self.draw_nodes(net=net, node_colors='g', node_radius=rms['stitchRms']) self.ini_error_collection = self.draw_nodes(net=net, node_colors='b', node_radius=rms['iniRms'])
def test_dist_intrastitch(self): """ Test dist intrastitch Clusters are setup so that first stitch is src[0] with dst[1] and then dst[0] and dst[1] can be intrastitched. """ src = self.setup_positions([[1, 2, 4, 5, 6]]) dst = self.setup_positions([[0, 2, 3, 4], [0, 1, 2, 6]]) self.transform(src, s_i=1) #transform src positions self.transform(dst, s_i=1) #transform src positions stitcher = DistStitcher() stitcher.stitch(dst, src) self.assertTrue(len(dst) == 1, 'Wrong number of subclusters.') # without align new subcluster should be wrongly (not) rotated rms = get_rms(self.test_cluster, dst) self.assertFalse(rms < 0.001, 'Stitching was too good.') # with align rms should be ok rms_align = get_rms(self.test_cluster, dst, align=True) self.assertTrue(rms_align < 0.001, 'Stitching was not good enough.')
def test_dist_intrastitch(self): """ Test dist intrastitch Clusters are setup so that first stitch is src[0] with dst[1] and then dst[0] and dst[1] can be intrastitched. """ src = self.setup_positions([[1, 2, 4, 5, 6]]) dst = self.setup_positions([[0, 2, 3, 4], [0, 1, 2, 6]]) self.transform(src, s_i=1) #transform src positions self.transform(dst, s_i=1) #transform src positions stitcher = DistStitcher() stitcher.stitch(dst, src) self.assertTrue(len(dst)==1, 'Wrong number of subclusters.') # without align new subcluster should be wrongly (not) rotated rms = get_rms(self.test_cluster, dst) self.assertFalse(rms<0.001, 'Stitching was too good.') # with align rms should be ok rms_align = get_rms(self.test_cluster, dst, align=True) self.assertTrue(rms_align<0.001, 'Stitching was not good enough.')
def test_aoa_stitcher(self): src = self.setup_positions([[0, 1, 2, 3, 4]]) dst = self.setup_positions([[0, 1, 2, 5, 6]]) #theta = 60/180.*pi #R = array([[cos(theta), -sin(theta)], [sin(theta), cos(theta)]]) #ccw #self.transform(src, R, [-1.62, -0.8], 0.5) #transform src positions self.transform(src) stitcher = AoAStitcher() stitcher.stitch(dst, src) rms = get_rms(self.test_cluster, dst) self.assertTrue(rms < 0.001, 'Stitching was not good enough.') self.assertTrue(len(dst) == 1, 'Wrong number of subclusters.')
def test_aoa_stitcher(self): src = self.setup_positions([[0, 1, 2, 3, 4]]) dst = self.setup_positions([[0, 1, 2, 5, 6]]) #theta = 60/180.*pi #R = array([[cos(theta), -sin(theta)], [sin(theta), cos(theta)]]) #ccw #self.transform(src, R, [-1.62, -0.8], 0.5) #transform src positions self.transform(src) stitcher = AoAStitcher() stitcher.stitch(dst, src) rms = get_rms(self.test_cluster, dst) self.assertTrue(rms<0.001, 'Stitching was not good enough.') self.assertTrue(len(dst)==1, 'Wrong number of subclusters.')