def test_define_default_kernel_2(self): kernel = ScaledKernel.define_default_kernel(1, None, None, None, *([MATERN52_NAME], )) assert kernel.name == MATERN52_NAME assert kernel.dimension == 1 assert kernel.dimension_parameters == 2 assert kernel.sigma2.value == [1.0] assert kernel.kernel.length_scale.value == [1.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)