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)
def test_sir_pca_strat(): #Compute Sapo's version.3 sir_pca = SIR_UnitBox(delta=0.5) sir = SIR(delta=0.5) sir_reach = ReachSet(sir) sir_flow = sir_reach.computeReachSet(NUM_STEPS) sir_plot = Plot() sir_plot.add(sir_flow, "SIR SAPO") for i in range(ITER_SPREAD, ITER_SPREAD + 1): print( colored("Generating PCA with Iterative Step Size: {}".format(i), "white", attrs=['reverse', 'blink'])) sir_pca_reach = ReachSet(sir_pca) sir_flow_pca = sir_pca_reach.computeReachSet( NUM_STEPS, tempstrat=PCAStrat(sir_pca, iter_steps=i), transmode=BundleMode.AFO) sir_plot.add(sir_flow_pca, "SIR_PCA_{}".format(i)) sir_plot.plot2DPhase(0, 1, separate=False, plotvertices=True) #sir_plot.plot(0,1,2) Timer.generate_stats() """
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() """
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()
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()
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()
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)
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()
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)
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()
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()
def test_SIR(): model = SIR(delta=0.5) model_unit = SIR_UnitBox() #trajs = generate_traj(model, 10, 200) mod_reach = ReachSet(model) mod_unit_reach = ReachSet(model_unit) mod_flow = mod_reach.computeReachSet(70) #mod_unit_flow = mod_unit_reach.computeReachSet(300) sir_plot = Plot() #trajs = generate_traj(model, 10, 200) 'Generaste the trajectories and add them to the plot.' #for traj in trajs: # sir_plot.add(traj) sir_plot.add(mod_flow) #sir_plot.add(mod_unit_flow) sir_plot.plot2DPhase(0,1) Timer.generate_stats()
def test_haroscrotate(): NUM_STEPS = 4 model = HarOscRotate() mod_reach = ReachSet(model) mod_flow = mod_reach.computeReachSet(NUM_STEPS) 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. #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) vdp_plot = Plot() vdp_plot.add(mod_flow, "HarOsc") #vdp_plot.add(mod_pca_flow, "HarOsc PCA") vdp_plot.plot2DPhase(0, 1) Timer.generate_stats()