def true_cov_ma1_of_t(t_par, sigma, lag): """ True autocovariance for given parameters. :param t_par: t parameter of a scaled time. :param sigma: standard deviation of noise used to simulate the MA1 sample. :param lag: lag of autocovariance to be computed. :return: true autocovariance value. """ if lag == 0: return (sigma**2) * (1 + (coef(t_par=t_par)**2)) elif lag == 1: return coef(t_par=t_par) * (sigma**2) else: return 0
def horizontal_sample_tvma1(sample_size: int, t_par_count: int, mean: int, sigma: int, noise_type: str, noise=None): """ Generates MA(1) sample for the given noise or its parameters. :sample_size: number of observations or number of columns in the returned matrix. :t_par_count: number of t values or number of rows in the returned matrix. :mean: mean of the noise. :return: a double array t_par_count by sample_size of stationary MA1 samples. Each line, corresponding to tPar value. """ if noise is None: noise = create_noise(noise_size=sample_size + 1, mean=mean, sigma=sigma, noise_type=noise_type) elif len(noise) != sample_size + 1: raise ValueError("length of noise should be sample_size + 1") t_par_array = create_t_par_array(t_par_count=t_par_count) horizontal_sample_tvma1 = np.full(shape=(t_par_count,sample_size), fill_value=np.nan) for i in range(t_par_count): for j in range(sample_size): horizontal_sample_tvma1[i, j] = coef(t_par=t_par_array[i]) * \ noise[j] + noise[j + 1] return horizontal_sample_tvma1
def diagonal_sample_scaled_noise(sample_size: int, mean: int, sigma: int, noise_type: str, noise=None): """ Currently unused. Copied from the first project with translation from R to Python. Forms a diagonal sample of noise, stretched by coef(t) values at each index point. :sample_size: size of a sample to be generated. :mean: mean of a notise to be genrated. :noise_type: "gaussian" or "bernoulli". :return: one-dimensional array of noise values. """ if noise is None: noise = create_noise(noise_size=sample_size + 1, mean=mean, sigma=sigma, noise_type=noise_type) elif len(noise) != sample_size + 1: raise ValueError("length of noise should be sample_size + 1") diagonal_sample_scaled_noise = np.full(shape=sample_size, fill_value=np.nan) for i in range(1, sample_size + 1): diagonal_sample_scaled_noise[i - 1] = coef(t_par=i / sample_size) * \ noise[i - 1] return diagonal_sample_scaled_noise
def diagonal_sample_tvma3(sample_size: int, mean: int, sigma: int, noise_type: str, noise=None): """ Creates the diagonal time-varying MA3 sample, given sample size, mean, sigma and noise type. :param sample_size: size of a sample to be generated. :param mean: mean of the noise to generate, if not given. :param sigma: sigma of the noise to generate, if not given. :param noise_type: type of the noise to generate, if not given. :param noise: an array of the size sample_size+3. If it is given (not None), then sample size agreement is checked, and other arguments ignored. The cycle starts from 1, not from 0, because we pass i+1 to theta. Basically, indexation in Python is x(0), ...x(n-1), while in formulas, it is for the case x(1), ...x(n). """ if noise is None: noise = create_noise(noise_size=sample_size + 3, mean=mean, sigma=sigma, noise_type=noise_type) elif len(noise) != sample_size + 3: raise ValueError("length of noise should be sample_size + 3") diagonal_sample_tvma3 = np.full(shape=sample_size, fill_value=np.nan) for i in range(1, sample_size + 1): diagonal_sample_tvma3[i - 1] = noise[i + 2] + \ coef(t_par=i / sample_size) * noise[i + 1] + \ coef_2(t_par=i / sample_size) * noise[i] + \ coef_3(t_par=i / sample_size) * noise[i - 1] return diagonal_sample_tvma3
def horizontal_sample_scaled_noise(sample_size: int, t_par_count: int, mean: int, sigma: int, noise_type: str, noise=None): """ Creates and returns a double array of dimensions [sample_size, t_par_count]. Each row is a noise sample, streched by coef(t). So it produces the double array with proportional rows. """ if noise is None: noise = create_noise(noise_size=sample_size + 1, mean=mean, sigma=sigma, noise_type=noise_type) elif len(noise) != sample_size + 1: raise ValueError("length of noise should be sample_size + 1") t_par_array = create_t_par_array(t_par_count=t_par_count) horizontal_sample_tvma1 = np.full(shape=(t_par_count, sample_size), fill_value=np.nan) for i in range(t_par_count): for j in range(sample_size): horizontal_sample_tvma1[i, j] = coef(t_par=t_par_array[i]) * \ noise[j] return horizontal_sample_tvma1
def diagonal_sample_tvma1(sample_size: int, mean: float, sigma: float, noise_type: str, noise=None) -> np.array: """ Create diagonal sample tvma1. :param sample_size: len of sample :param mean: mean :param sigma: sigma :param noise_type: type :return: diagonal sample tvma1 """ if noise is None: noise = create_noise(noise_size=sample_size + 1, mean=mean, sigma=sigma, noise_type=noise_type) elif len(noise) != sample_size + 1: raise ValueError("length of noise should be sample_size + 1") diagonal_sample_tvma1 = np.full(shape=sample_size, fill_value=np.nan) for i in range(1, sample_size + 1): diagonal_sample_tvma1[ i - 1] = coef(t_par=i / sample_size) * noise[i - 1] + noise[i] return diagonal_sample_tvma1
def true_lrv_ma3_of_single_t(sigma, t_par): """ True local LRV for given parameters. :param sigma: standard deviation of noise used to simulate the MA3 sample. :param t_par: t parameter or scaled time. :return: true LRV value. """ lrv = (sigma**2) * (1 + coef(t_par) + coef_2(t_par) + coef_3(t_par))**2 return lrv
def true_cov_scaled_noise_of_t(t_par, sigma, lag): """ True autocovariance for given parameters. :param t_par: t parameter of a scaled time. :param sigma: standard deviation of noise used to simulate the scaled noise sample. :param lag: lag of autocovariance to be computed. :return: true autocovariance value. """ if lag == 0: return coef(t_par=t_par)**2 * sigma**2 elif lag != 0: return 0
def true_cov_ma3_of_t(t_par, lag, sigma): """ True autocovariance for given parameters. :param t_par: t parameter of a scaled time. :param sigma: standard deviation of noise used to simulate the MA3 sample. :param lag: lag of autocovariance to be computed. :return: true autocovariance value. """ if lag == 0: return ((1**2) + (coef(t_par=t_par)**2) + (coef_2(t_par=t_par)**2) + (coef_3(t_par=t_par)**2)) * (sigma**2) elif lag == 1: return (1 * coef(t_par=t_par) + coef(t_par=t_par) * coef_2(t_par=t_par) + coef_2(t_par=t_par) * coef_3(t_par=t_par))\ * (sigma ** 2) elif lag == 2: return (1 * coef_2(t_par=t_par) + coef(t_par=t_par) * coef_3(t_par=t_par)) * (sigma**2) elif lag == 3: return (1 * coef_3(t_par=t_par)) * (sigma**2) else: return 0