idx int64 0 251k | question stringlengths 53 3.53k | target stringlengths 5 1.23k | len_question int64 20 893 | len_target int64 3 238 |
|---|---|---|---|---|
247,700 | def condition_tpm ( tpm , fixed_nodes , state ) : conditioning_indices = [ [ slice ( None ) ] ] * len ( state ) for i in fixed_nodes : # Preserve singleton dimensions with `np.newaxis` conditioning_indices [ i ] = [ state [ i ] , np . newaxis ] # Flatten the indices. conditioning_indices = list ( chain . from_iterable ... | Return a TPM conditioned on the given fixed node indices whose states are fixed according to the given state - tuple . | 130 | 23 |
247,701 | def expand_tpm ( tpm ) : unconstrained = np . ones ( [ 2 ] * ( tpm . ndim - 1 ) + [ tpm . shape [ - 1 ] ] ) return tpm * unconstrained | Broadcast a state - by - node TPM so that singleton dimensions are expanded over the full network . | 50 | 22 |
247,702 | def marginalize_out ( node_indices , tpm ) : return tpm . sum ( tuple ( node_indices ) , keepdims = True ) / ( np . array ( tpm . shape ) [ list ( node_indices ) ] . prod ( ) ) | Marginalize out nodes from a TPM . | 60 | 9 |
247,703 | def infer_edge ( tpm , a , b , contexts ) : def a_in_context ( context ) : """Given a context C(A), return the states of the full system with A OFF and ON, respectively. """ a_off = context [ : a ] + OFF + context [ a : ] a_on = context [ : a ] + ON + context [ a : ] return ( a_off , a_on ) def a_affects_b_in_context (... | Infer the presence or absence of an edge from node A to node B . | 187 | 16 |
247,704 | def infer_cm ( tpm ) : network_size = tpm . shape [ - 1 ] all_contexts = tuple ( all_states ( network_size - 1 ) ) cm = np . empty ( ( network_size , network_size ) , dtype = int ) for a , b in np . ndindex ( cm . shape ) : cm [ a ] [ b ] = infer_edge ( tpm , a , b , all_contexts ) return cm | Infer the connectivity matrix associated with a state - by - node TPM in multidimensional form . | 102 | 21 |
247,705 | def get_num_processes ( ) : cpu_count = multiprocessing . cpu_count ( ) if config . NUMBER_OF_CORES == 0 : raise ValueError ( 'Invalid NUMBER_OF_CORES; value may not be 0.' ) if config . NUMBER_OF_CORES > cpu_count : log . info ( 'Requesting %s cores; only %s available' , config . NUMBER_OF_CORES , cpu_count ) return c... | Return the number of processes to use in parallel . | 195 | 10 |
247,706 | def init_progress_bar ( self ) : # Forked worker processes can't show progress bars. disable = MapReduce . _forked or not config . PROGRESS_BARS # Don't materialize iterable unless we have to: huge iterables # (e.g. of `KCuts`) eat memory. if disable : total = None else : self . iterable = list ( self . iterable ) tota... | Initialize and return a progress bar . | 122 | 8 |
247,707 | def worker ( compute , task_queue , result_queue , log_queue , complete , * context ) : try : MapReduce . _forked = True log . debug ( 'Worker process starting...' ) configure_worker_logging ( log_queue ) for obj in iter ( task_queue . get , POISON_PILL ) : if complete . is_set ( ) : log . debug ( 'Worker received sign... | A worker process run by multiprocessing . Process . | 192 | 12 |
247,708 | def start_parallel ( self ) : self . num_processes = get_num_processes ( ) self . task_queue = multiprocessing . Queue ( maxsize = Q_MAX_SIZE ) self . result_queue = multiprocessing . Queue ( ) self . log_queue = multiprocessing . Queue ( ) # Used to signal worker processes when a result is found that allows # the comp... | Initialize all queues and start the worker processes and the log thread . | 225 | 14 |
247,709 | def initialize_tasks ( self ) : # Add a poison pill to shutdown each process. self . tasks = chain ( self . iterable , [ POISON_PILL ] * self . num_processes ) for task in islice ( self . tasks , Q_MAX_SIZE ) : log . debug ( 'Putting %s on queue' , task ) self . task_queue . put ( task ) | Load the input queue to capacity . | 87 | 7 |
247,710 | def maybe_put_task ( self ) : try : task = next ( self . tasks ) except StopIteration : pass else : log . debug ( 'Putting %s on queue' , task ) self . task_queue . put ( task ) | Enqueue the next task if there are any waiting . | 52 | 11 |
247,711 | def run_parallel ( self ) : try : self . start_parallel ( ) result = self . empty_result ( * self . context ) while self . num_processes > 0 : r = self . result_queue . get ( ) self . maybe_put_task ( ) if r is POISON_PILL : self . num_processes -= 1 elif isinstance ( r , ExceptionWrapper ) : r . reraise ( ) else : res... | Perform the computation in parallel reading results from the output queue and passing them to process_result . | 177 | 20 |
247,712 | def finish_parallel ( self ) : for process in self . processes : process . join ( ) # Shutdown the log thread log . debug ( 'Joining log thread' ) self . log_queue . put ( POISON_PILL ) self . log_thread . join ( ) self . log_queue . close ( ) # Close all queues log . debug ( 'Closing queues' ) self . task_queue . clos... | Orderly shutdown of workers . | 101 | 6 |
247,713 | def run_sequential ( self ) : try : result = self . empty_result ( * self . context ) for obj in self . iterable : r = self . compute ( obj , * self . context ) result = self . process_result ( r , result ) self . progress . update ( 1 ) # Short-circuited? if self . done : break except Exception as e : raise e finally ... | Perform the computation sequentially only holding two computed objects in memory at a time . | 96 | 17 |
247,714 | def configure_logging ( conf ) : logging . config . dictConfig ( { 'version' : 1 , 'disable_existing_loggers' : False , 'formatters' : { 'standard' : { 'format' : '%(asctime)s [%(name)s] %(levelname)s ' '%(processName)s: %(message)s' } } , 'handlers' : { 'file' : { 'level' : conf . LOG_FILE_LEVEL , 'filename' : conf . ... | Reconfigure PyPhi logging based on the current configuration . | 253 | 13 |
247,715 | def _validate ( self , value ) : if self . values and value not in self . values : raise ValueError ( '{} is not a valid value for {}' . format ( value , self . name ) ) | Validate the new value . | 47 | 6 |
247,716 | def options ( cls ) : return { k : v for k , v in cls . __dict__ . items ( ) if isinstance ( v , Option ) } | Return a dictionary of the Option objects for this config . | 36 | 11 |
247,717 | def defaults ( self ) : return { k : v . default for k , v in self . options ( ) . items ( ) } | Return the default values of this configuration . | 28 | 8 |
247,718 | def load_dict ( self , dct ) : for k , v in dct . items ( ) : setattr ( self , k , v ) | Load a dictionary of configuration values . | 32 | 7 |
247,719 | def load_file ( self , filename ) : filename = os . path . abspath ( filename ) with open ( filename ) as f : self . load_dict ( yaml . load ( f ) ) self . _loaded_files . append ( filename ) | Load config from a YAML file . | 54 | 9 |
247,720 | def log ( self ) : log . info ( 'PyPhi v%s' , __about__ . __version__ ) if self . _loaded_files : log . info ( 'Loaded configuration from %s' , self . _loaded_files ) else : log . info ( 'Using default configuration (no configuration file ' 'provided)' ) log . info ( 'Current PyPhi configuration:\n %s' , str ( self ) ) | Log current settings . | 95 | 4 |
247,721 | def be2le_state_by_state ( tpm ) : le = np . empty ( tpm . shape ) N = tpm . shape [ 0 ] n = int ( log2 ( N ) ) for i in range ( N ) : le [ i , : ] = tpm [ be2le ( i , n ) , : ] return le | Convert a state - by - state TPM from big - endian to little - endian or vice versa . | 76 | 24 |
247,722 | def to_multidimensional ( tpm ) : # Cast to np.array. tpm = np . array ( tpm ) # Get the number of nodes. N = tpm . shape [ - 1 ] # Reshape. We use Fortran ordering here so that the rows use the # little-endian convention (least-significant bits correspond to low-index # nodes). Note that this does not change the actua... | Reshape a state - by - node TPM to the multidimensional form . | 139 | 18 |
247,723 | def state_by_state2state_by_node ( tpm ) : # Cast to np.array. tpm = np . array ( tpm ) # Get the number of states from the length of one side of the TPM. S = tpm . shape [ - 1 ] # Get the number of nodes from the number of states. N = int ( log2 ( S ) ) # Initialize the new state-by node TPM. sbn_tpm = np . zeros ( ( ... | Convert a state - by - state TPM to a state - by - node TPM . | 347 | 20 |
247,724 | def state_by_node2state_by_state ( tpm ) : # Cast to np.array. tpm = np . array ( tpm ) # Convert to multidimensional form. tpm = to_multidimensional ( tpm ) # Get the number of nodes from the last dimension of the TPM. N = tpm . shape [ - 1 ] # Get the number of states. S = 2 ** N # Initialize the state-by-state TPM. ... | Convert a state - by - node TPM to a state - by - state TPM . | 410 | 20 |
247,725 | def load_json_network ( json_dict ) : network = pyphi . Network . from_json ( json_dict [ 'network' ] ) state = json_dict [ 'state' ] return ( network , state ) | Load a network from a json file | 48 | 7 |
247,726 | def all_network_files ( ) : # TODO: list explicitly since some are missing? network_types = [ 'AND-circle' , 'MAJ-specialized' , 'MAJ-complete' , 'iit-3.0-modular' ] network_sizes = range ( 5 , 8 ) network_files = [ ] for n in network_sizes : for t in network_types : network_files . append ( '{}-{}' . format ( n , t ) ... | All network files | 115 | 3 |
247,727 | def profile_network ( filename ) : log = logging . getLogger ( filename ) logfile = os . path . join ( LOGS , filename + '.log' ) os . makedirs ( os . path . dirname ( logfile ) , exist_ok = True ) handler = logging . FileHandler ( logfile ) handler . setFormatter ( formatter ) log . addHandler ( handler ) log . setLev... | Profile a network . | 372 | 4 |
247,728 | def run_tpm ( tpm , time_scale ) : sbs_tpm = convert . state_by_node2state_by_state ( tpm ) if sparse ( tpm ) : tpm = sparse_time ( sbs_tpm , time_scale ) else : tpm = dense_time ( sbs_tpm , time_scale ) return convert . state_by_state2state_by_node ( tpm ) | Iterate a TPM by the specified number of time steps . | 98 | 13 |
247,729 | def run_cm ( cm , time_scale ) : cm = np . linalg . matrix_power ( cm , time_scale ) # Round non-unitary values back to 1 cm [ cm > 1 ] = 1 return cm | Iterate a connectivity matrix the specified number of steps . | 50 | 11 |
247,730 | def _reachable_subsystems ( network , indices , state ) : validate . is_network ( network ) # Return subsystems largest to smallest to optimize parallel # resource usage. for subset in utils . powerset ( indices , nonempty = True , reverse = True ) : try : yield Subsystem ( network , state , subset ) except exceptions ... | A generator over all subsystems in a valid state . | 81 | 11 |
247,731 | def all_complexes ( network , state ) : engine = FindAllComplexes ( subsystems ( network , state ) ) return engine . run ( config . PARALLEL_COMPLEX_EVALUATION ) | Return a generator for all complexes of the network . | 47 | 10 |
247,732 | def complexes ( network , state ) : engine = FindIrreducibleComplexes ( possible_complexes ( network , state ) ) return engine . run ( config . PARALLEL_COMPLEX_EVALUATION ) | Return all irreducible complexes of the network . | 49 | 11 |
247,733 | def major_complex ( network , state ) : log . info ( 'Calculating major complex...' ) result = complexes ( network , state ) if result : result = max ( result ) else : empty_subsystem = Subsystem ( network , state , ( ) ) result = _null_sia ( empty_subsystem ) log . info ( "Finished calculating major complex." ) return... | Return the major complex of the network . | 84 | 8 |
247,734 | def condensed ( network , state ) : result = [ ] covered_nodes = set ( ) for c in reversed ( sorted ( complexes ( network , state ) ) ) : if not any ( n in covered_nodes for n in c . subsystem . node_indices ) : result . append ( c ) covered_nodes = covered_nodes | set ( c . subsystem . node_indices ) return result | Return a list of maximal non - overlapping complexes . | 88 | 10 |
247,735 | def basic_network ( cm = False ) : tpm = np . array ( [ [ 0 , 0 , 0 ] , [ 0 , 0 , 1 ] , [ 1 , 0 , 1 ] , [ 1 , 0 , 0 ] , [ 1 , 1 , 0 ] , [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] , [ 1 , 1 , 0 ] ] ) if cm is False : cm = np . array ( [ [ 0 , 0 , 1 ] , [ 1 , 0 , 1 ] , [ 1 , 1 , 0 ] ] ) else : cm = None return Network ( tpm , cm = cm... | A 3 - node network of logic gates . | 154 | 9 |
247,736 | def basic_noisy_selfloop_network ( ) : tpm = np . array ( [ [ 0.271 , 0.19 , 0.244 ] , [ 0.919 , 0.19 , 0.756 ] , [ 0.919 , 0.91 , 0.756 ] , [ 0.991 , 0.91 , 0.244 ] , [ 0.919 , 0.91 , 0.756 ] , [ 0.991 , 0.91 , 0.244 ] , [ 0.991 , 0.99 , 0.244 ] , [ 0.999 , 0.99 , 0.756 ] ] ) cm = np . array ( [ [ 1 , 0 , 1 ] , [ 1 , ... | Based on the basic_network but with added selfloops and noisy edges . | 182 | 16 |
247,737 | def residue_network ( ) : tpm = np . array ( [ [ int ( s ) for s in bin ( x ) [ 2 : ] . zfill ( 5 ) [ : : - 1 ] ] for x in range ( 32 ) ] ) tpm [ np . where ( np . sum ( tpm [ 0 : , 2 : 4 ] , 1 ) == 2 ) , 0 ] = 1 tpm [ np . where ( np . sum ( tpm [ 0 : , 3 : 5 ] , 1 ) == 2 ) , 1 ] = 1 tpm [ np . where ( np . sum ( tpm ... | The network for the residue example . | 242 | 7 |
247,738 | def propagation_delay_network ( ) : num_nodes = 9 num_states = 2 ** num_nodes tpm = np . zeros ( ( num_states , num_nodes ) ) for previous_state_index , previous in enumerate ( all_states ( num_nodes ) ) : current_state = [ 0 for i in range ( num_nodes ) ] if previous [ 2 ] == 1 or previous [ 7 ] == 1 : current_state [... | A version of the primary example from the IIT 3 . 0 paper with deterministic COPY gates on each connection . These copy gates essentially function as propagation delays on the signal between OR AND and XOR gates from the original system . | 457 | 47 |
247,739 | def macro_network ( ) : tpm = np . array ( [ [ 0.3 , 0.3 , 0.3 , 0.3 ] , [ 0.3 , 0.3 , 0.3 , 0.3 ] , [ 0.3 , 0.3 , 0.3 , 0.3 ] , [ 0.3 , 0.3 , 1.0 , 1.0 ] , [ 0.3 , 0.3 , 0.3 , 0.3 ] , [ 0.3 , 0.3 , 0.3 , 0.3 ] , [ 0.3 , 0.3 , 0.3 , 0.3 ] , [ 0.3 , 0.3 , 1.0 , 1.0 ] , [ 0.3 , 0.3 , 0.3 , 0.3 ] , [ 0.3 , 0.3 , 0.3 , 0.3... | A network of micro elements which has greater integrated information after coarse graining to a macro scale . | 329 | 19 |
247,740 | def blackbox_network ( ) : num_nodes = 6 num_states = 2 ** num_nodes tpm = np . zeros ( ( num_states , num_nodes ) ) for index , previous_state in enumerate ( all_states ( num_nodes ) ) : current_state = [ 0 for i in range ( num_nodes ) ] if previous_state [ 5 ] == 1 : current_state [ 0 ] = 1 current_state [ 1 ] = 1 if... | A micro - network to demonstrate blackboxing . | 315 | 9 |
247,741 | def actual_causation ( ) : tpm = np . array ( [ [ 1 , 0 , 0 , 0 ] , [ 0 , 1 , 0 , 0 ] , [ 0 , 1 , 0 , 0 ] , [ 0 , 0 , 0 , 1 ] ] ) cm = np . array ( [ [ 1 , 1 ] , [ 1 , 1 ] ] ) return Network ( tpm , cm , node_labels = ( 'OR' , 'AND' ) ) | The actual causation example network consisting of an OR and AND gate with self - loops . | 101 | 17 |
247,742 | def prevention ( ) : tpm = np . array ( [ [ 0.5 , 0.5 , 1 ] , [ 0.5 , 0.5 , 0 ] , [ 0.5 , 0.5 , 1 ] , [ 0.5 , 0.5 , 1 ] , [ 0.5 , 0.5 , 1 ] , [ 0.5 , 0.5 , 0 ] , [ 0.5 , 0.5 , 1 ] , [ 0.5 , 0.5 , 1 ] ] ) cm = np . array ( [ [ 0 , 0 , 1 ] , [ 0 , 0 , 1 ] , [ 0 , 0 , 0 ] ] ) network = Network ( tpm , cm , node_labels = [... | The |Transition| for the prevention example from Actual Causation Figure 5D . | 216 | 18 |
247,743 | def clear_subsystem_caches ( subsys ) : try : # New-style caches subsys . _repertoire_cache . clear ( ) subsys . _mice_cache . clear ( ) except TypeError : try : # Pre cache.clear() implementation subsys . _repertoire_cache . cache = { } subsys . _mice_cache . cache = { } except AttributeError : # Old school, pre cache... | Clear subsystem caches | 142 | 3 |
247,744 | def all_states ( n , big_endian = False ) : if n == 0 : return for state in product ( ( 0 , 1 ) , repeat = n ) : if big_endian : yield state else : yield state [ : : - 1 ] | Return all binary states for a system . | 55 | 8 |
247,745 | def np_hash ( a ) : if a is None : return hash ( None ) # Ensure that hashes are equal whatever the ordering in memory (C or # Fortran) a = np . ascontiguousarray ( a ) # Compute the digest and return a decimal int return int ( hashlib . sha1 ( a . view ( a . dtype ) ) . hexdigest ( ) , 16 ) | Return a hash of a NumPy array . | 86 | 9 |
247,746 | def powerset ( iterable , nonempty = False , reverse = False ) : iterable = list ( iterable ) if nonempty : # Don't include 0-length subsets start = 1 else : start = 0 seq_sizes = range ( start , len ( iterable ) + 1 ) if reverse : seq_sizes = reversed ( seq_sizes ) iterable . reverse ( ) return chain . from_iterable (... | Generate the power set of an iterable . | 107 | 10 |
247,747 | def load_data ( directory , num ) : root = os . path . abspath ( os . path . dirname ( __file__ ) ) def get_path ( i ) : # pylint: disable=missing-docstring return os . path . join ( root , 'data' , directory , str ( i ) + '.npy' ) return [ np . load ( get_path ( i ) ) for i in range ( num ) ] | Load numpy data from the data directory . | 96 | 9 |
247,748 | def time_annotated ( func , * args , * * kwargs ) : start = time ( ) result = func ( * args , * * kwargs ) end = time ( ) result . time = round ( end - start , config . PRECISION ) return result | Annotate the decorated function or method with the total execution time . | 59 | 14 |
247,749 | def _null_ria ( direction , mechanism , purview , repertoire = None , phi = 0.0 ) : # TODO Use properties here to infer mechanism and purview from # partition yet access them with .mechanism and .partition return RepertoireIrreducibilityAnalysis ( direction = direction , mechanism = mechanism , purview = purview , part... | The irreducibility analysis for a reducible mechanism . | 101 | 12 |
247,750 | def damaged_by_cut ( self , subsystem ) : return ( subsystem . cut . splits_mechanism ( self . mechanism ) or np . any ( self . _relevant_connections ( subsystem ) * subsystem . cut . cut_matrix ( subsystem . network . size ) == 1 ) ) | Return True if this MICE is affected by the subsystem s cut . | 63 | 14 |
247,751 | def eq_repertoires ( self , other ) : return ( np . array_equal ( self . cause_repertoire , other . cause_repertoire ) and np . array_equal ( self . effect_repertoire , other . effect_repertoire ) ) | Return whether this concept has the same repertoires as another . | 65 | 12 |
247,752 | def emd_eq ( self , other ) : return ( self . phi == other . phi and self . mechanism == other . mechanism and self . eq_repertoires ( other ) ) | Return whether this concept is equal to another in the context of an EMD calculation . | 43 | 17 |
247,753 | def directed_account ( transition , direction , mechanisms = False , purviews = False , allow_neg = False ) : if mechanisms is False : mechanisms = utils . powerset ( transition . mechanism_indices ( direction ) , nonempty = True ) links = [ transition . find_causal_link ( direction , mechanism , purviews = purviews , ... | Return the set of all |CausalLinks| of the specified direction . | 108 | 15 |
247,754 | def account ( transition , direction = Direction . BIDIRECTIONAL ) : if direction != Direction . BIDIRECTIONAL : return directed_account ( transition , direction ) return Account ( directed_account ( transition , Direction . CAUSE ) + directed_account ( transition , Direction . EFFECT ) ) | Return the set of all causal links for a |Transition| . | 65 | 14 |
247,755 | def _evaluate_cut ( transition , cut , unpartitioned_account , direction = Direction . BIDIRECTIONAL ) : cut_transition = transition . apply_cut ( cut ) partitioned_account = account ( cut_transition , direction ) log . debug ( "Finished evaluating %s." , cut ) alpha = account_distance ( unpartitioned_account , partiti... | Find the |AcSystemIrreducibilityAnalysis| for a given cut . | 141 | 16 |
247,756 | def _get_cuts ( transition , direction ) : n = transition . network . size if direction is Direction . BIDIRECTIONAL : yielded = set ( ) for cut in chain ( _get_cuts ( transition , Direction . CAUSE ) , _get_cuts ( transition , Direction . EFFECT ) ) : cm = utils . np_hashable ( cut . cut_matrix ( n ) ) if cm not in yi... | A list of possible cuts to a transition . | 164 | 9 |
247,757 | def sia ( transition , direction = Direction . BIDIRECTIONAL ) : validate . direction ( direction , allow_bi = True ) log . info ( "Calculating big-alpha for %s..." , transition ) if not transition : log . info ( 'Transition %s is empty; returning null SIA ' 'immediately.' , transition ) return _null_ac_sia ( transitio... | Return the minimal information partition of a transition in a specific direction . | 319 | 13 |
247,758 | def nexus ( network , before_state , after_state , direction = Direction . BIDIRECTIONAL ) : validate . is_network ( network ) sias = ( sia ( transition , direction ) for transition in transitions ( network , before_state , after_state ) ) return tuple ( sorted ( filter ( None , sias ) , reverse = True ) ) | Return a tuple of all irreducible nexus of the network . | 78 | 14 |
247,759 | def causal_nexus ( network , before_state , after_state , direction = Direction . BIDIRECTIONAL ) : validate . is_network ( network ) log . info ( "Calculating causal nexus..." ) result = nexus ( network , before_state , after_state , direction ) if result : result = max ( result ) else : null_transition = Transition (... | Return the causal nexus of the network . | 144 | 8 |
247,760 | def nice_true_ces ( tc ) : cause_list = [ ] next_list = [ ] cause = '<--' effect = '-->' for event in tc : if event . direction == Direction . CAUSE : cause_list . append ( [ "{0:.4f}" . format ( round ( event . alpha , 4 ) ) , event . mechanism , cause , event . purview ] ) elif event . direction == Direction . EFFECT... | Format a true |CauseEffectStructure| . | 184 | 10 |
247,761 | def true_ces ( subsystem , previous_state , next_state ) : network = subsystem . network nodes = subsystem . node_indices state = subsystem . state _events = events ( network , previous_state , state , next_state , nodes ) if not _events : log . info ( "Finished calculating, no echo events." ) return None result = tupl... | Set of all sets of elements that have true causes and true effects . | 134 | 14 |
247,762 | def true_events ( network , previous_state , current_state , next_state , indices = None , major_complex = None ) : # TODO: validate triplet of states if major_complex : nodes = major_complex . subsystem . node_indices elif indices : nodes = indices else : major_complex = compute . major_complex ( network , current_sta... | Return all mechanisms that have true causes and true effects within the complex . | 112 | 14 |
247,763 | def extrinsic_events ( network , previous_state , current_state , next_state , indices = None , major_complex = None ) : if major_complex : mc_nodes = major_complex . subsystem . node_indices elif indices : mc_nodes = indices else : major_complex = compute . major_complex ( network , current_state ) mc_nodes = major_co... | Set of all mechanisms that are in the major complex but which have true causes and effects within the entire network . | 153 | 22 |
247,764 | def apply_cut ( self , cut ) : return Transition ( self . network , self . before_state , self . after_state , self . cause_indices , self . effect_indices , cut ) | Return a cut version of this transition . | 45 | 8 |
247,765 | def cause_repertoire ( self , mechanism , purview ) : return self . repertoire ( Direction . CAUSE , mechanism , purview ) | Return the cause repertoire . | 31 | 5 |
247,766 | def effect_repertoire ( self , mechanism , purview ) : return self . repertoire ( Direction . EFFECT , mechanism , purview ) | Return the effect repertoire . | 31 | 5 |
247,767 | def repertoire ( self , direction , mechanism , purview ) : system = self . system [ direction ] node_labels = system . node_labels if not set ( purview ) . issubset ( self . purview_indices ( direction ) ) : raise ValueError ( '{} is not a {} purview in {}' . format ( fmt . fmt_mechanism ( purview , node_labels ) , di... | Return the cause or effect repertoire function based on a direction . | 170 | 12 |
247,768 | def state_probability ( self , direction , repertoire , purview , ) : purview_state = self . purview_state ( direction ) index = tuple ( node_state if node in purview else 0 for node , node_state in enumerate ( purview_state ) ) return repertoire [ index ] | Compute the probability of the purview in its current state given the repertoire . | 67 | 16 |
247,769 | def probability ( self , direction , mechanism , purview ) : repertoire = self . repertoire ( direction , mechanism , purview ) return self . state_probability ( direction , repertoire , purview ) | Probability that the purview is in it s current state given the state of the mechanism . | 42 | 20 |
247,770 | def purview_state ( self , direction ) : return { Direction . CAUSE : self . before_state , Direction . EFFECT : self . after_state } [ direction ] | The state of the purview when we are computing coefficients in direction . | 38 | 14 |
247,771 | def mechanism_indices ( self , direction ) : return { Direction . CAUSE : self . effect_indices , Direction . EFFECT : self . cause_indices } [ direction ] | The indices of nodes in the mechanism system . | 40 | 9 |
247,772 | def purview_indices ( self , direction ) : return { Direction . CAUSE : self . cause_indices , Direction . EFFECT : self . effect_indices } [ direction ] | The indices of nodes in the purview system . | 41 | 10 |
247,773 | def cause_ratio ( self , mechanism , purview ) : return self . _ratio ( Direction . CAUSE , mechanism , purview ) | The cause ratio of the purview given mechanism . | 31 | 10 |
247,774 | def effect_ratio ( self , mechanism , purview ) : return self . _ratio ( Direction . EFFECT , mechanism , purview ) | The effect ratio of the purview given mechanism . | 31 | 10 |
247,775 | def partitioned_repertoire ( self , direction , partition ) : system = self . system [ direction ] return system . partitioned_repertoire ( direction , partition ) | Compute the repertoire over the partition in the given direction . | 39 | 12 |
247,776 | def partitioned_probability ( self , direction , partition ) : repertoire = self . partitioned_repertoire ( direction , partition ) return self . state_probability ( direction , repertoire , partition . purview ) | Compute the probability of the mechanism over the purview in the partition . | 49 | 15 |
247,777 | def find_mip ( self , direction , mechanism , purview , allow_neg = False ) : alpha_min = float ( 'inf' ) probability = self . probability ( direction , mechanism , purview ) for partition in mip_partitions ( mechanism , purview , self . node_labels ) : partitioned_probability = self . partitioned_probability ( directi... | Find the ratio minimum information partition for a mechanism over a purview . | 329 | 14 |
247,778 | def find_causal_link ( self , direction , mechanism , purviews = False , allow_neg = False ) : purviews = self . potential_purviews ( direction , mechanism , purviews ) # Find the maximal RIA over the remaining purviews. if not purviews : max_ria = _null_ac_ria ( self . mechanism_state ( direction ) , direction , mecha... | Return the maximally irreducible cause or effect ratio for a mechanism . | 142 | 16 |
247,779 | def find_actual_cause ( self , mechanism , purviews = False ) : return self . find_causal_link ( Direction . CAUSE , mechanism , purviews ) | Return the actual cause of a mechanism . | 37 | 8 |
247,780 | def find_actual_effect ( self , mechanism , purviews = False ) : return self . find_causal_link ( Direction . EFFECT , mechanism , purviews ) | Return the actual effect of a mechanism . | 37 | 8 |
247,781 | def find ( key ) : docs = list ( collection . find ( { KEY_FIELD : key } ) ) # Return None if we didn't find anything. if not docs : return None pickled_value = docs [ 0 ] [ VALUE_FIELD ] # Unpickle and return the value. return pickle . loads ( pickled_value ) | Return the value associated with a key . | 74 | 8 |
247,782 | def insert ( key , value ) : # Pickle the value. value = pickle . dumps ( value , protocol = constants . PICKLE_PROTOCOL ) # Store the value as binary data in a document. doc = { KEY_FIELD : key , VALUE_FIELD : Binary ( value ) } # Pickle and store the value with its key. If the key already exists, we # don't insert (s... | Store a value with a key . | 126 | 7 |
247,783 | def generate_key ( filtered_args ) : # Convert the value to a (potentially singleton) tuple to be consistent # with joblib.filtered_args. if isinstance ( filtered_args , Iterable ) : return hash ( tuple ( filtered_args ) ) return hash ( ( filtered_args , ) ) | Get a key from some input . | 68 | 7 |
247,784 | def cache ( ignore = None ) : def decorator ( func ) : # Initialize both cached versions joblib_cached = constants . joblib_memory . cache ( func , ignore = ignore ) db_cached = DbMemoizedFunc ( func , ignore ) @ functools . wraps ( func ) def wrapper ( * args , * * kwargs ) : """Dynamically choose the cache at call-ti... | Decorator for memoizing a function using either the filesystem or a database . | 184 | 16 |
247,785 | def get_output_key ( self , args , kwargs ) : # Get a dictionary mapping argument names to argument values where # ignored arguments are omitted. filtered_args = joblib . func_inspect . filter_args ( self . func , self . ignore , args , kwargs ) # Get a sorted tuple of the filtered argument. filtered_args = tuple ( sor... | Return the key that the output should be cached with given arguments keyword arguments and a list of arguments to ignore . | 109 | 22 |
247,786 | def load_output ( self , args , kwargs ) : return db . find ( self . get_output_key ( args , kwargs ) ) | Return cached output . | 34 | 4 |
247,787 | def cache_info ( self ) : return { 'single_node_repertoire' : self . _single_node_repertoire_cache . info ( ) , 'repertoire' : self . _repertoire_cache . info ( ) , 'mice' : self . _mice_cache . info ( ) } | Report repertoire cache statistics . | 77 | 5 |
247,788 | def clear_caches ( self ) : self . _single_node_repertoire_cache . clear ( ) self . _repertoire_cache . clear ( ) self . _mice_cache . clear ( ) | Clear the mice and repertoire caches . | 50 | 7 |
247,789 | def apply_cut ( self , cut ) : return Subsystem ( self . network , self . state , self . node_indices , cut = cut , mice_cache = self . _mice_cache ) | Return a cut version of this |Subsystem| . | 45 | 11 |
247,790 | def indices2nodes ( self , indices ) : if set ( indices ) - set ( self . node_indices ) : raise ValueError ( "`indices` must be a subset of the Subsystem's indices." ) return tuple ( self . _index2node [ n ] for n in indices ) | Return |Nodes| for these indices . | 65 | 9 |
247,791 | def cause_repertoire ( self , mechanism , purview ) : # If the purview is empty, the distribution is empty; return the # multiplicative identity. if not purview : return np . array ( [ 1.0 ] ) # If the mechanism is empty, nothing is specified about the previous # state of the purview; return the purview's maximum entro... | Return the cause repertoire of a mechanism over a purview . | 297 | 12 |
247,792 | def effect_repertoire ( self , mechanism , purview ) : # If the purview is empty, the distribution is empty, so return the # multiplicative identity. if not purview : return np . array ( [ 1.0 ] ) # Use a frozenset so the arguments to `_single_node_effect_repertoire` # can be hashed and cached. mechanism = frozenset ( ... | Return the effect repertoire of a mechanism over a purview . | 190 | 12 |
247,793 | def repertoire ( self , direction , mechanism , purview ) : if direction == Direction . CAUSE : return self . cause_repertoire ( mechanism , purview ) elif direction == Direction . EFFECT : return self . effect_repertoire ( mechanism , purview ) return validate . direction ( direction ) | Return the cause or effect repertoire based on a direction . | 67 | 11 |
247,794 | def partitioned_repertoire ( self , direction , partition ) : repertoires = [ self . repertoire ( direction , part . mechanism , part . purview ) for part in partition ] return functools . reduce ( np . multiply , repertoires ) | Compute the repertoire of a partitioned mechanism and purview . | 54 | 13 |
247,795 | def expand_repertoire ( self , direction , repertoire , new_purview = None ) : if repertoire is None : return None purview = distribution . purview ( repertoire ) if new_purview is None : new_purview = self . node_indices # full subsystem if not set ( purview ) . issubset ( new_purview ) : raise ValueError ( "Expanded ... | Distribute an effect repertoire over a larger purview . | 208 | 11 |
247,796 | def cause_info ( self , mechanism , purview ) : return repertoire_distance ( Direction . CAUSE , self . cause_repertoire ( mechanism , purview ) , self . unconstrained_cause_repertoire ( purview ) ) | Return the cause information for a mechanism over a purview . | 55 | 12 |
247,797 | def effect_info ( self , mechanism , purview ) : return repertoire_distance ( Direction . EFFECT , self . effect_repertoire ( mechanism , purview ) , self . unconstrained_effect_repertoire ( purview ) ) | Return the effect information for a mechanism over a purview . | 55 | 12 |
247,798 | def cause_effect_info ( self , mechanism , purview ) : return min ( self . cause_info ( mechanism , purview ) , self . effect_info ( mechanism , purview ) ) | Return the cause - effect information for a mechanism over a purview . | 42 | 14 |
247,799 | def evaluate_partition ( self , direction , mechanism , purview , partition , repertoire = None ) : if repertoire is None : repertoire = self . repertoire ( direction , mechanism , purview ) partitioned_repertoire = self . partitioned_repertoire ( direction , partition ) phi = repertoire_distance ( direction , repertoi... | Return the |small_phi| of a mechanism over a purview for the given partition . | 94 | 19 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.