Exemplo n.º 1
0
  def getInputSpecification(cls):
    """
      Method to get a reference to a class that specifies the input data for
      class cls.
      @ In, cls, the class for which we are retrieving the specification
      @ Out, inputSpecification, InputData.ParameterInput, class to use for
        specifying input of cls.
    """
    inputSpecification = super(MCMC, cls).getInputSpecification()

    samplerInitInput = InputData.parameterInputFactory("samplerInit", strictMode=True,
        printPriority=10,
        descr=r"""collection of nodes that describe the initialization of the MCMC algorithm.""")
    limitInput = InputData.parameterInputFactory("limit", contentType=InputTypes.IntegerType,
        descr=r"""the limit for the total samples""")
    samplerInitInput.addSub(limitInput)
    initialSeedInput = InputData.parameterInputFactory("initialSeed", contentType=InputTypes.IntegerType,
        descr=r"""The initial seed for random number generator""")
    samplerInitInput.addSub(initialSeedInput)
    burnInInput = InputData.parameterInputFactory("burnIn", contentType=InputTypes.IntegerType,
        descr=r"""The number of samples that will be discarded""")
    samplerInitInput.addSub(burnInInput)
    tune = InputData.parameterInputFactory("tune", contentType=InputTypes.BoolType,
        descr=r"""The option to tune the scaling parameter""")
    samplerInitInput.addSub(tune)
    tuneInterval = InputData.parameterInputFactory("tuneInterval", contentType=InputTypes.IntegerType,
        descr=r"""The number of sample steps for each tuning of scaling parameter""")
    samplerInitInput.addSub(tuneInterval)
    inputSpecification.addSub(samplerInitInput)
    likelihoodInp = InputData.parameterInputFactory("likelihood",contentType=InputTypes.StringType,
        printPriority=5,
        descr=r"""Output of likelihood function""")
    likelihoodInp.addParam('log', InputTypes.BoolType, required=False,
        descr=r"""True if the user provided is the log likelihood, otherwise, treat it as
        the standard likelihood""")
    inputSpecification.addSub(likelihoodInp)
    # modify Sampler variable nodes
    variable = inputSpecification.getSub('variable')
    variable.addSub(InputData.parameterInputFactory('initial', contentType=InputTypes.FloatType,
        descr=r"""inital value for given variable"""))
    proposal = InputData.assemblyInputFactory('proposal', contentType=InputTypes.StringType, strictMode=True,
        printPriority=30,
        descr=r"""name of the Distribution that is used as proposal distribution""")
    proposal.addParam('dim', InputTypes.IntegerType, required=False,
        descr=r"""for an ND proposal distribution, indicates the dimension within the ND Distribution that corresponds
              to this variable""")
    variable.addSub(proposal)
    variable.addSub(InputData.assemblyInputFactory('probabilityFunction', contentType=InputTypes.StringType, strictMode=True,
        printPriority=30,
        descr=r"""name of the function that is used as prior distribution (doesn't need to be normalized)"""))
    inputSpecification.addSub(variable)
    return inputSpecification
Exemplo n.º 2
0
 def getInputSpecification(cls):
     """
   Method to get a reference to a class that specifies the input data for class cls.
   @ In, cls, the class for which we are retrieving the specification
   @ Out, specs, InputData.ParameterInput, class to use for specifying input of cls.
 """
     specs = super(AdaptiveSampler, cls).getInputSpecification()
     specs.description = 'Base class for all kinds of adaptive sampling efforts in RAVEN.'
     specs.addSub(
         InputData.assemblyInputFactory(
             'TargetEvaluation',
             contentType=InputTypes.StringType,
             strictMode=True,
             printPriority=101,
             descr=
             r"""name of the DataObject where the sampled outputs of the Model will be collected.
           This DataObject is the means by which the sampling entity obtains the results of requested
           samples, and so should require all the input and output variables needed for adaptive sampling."""
         ))
     return specs
Exemplo n.º 3
0
  def getInputSpecification(cls):
    """
      Method to get a reference to a class that specifies the input data for class cls.
      @ In, cls, the class for which we are retrieving the specification
      @ Out, specs, InputData.ParameterInput, class to use for specifying input of cls.
    """
    specs = super(Optimizer, cls).getInputSpecification()
    specs.description = 'Optimizers'

    # objective variable
    specs.addSub(InputData.parameterInputFactory('objective', contentType=InputTypes.StringType, strictMode=True,
        printPriority=90, # more important than <variable>
        descr=r"""Name of the response variable (or ``objective function'') that should be optimized
        (minimized or maximized)."""))

    # modify Sampler variable nodes
    variable = specs.getSub('variable')
    variable.addSub(InputData.parameterInputFactory('initial', contentType=InputTypes.FloatListType,
        descr=r"""indicates the initial values where independent trajectories for this optimization
              effort should begin. The number of entries should be the same for all variables, unless
              a variable is initialized with a sampler (see \xmlNode{samplerInit} below). Note these
              entries are ordered; that is, if the optimization variables are $x$ and $y$, and the initial
              values for $x$ are \xmlString{1, 2, 3, 4} and initial values for $y$ are \xmlString{5, 6, 7, 8},
              then there will be four starting trajectories beginning at the locations (1, 5), (2, 6),
              (3, 7), and (4, 8)."""))

    # initialization
    ## TODO similar to MonteCarlo and other samplers, maybe overlap?
    init = InputData.parameterInputFactory('samplerInit', strictMode=True,
        printPriority=105, # more important than <variable>
        descr=r"""collection of nodes that describe the initialization of the optimization algorithm.""")
    seed = InputData.parameterInputFactory('initialSeed', contentType=InputTypes.IntegerType,
        descr=r"""seed for random number generation. Note that by default RAVEN uses an internal seed,
              so this seed must be changed to observe changed behavior. \default{RAVEN-determined}""")
    minMaxEnum = InputTypes.makeEnumType('MinMax', 'MinMaxType', ['min', 'max'])
    minMax = InputData.parameterInputFactory('type', contentType=minMaxEnum,
        descr=r"""the type of optimization to perform. \xmlString{min} will search for the lowest
              \xmlNode{objective} value, while \xmlString{max} will search for the highest value.""")
    init.addSub(seed)
    init.addSub(minMax)
    specs.addSub(init)

    ConstraintInput = InputData.parameterInputFactory('Constraint', contentType=InputTypes.StringType, strictMode=True,
        printPriority=150,
        descr=r"""name of \xmlNode{Function} which contains explicit constraints for the sampling of
              the input space of the Model. From a practical point of view, this XML node must contain
              the name of a function defined in the \xmlNode{Functions} block (see Section~\ref{sec:functions}).
              This external function must contain a method called ``constrain'', which returns True for
              inputs satisfying the explicit constraints and False otherwise.""")
    ConstraintInput.addParam("class", InputTypes.StringType, True,
        descr=r"""RAVEN class for this source. Options include \xmlString{Functions}. """)
    ConstraintInput.addParam("type", InputTypes.StringType, True,
        descr=r"""RAVEN type for this source. Options include \xmlNode{External}.""")


    ImplicitConstraintInput =  InputData.parameterInputFactory('ImplicitConstraint', contentType=InputTypes.StringType, strictMode=True,
        printPriority=150,
        descr=r"""name of \xmlNode{Function} which contains implicit constraints of the Model. From a practical
              point of view, this XML node must contain the name of a function defined in the \xmlNode{Functions}
              block (see Section~\ref{sec:functions}). This external function must contain a method called
              ``implicitConstrain'', which returns True for outputs satisfying the implicit constraints and False otherwise.""")
    ImplicitConstraintInput.addParam("class", InputTypes.StringType, True,
        descr=r"""RAVEN class for this source. Options include \xmlString{Functions}. """)
    ImplicitConstraintInput.addParam("type", InputTypes.StringType, True,
        descr=r"""RAVEN type for this source. Options include \xmlNode{External}.""")

    specs.addSub(ConstraintInput)
    specs.addSub(ImplicitConstraintInput)


    # assembled objects

    specs.addSub(InputData.assemblyInputFactory('Sampler', contentType=InputTypes.StringType, strictMode=True,
        printPriority=175,
        descr=r"""name of a Sampler that can be used to initialize the starting points for the trajectories
              of some of the variables. From a practical point of view, this XML node must contain the
              name of a Sampler defined in the \xmlNode{Samplers} block (see Section~\ref{subsec:onceThroughSamplers}).
              The Sampler will be used to initialize the trajectories' initial points for some or all
              of the variables. For example, if the Sampler selected samples only 2 of the 5 optimization
              variables, the \xmlNode{initial} XML node is required only for the remaining 3 variables."""))
    return specs