Пример #1
0
def test_VDP():

    model = VanDerPol()
    mod_reach = ReachSet(model)
    mod_flow = mod_reach.computeReachSet(200)

    FlowPipePlotter(mod_flow).plot2DPhase(0,1)
Пример #2
0
def test_sir_lin_pca_strat():

    NUM_STEPS = 70
    SIR_PCA_ITER_STEPS = 1 #Number of steps between each recomputation of PCA Templates.
    'PCA Strategy Parameters'
    SIR_PCA_TRAJ_STEPS = 1 #Number of steps our sample trajectories should run.
    SIR_PCA_NUM_TRAJ = 100 #Number of sample trajectories we should use for the PCA routine.
    SIR_LIN_ITER_STEPS = 1
    #
    SIR_PCA_LIFE_SPAN = 3

    sir_pca = SIR_UnitBox(delta=0.5)
    sir_plot = Plot()

    points = [[0.79,0.19,0], [0.79, 0.2,0], [0.8,0.19,0], [0.8,0.2,0], [0.79,0.195,0], [0.8,0.195,0], [0.795,0.19,0],  [0.795,0.2,0]]
    trajs = [Traj(sir_pca, point, NUM_STEPS) for point in points]

    pca_strat = MultiStrategy(LinStrat(sir_pca, iter_steps=SIR_LIN_ITER_STEPS), \
                              DelayedPCAStrat(sir_pca, traj_steps=SIR_PCA_TRAJ_STEPS, num_trajs=SIR_PCA_NUM_TRAJ, life_span=SIR_PCA_LIFE_SPAN))

    sir_pca_reach = ReachSet(sir_pca)
    sir_flow_pca = sir_pca_reach.computeReachSet(NUM_STEPS, tempstrat=pca_strat)
    sir_plot.add(sir_flow_pca, "SIR_LinApp&PCA")

    'Add trajectories'
    for traj in trajs:
        sir_plot.add(traj)

   # sir_plot.plot2DPhase(0,1,separate=False, plotvertices=True)
    sir_plot.plot2DPhase(1,2,separate=False, plotvertices=True)
    sir_plot.plot2DPhase(0,2,separate=False, plotvertices=True)

    Timer.generate_stats()
Пример #3
0
def test_pca_Quad():
    NUM_STEPS = 5
    QUAD_PCA_ITER_STEPS = 1  #Number of steps between each recomputation of PCA Templates.
    'PCA Strategy Parameters'
    QUAD_PCA_TRAJ_STEPS = 1  #Number of steps our sample trajectories should run.
    QUAD_PCA_NUM_TRAJ = 200  #Number of sample trajectories we should use for the PCA routine.

    quad_pca = Quadcopter_UnitBox()
    quad_plot = Plot()

    #trajs = [Traj(rossler_pca, point, NUM_STEPS) for point in points]

    pca_strat = PCAStrat(quad_pca,
                         traj_steps=QUAD_PCA_TRAJ_STEPS,
                         num_trajs=QUAD_PCA_NUM_TRAJ,
                         iter_steps=QUAD_PCA_ITER_STEPS)
    quad_pca_reach = ReachSet(quad_pca)
    quad_flow_pca = quad_pca_reach.computeReachSet(NUM_STEPS,
                                                   tempstrat=pca_strat)

    'Add trajectories'
    #for traj in trajs:
    #    rossler_plot.add(traj)

    quad_plot.add(quad_flow_pca, "Quad_PCA")
    quad_plot.plot2DPhase(2, 5, separate=True, plotvertices=True)
Пример #4
0
def test_phase_rossler():

    basic_mod = Rossler()
    basic_reach = ReachSet(basic_mod)

    flowpipe = basic_reach.computeReachSet(100)
    FlowPipePlotter(flowpipe).plot2DPhase(0, 1)
Пример #5
0
def test_sir_lin_strat():

    #Compute Sapo's version.
    sir_lin = SIR_UnitBox(delta=0.5)
    sir = SIR()
    #sir_reach = ReachSet(sir)

    #sir_flow = sir_reach.computeReachSet(NUM_STEPS)
    sir_plot = Plot()
    #sir_plot.add(sir_flow)

    for i in range(10, 11):
        print(
            colored(
                "Generating Lin_Approx with Iterative Step Size: {}".format(i),
                "white",
                attrs=['reverse', 'blink']))
        sir_lin_reach = ReachSet(sir_lin)
        sir_flow_lin = sir_lin_reach.computeReachSet(
            NUM_STEPS, LinStrat(sir_lin, iter_steps=i))
        sir_plot.add(sir_flow_lin, "SIR_LIN_{}".format(i))

    #sir_plot.plot(0,1,2)
    sir_plot.plot2DPhase(0, 1, separate=True)
    Timer.generate_stats()
    """
Пример #6
0
def test_pca_lin_Rossler():
    NUM_STEPS = 5
    ROSS_PCA_ITER_STEPS = 1 #Number of steps between each recomputation of PCA Templates.
    'PCA Strategy Parameters'
    ROSS_PCA_TRAJ_STEPS = 1 #Number of steps our sample trajectories should run.
    ROSS_PCA_NUM_TRAJ = 200 #Number of sample trajectories we should use for the PCA routine.

    rossler_pca = Rossler_UnitBox(delta=0.5)
    rossler_plot = Plot()

    points = [[0.05,4.95,0.05], [0.1,4.95,0.05], [0.05,5,0.05], [0.1,5,0.05], [0.05,4.95,0.05], [0.05,4.95,0.1], [0.1,4.95,0.1], [0.1,5,0.1]]
    trajs = [Traj(rossler_pca, point, NUM_STEPS) for point in points]

    pca_strat = PCALinStrat(rossler_pca, traj_steps=ROSS_PCA_TRAJ_STEPS, num_trajs=ROSS_PCA_NUM_TRAJ, iter_steps=ROSS_PCA_ITER_STEPS)

    ross_pca_reach = ReachSet(rossler_pca)
    ross_flow_pca = ross_pca_reach.computeReachSet(NUM_STEPS, tempstrat=pca_strat)
    rossler_plot.add(ross_flow_pca, "SIR_LinApp&PCA")

    'Add trajectories'
    for traj in trajs:
        rossler_plot.add(traj)

    rossler_plot.plot2DPhase(0,1,separate=True, plotvertices=True)
    Timer.generate_stats()
Пример #7
0
def test_lin_HarOsc():

    NUM_STEPS = 5

    model = HarOsc()
    #trajs = generate_traj(model, 10, 200)
    mod_reach = ReachSet(model)
    #mod_flow = mod_reach.computeReachSet()

    sir_plot = Plot()

    #mod_flow = mod_reach.computeReachSet(NUM_STEPS)

    SIR_LIN_ITER_STEPS = 1 #Number of steps between each recomputation of PCA Templates.

    lin_strat = LinStrat(model, iter_steps=SIR_LIN_ITER_STEPS)
    mod_lin_flow = mod_reach.computeReachSet(NUM_STEPS, tempstrat=lin_strat, transmode=BundleMode.AFO)
    trajs = [Traj(model, point, steps=NUM_STEPS) for point in product([-5,-4],[0,1])]

    'Generaste the trajectories and add them to the plot.'
    sir_plot.add(mod_lin_flow, "HarOsc LINAPP")
    for t in trajs:
        sir_plot.add(t)

    sir_plot.plot2DPhase(0,1, separate=True, plotvertices=True)

    Timer.generate_stats()
Пример #8
0
def test_pca_HarOsc():

    NUM_STEPS = 4

    model = HarOsc()
    #trajs = generate_traj(model, 10, 200)
    mod_reach = ReachSet(model)
    #mod_flow = mod_reach.computeReachSet()

    sir_plot = Plot()

    SIR_PCA_ITER_STEPS = 1 #Number of steps between each recomputation of PCA Templates.
    'PCA Strategy Parameters'
    SIR_PCA_TRAJ_STEPS = 2 #Number of steps our sample trajectories should run.
    SIR_PCA_NUM_TRAJ = 100 #Number of sample trajectories we should use for the PCA routine.

    pca_strat = PCAStrat(model, traj_steps=SIR_PCA_TRAJ_STEPS, num_trajs=SIR_PCA_NUM_TRAJ, iter_steps=SIR_PCA_ITER_STEPS)
    mod_pca_flow = mod_reach.computeReachSet(NUM_STEPS, tempstrat=[pca_strat], transmode=BundleMode.AFO)
    #trajs = generate_traj(model, 10, 200)

    'Generaste the trajectories and add them to the plot.'
    sir_plot.add(mod_pca_flow, "HarOsc PCA")
    sir_plot.plot2DPhase(0,1, separate=True, plotvertices=True)
    
    Timer.generate_stats()
Пример #9
0
def test_pca_lin_Phos():

    NUM_STEPS = 30
    PHOS_LIN_ITER_STEPS = 1  #Number of steps between each recomputation of LinApp Templates.
    PHOS_PCA_ITER_STEPS = 1  #Number of steps between each recomputation of PCA Templates.
    'PCA Strategy Parameters'
    PHOS_PCA_TRAJ_STEPS = 5  #Number of steps our sample trajectories should run.
    PHOS_PCA_NUM_TRAJ = 200  #Number of sample trajectories we should use for the PCA routine.
    PHOS_LIFE_SPAN = 3

    unit_model = Phosphorelay_UnitBox()
    unit_mod_reach = ReachSet(unit_model)

    #points = [[1,1,1], [1.005, 1,1], [1.01,1.01,1.01], [1.005,1.01,1.01], [1,1.005,1], [1.01,1,1.05]]
    #trajs = [Traj(unit_model , point, NUM_STEPS) for point in points]

    multi_strat = MultiStrategy(LinStrat(unit_model, iter_steps=PHOS_LIN_ITER_STEPS), \
                                DelayedPCAStrat(unit_model, traj_steps=PHOS_PCA_TRAJ_STEPS, num_trajs=PHOS_PCA_NUM_TRAJ, life_span=PHOS_LIFE_SPAN))
    #PCAStrat(unit_model, traj_steps=PHOS_PCA_TRAJ_STEPS, num_trajs=PHOS_PCA_NUM_TRAJ, iter_steps=PHOS_PCA_ITER_STEPS+PHOS_PCA_DELAY))
    #PCAStrat(unit_model, traj_steps=PHOS_PCA_TRAJ_STEPS, num_trajs=PHOS_PCA_NUM_TRAJ, iter_steps=PHOS_PCA_ITER_STEPS+2*PHOS_PCA_DELAY))
    mod_lin_flow = unit_mod_reach.computeReachSet(NUM_STEPS,
                                                  tempstrat=multi_strat)

    # points = [[0,1.97], [0.01, 1.97], [0.01,2], [0,2], [0.005,1.97], [0.005,2], [0,1.97],  [0,1.985], [0.01,1.985]]
    #trajs = [Traj(unit_model, point, NUM_STEPS) for point in points]

    phos_plot = Plot()
    phos_plot.add(mod_lin_flow)

    'Add trajectories'
    for traj in trajs:
        phos_plot.add(traj)

    phos_plot.plot2DPhase(0, 1, separate=False, plotvertices=True)
Пример #10
0
def test_phase_sir():

    sir_mod = SIR()
    sir_reach = ReachSet(sir_mod)

    flowpipe = sir_reach.computeReachSet(300)
    FlowPipePlotter(flowpipe).plot2DPhase(0, 1)
Пример #11
0
def test_plot_basic():

    basic_mod = Basic()
    basic_reach = ReachSet(basic_mod)

    flowpipe = basic_reach.computeReachSet(10)
    FlowPipePlotter(flowpipe).plot2DProj(0)

    Benchmark.generate_stats()
Пример #12
0
def test_phase_sir():

    sir_mod = SIR_UnitBox(delta=0.5)
    sir_reach = ReachSet(sir_mod)

    flowpipe = sir_reach.computeReachSet(50)
    plot = Plot()
    plot.add(flowpipe)
    plot.plot2DPhase(1, 2)
Пример #13
0
    def execute(self):
        model = experi_input['model']
        strat = experi_input['strat']
        label = experi_input['label']
        num_steps = experi_input['num_steps']

        mod_reach = ReachSet(model)
        mod_flow = mod_reach.computeReachSet(num_steps, tempstrat=strat)
        self.animation = TempAnimation(mod_flow)
Пример #14
0
def test_Rossler():

    model = Rossler()
    mod_reach = ReachSet(model)
    mod_flow = mod_reach.computeReachSet(300)

    FlowPipePlotter(mod_flow).plot2DProj(0)
    FlowPipePlotter(mod_flow).plot2DProj(1)
    FlowPipePlotter(mod_flow).plot2DProj(2)
Пример #15
0
def test_basic():

    basic_mod = Basic()
    basic_reach = ReachSet(basic_mod)
    flowpipe = basic_reach.computeReachSet(300)

    basic_plot = Plot()
    basic_plot.add_flowpipe(flowpipe)
    basic_plot.plot(0)
Пример #16
0
def test_LL():

    model = LL()
    mod_reach = ReachSet(model)
    mod_flow = mod_reach.computeReachSet(150)

    FlowPipePlotter(mod_flow).plot2DProj(3)

    Timer.generate_stats()
Пример #17
0
def test_Quad():

    model = Quadcopter()
    mod_reach = ReachSet(model)
    mod_flow = mod_reach.computeReachSet(10)

    FlowPipePlotter(mod_flow).plot2DProj(2)
    FlowPipePlotter(mod_flow).plot2DProj(5)
    FlowPipePlotter(mod_flow).plot2DProj(13)
    Timer.generate_stats()
Пример #18
0
def test_LV():

    model = LotkaVolterra()
    mod_reach = ReachSet(model)
    mod_flow = mod_reach.computeReachSet(100)

    plot = Plot()
    plot.add(mod_flow)
    plot.plot(0,1,2)

    Timer.generate_stats()
Пример #19
0
def test_rossler_phase():

    model = Rossler()
    mod_reach = ReachSet(model)
    mod_flow = mod_reach.computeReachSet(200)

    rossler_plot = Plot()
    rossler_plot.add(mod_flow)
    rossler_plot.plot2DPhase(0,1)

    Timer.generate_stats()
Пример #20
0
def test_Rossler():

    model = Rossler()
    mod_reach = ReachSet(model)
    mod_flow = mod_reach.computeReachSet(300)

    rossler_plot = Plot()
    rossler_plot.add(mod_flow)
    rossler_plot.plot(0,1,2)

    Timer.generate_stats()
Пример #21
0
def test_LL():

    model = LL()
    mod_reach = ReachSet(model)
    mod_flow = mod_reach.computeReachSet(150)

    ll_plot = Plot()
    ll_plot.add(mod_flow)
    ll_plot.plot(0)

    Timer.generate_stats()
Пример #22
0
def test_basic2():

    basic_mod = Basic2()
    basic_reach = ReachSet(basic_mod)
    flowpipe = basic_reach.computeReachSet(300)

    basic_plot = Plot()
    basic_plot.add(flowpipe)
    basic_plot.plot(0)

    Timer.generate_stats()
Пример #23
0
def test_Quad():

    model = Quadcopter()
    mod_reach = ReachSet(model)
    mod_flow = mod_reach.computeReachSet(3)

    quad_plot = Plot()
    quad_plot.add(mod_flow)
    quad_plot.plot(2, 5, 13)

    Timer.generate_stats()
Пример #24
0
def test_SIR():

    model = SIR()
    mod_reach = ReachSet(model)

    mod_flow = mod_reach.computeReachSet(200)

    FlowPipePlotter(mod_flow).plot2DProj(0)
    FlowPipePlotter(mod_flow).plot2DProj(1)
    FlowPipePlotter(mod_flow).plot2DProj(2)

    Timer.generate_stats()
Пример #25
0
    def execute(self):
        self.output_flowpipes = []

        for experi_input in self.inputs:
            model = experi_input['model']
            strat = experi_input['strat']
            label = experi_input['label']
            num_steps = experi_input['num_steps']

            mod_reach = ReachSet(model)
            mod_flow = mod_reach.computeReachSet(num_steps, tempstrat=strat)
            self.plot.add(mod_flow, label=label)
            self.output_flowpipes.append(mod_flow)
            self.max_num_steps = max(self.max_num_steps, num_steps)
Пример #26
0
def test_Phos():

    model = Phosphorelay()
    #unit_model = Phosphorelay_UnitBox()
    mod_reach = ReachSet(model)
    #mod_unit_reach = ReachSet(unit_model)
    #unit_flow = mod_unit_reach.computeReachSet(200)
    mod_flow = mod_reach.computeReachSet(30)

    phos_plot = Plot()
    phos_plot.add(mod_flow)
    phos_plot.plot2DPhase(0, 1, separate=False, plotvertices=True)

    Timer.generate_stats()
Пример #27
0
def test_Phos():

    model = Phosphorelay()
    mod_reach = ReachSet(model)
    timer = Benchmark.assign_timer(Label.TOTAL)
    timer.start()

    mod_flow = mod_reach.computeReachSet(200)

    timer.end()

    FlowPipePlotter(mod_flow).plot2DProj(0)
    FlowPipePlotter(mod_flow).plot2DProj(1)
    FlowPipePlotter(mod_flow).plot2DProj(2)
    Benchmark.generate_stats()
Пример #28
0
def test_OscPart():

    model = OscPart()
    #trajs = generate_traj(model, 10, 200)
    mod_reach = ReachSet(model)
    mod_flow = mod_reach.computeReachSet(20)

    sir_plot = Plot()
    #trajs = generate_traj(model, 10, 200)

    'Generaste the trajectories and add them to the plot.'
    sir_plot.add(mod_flow)
    sir_plot.plot(0, 1, 2)

    Timer.generate_stats()
Пример #29
0
def test_all_pca():

    num_steps = 100

    model_var_dict = {
        Basic: [0],
        Rossler_PCA: [0, 1, 2],
        SIR_PCA: [0, 1, 2],
        LotkaVolterra_PCA: [0, 1, 2],
        Quadcopter_PCA: [2, 5, 13],
        Phosphorelay_PCA: [0, 1]
    }

    model_path_dict = {
        Basic: "/Users/edwardkim/Work/kaa-optimize/figures/Basic",
        Rossler_PCA: "/Users/edwardkim/Work/kaa-optimize/figures/Rossler",
        SIR_PCA: "/Users/edwardkim/Work/kaa-optimize/figures/SIR",
        LotkaVolterra_PCA:
        "/Users/edwardkim/Work/kaa-optimize/figures/LotVolt",
        Quadcopter_PCA: "/Users/edwardkim/Work/kaa-optimize/figures/Quad",
        Phosphorelay_PCA: "/Users/edwardkim/Work/kaa-optimize/figures/Phos"
    }

    for model, var_ind_list in model_var_dict.items():

        print("\n Generating Model: {}\n".format(model))

        flowpipe = ReachSet(model()).computeReachSet(num_steps, PCAStrat)
        plot = Plot()
        plot.add(flowpipe)
        plot.plot(*var_ind_list, path=model_path_dict[model])
Пример #30
0
def test_LV():

    model = LotkaVolterra()
    mod_reach = ReachSet(model)

    timer = Benchmark.assign_timer(Label.TOTAL)
    timer.start()

    mod_flow = mod_reach.computeReachSet(300)

    timer.end()

    FlowPipePlotter(mod_flow).plot2DProj(0)
    FlowPipePlotter(mod_flow).plot2DProj(1)
    FlowPipePlotter(mod_flow).plot2DProj(2)
    Benchmark.generate_stats()