Skip to content

Update GIN #87

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
45 changes: 45 additions & 0 deletions causallearn/search/HiddenCausal/GIN/FisherTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#-------------------------------------------------------------------------------
# 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):

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

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?

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:

TP = 1e-05
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_pval = 1-chi2.cdf(Fisher_Stat, 2*L) #自由度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.

same


#print(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.

remove this


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]

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)


if __name__ == '__main__':
main()
Loading