Skip to content
New issue

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

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

Already on GitHub? # to your account

Mean sign is flipped in Gaussian inference #12

Open
RachelMcNeely opened this issue Apr 14, 2023 · 0 comments
Open

Mean sign is flipped in Gaussian inference #12

RachelMcNeely opened this issue Apr 14, 2023 · 0 comments

Comments

@RachelMcNeely
Copy link

The sign of the mean is flipped when retrieving the parameters for Gaussian inference. This is being done in the .P() method ( https://github.com/vangj/py-bbn/blob/master/pybbn/gaussian/inference.py#L71 ). Used the following code from sample docs to recreate:

import numpy as np
import pandas as pd
from pybbn.gaussian.inference import GaussianInference

def get_cowell_data():
    """
    Gets Cowell data.

    :return: Data and headers.
    """
    n = 10000
    Y = np.random.normal(0, 1, n)
    X = np.random.normal(Y, 1, n)
    Z = np.random.normal(X, 1, n)

    D = np.vstack([Y, X, Z]).T
    return D, ['Y', 'X', 'Z']


# assume we have data and headers (variable names per column)
# X is the data (rows are observations, columns are variables)
# H is just a list of variable names
X, H = get_cowell_data()
![Screen Shot 2023-04-14 at 11 22 44 AM](https://user-images.githubusercontent.com/16946130/232086920-bf55358e-d798-4789-8017-b25e70c6a57b.png)

# then we can compute the means and covariance matrix easily
M = X.mean(axis=0)
E = np.cov(X.T)
print('Means from data: ', M)

g = GaussianInference(H, M, E)
print('Means returned from g.P: ', g.P)

image

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant