def _ica_explained_variance(ica, inst, normalize=False):
 if (not isinstance(ica, ICA)):
  raise TypeError('first argument must be an instance of ICA.')
 if (not isinstance(inst, (BaseRaw, BaseEpochs, Evoked))):
  raise TypeError('second argument must an instance of either Raw, Epochs or Evoked.')
 source_data = _get_inst_data(ica.get_sources(inst))
 if isinstance(inst, BaseEpochs):
  (n_epochs, n_chan, n_samp) = source_data.shape
  source_data = source_data.transpose(1, 0, 2).reshape((n_chan, (n_epochs * n_samp)))
 (n_chan, n_samp) = source_data.shape
 var = ((np.sum((ica.mixing_matrix_ ** 2), axis=0) * np.sum((source_data ** 2), axis=1)) / ((n_chan * n_samp) - 1))
 if normalize:
  var /= var.sum()
 return var

def _ica_explained_variance ( ica , inst , normalize = False ) : if ( not isinstance ( ica , ICA ) ) : raise TypeError ( 'first argument must be an instance of ICA.' ) if ( not isinstance ( inst , ( BaseRaw , BaseEpochs , Evoked ) ) ) : raise TypeError ( 'second argument must an instance of either Raw, Epochs or Evoked.' ) source_data = _get_inst_data ( ica . get_sources ( inst ) ) if isinstance ( inst , BaseEpochs ) : ( n_epochs , n_chan , n_samp ) = source_data . shape source_data = source_data . transpose ( 1 , 0 , 2 ) . reshape ( ( n_chan , ( n_epochs * n_samp ) ) ) ( n_chan , n_samp ) = source_data . shape var = ( ( np . sum ( ( ica . mixing_matrix_ ** 2 ) , axis = 0 ) * np . sum ( ( source_data ** 2 ) , axis = 1 ) ) / ( ( n_chan * n_samp ) - 1 ) ) if normalize : var /= var . sum ( ) return var
check variance accounted for by each component in supplied data .