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

Update GIN #87

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Update GIN #87

wants to merge 14 commits into from

Conversation

fengxie009
Copy link

No description provided.

Copy link
Contributor

@tofuwen tofuwen left a comment

Choose a reason for hiding this comment

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

did part of review as code style examples~

Comment on lines 1 to 10
#-------------------------------------------------------------------------------
# Name: 模块1
# Purpose:
#
# Author: YY
#
# Created: 03/03/2021
# Copyright: (c) YY 2021
# Licence: <your licence>
#-------------------------------------------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

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

We should delete this, or fill it.

In the open-source code, we should maintain high code quality --- we shouldn't allow any unnecessary comments in the code.

Sorry there are lots of rules in industry code that are different from research code :(

import math
from scipy.stats import chi2

def FisherTest(pvals,alph=0.01):
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: comma between different variables.

You can follow Google Python codestyle when writing code: https://google.github.io/styleguide/pyguide.html

You can find automated tool like pylint in the link.

Suggested change
def FisherTest(pvals,alph=0.01):
def FisherTest(pvals, alph=0.01):

from scipy.stats import chi2

def FisherTest(pvals,alph=0.01):
Fisher_Stat=0
Copy link
Contributor

Choose a reason for hiding this comment

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

space between operand

Suggested change
Fisher_Stat=0
Fisher_Stat = 0

def FisherTest(pvals,alph=0.01):
Fisher_Stat=0
L = len(pvals)
for i in range(0,L):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for i in range(0,L):
for i in range(0, L):

Copy link
Contributor

Choose a reason for hiding this comment

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

address this?

Fisher_Stat=0
L = len(pvals)
for i in range(0,L):
if pvals[i] ==0:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if pvals[i] ==0:
if pvals[i] == 0:

Comment on lines 30 to 33
if Fisher_pval >alph:
return True,Fisher_pval
else:
return False,Fisher_pval
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if Fisher_pval >alph:
return True,Fisher_pval
else:
return False,Fisher_pval
return Fisher_pval > alph, Fisher_pval



def main():
pvals = [0.01,0.9]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
pvals = [0.01,0.9]
pvals = [0.01, 0.9]


def main():
pvals = [0.01,0.9]
FisherTest(pvals,0.1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
FisherTest(pvals,0.1)
FisherTest(pvals, 0.1)

Comment on lines 18 to 25
if pval > alpha:
flag = True
else:
flag = False

if not flag:#not false == ture ---> if false
#print(X,Z,flag)
return False
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if pval > alpha:
flag = True
else:
flag = False
if not flag:#not false == ture ---> if false
#print(X,Z,flag)
return False
if pval <= alpha:
return False

Comment on lines 52 to 55
if pvalue >alph:
return True
else:
return False
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if pvalue >alph:
return True
else:
return False
return pvalue > alph

@tofuwen
Copy link
Contributor

tofuwen commented Dec 7, 2022

BTW, for every PR, we should have an informative description.

Could you add your description? Here is a good example PR with great descriptions: #85

@fengxie009
Copy link
Author

Updates

Modified the whole GIN package to make it more readable

  1. GIN.py: GIN(data, indep_test_method='kci', alpha=0.05, MAX_Factor = 2)
    The MAX_Factor parameter is added to make the GIN algorithm more efficient

Notes
Please kindly note that the GIN method highly relies on the independent test, e.g., KCI or HSIC. Please try to modify the default parameters in the independent test method, such as kernel width, when the GIN method can not output any information.

Copy link
Contributor

@tofuwen tofuwen left a comment

Choose a reason for hiding this comment

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

Thanks so much for your great work! This version is much better than previous version!

Added more comments.

And there are two main changes we need for this PR:

  1. could you write tests for GIN method to make sure GIN behaves as expected?
  2. could you edit your first message to include the description of this PR? We need to have great descriptions for every PR, so in the future, when we come back or if our users are checking the PR, we / they can know what is happening.

import math
from scipy.stats import chi2

def FisherTest(pvals, alpha = 0.01):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def FisherTest(pvals, alpha = 0.01):
def FisherTest(pvals, alpha=0.01):

def FisherTest(pvals,alph=0.01):
Fisher_Stat=0
L = len(pvals)
for i in range(0,L):
Copy link
Contributor

Choose a reason for hiding this comment

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

address this?

else:
TP = pvals[i]

Fisher_Stat = Fisher_Stat - 2*math.log(TP)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Fisher_Stat = Fisher_Stat - 2*math.log(TP)
Fisher_Stat = Fisher_Stat - 2 * math.log(TP)


Fisher_Stat = Fisher_Stat - 2*math.log(TP)

Fisher_pval = 1 - chi2.cdf(Fisher_Stat, 2*L)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Fisher_pval = 1 - chi2.cdf(Fisher_Stat, 2*L)
Fisher_pval = 1 - chi2.cdf(Fisher_Stat, 2 * L)

Comment on lines +17 to +20
if Fisher_pval >alpha:
return True, Fisher_pval
else:
return False, Fisher_pval
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if Fisher_pval >alpha:
return True, Fisher_pval
else:
return False, Fisher_pval
return Fisher_pval > alpha, Fisher_pval

Comment on lines +152 to +157
def _entropy(u):
"""Calculate entropy using the maximum entropy approximations."""
k1 = 79.047
k2 = 7.4129
gamma = 0.37457
return (1 + np.log(2 * np.pi)) / 2 - k1 * (np.mean(np.log(np.cosh(u))) - gamma)**2 - k2 * (np.mean(u * np.exp((-u**2) / 2)))**2
Copy link
Contributor

Choose a reason for hiding this comment

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

seems equivalent to previous functions?

Re-use code whenever possible and never duplicate code


def MI_1(x1, y1):
"""estimating mutual information by Non-parametric computation of entropy and mutual-information"""
x=x1.reshape(len(x1),1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
x=x1.reshape(len(x1),1)
x = x1.reshape(len(x1), 1)

def MI_1(x1, y1):
"""estimating mutual information by Non-parametric computation of entropy and mutual-information"""
x=x1.reshape(len(x1),1)
y=y1.reshape(len(y1),1)
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Comment on lines +31 to +39
if pval > alpha:
flag = True
else:
flag = False

if not flag:
return False

return True
Copy link
Contributor

Choose a reason for hiding this comment

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

I remembered I commented on this before?

Suggested change
if pval > alpha:
flag = True
else:
flag = False
if not flag:
return False
return True
if pval <= alpha:
return False
return True

temp = np.array(data[:, i])
mi = ID.MI_1(result, temp)
MIS += mi
MIS = MIS/len(Z)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
MIS = MIS/len(Z)
MIS = MIS / len(Z)

@tofuwen
Copy link
Contributor

tofuwen commented Dec 20, 2022

Screen Shot 2022-12-20 at 3 42 39 PM

Basically add description there. People will tend to read the first block, but not the conversions (because it's too much)

So in industry (or open-sourced project), it's a good practice to have great descriptions in the first cell.

@kunwuz
Copy link
Collaborator

kunwuz commented Jan 31, 2023

Hi all @fengxie009 @tofuwen, just would like to quickly check whether there are any updates on this PR. Please feel free to let others know if there are any questions :)

@fengxie009
Copy link
Author

fengxie009 commented Feb 3, 2023 via email

@tofuwen
Copy link
Contributor

tofuwen commented Mar 22, 2023

Hi @fengxie009,

Do we have some updates here? :)

We need to ensure that we have unit tests coverage for all the methods, as it's required here: #100

And we will build the CI once your unit tests are completed. :)

@kunwuz
Copy link
Collaborator

kunwuz commented Oct 12, 2023

Hi @fengxie009 and @tofuwen, are there any updates on this PR? I believe some quick tests to make sure that the modification is correct is enough to merge this. It seems to be around too long.

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

Successfully merging this pull request may close these issues.

None yet

3 participants