Skip to content

Commit

Permalink
Merge pull request #132 from cdt15/revert-128-master
Browse files Browse the repository at this point in the history
Revert "Accelerate DirectLiNGAM by parallelising causal ordering on GPUs with CUDA"
  • Loading branch information
ikeuchi-screen authored Mar 10, 2024
2 parents 77fef10 + 114c71a commit 3d5eb71
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 99 deletions.
59 changes: 0 additions & 59 deletions examples/DirectLiNGAM_fast.py

This file was deleted.

28 changes: 1 addition & 27 deletions lingam/direct_lingam.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from sklearn.utils import check_array

from .base import _BaseLiNGAM
from lingam_cuda import causal_order as causal_order_gpu


class DirectLiNGAM(_BaseLiNGAM):
Expand Down Expand Up @@ -46,7 +45,7 @@ def __init__(
* ``-1`` : No prior knowledge is available to know if either of the two cases above (0 or 1) is true.
apply_prior_knowledge_softly : boolean, optional (default=False)
If True, apply prior knowledge softly.
measure : {'pwling', 'kernel', 'pwling_fast'}, optional (default='pwling')
measure : {'pwling', 'kernel'}, optional (default='pwling')
Measure to evaluate independence: 'pwling' [2]_ or 'kernel' [1]_.
"""
super().__init__(random_state)
Expand Down Expand Up @@ -97,8 +96,6 @@ def fit(self, X):
for _ in range(n_features):
if self._measure == "kernel":
m = self._search_causal_order_kernel(X_, U)
elif self._measure == "pwling_fast":
m = self._search_causal_order_gpu(X_.astype(np.float64), U.astype(np.int32))
else:
m = self._search_causal_order(X_, U)
for i in U:
Expand Down Expand Up @@ -236,29 +233,6 @@ def _search_causal_order(self, X, U):
M_list.append(-1.0 * M)
return Uc[np.argmax(M_list)]

def _search_causal_order_gpu(self, X, U):
"""Accelerated Causal ordering.
Parameters
----------
X : array-like, shape (n_samples, n_features)
Training data, where ``n_samples`` is the number of samples
and ``n_features`` is the number of features.
U: indices of cols in X
Returns
-------
self : object
Returns the instance itself.
mlist: causal ordering
"""
cols = len(U)
rows = len(X)

arr = X[:, np.array(U)]
mlist = causal_order_gpu(arr, rows, cols)
return U[np.argmax(mlist)]

def _mutual_information(self, x1, x2, param):
"""Calculate the mutual informations."""
kappa, sigma = param
Expand Down
11 changes: 0 additions & 11 deletions lingam/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import numpy as np
import pandas as pd
import semopy
import subprocess

from matplotlib import colors as mcolors
from matplotlib.colors import is_color_like
from sklearn import linear_model
Expand Down Expand Up @@ -1130,12 +1128,3 @@ def calculate_total_effect(adjacency_matrix, from_index, to_index, is_continuous
total_effect = sum(effects)

return total_effect

def get_cuda_version():
try:
nvcc_version = subprocess.check_output(["nvcc", "--version"]).decode('utf-8')
print("CUDA Version found:\n", nvcc_version)
return True
except Exception as e:
print("CUDA not found or nvcc not in PATH:", e)
return False
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ pygam
matplotlib
psy
semopy
#optional (install if gpu and cuda is available)
# culingam==0.0.7

0 comments on commit 3d5eb71

Please sign in to comment.