コード例 #1
0
    def test_define_default_kernel(self):
        kern1 = Matern52.define_default_kernel(1)

        assert kern1.name == MATERN52_NAME
        assert kern1.dimension == 1
        assert kern1.dimension_parameters == 1
        assert kern1.length_scale.value == np.array([1])
        assert kern1.length_scale.prior.max == [LARGEST_NUMBER]
        assert kern1.length_scale.prior.min == [SMALLEST_POSITIVE_NUMBER]

        kern2 = Matern52.define_default_kernel(1, default_values=np.array([5]))

        assert kern2.name == MATERN52_NAME
        assert kern2.dimension == 1
        assert kern2.dimension_parameters == 1
        assert kern2.length_scale.value == np.array([5])
        assert kern2.length_scale.prior.max == [LARGEST_NUMBER]
        assert kern2.length_scale.prior.min == [SMALLEST_POSITIVE_NUMBER]

        kern3 = Matern52.define_default_kernel(1, bounds=[[5, 6]])
        assert kern3.name == MATERN52_NAME
        assert kern3.dimension == 1
        assert kern3.dimension_parameters == 1
        assert kern3.length_scale.value == np.array([1])
        assert kern3.length_scale.prior.max == [20.0]
        assert kern3.length_scale.prior.min == [SMALLEST_POSITIVE_NUMBER]
コード例 #2
0
def get_kernel_default(kernel_name,
                       dimension,
                       bounds=None,
                       default_values=None,
                       parameters_priors=None,
                       **kernel_parameters):
    """
    Returns a default kernel object associated to the kernel_name
    :param kernel_name: [str]
    :param dimension: [int]. It's the number of tasks for the task kernel.
    :param bounds: [[float, float]], lower bound and upper bound for each entry. This parameter
            is to compute priors in a smart way.
    :param default_values: np.array(k), default values for the parameters of the kernel
    :param parameters_priors: {
            SIGMA2_NAME: float,
            LENGTH_SCALE_NAME: [float],
            LOWER_TRIANG_NAME: [float],
        }
    :param kernel_parameters: additional kernel parameters,
        - SAME_CORRELATION: (boolean) True or False. Parameter used only for task kernel.

    :return: kernel object
    """

    if kernel_name[0] == SCALED_KERNEL:
        if kernel_name[1] == MATERN52_NAME:
            return ScaledKernel.define_default_kernel(dimension[0], bounds,
                                                      default_values,
                                                      parameters_priors,
                                                      *([MATERN52_NAME], ))

    if kernel_name[0] == MATERN52_NAME:
        return Matern52.define_default_kernel(dimension[0], bounds,
                                              default_values,
                                              parameters_priors)

    if kernel_name[0] == TASKS_KERNEL_NAME:
        return TasksKernel.define_default_kernel(dimension[0], bounds,
                                                 default_values,
                                                 parameters_priors,
                                                 **kernel_parameters)

    if kernel_name[0] == PRODUCT_KERNELS_SEPARABLE:
        values = []
        cont = 0
        bounds_ = []
        cont_b = 0
        for name, dim in zip(kernel_name[1:], dimension[1:]):
            n_params = get_number_parameters_kernel([name], [dim],
                                                    **kernel_parameters)
            if default_values is not None:
                value_kernel = default_values[cont:cont + n_params]
            else:
                value_kernel = None

            if bounds is not None:
                if name == MATERN52_NAME:
                    bounds_.append(bounds[cont_b:cont_b + dim])
                    cont_b += dim
                if name == TASKS_KERNEL_NAME:
                    bounds_.append(bounds[cont_b:cont_b + 1])
                    cont_b += 1
            cont += n_params
            values.append(value_kernel)

        if len(bounds_) > 0:
            bounds = bounds_

        return ProductKernels.define_default_kernel(dimension[1:], bounds,
                                                    values, parameters_priors,
                                                    kernel_name[1:],
                                                    **kernel_parameters)