Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test for generate_data #148

Merged
merged 2 commits into from
Nov 11, 2020
Merged

test: add test for generate_data #148

merged 2 commits into from
Nov 11, 2020

Conversation

redeboer
Copy link
Member

Needed for #146

@redeboer redeboer added the 🔨 Maintenance Maintenance and upkeep improvements label Nov 10, 2020
@redeboer redeboer requested a review from spflueger November 10, 2020 09:36
Comment on lines 49 to 84
def test_generate_data(canonical_model: es.AmplitudeModel):
n_phsp = 1000
n_data = 100
model = canonical_model
kinematics = HelicityKinematics.from_model(model)
phsp_sample = generate_phsp(n_phsp, kinematics)
builder = IntensityBuilder(model.particles, kinematics, phsp_sample)
intensity = builder.create_intensity(model)
data_sample = generate_data(n_data, kinematics, intensity)
assert len(data_sample) == len(model.kinematics.final_state)
for sample in data_sample:
assert len(sample) == n_data
data_sq = data_sample ** 2
e_sq = data_sq[:, :, 3]
p3_sq = data_sq[:, :, :3]
m_sq = np.abs(e_sq - p3_sq.sum(axis=2))
assert pytest.approx(list(np.sqrt(m_sq.mean(axis=1))), abs=1e-4) == [
0,
0.135,
0.135,
]
data_set = kinematics.convert(data_sample)
assert set(data_set) == {
"mSq_2",
"mSq_2_3_4",
"mSq_3",
"mSq_3_4",
"mSq_4",
"phi+3+4_vs_2",
"phi+3_4+2",
"theta+3+4_vs_2",
"theta+3_4+2",
}
assert pytest.approx(data_set["mSq_2"].mean()) == 0
assert pytest.approx(data_set["mSq_3"].mean()) == data_set["mSq_4"].mean()
assert pytest.approx(data_set["mSq_3_4"].mean(), abs=1e-1) == 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would test these kinematic related things like masses inside the phase space generation, since that is related to that. The generate data is related to the model, so we should perform checks that test for some expected distribution or so.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which checks do you suggest? (The masses are already checked in test_generate_phsp.)

Copy link
Member

@spflueger spflueger Nov 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some distribution checks in pycompwa that we could move here https://github.com/ComPWA/pycompwa/tree/master/tests/angular-distribution-tests . But they are slighly more complicated though and took a few more seconds to run.

For now we could just check that the sample sizes match and extend the tests to distribution verifications later on

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@redeboer redeboer merged commit c775f5b into ComPWA:epic/23-data-module Nov 11, 2020
@redeboer redeboer deleted the test-generate_data branch November 11, 2020 13:23
redeboer added a commit that referenced this pull request Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 Maintenance Maintenance and upkeep improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants