-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PNE-6367] Add support for feature effects. #982
Merged
+153
−4
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "3.11.6" | ||
__version__ = "3.12.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from typing import Dict | ||
from uuid import UUID | ||
|
||
from citrine._rest.resource import Resource | ||
from citrine._serialization import properties | ||
|
||
|
||
class ShapleyMaterial(Resource): | ||
"""The feature effect of a material.""" | ||
|
||
material_id = properties.UUID('material_id', serializable=False) | ||
value = properties.Float('value', serializable=False) | ||
|
||
|
||
class ShapleyFeature(Resource): | ||
"""All feature effects for this feature by material.""" | ||
|
||
feature = properties.String('feature', serializable=False) | ||
materials = properties.List(properties.Object(ShapleyMaterial), 'materials', | ||
serializable=False) | ||
|
||
@property | ||
def material_dict(self) -> Dict[UUID, float]: | ||
"""Presents the feature's effects as a dictionary by material.""" | ||
return {material.material_id: material.value for material in self.materials} | ||
|
||
|
||
class ShapleyOutput(Resource): | ||
"""All feature effects for this output by feature.""" | ||
|
||
output = properties.String('output', serializable=False) | ||
features = properties.List(properties.Object(ShapleyFeature), 'features', serializable=False) | ||
|
||
@property | ||
def feature_dict(self) -> Dict[str, Dict[UUID, float]]: | ||
"""Presents the output's feature effects as a dictionary by feature.""" | ||
return {feature.feature: feature.material_dict for feature in self.features} | ||
|
||
|
||
class FeatureEffects(Resource): | ||
"""Captures information about the feature effects associated with a predictor.""" | ||
|
||
predictor_id = properties.UUID('metadata.predictor_id', serializable=False) | ||
predictor_version = properties.Integer('metadata.predictor_version', serializable=False) | ||
status = properties.String('metadata.status', serializable=False) | ||
failure_reason = properties.Optional(properties.String(), 'metadata.failure_reason', | ||
serializable=False) | ||
|
||
outputs = properties.Optional(properties.List(properties.Object(ShapleyOutput)), 'resultobj', | ||
serializable=False) | ||
|
||
@classmethod | ||
def _pre_build(cls, data: dict) -> Dict: | ||
shapley = data["result"] | ||
material_ids = shapley["materials"] | ||
|
||
outputs = [] | ||
for output, feature_dict in shapley["outputs"].items(): | ||
features = [] | ||
for feature, values in feature_dict.items(): | ||
items = zip(material_ids, values) | ||
materials = [{"material_id": mid, "value": value} for mid, value in items] | ||
features.append({ | ||
"feature": feature, | ||
"materials": materials | ||
}) | ||
|
||
outputs.append({"output": output, "features": features}) | ||
|
||
data["resultobj"] = outputs | ||
return data | ||
|
||
@property | ||
def as_dict(self) -> Dict[str, Dict[str, Dict[UUID, float]]]: | ||
"""Presents the feature effects as a dictionary by output.""" | ||
return {output.output: output.feature_dict for output in self.outputs} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,7 @@ class TableConfig(Resource["TableConfig"]): | |
The query used to define the materials underpinning this table | ||
generation_algorithm: TableFromGemdQueryAlgorithm | ||
Which algorithm was used to generate the config based on the GemdQuery results | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My local |
||
""" | ||
|
||
# FIXME (DML): rename this (this is dependent on the server side) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resource.py supports an
as_dict
method that is not a property. Does it need to be a property? I'm concerned about changing the signature on a derived class.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resource
doesn't defineas_dict
, justGEMDResource
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right. Not a sig collision.
Choice of property or method doesn't seem to have a consistent flavor in the library. This feels more like a method to me than a property, but acceptable as is if you feel strongly to the contrary.