# -*- coding: utf-8 -*-
# Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 3 as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

# Contributors:
#    INITIAL AUTHORS - initial API and implementation and/or initial
#                         documentation
#        :author: Matthias De Lozzo, Syver Doving Agdestein
#    OTHER AUTHORS   - MACROSCOPIC CHANGES
"""Dimension reduction as a generic transformer.

The :class:`.DimensionReduction` class implements the concept of dimension reduction.

.. seealso::

   :mod:`~gemseo.mlearning.transform.dimension_reduction.pca`
"""
from __future__ import division, unicode_literals

from typing import NoReturn, Optional, Union

from numpy import ndarray

from gemseo.mlearning.transform.transformer import Transformer, TransformerFitOptionType


class DimensionReduction(Transformer):
    """Dimension reduction."""

    def __init__(
        self,
        name="DimensionReduction",  # type: str
        n_components=5,  # type: int
        **parameters  # type: Optional[Union[float,int,str,bool]]
    ):  # type: (...) -> None
        """
        Args:
            name: A name for this transformer.
            n_components: The number of components of the latent space.
            **parameters: The parameters of the transformer.
        """
        super(DimensionReduction, self).__init__(
            name, n_components=n_components, **parameters
        )

    def fit(
        self,
        data,  # type: ndarray
        *args  # type: TransformerFitOptionType
    ):  # type: (...) -> NoReturn
        """Fit the transformer to the data.

        Args:
            data: The data to be fitted.
        """
        raise NotImplementedError

    @property
    def n_components(self):  # type: (...) -> int
        """The number of components."""
        return self.parameters["n_components"]
