Skip to content

Mean sign is flipped in Gaussian inference #12

@RachelMcNeely

Description

@RachelMcNeely

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions