Question: import numpy as np def polynomial_regression_with_cem(x: np.ndarray, y: np.ndarray, d: int, num_iters: int = 12, elite_frac: float = 0.2, batch_size: int = 1000): ''' Inputs

 import numpy as np def polynomial_regression_with_cem(x: np.ndarray, y: np.ndarray, d: int,

import numpy as np

def polynomial_regression_with_cem(x: np.ndarray, y: np.ndarray, d: int, num_iters: int = 12, elite_frac: float = 0.2, batch_size: int = 1000): ''' Inputs `x` (np.ndarray): a 1-D numpy array corresponding to the 'x' values of some unknown function f. `y` (np.ndarray): a 1-D numpy array corresponding to the 'y' values of some unknown function f, f(x[i]) = y[i]. Has precisely the same shape as `x`. `d` (integer): a scalar reflecting the maximum degree of the least-squares polynomial whose coefficients we hope to estimate with CEM. `num_iters` (integer): CEM hyperparameter, the total number of CEM iterations to perform. `elite_frac` (float): CEM hyperparameter, the total proportion of "top" samples used to refine CEM parameter estimates at each iteration. `batch_size` (int): CEM hyperparameter, the total number of parameter values sampled from the paramter inference distribution at each iteration. Outputs `dummy_coeffs` (np.ndarray): a 1-D numpy array of shape (d+1,), containing the final estimates for each of the polynomial coefficients regressed with CEM after `num_iters` have been completed. Each value `dummy_coeffs[i]` should correspond to the degree i coefficient of the regressed polynomial.

''' dummy_coeffs = np.zeros((d+1,)) assert isinstance(dummy_coeffs, np.ndarray) and (dummy_coeffs.shape == (d+1,)) return dummy_coeffs

def sample_test(f): x = np.array([[1, 2.5, 3.5, 4, 5, 7, 8.5]]) y = np.array([[0.3, 1.1, 1.5, 2.0, 3.2, 6.6, 8.6]]) d = 1

out = f(x, y, d, num_iters=100, elite_frac=0.01, batch_size = 1000) assert np.allclose(out, [1.03571252, -1.19191605], rtol=1)

sample_test(polynomial_regression_with_cem)

In this problem, your task is to write a complete implementation of Cross-Entropy Method for generalized polynomial regression. More precisely, given - a polynomial degree d:d1 - a dataset of data pairs (xi,yi) represented via two equal-length 1-D numpy arrays; and - CEM hyperparameters num_iters, elite_frac, and batch_size, your code should return the final regressed estimates for the values of each of the (d+1) coefficients of the polynomial minimizing the total sum of squared errors, f(xi^;)=dxid+d1xid1++1xi+0 i(yif(xi^;))2 via the parameter vector [0,,d]. Employ a multi-dimensional Gaussian distribution with diagonal covariance as the distribution underlying parameter inference. The "starting" estimation distribution should be centered on the zero vector and have the identity as its covariance

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!