|
- .. _learnware:
- ==========================================
- Learnware & Reuser
- ==========================================
-
- ``Learnware`` is the most basic concept in the ``learnware paradigm``. In this section, we will introduce the concept and design of ``learnware`` and its extension for ``Hetero Reuse``. Then we will introduce the ``Reuse Methods``, which applies one or several ``learnware``s to solve the user's task.
-
- Concepts
- ===================
- In the learnware paradigm, a learnware is a well-performed trained machine learning model with a specification which enables it to be adequately identified to reuse according to the requirement of future users who know nothing about the learnware in advance. The introduction of specifications are shown in `COMPONENTS: Specification <./spec.html>`_.
-
- In our implementation, the class ``Learnware`` has 3 important member variables:
-
- - ``id``: The learnware id is generated by ``market``.
- - ``model``: The model in the learnware, can be a ``BaseModel`` or a dict including model name and path. When it is a dict, the function ``Learnware.instantiate_model`` is used to transform it to a ``BaseModel``. The function ``Learnware.predict`` use the model to predict for an input ``X``. See more in `COMPONENTS: Model <./model.html>`_.
- - ``specification``: The specification including the semantic specification and the statistic specification.
-
-
- Learnware for Hetero Reuse (Feature Align + Hetero Map Learnware)
- =======================================================================
-
- In the Hetero Market(see `COMPONENTS:Market <./market>`_ for details), ``HeteroSearcher`` identifies and recommends helpful learnwares among all learnwares in the market,
- including learnwares with feature/label space different from the user's task requirements(heterogeneous learnwares). ``FeatureAlignLearnware`` and ``HeteroMapLearnware``
- extends ``Learnware`` with the ability to align the feature space and label space of the learnware to the user's task requirements, providing methods for heterogeneous learnwares to be reused in tasks beyond their original purposes.
-
- ``FeatureAlignLearnware``
- _________________________
-
- ``FeatureAlignLearnware`` employs a neural network to align the feature space of the learnware to the user's task.
- It is initialized with a ``Learnware``, and has the following methods to expand the applicable scope of this ``Learnware``:
-
- - **align**: Key interface that trains a neural network to align ``user_rkme``, which is the ``RKMETableSpecification`` of the user's data, with the learnware's statistical specification.
- - **predict**: Predict the output for user data using the trained neural network and the original learnware's model.
-
-
- ``HeteroMapAlignLearnware``
- ____________________________
-
- If user data is not only heterogeneous in feature space but also in label space, ``HeteroMapAlignLearnware`` uses the help of
- a small amount of labeled data ``(x_train, y_train)`` required from the user task to align heterogeneous learnwares with the user task.
-
- - ``HeteroMapAlignLearnware.align(self, user_rkme: RKMETableSpecification, x_train: np.ndarray, y_train: np.ndarray)``
-
- - **input space alignment**: Align the feature space of the learnware to the user task's statistical specification ``user_rkme`` using ``FeatureAlignLearnware``.
- - **output space alignment**: Further align the label space of the aligned learnware to the user task through supervised learning of ``FeatureAugmentReuser`` using ``(x_train, y_train)``.
-
- - ``HeteroMapAlignLearnware.predict(self, user_data)``
-
- - If input space and output space alignment are both performed, use the ``FeatureAugmentReuser`` to predict the output for user data.
-
-
-
- All Reuse Methods
- ===========================
-
- JobSelectorReuser
- --------------------
-
- The ``JobSelectorReuser`` is a class that inherits from the base reuse class ``BaseReuser``.
- Its purpose is to create a job selector that identifies the optimal learnware for each data point in user data.
- There are three parameters required to initialize the class:
-
- - ``learnware_list``: A list of objects of type ``Learnware``. Each ``Learnware`` object should have an RKME specification.
- - ``herding_num``: An optional integer that specifies the number of items to herd, which defaults to 1000 if not provided.
- - ``use_herding``: A boolean flag indicating whether to use kernel herding.
-
- The job selector is essentially a multi-class classifier :math:`g(\boldsymbol{x}):\mathcal{X}\rightarrow \mathcal{I}` with :math:`\mathcal{I}=\{1,\ldots, C\}`, where :math:`C` is the size of ``learnware_list``.
- Given a testing sample :math:`\boldsymbol{x}`, the ``JobSelectorReuser`` predicts it by using the :math:`g(\boldsymbol{x})`-th learnware in ``learnware_list``.
- If ``use_herding`` is set to false, the ``JobSelectorReuser`` uses data points in each learware's RKME spefication with the corresponding learnware index to train a job selector.
- If ``use_herding`` is true, the algorithm estimates the mixture weight based on RKME specifications and raw user data, uses the weight to generate ``herding_num`` auxiliary data points mimicking the user distribution through the kernel herding method, and learns a job selector on these data.
-
-
-
- AveragingReuser
- ------------------
-
- The ``AveragingReuser`` is a class that inherits from the base reuse class ``BaseReuser``, that implements the average ensemble method by averaging each learnware's output to predict user data.
- There are two parameters required to initialize the class:
-
- - ``learnware_list``: A list of objects of type ``Learnware``.
- - ``mode``: The mode of averaging leanrware outputs, which can be set to "mean" or "vote" and defaults to "mean".
-
- If ``mode`` is set to "mean", the ``AveragingReuser`` computes the mean of the learnware's output to predict user data, which is commonly used in regression tasks.
- If ``mode`` is set to "vote", the ``AveragingReuser`` computes the mean of the softmax of the learnware's output to predict each label probability of user data, which is commonly used in classification tasks.
|