Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
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
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Leipzig Machine Learning Group
conML
python
Commits
a0eab2f7
Commit
a0eab2f7
authored
5 years ago
by
dmt
Browse files
Options
Downloads
Patches
Plain Diff
Log the construction result.
parent
bc7521aa
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
cml/domain/construction.py
+40
-16
40 additions, 16 deletions
cml/domain/construction.py
with
40 additions
and
16 deletions
cml/domain/construction.py
+
40
−
16
View file @
a0eab2f7
from
functools
import
partial
from
cml.shared.parameter
import
PROTOCOL_LEVEL
__all__
=
(
"
Constructor
"
,
)
def
log_construction
(
func
):
def
wrapper
(
self
,
learnblock
):
for
complete_learnblock
in
func
(
self
,
learnblock
):
if
self
.
logger
and
self
.
logger
.
level
==
PROTOCOL_LEVEL
:
self
.
logger
.
protocol
(
"
\t
"
.
join
([
""
,
str
(
complete_learnblock
.
length
),
str
(
complete_learnblock
.
min_timestamp
),
str
(
complete_learnblock
.
max_timestamp
),
str
(
complete_learnblock
.
relatives
),
str
(
complete_learnblock
.
n_cluster
),
str
(
complete_learnblock
.
feature_count
)
]))
yield
complete_learnblock
return
wrapper
def
update_construction
(
func
):
def
wrapper
(
self
,
value
):
func
(
self
,
value
)
...
...
@@ -16,11 +37,13 @@ def update_construction(func):
class
Constructor
:
def
__init__
(
self
,
ml_models
,
settings
):
self
.
logger
=
None
self
.
settings
=
settings
self
.
ml_models
=
ml_models
self
.
_logging_dir
=
None
self
.
_construction
=
None
self
.
_construction_type
=
"
conceptual
"
@log_construction
def
construct
(
self
,
learnblock
):
for
block
in
self
.
_construction
(
learnblock
):
yield
block
...
...
@@ -63,20 +86,18 @@ class Constructor:
@property
def
construction_type
(
self
):
return
self
.
_
construct
ion
_type
return
self
.
settings
.
construct_type
@construction_type.setter
def
construction_type
(
self
,
construct_type
):
if
construct_type
==
"
conceptual
"
:
self
.
_construction_type
=
construct_type
if
self
.
settings
.
construct_type
==
"
conceptual
"
:
self
.
_construction
=
partial
(
self
.
_construct_conceptual_knowledge
,
categorial_complexity
=
self
.
settings
.
max_categories
,
min_category_size
=
self
.
settings
.
min_category_size
,
)
elif
construct_type
==
"
procedural
"
:
self
.
_construction_type
=
construct_type
elif
self
.
settings
.
construct_type
==
"
procedural
"
:
self
.
_construction
=
partial
(
self
.
_construct_procedural_knowledge
,
procedural_complexity
=
self
.
settings
.
max_model_targets
,
...
...
@@ -92,26 +113,29 @@ class Constructor:
categorial_complexity
=
None
,
min_category_size
=
None
):
for
ml_model
in
self
.
ml_models
:
for
cluster_number
in
range
(
2
,
categorial_complexity
):
for
cluster_number
in
range
(
2
,
categorial_complexity
+
1
):
ml_model
.
cluster
=
cluster_number
trained_model
=
ml_model
.
train
(
learnblock
)
for
cluster
,
size
in
trained_model
.
cluster_sizes
.
items
():
print
(
cluster
,
size
)
if
size
<
min_category_size
:
continue
labels
=
trained_model
.
get_labels
()
labeld_learnblock
=
learnblock
.
set_labels
(
labels
)
yield
labeld_learnblock
labeled_learnblock
=
learnblock
.
set_labels
(
labels
)
labeled_learnblock
.
n_cluster
=
cluster_number
yield
labeled_learnblock
def
_construct_procedural_knowledge
(
self
,
learnblock
,
procedural_complexity
=
None
,
max_target_error
=
None
):
for
ml_model
in
self
.
ml_models
:
for
target_number
in
range
(
2
,
procedural_complexity
):
ml_model
.
target_number
=
target_number
trained_model
=
ml_model
.
train
(
learnblock
)
for
target_number
in
range
(
2
,
procedural_complexity
+
1
):
model
=
ml_model
()
model
.
io_shape
=
learnblock
.
learn_rows
model
.
target_number
=
target_number
trained_model
=
model
.
train
(
learnblock
.
as_numpy_array
())
if
trained_model
.
target_error
<
max_target_error
:
labeld_learnblock
=
learnblock
.
set_labels
(
trained_model
)
yield
labeld_learnblock
for
labels
in
trained_model
.
targets
:
labeled_learnblock
=
learnblock
.
set_labels
(
list
(
labels
))
labeled_learnblock
.
n_cluster
=
target_number
yield
labeled_learnblock
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