py-why / causal-learn

Causal Discovery in Python. It also includes (conditional) independence tests and score functions.
https://causal-learn.readthedocs.io/en/latest/
MIT License
1.13k stars 186 forks source link

how to interpret the output of the ganger_lasso #143

Open cunjunyu opened 11 months ago

cunjunyu commented 11 months ago

Hi, thanks for the great work.

I am currently experimenting with the granger_lasso algorithm provided in the repository.

Given that one time series has N dimensions, and the time lag is equal to T. The shape of the output of granger_lasso is [N, N * T].

May I know how I should interpret this and convert it into a [T, N, N] matrix where, along the time lag dimension, the matrix [N, N] represents the influence of the i-th node on the j-th node.

Thank you!

kunwuz commented 11 months ago

Hi, maybe something as follows could be helpful:

reshaped_coeff = np.zeros((T, N, N))
for t in range(T):
    block = coeff[:, N*t:N*(t+1)]
    reshaped_coeff[t] = block
cunjunyu commented 11 months ago

Thank you for the prompt reply.

I have one more thing to clarify. In the implementation, it says:

The ij-th entry in A_k represents the causal influence from the j-th variable to the i-th variable.

Should I expect the same for the reshaped matrix?

Thank you!

mingming-gong commented 9 months ago

it should be guaranteed if you use the code provided by kunwz. You can also check whether the t-th NxN matrix is the same as coeff[:, Nt:N(t+1)].