Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mhc_rank
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Show more breadcrumbs
Patrick Skillman-Lawrence
mhc_rank
Commits
1c1e75c6
Commit
1c1e75c6
authored
8 years ago
by
Tim O'Donnell
Browse files
Options
Downloads
Patches
Plain Diff
Simpler cache handling
parent
337b1039
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
mhcflurry/antigen_presentation/presentation_component_models/presentation_component_model.py
+18
-23
18 additions, 23 deletions
...entation_component_models/presentation_component_model.py
with
18 additions
and
23 deletions
mhcflurry/antigen_presentation/presentation_component_models/presentation_component_model.py
+
18
−
23
View file @
1c1e75c6
...
@@ -21,8 +21,6 @@ def cache_dict_for_policy(policy):
...
@@ -21,8 +21,6 @@ def cache_dict_for_policy(policy):
class
PresentationComponentModel
(
object
):
class
PresentationComponentModel
(
object
):
cache_fields
=
[
"
cached_fits
"
,
"
cached_predictions
"
]
'''
'''
Base class for inputs to a
"
final model
"
. By
"
final model
"
we mean
Base class for inputs to a
"
final model
"
. By
"
final model
"
we mean
something like a logistic regression model that takes as input expression,
something like a logistic regression model that takes as input expression,
...
@@ -31,9 +29,24 @@ class PresentationComponentModel(object):
...
@@ -31,9 +29,24 @@ class PresentationComponentModel(object):
'''
'''
def
__init__
(
def
__init__
(
self
,
fit_cache_policy
=
"
weak
"
,
predictions_cache_policy
=
"
weak
"
):
self
,
fit_cache_policy
=
"
weak
"
,
predictions_cache_policy
=
"
weak
"
):
self
.
cached_fits
=
cache_dict_for_policy
(
fit_cache_policy
)
self
.
fit_cache_policy
=
fit_cache_policy
self
.
predictions_cache_policy
=
predictions_cache_policy
self
.
reset_cache
()
def
reset_cache
(
self
):
self
.
cached_fits
=
cache_dict_for_policy
(
self
.
fit_cache_policy
)
self
.
cached_predictions
=
cache_dict_for_policy
(
self
.
cached_predictions
=
cache_dict_for_policy
(
predictions_cache_policy
)
self
.
predictions_cache_policy
)
def
__getstate__
(
self
):
d
=
dict
(
self
.
__dict__
)
d
[
"
cached_fits
"
]
=
None
d
[
"
cached_predictions
"
]
=
None
return
d
def
__setstate__
(
self
,
state
):
self
.
__dict__
.
update
(
state
)
self
.
reset_cache
()
def
column_names
(
self
):
def
column_names
(
self
):
"""
"""
...
@@ -98,19 +111,6 @@ class PresentationComponentModel(object):
...
@@ -98,19 +111,6 @@ class PresentationComponentModel(object):
print
(
"
Cache hit in clone_and_restore_fit: %s
"
%
str
(
self
))
print
(
"
Cache hit in clone_and_restore_fit: %s
"
%
str
(
self
))
return
result
return
result
def
__getstate__
(
self
):
d
=
dict
(
self
.
__dict__
)
# Don't pickle the cache variables, but remember what type they are.
for
key
in
PresentationComponentModel
.
cache_fields
:
d
[
key
]
=
type
(
d
[
key
])
return
d
def
__setstate__
(
self
,
state
):
self
.
__dict__
.
update
(
state
)
for
key
in
PresentationComponentModel
.
cache_fields
:
setattr
(
self
,
key
,
state
[
key
]())
def
fit
(
self
,
hits_df
):
def
fit
(
self
,
hits_df
):
"""
"""
Train the final model input.
Train the final model input.
...
@@ -229,14 +229,9 @@ class PresentationComponentModel(object):
...
@@ -229,14 +229,9 @@ class PresentationComponentModel(object):
self
.
cached_predictions
[
cache_key
]
=
return_value
self
.
cached_predictions
[
cache_key
]
=
return_value
return
return_value
return
return_value
def
fit_ensemble_and_predict
(
peptides_df
):
def
fit_ensemble_and_predict
(
self
,
peptides_df
):
raise
NotImplementedError
raise
NotImplementedError
def
reset_cache
(
self
):
for
key
in
PresentationComponentModel
.
cache_fields
:
obj_type
=
type
(
getattr
(
self
,
key
))
setattr
(
self
,
key
,
obj_type
())
def
clone
(
self
):
def
clone
(
self
):
"""
"""
Copy this object so that the original and copy can be fit
Copy this object so that the original and copy can be fit
...
...
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