Created
November 14, 2023 03:26
-
-
Save smsharma/09ea6128a6bae4886ee2cb6552797f63 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"import corner" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## Generate fake data" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def random_covariance_matrix(n_dim, min_correlation, max_correlation):\n", | |
" \"\"\" Generate a random covariance matrix with the specified dimensions and correlation range.\n", | |
" \"\"\"\n", | |
" # Initialize a matrix of zeros\n", | |
" A = np.zeros((n_dim, n_dim))\n", | |
"\n", | |
" # Populate the matrix with random correlations within the specified range\n", | |
" for i in range(n_dim):\n", | |
" for j in range(i, n_dim):\n", | |
" if i == j:\n", | |
" A[i, j] = 1 # Variance of 1 along the diagonal\n", | |
" else:\n", | |
" A[i, j] = A[j, i] = np.random.uniform(min_correlation, max_correlation)\n", | |
"\n", | |
" # Ensure the matrix is positive definite\n", | |
" A = A.T.dot(A)\n", | |
" return A" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"n_dim = 14\n", | |
"min_correlation = -1\n", | |
"max_correlation = 1\n", | |
"\n", | |
"A_cov = random_covariance_matrix(n_dim, min_correlation, max_correlation)\n", | |
"A_mean = np.random.uniform(-2, 2, n_dim) # Random mean offset\n", | |
"\n", | |
"# Train and val sets\n", | |
"X_samples = np.random.multivariate_normal(A_mean, A_cov, 100000)\n", | |
"X_samples_val = np.random.multivariate_normal(A_mean, A_cov, 1000)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment