-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Bayesian search examples #1100
base: main
Are you sure you want to change the base?
Conversation
# To introduce Bayesian search in Stone Soup, we will start with a simple example. We will simulate | ||
# a bearings-only sensor searching for a single stationary target (we will visualise this later). | ||
# We assume that the sensor never locates the target, but record the probability that the target | ||
# should have been found by a given timestep. We will control the sensor using using a few different |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# should have been found by a given timestep. We will control the sensor using using a few different | |
# should have been found by a given timestep. We will control the sensor using a few different |
# Bayesian Search | ||
# --------------- | ||
# The implementation of sensor management in many of Stone Soup's existing tutorials and examples | ||
# relies on the assumption that we have perfect knowledge of a target's prior location. However in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# relies on the assumption that we have perfect knowledge of a target's prior location. However in | |
# relies on the assumption that we have perfect knowledge of a target's prior location. However, in |
# if running sequential search, perform this now | ||
if seq_flag: | ||
sensor.timestamp = timestep | ||
sensor.dwell_centre = sensor.dwell_centre + sensor.fov_angle/2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sensor.dwell_centre = sensor.dwell_centre + sensor.fov_angle/2. | |
sensor.dwell_centre = sensor.dwell_centre + sensor.fov_angle/3. |
Does it make more sense to rotate the sensor by one bin per step?
from stonesoup.plotter import AnimatedPlotterly | ||
|
||
import copy | ||
from datetime import datetime, timedelta | ||
import numpy as np | ||
import pandas as pd | ||
import plotly.express as px | ||
import plotly.graph_objects as go | ||
import time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from stonesoup.plotter import AnimatedPlotterly | |
import copy | |
from datetime import datetime, timedelta | |
import numpy as np | |
import pandas as pd | |
import plotly.express as px | |
import plotly.graph_objects as go | |
import time | |
import copy | |
from datetime import datetime, timedelta | |
import numpy as np | |
import plotly.graph_objects as go | |
import time |
Unused imports
|
||
from stonesoup.types.state import StateVector | ||
from stonesoup.sensor.radar.radar import RadarRotatingBearing | ||
from stonesoup.types.angle import Angle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from stonesoup.types.angle import Angle |
Unused Import
covar=np.diag([400*weights[j][i], 0, | ||
400*weights[j][i], 0]), | ||
timestamp=timesteps[j]) | ||
for j in range(simulation_length)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for j in range(simulation_length)]) | |
for j in range(sim_length)]) |
sensor_history_b, search_cell_history_b, probs_b = search_loop(prior, sensor1, | ||
optbrutesensormanager, timesteps, | ||
prob_det) | ||
sensor_history_r, search_cell_history_r, probs_r = search_loop(prior, sensor2, | ||
randomsensormanager, timesteps, | ||
prob_det) | ||
sensor_history_s, search_cell_history_s, probs_s = search_loop(prior, sensor3, None, timesteps, | ||
prob_det, seq_flag=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sensor_history_b, search_cell_history_b, probs_b = search_loop(prior, sensor1, | |
optbrutesensormanager, timesteps, | |
prob_det) | |
sensor_history_r, search_cell_history_r, probs_r = search_loop(prior, sensor2, | |
randomsensormanager, timesteps, | |
prob_det) | |
sensor_history_s, search_cell_history_s, probs_s = search_loop(prior, sensor3, None, timesteps, | |
prob_det, seq_flag=True) | |
sensor_history_b, search_cell_history_b, probs_b = search_loop(prior, sensor1, | |
optbrutesensormanager, timesteps, | |
prob_det) | |
sensor_history_r, search_cell_history_r, probs_r = search_loop(prior, sensor2, | |
randomsensormanager, timesteps, | |
prob_det) | |
sensor_history_s, search_cell_history_s, probs_s = search_loop(prior, sensor3, None, timesteps, | |
prob_det, seq_flag=True) |
# from plotly import graph_objects as go | ||
# def plot_search_heatmap(plt, x_pos, y_pos, search_cell_history, **kwargs): | ||
# | ||
# # initialise heatmap trace | ||
# trace_base = len(plt.fig.data) | ||
# | ||
# heatmap_kwargs = dict(x=[], y=[], z=[], colorscale="YlOrRd", opacity=0.6, | ||
# showlegend=True, showscale=False, name="heatmap", | ||
# legendgroup="heatmap") | ||
# heatmap_kwargs.update(kwargs) | ||
# plt.fig.add_trace(go.Heatmap(heatmap_kwargs)) | ||
# | ||
# # get number of traces already in plt | ||
# # add data for each frame | ||
# for frame in plt.fig.frames: | ||
# | ||
# data_ = list(frame.data) | ||
# traces_ = list(frame.traces) | ||
# | ||
# frame_time = datetime.fromisoformat(frame.name) | ||
# | ||
# for particle_state in search_cell_history: | ||
# if frame_time == particle_state.timestamp: | ||
# weights = [float(w) for w in particle_state.weight] | ||
# data_.append(go.Heatmap(x=x_pos, y=y_pos, z=weights)) | ||
# traces_.append(trace_base) | ||
# frame.traces = traces_ | ||
# frame.data = data_ | ||
# | ||
# return plt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function isn't used for plotting in this example
sensor_info = [copy(sensor)] | ||
prob_found_list = [0] | ||
|
||
for i, timestep in enumerate(timesteps[1:]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for i, timestep in enumerate(timesteps[1:]): | |
for timestep in timesteps[1:]: |
i
is unused
Add two examples showcasing the use of Bayesian search in Stone Soup. Note that much of length of the two files comes from plotting functions which are hidden by default in the rendered examples.