Exemplo n.º 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)
Exemplo n.º 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))
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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']
Exemplo n.º 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)
Exemplo n.º 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'])
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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))
Exemplo n.º 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)
Exemplo n.º 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'])
Exemplo n.º 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))
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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])
Exemplo n.º 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)
Exemplo n.º 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))
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 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)