# -------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
# -------------------------------------------------------------------------------------------
"""Extends IntegratedHyperParameterAcquisition class to enable integration."""
from typing import Callable, Union

import numpy as np
from emukit.core.acquisition import IntegratedHyperParameterAcquisition
from emukit.core.interfaces import IModel, IPriorHyperparameters


class IntegratedHyperParameterAcquisitionFromSamples(IntegratedHyperParameterAcquisition):
    """
    This acquisition class provides functionality for integrating any acquisition function over model hyper-parameters.

    Kind of a hacky work-around to get HMC to work with Batch Acquisition Functions in more diverse settings.
    """

    def __init__(
        self,
        model: Union[IModel, IPriorHyperparameters],
        acquisition_generator: Callable,
        hyperparam_samples: np.ndarray,
    ):  # pragma: no cover
        """
        Args:
            model: An emukit model that implements `IPriorHyperparameters`
            acquisition_generator: Function that returns acquisition object when given the model as the only argument
            hyperparam_samples: If given, those should be the HMC samples generated by
                `model.generate_hyperparameters_samples()`, and will be used to integrate out the acquisition
        """
        self.model = model
        self.acquisition_generator = acquisition_generator
        self.samples = hyperparam_samples  # type: ignore # auto
        self._has_gradients = acquisition_generator(model).has_gradients

    @property
    def n_samples(self) -> int:  # pragma: no cover
        """Number of HMC samples used"""
        return self.samples.shape[0]

    def update_parameters(self):  # pragma: no cover
        """
        This method has a bug in the official version: https://github.com/EmuKit/emukit/issues/363
        and is not needed for the functioning of this wrapper
        """
        raise NotImplementedError()

e0eb4ffbeb6577fe3e0f1600fa9d76f629c1feab
<mask token>


class IntegratedHyperParameterAcquisitionFromSamples(
    IntegratedHyperParameterAcquisition):
    <mask token>

    def __init__(self, model: Union[IModel, IPriorHyperparameters],
        acquisition_generator: Callable, hyperparam_samples: np.ndarray):
        """
        Args:
            model: An emukit model that implements `IPriorHyperparameters`
            acquisition_generator: Function that returns acquisition object when given the model as the only argument
            hyperparam_samples: If given, those should be the HMC samples generated by
                `model.generate_hyperparameters_samples()`, and will be used to integrate out the acquisition
        """
        self.model = model
        self.acquisition_generator = acquisition_generator
        self.samples = hyperparam_samples
        self._has_gradients = acquisition_generator(model).has_gradients
    <mask token>
    <mask token>

<mask token>


class IntegratedHyperParameterAcquisitionFromSamples(
    IntegratedHyperParameterAcquisition):
    <mask token>

    def __init__(self, model: Union[IModel, IPriorHyperparameters],
        acquisition_generator: Callable, hyperparam_samples: np.ndarray):
        """
        Args:
            model: An emukit model that implements `IPriorHyperparameters`
            acquisition_generator: Function that returns acquisition object when given the model as the only argument
            hyperparam_samples: If given, those should be the HMC samples generated by
                `model.generate_hyperparameters_samples()`, and will be used to integrate out the acquisition
        """
        self.model = model
        self.acquisition_generator = acquisition_generator
        self.samples = hyperparam_samples
        self._has_gradients = acquisition_generator(model).has_gradients

    @property
    def n_samples(self) ->int:
        """Number of HMC samples used"""
        return self.samples.shape[0]

    def update_parameters(self):
        """
        This method has a bug in the official version: https://github.com/EmuKit/emukit/issues/363
        and is not needed for the functioning of this wrapper
        """
        raise NotImplementedError()

<mask token>


class IntegratedHyperParameterAcquisitionFromSamples(
    IntegratedHyperParameterAcquisition):
    """
    This acquisition class provides functionality for integrating any acquisition function over model hyper-parameters.

    Kind of a hacky work-around to get HMC to work with Batch Acquisition Functions in more diverse settings.
    """

    def __init__(self, model: Union[IModel, IPriorHyperparameters],
        acquisition_generator: Callable, hyperparam_samples: np.ndarray):
        """
        Args:
            model: An emukit model that implements `IPriorHyperparameters`
            acquisition_generator: Function that returns acquisition object when given the model as the only argument
            hyperparam_samples: If given, those should be the HMC samples generated by
                `model.generate_hyperparameters_samples()`, and will be used to integrate out the acquisition
        """
        self.model = model
        self.acquisition_generator = acquisition_generator
        self.samples = hyperparam_samples
        self._has_gradients = acquisition_generator(model).has_gradients

    @property
    def n_samples(self) ->int:
        """Number of HMC samples used"""
        return self.samples.shape[0]

    def update_parameters(self):
        """
        This method has a bug in the official version: https://github.com/EmuKit/emukit/issues/363
        and is not needed for the functioning of this wrapper
        """
        raise NotImplementedError()

<mask token>
from typing import Callable, Union
import numpy as np
from emukit.core.acquisition import IntegratedHyperParameterAcquisition
from emukit.core.interfaces import IModel, IPriorHyperparameters


class IntegratedHyperParameterAcquisitionFromSamples(
    IntegratedHyperParameterAcquisition):
    """
    This acquisition class provides functionality for integrating any acquisition function over model hyper-parameters.

    Kind of a hacky work-around to get HMC to work with Batch Acquisition Functions in more diverse settings.
    """

    def __init__(self, model: Union[IModel, IPriorHyperparameters],
        acquisition_generator: Callable, hyperparam_samples: np.ndarray):
        """
        Args:
            model: An emukit model that implements `IPriorHyperparameters`
            acquisition_generator: Function that returns acquisition object when given the model as the only argument
            hyperparam_samples: If given, those should be the HMC samples generated by
                `model.generate_hyperparameters_samples()`, and will be used to integrate out the acquisition
        """
        self.model = model
        self.acquisition_generator = acquisition_generator
        self.samples = hyperparam_samples
        self._has_gradients = acquisition_generator(model).has_gradients

    @property
    def n_samples(self) ->int:
        """Number of HMC samples used"""
        return self.samples.shape[0]

    def update_parameters(self):
        """
        This method has a bug in the official version: https://github.com/EmuKit/emukit/issues/363
        and is not needed for the functioning of this wrapper
        """
        raise NotImplementedError()

# -------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
# -------------------------------------------------------------------------------------------
"""Extends IntegratedHyperParameterAcquisition class to enable integration."""
from typing import Callable, Union

import numpy as np
from emukit.core.acquisition import IntegratedHyperParameterAcquisition
from emukit.core.interfaces import IModel, IPriorHyperparameters


class IntegratedHyperParameterAcquisitionFromSamples(IntegratedHyperParameterAcquisition):
    """
    This acquisition class provides functionality for integrating any acquisition function over model hyper-parameters.

    Kind of a hacky work-around to get HMC to work with Batch Acquisition Functions in more diverse settings.
    """

    def __init__(
        self,
        model: Union[IModel, IPriorHyperparameters],
        acquisition_generator: Callable,
        hyperparam_samples: np.ndarray,
    ):  # pragma: no cover
        """
        Args:
            model: An emukit model that implements `IPriorHyperparameters`
            acquisition_generator: Function that returns acquisition object when given the model as the only argument
            hyperparam_samples: If given, those should be the HMC samples generated by
                `model.generate_hyperparameters_samples()`, and will be used to integrate out the acquisition
        """
        self.model = model
        self.acquisition_generator = acquisition_generator
        self.samples = hyperparam_samples  # type: ignore # auto
        self._has_gradients = acquisition_generator(model).has_gradients

    @property
    def n_samples(self) -> int:  # pragma: no cover
        """Number of HMC samples used"""
        return self.samples.shape[0]

    def update_parameters(self):  # pragma: no cover
        """
        This method has a bug in the official version: https://github.com/EmuKit/emukit/issues/363
        and is not needed for the functioning of this wrapper
        """
        raise NotImplementedError()
