def test_rigorous_henon(depth, box, plot=False, fpath="../sandbox/henon_test"): # our tree, mapper, enclosure tree = Tree(box, full=True) m = HenonMapper() ce = CombEnc(tree, m) for d in range(depth): # print 'at depth', d ce.tree.subdivide() # print 'subdivided:', ce.tree.size, 'boxes' ce.update() # print 'enclosure updated' I = graph_mis(ce.mvm) # print 'len(I) = ', len(I) # print '' # now remove all boxes not in I (the maximal invariant set) ce.tree.remove(list(set(range(ce.tree.size)) - set(I))) if plot: # now display the tree! boxes = ce.tree.boxes() gfx.show_uboxes(boxes, col="c", ecol="b") print "done with rigorous henon @ depth", depth print "" fname = fpath + dot + "CE" + dot + str(depth) utils.write_dot(ce.mvm.graph, fname + ".dot") utils.pickle_tree(ce.tree, fname + ".pkl")
def test_one_box(box,tree,graphics=False,callback=None):#,f): print 'box',box[0],box[1],':', s = tree.search(box) print "" print "box search:", s print "len(s):", len( s ) boxes = tree.boxes() if graphics: plt.close() gfx.show_uboxes(boxes) gfx.show_uboxes(boxes, S=s, col='r') if len(s) < ((tree.dim**tree.depth)/2): # dim^depth/2 t = tree.insert(box) if graphics: boxes = tree.boxes() gfx.show_uboxes(boxes, S=t, col='c') print 'ins:',t else: t = tree.remove(s) print 'rem:',t if graphics: gfx.show_box(box,col='g',alpha=0.5) if callback: plt.gcf().canvas.mpl_connect('button_press_event', callback) plt.show()
# convert nodes to integers starting at 0 H = nx.convert_node_labels_to_integers( FR.mvm.graph, first_label=0 ) # True Henon # our tree, mapper, enclosure tree = Tree(box,full=True) m = HenonMapper() ce = CombEnc(tree,m) for d in range(depth): print 'at depth', d ce.tree.subdivide() print 'subdivided:', ce.tree.size, 'boxes' ce.update() #print 'enclosure updated' I = graph_mis(ce.mvm) #print 'len(I) = ', len(I) print '' # now remove all boxes not in I (the maximal invariant set) ce.tree.remove(list(set(range(ce.tree.size))-set(I))) # now display the tree! boxes = ce.tree.boxes() gfx.show_uboxes(boxes, col='c', ecol='b') print "Plotting boxes... " fig = FR.show_boxes() fig = FR.show_error_boxes( color='r', fig=fig ) confidence( ce.mvm, H )
def show_boxes( self, color='b', alpha=0.6 ): """ """ fig = gfx.show_uboxes( self.boxes(), col=color ) return fig
print "subdivided:", ce.tree.size, "boxes" t = time.time() ce.update() times[1, d, n] = time.time() - t print "updated" t = time.time() I = graph_mis(ce.mvm) times[2, d, n] = time.time() - t print "len(I) = ", len(I) t = time.time() ce.tree.remove(list(set(range(ce.tree.size)) - set(I))) times[3, d, n] = time.time() - t print "removed" boxes = ce.tree.boxes() gfx.show_uboxes(boxes, col="c", ecol="b") # print times pickle.dump(times, file("henon-times.pickle", "w")) else: import scipy.io import scipy.stats as stats import matplotlib.pyplot as plt ptimes = np.array( [ [ [ 1.40666962e-05, 2.38418579e-05,
# keep track of 'physical' box corners B = ce.tree.boxes().corners idx_mapping = {} for i in I: idx_mapping[i] = B[i] # now trim the tree, which will reorder/renumber the corners ce.tree.remove( list( nodes - set(I) ) ) ce.mvm.remove_nodes_from( nodes - set(I) ) for i,u in idx_mapping.items(): ce.mvm.graph.node[i]['corner'] = ce.tree.search( u ) #now display the tree! boxes = ce.tree.boxes() gfx.show_uboxes(boxes, col='c', ecol='b') # # we have to relabel the nodes to go from 0..N-1 # new_mvm = nx.convert_node_labels_to_integers( ce.mvm.graph ) # print "new_mvm isomorphic to old mvm:", nx.is_isomorphic( ce.mvm.graph, new_mvm ) # ce.mvm.graph = new_mvm # ce.adj.remove_nodes_from( nodes - set(I) ) # new_adj = nx.convert_node_labels_to_integers( ce.adj.graph ) # ce.adj.graph = new_adj # draw the outer enclosure. the 'mvm' is the MultiValued Map on the # nodes/intervals in the subdivided grid on [0,1].