-
Notifications
You must be signed in to change notification settings - Fork 199
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
Example #7
Comments
Hi, |
Awesome, that sorted the first one out! On the next tab, I have this issue. Thanks for taking the time.
The pairwise GNN model is computed on each edge of the UMG to initialize the model and start CGNN with a DAGTypeError Traceback (most recent call last) ~/anaconda/envs/py36/lib/python3.6/site-packages/cdt/causality/graph/model.py in predict(self, df_data, graph, **kwargs) ~/anaconda/envs/py36/lib/python3.6/site-packages/cdt/causality/graph/CGNN.py in orient_undirected_graph(self, data, umg, nh, nb_runs, nb_jobs, gpu, lr, train_epochs, test_epochs, verbose, nb_max_runs) ~/anaconda/envs/py36/lib/python3.6/site-packages/cdt/causality/pairwise/model.py in orient_graph(self, df_data, graph, printout, nb_runs, **kwargs) TypeError: 'method' object is not iterable |
Oh yes, I had this bug corrected, could you update your toolbox to master? |
Sorry I got one problem after the update. - Running the same code. The pairwise GNN model is computed on each edge of the UMG to initialize the model and start CGNN with a DAGAttributeError Traceback (most recent call last) /Volumes/extra/FirmAI/Causal Inference/CausalDiscoveryToolbox-master/examples/cdt/causality/graph/model.py in predict(self, df_data, graph, **kwargs) /Volumes/extra/FirmAI/Causal Inference/CausalDiscoveryToolbox-master/examples/cdt/causality/graph/CGNN.py in orient_undirected_graph(self, data, umg, nh, nb_runs, nb_jobs, gpu, lr, train_epochs, test_epochs, verbose, nb_max_runs) /Volumes/extra/FirmAI/Causal Inference/CausalDiscoveryToolbox-master/examples/cdt/utils/graph_utils.py in dagify_min_edge(g) AttributeError: 'generator' object has no attribute 'next' |
It might be a python 3 thing, I will jsut change it locally. Thank, one last question - more personal - would you recommend any packages for automated causal effects from observational data after I have done the casual discovery? I have had a look at the following, https://github.com/laurencium/Causalinference, and https://github.com/akelleh/causality. If you are unsure then please just ignore the question, thanks so much for your help :) |
Hi again, glad that some errors are sorted out. Please keep me updated about the generator error. We plan to bring tools for causal effect evaluation in this toolbox, but it will be at a later date =) |
I'll be closing this issue, don't hesitate to open it if a bug pops again. |
Hey man in trying your example, I have run into an error. I am not sure what to make of it, as it might be device related. I will include the message here and the file link.
https://github.com/snowde/firmai.github.io/blob/master/Discovery_LUCAS.ipynb
`---------------------------------------------------------------------------
RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
"""
Traceback (most recent call last):
File "/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/joblib/_parallel_backends.py", line 350, in call
return self.func(*args, **kwargs)
File "/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/joblib/parallel.py", line 131, in call
return [func(*args, **kwargs) for func, args, kwargs in self.items]
File "/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/joblib/parallel.py", line 131, in
return [func(*args, **kwargs) for func, args, kwargs in self.items]
File "/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/cdt/independence/graph/model.py", line 43, in run_feature_selection
return self.predict_features(df_features, df_target, **kwargs)
File "/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/cdt/independence/graph/FSGNN.py", line 79, in predict_features
x = th.FloatTensor(scale(df_features.as_matrix())).to(device)
AttributeError: 'torch.FloatTensor' object has no attribute 'to'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/dereksnow/anaconda/envs/py36/lib/python3.6/multiprocessing/pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/joblib/_parallel_backends.py", line 359, in call
raise TransportableException(text, e_type)
joblib.my_exceptions.TransportableException: TransportableException
AttributeError Sat Jun 30 16:19:48 2018
PID: 92373 Python 3.6.3: /Users/dereksnow/anaconda/envs/py36/bin/python
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/joblib/parallel.py in call(self=<joblib.parallel.BatchedCalls object>)
126 def init(self, iterator_slice):
127 self.items = list(iterator_slice)
128 self.size = len(self.items)
129
130 def call(self):
--> 131 return [func(*args, **kwargs) for func, args, kwargs in self.items]
self.items = [(<bound method FeatureSelectionModel.run_feature...n of <cdt.independence.graph.FSGNN.FSGNN object>>, ( Allergy Anxiety Genetics Peer_Pressure...0.858699 -1.037579
[500 rows x 11 columns], 'Allergy', 0), {'l1': 0.01, 'test_epochs': 1000, 'train_epochs': 2000})]
132
133 def len(self):
134 return self._size
135
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/joblib/parallel.py in (.0=<list_iterator object>)
126 def init(self, iterator_slice):
127 self.items = list(iterator_slice)
128 self.size = len(self.items)
129
130 def call(self):
--> 131 return [func(*args, **kwargs) for func, args, kwargs in self.items]
func = <bound method FeatureSelectionModel.run_feature...n of <cdt.independence.graph.FSGNN.FSGNN object>>
args = ( Allergy Anxiety Genetics Peer_Pressure...0.858699 -1.037579
[500 rows x 11 columns], 'Allergy', 0)
kwargs = {'l1': 0.01, 'test_epochs': 1000, 'train_epochs': 2000}
132
133 def len(self):
134 return self._size
135
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/cdt/independence/graph/model.py in run_feature_selection(self=<cdt.independence.graph.FSGNN.FSGNN object>, df_data= Allergy Anxiety Genetics Peer_Pressure...0.858699 -1.037579
[500 rows x 11 columns], target='Allergy', idx=0, **kwargs={'l1': 0.01, 'test_epochs': 1000, 'train_epochs': 2000})
38 list_features = list(df_data.columns.values)
39 list_features.remove(target)
40 df_target = pd.DataFrame(df_data[target], columns=[target])
41 df_features = df_data[list_features]
42
---> 43 return self.predict_features(df_features, df_target, **kwargs)
self.predict_features = <bound method FSGNN.predict_features of <cdt.independence.graph.FSGNN.FSGNN object>>
df_features = Anxiety Genetics Peer_Pressure Attentio...0.858699 -1.037579
[500 rows x 10 columns]
df_target = Allergy
0 -0.266076
1 -0.579084
2 -0...8 -0.064685
499 -0.638704
[500 rows x 1 columns]
kwargs = {'l1': 0.01, 'test_epochs': 1000, 'train_epochs': 2000}
44
45 def predict(self, df_data, threshold=0.05, **kwargs):
46 """Get the skeleton of the graph from raw data.
47
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/cdt/independence/graph/FSGNN.py in predict_features(self=<cdt.independence.graph.FSGNN.FSGNN object>, df_features= Anxiety Genetics Peer_Pressure Attentio...0.858699 -1.037579
[500 rows x 10 columns], df_target= Allergy
0 -0.266076
1 -0.579084
2 -0...8 -0.064685
499 -0.638704
[500 rows x 1 columns], nh=20, idx=0, dropout=0.0, activation_function=<class 'torch.nn.modules.activation.ReLU'>, lr=0.01, l1=0.01, train_epochs=2000, test_epochs=1000, device='cpu', verbose=False, nb_runs=3)
74 activation_function=th.nn.ReLU, lr=0.01, l1=0.1, # batch_size=-1,
75 train_epochs=1000, test_epochs=1000, device=None,
76 verbose=None, nb_runs=3):
77 """For one variable, predict its neighbours."""
78 device, verbose = SETTINGS.get_default(('device', device), ('verbose', verbose))
---> 79 x = th.FloatTensor(scale(df_features.as_matrix())).to(device)
x = undefined
df_features.as_matrix.to = undefined
device = 'cpu'
80 y = th.FloatTensor(scale(df_target.as_matrix())).to(device)
81 out = []
82 for i in range(nb_runs):
83 model = FSGNN_model([x.size()[1], nh, 1],
AttributeError: 'torch.FloatTensor' object has no attribute 'to'
"""
The above exception was the direct cause of the following exception:
TransportableException Traceback (most recent call last)
~/anaconda/envs/py36/lib/python3.6/site-packages/joblib/parallel.py in retrieve(self)
698 if getattr(self._backend, 'supports_timeout', False):
--> 699 self._output.extend(job.get(timeout=self.timeout))
700 else:
~/anaconda/envs/py36/lib/python3.6/multiprocessing/pool.py in get(self, timeout)
643 else:
--> 644 raise self._value
645
TransportableException: TransportableException
AttributeError Sat Jun 30 16:19:48 2018
PID: 92373 Python 3.6.3: /Users/dereksnow/anaconda/envs/py36/bin/python
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/joblib/parallel.py in call(self=<joblib.parallel.BatchedCalls object>)
126 def init(self, iterator_slice):
127 self.items = list(iterator_slice)
128 self.size = len(self.items)
129
130 def call(self):
--> 131 return [func(*args, **kwargs) for func, args, kwargs in self.items]
self.items = [(<bound method FeatureSelectionModel.run_feature...n of <cdt.independence.graph.FSGNN.FSGNN object>>, ( Allergy Anxiety Genetics Peer_Pressure...0.858699 -1.037579
[500 rows x 11 columns], 'Allergy', 0), {'l1': 0.01, 'test_epochs': 1000, 'train_epochs': 2000})]
132
133 def len(self):
134 return self._size
135
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/joblib/parallel.py in (.0=<list_iterator object>)
126 def init(self, iterator_slice):
127 self.items = list(iterator_slice)
128 self.size = len(self.items)
129
130 def call(self):
--> 131 return [func(*args, **kwargs) for func, args, kwargs in self.items]
func = <bound method FeatureSelectionModel.run_feature...n of <cdt.independence.graph.FSGNN.FSGNN object>>
args = ( Allergy Anxiety Genetics Peer_Pressure...0.858699 -1.037579
[500 rows x 11 columns], 'Allergy', 0)
kwargs = {'l1': 0.01, 'test_epochs': 1000, 'train_epochs': 2000}
132
133 def len(self):
134 return self._size
135
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/cdt/independence/graph/model.py in run_feature_selection(self=<cdt.independence.graph.FSGNN.FSGNN object>, df_data= Allergy Anxiety Genetics Peer_Pressure...0.858699 -1.037579
[500 rows x 11 columns], target='Allergy', idx=0, **kwargs={'l1': 0.01, 'test_epochs': 1000, 'train_epochs': 2000})
38 list_features = list(df_data.columns.values)
39 list_features.remove(target)
40 df_target = pd.DataFrame(df_data[target], columns=[target])
41 df_features = df_data[list_features]
42
---> 43 return self.predict_features(df_features, df_target, **kwargs)
self.predict_features = <bound method FSGNN.predict_features of <cdt.independence.graph.FSGNN.FSGNN object>>
df_features = Anxiety Genetics Peer_Pressure Attentio...0.858699 -1.037579
[500 rows x 10 columns]
df_target = Allergy
0 -0.266076
1 -0.579084
2 -0...8 -0.064685
499 -0.638704
[500 rows x 1 columns]
kwargs = {'l1': 0.01, 'test_epochs': 1000, 'train_epochs': 2000}
44
45 def predict(self, df_data, threshold=0.05, **kwargs):
46 """Get the skeleton of the graph from raw data.
47
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/cdt/independence/graph/FSGNN.py in predict_features(self=<cdt.independence.graph.FSGNN.FSGNN object>, df_features= Anxiety Genetics Peer_Pressure Attentio...0.858699 -1.037579
[500 rows x 10 columns], df_target= Allergy
0 -0.266076
1 -0.579084
2 -0...8 -0.064685
499 -0.638704
[500 rows x 1 columns], nh=20, idx=0, dropout=0.0, activation_function=<class 'torch.nn.modules.activation.ReLU'>, lr=0.01, l1=0.01, train_epochs=2000, test_epochs=1000, device='cpu', verbose=False, nb_runs=3)
74 activation_function=th.nn.ReLU, lr=0.01, l1=0.1, # batch_size=-1,
75 train_epochs=1000, test_epochs=1000, device=None,
76 verbose=None, nb_runs=3):
77 """For one variable, predict its neighbours."""
78 device, verbose = SETTINGS.get_default(('device', device), ('verbose', verbose))
---> 79 x = th.FloatTensor(scale(df_features.as_matrix())).to(device)
x = undefined
df_features.as_matrix.to = undefined
device = 'cpu'
80 y = th.FloatTensor(scale(df_target.as_matrix())).to(device)
81 out = []
82 for i in range(nb_runs):
83 model = FSGNN_model([x.size()[1], nh, 1],
AttributeError: 'torch.FloatTensor' object has no attribute 'to'
During handling of the above exception, another exception occurred:
JoblibAttributeError Traceback (most recent call last)
in ()
6
7 start_time = time.time()
----> 8 ugraph = Fsgnn.predict(data, train_epochs=2000, test_epochs=1000, threshold=5e-4, l1=0.01)
9 print("--- Execution time : %4.4s seconds ---" % (time.time() - start_time))
10 nx.draw_networkx(ugraph, font_size=8) # The plot function allows for quick visualization of the graph.
~/anaconda/envs/py36/lib/python3.6/site-packages/cdt/independence/graph/model.py in predict(self, df_data, threshold, **kwargs)
53 result_feature_selection = Parallel(n_jobs=nb_jobs)(delayed(self.run_feature_selection)
54 (df_data, node, idx, **kwargs)
---> 55 for idx, node in enumerate(list_nodes))
56 else:
57 result_feature_selection = [self.run_feature_selection(df_data, node, idx, **kwargs) for idx, node in enumerate(list_nodes)]
~/anaconda/envs/py36/lib/python3.6/site-packages/joblib/parallel.py in call(self, iterable)
787 # consumption.
788 self._iterating = False
--> 789 self.retrieve()
790 # Make sure that we get a last message telling us we are done
791 elapsed_time = time.time() - self._start_time
~/anaconda/envs/py36/lib/python3.6/site-packages/joblib/parallel.py in retrieve(self)
738 exception = exception_type(report)
739
--> 740 raise exception
741
742 def call(self, iterable):
JoblibAttributeError: JoblibAttributeError
Multiprocessing exception:
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/runpy.py in _run_module_as_main(mod_name='ipykernel.main', alter_argv=1)
188 sys.exit(msg)
189 main_globals = sys.modules["main"].dict
190 if alter_argv:
191 sys.argv[0] = mod_spec.origin
192 return _run_code(code, main_globals, None,
--> 193 "main", mod_spec)
mod_spec = ModuleSpec(name='ipykernel.main', loader=<_f...b/python3.6/site-packages/ipykernel/main.py')
194
195 def run_module(mod_name, init_globals=None,
196 run_name=None, alter_sys=False):
197 """Execute a module's code without importing it
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/runpy.py in _run_code(code=<code object at 0x10f262a50, file "/Use...3.6/site-packages/ipykernel/main.py", line 1>, run_globals={'annotations': {}, 'builtins': <module 'builtins' (built-in)>, 'cached': '/Users/dereksnow/anaconda/envs/py36/lib/python3....ges/ipykernel/pycache/main.cpython-36.pyc', 'doc': None, 'file': '/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/ipykernel/main.py', 'loader': <_frozen_importlib_external.SourceFileLoader object>, 'name': 'main', 'package': 'ipykernel', 'spec': ModuleSpec(name='ipykernel.main', loader=<_f...b/python3.6/site-packages/ipykernel/main.py'), 'app': <module 'ipykernel.kernelapp' from '/Users/derek.../python3.6/site-packages/ipykernel/kernelapp.py'>}, init_globals=None, mod_name='main', mod_spec=ModuleSpec(name='ipykernel.main', loader=<_f...b/python3.6/site-packages/ipykernel/main.py'), pkg_name='ipykernel', script_name=None)
80 cached = cached,
81 doc = None,
82 loader = loader,
83 package = pkg_name,
84 spec = mod_spec)
---> 85 exec(code, run_globals)
code = <code object at 0x10f262a50, file "/Use...3.6/site-packages/ipykernel/main.py", line 1>
run_globals = {'annotations': {}, 'builtins': <module 'builtins' (built-in)>, 'cached': '/Users/dereksnow/anaconda/envs/py36/lib/python3....ges/ipykernel/pycache/main.cpython-36.pyc', 'doc': None, 'file': '/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/ipykernel/main.py', 'loader': <_frozen_importlib_external.SourceFileLoader object>, 'name': 'main', 'package': 'ipykernel', 'spec': ModuleSpec(name='ipykernel.main', loader=<_f...b/python3.6/site-packages/ipykernel/main.py'), 'app': <module 'ipykernel.kernelapp' from '/Users/derek.../python3.6/site-packages/ipykernel/kernelapp.py'>}
86 return run_globals
87
88 def _run_module_code(code, init_globals=None,
89 mod_name=None, mod_spec=None,
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/ipykernel/main.py in ()
1 if name == 'main':
2 from ipykernel import kernelapp as app
----> 3 app.launch_new_instance()
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/traitlets/config/application.py in launch_instance(cls=<class 'ipykernel.kernelapp.IPKernelApp'>, argv=None, **kwargs={})
653
654 If a global instance already exists, this reinitializes and starts it
655 """
656 app = cls.instance(**kwargs)
657 app.initialize(argv)
--> 658 app.start()
app.start = <bound method IPKernelApp.start of <ipykernel.kernelapp.IPKernelApp object>>
659
660 #-----------------------------------------------------------------------------
661 # utility functions, for convenience
662 #-----------------------------------------------------------------------------
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/ipykernel/kernelapp.py in start(self=<ipykernel.kernelapp.IPKernelApp object>)
472 return self.subapp.start()
473 if self.poller is not None:
474 self.poller.start()
475 self.kernel.start()
476 try:
--> 477 ioloop.IOLoop.instance().start()
478 except KeyboardInterrupt:
479 pass
480
481 launch_new_instance = IPKernelApp.launch_instance
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/tornado/ioloop.py in start(self=<zmq.eventloop.ioloop.ZMQIOLoop object>)
883 self._events.update(event_pairs)
884 while self._events:
885 fd, events = self._events.popitem()
886 try:
887 fd_obj, handler_func = self._handlers[fd]
--> 888 handler_func(fd_obj, events)
handler_func = <function wrap..null_wrapper>
fd_obj = <zmq.sugar.socket.Socket object>
events = 1
889 except (OSError, IOError) as e:
890 if errno_from_exception(e) == errno.EPIPE:
891 # Happens when the client closes the connection
892 pass
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/tornado/stack_context.py in null_wrapper(*args=(<zmq.sugar.socket.Socket object>, 1), **kwargs={})
272 # Fast path when there are no active contexts.
273 def null_wrapper(*args, **kwargs):
274 try:
275 current_state = _state.contexts
276 _state.contexts = cap_contexts[0]
--> 277 return fn(*args, **kwargs)
args = (<zmq.sugar.socket.Socket object>, 1)
kwargs = {}
278 finally:
279 _state.contexts = current_state
280 null_wrapper._wrapped = True
281 return null_wrapper
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py in _handle_events(self=<zmq.eventloop.zmqstream.ZMQStream object>, fd=<zmq.sugar.socket.Socket object>, events=1)
445 return
446 zmq_events = self.socket.EVENTS
447 try:
448 # dispatch events:
449 if zmq_events & zmq.POLLIN and self.receiving():
--> 450 self._handle_recv()
self._handle_recv = <bound method ZMQStream._handle_recv of <zmq.eventloop.zmqstream.ZMQStream object>>
451 if not self.socket:
452 return
453 if zmq_events & zmq.POLLOUT and self.sending():
454 self._handle_send()
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py in _handle_recv(self=<zmq.eventloop.zmqstream.ZMQStream object>)
475 else:
476 raise
477 else:
478 if self._recv_callback:
479 callback = self._recv_callback
--> 480 self._run_callback(callback, msg)
self._run_callback = <bound method ZMQStream._run_callback of <zmq.eventloop.zmqstream.ZMQStream object>>
callback = <function wrap..null_wrapper>
msg = [<zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>]
481
482
483 def _handle_send(self):
484 """Handle a send event."""
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/zmq/eventloop/zmqstream.py in _run_callback(self=<zmq.eventloop.zmqstream.ZMQStream object>, callback=<function wrap..null_wrapper>, *args=([<zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>],), **kwargs={})
427 close our socket."""
428 try:
429 # Use a NullContext to ensure that all StackContexts are run
430 # inside our blanket exception handler rather than outside.
431 with stack_context.NullContext():
--> 432 callback(*args, **kwargs)
callback = <function wrap..null_wrapper>
args = ([<zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>],)
kwargs = {}
433 except:
434 gen_log.error("Uncaught exception in ZMQStream callback",
435 exc_info=True)
436 # Re-raise the exception so that IOLoop.handle_callback_exception
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/tornado/stack_context.py in null_wrapper(*args=([<zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>],), **kwargs={})
272 # Fast path when there are no active contexts.
273 def null_wrapper(*args, **kwargs):
274 try:
275 current_state = _state.contexts
276 _state.contexts = cap_contexts[0]
--> 277 return fn(*args, **kwargs)
args = ([<zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>],)
kwargs = {}
278 finally:
279 _state.contexts = current_state
280 null_wrapper._wrapped = True
281 return null_wrapper
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/ipykernel/kernelbase.py in dispatcher(msg=[<zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>])
278 if self.control_stream:
279 self.control_stream.on_recv(self.dispatch_control, copy=False)
280
281 def make_dispatcher(stream):
282 def dispatcher(msg):
--> 283 return self.dispatch_shell(stream, msg)
msg = [<zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>, <zmq.sugar.frame.Frame object>]
284 return dispatcher
285
286 for s in self.shell_streams:
287 s.on_recv(make_dispatcher(s), copy=False)
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/ipykernel/kernelbase.py in dispatch_shell(self=<ipykernel.ipkernel.IPythonKernel object>, stream=<zmq.eventloop.zmqstream.ZMQStream object>, msg={'buffers': [], 'content': {'allow_stdin': True, 'code': "# So the question is, if you only have the data ...s\npd.DataFrame(list(ugraph.edges(data='weight')))", 'silent': False, 'stop_on_error': True, 'store_history': True, 'user_expressions': {}}, 'header': {'date': datetime.datetime(2018, 6, 30, 4, 19, 48, 623932, tzinfo=tzutc()), 'msg_id': '3F664F4DF8994E9980115EFD76A70918', 'msg_type': 'execute_request', 'session': '1DCE294733F74AD0BBF17671DE4E5820', 'username': 'username', 'version': '5.2'}, 'metadata': {}, 'msg_id': '3F664F4DF8994E9980115EFD76A70918', 'msg_type': 'execute_request', 'parent_header': {}})
230 self.log.warn("Unknown message type: %r", msg_type)
231 else:
232 self.log.debug("%s: %s", msg_type, msg)
233 self.pre_handler_hook()
234 try:
--> 235 handler(stream, idents, msg)
handler = <bound method Kernel.execute_request of <ipykernel.ipkernel.IPythonKernel object>>
stream = <zmq.eventloop.zmqstream.ZMQStream object>
idents = [b'1DCE294733F74AD0BBF17671DE4E5820']
msg = {'buffers': [], 'content': {'allow_stdin': True, 'code': "# So the question is, if you only have the data ...s\npd.DataFrame(list(ugraph.edges(data='weight')))", 'silent': False, 'stop_on_error': True, 'store_history': True, 'user_expressions': {}}, 'header': {'date': datetime.datetime(2018, 6, 30, 4, 19, 48, 623932, tzinfo=tzutc()), 'msg_id': '3F664F4DF8994E9980115EFD76A70918', 'msg_type': 'execute_request', 'session': '1DCE294733F74AD0BBF17671DE4E5820', 'username': 'username', 'version': '5.2'}, 'metadata': {}, 'msg_id': '3F664F4DF8994E9980115EFD76A70918', 'msg_type': 'execute_request', 'parent_header': {}}
236 except Exception:
237 self.log.error("Exception in message handler:", exc_info=True)
238 finally:
239 self.post_handler_hook()
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/ipykernel/kernelbase.py in execute_request(self=<ipykernel.ipkernel.IPythonKernel object>, stream=<zmq.eventloop.zmqstream.ZMQStream object>, ident=[b'1DCE294733F74AD0BBF17671DE4E5820'], parent={'buffers': [], 'content': {'allow_stdin': True, 'code': "# So the question is, if you only have the data ...s\npd.DataFrame(list(ugraph.edges(data='weight')))", 'silent': False, 'stop_on_error': True, 'store_history': True, 'user_expressions': {}}, 'header': {'date': datetime.datetime(2018, 6, 30, 4, 19, 48, 623932, tzinfo=tzutc()), 'msg_id': '3F664F4DF8994E9980115EFD76A70918', 'msg_type': 'execute_request', 'session': '1DCE294733F74AD0BBF17671DE4E5820', 'username': 'username', 'version': '5.2'}, 'metadata': {}, 'msg_id': '3F664F4DF8994E9980115EFD76A70918', 'msg_type': 'execute_request', 'parent_header': {}})
394 if not silent:
395 self.execution_count += 1
396 self._publish_execute_input(code, parent, self.execution_count)
397
398 reply_content = self.do_execute(code, silent, store_history,
--> 399 user_expressions, allow_stdin)
user_expressions = {}
allow_stdin = True
400
401 # Flush output before sending the reply.
402 sys.stdout.flush()
403 sys.stderr.flush()
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/ipykernel/ipkernel.py in do_execute(self=<ipykernel.ipkernel.IPythonKernel object>, code="# So the question is, if you only have the data ...s\npd.DataFrame(list(ugraph.edges(data='weight')))", silent=False, store_history=True, user_expressions={}, allow_stdin=True)
191
192 self._forward_input(allow_stdin)
193
194 reply_content = {}
195 try:
--> 196 res = shell.run_cell(code, store_history=store_history, silent=silent)
res = undefined
shell.run_cell = <bound method ZMQInteractiveShell.run_cell of <ipykernel.zmqshell.ZMQInteractiveShell object>>
code = "# So the question is, if you only have the data ...s\npd.DataFrame(list(ugraph.edges(data='weight')))"
store_history = True
silent = False
197 finally:
198 self._restore_input()
199
200 if res.error_before_exec is not None:
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/ipykernel/zmqshell.py in run_cell(self=<ipykernel.zmqshell.ZMQInteractiveShell object>, *args=("# So the question is, if you only have the data ...s\npd.DataFrame(list(ugraph.edges(data='weight')))",), **kwargs={'silent': False, 'store_history': True})
528 )
529 self.payload_manager.write_payload(payload)
530
531 def run_cell(self, *args, **kwargs):
532 self._last_traceback = None
--> 533 return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
self.run_cell = <bound method ZMQInteractiveShell.run_cell of <ipykernel.zmqshell.ZMQInteractiveShell object>>
args = ("# So the question is, if you only have the data ...s\npd.DataFrame(list(ugraph.edges(data='weight')))",)
kwargs = {'silent': False, 'store_history': True}
534
535 def _showtraceback(self, etype, evalue, stb):
536 # try to preserve ordering of tracebacks and print statements
537 sys.stdout.flush()
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_cell(self=<ipykernel.zmqshell.ZMQInteractiveShell object>, raw_cell="# So the question is, if you only have the data ...s\npd.DataFrame(list(ugraph.edges(data='weight')))", store_history=True, silent=False, shell_futures=True)
2723 self.displayhook.exec_result = result
2724
2725 # Execute the user code
2726 interactivity = "none" if silent else self.ast_node_interactivity
2727 has_raised = self.run_ast_nodes(code_ast.body, cell_name,
-> 2728 interactivity=interactivity, compiler=compiler, result=result)
interactivity = 'last_expr'
compiler = <IPython.core.compilerop.CachingCompiler object>
2729
2730 self.last_execution_succeeded = not has_raised
2731 self.last_execution_result = result
2732
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_ast_nodes(self=<ipykernel.zmqshell.ZMQInteractiveShell object>, nodelist=[<_ast.ImportFrom object>, <_ast.Assign object>, <_ast.Assign object>, <_ast.Assign object>, <_ast.Expr object>, <_ast.Expr object>, <_ast.Expr object>, <ast.Expr object>], cell_name='', interactivity='last', compiler=<IPython.core.compilerop.CachingCompiler object>, result=<ExecutionResult object at 111a330b8, execution...before_exec=None error_in_exec=None result=None>)
2845
2846 try:
2847 for i, node in enumerate(to_run_exec):
2848 mod = ast.Module([node])
2849 code = compiler(mod, cell_name, "exec")
-> 2850 if self.run_code(code, result):
self.run_code = <bound method InteractiveShell.run_code of <ipykernel.zmqshell.ZMQInteractiveShell object>>
code = <code object at 0x1a1f3f18a0, file "", line 8>
result = <ExecutionResult object at 111a330b8, execution..._before_exec=None error_in_exec=None result=None>
2851 return True
2852
2853 for i, node in enumerate(to_run_interactive):
2854 mod = ast.Interactive([node])
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/IPython/core/interactiveshell.py in run_code(self=<ipykernel.zmqshell.ZMQInteractiveShell object>, code_obj=<code object at 0x1a1f3f18a0, file "", line 8>, result=<ExecutionResult object at 111a330b8, execution_...before_exec=None error_in_exec=None result=None>)
2905 outflag = True # happens in more places, so it's easier as default
2906 try:
2907 try:
2908 self.hooks.pre_run_code_hook()
2909 #rprint('Running code', repr(code_obj)) # dbg
-> 2910 exec(code_obj, self.user_global_ns, self.user_ns)
code_obj = <code object at 0x1a1f3f18a0, file "", line 8>
self.user_global_ns = {'FSGNN': <class 'cdt.independence.graph.FSGNN.FSGNN'>, 'Fsgnn': <cdt.independence.graph.FSGNN.FSGNN object>, 'In': ['', '#Import libraries\nimport cdt\nfrom cdt import SET...pandas as pd\nfrom matplotlib import pyplot as plt', '#Import libraries\nimport cdt\nfrom cdt import SET...pandas as pd\nfrom matplotlib import pyplot as plt', '# Load data and graph solution\ndata = pd.read_cs...sualization of the graph. \nplt.show()\ndata.head()', 'solution', "# So the question is, if you only have the data ...s\npd.DataFrame(list(ugraph.edges(data='weight')))"], 'Out': {3: Allergy Anxiety Genetics Peer_Pressure ... -0.733240 -0.149308 0.854195 -0.633940 , 4: <networkx.classes.digraph.DiGraph object>}, 'SETTINGS': <cdt.utils.Settings.ConfigSettings object>, '': <networkx.classes.digraph.DiGraph object>, '3': Allergy Anxiety Genetics Peer_Pressure ... -0.733240 -0.149308 0.854195 -0.633940 , '4': <networkx.classes.digraph.DiGraph object>, '': Allergy Anxiety Genetics Peer_Pressure ... -0.733240 -0.149308 0.854195 -0.633940 , '': '', ...}
self.user_ns = {'FSGNN': <class 'cdt.independence.graph.FSGNN.FSGNN'>, 'Fsgnn': <cdt.independence.graph.FSGNN.FSGNN object>, 'In': ['', '#Import libraries\nimport cdt\nfrom cdt import SET...pandas as pd\nfrom matplotlib import pyplot as plt', '#Import libraries\nimport cdt\nfrom cdt import SET...pandas as pd\nfrom matplotlib import pyplot as plt', '# Load data and graph solution\ndata = pd.read_cs...sualization of the graph. \nplt.show()\ndata.head()', 'solution', "# So the question is, if you only have the data ...s\npd.DataFrame(list(ugraph.edges(data='weight')))"], 'Out': {3: Allergy Anxiety Genetics Peer_Pressure ... -0.733240 -0.149308 0.854195 -0.633940 , 4: <networkx.classes.digraph.DiGraph object>}, 'SETTINGS': <cdt.utils.Settings.ConfigSettings object>, '': <networkx.classes.digraph.DiGraph object>, '_3': Allergy Anxiety Genetics Peer_Pressure ... -0.733240 -0.149308 0.854195 -0.633940 , '4': <networkx.classes.digraph.DiGraph object>, '': Allergy Anxiety Genetics Peer_Pressure ... -0.733240 -0.149308 0.854195 -0.633940 , '': '', ...}
2911 finally:
2912 # Reset our crash handler in place
2913 sys.excepthook = old_excepthook
2914 except SystemExit as e:
...........................................................................
/Volumes/extra/FirmAI/Causal Inference/CausalDiscoveryToolbox-master/examples/ in ()
3 from cdt.independence.graph import FSGNN
4
5 Fsgnn = FSGNN()
6
7 start_time = time.time()
----> 8 ugraph = Fsgnn.predict(data, train_epochs=2000, test_epochs=1000, threshold=5e-4, l1=0.01)
9 print("--- Execution time : %4.4s seconds ---" % (time.time() - start_time))
10 nx.draw_networkx(ugraph, font_size=8) # The plot function allows for quick visualization of the graph.
11 plt.show()
12 # List results
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/cdt/independence/graph/model.py in predict(self=<cdt.independence.graph.FSGNN.FSGNN object>, df_data= Allergy Anxiety Genetics Peer_Pressure...0.858699 -1.037579
[500 rows x 11 columns], threshold=0.0005, **kwargs={'l1': 0.01, 'test_epochs': 1000, 'train_epochs': 2000})
50 nb_jobs = kwargs.get("nb_jobs", SETTINGS.NB_JOBS)
51 list_nodes = list(df_data.columns.values)
52 if nb_jobs != 1:
53 result_feature_selection = Parallel(n_jobs=nb_jobs)(delayed(self.run_feature_selection)
54 (df_data, node, idx, **kwargs)
---> 55 for idx, node in enumerate(list_nodes))
idx = undefined
node = undefined
list_nodes = ['Allergy', 'Anxiety', 'Genetics', 'Peer_Pressure', 'Attention_Disorder', 'Smoking', 'Lung_Cancer', 'Yellow_Fingers', 'Coughing', 'Fatigue', 'Car_Accident']
56 else:
57 result_feature_selection = [self.run_feature_selection(df_data, node, idx, **kwargs) for idx, node in enumerate(list_nodes)]
58 for idx, i in enumerate(result_feature_selection):
59 try:
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/joblib/parallel.py in call(self=Parallel(n_jobs=4), iterable=<generator object FeatureSelectionModel.predict..>)
784 if pre_dispatch == "all" or n_jobs == 1:
785 # The iterable was consumed all at once by the above for loop.
786 # No need to wait for async callbacks to trigger to
787 # consumption.
788 self._iterating = False
--> 789 self.retrieve()
self.retrieve = <bound method Parallel.retrieve of Parallel(n_jobs=4)>
790 # Make sure that we get a last message telling us we are done
791 elapsed_time = time.time() - self._start_time
792 self._print('Done %3i out of %3i | elapsed: %s finished',
793 (len(self._output), len(self._output),
Sub-process traceback:
AttributeError Sat Jun 30 16:19:48 2018
PID: 92373 Python 3.6.3: /Users/dereksnow/anaconda/envs/py36/bin/python
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/joblib/parallel.py in call(self=<joblib.parallel.BatchedCalls object>)
126 def init(self, iterator_slice):
127 self.items = list(iterator_slice)
128 self.size = len(self.items)
129
130 def call(self):
--> 131 return [func(*args, **kwargs) for func, args, kwargs in self.items]
self.items = [(<bound method FeatureSelectionModel.run_feature...n of <cdt.independence.graph.FSGNN.FSGNN object>>, ( Allergy Anxiety Genetics Peer_Pressure...0.858699 -1.037579
[500 rows x 11 columns], 'Allergy', 0), {'l1': 0.01, 'test_epochs': 1000, 'train_epochs': 2000})]
132
133 def len(self):
134 return self._size
135
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/joblib/parallel.py in (.0=<list_iterator object>)
126 def init(self, iterator_slice):
127 self.items = list(iterator_slice)
128 self.size = len(self.items)
129
130 def call(self):
--> 131 return [func(*args, **kwargs) for func, args, kwargs in self.items]
func = <bound method FeatureSelectionModel.run_feature...n of <cdt.independence.graph.FSGNN.FSGNN object>>
args = ( Allergy Anxiety Genetics Peer_Pressure...0.858699 -1.037579
[500 rows x 11 columns], 'Allergy', 0)
kwargs = {'l1': 0.01, 'test_epochs': 1000, 'train_epochs': 2000}
132
133 def len(self):
134 return self._size
135
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/cdt/independence/graph/model.py in run_feature_selection(self=<cdt.independence.graph.FSGNN.FSGNN object>, df_data= Allergy Anxiety Genetics Peer_Pressure...0.858699 -1.037579
[500 rows x 11 columns], target='Allergy', idx=0, **kwargs={'l1': 0.01, 'test_epochs': 1000, 'train_epochs': 2000})
38 list_features = list(df_data.columns.values)
39 list_features.remove(target)
40 df_target = pd.DataFrame(df_data[target], columns=[target])
41 df_features = df_data[list_features]
42
---> 43 return self.predict_features(df_features, df_target, **kwargs)
self.predict_features = <bound method FSGNN.predict_features of <cdt.independence.graph.FSGNN.FSGNN object>>
df_features = Anxiety Genetics Peer_Pressure Attentio...0.858699 -1.037579
[500 rows x 10 columns]
df_target = Allergy
0 -0.266076
1 -0.579084
2 -0...8 -0.064685
499 -0.638704
[500 rows x 1 columns]
kwargs = {'l1': 0.01, 'test_epochs': 1000, 'train_epochs': 2000}
44
45 def predict(self, df_data, threshold=0.05, **kwargs):
46 """Get the skeleton of the graph from raw data.
47
...........................................................................
/Users/dereksnow/anaconda/envs/py36/lib/python3.6/site-packages/cdt/independence/graph/FSGNN.py in predict_features(self=<cdt.independence.graph.FSGNN.FSGNN object>, df_features= Anxiety Genetics Peer_Pressure Attentio...0.858699 -1.037579
[500 rows x 10 columns], df_target= Allergy
0 -0.266076
1 -0.579084
2 -0...8 -0.064685
499 -0.638704
[500 rows x 1 columns], nh=20, idx=0, dropout=0.0, activation_function=<class 'torch.nn.modules.activation.ReLU'>, lr=0.01, l1=0.01, train_epochs=2000, test_epochs=1000, device='cpu', verbose=False, nb_runs=3)
74 activation_function=th.nn.ReLU, lr=0.01, l1=0.1, # batch_size=-1,
75 train_epochs=1000, test_epochs=1000, device=None,
76 verbose=None, nb_runs=3):
77 """For one variable, predict its neighbours."""
78 device, verbose = SETTINGS.get_default(('device', device), ('verbose', verbose))
---> 79 x = th.FloatTensor(scale(df_features.as_matrix())).to(device)
x = undefined
df_features.as_matrix.to = undefined
device = 'cpu'
80 y = th.FloatTensor(scale(df_target.as_matrix())).to(device)
81 out = []
82 for i in range(nb_runs):
83 model = FSGNN_model([x.size()[1], nh, 1],
AttributeError: 'torch.FloatTensor' object has no attribute 'to'
___________________________________________________________________________`
The text was updated successfully, but these errors were encountered: