pwollstadt/IDTxl

Discrete Data Issue

Xirailuyo opened this issue · 3 comments

I seem to be getting the following error given a 0,1 numpy 2d array. I have verified that the data is a 463x14 shaped numpy array, with only 0s and 1s. I put it through the data class given by IDTxl and receive this error when running network_analysis. Thank you for the assistance.


AssertionError Traceback (most recent call last)
in ()
1 # IDTxl analysis
----> 2 results = network_analysis.analyse_network(settings=settings, data=idtxl_data)

/home/xirailuyo/Desktop/Network/IDTxl/idtxl/bivariate_te.py in analyse_network(self, settings, data, targets, sources)
153 .format(t, targets))
154 res_single = self.analyse_single_target(
--> 155 settings, data, targets[t], sources[t])
156 results.combine_results(res_single)
157

/home/xirailuyo/Desktop/Network/IDTxl/idtxl/bivariate_te.py in analyse_single_target(self, settings, data, target, sources)
273 # Main algorithm.
274 print('\n---------------------------- (1) include target candidates')
--> 275 self._include_target_candidates(data)
276 print('\n---------------------------- (2) include source candidates')
277 self._include_source_candidates(data)

/home/xirailuyo/Desktop/Network/IDTxl/idtxl/network_inference.py in _include_target_candidates(self, data)
426 -self.settings['tau_target']).tolist()
427 candidates = self._define_candidates(procs, samples)
--> 428 sources_found = self._include_candidates(candidates, data)
429
430 # If no candidates were found in the target's past, add at least one

/home/xirailuyo/Desktop/Network/IDTxl/idtxl/network_inference.py in _include_candidates(self, candidate_set, data)
118 var1=cand_real,
119 var2=self._current_value_realisations,
--> 120 conditional=self._selected_vars_realisations)
121 except ex.AlgorithmExhaustedError as aee:
122 # The algorithm cannot continue here, so

/home/xirailuyo/Desktop/Network/IDTxl/idtxl/estimator.py in estimate_parallel(self, n_chunks, re_use, **data)
328 v, data[v].shape[0], chunk_size))
329 chunk_data[v] = data[v]
--> 330 results[i] = self.estimate(**chunk_data)
331 idx_1 = idx_2
332 idx_2 += chunk_size

/home/xirailuyo/Desktop/Network/IDTxl/idtxl/estimators_jidt.py in estimate(self, var1, var2, conditional, return_calc)
568 # Return value will be just the estimate if return_calc is False,
569 # or estimate plus the JIDT MI calculator if return_calc is True:
--> 570 return self.mi_calc.estimate(var1, var2, return_calc)
571 else:
572 assert(conditional.size != 0), 'Conditional Array is empty.'

/home/xirailuyo/Desktop/Network/IDTxl/idtxl/estimators_jidt.py in estimate(self, var1, var2, return_calc)
744
745 # Discretise variables if requested.
--> 746 var1, var2 = self._discretise_vars(var1, var2)
747
748 # Then collapse any mulitvariates into univariate arrays:

/home/xirailuyo/Desktop/Network/IDTxl/idtxl/estimators_jidt.py in _discretise_vars(self, var1, var2, conditional)
220 elif self.settings['discretise_method'] == 'none':
221 assert issubclass(var1.dtype.type, np.integer), (
--> 222 'Var1 is not an integer numpy array. '
223 'Discretise data to use this estimator.')
224 assert issubclass(var2.dtype.type, np.integer), (

AssertionError: Var1 is not an integer numpy array. Discretise data to use this estimator.

It looks like python is not recognising that you're supplying an array of integers. I would assume your array is typed as floats instead, even though you're assigning 0's and 1's. Could you check that please? Then try the following:

  1. Try forcing the type of the array data to be integers. That is the recommended solution.
  2. Otherwise a more hacky fix would be to set 'discretise_method' to 'equal', 'alph1' to 2 and 'alph2' to 2, and IDTxl will make a conversion which should keep the right integer values (so long as each variable has samples of both 0's and 1's)
  3. Finally, send a minimal example to reproduce this error.

--joe

Thank you for the response. I needed to turn normalization off with the Data function.

Ok, thanks @Xirailuyo - from what I gather, your use of this option was changing your discrete data into floats (before passing to analyse_network) without you realising it. Closing, not a bug.