Skip to content

Instantly share code, notes, and snippets.

@ThomasParistech
Last active April 8, 2024 20:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasParistech/11b7682e7ee19718b6450ea73febe4cf to your computer and use it in GitHub Desktop.
Save ThomasParistech/11b7682e7ee19718b6450ea73febe4cf to your computer and use it in GitHub Desktop.
import numpy as np
def reflective_kde(x_data: np.ndarray, x_prediction: np.ndarray) -> np.ndarray:
h = silverman_bandwidth(x_data) # Compute before adding reflected data
x_data_augmented = np.stack((-x_data, x_data, 2-x_data))
reflective_densities = basic_kde(x_data_augmented, x_prediction, h)
# Discard left and right reflected samples and normalize density by 1/3
return 3 * reflective_densities
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment