Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
apollon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Blaß, Michael
apollon
Commits
feef5375
Commit
feef5375
authored
Aug 4, 2020
by
Blaß, Michael
Browse files
Options
Downloads
Patches
Plain Diff
Moved SOM shape attribute to SomGrid
parent
b033d3ea
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/apollon/som/som.py
+12
-14
12 additions, 14 deletions
src/apollon/som/som.py
with
12 additions
and
14 deletions
src/apollon/som/som.py
+
12
−
14
View file @
feef5375
# Licensed under the terms of the BSD-3-Clause license.
# Licensed under the terms of the BSD-3-Clause license.
# Copyright (C) 2019 Michael Blaß
# Copyright (C) 2019 Michael Blaß
# mblass@posteo.net
# mblass@posteo.net
import
collections
from
typing
import
Dict
,
List
,
Optional
,
Tuple
from
typing
import
Dict
,
List
,
Optional
,
Tuple
import
numpy
as
np
import
numpy
as
np
...
@@ -16,7 +15,11 @@ from .. types import Array, Shape, Coord
...
@@ -16,7 +15,11 @@ from .. types import Array, Shape, Coord
class
SomGrid
:
class
SomGrid
:
def
__init__
(
self
,
shape
:
Shape
):
def
__init__
(
self
,
shape
:
Shape
)
->
None
:
if
not
all
(
isinstance
(
val
,
int
)
and
val
>=
1
for
val
in
shape
):
raise
ValueError
(
'
Dimensions must be integer > 0.
'
)
self
.
shape
=
shape
self
.
pos
=
np
.
asarray
(
list
(
np
.
ndindex
(
shape
)),
dtype
=
int
)
self
.
pos
=
np
.
asarray
(
list
(
np
.
ndindex
(
shape
)),
dtype
=
int
)
self
.
tree
=
cKDTree
(
self
.
pos
)
self
.
tree
=
cKDTree
(
self
.
pos
)
self
.
rows
,
self
.
cols
=
np
.
indices
(
shape
)
self
.
rows
,
self
.
cols
=
np
.
indices
(
shape
)
...
@@ -63,12 +66,8 @@ class SomBase:
...
@@ -63,12 +66,8 @@ class SomBase:
nhr
:
float
,
nh_shape
:
str
,
init_distr
:
str
,
metric
:
str
,
nhr
:
float
,
nh_shape
:
str
,
init_distr
:
str
,
metric
:
str
,
seed
:
Optional
[
float
]
=
None
):
seed
:
Optional
[
float
]
=
None
):
# check dimensions
self
.
_grid
=
SomGrid
(
dims
[:
2
])
for
d
in
dims
:
self
.
n_features
=
dims
[
2
]
if
not
isinstance
(
d
,
int
)
or
not
d
>=
1
:
raise
ValueError
(
'
Dimensions must be integer > 0.
'
)
self
.
_dims
=
dims
self
.
_hit_counts
=
np
.
zeros
(
self
.
n_units
)
self
.
_hit_counts
=
np
.
zeros
(
self
.
n_units
)
self
.
n_iter
=
n_iter
self
.
n_iter
=
n_iter
self
.
metric
=
metric
self
.
metric
=
metric
...
@@ -110,28 +109,27 @@ class SomBase:
...
@@ -110,28 +109,27 @@ class SomBase:
raise
ValueError
(
f
'
Unknown initializer
"
{
init_distr
}
"
. Use
'
raise
ValueError
(
f
'
Unknown initializer
"
{
init_distr
}
"
. Use
'
'"
uniform
"
,
"
simplex
"
, or
"
pca
"
.
'
)
'"
uniform
"
,
"
simplex
"
, or
"
pca
"
.
'
)
self
.
_grid
=
SomGrid
(
self
.
shape
)
self
.
_dists
:
Optional
[
Array
]
=
None
self
.
_dists
:
Optional
[
Array
]
=
None
@property
@property
def
dims
(
self
)
->
Tuple
[
int
,
int
,
int
]:
def
dims
(
self
)
->
Tuple
[
int
,
int
,
int
]:
"""
Return the SOM dimensions.
"""
"""
Return the SOM dimensions.
"""
return
self
.
_
dims
return
(
*
self
.
_
grid
.
shape
,
self
.
n_features
)
@property
@property
def
dx
(
self
)
->
int
:
def
dx
(
self
)
->
int
:
"""
Return the number of units along the first dimension.
"""
"""
Return the number of units along the first dimension.
"""
return
self
.
dims
[
0
]
return
self
.
_grid
.
shape
[
0
]
@property
@property
def
dy
(
self
)
->
int
:
def
dy
(
self
)
->
int
:
"""
Return the number of units along the second dimension.
"""
"""
Return the number of units along the second dimension.
"""
return
self
.
dims
[
1
]
return
self
.
_grid
.
shape
[
1
]
@property
@property
def
dw
(
self
)
->
int
:
def
dw
(
self
)
->
int
:
"""
Return the dimension of the weight vectors.
"""
"""
Return the dimension of the weight vectors.
"""
return
self
.
dims
[
2
]
return
self
.
n_features
@property
@property
def
n_units
(
self
)
->
int
:
def
n_units
(
self
)
->
int
:
...
@@ -141,7 +139,7 @@ class SomBase:
...
@@ -141,7 +139,7 @@ class SomBase:
@property
@property
def
shape
(
self
)
->
Shape
:
def
shape
(
self
)
->
Shape
:
"""
Return the map shape.
"""
"""
Return the map shape.
"""
return
(
self
.
dx
,
self
.
dy
)
return
self
.
_grid
.
shape
@property
@property
def
grid
(
self
)
->
Array
:
def
grid
(
self
)
->
Array
:
...
...
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