def add_rv(self, variable, distribution='uniform', loc=0., scale=1., shape=1., n_int=30): '''Declare a variable as random ''' if variable not in self.rf.param_keys: raise AssertionError('parameter %s not defined by the response function' \ % variable) params_with_distr = self.rf.traits( distr=lambda x: type(x) == ListType and distribution in x) if variable not in params_with_distr: raise AssertionError('distribution type %s not allowed for parameter %s' \ % ( distribution, variable )) # @todo - let the RV take care of PDistrib specification. # isolate the dirty two-step definition of the distrib from spirrid # pd = PDistrib(distr_choice=distribution, n_segments=n_int) pd.distr_type.set(scale=scale, shape=shape, loc=loc) self.rv_dict[variable] = RV(name=variable, pd=pd, n_int=n_int)
def set_random( self, distribution = 'uniform', discr_type = 'T grid', loc = 0., scale = 1., shape = 1., n_int = 30 ): possible_distr = self.source_trait.distr if distribution and distribution not in possible_distr: raise AssertionError, 'distribution type %s not allowed for parameter %s' \ % ( distribution, self.name ) self.pd = PDistrib( distr_choice = distribution, n_segments = n_int ) self.pd.distr_type.set( scale = scale, shape = shape, loc = loc ) self.n_int = n_int self.discr_type = discr_type self.random = True
def _get_pd( self ): if self.random: tr = self.rf.trait( self.varname ) pd = PDistrib( distr_choice = tr.distr[0], n_segments = self.n_int ) trait = self.rf.trait( self.varname ) # get the distribution parameters from the metadata # distr_params = {'scale' : trait.scale, 'loc' : trait.loc, 'shape' : trait.shape } dparams = {} for key, val in distr_params.items(): if val: dparams[key] = val pd.distr_type.set( **dparams ) return pd else: return None
def _pdf_xi_default(self): pd = PDistrib(distr_choice='weibull_min', n_segments=30) pd.distr_type.set(shape=4.54, scale=0.017) return pd