コード例 #1
0
    def test_define_prior_parameters(self):
        data = {
            'points': np.array([[1]]),
            'evaluations': np.array([1]),
            'var_noise': None,
        }

        dimension = 1

        result = Matern52.define_prior_parameters(data, dimension)

        assert result == {
            LENGTH_SCALE_NAME: [0.0],
        }

        data2 = {
            'points': np.array([[1], [2]]),
            'evaluations': np.array([1, 2]),
            'var_noise': None,
        }

        dimension2 = 1

        result2 = Matern52.define_prior_parameters(data2, dimension2)

        assert result2 == {
            LENGTH_SCALE_NAME: [1.5432098765432098],
        }
コード例 #2
0
def define_prior_parameters_using_data(data,
                                       type_kernel,
                                       dimensions,
                                       sigma2=None,
                                       **kernel_parameters):
    """
    Defines value of the parameters of the prior distributions of the kernel's parameters.

    :param data: {'points': np.array(nxm), 'evaluations': np.array(n),
            'var_noise': np.array(n) or None}
    :param type_kernel: [str]
    :param dimensions: [int], It has only the n_tasks for the task_kernels, and for the
            PRODUCT_KERNELS_SEPARABLE contains the dimensions of every kernel in the product, and
            the total dimension of the product_kernels_separable too in the first entry.
    :param: sigma2: float
    :param kernel_parameters: additional kernel parameters,
        - SAME_CORRELATION: (boolean) True or False. Parameter used only for task kernel.
    :return: {
        SIGMA2_NAME: float,
        LENGTH_SCALE_NAME: [float],
        LOWER_TRIANG_NAME: [float],
    }
    """

    # We assume that there is at most one task kernel, and mattern52 kernel in the product.

    parameters_priors = {
        SIGMA2_NAME: None,
        LENGTH_SCALE_NAME: None,
        LOWER_TRIANG_NAME: None,
    }

    index = 1

    if TASKS_KERNEL_NAME in type_kernel:
        same_correlation = kernel_parameters.get(SAME_CORRELATION, False)
        index = type_kernel.index(TASKS_KERNEL_NAME)
        index_tasks = 0
        for i in xrange(1, index):
            index_tasks += dimensions[i]
        n_tasks = dimensions[index]

        if n_tasks > 1:
            tasks_index = data['points'][:, index_tasks]
            task_data = data.copy()
            task_data['points'] = tasks_index.reshape((len(tasks_index), 1))
        else:
            task_data = None
        task_parameters = TasksKernel.define_prior_parameters(
            task_data,
            n_tasks,
            same_correlation=same_correlation,
            var_evaluations=sigma2)
        parameters_priors[LOWER_TRIANG_NAME] = task_parameters[
            LOWER_TRIANG_NAME]

    if MATERN52_NAME in type_kernel:
        m = data['points'].shape[1]
        indexes = [i for i in range(m) if i != m - index + 1]
        points_matern = data['points'][:, indexes]
        matern_data = data.copy()
        matern_data['points'] = points_matern
        matern52_parameters = Matern52.define_prior_parameters(
            matern_data, len(indexes))
        parameters_priors[LENGTH_SCALE_NAME] = matern52_parameters[
            LENGTH_SCALE_NAME]

        if SCALED_KERNEL in type_kernel:
            parameters = \
                ScaledKernel.define_prior_parameters(data, len(indexes), var_evaluations=sigma2)
            parameters_priors[SIGMA2_NAME] = parameters[SIGMA2_NAME]

    return parameters_priors