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

Plugin "marginal_distributions" does not sample from marginal distributions #299

Open
gg-tmp opened this issue Oct 16, 2024 · 0 comments
Open

Comments

@gg-tmp
Copy link

gg-tmp commented Oct 16, 2024

Description

I had the impression that the plugin "marginal_distributions" is supposed to sample (independently) from the marginal distributions of the given dataset. But, in fact, it does not seem to sample at all!

How to Reproduce

A brief experiment demonstrates the problem.

from synthcity.plugins import Plugins
from synthcity.plugins.core.dataloader import GenericDataLoader
import pandas as pd
import numpy as np

# Generate sample of two independent Variables

# Parameters
N = 1_000  # Sample size
p = 0.6  # Probability P(X1 = "I")
q = 0.3  # Probability P(X2 = "A")

# Categoricals
v1 = ["I", "II"]
X1 = np.random.choice(v1, size=N, p=[p, 1 - p])
v2 = ["A", "B"]
X2 = np.random.choice(v2, size=N, p=[q, 1 - q])

# # Integers
# v1 = [-2, -1]
# X1 = np.random.choice(v1, size=N, p=[p, 1 - p])
# v2 = [ 1, 2]
# X2 = np.random.choice(v2, size=N, p=[q, 1 - q])

data = GenericDataLoader(list(zip(X1, X2)))
print(data)

syn_model = Plugins().get("marginal_distributions")

syn_model.fit(data)
tt = syn_model.generate(N).dataframe()
print(syn_model.sampling_strategy)

print(tt)

df = pd.DataFrame({
    '0': v1,
    '1': v2
}, dtype=tt["0"].dtype)
# Replicate the DataFrame N/2 times
df_replicated = pd.concat([df] * int(N / 2), ignore_index=True)

print(tt.equals(df_replicated))

Expected Behavior

I would have expected that

  1. tt is random
  2. the marginal distributions of tt are (up to sampling error) equal to the marginal distributions of data, i.e. p respectively q.

System Information

  • OS: Microsoft Windows [Version 10.0.22631.4317]
  • Language Version: Python 3.11.9
  • synthcity Version: 0.2.11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant