def __init__(self, shape, probc, meanc, varc,name=None,\ var_axes=(0,),mean_fix=None,var_fix=None,\ is_complex=False,map_est=False,zvarmin=1e-3, tune_gmm=False): # Save properties self.map_est = map_est self.is_complex = is_complex self.zvarmin = zvarmin self.tune_gmm = tune_gmm self.mean_fix = mean_fix self.var_fix = var_fix dtype = meanc.dtype BaseEst.__init__(self,shape=shape,var_axes=var_axes,dtype=dtype,\ name=name, type_name='GMM', nvars=1, cost_avail=True) # If the GMM parameters are given, set them now self.mix = None self.set_gmm_param(probc, meanc, varc) self.it = 0 # Set the indicators on which the variance and means are fixed if self.mean_fix is None: self.mean_fix = np.zeros(len(probc)) if self.var_fix is None: self.var_fix = np.zeros(len(probc))
def __init__(self,shape,var_axes=(0,),max_it=10, step_init=1,\ dtype=np.float64,name=None,\ step_max=1,step_min=1e-8,zinit=None,is_complex=False,gtol=1e-3): BaseEst.__init__(self,shape=shape,var_axes=var_axes,dtype=dtype,\ name=name, type_name='ScalarNL', nvars=1, cost_avail=True) # Save parameters self.max_it = max_it self.cost_avail = True self.step_last = step_init self.step_max = step_max self.step_min = step_min self.is_complex = is_complex self.gtol = gtol self.min_it = 1 # Set default value that the Hessian is available self.hess_avail = True # Set initial point if (zinit is None): self.zlast = self.proj(np.zeros(self.shape)) else: self.zlast = zinit
def __init__(self, zmean, zvar, shape,name=None,\ var_axes = (0,), zmean_axes='all',\ is_complex=False, map_est=False, tune_zvar=False,\ tune_rvar=False): if np.isscalar(shape): shape = (shape,) if is_complex: dtype = np.double else: dtype = np.complex BaseEst.__init__(self,shape=shape,dtype=dtype,name=name, var_axes=var_axes,type_name='GaussEst', cost_avail=True) self.zmean = zmean self.zvar = zvar self.cost_avail = True self.is_complex = is_complex self.map_est = map_est self.zmean_axes = zmean_axes self.tune_zvar = tune_zvar self.tune_rvar = tune_rvar ndim = len(self.shape) if self.zmean_axes == 'all': self.zmean_axes = tuple(range(ndim)) # If zvar is a scalar, then repeat it to the required shape, # which are all the dimensions not being averaged over if np.isscalar(self.zvar): var_shape = get_var_shape(self.shape, self.var_axes) self.zvar = np.tile(self.zvar, var_shape)
def __init__(self, zval, pz, shape, var_axes=(0,),\ is_complex=False,name=None): if np.isscalar(shape): shape = (shape,) # Convert scalars to arrays if np.isscalar(zval): zval = np.array([zval]) if not is_complex and np.any(zval.imag != 0): import warnings warnings.warn('zval is complex, but is_complex is False (forcing True)') is_complex = True if np.isscalar(pz): pz = np.array([pz]) # Set parameters of base estimator dtype = zval.dtype BaseEst.__init__(self,shape=shape, var_axes=var_axes, dtype=dtype, name=name,\ type_name='DiscreteEst', nvars=1, cost_avail=True) # Set parameters self.zval = zval self.pz = pz self.shape = shape self.is_complex = is_complex self.fz = -np.log(pz)
def __init__(self,y,shape,var_axes=(0,),thresh=0,perr=1e-6,\ name=None,var_init=np.Inf,dtype=np.float64): BaseEst.__init__(self, shape=shape, var_axes=var_axes, dtype=dtype,\ name=name,type_name='BinaryQuantEst', nvars=1, cost_avail=True) self.y = y self.shape = shape self.thresh = thresh self.perr = perr self.cost_avail = True self.var_init = var_init
def __init__(self,A,y,wvar=0,\ wrep_axes='all', var_axes=(0,),name=None,map_est=False,\ is_complex=False,rvar_init=1e5,tune_wvar=False): BaseEst.__init__(self, shape=A.shape0, var_axes=var_axes,\ dtype=A.dtype0, name=name,\ type_name='LinEstim', nvars=1, cost_avail=True) self.A = A self.y = y self.wvar = wvar self.map_est = map_est self.is_complex = is_complex self.cost_avail = True self.rvar_init = rvar_init self.tune_wvar = tune_wvar # Get the input and output shape self.zshape = A.shape0 self.yshape = A.shape1 # Set the repetition axes ndim = len(self.yshape) if wrep_axes == 'all': wrep_axes = tuple(range(ndim)) self.wrep_axes = wrep_axes # Compute the SVD terms # Take an SVD A=USV'. Then write p = SV'z + w, if not A.svd_avail: raise common.VpException("Transform must support an SVD") self.p = A.UsvdH(y) srep_axes = A.get_svd_diag()[2] # Compute the norm of ||y-UU*(y)||^2/wvar if np.all(self.wvar > 0): yp = A.Usvd(self.p) wvar1 = common.repeat_axes(wvar, self.yshape, self.wrep_axes, rep=False) err = np.abs(y - yp)**2 self.ypnorm = np.sum(err / wvar1) else: self.ypnorm = 0 # Check that all axes on which A operates are repeated for i in range(ndim): if not (i in self.wrep_axes) and not (i in srep_axes): raise common.VpException( "Variance must be constant over output axis") if not (i in self.var_axes) and not (i in srep_axes): raise common.VpException( "Variance must be constant over input axis")
def __init__(self, shape, var_axes=[(0, ), (0, )], name=None, map_est=False): self.map_est = map_est # Initial variances self.zvar0_init = np.Inf self.zvar1_init = np.Inf nvars = 2 dtype = np.float64 BaseEst.__init__(self,shape=[shape,shape], var_axes=var_axes, dtype=dtype, name=name,\ type_name='ReLUEst', nvars=nvars, cost_avail=True)
def __init__(self,A,b,wvar=0,var_axes=[(0,), (0,)], wrep_axes='all',\ name=None,map_est=False,is_complex=False,est_meth='svd',\ nit_cg=100, atol_cg=1e-3, save_stats=False): self.A = A self.b = b self.wvar = wvar self.map_est = map_est self.is_complex = is_complex self.cost_avail = True # Initial variance. This is large value since the quantities # are underdetermined self.zvar0_init = np.Inf self.zvar1_init = np.Inf # Set parameters of the base estimator shape = [A.shape0, A.shape1] dtype = [A.dtype0, A.dtype1] nvars = 2 for i in range(nvars): if var_axes[i] == 'all': ndim = len(shape[i]) var_axes[i] = tuple(range(ndim)) if wrep_axes == 'all': ndim = len(shape[1]) wrep_axes = tuple(range(ndim)) self.wrep_axes = wrep_axes BaseEst.__init__(self,shape=shape, var_axes=var_axes, dtype=dtype, name=name,\ type_name='LinEstTwo', nvars=nvars, cost_avail=True) # Initialization depending on the estimation method self.est_meth = est_meth if self.est_meth == 'svd': self.init_svd() elif self.est_meth == 'cg': self.init_cg() else: raise common.VpException( "Unknown estimation method {0:s}".format(est_meth)) # CG parameters self.nit_cg = nit_cg self.atol_cg = atol_cg self.save_stats = save_stats self.init_hist_dict()
def __init__(self, est_list, name=None): # Save estimator list self.est_list = est_list # Get parameters from the estimators shape = [] var_axes = [] dtype = [] cost_avail = True nvars = len(est_list) for est in est_list: shape.append(est.shape) var_axes.append(est.var_axes) dtype.append(est.dtype) cost_avail = cost_avail and est.cost_avail self.cost_avail = cost_avail BaseEst.__init__(self,shape=shape,var_axes=shape,dtype=dtype,\ name=name, type_name='StackEst', nvars=nvars, cost_avail=cost_avail)
def __init__(self, zval, pz, shape, var_axes=(0,),\ is_complex=False,name=None): # Convert scalars to arrays if np.isscalar(zval): zval = np.array([zval]) if np.isscalar(pz): pz = np.array([pz]) # Set parameters of base estimator dtype = zval.dtype BaseEst.__init__(self,shape=shape, var_axes=var_axes, dtype=dtype, name=name,\ type_name='DiscreteEst', nvars=1, cost_avail=True) # Set parameters self.zval = zval self.pz = pz self.shape = shape self.is_complex = is_complex self.fz = -np.log(pz)
def __init__(self, est_list, w, name=None): self.est_list = est_list self.w = w shape = est_list[0].shape var_axes = est_list[0].var_axes dtype = est_list[0].dtype # Check that all estimators have cost available for est in est_list: if est.shape != shape: raise common.VpException('Estimators must have the same shape') if est.var_axes != var_axes: raise common.VpException( 'Estimators must have the same var_axes') if not est.cost_avail: raise common.VpException(\ "Estimators in a mixture distribution"+\ "must have cost_avail==True") BaseEst.__init__(self,shape=shape,var_axes=var_axes,dtype=dtype,\ name=name, type_name='Mixture', nvars=1, cost_avail=True)