huawei-noah / trustworthyai Goto Github PK
View Code? Open in Web Editor NEWTrustworthy AI related projects
License: Apache License 2.0
Trustworthy AI related projects
License: Apache License 2.0
Hello! I have read all of your code and the great paper published in ICLR2020.
I have some questions about the code:
1 . in train step1, why the loss1 of the actor has to be:
self.loss1 = tf.reduce_mean(self.reward_baseline * self.log_softmax, 0) - 1 * self.lr1 *
tf.reduce_mean(self.entropy_regularization, 0)
i didn't find any formula or explanation in the paper.
2. What does reward base line in this code use for?
I would be appreciated if you can answer these questions.
I have a .CSV file of a dataset with ground truth being available. I want to see how these algorithms in the gCastle package perform on my dataset. My query is in the codes, where and how should I make changes so that the algorithms can read data from my own .CSV file.
Hi,
I think it would be great to add GES algorithm implementation to gcastle
. It would make broad comparisons between algorithms easier.
There is an existing Python implementation of GES by Juan Gamella: https://github.com/juangamella/ges
Maybe it could be integrated into gcastle
. What are your thoughts?
If you think it's a good idea, I am happy to help with the integration.
BTW., I'll be speaking about gcastle
in my upcoming conference talk next week: https://ghostday.pl/#agenda
Hi, thank you so much for this amazing work.
I don't understand how to combine RL algorithm and Causal discovert algorithm., and how to use the BIC score.
Could you please help me with it.
Thank you so much!
Hi. When I use the GUI web for the task of data generation. I found that the edges in the graph are not equal to those in the configuration parameters. When I change the seed while keeping the n_nodes and n_edges identical, the edges in the graph may also be changed. So What's the effect of seed? Thanks.
请问如果是处理非线性问题应该如何修改代码,只修改reg_type为“GPR”似乎在variable selection时有个pruning_cam方法没有定义,请问该如何解决,谢谢!
你好,感谢你们做出这个强大和好用的因果发现library。
通过CastleBoard,我已经成功生成了因果图。但在评价时,不知道该提供什么样的True Causal Graph文件,可以提供个例子吗?谢谢
(如果我遗漏了什么,十分抱歉。)
can I loader the fin-data? just the csv of (open low high close volume).
if not, how can I deal with it?
Hi - Do the algorithms in this repository work with discrete-valued variables, e.g., categorical variables? Thanks.
Based on the output and comments of the example in the screenshot above (See priori_knowledge.py #line 45 and priori_knowledge.py #line 69), you may want to add Directed Edge '0-->1' and '1-->2' after this code:
>>>p.add_required_edges([(0, 1), (1, 2)]
which can be expressed as adjacency matrix:
p.matrix[0][1] = 1;
p.matrix[1][0] = 0;
p.matrix[1][2] = 1;
p.matrix[2][1] = 0 ;
The function has only 2 lines:
However, it seems that you've forgotten set the 0, but only the 1, so actually, the output is:
p.matrix[0][1] = 1;
p.matrix[1][0] = -1;
p.matrix[1][2] = 1;
p.matrix[2][1] = -1 ;
I am not sure if I have misunderstood but this error can lead to serious problems, providing incorrect priori knowledge when orienting.
而是在CITest里面重复计算每组数据相关快系数
您好!感谢您在ICLR2020发表的论文中提出的方法。
我有四个问题想请问一下,在节点数一定的情况下。
Hi there,
Thanks for your great work for causal structure learning. I'm currently reading your paper (A Graph Autoencoder Approach to Causal Structure Learning) and have a little bit confusion so far.
For part 4.2 Vector-Valued Case, I don't quite understand how the comparison made with the NOTEARS code? I mean, the NOTEARS only designed for handling the Scalar-Valued variable. But in this part, the variable dimension are set to 5, but the NOTEARS code as far as I check, it can't set the variable dimension. Am I missing something?
Thanks for any reply!
Hello! Thank you for the the implementation of the method proposed in paper published in ICLR2020.
I have some questions when reproducing the experimental results.
Our commands is the same as the 'exp3' in README.md . And the data we used comes from 'https://github.com/kurowasan/GraN-DAG/blob/master/data/data_p10_e40_n1000_GP.zip', which should be the same as yours. But the performance is less than the results presented in the paper.
I'd appreciate it if you could tell me where the problem is.Thanks~
# Our command:
python main.py --max_length 10 --data_size 1000 --score_type BIC --reg_type GPR --read_data --normalize --data_path ./data/data_p10_e40_n1000_GP_seed1 --lambda_flag_default --nb_epoch 20000 --input_dimension 128 --lambda_iter_num 1000
# training log:
2020-09-22 02:54:35,182 INFO - __main__ - [iter 18000] reward_batch: -4.175537586212158, max_reward: -3.6388002559621855, max_reward_batch: -3.7585916127016294
2020-09-22 02:56:12,809 INFO - __main__ - [iter 18500] reward_batch: -4.152896881103516, max_reward: -3.6388002559621855, max_reward_batch: -3.823972058605565
2020-09-22 02:58:37,596 INFO - __main__ - [iter 19000] lambda1 3.6388002559621855, upper 3.6388002559621855, lambda2 0.01, upper 0.01, score_min 3.6388002559621855, cyc_min 0.0
2020-09-22 02:58:40,635 INFO - __main__ - before pruning: fdr 0.7727272727272727, tpr 0.2564102564102564, fpr 5.666666666666667, shd 35, nnz 44
2020-09-22 02:58:40,636 INFO - __main__ - after pruning: fdr 0.84375, tpr 0.1282051282051282, fpr 4.5, shd 37, nnz 32
2020-09-22 02:58:40,806 INFO - __main__ - [iter 19000] reward_batch: -4.204100608825684, max_reward: -3.6388002559621855, max_reward_batch: -3.7716216965236127
2020-09-22 03:00:17,209 INFO - __main__ - [iter 19500] reward_batch: -4.158496856689453, max_reward: -3.6388002559621855, max_reward_batch: -3.8702693792409377
2020-09-22 03:02:40,728 INFO - __main__ - [iter 20000] lambda1 3.6388002559621855, upper 3.6388002559621855, lambda2 0.01, upper 0.01, score_min 3.6388002559621855, cyc_min 0.0
2020-09-22 03:02:43,523 INFO - __main__ - before pruning: fdr 0.7727272727272727, tpr 0.2564102564102564, fpr 5.666666666666667, shd 35, nnz 44
2020-09-22 03:02:43,523 INFO - __main__ - after pruning: fdr 0.84375, tpr 0.1282051282051282, fpr 4.5, shd 37, nnz 32
2020-09-22 03:02:43,733 INFO - __main__ - [iter 20000] reward_batch: -4.166861534118652, max_reward: -3.6388002559621855, max_reward_batch: -3.723014876623765
2020-09-22 03:02:45,956 INFO - __main__ - Model saved in file: output/2020-09-22_00-52-32-724/model/tmp.ckpt-20000
2020-09-22 03:02:45,957 INFO - __main__ - Training COMPLETED !
When learning causal structure, can I set a parameter to specify which causal edges exist or do not exist?
在论文中看到说还提供了web可视化的功能,叫castleboard,例子中没有说明怎么使用
Hi,
Thank you for releasing the three datasets from your Causal Discovery competition in 2021. I was just wondering if there were more details on these datasets? Or more specifically, are these sub-sampled data from the full datasets described in the papers arXiv:2105.10884 and arXiv:2105.03092?
Many thanks
Hello, how did CausalVAE intervention operation? In the published source code, intervention is to forcibly assign a concept to a fixed integer by using "mask_z", as follows:
z_mask = torch.ones(q_m.size()[0], self.z1_dim, self.z2_dim).to(device) * adj
decode_m[:, mask, :] = z_mask[:, mask, :]
decode_v[:, mask, :] = z_mask[:, mask, :]
In the test result, the result is very poor. Where did I make a mistake?
The original input image is this
Output image with intervention of 1 for the 0th concept
Should I modify the published code to achieve the effect in the paper?
Hi I already installed gcastle with pip install gcastle==1.0.3rc2.
But when I try to run the demo program like anm_demo.py.
There still an error said
from castle.common import GraphDAG ModuleNotFoundError: No module named 'castle'
Anyone know why there is a ModuleNotFoundError even I have installed the package already?
On the synthetic dataset, there is no error in the execution result. On the sachs dataset, the code error is as follows:
Traceback (most recent call last):
File "main.py", line 314, in
main()
File "main.py", line 284, in main
graph_batch_pruned = np.transpose(pruning_cam(training_set.inputdata, np.array(graph_batch).T))
File "D:\code\trustworthyAI-master\Causal_Structure_Learning\Causal_Discovery_RL\src\helpers\cam_with_pruning_cam.py", line 129, in pruning_cam
X2 = numpy2ri.py2rpy(XX)
AttributeError: module 'rpy2.robjects.numpy2ri' has no attribute 'py2rpy'
Please help me how to solve this problem?
Hello,
I am trying to use Causal Disocvery RL on bnlearn benchmarks. I encounter the error in convert_graph_int_to_adj_mat function.
The input to this function is
[-1903318164 235405414 101482606 495790951 201853294 378349935
-1634426101 -1718146065 134742090 64 134742086 134742084
446475107 470616428 -1785775892 -1768316434 201884524 134217728
201949548 -1903613075 470286702 101187694 -1734505621 503843118
-2070074547 134217838 513518542 503875886 235405386 445754223
0 524358 236432367 134742086 134217792 134217792
503908622]
And the error message follows:
Traceback (most recent call last):
File "main.py", line 337, in <module>
main()
File "main.py", line 285, in main
graph_batch = convert_graph_int_to_adj_mat(graph_int)
File "/home/user/Causal_Discovery_RL/src/helpers/analyze_utils.py", line 156, in convert_graph_int_to_adj_mat
for curr_int in graph_int], dtype=int)
File "/home/user/Causal_Discovery_RL/src/helpers/analyze_utils.py", line 156, in <listcomp>
for curr_int in graph_int], dtype=int)
ValueError: invalid literal for int() with base 10: '-'
请问CORL1和CORL2是什么算法,跟RL算法什么关系,在哪里可以看到详细介绍?
Hello,
I am trying to use Causal Disocvery RL on bnlearn benchmarks. It throws the following errors on some datasets (e.g., hailfinder, water) after some iterations.
Traceback (most recent call last):
File "main.py", line 344, in <module>
main()
File "main.py", line 180, in main
reward_feed = callreward.cal_rewards(graphs_feed, lambda1, lambda2)
File "/home/v-pingma/Causal_Discovery_RL/src/rewards/Reward_BIC.py", line 45, in cal_rewards
reward_ = self.calculate_reward_single_graph(graphi, lambda1, lambda2)
File "/home/v-pingma/Causal_Discovery_RL/src/rewards/Reward_BIC.py", line 117, in calculate_reward_single_graph
y_err = self.calculate_yerr(X_train, y_train)
File "/home/v-pingma/Causal_Discovery_RL/src/rewards/Reward_BIC.py", line 55, in calculate_yerr
return self.calculate_LR(X_train, y_train)
File "/home/v-pingma/Causal_Discovery_RL/src/rewards/Reward_BIC.py", line 69, in calculate_LR
theta = np.linalg.solve(XtX, Xty)
File "<__array_function__ internals>", line 6, in solve
File "/anaconda/envs/cdrl/lib/python3.6/site-packages/numpy/linalg/linalg.py", line 394, in solve
r = gufunc(a, b, signature=signature, extobj=extobj)
File "/anaconda/envs/cdrl/lib/python3.6/site-packages/numpy/linalg/linalg.py", line 88, in _raise_linalgerror_singular
raise LinAlgError("Singular matrix")
numpy.linalg.LinAlgError: Singular matrix
In the CasualVAE, the MIC and TIC should be a matrix between learned representation z and the label u , how to get a single scalar ?
请教下用gcastle能否产生变量为离散值的因果网络+CPT并在上面sample数据
Hi,
First of all, thanks for the great package! Having all causal discovery algorithms with a unified interface is extremely useful.
I'm trying to use gcastle as part of a larger system that uses the latest version of tensorflow. However, gcastle requires tensorflow 1.15, and is not compatible with later versions. I think this is mainly due to its import statements, which refer to some directories that are not there any more in the newer tensorflow version. For instance, it has "from tensorflow.contrib import distributions". The directory tensorflow.contrib is not there anymore, and now distributions are in the probability directory. Are you aware of any other potential sources of incompatibility? Or is it just the imports?
Also, are you planning on updating the code to make it compatible with newer versions of tensorflow?
Thanks!
I am trying to use GAE following https://github.com/huawei-noah/trustworthyAI/blob/master/gcastle/example/gae/gae_demo.py and am getting the following error
ImportError Traceback (most recent call last)
/tmp/ipykernel_33/894238180.py in
2 from castle.metrics import MetricsDAG
3 from castle.datasets import DAG, IIDSimulation
----> 4 from castle.algorithms import GAE
5
6
ImportError: cannot import name 'GAE' from 'castle.algorithms' (/opt/conda/lib/python3.7/site-packages/castle/algorithms/init.py)
gcastle is suggested to be installed using tensorflow>=1.15.0, which computing speed is very low, and the package cannot install with GPU version TensorFlow. When I install the gcastle using pip, it always installs a CPU version TensorFlow automatically. How can I fix it?
Hi,
First of all, thank you for all your work on this package, collecting together the distributed (and sometimes un-implemented) research on causal inference is infinitely helpful and useful.
I was just wondering if you had any rough ETA on the implementation of the HPC algorithm within your toolbox? The results of this paper look extremely promising and I would like to test them further.
Many thanks
In CausalVAE code
Is there any special reason why using 4 different decoders?
Besides, for pendulum
and flow
datasets, the latent space dimension should be equal to the dimension of the label, which is 4. Why the latent space dimension in code is set to be 16?
I checked the Appendix of the paper: we extend the multivariate Gaussian to the matrix Gaussian. Why the model is designed in this way and what are the advantages if we set the VAE in this way?
Many thanks for your response
Just like the example of PC algorithm,PC demo.py
I hope you can provide interfaces to allow more algorithms to adopt a priori knowledge.
Please consider adding this reference to the gcastle readme:
https://arxiv.org/abs/2111.15155
gCastle: A Python Toolbox for Causal Discovery
Hello, I'm linking from the page of paper -《Federated Causal Discovery》 on the website of #paper with code#. Is the code of FCL in this library, I can't find it ......
Would it make sense to have gCastle in its own repo? Just wondering.
I'm interested in the dataset from real telecommunication networks.
I have some questions, of which I failed to find the answers in neither this repo nor the dataset repo.
I notice that the result part is still empty after more than a year since the last edition.
The listed two paper, in NIPS 2019 and ICLR 2020, did not use this dataset for evaluation.
Hi, I notice some kernel-based conditional independence test methods, e.g., hsci, is implemeneted in the CITest folder.
However, for Parallel-PC algorithm, only fisherz, chi2, g2 tests are avariable.
Is it possible to modify the code and use these kernel-based tests instead?
When experimenting with the real dataset Sachs, the real dataset has been downloaded from the website, should I get the DAG.npy and data.npy of the real dataset?
Hi,
Thanks for great implementation. I have problem to with rpy2 packets. I got the error when running the code:
rpy2.rinterface_lib.embedded.RRuntimeError: Error in loadNamespace(name) : there is no package called 'CAM'
Do you have the same problem? I used rpy2 version 3.2.7 in ubuntu 16.0
算法默认使用cpu训练,当我想要使用GPU训练的时候,会提示:
File "/home/DQN/cdt/test_common_dataset.py", line 22, in
rl.learn(alarm_data)
File "/root/miniconda3/envs/cdt/lib/python3.8/site-packages/castle/algorithms/gradient/rl/torch/rl.py", line 260, in learn
causal_matrix = self._rl(X, config)
File "/root/miniconda3/envs/cdt/lib/python3.8/site-packages/castle/algorithms/gradient/rl/torch/rl.py", line 355, in rl
actor.build_reward(reward = -torch.from_numpy(reward_feed)[:,0].cuda(config.device_ids))
File "/root/miniconda3/envs/cdt/lib/python3.8/site-packages/castle/algorithms/gradient/rl/torch/models/actor_graph.py", line 132, in build_reward
self.build_optim()
File "/root/miniconda3/envs/cdt/lib/python3.8/site-packages/castle/algorithms/gradient/rl/torch/models/actor_graph.py", line 139, in build_optim
self.avg_baseline = self.alpha * self.avg_baseline + (1.0 - self.alpha) * reward_mean
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
看了一下源码,是因为rl.learn(data),data只接受nd.array和自己定义的Tensor,都不支持转移到GPU上,这个问题有什么办法处理吗
Hi,
I'm wondering what's the meaning of mu[i] * self._T
in the first part of likelihood. It's not consistent with the paper, which should be lambda*delta t
Hi, I want to know the data requirement for causal discovery in the web GUI. The following data1 & data3 are my local dataset's data format. Data2 is the data format generated by the data generation task.
I can successfully use causal discovery when I choose data1 from the external training dataset and data2 from the built-in training dataset.
When I choose data3 from the external training dataset, it always prompts "校验结果为false" in the web GUI, and the terminal shows "POST /task/check_dataset HTTP/1.1" 200 -". When I download the file of data2 to to my local, then choose data2 from the external training dataset, the WEB GUI and terminal show the same fail text.
data1:[0 1 0 0 0 0 0 1 0 0 0 0 0 -1]
data2:[-0.516906642 0.498168803 -0.228214563 0.752834357 0.592922701]
data3:[0.363636364 0 0.090909091 0 0 0 0.090909091 0 0.090909091 0.363636364 0 0 0 -3]
我理解关于权值矩阵初始化,应该是先做均匀分布随机,再将对角线归零,最后将得到的参数作为权值矩阵的初始化参数。因此我把60-62行代码:
W = tf.Variable(tf.random.uniform([self.d, self.d], minval=-0.1, maxval=0.1,
dtype=self.tf_float_type, seed=self.seed))
self.W_prime = self._preprocess_graph(W)
改为:
W = np.random.uniform(-0.1, 0.1, size=(self.d, self.d)) * (1 - np.eye(self.d))
self.W_prime = tf.Variable(W)
但是得到的结果就很差,在第一轮iteration阶段,估计的图基本收敛在对角线处(见下图),而且最后得到的效果也很差,基本和NOTEARS和DAG-GNN类似甚至不如,请问这是什么原因呢?
附:这是原始代码在第一轮估计的图
希望能给我解答一下困惑,谢谢~
Hi,
thank you for building and sharing such a great package! ❤️
I noticed that when using the RL()
method with GPU (RL(device_type='gpu')
) I am getting a RuntimeError
(traceback attached below).
Other similar methods, like CORL()
work with GPU without any issues.
I am using gcastle
version 1.0.3rc2 on Win 11 with NVIDIA GeForce GTX 1650 and torch
backend.
What I understand from the traceback is that some tensors are not being sent to GPU and hence the error.
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_32844/3516016318.py in <module>
3 )
4
----> 5 rl.learn(X)
~\anaconda3\envs\econml-dowhy-py38\lib\site-packages\castle\algorithms\gradient\rl\torch\rl.py in learn(self, data, columns, dag, **kwargs)
258 config.max_length = X.shape[1]
259
--> 260 causal_matrix = self._rl(X, config)
261 self.causal_matrix = causal_matrix
262
~\anaconda3\envs\econml-dowhy-py38\lib\site-packages\castle\algorithms\gradient\rl\torch\rl.py in _rl(self, X, config)
353 if config.device_type == 'gpu':
354 reward_feed = callreward.cal_rewards(graphs_feed.cpu().detach().numpy(), lambda1, lambda2) # np.array
--> 355 actor.build_reward(reward_ = -torch.from_numpy(reward_feed)[:,0].cuda(config.device_ids))
356 else:
357 reward_feed = callreward.cal_rewards(graphs_feed.detach().numpy(), lambda1, lambda2) # np.array
~\anaconda3\envs\econml-dowhy-py38\lib\site-packages\castle\algorithms\gradient\rl\torch\models\actor_graph.py in build_reward(self, reward_)
130 self.reward = reward_
131
--> 132 self.build_optim()
133
134 def build_optim(self):
~\anaconda3\envs\econml-dowhy-py38\lib\site-packages\castle\algorithms\gradient\rl\torch\models\actor_graph.py in build_optim(self)
137 reward_mean, reward_var = torch.mean(self.reward), torch.std(self.reward)
138 self.reward_batch = reward_mean
--> 139 self.avg_baseline = self.alpha * self.avg_baseline + (1.0 - self.alpha) * reward_mean
140 if self.config.device_type == 'gpu':
141 self.avg_baseline = self.avg_baseline.cuda(self.config.device_ids)
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu!
Hi guys,
I can't run notears in a container based on the Dockerfile for gcastle.
Felix
Dear huawei team,
I have recognized that several implementations of the PC algorithm allow providing "arcs" which are allowed/known (=whitelist) or not allowed (=blacklist), e.g. https://www.bnlearn.com/documentation/man/constraint.html.
This also accelerate the computation.
Maybe, you can also add these your PC algorithms :)
Best regards,
Marvin
Branch: Causal_Disentangled_Representation_Learning
train on flow data: python ./run_pendulum.py
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.