Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
navipy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
Olivier Bertrand
navipy
Commits
394c53bc
Commit
394c53bc
authored
7 years ago
by
Luise Odenthal
Browse files
Options
Downloads
Patches
Plain Diff
added comparison init
parent
6a895ea7
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
navipy/comparing/__init__.py
+101
-0
101 additions, 0 deletions
navipy/comparing/__init__.py
with
101 additions
and
0 deletions
navipy/comparing/__init__.py
+
101
−
0
View file @
394c53bc
...
@@ -6,6 +6,87 @@ memorised places.
...
@@ -6,6 +6,87 @@ memorised places.
import
numpy
as
np
import
numpy
as
np
from
navipy.processing.tools
import
is_ibpc
,
is_obpc
from
navipy.processing.tools
import
is_ibpc
,
is_obpc
def
is_numeric_array
(
array
):
"""
Checks if the dtype of the array is numeric.
Booleans, unsigned integer, signed integer, floats and complex are
considered numeric.
Parameters
----------
array : `numpy.ndarray`-like
The array to check.
Returns
-------
is_numeric : `bool`
True if it is a recognized numerical and False if object or
string.
"""
numerical_dtype_kinds
=
{
'
b
'
,
# boolean
'
u
'
,
# unsigned integer
'
i
'
,
# signed integer
'
f
'
,
# floats
'
c
'
}
# complex
try
:
return
array
.
dtype
.
kind
in
numerical_dtype_kinds
except
AttributeError
:
# in case it's not a numpy array it will probably have no dtype.
return
np
.
asarray
(
array
).
dtype
.
kind
in
numerical_dtype_kinds
def
check_scene
(
scene
):
if
is_ibpc
(
scene
):
# print("normal")
assert
is_numeric_array
(
scene
)
# np.isscalar(scene)
assert
~
np
.
any
(
np
.
isnan
(
scene
))
assert
len
(
scene
.
shape
)
==
4
assert
(
scene
.
shape
[
1
]
>
0
)
assert
(
scene
.
shape
[
0
]
>
0
)
assert
(
scene
.
shape
[
2
]
==
4
)
assert
(
scene
.
shape
[
3
]
==
1
)
# assert ~(np.any(np.isNone(scene)))
elif
is_obpc
(
scene
):
assert
is_numeric_array
(
scene
)
# np.isscalar(scene)
assert
~
np
.
any
(
np
.
isnan
(
scene
))
assert
len
(
scene
.
shape
)
==
3
assert
~
(
scene
.
shape
[
1
]
<=
0
)
assert
~
(
scene
.
shape
[
0
]
<=
0
)
assert
(
scene
.
shape
[
2
]
==
4
)
assert
(
scene
.
shape
[
3
]
==
1
)
# assert ~(np.any(np.isNone(scene)))
def
simple_imagediff
(
current
,
memory
):
"""
Compute the root mean square difference between
the current and memorised place code
:param current: current place code
:param memory: memorised place code
:returns: the image difference
:rtype: float
..ref: Zeil, J., 2012. Visual homing: an insect perspective.
Current opinion in neurobiology
"""
assert
isinstance
(
current
,
np
.
ndarray
),
\
'
current place code should be a numpy array
'
assert
isinstance
(
memory
,
np
.
ndarray
),
\
'
memory place code should be a numpy array
'
assert
np
.
all
(
current
.
shape
==
memory
.
shape
),
\
'
memory and current place code should have the same shape
'
assert
check_scene
(
current
)
assert
check_scene
(
memory
)
diff
=
current
-
memory
if
is_ibpc
(
current
):
return
diff
elif
is_obpc
(
current
):
return
diff
else
:
raise
TypeError
(
'
place code is neither an ibpc nor obpc
'
)
def
imagediff
(
current
,
memory
):
def
imagediff
(
current
,
memory
):
"""
Compute the root mean square difference between
"""
Compute the root mean square difference between
...
@@ -26,6 +107,8 @@ the current and memorised place code
...
@@ -26,6 +107,8 @@ the current and memorised place code
'
memory place code should be a numpy array
'
'
memory place code should be a numpy array
'
assert
np
.
all
(
current
.
shape
==
memory
.
shape
),
\
assert
np
.
all
(
current
.
shape
==
memory
.
shape
),
\
'
memory and current place code should have the same shape
'
'
memory and current place code should have the same shape
'
assert
check_scene
(
current
)
assert
check_scene
(
memory
)
diff
=
np
.
power
(
current
-
memory
,
2
)
diff
=
np
.
power
(
current
-
memory
,
2
)
if
is_ibpc
(
current
):
if
is_ibpc
(
current
):
return
np
.
sqrt
(
diff
.
mean
(
axis
=
0
).
mean
(
axis
=
1
))
return
np
.
sqrt
(
diff
.
mean
(
axis
=
0
).
mean
(
axis
=
1
))
...
@@ -51,8 +134,26 @@ the current and memorised place code.
...
@@ -51,8 +134,26 @@ the current and memorised place code.
"""
"""
assert
is_ibpc
(
current
),
\
assert
is_ibpc
(
current
),
\
'
The current and memory place code should be image based
'
'
The current and memory place code should be image based
'
assert
check_scene
(
current
)
assert
check_scene
(
memory
)
ridf
=
np
.
zeros
(
current
.
shape
[
1
])
ridf
=
np
.
zeros
(
current
.
shape
[
1
])
for
azimuth_i
in
range
(
0
,
current
.
shape
[
1
]):
for
azimuth_i
in
range
(
0
,
current
.
shape
[
1
]):
rot_im
=
np
.
roll
(
current
,
azimuth_i
,
axis
=
1
)
rot_im
=
np
.
roll
(
current
,
azimuth_i
,
axis
=
1
)
rot_im
[
azimuth_i
]
=
imagediff
(
rot_im
,
memory
)
rot_im
[
azimuth_i
]
=
imagediff
(
rot_im
,
memory
)
return
ridf
return
ridf
def
diff_optic_flow
(
current
,
memory
):
currrol
=
np
.
roll
(
current
,
1
,
axis
=
1
)
dx
=
current
-
currroll
memrrol
=
np
.
roll
(
memory
,
1
,
axis
=
1
)
dy
=
memory
-
memroll
dy
=
np
.
reshape
(
dy
,
(
np
.
prod
(
dy
.
shape
),
1
))
dx
=
np
.
reshape
(
dx
,
(
np
.
prod
(
dx
.
shape
),
1
))
di
=
current
-
memory
di
=
np
.
reshape
(
di
,
(
np
.
prod
(
di
.
shape
),
1
))
A
=
np
.
column_stack
(
dy
,
dx
)
ATA
=
np
.
dot
(
np
.
transpose
(
A
),
A
)
b
=
np
.
dot
(
np
.
transpose
(
A
),
di
)
res
=
numpy
.
linalg
.
solve
(
ATA
,
b
)
return
res
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment