-
Notifications
You must be signed in to change notification settings - Fork 123
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
Transition and measurement models for road networks #812
base: main
Are you sure you want to change the base?
Conversation
…RoadNetwork add_nodes_from
…to better reflect their purpose
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #812 +/- ##
==========================================
+ Coverage 93.49% 93.56% +0.06%
==========================================
Files 200 204 +4
Lines 12715 13055 +340
Branches 2615 2685 +70
==========================================
+ Hits 11888 12215 +327
- Misses 585 590 +5
- Partials 242 250 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@jswright-dstl, @sdhiscocks this PR is ready for review. I've left the example in for now to help with the review, but plan to remove it before merging. |
x_k = \left[r_k, \cdots, e_k, d_k, s_k\right] | ||
|
||
and :math:`e_k` denotes the edge the target is currently on, :math:`r_k` is the distance | ||
travelled along the edge, :m ath:`d_k` is the destination node, and :math:`s_k` is |
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.
travelled along the edge, :m ath:`d_k` is the destination node, and :math:`s_k` is | |
travelled along the edge, :math:`d_k` is the destination node, and :math:`s_k` is |
stonesoup/models/transition/graph.py
Outdated
v_dest = dict() | ||
for edge in unique_edges: | ||
# Filter paths that contain the edge | ||
filtered_paths = filter(lambda x: np.any(x[1] == edge), s_paths.items()) | ||
v_dest_tmp = {dest for (_, dest), _ in filtered_paths} | ||
if len(v_dest_tmp): | ||
try: | ||
v_dest[edge] |= v_dest_tmp | ||
except KeyError: | ||
v_dest[edge] = v_dest_tmp | ||
|
||
# Perform destination sampling | ||
resample_inds = np.flatnonzero( | ||
np.random.binomial(1, float(self.destination_resample_probability), num_particles) | ||
) | ||
for i in resample_inds: | ||
try: | ||
v_dest_tmp = list(v_dest[edges[i]]) | ||
except KeyError: | ||
# If no valid destinations exist for the current edge, keep the current | ||
# destination | ||
continue | ||
new_state_vectors[-2, i] = np.random.choice(v_dest_tmp) |
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.
I think this reads a little better vs. temp variables. Also change np.random.choice
to self.random_state.choice
.
v_dest = dict() | |
for edge in unique_edges: | |
# Filter paths that contain the edge | |
filtered_paths = filter(lambda x: np.any(x[1] == edge), s_paths.items()) | |
v_dest_tmp = {dest for (_, dest), _ in filtered_paths} | |
if len(v_dest_tmp): | |
try: | |
v_dest[edge] |= v_dest_tmp | |
except KeyError: | |
v_dest[edge] = v_dest_tmp | |
# Perform destination sampling | |
resample_inds = np.flatnonzero( | |
np.random.binomial(1, float(self.destination_resample_probability), num_particles) | |
) | |
for i in resample_inds: | |
try: | |
v_dest_tmp = list(v_dest[edges[i]]) | |
except KeyError: | |
# If no valid destinations exist for the current edge, keep the current | |
# destination | |
continue | |
new_state_vectors[-2, i] = np.random.choice(v_dest_tmp) | |
v_dest = defaultdict(set) | |
for edge in unique_edges: | |
# Filter paths that contain the edge | |
filtered_paths = filter(lambda x: np.any(x[1] == edge), s_paths.items()) | |
v_dest[edge] |= {dest for (_, dest), _ in filtered_paths} | |
# Perform destination sampling | |
resample_inds = np.flatnonzero( | |
np.random.binomial(1, float(self.destination_resample_probability), num_particles) | |
) | |
for i in resample_inds: | |
dests = v_dest[edges[i]] | |
# If no valid destinations exist for the current edge, keep the current | |
# destination | |
if dests: | |
new_state_vectors[-2, i] = self.random_state.choice(list(dests)) |
setup.cfg
Outdated
geopandas | ||
shapely | ||
networkx |
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.
Wondering if this should be optional
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.
I have added these under a new "roadnet" optional deps group. However, now the road net tests are getting skipped. Should I add also these to the "dev" dependencies, or should I modify the CircleCI config to install with "roadnet" deps?
stonesoup/models/transition/graph.py
Outdated
|
||
# Perform destination sampling | ||
resample_inds = np.flatnonzero( | ||
np.random.binomial(1, float(self.destination_resample_probability), num_particles) |
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.
np.random.binomial(1, float(self.destination_resample_probability), num_particles) | |
self.random_state.binomial(1, float(self.destination_resample_probability), num_particles) |
stonesoup/models/transition/graph.py
Outdated
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
self.random_state = np.random.RandomState(self.seed) if self.seed is not None else None |
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.
self.random_state = np.random.RandomState(self.seed) if self.seed is not None else None | |
if self.seed is not None: | |
self.random_state = np.random.RandomState(self.seed) | |
else: | |
self.random_state = np.random.mtrand._rand |
… and remove use of temp variables
This PR aims to add the following:
RoadNetwork
type:networkx.DiGraph
, with some limitations on the allowed node and edge attributes, and some additional methods.OptimalPathToDestinationTransitionModel
transition model:OptimalPathToDestinationMeasurementModel
measurement model:TODO