:mod:`lookout.style.format.features` ==================================== .. py:module:: lookout.style.format.features .. autoapi-nested-parse:: Features definition. Module Contents --------------- .. data:: FEATURES_NUMPY_TYPE .. data:: FEATURES_MIN .. data:: FEATURES_MAX .. py:class:: FeatureGroup Bases::class:`enum.Enum` Feature groups. Each feature belongs to one and only one of these classes. .. attribute:: node :annotation: = 1 .. attribute:: left :annotation: = 2 .. attribute:: right :annotation: = 3 .. attribute:: parents :annotation: = 4 .. method:: format(self, value) Represent the feature group for user interfaces. The trailing dot is appended as needed. :param value: The feature group parameter. E.g., the index of the node for "left" and "right". :return: pretty-printed string, the trailing dot is appended as needed. .. method:: __lt__(self, other:'FeatureGroup') Compare two groups: am I less than the other. .. data:: FEATURE_GROUP_TYPES .. py:class:: FeatureId Bases::class:`enum.Enum` Feature identifiers. .. attribute:: diff_col :annotation: = 0 .. attribute:: diff_line :annotation: = 1 .. attribute:: diff_offset :annotation: = 2 .. attribute:: index_internal_type :annotation: = 3 .. attribute:: index_label :annotation: = 4 .. attribute:: index_reserved :annotation: = 5 .. attribute:: internal_type :annotation: = 6 .. attribute:: label :annotation: = 7 .. attribute:: reserved :annotation: = 8 .. attribute:: roles :annotation: = 9 .. attribute:: length :annotation: = 10 .. attribute:: start_col :annotation: = 11 .. attribute:: start_line :annotation: = 12 .. method:: __lt__(self, other:'FeatureId') Compare two identifiers: am I less than the other. This does not make much apart from ordering enums. .. data:: TV .. data:: Layout .. data:: MutableLayout .. data:: FeatureLayout .. data:: MutableFeatureLayout .. data:: TVFeature .. data:: TVAnyNode .. py:class:: Feature(*, language:str, labels_to_class_sequences:Sequence[Tuple[int, ...]], selected_indices:Optional[Sequence[int]]=None, **kwargs) Base type for features. .. attribute:: id .. attribute:: selected_indices Return the sequence of selected indices. .. attribute:: selected_indices_index Return the set of selected indices. .. attribute:: selected_names Return the names of the features this Feature computes (after feature selection). .. attribute:: names Return the names of the features this Feature computes (before feature selection). .. attribute:: selected_names_index Return the index of a name to its position (after feature selection). .. method:: __call__(self, neighbours:Layout[Sequence[Optional[AnyNode]]]) Compute the relevant values for this feature. This method only creates the resulting array and delegates the filling to subclasses. :param neighbours: Neighbouring nodes to the current sample. :return: Numpy array containing the feature values. 2-dimensional. .. staticmethod:: _clip_int(integer:int) .. method:: _compute(self, neighbours:Layout[Sequence[Optional[AnyNode]]]) .. py:class:: MultipleValuesFeature Bases::class:`lookout.style.format.features.Feature` Base type for features that produce multiple values. .. py:class:: CategoricalFeature Bases::class:`lookout.style.format.features.MultipleValuesFeature` Base type for features that have a one hot encoded value. .. py:class:: BagFeature Bases::class:`lookout.style.format.features.MultipleValuesFeature` Base type for features that have multiple values. .. py:class:: OrdinalFeature(**kwargs) Bases::class:`lookout.style.format.features.Feature` Base type for ordinal features. .. py:class:: NeighbourFeature(neighbour_group:FeatureGroup, neighbour_index:int, **kwargs) Bases::class:`lookout.style.format.features.Feature`, :class:`Generic[TVAnyNode]` Base type for features that focus on a node among the neighbours of the current node. .. method:: _convert_nodes(self, nodes:Sequence[Optional[AnyNode]]) .. method:: _check_whitelist(self) .. py:class:: ComparisonFeature Bases::class:`NeighbourFeature[TVAnyNode]` Base type for features that compare the current node to one of its neighbours. .. method:: _compute(self, neighbours:Layout[Sequence[Optional[AnyNode]]]) Focus on the relevant nodes and compute the feature values. .. method:: _focused_compute(self, nodes:Sequence[VirtualNode], neighbours:Sequence[Optional[TVAnyNode]]) Compute the feature values. .. method:: _compute_row(self, node:VirtualNode, neighbour:TVAnyNode) Compute the feature value(s) for a given node and its neighbour. .. py:class:: VirtualNodeComparisonFeature Bases::class:`ComparisonFeature[VirtualNode]` Base type for Feature-s that compare the current virtual node to another virtual node. .. attribute:: target_type .. py:class:: NodeFeature Bases::class:`NeighbourFeature[TVAnyNode]` Base type for features that compute a property of a single node. .. method:: _compute(self, neighbours:Layout[Sequence[Optional[AnyNode]]]) Focus on the relevant nodes and compute the feature values. .. method:: _focused_compute(self, nodes:Sequence[Optional[TVAnyNode]]) Compute the feature values. .. method:: _compute_row(self, node:TVAnyNode) Compute the feature value(s) for a given node. .. py:class:: VirtualNodeFeature Bases::class:`NodeFeature[VirtualNode]` Base type for Feature-s computed on a virtual node per sample. .. attribute:: target_type .. py:class:: BblfshNodeFeature Bases::class:`NodeFeature[bblfsh.Node]` Base type for Feature-s computed on a bblfsh node per sample. .. attribute:: target_type .. data:: FEATURE_CLASSES .. function:: register_feature(cls:Type[TVFeature]) Register features in the __features__ module attribute. .. py:class:: _FeatureDiffCol Bases::class:`lookout.style.format.features.OrdinalFeature`, :class:`lookout.style.format.features.VirtualNodeComparisonFeature` .. attribute:: id .. attribute:: feature_groups_whitelist .. method:: _compute_row(self, node:VirtualNode, neighbour:VirtualNode) .. py:class:: _FeatureDiffLine Bases::class:`lookout.style.format.features.OrdinalFeature`, :class:`lookout.style.format.features.VirtualNodeComparisonFeature` .. attribute:: id .. attribute:: feature_groups_whitelist .. method:: _compute_row(self, node:VirtualNode, neighbour:VirtualNode) .. py:class:: _FeatureDiffOffset Bases::class:`lookout.style.format.features.OrdinalFeature`, :class:`lookout.style.format.features.VirtualNodeComparisonFeature` .. attribute:: id .. attribute:: feature_groups_whitelist .. method:: _compute_row(self, node:VirtualNode, neighbour:VirtualNode) .. py:class:: _FeatureIndexInternalType Bases::class:`lookout.style.format.features.OrdinalFeature`, :class:`lookout.style.format.features.BblfshNodeFeature` .. attribute:: id .. method:: _compute_row(self, node:bblfsh.Node) .. py:class:: _FeatureIndexLabel Bases::class:`lookout.style.format.features.OrdinalFeature`, :class:`lookout.style.format.features.VirtualNodeFeature` .. attribute:: id .. attribute:: feature_groups_whitelist .. method:: _compute_row(self, node:VirtualNode) .. py:class:: _FeatureIndexReserved Bases::class:`lookout.style.format.features.OrdinalFeature`, :class:`lookout.style.format.features.VirtualNodeFeature` .. attribute:: id .. method:: _compute_row(self, node:VirtualNode) .. py:class:: _FeatureInternalType(**kwargs) Bases::class:`lookout.style.format.features.CategoricalFeature`, :class:`lookout.style.format.features.BblfshNodeFeature` .. attribute:: id .. method:: _compute_row(self, node:bblfsh.Node) .. py:class:: _FeatureLabel(**kwargs) Bases::class:`lookout.style.format.features.BagFeature`, :class:`lookout.style.format.features.VirtualNodeFeature` .. attribute:: id .. attribute:: feature_groups_whitelist .. method:: _compute_row(self, node:VirtualNode) .. py:class:: _FeatureReserved(**kwargs) Bases::class:`lookout.style.format.features.CategoricalFeature`, :class:`lookout.style.format.features.VirtualNodeFeature` .. attribute:: id .. method:: _compute_row(self, node:VirtualNode) .. py:class:: _FeatureRoles(**kwargs) Bases::class:`lookout.style.format.features.BagFeature`, :class:`lookout.style.format.features.BblfshNodeFeature` .. attribute:: id .. method:: _compute_row(self, node:bblfsh.Node) .. py:class:: _FeatureLength Bases::class:`lookout.style.format.features.OrdinalFeature`, :class:`lookout.style.format.features.VirtualNodeFeature` .. attribute:: id .. attribute:: feature_groups_whitelist .. method:: _compute_row(self, node:VirtualNode) .. py:class:: _FeatureStartCol Bases::class:`lookout.style.format.features.OrdinalFeature`, :class:`lookout.style.format.features.VirtualNodeFeature` .. attribute:: id .. attribute:: feature_groups_whitelist .. method:: _compute_row(self, node:VirtualNode) .. py:class:: _FeatureStartLine Bases::class:`lookout.style.format.features.OrdinalFeature`, :class:`lookout.style.format.features.VirtualNodeFeature` .. attribute:: id .. attribute:: feature_groups_whitelist .. method:: _compute_row(self, node:VirtualNode)