예제 #1
0
def ex3_plots(instance, destination, prefix, save, animate):
    plts = ukf_plots(instance, destination, prefix, save, animate)

    truths = truth_parser(instance)
    nan_array = nan_array_parser(instance, truths, instance.base_model)
    #obs, obs_key = obs_parser(instance, True)
    obs_key = obs_key_parser(instance, True)
    preds = preds_parser(instance, True)
    #forecasts =  forecasts_parser(instance, True)
    gates = np.array(instance.estimated_gates).astype('float64')

    ukf_params = instance.ukf_params
    #forecasts = np.vstack(instance.forecasts)

    "remove agents not in model to avoid wierd plots"
    truths *= nan_array
    preds *= nan_array
    #forecasts*= nan_array
    #gates *= nan_array[::instance.sample_rate, 0::2]
    "indices for unobserved agents"

    subset = np.arange(truths.shape[1] // 2)
    subset2 = np.repeat((2 * subset), 2)
    subset2[1::2] += 1

    #turn on for subset plots
    #if instance.model_params["random_seed"] == 8:
    #   subset = np.array([1, 5, 3])
    #   subset2 = np.repeat((2*subset), 2)
    #   subset2[1::2] +=1

    #plts.path_plots(obs, "Observed")
    plts.pair_frame(truths, preds, obs_key, 100, destination)

    error_plot(instance.true_gate, instance.estimated_gates,
               instance.sample_rate)

    plts.error_hist(truths[::instance.sample_rate, :],
                    preds[::instance.sample_rate, :], "Observed Errors")

    plts.path_plots(preds[::instance.sample_rate, subset2], "Predicted")
    plts.path_plots(truths[:, subset2], "True")
    #plts.path_plots(forecasts[::instance.sample_rate, subset2], "Forecasts")
    plts.dual_path_plots(truths[::instance.sample_rate, subset2],
                         preds[::instance.sample_rate,
                               subset2], "True and Predicted")

    plts.gate_choices(gates[:, ], instance.sample_rate)

    #split_gate_choices(gates[:, subset], instance.sample_rate)
    if animate:
        #plts.trajectories(truths, "plots/")
        plts.pair_frames(truths[::instance.sample_rate],
                         preds[::instance.sample_rate],
                         obs_key[::instance.sample_rate],
                         truths[::instance.sample_rate].shape[0],
                         "../../plots/")
예제 #2
0
파일: ukf_ex1.py 프로젝트: Guonalll/dust
def ex1_plots(instance, destination, prefix, save, animate):
    """do plots for experiment 1
    
    - extract truths, obs, ukf predictions (preds), and forecasts
    - remove inactive agent measurements to prevent bias
    - plot one pairs plot frame linking ukf predictions to true values by tethers
    - plot population of agent median L2 errors in a  histogram
    - plot agent paths for observations, ukf preditions, and true values
    - if animated
    - plot true paths for agents in trajectories
    - plot a pair plot frame for every model step and animate them together.
    
    Parameters
    ------
    
    instance : class
        uks_ss class `instance` after completed run.
    plot_dir, prefix : str
        `plot_dir` where to save the plot to e.g. "" for this directory or 
        "ukf_results/ for ukf_results"
        `prefix` puts some prefix in front of various picture file names.
        e.g. "ukf_" or "agg_ukf_" so you can differentiate them and not overwrite
        them
    save , animate : bool
        `save` plots or `animate` whole model run?
    
    """

    marker_attributes = {
        "markers": {
            -1: "o",
            0: "X",
            2: "s"
        },
        "colours": {
            -1: "black",
            0: "orangered",
            2: "skyblue"
        },
        "labels": {
            -1: "Pseudo-True Positions",
            0: "Unobserved Agents",
            2: "Observed Agents"
        }
    }

    plts = ukf_plots(instance, destination, prefix, save, animate,
                     marker_attributes)

    obs, preds, truths, nan_array = instance.data_parser()
    obs_key = instance.obs_key_parser()
    ukf_params = instance.ukf_params
    index2 = ukf_params["index2"]
    forecasts = np.vstack(instance.forecasts)

    obs *= nan_array[::instance.sample_rate, index2]
    truths *= nan_array
    preds *= nan_array
    forecasts *= nan_array

    "indices for unobserved agents"
    not_index2 = np.array(
        [i for i in np.arange(truths.shape[1]) if i not in index2])
    plts.pair_frame(truths, preds, obs_key, 50, "plots/")
    plts.error_hist(truths[:, index2], preds[:, index2], "Observed Errors")
    plts.error_hist(truths[:, not_index2], preds[:, not_index2],
                    "Unobserved Errors")
    plts.path_plots(obs, "Observed")
    "remove nan rows to stop plot clipping"
    plts.path_plots(preds[::instance.sample_rate], "Predicted")
    plts.path_plots(truths, "True")

    if animate:
        #plts.trajectories(truths, "plots/")
        plts.pair_frames(truths, forecasts, obs_key, truths.shape[0], "plots/")
예제 #3
0
파일: ukf_ex2.py 프로젝트: Guonalll/dust
def ex2_plots(instance, destination, prefix, save, animate):
    """plots for experiments 2
    
    Parameters
    ------
    
    instance : class
    
        ukf_ss `instance` containing a finished stationsim run to publish
        
    destination, prefix : str
        
        `destination to save 
    save, animate : bool
    """

    marker_attributes = {
        "markers": {
            -1: "o",
            0: "X",
            1: "^"
        },
        "colours": {
            -1: "black",
            0: "orangered",
            1: "yellow"
        },
        "labels": {
            -1: "Pseudo-Truths",
            0: "Unobserved",
            1: "Aggregated"
        }
    }

    plts = ukf_plots(instance, destination, prefix, save, animate,
                     marker_attributes)

    "pull data and put finished agents to nan"
    obs, preds, truths, nan_array = instance.data_parser()
    obs_key = instance.obs_key_parser()
    forecasts = np.vstack(instance.forecasts)

    truths *= nan_array
    preds *= nan_array
    forecasts *= nan_array

    plts.pair_frame(truths, preds, obs_key, 50, "plots/")
    plts.heatmap_frame(truths, 50, "plots/")
    plts.error_hist(truths, preds, "Aggregate")

    "remove nan rows to stop plot clipping"
    plts.path_plots(preds[::instance.sample_rate],
                    "Predicted",
                    polygons=instance.ukf_params["poly_list"])
    plts.path_plots(truths, "True")

    if animate:

        #plts.trajectories(truths, "plots/")
        #plts.heatmap(truths,truths.shape[0], "plots/")
        plts.pair_frames(truths, forecasts, np.vstack(obs_key),
                         truths.shape[0], "plots/")
예제 #4
0
def ex1_plots(instance, destination, prefix, save, animate):
    
    
    """do plots for experiment 1
    
    - extract truths, obs, ukf predictions (preds), and forecasts
    - remove inactive agent measurements to prevent bias
    - plot one pairs plot frame linking ukf predictions to true values by tethers
    - plot population of agent median L2 errors in a  histogram
    - plot agent paths for observations, ukf preditions, and true values
    - if animated
    - plot true paths for agents in trajectories
    - plot a pair plot frame for every model step and animate them together.
    
    Parameters
    ------
    
    instance : class
        uks_ss class `instance` after completed run.
    plot_dir, prefix : str
        `plot_dir` where to save the plot to e.g. "" for this directory or 
        "ukf_results/ for ukf_results"
        `prefix` puts some prefix in front of various picture file names.
        e.g. "ukf_" or "agg_ukf_" so you can differentiate them and not overwrite
        them
    save , animate : bool
        `save` plots or `animate` whole model run?
    
    """
    
    plts = ukf_plots(instance, destination, prefix, save, animate)

    truths = truth_parser(instance)
    nan_array= nan_array_parser(instance, truths, instance.base_model)
    #obs, obs_key = obs_parser(instance, True)
    obs_key = obs_key_parser(instance, True)
    preds = preds_parser(instance, True)
    #forecasts =  forecasts_parser(instance, True)
    
    ukf_params = instance.ukf_params
    index2 = ukf_params["index2"]
    
    "remove agents not in model to avoid wierd plots"
    #obs *= nan_array
    truths *= nan_array
    preds *= nan_array
    #forecasts*= nan_array
    
    "indices for unobserved agents"
    not_index2 = np.array([i for i in np.arange(truths.shape[1]) if i not in index2])
    plts.pair_frame(truths, preds, obs_key, 10, destination)
    plts.error_hist(truths[::instance.sample_rate,index2], 
                    preds[::instance.sample_rate,index2],"Observed Errors")
    if len(not_index2)>0:
        plts.error_hist(truths[::instance.sample_rate, not_index2], 
                        preds[::instance.sample_rate, not_index2],"Unobserved Errors")
        
    #plts.path_plots(obs[::instance.sample_rate] , "Observed")
    plts.path_plots(preds[::instance.sample_rate], "Predicted")
    plts.path_plots(truths, "True")
    #plts.path_plots(forecasts[::instance.sample_rate], "Forecasts")

    if animate:
        #plts.trajectories(truths, "plots/")
        plts.pair_frames(truths, preds, obs_key,
                         truths.shape[0], "../../plots/")