def _process_kappa(self, options_GP): """ static or dynamic kappa""" kappa = options_GP['kappa'] niter = options_GP['maxiter'] if(isinstance(kappa, float)): kappa = np.repeat(kappa, niter) else: bits = ut.splitString(kappa) if(bits[0] == 'linear'): kappa = float(bits[1]) * (1 - np.arange(niter) / (niter - 1)) else: raise NotImplementedError() return kappa
def gen_rdmfunc_from_string(self, method_rdm, dim=1): """return a function that when called return random variables according to the distribution described by the string, with specific dim convention: dim[-1] correspond to the dim of the RV while dim[:-1] to the size of the population TODO: works only for 1D dim """ if ut.is_list(method_rdm): # return a lst of function # should it be a function returning a list?? func = [ self.gen_rdmfunc_from_string(meth, dim) for meth in method_rdm ] else: args = ut.splitString(method_rdm) if (ut.is_int(dim)): dimRV = dim else: dimRV = dim[-1] if (args[0] in ['uniform', 'normal']): if (len(args) == 1): first_args = np.repeat(0, dimRV) second_args = np.repeat(1, dimRV) elif (len(args) == 3): first_args = np.repeat(float(args[1]), dimRV) second_args = np.repeat(float(args[2]), dimRV) elif (len(args) == (1 + 2 * dimRV)): first_args = np.array( [float(args[1 + 2 * d]) for d in range(dimRV)]) second_args = np.array( [float(args[2 + 2 * d]) for d in range(dimRV)]) else: raise NotImplementedError() if (dim == 1): # such that function return a value instead of an array # may change first_args, second_args = first_args[0], second_args[0] dim = None if args[0] == 'normal': def func(): return self.normal(first_args, second_args, size=dim) else: def func(): return self.uniform(first_args, second_args, size=dim) elif (args[0] == 'determ'): if (len(args) == 1): constant = np.repeat(0, dim) elif (len(args) == 2): constant = np.repeat(float(args[1]), dim) elif (len(args) == (1 + dimRV)): constant = np.array(args[1:]) if (ut.is_list(dim)): dim_pop = np.product(dim[:-1]) constant = np.tile(constant, dim_pop).reshape(dim) else: raise NotImplementedError() def func(): return constant else: raise NotImplementedError() return func