# ./tests/test_maxent.py
""" Tests the maxent classes.

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 
SPDX-License-Identifier: Apache-2.0
"""
import numpy as np
import pytest

from src.cmaxent.maxent import *
from src.cmaxent.moments import *
from experiments.synthetic_data_generation import *


@pytest.mark.parametrize("data", [make_data_known_multipliers_underspecified_conditional_independence()])
def test_ConditionalMAXENT_givenFirstAndSecondMomentLossAndResidualsAreZero(data):
    mean = Mean(data["mean"])
    variance = SecondOrder(data["variance"])
    moment_constraints = {"mean":mean, 
                        "variance":variance}
    known = ConditionalMAXENT(x=data["y"]+data["x"],
                                moment_dict=moment_constraints,
                                probability_x=data["px"],
                                seed=42)
    known.fit()

    assert np.allclose(known.compute_loss(known.multipliers), 0)
    assert np.allclose(known.expectations["mean"], data["mean"])
    assert np.allclose(known.expectations["variance"], data["variance"])

# ./tests/test_maxent.py
""" Tests the maxent classes.

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 
SPDX-License-Identifier: Apache-2.0
"""
import numpy as np
import pytest

from src.cmaxent.maxent import *
from src.cmaxent.moments import *
from experiments.synthetic_data_generation import *


@pytest.mark.parametrize("data", [make_data_known_multipliers_underspecified_conditional_independence()])
def test_ConditionalMAXENT_givenFirstAndSecondMomentLossAndResidualsAreZero(data):
    mean = Mean(data["mean"])
    variance = SecondOrder(data["variance"])
    moment_constraints = {"mean":mean, 
                        "variance":variance}
    known = ConditionalMAXENT(x=data["y"]+data["x"],
                                moment_dict=moment_constraints,
                                probability_x=data["px"],
                                seed=42)
    known.fit()

    assert np.allclose(known.compute_loss(known.multipliers), 0)
    assert np.allclose(known.expectations["mean"], data["mean"])
    assert np.allclose(known.expectations["variance"], data["variance"])

# ./tests/test_maxent.py Tests the maxent classes.  Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.  SPDX-License-Identifier: Apache-2.0