Пример #1
0
def main():
    #X = gds.graphs.CircleGraph(4)
    #X.add_edge(0, 2)
    #DumpObject("/home/sichao/gds/gds/graphs/cir4", X)
    #sys.exit(0)
    cs = xml_config.load_config(
        "/home/sichao/svn/Sichao/Thesis/DigitalObjects/gdsConfig.xml")
    config = gdsConfig(cs)
    gds1 = config.gds

    transitions = algorithms.GenerateTransitions(gds1)
    fixedPoints = algorithms.FixedPoints(gds1, transitions)

    p = phase_space.PhaseSpace(gds1)

    fixedPoints = p.GetFixedPoints()
    periodicPoints = p.GetPeriodicPoints()
    components = p.GetComponents()

    print "Fixed points: "
    for i in fixedPoints:
        print i, gds1.IntegerToState(i)

    print "Periodic points: "
    for i, cycle in enumerate(periodicPoints):
        print i
        for j in cycle:
            print gds1.IntegerToState(j)

    print "Components: ", components

    for x, y in enumerate(transitions):
        print gds1.IntegerToState(x), "->", gds1.IntegerToState(y)
 def ComputeActivity(self):
     """Compute alpha_{F,i}"""
     transitions = algorithms.GenerateTransitions(self.gds)
     for x, y in enumerate(transitions):
         state = self.gds.IntegerToState(x)
         iFlipState = state
         if (iFlipState[self.iNode].x == 0):
             iFlipState[self.iNode].x = 1
         else:
             iFlipState[self.iNode].x = 0
         iFlipStateIndex = self.gds.StateToInteger(iFlipState)
         iFlipImageIndex = transitions[iFlipStateIndex]
         if (y != iFlipImageIndex):
             self.diff = self.diff + 1
     self.activity = float(self.diff) / (self.gds.NumStates())
Пример #3
0
    def GenerateTransitions(self):
        self.Invalidate()

        self.graph = None
        self.transitions = algorithms.GenerateTransitions(self.gds)
        return self.transitions
def Output_PS_Figures(gds, pi, s):
    # initialize sequence of local functions: F_n \circ ... \circ F_1
    pi_seq = []
    for i in range(0, s):
        pi_seq.append(pi[i])

    # save transitions from applying local function seq.
    gds.SetSequence(pi_seq)
    transitions = algorithms.GenerateTransitions(gds)
    shift_transitions = []
    for x, y in enumerate(transitions):
        x1 = gds.IntegerToState(x)
        y1 = gds.IntegerToState(y)
        # print gds.StateToString(x), "->", gds.StateToString(y)
        shift_transitions.append(y)

    # graph non-shifted phase space, phase_space_figure.pdf
    gds.SetSequence(pi)
    ps = phase_space.PhaseSpace(gds, shift_transitions)
    ps.phase_space_figure()
    phase_space_figure = ps.GetDigraph()

    # cannot draw graphs with selfloops!
    se = phase_space_figure.selfloop_edges()
    phase_space_figure.remove_edges_from(se)

    A = nx.drawing.nx_agraph.to_agraph(phase_space_figure)
    A.layout(prog='neato', args="-Goverlap=false ")
    A.draw('phase_space_figure.pdf')
    subprocess.Popen('phase_space_figure.pdf', shell=True)  # automatically open .pdf file

    # saved transitions from applying local function seq.
    ps.shifted_phase_space_figure()
    shift_transition_digraph = ps.GetDigraph()

    # make shifted_phase_space_figure
    shifted_Pi = shift(pi, s)
    gds.SetSequence(shifted_Pi)
    ps = phase_space.PhaseSpace(gds)
    ps.phase_space_figure()
    shifted_phase_space_figure = ps.GetDigraph()

    # paint coinciding shifted edges/nodes
    num_edges = len(shifted_phase_space_figure.edges())
    hit_ratio = 0
    for edge in shifted_phase_space_figure.edges():
        # paint nodes and edge
        if edge in shift_transition_digraph.edges():
            shifted_phase_space_figure.add_edge(*edge, color="red")
            shifted_phase_space_figure.add_node(edge[0], color="red")
            shifted_phase_space_figure.add_node(edge[1], color="red")
            hit_ratio += 1
    # no. of painted states / no. of total states = hit_ratio
    hit_ratio /= float(num_edges)

    se = shifted_phase_space_figure.selfloop_edges()
    shifted_phase_space_figure.remove_edges_from(se)
    A = nx.drawing.nx_agraph.to_agraph(shifted_phase_space_figure)
    A.layout(prog='neato', args="-Goverlap=false ")
    A.draw('shifted_phase_space_figure.pdf')
    subprocess.Popen('shifted_phase_space_figure.pdf', shell=True)

    return hit_ratio