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
582bd4ff
Commit
582bd4ff
authored
5 years ago
by
dmt
Browse files
Options
Downloads
Patches
Plain Diff
Implement the construction logic for conceptual knowledge finding.
parent
fa36ef69
No related branches found
Branches containing commit
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
+110
-2
110 additions, 2 deletions
cml/domain/construction.py
with
110 additions
and
2 deletions
cml/domain/construction.py
+
110
−
2
View file @
582bd4ff
from
functools
import
partial
__all__
=
(
"
Construct
ion
"
"
Construct
or
"
,
)
def
update_construction
(
func
):
def
wrapper
(
self
,
value
):
func
(
self
,
value
)
self
.
construction_type
=
self
.
construction_type
return
wrapper
class
Constructor
:
pass
def
__init__
(
self
,
ml_models
,
settings
):
self
.
settings
=
settings
self
.
ml_models
=
ml_models
self
.
_construction
=
None
self
.
_construction_type
=
"
conceptual
"
def
construct
(
self
,
learnblock
):
for
block
in
self
.
_construction
(
learnblock
):
yield
block
@property
def
max_target_error
(
self
):
return
self
.
settings
.
max_target_error
@max_target_error.setter
@update_construction
def
max_target_error
(
self
,
value
):
self
.
settings
.
max_target_error
=
value
@property
def
max_model_targets
(
self
):
return
self
.
settings
.
max_model_targets
@max_model_targets.setter
@update_construction
def
max_model_targets
(
self
,
value
):
self
.
settings
.
max_model_targets
=
value
@property
def
min_category_size
(
self
):
return
self
.
settings
.
min_category_size
@min_category_size.setter
@update_construction
def
min_category_size
(
self
,
value
):
self
.
settings
.
min_category_size
=
value
@property
def
max_categories
(
self
):
return
self
.
settings
.
max_categories
@max_categories.setter
def
max_categories
(
self
,
value
):
self
.
settings
.
max_categories
=
value
self
.
construction_type
=
self
.
construction_type
@property
def
construction_type
(
self
):
return
self
.
_construction_type
@construction_type.setter
def
construction_type
(
self
,
construct_type
):
if
construct_type
==
"
conceptual
"
:
self
.
_construction_type
=
construct_type
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
self
.
_construction
=
partial
(
self
.
_construct_procedural_knowledge
,
procedural_complexity
=
self
.
settings
.
max_model_targets
,
max_target_error
=
self
.
settings
.
max_target_error
)
else
:
# TODO (dmt): Provide proper exception handling.
raise
Exception
(
"
Provide valid construction type.
"
)
def
_construct_conceptual_knowledge
(
self
,
learnblock
,
categorial_complexity
=
None
,
min_category_size
=
None
):
for
ml_model
in
self
.
ml_models
:
for
cluster_number
in
range
(
2
,
categorial_complexity
):
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
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
)
if
trained_model
.
target_error
<
max_target_error
:
labeld_learnblock
=
learnblock
.
set_labels
(
trained_model
)
yield
labeld_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