diff options
author | Diego Russo <diego.russo@arm.com> | 2022-05-30 13:34:14 +0100 |
---|---|---|
committer | Diego Russo <diego.russo@arm.com> | 2022-05-30 13:34:14 +0100 |
commit | 0efca3cadbad5517a59884576ddb90cfe7ac30f8 (patch) | |
tree | abed6cb6fbf3c439fc8d947f505b6a53d5daeb1e /src/mlia/core/data_analysis.py | |
parent | 0777092695c143c3a54680b5748287d40c914c35 (diff) | |
download | mlia-0efca3cadbad5517a59884576ddb90cfe7ac30f8.tar.gz |
Add MLIA codebase0.3.0-rc.1
Add MLIA codebase including sources and tests.
Change-Id: Id41707559bd721edd114793618d12ccd188d8dbd
Diffstat (limited to 'src/mlia/core/data_analysis.py')
-rw-r--r-- | src/mlia/core/data_analysis.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/mlia/core/data_analysis.py b/src/mlia/core/data_analysis.py new file mode 100644 index 0000000..6adb41e --- /dev/null +++ b/src/mlia/core/data_analysis.py @@ -0,0 +1,70 @@ +# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates. +# SPDX-License-Identifier: Apache-2.0 +"""Module for data analysis.""" +from abc import ABC +from abc import abstractmethod +from dataclasses import dataclass +from typing import List + +from mlia.core.common import DataItem +from mlia.core.mixins import ContextMixin + + +class DataAnalyzer(ABC): + """Base class for the data analysis. + + Purpose of this class is to extract valuable data out of + collected data which could be used for advice generation. + + This process consists of two steps: + - analyze every item of the collected data + - get analyzed data + """ + + @abstractmethod + def analyze_data(self, data_item: DataItem) -> None: + """Analyze data. + + :param data_item: item of the collected data + """ + + @abstractmethod + def get_analyzed_data(self) -> List[DataItem]: + """Get analyzed data.""" + + +class ContextAwareDataAnalyzer(DataAnalyzer, ContextMixin): + """Context aware data analyzer. + + This class makes easier access to the Context object. Context object could + be automatically injected during workflow configuration. + """ + + +@dataclass +class Fact: + """Base class for the facts. + + Fact represents some piece of knowledge about collected + data. + """ + + +class FactExtractor(ContextAwareDataAnalyzer): + """Data analyzer based on extracting facts. + + Utility class that makes fact extraction easier. + Class maintains list of the extracted facts. + """ + + def __init__(self) -> None: + """Init fact extractor.""" + self.facts: List[Fact] = [] + + def get_analyzed_data(self) -> List[DataItem]: + """Return list of the collected facts.""" + return self.facts + + def add_fact(self, fact: Fact) -> None: + """Add fact.""" + self.facts.append(fact) |