Feature¶
Feature module holds base implementation for features,
Feature
, that creative agents have in their
rulesets.
-
class
creamas.rules.feature.
Feature
(name, domains, rtype)[source]¶ Base feature class that is callable after initialization.
Each feature value takes as an input an artifact, and returns feature’s value for that artifact. If artifact type is not supported, feature’s evaluation should return
None
.Returned feature values can be of any type, but rules (
Rule
) should have appropriate mappers to map possible feature values to the interval [-1, 1].Usage example:
from myfeat import MyFeature from myartifact import MyArtifact myart = MyArtifact(*myparams) myart.domain = mytype f = MyFeature() mytype in f.domains == True # True ret = f(myart) type(ret) == f.rtype # True
- Parameters
-
extract
(artifact)[source]¶ Extract feature’s value from an artifact.
If artifact with a domain not in
domains
is used as a parameter, the function should returnNone
.Note
Dummy implementation, override in a subclass.
- Returns
Value extracted from the artifact.
- Return type
rtype
or None- Raises
NotImplementedError – if not overridden in subclass
-
property
domains
¶ Set of acceptable artifact domains for this feature.
When artifacts with other domains are used as parameters for
extract()
, the function should returnNone
.
-
property
name
¶ Human readable name of the feature.
-
property
rtype
¶ Value type returned by this feature.