# coding: utf-8
"""
Functions to create kernels from already existing kernels.

"""

import numpy as np


def normalize(kernel, *args, **kwargs):
    """Return the normalized version.

    This correspond to the new kernel
    .. math::
        K(x_1, x_2) = \\frac{k_0(x_1, x2)}{\\sqrt(k_0(x_1, x_1) k_0(x_2, x_2))}

    This is equivalent to normalize the feature map:

    .. math::
        \\Phi(x) = \\frac{\\phi(x)}{\\|\\phi(x)\\|}

    """

    def normalized_kernel(x1, x2, *args, **kwargs):
        """actual kernel to return"""
        denom = np.sqrt(
            kernel(x1, x1, *args, **kwargs) * kernel(x2, x2, *args, **kwargs)
        )
        if denom == 0:
            return 0
        else:
            return kernel(x1, x2, *args, **kwargs) / denom

    return normalized_kernel

@@ -216,16 +216,17 @@
  kernel%0A
+%0A
     .. m
@@ -275,17 +275,16 @@
 , x2)%7D%7B%5C
-%5C
 sqrt(k_0
@@ -387,17 +387,16 @@
         
-%5C
 %5CPhi(x) 
@@ -405,17 +405,16 @@
 %5C%5Cfrac%7B%5C
-%5C
 phi(x)%7D%7B
@@ -418,19 +418,17 @@
 )%7D%7B%5C
-%5C%7C%5C
+%7C
 %5Cphi(x)%5C
 %5C%7C%7D%0A
@@ -427,13 +427,61 @@
 (x)%5C
-%5C
 %7C%7D%0A%0A
+    Returns:%0A        (fun) the kernel function.%0A%0A
     

Fix sphinx compilation errors on composition.py