Пример #1
0
def test_simultaneous_minimization_profile():
    '''
    Test the calculation of minimization profiles by the minimizers.
    '''
    g1 = helpers.default_gaussian('g1', 'x1', 'c1', 's1')
    g2 = helpers.default_gaussian('g2', 'x2', 'c2', 's2')

    c1 = g1.args.get('c1')
    s2 = g2.args.get('s2')

    # Change the bounds to avoid evaluations to zero
    c1.bounds = (-2, +2)
    s2.bounds = (0.5, 1.5)

    d1 = g1.generate(1000)
    d2 = g2.generate(1000)

    cats = [minkit.Category('uml', g1, d1), minkit.Category('uml', g2, d2)]

    cv = np.linspace(*c1.bounds, 10)
    sv = np.linspace(*s2.bounds, 10)

    mp = tuple(a.flatten() for a in np.meshgrid(cv, sv))

    with minkit.simultaneous_minimizer(cats) as minimizer:
        minimizer.minimize()
        minimizer.minos_profile('c1')
        minimizer.minimization_profile('c1', cv)
        minimizer.minimization_profile(['c1', 's2'], mp)
Пример #2
0
def test_simultaneous_minimizer():
    '''
    Test the "simultaneous_minimizer" function.
    '''
    m = minkit.Parameter('m', bounds=(10, 20))

    # Common mean
    s = minkit.Parameter('s', 1, bounds=(0.1, +3))

    # First Gaussian
    c1 = minkit.Parameter('c1', 15, bounds=(10, 20))
    g1 = minkit.Gaussian('g1', m, c1, s)

    data1 = g1.generate(size=1000)

    # Second Gaussian
    c2 = minkit.Parameter('c2', 15, bounds=(10, 20))
    g2 = minkit.Gaussian('g2', m, c2, s)

    data2 = g2.generate(size=10000)

    categories = [
        minkit.Category('uml', g1, data1),
        minkit.Category('uml', g2, data2)
    ]

    with helpers.fit_test(categories, simultaneous=True) as test:
        with minkit.simultaneous_minimizer(categories,
                                           minimizer='minuit') as minuit:
            test.result = minuit.migrad()
Пример #3
0
def test_simultaneous_fcn_profile():
    '''
    Test the calculations of profiles in simultaneous minimizers.
    '''
    g1 = helpers.default_gaussian('g1', 'x1', 'c1', 's1')
    g2 = helpers.default_gaussian('g2', 'x2', 'c2', 's2')

    d1 = g1.generate(1000)
    d2 = g2.generate(1000)

    cats = [minkit.Category('uml', g1, d1), minkit.Category('uml', g2, d2)]

    cv = np.linspace(*g1.args.get('c1').bounds, 10)
    sv = np.linspace(*g2.args.get('s2').bounds, 10)

    mp = tuple(a.flatten() for a in np.meshgrid(cv, sv))

    with minkit.simultaneous_minimizer(cats) as minimizer:
        minimizer.fcn_profile('c1', cv)
        minimizer.fcn_profile(['c1', 's2'], mp)
Пример #4
0
def test_category():
    '''
    Test the "Category" class.
    '''
    with pytest.raises(TypeError):
        c = minkit.Category()