Skip to content
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Add Bayesian search examples #1100

wants to merge 4 commits into from

Conversation

akenyon
Copy link
Contributor

@akenyon akenyon commented Nov 14, 2024

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.

@akenyon akenyon requested a review from jmbarr November 14, 2024 12:53
@akenyon akenyon requested a review from a team as a code owner November 14, 2024 12:53
@akenyon akenyon requested review from sdhiscocks and removed request for a team November 14, 2024 12:53
# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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?

Comment on lines +91 to +99
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for j in range(simulation_length)])
for j in range(sim_length)])

Comment on lines +380 to +387
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)

Comment on lines +439 to +468
# 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
Copy link
Contributor

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:]):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for i, timestep in enumerate(timesteps[1:]):
for timestep in timesteps[1:]:

i is unused

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants