Skip to content

Commit

Permalink
fix: hsic stat
Browse files Browse the repository at this point in the history
Signed-off-by: ZhiyiHuang <huangzhiyi.chn@gmail.com>
  • Loading branch information
zhi-yi-huang committed Jun 30, 2024
1 parent ac36b32 commit 9ad2c8e
Show file tree
Hide file tree
Showing 80 changed files with 234 additions and 185 deletions.
1 change: 1 addition & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
python -m pip install numpy
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
Expand Down
9 changes: 5 additions & 4 deletions causaldmir/datasets/simlulators.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from itertools import product
from typing import List, Optional, Tuple, Union

import networkx as nx
import numpy as np
from sklearn.gaussian_process import GaussianProcessRegressor
from typing import List, Tuple, Union, Optional
import pandas as pd
from itertools import product
from tick.hawkes import SimuHawkes, HawkesKernelExp
from sklearn.gaussian_process import GaussianProcessRegressor
from tick.hawkes import HawkesKernelExp, SimuHawkes

try:
from scipy.special import expit as sigmoid
Expand Down
4 changes: 2 additions & 2 deletions causaldmir/datasets/tests/test_datasets_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import networkx as nx
import numpy as np

from causaldmir.datasets.utils import erdos_renyi, np2nx, generate_lag_transitions
from causaldmir.datasets.utils import erdos_renyi, generate_lag_transitions, np2nx


def test_erdos_renyi():
Expand Down
6 changes: 4 additions & 2 deletions causaldmir/datasets/tests/test_hawkes_simulator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from unittest import TestCase

import numpy as np
import pandas as pd
from ..simlulators import HawkesSimulator
from ..utils import erdos_renyi, generate_lag_transitions

from causaldmir.datasets.simlulators import HawkesSimulator
from causaldmir.datasets.utils import erdos_renyi, generate_lag_transitions


class TestHawkesSimulator(TestCase):
Expand Down
7 changes: 3 additions & 4 deletions causaldmir/datasets/tests/test_iid_simulator.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from unittest import TestCase

import numpy as np

from causaldmir.datasets.simlulators import IIDSimulator
from causaldmir.datasets.utils import erdos_renyi


class TestIIDSimulator:

pass

class TestIIDSimulator(TestCase):
def test_simulate_linear_anm_gauss(self):
n_nodes = 10
n_edges = 20
Expand Down
1 change: 1 addition & 0 deletions causaldmir/datasets/tests/test_time_lag_simulator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from unittest import TestCase

import numpy as np

from causaldmir.datasets.simlulators import TimeLagSimulator
Expand Down
7 changes: 4 additions & 3 deletions causaldmir/datasets/utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import random
from typing import List, Optional, Sequence, Tuple, Union

import networkx as nx
import numpy as np
import pandas as pd
import networkx as nx
import torch
import random
from typing import List, Tuple, Union, Optional, Sequence


def set_random_seed(seed, set_torch_seed=True):
Expand Down
2 changes: 1 addition & 1 deletion causaldmir/discovery/constraint/pc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from causaldmir.utils import data_form_converter_for_class_method
from causaldmir.utils.independence import ConditionalIndependentTest

from .adjacency_search import adjacency_search
from causaldmir.discovery.constraint.adjacency_search import adjacency_search


class PC(object):
Expand Down
3 changes: 2 additions & 1 deletion causaldmir/discovery/constraint/tests/test_pc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from scipy import stats

from causaldmir.discovery.constraint import PC
from causaldmir.graph import DiGraph, Edge, dag2cpdag
from causaldmir.graph import DiGraph, Edge
from causaldmir.graph.dag2cpdag import dag2cpdag
from causaldmir.utils.independence import Dsep, FisherZ
from causaldmir.utils.metrics.graph_evaluation import graph_equal

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import numpy as np
import pandas as pd
import FindCausalCluster
import MakeGraph
import MergeCluster as MC
import numpy as np
import Orientation
import pandas as pd
import UpdataData
import Utils
import Orientation
import MakeGraph



Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import VanishedTest as VT
import numpy as np
import pandas as pd
import itertools
import TetradMethod

import MergeCluster
import numpy as np
import Overlap_Merge
import pandas as pd
import TetradMethod
import VanishedTest as VT

def FindCausalCluster(data, PureCluster, ImpureCluster, alpha=0.01):
'''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#HSIC with pval return

from __future__ import division

import numpy as np
from scipy.stats import gamma

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import GIN2 as GIN #GIN based on mutual information
import numpy as np
import pandas as pd
import GIN2 as GIN #GIN based on mutual information


# identifying causal order by identifying root node recursively.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import networkx as nx
import matplotlib.pyplot as plt
import networkx as nx

def Make_graph(LatentIndex,order = [],ShareCommonChild = []):
clusters = []
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import VanishedTest as VT
import itertools

import numpy as np
import pandas as pd
import itertools
import Utils
import UpdataData
import Utils
import VanishedTest as VT



Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import VanishedTest as VT
import itertools

import numpy as np
import pandas as pd
import itertools
import Utils
import UpdataData
import Utils
import VanishedTest as VT



Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import GIN2 as GIN
import Infer_Causal_Order
import numpy as np
import pandas as pd
import GIN2 as GIN
import Utils
import Infer_Causal_Order

def Orientation_Cluster(Ora_data, LatentIndex, PureClusters, AllCausalCluster):
pass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import numpy as np
import pandas as pd
from itertools import combinations
import itertools
from itertools import combinations

import networkx as nx
import numpy as np
import pandas as pd

'''Merge overlap causal cluster'''
def merge_list(L2):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
# Copyright: (c) YY 2022
# Licence: <your licence>
#-------------------------------------------------------------------------------
import VanishedTest as VT
import itertools

import numpy as np
import pandas as pd
import itertools
import VanishedTest as VT

'''
Function: Check whether a variable set C is a causal cluster
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

from scipy.stats import norm
import scipy
import numpy as np
import pandas as pd
import math
import random

import numpy as np
import pandas as pd
import scipy
from scipy.stats import norm
from sklearn.utils import resample


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import math

from scipy.stats import chi2

#independent test by Fisher'method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#HSIC with pval return

from __future__ import division

import numpy as np
from scipy.stats import gamma

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#API for HSIC test
import sys
sys.path.append("./indTest")
from kerpy.GaussianKernel import GaussianKernel
from HSICTestObject import HSICTestObject
from numpy import shape,savetxt,loadtxt,transpose,shape,reshape,concatenate
from independence_testing.HSICSpectralTestObject import HSICSpectralTestObject
from independence_testing.HSICBlockTestObject import HSICBlockTestObject
import numpy as np
import pandas as pd
from HSICTestObject import HSICTestObject
from independence_testing.HSICBlockTestObject import HSICBlockTestObject
from independence_testing.HSICSpectralTestObject import HSICSpectralTestObject
from kerpy.GaussianKernel import GaussianKernel
from numpy import concatenate, loadtxt, reshape, savetxt, shape, shape, transpose

#method 1:HSIC test and return boolean
#x and y:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from TestObject import TestObject
import time

from HSICTestObject import HSICTestObject
from numpy import mean, sum, zeros, var, sqrt
from numpy import mean, sqrt, sum, var, zeros
from scipy.stats import norm
import time
from TestObject import TestObject

class HSICBlockTestObject(HSICTestObject):
def __init__(self,num_samples, data_generator=None, kernelX=None, kernelY=None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
@author: qinyi
'''
from HSICTestObject import HSICTestObject
import time

from HSICTestObject import HSICTestObject


class HSICPermutationTestObject(HSICTestObject):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
@author: qinyi
'''
from HSICTestObject import HSICTestObject
import numpy as np
import time

import numpy as np
from HSICTestObject import HSICTestObject

class HSICSpectralTestObject(HSICTestObject):

def __init__(self, num_samples, data_generator=None,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from numpy import shape, fill_diagonal, zeros, mean, sqrt,identity,dot,diag
from numpy.random import permutation, randn
from independence_testing.TestObject import TestObject
import numpy as np
import time
from abc import abstractmethod

import numpy as np
from independence_testing.TestObject import TestObject
from kerpy.Kernel import Kernel
import time
from scipy.linalg import sqrtm,inv
from numpy.linalg import eigh,svd
from numpy import diag, dot, fill_diagonal, identity, mean, shape, sqrt, zeros
from numpy.linalg import eigh, svd
from numpy.random import permutation, randn
from scipy.linalg import inv, sqrtm



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
# Copyright: (c) YY 2021
# Licence: <your licence>
#-------------------------------------------------------------------------------
import GIN
import numpy as np
import pandas as pd
import GIN
import SimulationData as SD


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from abc import abstractmethod

from scipy.stats import norm as normaldist


Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import sys
sys.path.append("./indTest")
from kerpy.GaussianKernel import GaussianKernel
from HSICTestObject import HSICTestObject
from numpy import shape,savetxt,loadtxt,transpose,shape,reshape,concatenate
from independence_testing.HSICSpectralTestObject import HSICSpectralTestObject
from independence_testing.HSICBlockTestObject import HSICBlockTestObject
import numpy as np
import pandas as pd
from HSICTestObject import HSICTestObject
from independence_testing.HSICBlockTestObject import HSICBlockTestObject
from independence_testing.HSICSpectralTestObject import HSICSpectralTestObject
from kerpy.GaussianKernel import GaussianKernel
from numpy import concatenate, loadtxt, reshape, savetxt, shape, shape, transpose


def test(x,y,alph=0.05):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mutual as MI
import numpy as np
import pandas as pd
import mutual as MI
from sklearn import metrics

#estimating mutual information by sklearn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mutual as MI
import numpy as np
import pandas as pd
import mutual as MI
from sklearn import metrics

#estimating mutual information by sklearn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
These computations rely on nearest-neighbor statistics
'''
import numpy as np

from scipy.special import gamma,psi
from numpy import pi
from scipy import ndimage
from scipy.linalg import det
from numpy import pi

from scipy.special import gamma, psi

from sklearn.neighbors import NearestNeighbors

Expand Down
Loading

0 comments on commit 9ad2c8e

Please sign in to comment.