Exemplo n.º 1
0
 def __init__(self):
     """
   Default Constructor that will initialize member variables with reasonable
   defaults or empty lists/dictionaries where applicable.
   @ In, None
   @ Out, None
 """
     AdaptiveSampler.__init__(self)
     self._initialValues = {
     }  # dict stores the user provided initial values, i.e. {var: val}
     self._updateValues = {
     }  # dict stores input variables values for the current MCMC iteration, i.e. {var:val}
     self._proposal = {
     }  # dict stores the proposal distributions for input variables, i.e. {var:dist}
     self._priorFuns = {
     }  # dict stores the prior functions for input variables, i.e. {var:fun}
     self._burnIn = 0  # integers indicate how many samples will be discarded
     self._likelihood = None  # stores the output from the likelihood
     self._logLikelihood = False  # True if the user provided likelihood is in log format
     self._availProposal = {
         'normal': Distributions.Normal(0.0, 1.0),
         'uniform': Distributions.Uniform(-1.0, 1.0)
     }  # available proposal distributions
     self._acceptDist = Distributions.Uniform(
         0.0, 1.0)  # uniform distribution for accept/rejection purpose
     self.toBeCalibrated = {}  # parameters that will be calibrated
     # assembler objects
     self.addAssemblerObject('proposal',
                             InputData.Quantity.zero_to_infinity)
     self.addAssemblerObject('probabilityFunction',
                             InputData.Quantity.zero_to_infinity)
Exemplo n.º 2
0
 def makeDistribution(self):
     """
   Used to make standardized distribution for this poly type.
   @ In, None
   @ Out, None
 """
     uniform = Distributions.Uniform(-1.0, 1.0)
     uniform.initializeDistribution()
     return uniform
Exemplo n.º 3
0
 def makeDistribution(self):
     """
   Used to make standardized distribution for this poly type.
   @ In, None
   @ Out, None
 """
     uniformElement = ET.Element("Uniform")
     element = ET.Element("lowerBound", {})
     element.text = "-1"
     uniformElement.append(element)
     element = ET.Element("upperBound", {})
     element.text = "1"
     uniformElement.append(element)
     uniform = Distributions.Uniform()
     uniform._readMoreXML(uniformElement)
     uniform.initializeDistribution()
     return uniform
Exemplo n.º 4
0
 def __init__(self):
   """
     Default Constructor that will initialize member variables with reasonable
     defaults or empty lists/dictionaries where applicable.
     @ In, None
     @ Out, None
   """
   AdaptiveSampler.__init__(self)
   self.onlySampleAfterCollecting = True
   self._initialValues = {} # dict stores the user provided initial values, i.e. {var: val}
   self._updateValues = {} # dict stores input variables values for the current MCMC iteration, i.e. {var:val}
   self._proposal = {} # dict stores the proposal distributions for input variables, i.e. {var:dist}
   self._proposalDist = {} # dist stores the input variables for each proposal distribution, i.e. {distName:[(var,dim)]}
   self._priorFuns = {} # dict stores the prior functions for input variables, i.e. {var:fun}
   self._burnIn = 0      # integers indicate how many samples will be discarded
   self._likelihood = None # stores the output from the likelihood
   self._logLikelihood = False # True if the user provided likelihood is in log format
   self._availProposal = {'normal': Distributions.Normal,
                          'multivariateNormal': Distributions.MultivariateNormal} # available proposal distributions
   self._acceptDist = Distributions.Uniform(0.0, 1.0) # uniform distribution for accept/rejection purpose
   self.toBeCalibrated = {} # parameters that will be calibrated
   self._correlated = False # True if input variables are correlated else False
   self.netLogPosterior = 0.0 # log-posterior vs iteration
   self._localReady = True # True if the submitted job finished
   self._currentRlz = None # dict stores the current realizations, i.e. {var: val}
   self._acceptRate = 1. # The accept rate for MCMC
   self._acceptCount = 1 # The total number of accepted samples
   self._tune = True # Tune the scaling parameter if True
   self._tuneInterval = 100 # the number of sample steps for each tuning of scaling parameter
   self._scaling = 1.0 # The initial scaling parameter
   self._countsUntilTune = self._tuneInterval # The remain number of sample steps until the next tuning
   self._acceptInTune = 0 # The accepted number of samples for given tune interval
   self._accepted = False # The indication of current samples, True if accepted otherwise False
   self._stdProposalDefault = 0.2 # the initial scaling of the std of proposal distribution (only apply to default)
   # assembler objects
   self.addAssemblerObject('proposal', InputData.Quantity.zero_to_infinity)
   self.addAssemblerObject('probabilityFunction', InputData.Quantity.zero_to_infinity)
Exemplo n.º 5
0
print(Distributions.knownTypes())
#Test error
try:
    Distributions.returnInstance("unknown", 'dud')
except:
    print("error worked")

#Test Uniform

uniformElement = ET.Element("Uniform")
uniformElement.append(createElement("lowerBound", text="1.0"))
uniformElement.append(createElement("upperBound", text="3.0"))

#ET.dump(uniformElement)

uniform = Distributions.Uniform()
uniform._readMoreXML(uniformElement)
uniform.initializeDistribution()
uniform.setMessageHandler(mh)

#check pickled version as well
pk.dump(uniform, open('testDistrDump.pk', 'wb'))
puniform = pk.load(open('testDistrDump.pk', 'rb'))

checkCrowDist("uniform", uniform, {
    'xMin': 1.0,
    'type': 'UniformDistribution',
    'xMax': 3.0
})
checkCrowDist("puniform", puniform, {
    'xMin': 1.0,