本文整理汇总了Python中dipy.reconst.csdeconv.ConstrainedSphericalDeconvModel.predict方法的典型用法代码示例。如果您正苦于以下问题:Python ConstrainedSphericalDeconvModel.predict方法的具体用法?Python ConstrainedSphericalDeconvModel.predict怎么用?Python ConstrainedSphericalDeconvModel.predict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dipy.reconst.csdeconv.ConstrainedSphericalDeconvModel
的用法示例。
在下文中一共展示了ConstrainedSphericalDeconvModel.predict方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_csd_predict
# 需要导入模块: from dipy.reconst.csdeconv import ConstrainedSphericalDeconvModel [as 别名]
# 或者: from dipy.reconst.csdeconv.ConstrainedSphericalDeconvModel import predict [as 别名]
def test_csd_predict():
"""
"""
SNR = 100
S0 = 1
_, fbvals, fbvecs = get_data('small_64D')
bvals = np.load(fbvals)
bvecs = np.load(fbvecs)
gtab = gradient_table(bvals, bvecs)
mevals = np.array(([0.0015, 0.0003, 0.0003],
[0.0015, 0.0003, 0.0003]))
angles = [(0, 0), (60, 0)]
S, sticks = multi_tensor(gtab, mevals, S0, angles=angles,
fractions=[50, 50], snr=SNR)
sphere = get_sphere('symmetric362')
odf_gt = multi_tensor_odf(sphere.vertices, mevals, angles, [50, 50])
response = (np.array([0.0015, 0.0003, 0.0003]), S0)
csd = ConstrainedSphericalDeconvModel(gtab, response)
csd_fit = csd.fit(S)
prediction = csd_predict(csd_fit.shm_coeff, gtab, response=response, S0=S0)
npt.assert_equal(prediction.shape[0], S.shape[0])
model_prediction = csd.predict(csd_fit.shm_coeff)
assert_array_almost_equal(prediction, model_prediction)
# Roundtrip tests (quite inaccurate, because of regularization):
assert_array_almost_equal(csd_fit.predict(gtab, S0=S0),S,decimal=1)
assert_array_almost_equal(csd.predict(csd_fit.shm_coeff, S0=S0),S,decimal=1)
示例2: test_csd_predict
# 需要导入模块: from dipy.reconst.csdeconv import ConstrainedSphericalDeconvModel [as 别名]
# 或者: from dipy.reconst.csdeconv.ConstrainedSphericalDeconvModel import predict [as 别名]
def test_csd_predict():
"""
Test prediction API
"""
SNR = 100
S0 = 1
_, fbvals, fbvecs = get_data('small_64D')
bvals = np.load(fbvals)
bvecs = np.load(fbvecs)
gtab = gradient_table(bvals, bvecs)
mevals = np.array(([0.0015, 0.0003, 0.0003],
[0.0015, 0.0003, 0.0003]))
angles = [(0, 0), (60, 0)]
S, sticks = multi_tensor(gtab, mevals, S0, angles=angles,
fractions=[50, 50], snr=SNR)
sphere = small_sphere
odf_gt = multi_tensor_odf(sphere.vertices, mevals, angles, [50, 50])
response = (np.array([0.0015, 0.0003, 0.0003]), S0)
csd = ConstrainedSphericalDeconvModel(gtab, response)
csd_fit = csd.fit(S)
# Predicting from a fit should give the same result as predicting from a
# model, S0 is 1 by default
prediction1 = csd_fit.predict()
prediction2 = csd.predict(csd_fit.shm_coeff)
npt.assert_array_equal(prediction1, prediction2)
npt.assert_array_equal(prediction1[..., gtab.b0s_mask], 1.)
# Same with a different S0
prediction1 = csd_fit.predict(S0=123.)
prediction2 = csd.predict(csd_fit.shm_coeff, S0=123.)
npt.assert_array_equal(prediction1, prediction2)
npt.assert_array_equal(prediction1[..., gtab.b0s_mask], 123.)
# For "well behaved" coefficients, the model should be able to find the
# coefficients from the predicted signal.
coeff = np.random.random(csd_fit.shm_coeff.shape) - .5
coeff[..., 0] = 10.
S = csd.predict(coeff)
csd_fit = csd.fit(S)
npt.assert_array_almost_equal(coeff, csd_fit.shm_coeff)
# Test predict on nd-data set
S_nd = np.zeros((2, 3, 4, S.size))
S_nd[:] = S
fit = csd.fit(S_nd)
predict1 = fit.predict()
predict2 = csd.predict(fit.shm_coeff)
npt.assert_array_almost_equal(predict1, predict2)
示例3: test_csd_predict_multi
# 需要导入模块: from dipy.reconst.csdeconv import ConstrainedSphericalDeconvModel [as 别名]
# 或者: from dipy.reconst.csdeconv.ConstrainedSphericalDeconvModel import predict [as 别名]
def test_csd_predict_multi():
"""
Check that we can predict reasonably from multi-voxel fits:
"""
S0 = 123.
_, fbvals, fbvecs = get_data('small_64D')
bvals = np.load(fbvals)
bvecs = np.load(fbvecs)
gtab = gradient_table(bvals, bvecs)
response = (np.array([0.0015, 0.0003, 0.0003]), S0)
csd = ConstrainedSphericalDeconvModel(gtab, response)
coeff = np.random.random(45) - .5
coeff[..., 0] = 10.
S = csd.predict(coeff, S0=123.)
multi_S = np.array([[S, S], [S, S]])
csd_fit_multi = csd.fit(multi_S)
S0_multi = np.mean(multi_S[..., gtab.b0s_mask], -1)
pred_multi = csd_fit_multi.predict(S0=S0_multi)
npt.assert_array_almost_equal(pred_multi, multi_S)