Skip to content

Instantly share code, notes, and snippets.

@hietalajulius
Last active July 28, 2023 12:11
Show Gist options
  • Save hietalajulius/e4b65ae12acae5367b5876ac26a77491 to your computer and use it in GitHub Desktop.
Save hietalajulius/e4b65ae12acae5367b5876ac26a77491 to your computer and use it in GitHub Desktop.
// Initialize the random number generator
let mut rng = StdRng::seed_from_u64(123);
// ...
// Set the batch size for training
let batch_size = 16;
// ...
// Generate random input samples within the range [-3.0, 3.0]
let x: Array2<f64> = Array2::from_shape_fn((batch_size, 2), |_| rng.gen_range(-3.0..=3.0));
// Compute the target values for the input samples using the PDF function
let pdf_values: Array1<f64> = x
.axis_iter(ndarray::Axis(0))
.map(|row| {
let (x, y) = (row[0], row[1]);
pdf(x, y)
})
.collect();
let target = pdf_values
.into_shape((batch_size, 1))
.expect("Unable to convert target to correct shape");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment