Пример #1
0
def test_complex_model_complex_data():
    # ======================================================================
    "Check the fit of a complex-valued model to complex-valued data"
    fitResult = fit(mymodel, y)

    assert np.allclose(fitResult.model.real, y.real) and np.allclose(
        fitResult.model.imag, y.imag)
Пример #2
0
def test_complex_model_real_data():
    # ======================================================================
    "Check the fit of a complex-valued model to real-valued data"
    fitResult = fit(mymodel, y.real)

    assert np.allclose(fitResult.model.real, y.real) and np.allclose(
        fitResult.model.imag, np.zeros_like(y.real))
Пример #3
0
def test_ex_fwd5pdeer_fit(): 
    "Check the forward 5-pulse DEER experimental model in fitting."

    experiment = ex_fwd5pdeer(tau1,tau2,tau3, pathways=[1,2,3])
    Vmodel = dipolarmodel(tdeer,r,Bmodel=bg_hom3d,experiment=experiment)
    result = fit(Vmodel,Vfwd5pdeer,nonlin_tol=1e-3)

    assert np.allclose(Vfwd5pdeer,result.model,atol=1e-2) and ovl(result.P/1e5,Pr)>0.975
Пример #4
0
def test_ex_4pdeer_fit(): 
    "Check the 4-pulse DEER experimental model."

    experiment = ex_4pdeer(tau1,tau2, pathways=[1,2])
    Vmodel = dipolarmodel(tdeer,r,Bmodel=bg_hom3d,experiment=experiment)
    result = fit(Vmodel,V4pdeer,nonlin_tol=1e-3)

    assert np.allclose(V4pdeer,result.model,atol=1e-2) and ovl(result.P/1e5,Pr)>0.975
Пример #5
0
def test_fit_Pnonparametric(): 
    "Check that the model with one dipolar pathway is correct"

    Vmodel = dipolarmodel(t,r,Bmodel=bg_hom3d,npathways=1)
    
    result = fit(Vmodel,V1path,nonlin_tol=1e-5)

    assert ovl(result.P/1e5,Pr)>0.975
Пример #6
0
def test_ex_ridme_fit(): 
    "Check the RIDME experimental model in fitting."

    experiment = ex_ridme(tau1,tau2, pathways=[1,2,3])
    Vmodel = dipolarmodel(tridme,r,Bmodel=bg_hom3d,experiment=experiment)
    result = fit(Vmodel,Vridme,nonlin_tol=1e-3)

    assert np.allclose(Vridme,result.model,atol=1e-2) and ovl(result.P/1e5,Pr)>0.975
Пример #7
0
def test_fit_1pathways(): 
    "Check that the model can be correctly fitted with one dipolar pathway"

    Vmodel = dipolarmodel(t,r,dd_gauss,bg_hom3d,npathways=1)
    
    result = fit(Vmodel,V1path,nonlin_tol=1e-3)

    assert np.allclose(result.model,V1path)
Пример #8
0
def test_preserve_original():
    "Check that the original model is not changed by the function"
    model = Model(gauss)
    model.mean.par0 = 3
    model.width.par0 = 0.2

    _ = fit(model, mock_data)
    assert model._parameter_list() == ['mean', 'width']
Пример #9
0
def test_fit_nonparametric():
    #================================================================
    "Check that a semiparametric model can be correctly fitted"
    model = _getmodel('nonparametric')

    fitResult = fit(model, mock_data)

    assert np.allclose(fitResult.model, mock_data, atol=1e-3)
Пример #10
0
def test_CIs_nonparametric():
    #================================================================
    "Check the default confidence intervals of the fitted parameters"
    model = _getmodel('semiparametric')

    fitResult = fit(model, mock_data)

    assert_attributes_cis(fitResult, ['amp1', 'amp2'])
Пример #11
0
def test_ex_sifter_fit(): 
    "Check the SIFTER experimental model in fitting."

    experiment = ex_sifter(tau1,tau2)
    Vmodel = dipolarmodel(tsifter,r,Bmodel=bg_hom3d,experiment=experiment)
    result = fit(Vmodel,Vsifter,nonlin_tol=1e-3)

    assert np.allclose(Vsifter,result.model,atol=1e-2) and ovl(result.P/1e5,Pr)>0.975
Пример #12
0
def test_fit_weight_unbounded(): 
    "Check fitting with a penalty with unbounded weight"
    
    model = deepcopy(dd_gauss)
    penaltyobj = Penalty(penalty_fcn,'icc')

    result = fit(model,mock_data,x,penalties=penaltyobj)

    assert not ovl(result.model,mock_data)>0.975
Пример #13
0
def test_fit_semiparametric_vec_constant():
    #================================================================
    "Check that a vectorized semiparametric model can be correctly fitted while specifying an axis"
    model = _getmodel_axis('semiparametric_vec')

    x = np.linspace(0, 10, 100)
    fitResult = fit(model, mock_data_fcn(x), x, noiselvl=1e-10)

    assert np.allclose(fitResult.model, mock_data_fcn(x), atol=1e-3)
Пример #14
0
def test_fit_semiparametric_constant():
    #================================================================
    "Check that a semiparametric model can be correctly fitted while specifying an axis"
    model = _getmodel_axis('semiparametric')

    x = np.linspace(0, 10, 200)
    fitResult = fit(model, mock_data_fcn(x), x)

    assert np.allclose(fitResult.model, mock_data_fcn(x))
Пример #15
0
def test_fit_nonparametric_frozen():
    #================================================================
    "Check that a semiparametric model can be correctly fitted"
    model = _getmodel('nonparametric')

    model.amp1.freeze(0.5)
    fitResult = fit(model, mock_data)

    assert np.allclose(fitResult.model, mock_data)
Пример #16
0
def test_bootCIs_nonparametric():
    #================================================================
    "Check the bootstrapped confidence intervals of the fitted parameters"
    model = _getmodel('semiparametric')

    noisydata = mock_data + whitegaussnoise(0.01, seed=1)
    fitResult = fit(model, noisydata, bootstrap=3)

    assert_attributes_cis(fitResult, ['amp1', 'amp2'])
Пример #17
0
def test_real_model_complex_data():
    # ======================================================================
    "Check the fit of a real-valued model to complex-valued data"
    mymodel = Model(gauss)
    mymodel.mean.set(par0=4, lb=1, ub=6)
    mymodel.width.set(par0=0.2, lb=0.05, ub=5)
    fitResult = fit(mymodel, y.real + 1j * np.zeros_like(y.imag))

    assert np.allclose(fitResult.model.real, y.real) and np.allclose(
        fitResult.model.imag, np.zeros_like(y.real))
Пример #18
0
def test_fit_weight_frozen(): 
    "Check fitting with a penalty with frozen weight"
    
    model = deepcopy(dd_gauss)
    penaltyobj = Penalty(penalty_fcn,'icc')
    penaltyobj.weight.freeze(0.00001)

    result = fit(model,mock_data,x,penalties=penaltyobj)

    assert ovl(result.model,mock_data)>0.975
Пример #19
0
def test_fit_icc(): 
    "Check fitting with a penalty with ICC-selected weight"

    model = deepcopy(dd_gauss)
    penaltyobj = Penalty(penalty_fcn,'icc')
    penaltyobj.weight.set(lb=1e-6,ub=1e1)

    result = fit(model,mock_data,x,penalties=penaltyobj)

    assert ovl(result.model,mock_data)>0.975
Пример #20
0
def test_fit_parametric_frozen():
    #================================================================
    "Check that a parametric model can be correctly fitted"
    model = _getmodel('parametric')

    model.mean1.freeze(3)

    fitResult = fit(model, mock_data)

    assert np.allclose(fitResult.model, mock_data)
Пример #21
0
def test_fit_weight_bounded(): 
    "Check fitting with a penalty with bounded weight"
    
    model = deepcopy(dd_gauss)
    penaltyobj = Penalty(penalty_fcn,'aicc')
    penaltyobj.weight.set(lb=1e-10,ub=1e1)

    result = fit(model,mock_data,x,penalties=penaltyobj)

    assert ovl(result.model,mock_data)>0.975
Пример #22
0
def test_fit_2pathways(): 
    "Check that the model can be correctly fitted with two dipolar pathways"

    Vmodel = dipolarmodel(t,r,dd_gauss,bg_hom3d,npathways=2)
    Vmodel.reftime1.freeze(0)
    Vmodel.reftime2.freeze(2)
    
    result = fit(Vmodel,V2path,nonlin_tol=1e-3)

    assert np.allclose(result.model,V2path)
Пример #23
0
def test_fit_fullyfrozen_linear():
    #================================================================
    "Check that a model with all linear parameters frozen can be fitted"

    model = _getmodel('semiparametric')
    model.amp1.freeze(0.5)
    model.amp2.freeze(0.6)

    fitResult = fit(model, mock_data)

    assert np.allclose(fitResult.model, mock_data)
Пример #24
0
def test_relate_fit(): 
    "Check that the method works correctly for one related parameter"
    model = dl.dd_gauss
    x = np.linspace(0,10,400)
    ref = model(x,4,0.2)

    newmodel = relate(model, width = lambda mean: mean/20)

    result = fit(newmodel,ref,x)

    assert np.allclose(result.model,ref)
Пример #25
0
def test_fit_model():
    "Check that that merge works correctly for two models"
    model1 = dl.dd_gauss
    model2 = dl.dd_rice
    model = merge(model1, model2)
    x = np.linspace(0, 10, 400)
    truth = [model1(x, 3, 0.2), model2(x, 4, 0.5)]
    result = fit(model, truth, x, x, weights=[1, 1])

    assert np.allclose(result.model[0], truth[0]) and np.allclose(
        result.model[1], truth[1])
Пример #26
0
def test_fit_propagate_semiparametric_vec():
    #================================================================
    "Check the propagate method of the fitResult object for evaluation of a vectorized semiparametric model"
    model = _getmodel_axis('semiparametric_vec')

    x = np.linspace(0, 10, 200)
    fitResult = fit(model, mock_data_fcn(x), x)

    modeluq = fitResult.propagate(model, x, lb=np.zeros_like(x))

    assert_cis(modeluq)
Пример #27
0
def test_fit_evaluate_semiparametric_vec():
    #================================================================
    "Check the evaluate method of the fitResult object for evaluation of a vectorized semiparametric model"
    model = _getmodel_axis('semiparametric_vec')

    x = np.linspace(0, 10, 200)
    fitResult = fit(model, mock_data_fcn(x), x)

    response = fitResult.evaluate(model, x)

    assert np.allclose(response, mock_data_fcn(x))
Пример #28
0
def test_fit_propagate_nonparametric_vec_bootstrapped():
    #================================================================
    "Check the propagate method of the fitResult object for evaluation of a vectorized nonparametric model"
    model = _getmodel_axis('nonparametric_vec', vec=80)

    x = np.linspace(0, 10, 80)
    fitResult = fit(model, mock_data_fcn(x), x, bootstrap=3)

    modeluq = fitResult.propagate(model, x, lb=np.zeros_like(x))

    assert_cis(modeluq)
Пример #29
0
def test_fit_multiple_penalties(): 
    "Check fitting with multiple penalties"
    
    model = deepcopy(dd_gauss)
    penaltyobj = Penalty(penalty_fcn,'icc')
    penaltyobj2 = deepcopy(penaltyobj)
    penaltyobj.weight.freeze(0.00001)
    penaltyobj2.weight.freeze(0.00001)

    result = fit(model,mock_data,x,penalties=[penaltyobj,penaltyobj2])

    assert ovl(result.model,mock_data)>0.975
Пример #30
0
def test_fit_fullyfrozen_nonlinear():
    #================================================================
    "Check that a model with all nonlinear parameters frozen can be fitted"

    model = _getmodel('semiparametric')
    model.mean1.freeze(3)
    model.mean2.freeze(4)
    model.width1.freeze(0.5)
    model.width2.freeze(0.2)

    fitResult = fit(model, mock_data)

    assert np.allclose(fitResult.model, mock_data)