Created
January 14, 2021 18:09
-
-
Save jjerphan/45e36d9859ea324888a091ba1b37ac9b to your computer and use it in GitHub Desktop.
sklearn#18850 - benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gc | |
import time | |
import numpy as np | |
import pandas as pd | |
from scipy import linalg | |
""" | |
A simple benchmark to know the performances of setting `check_finite` | |
to `False` for `linalg.cholesky` | |
""" | |
if __name__ == "__main__": | |
n_trials = 100 | |
header = f"n_features\tcheck_finite\tRunning time ({n_trials} trials)" | |
print(header) | |
for n_features in [10, 50, 100, 500, 1000, 2000]: | |
np.random.seed(1337) | |
print("--" * len(header)) | |
for check_finite in [True, False]: | |
times = [] | |
for _ in range(n_trials): | |
gc.collect() | |
covmatrix = np.cov(np.random.random((n_features, n_features + 100))) | |
cov_chol = linalg.cholesky(covmatrix, lower=True) | |
t1 = time.time() | |
_ = linalg.solve_triangular(cov_chol, | |
np.eye(n_features), | |
lower=True, | |
check_finite=check_finite) | |
t2 = time.time() | |
times.append(t2 - t1) | |
mean = np.mean(times) | |
std = np.std(times) | |
print(f"{n_features}\t\t{check_finite}\t\t{mean:.4f} ± {std:.4f}s") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment