def test_compare_kernels(self):
        kernel = Matern52.define_kernel_from_array(1, np.ones(1))

        kernel_ = copy.deepcopy(kernel)
        kernel_.name = 'a'
        assert Matern52.compare_kernels(kernel, kernel_) is False

        kernel_ = copy.deepcopy(kernel)
        kernel_.dimension = 2
        assert Matern52.compare_kernels(kernel, kernel_) is False

        kernel_ = copy.deepcopy(kernel)
        kernel_.dimension_parameters = 5
        assert Matern52.compare_kernels(kernel, kernel_) is False

        kernel_ = copy.deepcopy(kernel)
        kernel_.length_scale.value = np.array([-1])
        assert Matern52.compare_kernels(kernel, kernel_) is False
    def test_get_kernel_default(self):
        kernel_name = [MATERN52_NAME]
        dimension = [2]
        kernel = get_kernel_default(kernel_name, dimension)

        kernel_ = Matern52.define_kernel_from_array(2, np.ones(3))

        assert Matern52.compare_kernels(kernel, kernel_)

        kernel_name = [TASKS_KERNEL_NAME]
        dimension = [1]
        kernel = get_kernel_default(kernel_name, dimension)

        kernel_ = TasksKernel.define_kernel_from_array(1, np.array([0]))

        assert TasksKernel.compare_kernels(kernel, kernel_)

        kernel_name = [PRODUCT_KERNELS_SEPARABLE, MATERN52_NAME, TASKS_KERNEL_NAME]
        dimension = [2, 1, 1]
        kernel = get_kernel_default(kernel_name, dimension)

        kernel_ = ProductKernels.define_kernel_from_array([1, 1], [np.array([1]), np.array([0])],
                                                          [MATERN52_NAME, TASKS_KERNEL_NAME])
        assert ProductKernels.compare_kernels(kernel, kernel_)

        kernel = get_kernel_default(kernel_name, dimension, default_values=np.array([1, 0]))
        assert ProductKernels.compare_kernels(kernel, kernel_)
        assert kernel.parameters[MATERN52_NAME][LENGTH_SCALE_NAME].prior.max == [LARGEST_NUMBER]

        compare = kernel.parameters[MATERN52_NAME][LENGTH_SCALE_NAME].prior.min
        assert compare == SMALLEST_POSITIVE_NUMBER

        kernel = get_kernel_default(kernel_name, dimension, default_values=np.array([1, 0]),
                                    bounds=[[-1, 2]])

        assert ProductKernels.compare_kernels(kernel, kernel_)
        assert kernel.parameters[MATERN52_NAME][LENGTH_SCALE_NAME].prior.max == 60.0

        compare = kernel.parameters[MATERN52_NAME][LENGTH_SCALE_NAME].prior.min
        assert compare == SMALLEST_POSITIVE_NUMBER
    def compare_kernels(kernel1, kernel2):
        """
        Compare the values of kernel1 and kernel2. Returns True if they're equal, otherwise it
        return False.

        :param kernel1: ProductKernels instance object
        :param kernel2: ProductKernels instance object
        :return: boolean
        """

        if kernel1.name != kernel2.name:
            return False

        if kernel1.dimension != kernel2.dimension:
            return False

        if kernel1.dimension_parameters != kernel2.dimension_parameters:
            return False

        if kernel1.names != kernel2.names:
            return False

        for i in xrange(len(kernel1.names)):
            name1 = kernel1.names[i]

            kernel_1 = kernel1.kernels[name1]
            kernel_2 = kernel2.kernels[name1]

            if name1 == MATERN52_NAME:
                if Matern52.compare_kernels(kernel_1, kernel_2) is False:
                    return False

            if name1 == TASKS_KERNEL_NAME:
                if TasksKernel.compare_kernels(kernel_1, kernel_2) is False:
                    return False

        return True