def cosine_distance(x, y, name=''): ''' Computes the cosine distance between ``x`` and ``y``: Example: >>> a = np.asarray([-1, -1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1]).reshape(3,2,2) >>> b = np.asarray([1, 1, -1, 1, 1, -1, 1, -1, -1, -1, -1, 1]).reshape(3,2,2) >>> x = C.input_variable(shape=(2,)) >>> y = C.input_variable(shape=(2,)) >>> np.round(C.cosine_distance(x,y).eval({x:a,y:b}),5) array([[-1., 1.], [ 1., 0.], [ 0., -1.]], dtype=float32) Args: x: numpy array or any :class:`~cntk.ops.functions.Function` that outputs a tensor name (str, optional): the name of the Function instance in the network Returns: :class:`~cntk.ops.functions.Function` ''' from cntk.cntk_py import cosine_distance dtype = get_data_type(x, y) x = sanitize_input(x, dtype) y = sanitize_input(y, dtype) return cosine_distance(x, y, name)
def cosine_distance(x, y, name=''): ''' Computes the cosine distance between ``x`` and ``y``: Example: >>> a = np.asarray([-1, -1, -1, 1, 1, -1, 1, 1, -1, 1, 1, -1]).reshape(3,2,2) >>> b = np.asarray([1, 1, -1, 1, 1, -1, 1, -1, -1, -1, -1, 1]).reshape(3,2,2) >>> x = C.sequence.input_variable(shape=(2,)) >>> y = C.sequence.input_variable(shape=(2,)) >>> np.round(C.cosine_distance(x,y).eval({x:a,y:b}),5) array([[-1., 1.], [ 1., 0.], [ 0., -1.]], dtype=float32) Args: x: numpy array or any :class:`~cntk.ops.functions.Function` that outputs a tensor name (str, optional): the name of the Function instance in the network Returns: :class:`~cntk.ops.functions.Function` ''' from cntk.cntk_py import cosine_distance dtype = get_data_type(x, y) x = sanitize_input(x, dtype) y = sanitize_input(y, dtype) return cosine_distance(x, y, name)