huawei-noah / trustworthyAI

Trustworthy AI related projects
Apache License 2.0
967 stars 217 forks source link

`hsic_test()` function documentation #90

Closed AlxndrMlk closed 1 year ago

AlxndrMlk commented 1 year ago

Hi!

I was using the hsic_test() function from the castle.common.independence_tests module for one of the chapters of my book.

The documentation says:

    Returns
    -------
    out: int, 0 or 1
        If 0, x and y are independent.
        If 1, x and y are not independent.

The results seem to suggest that this is actually reversed:

# Generate random data
z = np.random.randn(1000)
w = np.random.randn(1000)

# Dependent
hsic_test(
    x = z.reshape(-1, 1), 
    y = (z*2).reshape(-1, 1)
) 

returns 0.

At the same time:

# Independent
hsic_test(
    x = z.reshape(-1, 1), 
    y = w.reshape(-1, 1)
) 

returns 1.

It seems to me that the documentation incorrectly describes the return values.

shaido987 commented 1 year ago

Hi @AlxndrMlk,

Yes, you are correct. The documentation here is incorrect and the values should be swapped. I will update the source code here on github with a fix. Thanks for alerting us of the problem!