Code
stringlengths
103
85.9k
Summary
listlengths
0
94
Please provide a description of the function: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 c...
[ "Set of all sets of elements that have true causes and true effects.\n\n .. note::\n Since the true |CauseEffectStructure| is always about the full system,\n the background conditions don't matter and the subsystem should be\n conditioned on the current state.\n " ]
Please provide a description of the function: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 = in...
[ "Return all mechanisms that have true causes and true effects within the\n complex.\n\n Args:\n network (Network): The network to analyze.\n previous_state (tuple[int]): The state of the network at ``t - 1``.\n current_state (tuple[int]): The state of the network at ``t``.\n next_s...
Please provide a description of the function: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: ...
[ "Set of all mechanisms that are in the major complex but which have true\n causes and effects within the entire network.\n\n Args:\n network (Network): The network to analyze.\n previous_state (tuple[int]): The state of the network at ``t - 1``.\n current_state (tuple[int]): The state of ...
Please provide a description of the function:def to_json(self): return { 'network': self.network, 'before_state': self.before_state, 'after_state': self.after_state, 'cause_indices': self.cause_indices, 'effect_indices': self.effect_indices, ...
[ "Return a JSON-serializable representation." ]
Please provide a description of the function: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." ]
Please provide a description of the function:def cause_repertoire(self, mechanism, purview): return self.repertoire(Direction.CAUSE, mechanism, purview)
[ "Return the cause repertoire." ]
Please provide a description of the function:def effect_repertoire(self, mechanism, purview): return self.repertoire(Direction.EFFECT, mechanism, purview)
[ "Return the effect repertoire." ]
Please provide a description of the function: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 {}'....
[ "Return the cause or effect repertoire function based on a direction.\n\n Args:\n direction (str): The temporal direction, specifiying the cause or\n effect repertoire.\n " ]
Please provide a description of the function: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 rep...
[ "Compute the probability of the purview in its current state given\n the repertoire.\n\n Collapses the dimensions of the repertoire that correspond to the\n purview nodes onto their state. All other dimension are already\n singular and thus receive 0 as the conditioning index.\n\n ...
Please provide a description of the function: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\n state of the mechanism.\n " ]
Please provide a description of the function: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\n ``direction``.\n\n For example, if we are computing the cause coefficient of a mechanism\n in ``after_state``, the direction is``CAUSE`` and the ``purview_state``\n is ``before_state``.\n " ]
Please provide a description of the function: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." ]
Please provide a description of the function: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." ]
Please provide a description of the function:def cause_ratio(self, mechanism, purview): return self._ratio(Direction.CAUSE, mechanism, purview)
[ "The cause ratio of the ``purview`` given ``mechanism``." ]
Please provide a description of the function:def effect_ratio(self, mechanism, purview): return self._ratio(Direction.EFFECT, mechanism, purview)
[ "The effect ratio of the ``purview`` given ``mechanism``." ]
Please provide a description of the function: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." ]
Please provide a description of the function: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\n the partition.\n " ]
Please provide a description of the function: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): par...
[ "Find the ratio minimum information partition for a mechanism\n over a purview.\n\n Args:\n direction (str): |CAUSE| or |EFFECT|\n mechanism (tuple[int]): A mechanism.\n purview (tuple[int]): A purview.\n\n Keyword Args:\n allow_neg (boolean): If true...
Please provide a description of the function:def potential_purviews(self, direction, mechanism, purviews=False): system = self.system[direction] return [ purview for purview in system.potential_purviews( direction, mechanism, purviews) if set(purview).iss...
[ "Return all purviews that could belong to the |MIC|/|MIE|.\n\n Filters out trivially-reducible purviews.\n\n Args:\n direction (str): Either |CAUSE| or |EFFECT|.\n mechanism (tuple[int]): The mechanism of interest.\n\n Keyword Args:\n purviews (tuple[int]): Opti...
Please provide a description of the function: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 purview...
[ "Return the maximally irreducible cause or effect ratio for a\n mechanism.\n\n Args:\n direction (str): The temporal direction, specifying cause or\n effect.\n mechanism (tuple[int]): The mechanism to be tested for\n irreducibility.\n\n Keywor...
Please provide a description of the function:def find_actual_cause(self, mechanism, purviews=False): return self.find_causal_link(Direction.CAUSE, mechanism, purviews)
[ "Return the actual cause of a mechanism." ]
Please provide a description of the function:def find_actual_effect(self, mechanism, purviews=False): return self.find_causal_link(Direction.EFFECT, mechanism, purviews)
[ "Return the actual effect of a mechanism." ]
Please provide a description of the function: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.\n\n If there is no value with the given key, returns ``None``.\n " ]
Please provide a description of the function: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 th...
[ "Store a value with a key.\n\n If the key is already present in the database, this does nothing.\n " ]
Please provide a description of the function: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.\n\n This function should be used whenever a key is needed, to keep keys\n consistent.\n " ]
Please provide a description of the function: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(*ar...
[ "Decorator for memoizing a function using either the filesystem or a\n database.\n ", "Dynamically choose the cache at call-time, not at import." ]
Please provide a description of the function: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) ...
[ "Return the key that the output should be cached with, given\n arguments, keyword arguments, and a list of arguments to ignore.\n " ]
Please provide a description of the function:def load_output(self, args, kwargs): return db.find(self.get_output_key(args, kwargs))
[ "Return cached output." ]
Please provide a description of the function:def nodes(self, value): # pylint: disable=attribute-defined-outside-init self._nodes = value self._index2node = {node.index: node for node in self._nodes}
[ "Remap indices to nodes whenever nodes are changed, e.g. in the\n `macro` module.\n " ]
Please provide a description of the function: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." ]
Please provide a description of the function:def clear_caches(self): self._single_node_repertoire_cache.clear() self._repertoire_cache.clear() self._mice_cache.clear()
[ "Clear the mice and repertoire caches." ]
Please provide a description of the function:def to_json(self): return { 'network': self.network, 'state': self.state, 'nodes': self.node_indices, 'cut': self.cut, }
[ "Return a JSON-serializable representation." ]
Please provide a description of the function: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|.\n\n Args:\n cut (Cut): The cut to apply to this |Subsystem|.\n\n Returns:\n Subsystem: The cut subsystem.\n " ]
Please provide a description of the function: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.\n\n Args:\n indices (tuple[int]): The indices in question.\n\n Returns:\n tuple[Node]: The |Node| objects corresponding to these indices.\n\n Raises:\n ValueError: If requested indices are not in the subsystem.\n " ]
Please provide a description of the function: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 spe...
[ "Return the cause repertoire of a mechanism over a purview.\n\n Args:\n mechanism (tuple[int]): The mechanism for which to calculate the\n cause repertoire.\n purview (tuple[int]): The purview over which to calculate the\n cause repertoire.\n\n Retur...
Please provide a description of the function: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 `...
[ "Return the effect repertoire of a mechanism over a purview.\n\n Args:\n mechanism (tuple[int]): The mechanism for which to calculate the\n effect repertoire.\n purview (tuple[int]): The purview over which to calculate the\n effect repertoire.\n\n Re...
Please provide a description of the function: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 the cause or effect repertoire based on a direction.\n\n Args:\n direction (Direction): |CAUSE| or |EFFECT|.\n mechanism (tuple[int]): The mechanism for which to calculate the\n repertoire.\n purview (tuple[int]): The purview over which to calculate the...
Please provide a description of the function: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." ]
Please provide a description of the function: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 subs...
[ "Distribute an effect repertoire over a larger purview.\n\n Args:\n direction (Direction): |CAUSE| or |EFFECT|.\n repertoire (np.ndarray): The repertoire to expand.\n\n Keyword Args:\n new_purview (tuple[int]): The new purview to expand the repertoire\n ...
Please provide a description of the function:def expand_cause_repertoire(self, repertoire, new_purview=None): return self.expand_repertoire(Direction.CAUSE, repertoire, new_purview)
[ "Alias for |expand_repertoire()| with ``direction`` set to |CAUSE|.\n " ]
Please provide a description of the function:def expand_effect_repertoire(self, repertoire, new_purview=None): return self.expand_repertoire(Direction.EFFECT, repertoire, new_purview)
[ "Alias for |expand_repertoire()| with ``direction`` set to |EFFECT|.\n " ]
Please provide a description of the function: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." ]
Please provide a description of the function: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." ]
Please provide a description of the function: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.\n\n This is the minimum of the cause and effect information.\n " ]
Please provide a description of the function:def evaluate_partition(self, direction, mechanism, purview, partition, repertoire=None): if repertoire is None: repertoire = self.repertoire(direction, mechanism, purview) partitioned_repertoire = self.partitio...
[ "Return the |small_phi| of a mechanism over a purview for the given\n partition.\n\n Args:\n direction (Direction): |CAUSE| or |EFFECT|.\n mechanism (tuple[int]): The nodes in the mechanism.\n purview (tuple[int]): The nodes in the purview.\n partition (Bipa...
Please provide a description of the function:def find_mip(self, direction, mechanism, purview): if not purview: return _null_ria(direction, mechanism, purview) # Calculate the unpartitioned repertoire to compare against the # partitioned ones. repertoire = self.repe...
[ "Return the minimum information partition for a mechanism over a\n purview.\n\n Args:\n direction (Direction): |CAUSE| or |EFFECT|.\n mechanism (tuple[int]): The nodes in the mechanism.\n purview (tuple[int]): The nodes in the purview.\n\n Returns:\n ...
Please provide a description of the function:def cause_mip(self, mechanism, purview): return self.find_mip(Direction.CAUSE, mechanism, purview)
[ "Return the irreducibility analysis for the cause MIP.\n\n Alias for |find_mip()| with ``direction`` set to |CAUSE|.\n " ]
Please provide a description of the function:def effect_mip(self, mechanism, purview): return self.find_mip(Direction.EFFECT, mechanism, purview)
[ "Return the irreducibility analysis for the effect MIP.\n\n Alias for |find_mip()| with ``direction`` set to |EFFECT|.\n " ]
Please provide a description of the function:def phi_cause_mip(self, mechanism, purview): mip = self.cause_mip(mechanism, purview) return mip.phi if mip else 0
[ "Return the |small_phi| of the cause MIP.\n\n This is the distance between the unpartitioned cause repertoire and the\n MIP cause repertoire.\n " ]
Please provide a description of the function:def phi_effect_mip(self, mechanism, purview): mip = self.effect_mip(mechanism, purview) return mip.phi if mip else 0
[ "Return the |small_phi| of the effect MIP.\n\n This is the distance between the unpartitioned effect repertoire and\n the MIP cause repertoire.\n " ]
Please provide a description of the function:def phi(self, mechanism, purview): return min(self.phi_cause_mip(mechanism, purview), self.phi_effect_mip(mechanism, purview))
[ "Return the |small_phi| of a mechanism over a purview." ]
Please provide a description of the function:def potential_purviews(self, direction, mechanism, purviews=False): if purviews is False: purviews = self.network.potential_purviews(direction, mechanism) # Filter out purviews that aren't in the subsystem purviews = [purv...
[ "Return all purviews that could belong to the |MIC|/|MIE|.\n\n Filters out trivially-reducible purviews.\n\n Args:\n direction (Direction): |CAUSE| or |EFFECT|.\n mechanism (tuple[int]): The mechanism of interest.\n\n Keyword Args:\n purviews (tuple[int]): Optio...
Please provide a description of the function:def find_mice(self, direction, mechanism, purviews=False): purviews = self.potential_purviews(direction, mechanism, purviews) if not purviews: max_mip = _null_ria(direction, mechanism, ()) else: max_mip = max(self.fin...
[ "Return the |MIC| or |MIE| for a mechanism.\n\n Args:\n direction (Direction): :|CAUSE| or |EFFECT|.\n mechanism (tuple[int]): The mechanism to be tested for\n irreducibility.\n\n Keyword Args:\n purviews (tuple[int]): Optionally restrict the possible pu...
Please provide a description of the function:def mic(self, mechanism, purviews=False): return self.find_mice(Direction.CAUSE, mechanism, purviews=purviews)
[ "Return the mechanism's maximally-irreducible cause (|MIC|).\n\n Alias for |find_mice()| with ``direction`` set to |CAUSE|.\n " ]
Please provide a description of the function:def mie(self, mechanism, purviews=False): return self.find_mice(Direction.EFFECT, mechanism, purviews=purviews)
[ "Return the mechanism's maximally-irreducible effect (|MIE|).\n\n Alias for |find_mice()| with ``direction`` set to |EFFECT|.\n " ]
Please provide a description of the function:def phi_max(self, mechanism): return min(self.mic(mechanism).phi, self.mie(mechanism).phi)
[ "Return the |small_phi_max| of a mechanism.\n\n This is the maximum of |small_phi| taken over all possible purviews.\n " ]
Please provide a description of the function:def null_concept(self): # Unconstrained cause repertoire. cause_repertoire = self.cause_repertoire((), ()) # Unconstrained effect repertoire. effect_repertoire = self.effect_repertoire((), ()) # Null cause. cause = Ma...
[ "Return the null concept of this subsystem.\n\n The null concept is a point in concept space identified with\n the unconstrained cause and effect repertoire of this subsystem.\n " ]
Please provide a description of the function:def concept(self, mechanism, purviews=False, cause_purviews=False, effect_purviews=False): log.debug('Computing concept %s...', mechanism) # If the mechanism is empty, there is no concept. if not mechanism: log.de...
[ "Return the concept specified by a mechanism within this subsytem.\n\n Args:\n mechanism (tuple[int]): The candidate set of nodes.\n\n Keyword Args:\n purviews (tuple[tuple[int]]): Restrict the possible purviews to\n those in this list.\n cause_purviews ...
Please provide a description of the function:def _null_ac_sia(transition, direction, alpha=0.0): return AcSystemIrreducibilityAnalysis( transition=transition, direction=direction, alpha=alpha, account=(), partitioned_account=() )
[ "Return an |AcSystemIrreducibilityAnalysis| with zero |big_alpha| and\n empty accounts.\n " ]
Please provide a description of the function:def mechanism(self): assert self.actual_cause.mechanism == self.actual_effect.mechanism return self.actual_cause.mechanism
[ "The mechanism of the event." ]
Please provide a description of the function:def irreducible_causes(self): return tuple(link for link in self if link.direction is Direction.CAUSE)
[ "The set of irreducible causes in this |Account|." ]
Please provide a description of the function:def irreducible_effects(self): return tuple(link for link in self if link.direction is Direction.EFFECT)
[ "The set of irreducible effects in this |Account|." ]
Please provide a description of the function:def make_repr(self, attrs): # TODO: change this to a closure so we can do # __repr__ = make_repr(attrs) ??? if config.REPR_VERBOSITY in [MEDIUM, HIGH]: return self.__str__() elif config.REPR_VERBOSITY is LOW: return '{}({})'.format( ...
[ "Construct a repr string.\n\n If `config.REPR_VERBOSITY` is ``1`` or ``2``, this function calls the\n object's __str__ method. Although this breaks the convention that __repr__\n should return a string which can reconstruct the object, readable reprs are\n invaluable since the Python interpreter calls `...
Please provide a description of the function:def indent(lines, amount=2, char=' '): r lines = str(lines) padding = amount * char return padding + ('\n' + padding).join(lines.split('\n'))
[ "Indent a string.\n\n Prepends whitespace to every line in the passed string. (Lines are\n separated by newline characters.)\n\n Args:\n lines (str): The string to indent.\n\n Keyword Args:\n amount (int): The number of columns to indent by.\n char (str): The character to to use as ...
Please provide a description of the function:def margin(text): r lines = str(text).split('\n') return '\n'.join(' {} '.format(l) for l in lines)
[ "Add a margin to both ends of each line in the string.\n\n Example:\n >>> margin('line1\\nline2')\n ' line1 \\n line2 '\n " ]
Please provide a description of the function:def box(text): r lines = text.split('\n') width = max(len(l) for l in lines) top_bar = (TOP_LEFT_CORNER + HORIZONTAL_BAR * (2 + width) + TOP_RIGHT_CORNER) bottom_bar = (BOTTOM_LEFT_CORNER + HORIZONTAL_BAR * (2 + width) + ...
[ "Wrap a chunk of text in a box.\n\n Example:\n >>> print(box('line1\\nline2'))\n ┌───────┐\n │ line1 │\n │ line2 │\n └───────┘\n " ]
Please provide a description of the function:def side_by_side(left, right): r left_lines = list(left.split('\n')) right_lines = list(right.split('\n')) # Pad the shorter column with whitespace diff = abs(len(left_lines) - len(right_lines)) if len(left_lines) > len(right_lines): fill = '...
[ "Put two boxes next to each other.\n\n Assumes that all lines in the boxes are the same width.\n\n Example:\n >>> left = 'A \\nC '\n >>> right = 'B\\nD'\n >>> print(side_by_side(left, right))\n A B\n C D\n <BLANKLINE>\n " ]
Please provide a description of the function:def header(head, text, over_char=None, under_char=None, center=True): lines = list(text.split('\n')) width = max(len(l) for l in lines) # Center or left-justify if center: head = head.center(width) + '\n' else: head = head.ljust(widt...
[ "Center a head over a block of text.\n\n The width of the text is the width of the longest line of the text.\n " ]
Please provide a description of the function:def labels(indices, node_labels=None): if node_labels is None: return tuple(map(str, indices)) return node_labels.indices2labels(indices)
[ "Get the labels for a tuple of mechanism indices." ]
Please provide a description of the function:def fmt_number(p): formatted = '{:n}'.format(p) if not config.PRINT_FRACTIONS: return formatted fraction = Fraction(p) nice = fraction.limit_denominator(128) return ( str(nice) if (abs(fraction - nice) < constants.EPSILON and ...
[ "Format a number.\n\n It will be printed as a fraction if the denominator isn't too big and as a\n decimal otherwise.\n " ]
Please provide a description of the function:def fmt_part(part, node_labels=None): def nodes(x): # pylint: disable=missing-docstring return ','.join(labels(x, node_labels)) if x else EMPTY_SET numer = nodes(part.mechanism) denom = nodes(part.purview) width = max(3, len(numer), len(denom)...
[ "Format a |Part|.\n\n The returned string looks like::\n\n 0,1\n ───\n ∅\n " ]
Please provide a description of the function:def fmt_partition(partition): if not partition: return '' parts = [fmt_part(part, partition.node_labels).split('\n') for part in partition] times = (' ', ' {} '.format(MULTIPLY), ' ') breaks = ('\n', '...
[ "Format a |Bipartition|.\n\n The returned string looks like::\n\n 0,1 ∅\n ─── ✕ ───\n 2 0,1\n\n Args:\n partition (Bipartition): The partition in question.\n\n Returns:\n str: A human-readable string representation of the partition.\n " ]
Please provide a description of the function:def fmt_ces(c, title=None): if not c: return '()\n' if title is None: title = 'Cause-effect structure' concepts = '\n'.join(margin(x) for x in c) + '\n' title = '{} ({} concept{})'.format( title, len(c), '' if len(c) == 1 else '...
[ "Format a |CauseEffectStructure|." ]
Please provide a description of the function:def fmt_concept(concept): def fmt_cause_or_effect(x): # pylint: disable=missing-docstring return box(indent(fmt_ria(x.ria, verbose=False, mip=True), amount=1)) cause = header('MIC', fmt_cause_or_effect(concept.cause)) effect = header('MIE', fmt_ca...
[ "Format a |Concept|." ]
Please provide a description of the function:def fmt_ria(ria, verbose=True, mip=False): if verbose: mechanism = 'Mechanism: {}\n'.format( fmt_mechanism(ria.mechanism, ria.node_labels)) direction = '\nDirection: {}'.format(ria.direction) else: mechanism = '' direc...
[ "Format a |RepertoireIrreducibilityAnalysis|." ]
Please provide a description of the function:def fmt_cut(cut): return 'Cut {from_nodes} {symbol} {to_nodes}'.format( from_nodes=fmt_mechanism(cut.from_nodes, cut.node_labels), symbol=CUT_SYMBOL, to_nodes=fmt_mechanism(cut.to_nodes, cut.node_labels))
[ "Format a |Cut|." ]
Please provide a description of the function:def fmt_sia(sia, ces=True): if ces: body = ( '{ces}' '{partitioned_ces}'.format( ces=fmt_ces( sia.ces, 'Cause-effect structure'), partitioned_ces=fmt_ces( ...
[ "Format a |SystemIrreducibilityAnalysis|." ]
Please provide a description of the function:def fmt_repertoire(r): # TODO: will this get unwieldy with large repertoires? if r is None: return '' r = r.squeeze() lines = [] # Header: 'S P(S)' space = ' ' * 4 head = '{S:^{s_width}}{space}Pr({S})'.format( S='S', s...
[ "Format a repertoire." ]
Please provide a description of the function:def fmt_ac_ria(ria): causality = { Direction.CAUSE: (fmt_mechanism(ria.purview, ria.node_labels), ARROW_LEFT, fmt_mechanism(ria.mechanism, ria.node_labels)), Direction.EFFECT: (fmt_mechanism(ria.mec...
[ "Format an AcRepertoireIrreducibilityAnalysis." ]
Please provide a description of the function:def fmt_account(account, title=None): if title is None: title = account.__class__.__name__ # `Account` or `DirectedAccount` title = '{} ({} causal link{})'.format( title, len(account), '' if len(account) == 1 else 's') body = '' body +...
[ "Format an Account or a DirectedAccount." ]
Please provide a description of the function:def fmt_ac_sia(ac_sia): body = ( '{ALPHA} = {alpha}\n' 'direction: {ac_sia.direction}\n' 'transition: {ac_sia.transition}\n' 'before state: {ac_sia.before_state}\n' 'after state: {ac_sia.after_state}\n' 'cut:\n{ac_sia....
[ "Format a AcSystemIrreducibilityAnalysis." ]
Please provide a description of the function:def fmt_transition(t): return "Transition({} {} {})".format( fmt_mechanism(t.cause_indices, t.node_labels), ARROW_RIGHT, fmt_mechanism(t.effect_indices, t.node_labels))
[ "Format a |Transition|." ]
Please provide a description of the function:def direction(direction, allow_bi=False): valid = [Direction.CAUSE, Direction.EFFECT] if allow_bi: valid.append(Direction.BIDIRECTIONAL) if direction not in valid: raise ValueError('`direction` must be one of {}'.format(valid)) return T...
[ "Validate that the given direction is one of the allowed constants.\n\n If ``allow_bi`` is ``True`` then ``Direction.BIDIRECTIONAL`` is\n acceptable.\n " ]
Please provide a description of the function:def tpm(tpm, check_independence=True): see_tpm_docs = ( 'See the documentation on TPM conventions and the `pyphi.Network` ' 'object for more information on TPM forms.' ) # Cast to np.array. tpm = np.array(tpm) # Get the number of node...
[ "Validate a TPM.\n\n The TPM can be in\n\n * 2-dimensional state-by-state form,\n * 2-dimensional state-by-node form, or\n * multidimensional state-by-node form.\n " ]
Please provide a description of the function:def conditionally_independent(tpm): if not config.VALIDATE_CONDITIONAL_INDEPENDENCE: return True tpm = np.array(tpm) if is_state_by_state(tpm): there_and_back_again = convert.state_by_node2state_by_state( convert.state_by_state2st...
[ "Validate that the TPM is conditionally independent." ]
Please provide a description of the function:def connectivity_matrix(cm): # Special case for empty matrices. if cm.size == 0: return True if cm.ndim != 2: raise ValueError("Connectivity matrix must be 2-dimensional.") if cm.shape[0] != cm.shape[1]: raise ValueError("Connecti...
[ "Validate the given connectivity matrix." ]
Please provide a description of the function:def node_labels(node_labels, node_indices): if len(node_labels) != len(node_indices): raise ValueError("Labels {0} must label every node {1}.".format( node_labels, node_indices)) if len(node_labels) != len(set(node_labels)): raise Va...
[ "Validate that there is a label for each node." ]
Please provide a description of the function:def network(n): tpm(n.tpm) connectivity_matrix(n.cm) if n.cm.shape[0] != n.size: raise ValueError("Connectivity matrix must be NxN, where N is the " "number of nodes in the network.") return True
[ "Validate a |Network|.\n\n Checks the TPM and connectivity matrix.\n " ]
Please provide a description of the function:def state_length(state, size): if len(state) != size: raise ValueError('Invalid state: there must be one entry per ' 'node in the network; this state has {} entries, but ' 'there are {} nodes.'.format(len(sta...
[ "Check that the state is the given size." ]
Please provide a description of the function:def state_reachable(subsystem): # If there is a row `r` in the TPM such that all entries of `r - state` are # between -1 and 1, then the given state has a nonzero probability of being # reached from some state. # First we take the submatrix of the condit...
[ "Return whether a state can be reached according to the network's TPM." ]
Please provide a description of the function:def cut(cut, node_indices): if cut.indices != node_indices: raise ValueError('{} nodes are not equal to subsystem nodes ' '{}'.format(cut, node_indices))
[ "Check that the cut is for only the given nodes." ]
Please provide a description of the function:def subsystem(s): node_states(s.state) cut(s.cut, s.cut_indices) if config.VALIDATE_SUBSYSTEM_STATES: state_reachable(s) return True
[ "Validate a |Subsystem|.\n\n Checks its state and cut.\n " ]
Please provide a description of the function:def partition(partition): nodes = set() for part in partition: for node in part: if node in nodes: raise ValueError( 'Micro-element {} may not be partitioned into multiple ' 'macro-eleme...
[ "Validate a partition - used by blackboxes and coarse grains." ]
Please provide a description of the function:def coarse_grain(coarse_grain): partition(coarse_grain.partition) if len(coarse_grain.partition) != len(coarse_grain.grouping): raise ValueError('output and state groupings must be the same size') for part, group in zip(coarse_grain.partition, coar...
[ "Validate a macro coarse-graining." ]
Please provide a description of the function:def blackbox(blackbox): if tuple(sorted(blackbox.output_indices)) != blackbox.output_indices: raise ValueError('Output indices {} must be ordered'.format( blackbox.output_indices)) partition(blackbox.partition) for part in blackbox.part...
[ "Validate a macro blackboxing." ]
Please provide a description of the function:def blackbox_and_coarse_grain(blackbox, coarse_grain): if blackbox is None: return for box in blackbox.partition: # Outputs of the box outputs = set(box) & set(blackbox.output_indices) if coarse_grain is None and len(outputs) > ...
[ "Validate that a coarse-graining properly combines the outputs of a\n blackboxing.\n " ]
Please provide a description of the function:def register(self, name): def register_func(func): self.store[name] = func return func return register_func
[ "Decorator for registering a function with PyPhi.\n\n Args:\n name (string): The name of the function\n " ]
Please provide a description of the function:def ces(subsystem, mechanisms=False, purviews=False, cause_purviews=False, effect_purviews=False, parallel=False): if mechanisms is False: mechanisms = utils.powerset(subsystem.node_indices, nonempty=True) engine = ComputeCauseEffectStructure(me...
[ "Return the conceptual structure of this subsystem, optionally restricted\n to concepts with the mechanisms and purviews given in keyword arguments.\n\n If you don't need the full |CauseEffectStructure|, restricting the possible\n mechanisms and purviews can make this function much faster.\n\n Args:\n ...
Please provide a description of the function:def conceptual_info(subsystem): ci = ces_distance(ces(subsystem), CauseEffectStructure((), subsystem=subsystem)) return round(ci, config.PRECISION)
[ "Return the conceptual information for a |Subsystem|.\n\n This is the distance from the subsystem's |CauseEffectStructure| to the\n null concept.\n " ]
Please provide a description of the function:def evaluate_cut(uncut_subsystem, cut, unpartitioned_ces): log.debug('Evaluating %s...', cut) cut_subsystem = uncut_subsystem.apply_cut(cut) if config.ASSUME_CUTS_CANNOT_CREATE_NEW_CONCEPTS: mechanisms = unpartitioned_ces.mechanisms else: ...
[ "Compute the system irreducibility for a given cut.\n\n Args:\n uncut_subsystem (Subsystem): The subsystem without the cut applied.\n cut (Cut): The cut to evaluate.\n unpartitioned_ces (CauseEffectStructure): The cause-effect structure of\n the uncut subsystem.\n\n Returns:\n ...