# Code for Monte Carlo class, Jonathan Goodman # http://www.math.nyu.edu/faculty/goodman/teaching/MonteCarlo20/ # MakeFakeData.py # The author gives permission for anyone to use this publicly posted # code for any purpose. The code was written for teaching, not research # or commercial use. It has not been tested thoroughly and probably has # serious bugs. Results may be inaccurate, incorrect, or just wrong. # Make a csv file with fake data to be read by PDFapproxDemo.py # See week 2 notes for an explanation in mathematical notation. # The notation in the code is the same as the notation in the notes. # In this experiment, the fake data are Gaussian from numpy.random import Generator, PCG64 # numpy randon number generator import numpy as np import csv # package for reading and writing .csv files # Define fake data parameters n = 20 # size of the data file mu = 2. # gaussian mean sig = 3. # gaussian standard deviation FakeDataFileName = "GaussianFakeData" # name the output .csv file ... FakeDataFileName = FakeDataFileName + ".csv" # ... filename.csv csvfile = open( FakeDataFileName, 'w', newline = '') # open the file for writing cfr = csv.writer( csvfile) # instantiate the writer object seed = 12344 # change this to get different answers bg = PCG64(seed) # instantiate a bit generator rg = Generator(bg) # instantiate a random number generator with ... # ... this bit generator form = " {xi:10.5f} " for i in range(n): xi = rg.normal(mu,sig) xis = form.format(xi = xi) print(xis) cfr.writerow([xis]) csvfile.close()