Ejemplo n.º 1
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])
Ejemplo n.º 2
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)
Ejemplo n.º 3
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()
Ejemplo n.º 4
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()
Ejemplo n.º 5
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()
Ejemplo n.º 6
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()
Ejemplo n.º 7
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()
Ejemplo n.º 8
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()
Ejemplo n.º 9
0
def pca_lin_comp():

    sir = SIR_UnitBox()
    sir_reach = ReachSet(sir)

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

    sir_lin_flow = sir_reach.computeReachSet(NUM_STEPS,
                                             LinStrat(sir, iter_steps=150))
    #sir_pca_flow = sir_reach.computeReachSet(NUM_STEPS, PCAStrat(sir, iter_steps=50))

    sir_plot.add(sir_lin_flow, "SIR_LIN")
    #sir_plot.add(sir_pca_flow, "SIR_PCA")

    sir_plot.plot(0, 1, 2)
    Timer.generate_stats()
Ejemplo n.º 10
0
def test_sir_cut_strat():

    #Compute Sapo's version.
    sir_cut = SIR()
    sir = SIR_UnitBox()
    sir_reach = ReachSet(sir)

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

    sir_cut_reach = ReachSet(sir_cut)
    sir_cut_flow = sir_cut_reach.computeReachSet(NUM_STEPS, CutStrat(sir_cut))

    sir_sapo_flow = sir_cut_reach.computeReachSet(NUM_STEPS)

    sir_plot.add(sir_cut_flow, "SIR_CUT_150")
    sir_plot.add(sir_sapo_flow, "SIR_SAPO")

    sir_plot.plot(0, 1, 2)
    Timer.generate_stats()
Ejemplo n.º 11
0
def test_rossler_pca_strat():

    #Compute Sapo's version.
    rossler_pca = Rossler_UnitBox()
    rossler = Rossler()
    rossler_reach = ReachSet(rossler)

    #rossler_flow = rossler_reach.computeReachSet(NUM_STEPS)
    rossler_plot = Plot()
    #rossler_plot.add(rossler_flow)

    for i in range(3, 4):
        print(
            colored("Generating PCA with Iterative Step Size: {}".format(i),
                    "white",
                    attrs=['reverse', 'blink']))
        rossler_pca_reach = ReachSet(rossler_pca)
        rossler_flow_pca = rossler_pca_reach.computeReachSet(
            NUM_STEPS, PCAStrat(rossler_pca, iter_steps=i))
        rossler_plot.add(rossler_flow_pca, "Rossler_PCA_{}".format(i))

    rossler_plot.plot(0, 1, 2)
    Timer.generate_stats()
Ejemplo n.º 12
0
def test_rossler_lin_strat():

    #Compute Sapo's version.
    rossler_lin = Rossler_UnitBox()
    rossler = Rossler()
    rossler_reach = ReachSet(rossler)

    rossler_flow = rossler_reach.computeReachSet(NUM_STEPS)
    rossler_plot = Plot()
    rossler_plot.add(rossler_flow)

    for i in range(10, 11):
        print(
            colored("Generating LIN with Iterative Step Size: {}".format(i),
                    "white",
                    attrs=['reverse', 'blink']))
        rossler_lin_reach = ReachSet(rossler_lin)
        rossler_flow_lin = rossler_lin_reach.computeReachSet(
            NUM_STEPS, LinStrat(rossler_lin, iter_steps=i))
        rossler_plot.add(rossler_flow_lin, "Rossler_LIN_{}".format(i))

    rossler_plot.plot(0, 1, 2)
    Timer.generate_stats()
Ejemplo n.º 13
0
def test_lv_pca_strat():

    #Compute Sapo's version.
    lv_pca = LotkaVolterra_UnitBox()
    lv = LotkaVolterra()
    lv_reach = ReachSet(lv)

    lv_flow = lv_reach.computeReachSet(NUM_STEPS)
    lv_plot = Plot()
    lv_plot.add(lv_flow)

    for i in range(1, ITER_SPREAD):
        print(
            colored("Generating PCA with Iterative Step Size: {}".format(2 *
                                                                         i),
                    "white",
                    attrs=['reverse', 'blink']))
        lv_pca_reach = ReachSet(lv_pca)
        lv_flow_pca = lv_pca_reach.computeReachSet(
            NUM_STEPS, PCAStrat(lv_pca, iter_steps=2 * i))
        lv_plot.add(lv_flow_pca, "LV_PCA_{}".format(2 * i))

    lv_plot.plot(0, 1, 2)
    Timer.generate_stats()
Ejemplo n.º 14
0
def test_quad_pca_strat():

    #Compute Sapo's version.
    quad_pca = Quadcopter_UnitBox()
    quad = Quadcopter()
    quad_reach = ReachSet(quad)

    quad_flow = quad_reach.computeReachSet(NUM_STEPS)
    quad_plot = Plot()
    quad_plot.add(quad_flow)

    for i in range(1, ITER_SPREAD):
        print(
            colored("Generating PCA with Iterative Step Size: {}".format(2 *
                                                                         i),
                    "white",
                    attrs=['reverse', 'blink']))
        quad_pca_reach = ReachSet(quad_pca)
        quad_flow_pca = quad_pca_reach.computeReachSet(
            NUM_STEPS, PCAStrat(quad_pca, iter_steps=2 * i))
        quad_plot.add(quad_flow_pca, "QUAD_PCA_{}".format(2 * i))

    quad_plot.plot(2, 5, 13)
    Timer.generate_stats()
Ejemplo n.º 15
0
class Experiment:
    def __init__(self, *inputs, label=""):
        self.inputs = inputs
        self.plot = Plot()
        self.max_num_steps = 0

        'Assuming that all models use the same dynamics and same initial set for now'
        self.model = inputs[0]['model']
        self.label = label

    """
    Execute the reachable set simulations and add the flowpipes to the Plot.
    """

    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)

    """
    Plot the results fed into the Plot object
    """

    def plot_results(self, *var_tup, plottrajs=True):
        border_sim_trajs = self.__simulate_border_points(self.max_num_steps)
        if plottrajs:
            self.plot.add(border_sim_trajs)

        self.plot.plot(*var_tup)

    def get_total_vol_results(self):
        assert self.output_flowpipes is not None, "Execute Experiment with ExperimentInputs before retrieving volume data."
        return [flowpipe.total_volume for flowpipe in self.output_flowpipes]

    """
    Extract the initial box intervals from the model
    """

    def __get_init_box(self):
        init_offu = self.model.bund.offu[:self.model.
                                         dim]  #Assume first dim # of offsets are associated to initial box
        init_offl = self.model.bund.offl[:self.model.dim]

        return [[-lower_off, upper_off]
                for lower_off, upper_off in zip(init_offl, init_offu)]

    """
    Sample points from the edges of the box and propagate them for a number of steps.
    """

    def __simulate_border_points(self, num_steps):
        init_box_inter = self.__get_init_box()
        border_points = get_init_box_borders(init_box_inter)

        trajs = [Traj(self.model, point, num_steps) for point in border_points]
        return TrajCollection(trajs)