Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1 Generating the Data Before we fit a model, we need data to fit it to . The data set will be a set of

1 Generating the Data
Before we fit a model, we need data to fit it to. The data set will be a set of points of the form {(x??(1),y1),(x??(2),y2),dots,(x??(N),yN)} where each x??(i)inR101,yiinR. To generate the data points (x,y), the following instructions lay out how to generate (x0,x1,x2,dots,x100), and then y based on that x? vector.
Note: In the following, I am using N(,2) to indicate a random value sampled from a normal distribution with mean and variance 2. In order to generate random values, you need to specify a distribution (see CS-206), and normal distributions are fairly standard functionality for RNG packages. I am performing a slight abuse of notation when I write (expression)+N(,2), but this should be interpreted as adding a small random bit of noise sampled from that distribution to the value of (expression). All noise terms should be taken as independent. These terms are present to represent noise or fluctuations in the measurements that you collect from the real world.
x0=1.
x1,dots,x50 are i.i.d. random values, with distribution N(0,1).
For i=51,52,dots,60,xi=x1+0.5**xi-50+N(0,0.1).
Note: The way to interpret this is that, for example, x55=x1+0.5**x5+(a little bit of noise).
For i=61,62,dots,70,xi=xi-60-xi-50+xi-40+N(0,0.1).
Example: x65=x5-x15+x25+(a little bit of noise).
For i=71,72,dots,80,xi=x6**(i-70)+3**xi-70+N(0,0.1).
For i=81,82,dots,90,xi=5-xi-10.
For i=91,92,dots,100,xi=0.5**x50+(i-90)**4+0.5**x50+(i-90)**3+N(0,0.1).
The output data will be generated in the following way. For any input x?, the output is given by
y=(i=150(-0.88)ix2i)+N(0,0.01).
Note that with this setup, none of the odd-indexed components of x? 'explicitly' show up in the value of y.
Note: This specifies that the value of y is based on x? via y=w*x+(a little noise), and that the 'true' weights are given by
w?=(0,0,-0.88,0,(-0.88)2,0,(-0.88)3,0,dots,0,(-0.88)50)
1
Problem 1: Write a function that takes as input a number of data points N, and gives as output a data matrix x as a PyTorch tensor, with N rows and 101 columns, where each row is an x? vector as above, as well as a PyTorch tensor y? with N rows and 1 column, where each entry of y? is the corresponding y value for that row of x.
Some functions that may be useful:
torch.zeros
torch.randn
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions