def calculate_frechet_distance(mu1, sigma1, mu2, sigma2, eps=<NUM_LIT>):
mu1 = np.atleast_1d(mu1)<EOL>mu2 = np.atleast_1d(mu2)<EOL>sigma1 = np.atleast_2d(sigma1)<EOL>sigma2 = np.atleast_2d(sigma2)<EOL>assert mu1.shape == mu2.shape, "<STR_LIT>"<EOL>assert sigma1.shape == sigma2.shape, "<STR_LIT>"<EOL>diff = mu1 - mu2<EOL>covmean, _ = linalg.sqrtm(sigma1.dot(sigma2), disp=False)<EOL>if not np.isfinite(covmean).all():<EOL><INDENT>offset = np.eye(sigma1.shape[<NUM_LIT:0>]) * eps<EOL>covmean = linalg.sqrtm((sigma1 + offset).dot(sigma2 + offset))<EOL><DEDENT>if np.iscomplexobj(covmean):<EOL><INDENT>if not np.allclose(np.diagonal(covmean).imag, <NUM_LIT:0>, atol=<NUM_LIT>):<EOL><INDENT>m = np.max(np.abs(covmean.imag))<EOL>raise ValueError("<STR_LIT>".format(m))<EOL><DEDENT>covmean = covmean.real<EOL><DEDENT>tr_covmean = np.trace(covmean)<EOL>return diff.dot(diff) + np.trace(sigma1) + np.trace(sigma2) - <NUM_LIT:2> * tr_covmean<EOL>
Numpy implementation of the Frechet Distance.
    The Frechet distance between two multivariate Gaussians X_1 ~ N(mu_1, C_1)
    and X_2 ~ N(mu_2, C_2) is
            d^2 = ||mu_1 - mu_2||^2 + Tr(C_1 + C_2 - 2*sqrt(C_1*C_2)).

    Stable version by Dougal J. Sutherland.

    Params:
    -- mu1:    The mean of the activations of preultimate layer of the
               CHEMNET ( like returned by the function 'get_predictions')
               for generated samples.
    -- mu2:    The mean of the activations of preultimate layer of the
               CHEMNET ( like returned by the function 'get_predictions')
               for real samples.
    -- sigma1: The covariance matrix of the activations of preultimate layer of the
               CHEMNET ( like returned by the function 'get_predictions')
               for generated samples.
    -- sigma2: The covariance matrix of the activations of preultimate layer of the
               CHEMNET ( like returned by the function 'get_predictions')
               for real samples.

    Returns:
    --   : The Frechet Distance.