コード例 #1
0
def test_convergence(reference_sample, expected_weights, controls_households,
                     controls_individuals):
    weights = fit_hipf(reference_sample=reference_sample,
                       controls_individuals=controls_individuals,
                       controls_households=controls_households,
                       maxiter=10)
    assert_weights_equal(expected_weights['infinity'], weights)
コード例 #2
0
def test_second_iteration(reference_sample, expected_weights,
                          controls_households, controls_individuals):
    weights = fit_hipf(reference_sample=reference_sample,
                       controls_individuals=controls_individuals,
                       controls_households=controls_households,
                       maxiter=2)
    assert_weights_equal(expected_weights[10],
                         weights)  # 5 iteration in paper represent 1 iteration
コード例 #3
0
def test_fails_with_invalid_type_reference_sample(reference_sample,
                                                  controls_households, controls_individuals):
    with pytest.raises(AssertionError):
        weights = fit_hipf(
            reference_sample=np.array(reference_sample),
            controls_individuals=controls_individuals,
            controls_households=controls_households,
            maxiter=2
        )
コード例 #4
0
def test_weights_tolerance_criteria_does_not_stop_early(
        reference_sample, expected_weights, tol, controls_households,
        controls_individuals):
    weights = fit_hipf(reference_sample=reference_sample,
                       controls_individuals=controls_individuals,
                       controls_households=controls_households,
                       residuals_tol=1e-16,
                       weights_tol=tol,
                       maxiter=10)
    assert_weights_equal(expected_weights['infinity'], weights)
コード例 #5
0
def test_converges(reference_sample, controls_households, controls_individuals, tol):
    weights = fit_hipf(
        reference_sample=reference_sample,
        controls_individuals=controls_individuals,
        controls_households=controls_households,
        weights_tol=2.220446e-16,
        residuals_tol=1e-6,
        maxiter=200
    )
    residuals = _all_residuals(reference_sample, weights, controls_households, controls_individuals)
    assert residuals.abs().max() < tol
コード例 #6
0
def test_same_result_like_mlipf(reference_sample, expected_weights, controls_individuals,
                                controls_households):
    weights = fit_hipf(
        reference_sample=reference_sample,
        controls_individuals=controls_individuals,
        controls_households=controls_households,
        weights_tol=2.220446e-16,
        residuals_tol=1e-6,
        maxiter=200
    )
    assert_weights_equal(expected_weights, weights)
コード例 #7
0
def test_weights_tolerance_criteria_stops_early(reference_sample,
                                                expected_weights, tol,
                                                controls_households,
                                                controls_individuals):
    weights = fit_hipf(reference_sample=reference_sample,
                       controls_individuals=controls_individuals,
                       controls_households=controls_households,
                       residuals_tol=1e-16,
                       weights_tol=tol,
                       maxiter=10)
    with pytest.raises(AssertionError):
        assert_weights_equal(expected_weights['infinity'], weights)