def _sampleDistribution(params, numSamples, verbosity=0):
 if params.has_key('name'):
  if (params['name'] == 'normal'):
   samples = numpy.random.normal(loc=params['mean'], scale=math.sqrt(params['variance']), size=numSamples)
  elif (params['name'] == 'pareto'):
   samples = numpy.random.pareto(params['alpha'], size=numSamples)
  elif (params['name'] == 'beta'):
   samples = numpy.random.beta(a=params['alpha'], b=params['beta'], size=numSamples)
  else:
   raise ValueError(('Undefined distribution: ' + params['name']))
 else:
  raise ValueError(('Bad distribution params: ' + str(params)))
 if (verbosity > 0):
  print '\nSampling from distribution:', params
  print 'After estimation, mean=', numpy.mean(samples), 'var=', numpy.var(samples), 'stdev=', math.sqrt(numpy.var(samples))
 return samples

def _sampleDistribution ( params , numSamples , verbosity = 0 ) : if params . has_key ( 'name' ) : if ( params [ 'name' ] == 'normal' ) : samples = numpy . random . normal ( loc = params [ 'mean' ] , scale = math . sqrt ( params [ 'variance' ] ) , size = numSamples ) elif ( params [ 'name' ] == 'pareto' ) : samples = numpy . random . pareto ( params [ 'alpha' ] , size = numSamples ) elif ( params [ 'name' ] == 'beta' ) : samples = numpy . random . beta ( a = params [ 'alpha' ] , b = params [ 'beta' ] , size = numSamples ) else : raise ValueError ( ( 'Undefined distribution: ' + params [ 'name' ] ) ) else : raise ValueError ( ( 'Bad distribution params: ' + str ( params ) ) ) if ( verbosity > 0 ) : print '\nSampling from distribution:' , params print 'After estimation, mean=' , numpy . mean ( samples ) , 'var=' , numpy . var ( samples ) , 'stdev=' , math . sqrt ( numpy . var ( samples ) ) return samples
given the parameters of a distribution .