def _kl_divergence_error(params, P, neighbors, degrees_of_freedom, n_samples, n_components):
 X_embedded = params.reshape(n_samples, n_components)
 n = pdist(X_embedded, 'sqeuclidean')
 n += 1.0
 n /= degrees_of_freedom
 n **= ((degrees_of_freedom + 1.0) / (-2.0))
 Q = np.maximum((n / (2.0 * np.sum(n))), MACHINE_EPSILON)
 if (len(P.shape) == 2):
  P = squareform(P)
 kl_divergence = (2.0 * np.dot(P, np.log((P / Q))))
 return kl_divergence

def _kl_divergence_error ( params , P , neighbors , degrees_of_freedom , n_samples , n_components ) : X_embedded = params . reshape ( n_samples , n_components ) n = pdist ( X_embedded , 'sqeuclidean' ) n += 1.0 n /= degrees_of_freedom n **= ( ( degrees_of_freedom + 1.0 ) / ( - 2.0 ) ) Q = np . maximum ( ( n / ( 2.0 * np . sum ( n ) ) ) , MACHINE_EPSILON ) if ( len ( P . shape ) == 2 ) : P = squareform ( P ) kl_divergence = ( 2.0 * np . dot ( P , np . log ( ( P / Q ) ) ) ) return kl_divergence
t-sne objective function: the absolute error of the kl divergence of p_ijs and q_ijs .