Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions boom/data/prepare_splits_10k.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,18 @@ def prepare_splits(
# Extract the hof values
hof_values = np.array(hof_values).reshape(-1, 1)

density_KDE = KernelDensity(kernel="gaussian", bandwidth="scott").fit(
# sklearn's "scott" assumes sigma=1, so we compute it manually:
# h = n^(-1/(d+4)) * sigma

n_samples_density, n_features_density = density_values.shape
scott_bw_density = n_samples_density ** (-1.0 / (n_features_density + 4)) * np.std(density_values)
density_KDE = KernelDensity(kernel="gaussian", bandwidth=scott_bw_density).fit(
density_values
)
hof_KDE = KernelDensity(kernel="gaussian", bandwidth="scott").fit(hof_values)

n_samples_hof, n_features_hof = hof_values.shape
scott_bw_hof = n_samples_hof ** (-1.0 / (n_features_hof + 4)) * np.std(hof_values)
hof_KDE = KernelDensity(kernel="gaussian", bandwidth=scott_bw_hof).fit(hof_values)

density_kde_scores = density_KDE.score_samples(density_values)
hof_kde_scores = hof_KDE.score_samples(hof_values)
Expand Down
7 changes: 6 additions & 1 deletion boom/data/prepare_splits_qm9.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,12 @@ def prepare_splits_qm9(
property_values = np.array(property_values).reshape(-1, 1).astype(np.float64)

print("Starting Kernel Density Estimation for " + property_name)
property_KDE = KernelDensity(kernel="gaussian", bandwidth="scott").fit(
# sklearn's "scott" assumes sigma=1, so we compute it manually:
# h = n^(-1/(d+4)) * sigma

n_samples, n_features = property_values.shape
scott_bandwidth = n_samples ** (-1.0 / (n_features + 4)) * np.std(property_values)
property_KDE = KernelDensity(kernel="gaussian", bandwidth=scott_bandwidth).fit(
property_values
)
print("Kernel Density Estimation Done!")
Expand Down