当前位置: 首页>>代码示例>>Python>>正文


Python Profile.setObservedProfile方法代码示例

本文整理汇总了Python中diffpy.srfit.fitbase.Profile.setObservedProfile方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.setObservedProfile方法的具体用法?Python Profile.setObservedProfile怎么用?Python Profile.setObservedProfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在diffpy.srfit.fitbase.Profile的用法示例。


在下文中一共展示了Profile.setObservedProfile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: makeRecipe

# 需要导入模块: from diffpy.srfit.fitbase import Profile [as 别名]
# 或者: from diffpy.srfit.fitbase.Profile import setObservedProfile [as 别名]
def makeRecipe(x, y, dy, A, sig, x0):
    """Make a FitRecipe for fitting a Gaussian curve to data.    
    """
    profile = Profile()
    profile.setObservedProfile(x, y, dy)

    contribution = FitContribution("g1")
    contribution.setProfile(profile, xname="x")
    contribution.setEquation("A * exp(-0.5*(x-x0)**2/sigma**2)")

    recipe = FitRecipe()
    recipe.addContribution(contribution)
    recipe.addVar(contribution.A, A)
    recipe.addVar(contribution.x0, x0)
    recipe.addVar(contribution.sigma, sig)
    return recipe
开发者ID:XiaohaoYang,项目名称:srfit-demos,代码行数:18,代码来源:gaussianfit.py

示例2: _makeRecipe

# 需要导入模块: from diffpy.srfit.fitbase import Profile [as 别名]
# 或者: from diffpy.srfit.fitbase.Profile import setObservedProfile [as 别名]
 def _makeRecipe(self, x, y, dy):
     '''Make a FitRecipe for fitting a Gaussian curve to data.
     '''
     profile = Profile()
     profile.setObservedProfile(x, y, dy)
     contribution = FitContribution("g1")
     contribution.setProfile(profile, xname="x")
     contribution.registerStringFunction(
             '1/sqrt(2 * pi * sig**2)', name='gaussnorm')
     contribution.setEquation(
             "A * gaussnorm * exp(-0.5 * (x - x0)**2/sig**2)")
     recipe = FitRecipe()
     recipe.addContribution(contribution)
     recipe.addVar(contribution.A)
     recipe.addVar(contribution.x0)
     recipe.addVar(contribution.sig)
     recipe.clearFitHooks()
     self.recipe = recipe
     return
开发者ID:diffpy,项目名称:cmi_exchange,代码行数:21,代码来源:ipy_gaussianfit.py

示例3: makeRecipe

# 需要导入模块: from diffpy.srfit.fitbase import Profile [as 别名]
# 或者: from diffpy.srfit.fitbase.Profile import setObservedProfile [as 别名]
def makeRecipe():
    """Make the recipe for the fit.

    The instructions for what we want to refine, and how to refine it will be
    defined within a FitRecipe instance. The job of a FitRecipe is to collect
    and associate all the data, the fitting equations, fitting variables,
    constraints and restrations. We will demonstrate each of these within the
    code. 

    Data is held within a Profile object. The Profile is simply a container
    that holds the data, and the theoretical profile once it has been
    calculated.

    Data is associated with a fitting equation within a FitContribution. The
    FitContribution defines the equation and parameters that will be adjusted
    to fit the data. The fitting equation can be defined within a function or
    optionally within the ProfileGenerator class. We won't need the
    ProfileGenerator class in this example since the signature of the fitting
    equation (the 'debye' function defined below) is so simple. The
    FitContribution also defines the residual function to optimize for the
    data/equation pair. This can be modified, but we won't do that here.
    
    """
        
    ## The Profile
    # Create a Profile to hold the experimental and calculated signal.
    profile = Profile()

    # Load data and add it to the profile. It is our responsibility to get our
    # data into the profile.
    xydy = numpy.array(map(float, data.split()), dtype=float).reshape(-1,3)
    x, y, dy = numpy.hsplit(xydy, 3)
    profile.setObservedProfile(x, y, dy)

    ## The FitContribution
    # The FitContribution associates the profile with the Debye function. 
    contribution = FitContribution("pb")
    # Tell the contribution about the Profile. We will need to use the
    # independent variable (the temperature) from the data to calculate the
    # theoretical signal, so give it an informative name ('T') that we can use
    # later.
    contribution.setProfile(profile, xname="T")

    # We now need to create the fitting equation.  We tell the FitContribution
    # to use the 'debye' function defined below. The 'registerFunction' method
    # will let us do this. Since we haven't told it otherwise,
    # 'registerFunction' will extract the name of the function ('debye') and
    # the names of the arguments ('T', 'm', 'thetaD'). These arguments will
    # become Parameters of the FitContribution. Since we named the x-variable
    # 'T' above, the 'T' in the 'debye' equation will refer to this x-variable
    # whenever it is used.
    contribution.registerFunction(debye)

    # Now we can create the fitting equation. We want to extend the 'debye'
    # equation by adding a vertical offset. We could wrap 'debye' in a new
    # function with an offset, and register that instead of 'debye', but what
    # we do here is easier. 
    #
    # When we set the fitting equation, we do not need to specify the
    # Parameters to the 'debye' function since the FitContribution already
    # knows what they are. If we choose to specify the arguments, we can make
    # adjustments to their input values.  We wish to have the thetaD value in
    # the debye equation to be positive, so we specify the input as abs(thetaD)
    # in the equation below.  Furthermore, we know 'm', the mass of lead, so we
    # can specify that as well.
    contribution.setEquation("debye(T, 207.2, abs(thetaD)) + offset")

    ## The FitRecipe
    # The FitRecipe lets us define what we want to fit. It is where we can
    # create variables, constraints and restraints. If we had multiple profiles
    # to fit simultaneously, the contribution from each could be added to the
    # recipe.
    recipe = FitRecipe()
    recipe.addContribution(contribution)

    # Specify which Parameters we want to refine.

    # Vary the offset
    recipe.addVar(contribution.offset, 0)
    # We also vary the Debye temperature.
    recipe.addVar(contribution.thetaD, 100)

    # We would like to 'suggest' that the offset should remain positive. This
    # is somethine that we know about the system that might help the refinement
    # converge to a physically reasonable result.  We will do this with a soft
    # contraint, or restraint. Here we restrain the offset variable to between
    # 0 and infinity. We tell the recipe that we want to scale the penalty for
    # breaking the restraint by the point-average chi^2 value so that the
    # restraint is roughly as significant as any other data point throughout
    # the fit.
    recipe.restrain(recipe.offset, lb = 0, scaled = True)

    # We're done setting up the recipe. We can now do other things with it.
    return recipe
开发者ID:cfarrow,项目名称:diffpy.srfit,代码行数:96,代码来源:debyemodel.py

示例4: data

# 需要导入模块: from diffpy.srfit.fitbase import Profile [as 别名]
# 或者: from diffpy.srfit.fitbase.Profile import setObservedProfile [as 别名]
# Plot the generated "observed" data (xobs, yobs).

import matplotlib.pyplot as plt
plt.ion(); plt.clf(); plt.hold(False)
plt.plot(xobs, yobs, 'x')
plt.title('y = 0.5*x + 3 generated with a normal noise at sigma=0.3')
plt.show()

# <demo> --- stop ---

# We are going to define a line fitting regression using SrFit.
# At first we create a SrFit Profile object that holds the observed data.

from diffpy.srfit.fitbase import Profile
linedata = Profile()
linedata.setObservedProfile(xobs, yobs, dyobs)

# The second step is to create a FitContribution object, which associates
# observed profile with a mathematical model for the dependent variable.

from diffpy.srfit.fitbase import FitContribution
linefit = FitContribution('linefit')
linefit.setProfile(linedata)
linefit.setEquation("A * x + B")

# SrFit objects can be examined by calling their show() function.  SrFit
# parses the model equation and finds two parameters A, B at independent
# variable x.  The values of parameters A, B are at this stage undefined.

linefit.show()
开发者ID:diffpy,项目名称:cmi_exchange,代码行数:32,代码来源:LinearFit.py


注:本文中的diffpy.srfit.fitbase.Profile.setObservedProfile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。