-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use transonic to optimize cost and heuristic functions for A*
- Loading branch information
1 parent
50b6757
commit 69ae9b6
Showing
17 changed files
with
441 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ venv | |
dist | ||
build | ||
rr30a_s0_ch2.tif | ||
__pythran__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .cost import Cost | ||
from .reciprocal import Reciprocal | ||
from .reciprocal import Reciprocal | ||
from .reciprocal_transonic import ReciprocalTransonic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
from transonic import boost | ||
|
||
from brightest_path_lib.cost import Cost | ||
|
||
@boost | ||
class ReciprocalTransonic(Cost): | ||
"""Uses the reciprocal of pixel/voxel intensity to compute the cost of moving | ||
to a neighboring point | ||
Parameters | ||
---------- | ||
min_intensity : float | ||
The minimum intensity a pixel/voxel can have in a given image | ||
max_intensity : float | ||
The maximum intensity a pixel/voxel can have in a given image | ||
Attributes | ||
---------- | ||
RECIPROCAL_MIN : float | ||
To cope with zero intensities, RECIPROCAL_MIN is added to the intensities | ||
in the range before reciprocal calculation | ||
RECIPROCAL_MAX : float | ||
We set the maximum intensity <= RECIPROCAL_MAX so that the intensity | ||
is between RECIPROCAL MIN and RECIPROCAL_MAX | ||
""" | ||
|
||
min_intensity: float | ||
max_intensity: float | ||
RECIPROCAL_MIN: float | ||
RECIPROCAL_MAX: float | ||
_min_step_cost: float | ||
|
||
def __init__(self, min_intensity: float, max_intensity: float) -> None: | ||
super().__init__() | ||
if min_intensity is None or max_intensity is None: | ||
raise TypeError | ||
if min_intensity > max_intensity: | ||
raise ValueError | ||
self.min_intensity = min_intensity | ||
self.max_intensity = max_intensity | ||
self.RECIPROCAL_MIN = float(1E-6) | ||
self.RECIPROCAL_MAX = 255.0 | ||
self._min_step_cost = 1.0 / self.RECIPROCAL_MAX | ||
|
||
|
||
@boost | ||
def cost_of_moving_to(self, intensity_at_new_point: float) -> float: | ||
"""calculates the cost of moving to a point | ||
Parameters | ||
---------- | ||
intensity_at_new_point : float | ||
The intensity of the new point under consideration | ||
Returns | ||
------- | ||
float | ||
the cost of moving to the new point | ||
Notes | ||
----- | ||
- To cope with zero intensities, RECIPROCAL_MIN is added to the intensities in the range before reciprocal calculation | ||
- We set the maximum intensity <= RECIPROCAL_MAX so that the intensity is between RECIPROCAL MIN and RECIPROCAL_MAX | ||
""" | ||
if intensity_at_new_point > self.max_intensity: | ||
raise ValueError | ||
|
||
intensity_at_new_point = self.RECIPROCAL_MAX * (intensity_at_new_point - self.min_intensity) / (self.max_intensity - self.min_intensity) | ||
|
||
if intensity_at_new_point < self.RECIPROCAL_MIN: | ||
intensity_at_new_point = self.RECIPROCAL_MIN | ||
|
||
return 1.0 / intensity_at_new_point | ||
|
||
@boost | ||
def minimum_step_cost(self) -> float: | ||
"""calculates the minimum step cost | ||
Returns | ||
------- | ||
float | ||
the minimum step cost | ||
""" | ||
return self._min_step_cost |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .heuristic import Heuristic | ||
from .euclidean import Euclidean | ||
from .euclidean_transonic import EuclideanTransonic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.