コード例 #1
0
# Fixed variables may be released with the "free" function.
# free("all") releases all fixed variables.
rec.free('all')

# Variables may be constrained to a result of an expression.
rec.constrain(rec.A, "2 * B")

# Perform linear fit where slope is twice the offset.
leastsq(rec.residual, rec.values)
print(FitResults(rec))
plt.plot(linedata.x, linedata.y, 'x', linedata.x, linedata.ycalc, '-')
plt.title('Line fit for variable A constrained to A = 2*B')

# <demo> --- stop ---

# Constraint expressions can be removed by calling the unconstrain function.
rec.unconstrain(rec.A)

# Variables may be restrained to a specific range.  Here "ub" is the upper
# boundary and "sig" acts as a standard deviation for ((x - ub)/sig)**2
# penalty function.

arst = rec.restrain(rec.A, ub=0.2, sig=0.001)

# Perform fit with the line slope restrained to a maximum value of 0.2:
leastsq(rec.residual, rec.values)
print(FitResults(rec))
plt.plot(linedata.x, linedata.y, 'x', linedata.x, linedata.ycalc, '-')
plt.title('Line fit with A restrained to an upper bound of 0.2')
コード例 #2
0
ファイル: LinearFit.py プロジェクト: diffpy/cmi_exchange
# Fixed variables may be released with the "free" function.
# free("all") releases all fixed variables.
rec.free('all')

# Variables may be constrained to a result of an expression.
rec.constrain(rec.A, "2 * B")

# Perform linear fit where slope is twice the offset.
leastsq(rec.residual, rec.values)
print(FitResults(rec))
plt.plot(linedata.x, linedata.y, 'x', linedata.x, linedata.ycalc, '-')
plt.title('Line fit for variable A constrained to A = 2*B')

# <demo> --- stop ---

# Constraint expressions can be removed by calling the unconstrain function.
rec.unconstrain(rec.A)

# Variables may be restrained to a specific range.  Here "ub" is the upper
# boundary and "sig" acts as a standard deviation for ((x - ub)/sig)**2
# penalty function.

arst = rec.restrain(rec.A, ub=0.2, sig=0.001)

# Perform fit with the line slope restrained to a maximum value of 0.2:
leastsq(rec.residual, rec.values)
print(FitResults(rec))
plt.plot(linedata.x, linedata.y, 'x', linedata.x, linedata.ycalc, '-')
plt.title('Line fit with A restrained to an upper bound of 0.2')