Feature¶
Feature module holds base implementation for features,
Feature
, which creative agents have in their
rule sets considering artifacts.
-
class
creamas.rules.feature.
Feature
(name, domains, rtype)[source]¶ Base feature class that is callable after initialization.
Each feature 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, **kwargs)[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
.- Returns
Value extracted from the artifact.
- Return type
rtype
or None
-
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.