本文整理汇总了Python中scipy.interpolate.UnivariateSpline._optimize方法的典型用法代码示例。如果您正苦于以下问题:Python UnivariateSpline._optimize方法的具体用法?Python UnivariateSpline._optimize怎么用?Python UnivariateSpline._optimize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.interpolate.UnivariateSpline
的用法示例。
在下文中一共展示了UnivariateSpline._optimize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_basic_template_model
# 需要导入模块: from scipy.interpolate import UnivariateSpline [as 别名]
# 或者: from scipy.interpolate.UnivariateSpline import _optimize [as 别名]
def test_basic_template_model():
template_id = 25
try:
templates = fetch_rrlyrae_templates()
except(URLError, ConnectionError):
raise SkipTest("No internet connection: "
"data download test skipped")
phase, y = templates.get_template(templates.ids[template_id])
model = UnivariateSpline(phase, y, s=0, k=5)
theta = [17, 0.5, 0.3]
period = 0.63
rng = np.random.RandomState(0)
t = rng.rand(20)
mag = theta[0] + theta[1] * model((t / period - theta[2]) % 1)
model = RRLyraeTemplateModeler('ugriz')
model.fit(t, mag, 1)
# check that the model matches what we expect
assert_allclose(model._model(t, theta, period, template_id), mag)
# check that the optimized model matches the input
for use_gradient in [True, False]:
theta_fit = model._optimize(period, template_id, use_gradient)
assert_allclose(theta, theta_fit, rtol=1E-4)
# check that the chi2 is near zero
assert_allclose(model._chi2(theta_fit, period, template_id), 0,
atol=1E-8)