repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
wmayner/pyphi | pyphi/subsystem.py | Subsystem.effect_mip | def effect_mip(self, mechanism, purview):
"""Return the irreducibility analysis for the effect MIP.
Alias for |find_mip()| with ``direction`` set to |EFFECT|.
"""
return self.find_mip(Direction.EFFECT, mechanism, purview) | python | def effect_mip(self, mechanism, purview):
"""Return the irreducibility analysis for the effect MIP.
Alias for |find_mip()| with ``direction`` set to |EFFECT|.
"""
return self.find_mip(Direction.EFFECT, mechanism, purview) | [
"def",
"effect_mip",
"(",
"self",
",",
"mechanism",
",",
"purview",
")",
":",
"return",
"self",
".",
"find_mip",
"(",
"Direction",
".",
"EFFECT",
",",
"mechanism",
",",
"purview",
")"
] | Return the irreducibility analysis for the effect MIP.
Alias for |find_mip()| with ``direction`` set to |EFFECT|. | [
"Return",
"the",
"irreducibility",
"analysis",
"for",
"the",
"effect",
"MIP",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/subsystem.py#L607-L612 | train |
wmayner/pyphi | pyphi/subsystem.py | Subsystem.phi_cause_mip | def phi_cause_mip(self, mechanism, purview):
"""Return the |small_phi| of the cause MIP.
This is the distance between the unpartitioned cause repertoire and the
MIP cause repertoire.
"""
mip = self.cause_mip(mechanism, purview)
return mip.phi if mip else 0 | python | def phi_cause_mip(self, mechanism, purview):
"""Return the |small_phi| of the cause MIP.
This is the distance between the unpartitioned cause repertoire and the
MIP cause repertoire.
"""
mip = self.cause_mip(mechanism, purview)
return mip.phi if mip else 0 | [
"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.
This is the distance between the unpartitioned cause repertoire and the
MIP cause repertoire. | [
"Return",
"the",
"|small_phi|",
"of",
"the",
"cause",
"MIP",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/subsystem.py#L614-L621 | train |
wmayner/pyphi | pyphi/subsystem.py | Subsystem.phi_effect_mip | def phi_effect_mip(self, mechanism, purview):
"""Return the |small_phi| of the effect MIP.
This is the distance between the unpartitioned effect repertoire and
the MIP cause repertoire.
"""
mip = self.effect_mip(mechanism, purview)
return mip.phi if mip else 0 | python | def phi_effect_mip(self, mechanism, purview):
"""Return the |small_phi| of the effect MIP.
This is the distance between the unpartitioned effect repertoire and
the MIP cause repertoire.
"""
mip = self.effect_mip(mechanism, purview)
return mip.phi if mip else 0 | [
"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.
This is the distance between the unpartitioned effect repertoire and
the MIP cause repertoire. | [
"Return",
"the",
"|small_phi|",
"of",
"the",
"effect",
"MIP",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/subsystem.py#L623-L630 | train |
wmayner/pyphi | pyphi/subsystem.py | Subsystem.phi | def phi(self, mechanism, purview):
"""Return the |small_phi| of a mechanism over a purview."""
return min(self.phi_cause_mip(mechanism, purview),
self.phi_effect_mip(mechanism, purview)) | python | def phi(self, mechanism, purview):
"""Return the |small_phi| of a mechanism over a purview."""
return min(self.phi_cause_mip(mechanism, purview),
self.phi_effect_mip(mechanism, purview)) | [
"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. | [
"Return",
"the",
"|small_phi|",
"of",
"a",
"mechanism",
"over",
"a",
"purview",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/subsystem.py#L632-L635 | train |
wmayner/pyphi | pyphi/subsystem.py | Subsystem.find_mice | def find_mice(self, direction, mechanism, purviews=False):
"""Return the |MIC| or |MIE| for a mechanism.
Args:
direction (Direction): :|CAUSE| or |EFFECT|.
mechanism (tuple[int]): The mechanism to be tested for
irreducibility.
Keyword Args:
p... | python | def find_mice(self, direction, mechanism, purviews=False):
"""Return the |MIC| or |MIE| for a mechanism.
Args:
direction (Direction): :|CAUSE| or |EFFECT|.
mechanism (tuple[int]): The mechanism to be tested for
irreducibility.
Keyword Args:
p... | [
"def",
"find_mice",
"(",
"self",
",",
"direction",
",",
"mechanism",
",",
"purviews",
"=",
"False",
")",
":",
"purviews",
"=",
"self",
".",
"potential_purviews",
"(",
"direction",
",",
"mechanism",
",",
"purviews",
")",
"if",
"not",
"purviews",
":",
"max_m... | Return the |MIC| or |MIE| for a mechanism.
Args:
direction (Direction): :|CAUSE| or |EFFECT|.
mechanism (tuple[int]): The mechanism to be tested for
irreducibility.
Keyword Args:
purviews (tuple[int]): Optionally restrict the possible purviews
... | [
"Return",
"the",
"|MIC|",
"or",
"|MIE|",
"for",
"a",
"mechanism",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/subsystem.py#L664-L693 | train |
wmayner/pyphi | pyphi/subsystem.py | Subsystem.phi_max | def phi_max(self, mechanism):
"""Return the |small_phi_max| of a mechanism.
This is the maximum of |small_phi| taken over all possible purviews.
"""
return min(self.mic(mechanism).phi, self.mie(mechanism).phi) | python | def phi_max(self, mechanism):
"""Return the |small_phi_max| of a mechanism.
This is the maximum of |small_phi| taken over all possible purviews.
"""
return min(self.mic(mechanism).phi, self.mie(mechanism).phi) | [
"def",
"phi_max",
"(",
"self",
",",
"mechanism",
")",
":",
"return",
"min",
"(",
"self",
".",
"mic",
"(",
"mechanism",
")",
".",
"phi",
",",
"self",
".",
"mie",
"(",
"mechanism",
")",
".",
"phi",
")"
] | Return the |small_phi_max| of a mechanism.
This is the maximum of |small_phi| taken over all possible purviews. | [
"Return",
"the",
"|small_phi_max|",
"of",
"a",
"mechanism",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/subsystem.py#L709-L714 | train |
wmayner/pyphi | pyphi/subsystem.py | Subsystem.null_concept | def null_concept(self):
"""Return the null concept of this subsystem.
The null concept is a point in concept space identified with
the unconstrained cause and effect repertoire of this subsystem.
"""
# Unconstrained cause repertoire.
cause_repertoire = self.cause_reperto... | python | def null_concept(self):
"""Return the null concept of this subsystem.
The null concept is a point in concept space identified with
the unconstrained cause and effect repertoire of this subsystem.
"""
# Unconstrained cause repertoire.
cause_repertoire = self.cause_reperto... | [
"def",
"null_concept",
"(",
"self",
")",
":",
"# Unconstrained cause repertoire.",
"cause_repertoire",
"=",
"self",
".",
"cause_repertoire",
"(",
"(",
")",
",",
"(",
")",
")",
"# Unconstrained effect repertoire.",
"effect_repertoire",
"=",
"self",
".",
"effect_reperto... | Return the null concept of this subsystem.
The null concept is a point in concept space identified with
the unconstrained cause and effect repertoire of this subsystem. | [
"Return",
"the",
"null",
"concept",
"of",
"this",
"subsystem",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/subsystem.py#L720-L742 | train |
wmayner/pyphi | pyphi/subsystem.py | Subsystem.concept | def concept(self, mechanism, purviews=False, cause_purviews=False,
effect_purviews=False):
"""Return the concept specified by a mechanism within this subsytem.
Args:
mechanism (tuple[int]): The candidate set of nodes.
Keyword Args:
purviews (tuple[tuple[... | python | def concept(self, mechanism, purviews=False, cause_purviews=False,
effect_purviews=False):
"""Return the concept specified by a mechanism within this subsytem.
Args:
mechanism (tuple[int]): The candidate set of nodes.
Keyword Args:
purviews (tuple[tuple[... | [
"def",
"concept",
"(",
"self",
",",
"mechanism",
",",
"purviews",
"=",
"False",
",",
"cause_purviews",
"=",
"False",
",",
"effect_purviews",
"=",
"False",
")",
":",
"log",
".",
"debug",
"(",
"'Computing concept %s...'",
",",
"mechanism",
")",
"# If the mechani... | Return the concept specified by a mechanism within this subsytem.
Args:
mechanism (tuple[int]): The candidate set of nodes.
Keyword Args:
purviews (tuple[tuple[int]]): Restrict the possible purviews to
those in this list.
cause_purviews (tuple[tuple[... | [
"Return",
"the",
"concept",
"specified",
"by",
"a",
"mechanism",
"within",
"this",
"subsytem",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/subsystem.py#L745-L785 | train |
wmayner/pyphi | pyphi/models/actual_causation.py | _null_ac_sia | def _null_ac_sia(transition, direction, alpha=0.0):
"""Return an |AcSystemIrreducibilityAnalysis| with zero |big_alpha| and
empty accounts.
"""
return AcSystemIrreducibilityAnalysis(
transition=transition,
direction=direction,
alpha=alpha,
account=(),
partitioned_... | python | def _null_ac_sia(transition, direction, alpha=0.0):
"""Return an |AcSystemIrreducibilityAnalysis| with zero |big_alpha| and
empty accounts.
"""
return AcSystemIrreducibilityAnalysis(
transition=transition,
direction=direction,
alpha=alpha,
account=(),
partitioned_... | [
"def",
"_null_ac_sia",
"(",
"transition",
",",
"direction",
",",
"alpha",
"=",
"0.0",
")",
":",
"return",
"AcSystemIrreducibilityAnalysis",
"(",
"transition",
"=",
"transition",
",",
"direction",
"=",
"direction",
",",
"alpha",
"=",
"alpha",
",",
"account",
"=... | Return an |AcSystemIrreducibilityAnalysis| with zero |big_alpha| and
empty accounts. | [
"Return",
"an",
"|AcSystemIrreducibilityAnalysis|",
"with",
"zero",
"|big_alpha|",
"and",
"empty",
"accounts",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/actual_causation.py#L354-L364 | train |
wmayner/pyphi | pyphi/models/actual_causation.py | Event.mechanism | def mechanism(self):
"""The mechanism of the event."""
assert self.actual_cause.mechanism == self.actual_effect.mechanism
return self.actual_cause.mechanism | python | def mechanism(self):
"""The mechanism of the event."""
assert self.actual_cause.mechanism == self.actual_effect.mechanism
return self.actual_cause.mechanism | [
"def",
"mechanism",
"(",
"self",
")",
":",
"assert",
"self",
".",
"actual_cause",
".",
"mechanism",
"==",
"self",
".",
"actual_effect",
".",
"mechanism",
"return",
"self",
".",
"actual_cause",
".",
"mechanism"
] | The mechanism of the event. | [
"The",
"mechanism",
"of",
"the",
"event",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/actual_causation.py#L213-L216 | train |
wmayner/pyphi | pyphi/models/actual_causation.py | Account.irreducible_causes | def irreducible_causes(self):
"""The set of irreducible causes in this |Account|."""
return tuple(link for link in self
if link.direction is Direction.CAUSE) | python | def irreducible_causes(self):
"""The set of irreducible causes in this |Account|."""
return tuple(link for link in self
if link.direction is Direction.CAUSE) | [
"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|. | [
"The",
"set",
"of",
"irreducible",
"causes",
"in",
"this",
"|Account|",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/actual_causation.py#L248-L251 | train |
wmayner/pyphi | pyphi/models/actual_causation.py | Account.irreducible_effects | def irreducible_effects(self):
"""The set of irreducible effects in this |Account|."""
return tuple(link for link in self
if link.direction is Direction.EFFECT) | python | def irreducible_effects(self):
"""The set of irreducible effects in this |Account|."""
return tuple(link for link in self
if link.direction is Direction.EFFECT) | [
"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|. | [
"The",
"set",
"of",
"irreducible",
"effects",
"in",
"this",
"|Account|",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/actual_causation.py#L254-L257 | train |
wmayner/pyphi | pyphi/models/fmt.py | make_repr | def make_repr(self, attrs):
"""Construct a repr string.
If `config.REPR_VERBOSITY` is ``1`` or ``2``, this function calls the
object's __str__ method. Although this breaks the convention that __repr__
should return a string which can reconstruct the object, readable reprs are
invaluable since the P... | python | def make_repr(self, attrs):
"""Construct a repr string.
If `config.REPR_VERBOSITY` is ``1`` or ``2``, this function calls the
object's __str__ method. Although this breaks the convention that __repr__
should return a string which can reconstruct the object, readable reprs are
invaluable since the P... | [
"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__",
"(",
... | Construct a repr string.
If `config.REPR_VERBOSITY` is ``1`` or ``2``, this function calls the
object's __str__ method. Although this breaks the convention that __repr__
should return a string which can reconstruct the object, readable reprs are
invaluable since the Python interpreter calls `repr` to r... | [
"Construct",
"a",
"repr",
"string",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L47-L76 | train |
wmayner/pyphi | pyphi/models/fmt.py | indent | def indent(lines, amount=2, char=' '):
r"""Indent a string.
Prepends whitespace to every line in the passed string. (Lines are
separated by newline characters.)
Args:
lines (str): The string to indent.
Keyword Args:
amount (int): The number of columns to indent by.
char (s... | python | def indent(lines, amount=2, char=' '):
r"""Indent a string.
Prepends whitespace to every line in the passed string. (Lines are
separated by newline characters.)
Args:
lines (str): The string to indent.
Keyword Args:
amount (int): The number of columns to indent by.
char (s... | [
"def",
"indent",
"(",
"lines",
",",
"amount",
"=",
"2",
",",
"char",
"=",
"' '",
")",
":",
"lines",
"=",
"str",
"(",
"lines",
")",
"padding",
"=",
"amount",
"*",
"char",
"return",
"padding",
"+",
"(",
"'\\n'",
"+",
"padding",
")",
".",
"join",
"(... | r"""Indent a string.
Prepends whitespace to every line in the passed string. (Lines are
separated by newline characters.)
Args:
lines (str): The string to indent.
Keyword Args:
amount (int): The number of columns to indent by.
char (str): The character to to use as the indenta... | [
"r",
"Indent",
"a",
"string",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L79-L102 | train |
wmayner/pyphi | pyphi/models/fmt.py | margin | def margin(text):
r"""Add a margin to both ends of each line in the string.
Example:
>>> margin('line1\nline2')
' line1 \n line2 '
"""
lines = str(text).split('\n')
return '\n'.join(' {} '.format(l) for l in lines) | python | def margin(text):
r"""Add a margin to both ends of each line in the string.
Example:
>>> margin('line1\nline2')
' line1 \n line2 '
"""
lines = str(text).split('\n')
return '\n'.join(' {} '.format(l) for l in lines) | [
"def",
"margin",
"(",
"text",
")",
":",
"lines",
"=",
"str",
"(",
"text",
")",
".",
"split",
"(",
"'\\n'",
")",
"return",
"'\\n'",
".",
"join",
"(",
"' {} '",
".",
"format",
"(",
"l",
")",
"for",
"l",
"in",
"lines",
")"
] | r"""Add a margin to both ends of each line in the string.
Example:
>>> margin('line1\nline2')
' line1 \n line2 ' | [
"r",
"Add",
"a",
"margin",
"to",
"both",
"ends",
"of",
"each",
"line",
"in",
"the",
"string",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L105-L113 | train |
wmayner/pyphi | pyphi/models/fmt.py | box | def box(text):
r"""Wrap a chunk of text in a box.
Example:
>>> print(box('line1\nline2'))
┌───────┐
│ line1 │
│ line2 │
└───────┘
"""
lines = text.split('\n')
width = max(len(l) for l in lines)
top_bar = (TOP_LEFT_CORNER + HORIZONTAL_BAR * (2 + width) +
... | python | def box(text):
r"""Wrap a chunk of text in a box.
Example:
>>> print(box('line1\nline2'))
┌───────┐
│ line1 │
│ line2 │
└───────┘
"""
lines = text.split('\n')
width = max(len(l) for l in lines)
top_bar = (TOP_LEFT_CORNER + HORIZONTAL_BAR * (2 + width) +
... | [
"def",
"box",
"(",
"text",
")",
":",
"lines",
"=",
"text",
".",
"split",
"(",
"'\\n'",
")",
"width",
"=",
"max",
"(",
"len",
"(",
"l",
")",
"for",
"l",
"in",
"lines",
")",
"top_bar",
"=",
"(",
"TOP_LEFT_CORNER",
"+",
"HORIZONTAL_BAR",
"*",
"(",
"... | r"""Wrap a chunk of text in a box.
Example:
>>> print(box('line1\nline2'))
┌───────┐
│ line1 │
│ line2 │
└───────┘ | [
"r",
"Wrap",
"a",
"chunk",
"of",
"text",
"in",
"a",
"box",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L119-L139 | train |
wmayner/pyphi | pyphi/models/fmt.py | side_by_side | def side_by_side(left, right):
r"""Put two boxes next to each other.
Assumes that all lines in the boxes are the same width.
Example:
>>> left = 'A \nC '
>>> right = 'B\nD'
>>> print(side_by_side(left, right))
A B
C D
<BLANKLINE>
"""
left_lines = lis... | python | def side_by_side(left, right):
r"""Put two boxes next to each other.
Assumes that all lines in the boxes are the same width.
Example:
>>> left = 'A \nC '
>>> right = 'B\nD'
>>> print(side_by_side(left, right))
A B
C D
<BLANKLINE>
"""
left_lines = lis... | [
"def",
"side_by_side",
"(",
"left",
",",
"right",
")",
":",
"left_lines",
"=",
"list",
"(",
"left",
".",
"split",
"(",
"'\\n'",
")",
")",
"right_lines",
"=",
"list",
"(",
"right",
".",
"split",
"(",
"'\\n'",
")",
")",
"# Pad the shorter column with whitesp... | r"""Put two boxes next to each other.
Assumes that all lines in the boxes are the same width.
Example:
>>> left = 'A \nC '
>>> right = 'B\nD'
>>> print(side_by_side(left, right))
A B
C D
<BLANKLINE> | [
"r",
"Put",
"two",
"boxes",
"next",
"to",
"each",
"other",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L142-L167 | train |
wmayner/pyphi | pyphi/models/fmt.py | header | def header(head, text, over_char=None, under_char=None, center=True):
"""Center a head over a block of text.
The width of the text is the width of the longest line of the text.
"""
lines = list(text.split('\n'))
width = max(len(l) for l in lines)
# Center or left-justify
if center:
... | python | def header(head, text, over_char=None, under_char=None, center=True):
"""Center a head over a block of text.
The width of the text is the width of the longest line of the text.
"""
lines = list(text.split('\n'))
width = max(len(l) for l in lines)
# Center or left-justify
if center:
... | [
"def",
"header",
"(",
"head",
",",
"text",
",",
"over_char",
"=",
"None",
",",
"under_char",
"=",
"None",
",",
"center",
"=",
"True",
")",
":",
"lines",
"=",
"list",
"(",
"text",
".",
"split",
"(",
"'\\n'",
")",
")",
"width",
"=",
"max",
"(",
"le... | Center a head over a block of text.
The width of the text is the width of the longest line of the text. | [
"Center",
"a",
"head",
"over",
"a",
"block",
"of",
"text",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L170-L192 | train |
wmayner/pyphi | pyphi/models/fmt.py | labels | def labels(indices, node_labels=None):
"""Get the labels for a tuple of mechanism indices."""
if node_labels is None:
return tuple(map(str, indices))
return node_labels.indices2labels(indices) | python | def labels(indices, node_labels=None):
"""Get the labels for a tuple of mechanism indices."""
if node_labels is None:
return tuple(map(str, indices))
return node_labels.indices2labels(indices) | [
"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. | [
"Get",
"the",
"labels",
"for",
"a",
"tuple",
"of",
"mechanism",
"indices",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L195-L199 | train |
wmayner/pyphi | pyphi/models/fmt.py | fmt_number | def fmt_number(p):
"""Format a number.
It will be printed as a fraction if the denominator isn't too big and as a
decimal otherwise.
"""
formatted = '{:n}'.format(p)
if not config.PRINT_FRACTIONS:
return formatted
fraction = Fraction(p)
nice = fraction.limit_denominator(128)
... | python | def fmt_number(p):
"""Format a number.
It will be printed as a fraction if the denominator isn't too big and as a
decimal otherwise.
"""
formatted = '{:n}'.format(p)
if not config.PRINT_FRACTIONS:
return formatted
fraction = Fraction(p)
nice = fraction.limit_denominator(128)
... | [
"def",
"fmt_number",
"(",
"p",
")",
":",
"formatted",
"=",
"'{:n}'",
".",
"format",
"(",
"p",
")",
"if",
"not",
"config",
".",
"PRINT_FRACTIONS",
":",
"return",
"formatted",
"fraction",
"=",
"Fraction",
"(",
"p",
")",
"nice",
"=",
"fraction",
".",
"lim... | Format a number.
It will be printed as a fraction if the denominator isn't too big and as a
decimal otherwise. | [
"Format",
"a",
"number",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L202-L219 | train |
wmayner/pyphi | pyphi/models/fmt.py | fmt_part | def fmt_part(part, node_labels=None):
"""Format a |Part|.
The returned string looks like::
0,1
───
∅
"""
def nodes(x): # pylint: disable=missing-docstring
return ','.join(labels(x, node_labels)) if x else EMPTY_SET
numer = nodes(part.mechanism)
denom = nodes(... | python | def fmt_part(part, node_labels=None):
"""Format a |Part|.
The returned string looks like::
0,1
───
∅
"""
def nodes(x): # pylint: disable=missing-docstring
return ','.join(labels(x, node_labels)) if x else EMPTY_SET
numer = nodes(part.mechanism)
denom = nodes(... | [
"def",
"fmt_part",
"(",
"part",
",",
"node_labels",
"=",
"None",
")",
":",
"def",
"nodes",
"(",
"x",
")",
":",
"# pylint: disable=missing-docstring",
"return",
"','",
".",
"join",
"(",
"labels",
"(",
"x",
",",
"node_labels",
")",
")",
"if",
"x",
"else",
... | Format a |Part|.
The returned string looks like::
0,1
───
∅ | [
"Format",
"a",
"|Part|",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L227-L249 | train |
wmayner/pyphi | pyphi/models/fmt.py | fmt_partition | def fmt_partition(partition):
"""Format a |Bipartition|.
The returned string looks like::
0,1 ∅
─── ✕ ───
2 0,1
Args:
partition (Bipartition): The partition in question.
Returns:
str: A human-readable string representation of the partition.
"""
... | python | def fmt_partition(partition):
"""Format a |Bipartition|.
The returned string looks like::
0,1 ∅
─── ✕ ───
2 0,1
Args:
partition (Bipartition): The partition in question.
Returns:
str: A human-readable string representation of the partition.
"""
... | [
"def",
"fmt_partition",
"(",
"partition",
")",
":",
"if",
"not",
"partition",
":",
"return",
"''",
"parts",
"=",
"[",
"fmt_part",
"(",
"part",
",",
"partition",
".",
"node_labels",
")",
".",
"split",
"(",
"'\\n'",
")",
"for",
"part",
"in",
"partition",
... | Format a |Bipartition|.
The returned string looks like::
0,1 ∅
─── ✕ ───
2 0,1
Args:
partition (Bipartition): The partition in question.
Returns:
str: A human-readable string representation of the partition. | [
"Format",
"a",
"|Bipartition|",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L252-L283 | train |
wmayner/pyphi | pyphi/models/fmt.py | fmt_ces | def fmt_ces(c, title=None):
"""Format a |CauseEffectStructure|."""
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 's')
... | python | def fmt_ces(c, title=None):
"""Format a |CauseEffectStructure|."""
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 's')
... | [
"def",
"fmt_ces",
"(",
"c",
",",
"title",
"=",
"None",
")",
":",
"if",
"not",
"c",
":",
"return",
"'()\\n'",
"if",
"title",
"is",
"None",
":",
"title",
"=",
"'Cause-effect structure'",
"concepts",
"=",
"'\\n'",
".",
"join",
"(",
"margin",
"(",
"x",
"... | Format a |CauseEffectStructure|. | [
"Format",
"a",
"|CauseEffectStructure|",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L286-L298 | train |
wmayner/pyphi | pyphi/models/fmt.py | fmt_concept | def fmt_concept(concept):
"""Format a |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_cause_or_effect(concep... | python | def fmt_concept(concept):
"""Format a |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_cause_or_effect(concep... | [
"def",
"fmt_concept",
"(",
"concept",
")",
":",
"def",
"fmt_cause_or_effect",
"(",
"x",
")",
":",
"# pylint: disable=missing-docstring",
"return",
"box",
"(",
"indent",
"(",
"fmt_ria",
"(",
"x",
".",
"ria",
",",
"verbose",
"=",
"False",
",",
"mip",
"=",
"T... | Format a |Concept|. | [
"Format",
"a",
"|Concept|",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L301-L318 | train |
wmayner/pyphi | pyphi/models/fmt.py | fmt_ria | def fmt_ria(ria, verbose=True, mip=False):
"""Format a |RepertoireIrreducibilityAnalysis|."""
if verbose:
mechanism = 'Mechanism: {}\n'.format(
fmt_mechanism(ria.mechanism, ria.node_labels))
direction = '\nDirection: {}'.format(ria.direction)
else:
mechanism = ''
... | python | def fmt_ria(ria, verbose=True, mip=False):
"""Format a |RepertoireIrreducibilityAnalysis|."""
if verbose:
mechanism = 'Mechanism: {}\n'.format(
fmt_mechanism(ria.mechanism, ria.node_labels))
direction = '\nDirection: {}'.format(ria.direction)
else:
mechanism = ''
... | [
"def",
"fmt_ria",
"(",
"ria",
",",
"verbose",
"=",
"True",
",",
"mip",
"=",
"False",
")",
":",
"if",
"verbose",
":",
"mechanism",
"=",
"'Mechanism: {}\\n'",
".",
"format",
"(",
"fmt_mechanism",
"(",
"ria",
".",
"mechanism",
",",
"ria",
".",
"node_labels"... | Format a |RepertoireIrreducibilityAnalysis|. | [
"Format",
"a",
"|RepertoireIrreducibilityAnalysis|",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L321-L360 | train |
wmayner/pyphi | pyphi/models/fmt.py | fmt_cut | def fmt_cut(cut):
"""Format a |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)) | python | def fmt_cut(cut):
"""Format a |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)) | [
"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_n... | Format a |Cut|. | [
"Format",
"a",
"|Cut|",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L363-L368 | train |
wmayner/pyphi | pyphi/models/fmt.py | fmt_sia | def fmt_sia(sia, ces=True):
"""Format a |SystemIrreducibilityAnalysis|."""
if ces:
body = (
'{ces}'
'{partitioned_ces}'.format(
ces=fmt_ces(
sia.ces,
'Cause-effect structure'),
partitioned_ces=fmt_ces(
... | python | def fmt_sia(sia, ces=True):
"""Format a |SystemIrreducibilityAnalysis|."""
if ces:
body = (
'{ces}'
'{partitioned_ces}'.format(
ces=fmt_ces(
sia.ces,
'Cause-effect structure'),
partitioned_ces=fmt_ces(
... | [
"def",
"fmt_sia",
"(",
"sia",
",",
"ces",
"=",
"True",
")",
":",
"if",
"ces",
":",
"body",
"=",
"(",
"'{ces}'",
"'{partitioned_ces}'",
".",
"format",
"(",
"ces",
"=",
"fmt_ces",
"(",
"sia",
".",
"ces",
",",
"'Cause-effect structure'",
")",
",",
"partit... | Format a |SystemIrreducibilityAnalysis|. | [
"Format",
"a",
"|SystemIrreducibilityAnalysis|",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L376-L398 | train |
wmayner/pyphi | pyphi/models/fmt.py | fmt_repertoire | def fmt_repertoire(r):
"""Format a repertoire."""
# 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_width=r.ndim, spac... | python | def fmt_repertoire(r):
"""Format a repertoire."""
# 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_width=r.ndim, spac... | [
"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",
"=",
"' '"... | Format a repertoire. | [
"Format",
"a",
"repertoire",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L401-L426 | train |
wmayner/pyphi | pyphi/models/fmt.py | fmt_ac_ria | def fmt_ac_ria(ria):
"""Format an AcRepertoireIrreducibilityAnalysis."""
causality = {
Direction.CAUSE: (fmt_mechanism(ria.purview, ria.node_labels),
ARROW_LEFT,
fmt_mechanism(ria.mechanism, ria.node_labels)),
Direction.EFFECT: (fmt_mechanism(r... | python | def fmt_ac_ria(ria):
"""Format an AcRepertoireIrreducibilityAnalysis."""
causality = {
Direction.CAUSE: (fmt_mechanism(ria.purview, ria.node_labels),
ARROW_LEFT,
fmt_mechanism(ria.mechanism, ria.node_labels)),
Direction.EFFECT: (fmt_mechanism(r... | [
"def",
"fmt_ac_ria",
"(",
"ria",
")",
":",
"causality",
"=",
"{",
"Direction",
".",
"CAUSE",
":",
"(",
"fmt_mechanism",
"(",
"ria",
".",
"purview",
",",
"ria",
".",
"node_labels",
")",
",",
"ARROW_LEFT",
",",
"fmt_mechanism",
"(",
"ria",
".",
"mechanism"... | Format an AcRepertoireIrreducibilityAnalysis. | [
"Format",
"an",
"AcRepertoireIrreducibilityAnalysis",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L429-L444 | train |
wmayner/pyphi | pyphi/models/fmt.py | fmt_account | def fmt_account(account, title=None):
"""Format an Account or a DirectedAccount."""
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 +... | python | def fmt_account(account, title=None):
"""Format an Account or a DirectedAccount."""
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 +... | [
"def",
"fmt_account",
"(",
"account",
",",
"title",
"=",
"None",
")",
":",
"if",
"title",
"is",
"None",
":",
"title",
"=",
"account",
".",
"__class__",
".",
"__name__",
"# `Account` or `DirectedAccount`",
"title",
"=",
"'{} ({} causal link{})'",
".",
"format",
... | Format an Account or a DirectedAccount. | [
"Format",
"an",
"Account",
"or",
"a",
"DirectedAccount",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L447-L461 | train |
wmayner/pyphi | pyphi/models/fmt.py | fmt_ac_sia | def fmt_ac_sia(ac_sia):
"""Format a AcSystemIrreducibilityAnalysis."""
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... | python | def fmt_ac_sia(ac_sia):
"""Format a AcSystemIrreducibilityAnalysis."""
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... | [
"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.cut}\\n'",
"'{a... | Format a AcSystemIrreducibilityAnalysis. | [
"Format",
"a",
"AcSystemIrreducibilityAnalysis",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L464-L485 | train |
wmayner/pyphi | pyphi/models/fmt.py | fmt_transition | def fmt_transition(t):
"""Format a |Transition|."""
return "Transition({} {} {})".format(
fmt_mechanism(t.cause_indices, t.node_labels),
ARROW_RIGHT,
fmt_mechanism(t.effect_indices, t.node_labels)) | python | def fmt_transition(t):
"""Format a |Transition|."""
return "Transition({} {} {})".format(
fmt_mechanism(t.cause_indices, t.node_labels),
ARROW_RIGHT,
fmt_mechanism(t.effect_indices, t.node_labels)) | [
"def",
"fmt_transition",
"(",
"t",
")",
":",
"return",
"\"Transition({} {} {})\"",
".",
"format",
"(",
"fmt_mechanism",
"(",
"t",
".",
"cause_indices",
",",
"t",
".",
"node_labels",
")",
",",
"ARROW_RIGHT",
",",
"fmt_mechanism",
"(",
"t",
".",
"effect_indices"... | Format a |Transition|. | [
"Format",
"a",
"|Transition|",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/fmt.py#L488-L493 | train |
wmayner/pyphi | pyphi/validate.py | direction | def direction(direction, allow_bi=False):
"""Validate that the given direction is one of the allowed constants.
If ``allow_bi`` is ``True`` then ``Direction.BIDIRECTIONAL`` is
acceptable.
"""
valid = [Direction.CAUSE, Direction.EFFECT]
if allow_bi:
valid.append(Direction.BIDIRECTIONAL)
... | python | def direction(direction, allow_bi=False):
"""Validate that the given direction is one of the allowed constants.
If ``allow_bi`` is ``True`` then ``Direction.BIDIRECTIONAL`` is
acceptable.
"""
valid = [Direction.CAUSE, Direction.EFFECT]
if allow_bi:
valid.append(Direction.BIDIRECTIONAL)
... | [
"def",
"direction",
"(",
"direction",
",",
"allow_bi",
"=",
"False",
")",
":",
"valid",
"=",
"[",
"Direction",
".",
"CAUSE",
",",
"Direction",
".",
"EFFECT",
"]",
"if",
"allow_bi",
":",
"valid",
".",
"append",
"(",
"Direction",
".",
"BIDIRECTIONAL",
")",... | Validate that the given direction is one of the allowed constants.
If ``allow_bi`` is ``True`` then ``Direction.BIDIRECTIONAL`` is
acceptable. | [
"Validate",
"that",
"the",
"given",
"direction",
"is",
"one",
"of",
"the",
"allowed",
"constants",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/validate.py#L18-L31 | train |
wmayner/pyphi | pyphi/validate.py | tpm | def tpm(tpm, check_independence=True):
"""Validate a TPM.
The TPM can be in
* 2-dimensional state-by-state form,
* 2-dimensional state-by-node form, or
* multidimensional state-by-node form.
"""
see_tpm_docs = (
'See the documentation on TPM conventions and the `pyphi.N... | python | def tpm(tpm, check_independence=True):
"""Validate a TPM.
The TPM can be in
* 2-dimensional state-by-state form,
* 2-dimensional state-by-node form, or
* multidimensional state-by-node form.
"""
see_tpm_docs = (
'See the documentation on TPM conventions and the `pyphi.N... | [
"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",
".",
"ar... | Validate a TPM.
The TPM can be in
* 2-dimensional state-by-state form,
* 2-dimensional state-by-node form, or
* multidimensional state-by-node form. | [
"Validate",
"a",
"TPM",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/validate.py#L34-L71 | train |
wmayner/pyphi | pyphi/validate.py | conditionally_independent | def conditionally_independent(tpm):
"""Validate that the TPM is conditionally independent."""
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... | python | def conditionally_independent(tpm):
"""Validate that the TPM is conditionally independent."""
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... | [
"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_... | Validate that the TPM is conditionally independent. | [
"Validate",
"that",
"the",
"TPM",
"is",
"conditionally",
"independent",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/validate.py#L74-L90 | train |
wmayner/pyphi | pyphi/validate.py | connectivity_matrix | def connectivity_matrix(cm):
"""Validate the given connectivity matrix."""
# 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... | python | def connectivity_matrix(cm):
"""Validate the given connectivity matrix."""
# 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... | [
"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.\"... | Validate the given connectivity matrix. | [
"Validate",
"the",
"given",
"connectivity",
"matrix",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/validate.py#L93-L105 | train |
wmayner/pyphi | pyphi/validate.py | node_labels | def node_labels(node_labels, node_indices):
"""Validate that there is a label for each node."""
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)):
ra... | python | def node_labels(node_labels, node_indices):
"""Validate that there is a label for each node."""
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)):
ra... | [
"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",
... | Validate that there is a label for each node. | [
"Validate",
"that",
"there",
"is",
"a",
"label",
"for",
"each",
"node",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/validate.py#L108-L115 | train |
wmayner/pyphi | pyphi/validate.py | network | def network(n):
"""Validate a |Network|.
Checks the TPM and connectivity matrix.
"""
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.")
retur... | python | def network(n):
"""Validate a |Network|.
Checks the TPM and connectivity matrix.
"""
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.")
retur... | [
"def",
"network",
"(",
"n",
")",
":",
"tpm",
"(",
"n",
".",
"tpm",
")",
"connectivity_matrix",
"(",
"n",
".",
"cm",
")",
"if",
"n",
".",
"cm",
".",
"shape",
"[",
"0",
"]",
"!=",
"n",
".",
"size",
":",
"raise",
"ValueError",
"(",
"\"Connectivity m... | Validate a |Network|.
Checks the TPM and connectivity matrix. | [
"Validate",
"a",
"|Network|",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/validate.py#L118-L128 | train |
wmayner/pyphi | pyphi/validate.py | state_length | def state_length(state, size):
"""Check that the state is the given 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... | python | def state_length(state, size):
"""Check that the state is the given 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... | [
"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.'",
"... | Check that the state is the given size. | [
"Check",
"that",
"the",
"state",
"is",
"the",
"given",
"size",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/validate.py#L147-L153 | train |
wmayner/pyphi | pyphi/validate.py | state_reachable | def state_reachable(subsystem):
"""Return whether a state can be reached according to the network's TPM."""
# 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 ta... | python | def state_reachable(subsystem):
"""Return whether a state can be reached according to the network's TPM."""
# 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 ta... | [
"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 conditioned TPM th... | Return whether a state can be reached according to the network's TPM. | [
"Return",
"whether",
"a",
"state",
"can",
"be",
"reached",
"according",
"to",
"the",
"network",
"s",
"TPM",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/validate.py#L156-L167 | train |
wmayner/pyphi | pyphi/validate.py | cut | def cut(cut, node_indices):
"""Check that the cut is for only the given nodes."""
if cut.indices != node_indices:
raise ValueError('{} nodes are not equal to subsystem nodes '
'{}'.format(cut, node_indices)) | python | def cut(cut, node_indices):
"""Check that the cut is for only the given nodes."""
if cut.indices != node_indices:
raise ValueError('{} nodes are not equal to subsystem nodes '
'{}'.format(cut, node_indices)) | [
"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. | [
"Check",
"that",
"the",
"cut",
"is",
"for",
"only",
"the",
"given",
"nodes",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/validate.py#L170-L174 | train |
wmayner/pyphi | pyphi/validate.py | subsystem | def subsystem(s):
"""Validate a |Subsystem|.
Checks its state and cut.
"""
node_states(s.state)
cut(s.cut, s.cut_indices)
if config.VALIDATE_SUBSYSTEM_STATES:
state_reachable(s)
return True | python | def subsystem(s):
"""Validate a |Subsystem|.
Checks its state and cut.
"""
node_states(s.state)
cut(s.cut, s.cut_indices)
if config.VALIDATE_SUBSYSTEM_STATES:
state_reachable(s)
return True | [
"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|.
Checks its state and cut. | [
"Validate",
"a",
"|Subsystem|",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/validate.py#L177-L186 | train |
wmayner/pyphi | pyphi/validate.py | partition | def partition(partition):
"""Validate a partition - used by blackboxes and coarse grains."""
nodes = set()
for part in partition:
for node in part:
if node in nodes:
raise ValueError(
'Micro-element {} may not be partitioned into multiple '
... | python | def partition(partition):
"""Validate a partition - used by blackboxes and coarse grains."""
nodes = set()
for part in partition:
for node in part:
if node in nodes:
raise ValueError(
'Micro-element {} may not be partitioned into multiple '
... | [
"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 in... | Validate a partition - used by blackboxes and coarse grains. | [
"Validate",
"a",
"partition",
"-",
"used",
"by",
"blackboxes",
"and",
"coarse",
"grains",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/validate.py#L195-L204 | train |
wmayner/pyphi | pyphi/validate.py | coarse_grain | def coarse_grain(coarse_grain):
"""Validate a macro coarse-graining."""
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, coarse_gra... | python | def coarse_grain(coarse_grain):
"""Validate a macro coarse-graining."""
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, coarse_gra... | [
"def",
"coarse_grain",
"(",
"coarse_grain",
")",
":",
"partition",
"(",
"coarse_grain",
".",
"partition",
")",
"if",
"len",
"(",
"coarse_grain",
".",
"partition",
")",
"!=",
"len",
"(",
"coarse_grain",
".",
"grouping",
")",
":",
"raise",
"ValueError",
"(",
... | Validate a macro coarse-graining. | [
"Validate",
"a",
"macro",
"coarse",
"-",
"graining",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/validate.py#L207-L220 | train |
wmayner/pyphi | pyphi/validate.py | blackbox | def blackbox(blackbox):
"""Validate a macro blackboxing."""
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.partition:
... | python | def blackbox(blackbox):
"""Validate a macro blackboxing."""
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.partition:
... | [
"def",
"blackbox",
"(",
"blackbox",
")",
":",
"if",
"tuple",
"(",
"sorted",
"(",
"blackbox",
".",
"output_indices",
")",
")",
"!=",
"blackbox",
".",
"output_indices",
":",
"raise",
"ValueError",
"(",
"'Output indices {} must be ordered'",
".",
"format",
"(",
"... | Validate a macro blackboxing. | [
"Validate",
"a",
"macro",
"blackboxing",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/validate.py#L223-L235 | train |
wmayner/pyphi | pyphi/validate.py | blackbox_and_coarse_grain | def blackbox_and_coarse_grain(blackbox, coarse_grain):
"""Validate that a coarse-graining properly combines the outputs of a
blackboxing.
"""
if blackbox is None:
return
for box in blackbox.partition:
# Outputs of the box
outputs = set(box) & set(blackbox.output_indices)
... | python | def blackbox_and_coarse_grain(blackbox, coarse_grain):
"""Validate that a coarse-graining properly combines the outputs of a
blackboxing.
"""
if blackbox is None:
return
for box in blackbox.partition:
# Outputs of the box
outputs = set(box) & set(blackbox.output_indices)
... | [
"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",
")",
"&",
"se... | Validate that a coarse-graining properly combines the outputs of a
blackboxing. | [
"Validate",
"that",
"a",
"coarse",
"-",
"graining",
"properly",
"combines",
"the",
"outputs",
"of",
"a",
"blackboxing",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/validate.py#L238-L258 | train |
wmayner/pyphi | pyphi/registry.py | Registry.register | def register(self, name):
"""Decorator for registering a function with PyPhi.
Args:
name (string): The name of the function
"""
def register_func(func):
self.store[name] = func
return func
return register_func | python | def register(self, name):
"""Decorator for registering a function with PyPhi.
Args:
name (string): The name of the function
"""
def register_func(func):
self.store[name] = func
return func
return register_func | [
"def",
"register",
"(",
"self",
",",
"name",
")",
":",
"def",
"register_func",
"(",
"func",
")",
":",
"self",
".",
"store",
"[",
"name",
"]",
"=",
"func",
"return",
"func",
"return",
"register_func"
] | Decorator for registering a function with PyPhi.
Args:
name (string): The name of the function | [
"Decorator",
"for",
"registering",
"a",
"function",
"with",
"PyPhi",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/registry.py#L23-L32 | train |
wmayner/pyphi | pyphi/compute/subsystem.py | ces | def ces(subsystem, mechanisms=False, purviews=False, cause_purviews=False,
effect_purviews=False, parallel=False):
"""Return the conceptual structure of this subsystem, optionally restricted
to concepts with the mechanisms and purviews given in keyword arguments.
If you don't need the full |CauseEf... | python | def ces(subsystem, mechanisms=False, purviews=False, cause_purviews=False,
effect_purviews=False, parallel=False):
"""Return the conceptual structure of this subsystem, optionally restricted
to concepts with the mechanisms and purviews given in keyword arguments.
If you don't need the full |CauseEf... | [
"def",
"ces",
"(",
"subsystem",
",",
"mechanisms",
"=",
"False",
",",
"purviews",
"=",
"False",
",",
"cause_purviews",
"=",
"False",
",",
"effect_purviews",
"=",
"False",
",",
"parallel",
"=",
"False",
")",
":",
"if",
"mechanisms",
"is",
"False",
":",
"m... | Return the conceptual structure of this subsystem, optionally restricted
to concepts with the mechanisms and purviews given in keyword arguments.
If you don't need the full |CauseEffectStructure|, restricting the possible
mechanisms and purviews can make this function much faster.
Args:
subsys... | [
"Return",
"the",
"conceptual",
"structure",
"of",
"this",
"subsystem",
"optionally",
"restricted",
"to",
"concepts",
"with",
"the",
"mechanisms",
"and",
"purviews",
"given",
"in",
"keyword",
"arguments",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/compute/subsystem.py#L66-L99 | train |
wmayner/pyphi | pyphi/compute/subsystem.py | conceptual_info | def conceptual_info(subsystem):
"""Return the conceptual information for a |Subsystem|.
This is the distance from the subsystem's |CauseEffectStructure| to the
null concept.
"""
ci = ces_distance(ces(subsystem),
CauseEffectStructure((), subsystem=subsystem))
return round(c... | python | def conceptual_info(subsystem):
"""Return the conceptual information for a |Subsystem|.
This is the distance from the subsystem's |CauseEffectStructure| to the
null concept.
"""
ci = ces_distance(ces(subsystem),
CauseEffectStructure((), subsystem=subsystem))
return round(c... | [
"def",
"conceptual_info",
"(",
"subsystem",
")",
":",
"ci",
"=",
"ces_distance",
"(",
"ces",
"(",
"subsystem",
")",
",",
"CauseEffectStructure",
"(",
"(",
")",
",",
"subsystem",
"=",
"subsystem",
")",
")",
"return",
"round",
"(",
"ci",
",",
"config",
"."... | Return the conceptual information for a |Subsystem|.
This is the distance from the subsystem's |CauseEffectStructure| to the
null concept. | [
"Return",
"the",
"conceptual",
"information",
"for",
"a",
"|Subsystem|",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/compute/subsystem.py#L102-L110 | train |
wmayner/pyphi | pyphi/compute/subsystem.py | evaluate_cut | def evaluate_cut(uncut_subsystem, cut, unpartitioned_ces):
"""Compute the system irreducibility for a given cut.
Args:
uncut_subsystem (Subsystem): The subsystem without the cut applied.
cut (Cut): The cut to evaluate.
unpartitioned_ces (CauseEffectStructure): The cause-effect structure... | python | def evaluate_cut(uncut_subsystem, cut, unpartitioned_ces):
"""Compute the system irreducibility for a given cut.
Args:
uncut_subsystem (Subsystem): The subsystem without the cut applied.
cut (Cut): The cut to evaluate.
unpartitioned_ces (CauseEffectStructure): The cause-effect structure... | [
"def",
"evaluate_cut",
"(",
"uncut_subsystem",
",",
"cut",
",",
"unpartitioned_ces",
")",
":",
"log",
".",
"debug",
"(",
"'Evaluating %s...'",
",",
"cut",
")",
"cut_subsystem",
"=",
"uncut_subsystem",
".",
"apply_cut",
"(",
"cut",
")",
"if",
"config",
".",
"... | Compute the system irreducibility for a given cut.
Args:
uncut_subsystem (Subsystem): The subsystem without the cut applied.
cut (Cut): The cut to evaluate.
unpartitioned_ces (CauseEffectStructure): The cause-effect structure of
the uncut subsystem.
Returns:
SystemI... | [
"Compute",
"the",
"system",
"irreducibility",
"for",
"a",
"given",
"cut",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/compute/subsystem.py#L113-L150 | train |
wmayner/pyphi | pyphi/compute/subsystem.py | sia_bipartitions | def sia_bipartitions(nodes, node_labels=None):
"""Return all |big_phi| cuts for the given nodes.
This value changes based on :const:`config.CUT_ONE_APPROXIMATION`.
Args:
nodes (tuple[int]): The node indices to partition.
Returns:
list[Cut]: All unidirectional partitions.
"""
if... | python | def sia_bipartitions(nodes, node_labels=None):
"""Return all |big_phi| cuts for the given nodes.
This value changes based on :const:`config.CUT_ONE_APPROXIMATION`.
Args:
nodes (tuple[int]): The node indices to partition.
Returns:
list[Cut]: All unidirectional partitions.
"""
if... | [
"def",
"sia_bipartitions",
"(",
"nodes",
",",
"node_labels",
"=",
"None",
")",
":",
"if",
"config",
".",
"CUT_ONE_APPROXIMATION",
":",
"bipartitions",
"=",
"directed_bipartition_of_one",
"(",
"nodes",
")",
"else",
":",
"# Don't consider trivial partitions where one part... | Return all |big_phi| cuts for the given nodes.
This value changes based on :const:`config.CUT_ONE_APPROXIMATION`.
Args:
nodes (tuple[int]): The node indices to partition.
Returns:
list[Cut]: All unidirectional partitions. | [
"Return",
"all",
"|big_phi|",
"cuts",
"for",
"the",
"given",
"nodes",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/compute/subsystem.py#L184-L201 | train |
wmayner/pyphi | pyphi/compute/subsystem.py | _sia | def _sia(cache_key, subsystem):
"""Return the minimal information partition of a subsystem.
Args:
subsystem (Subsystem): The candidate set of nodes.
Returns:
SystemIrreducibilityAnalysis: A nested structure containing all the
data from the intermediate calculations. The top level c... | python | def _sia(cache_key, subsystem):
"""Return the minimal information partition of a subsystem.
Args:
subsystem (Subsystem): The candidate set of nodes.
Returns:
SystemIrreducibilityAnalysis: A nested structure containing all the
data from the intermediate calculations. The top level c... | [
"def",
"_sia",
"(",
"cache_key",
",",
"subsystem",
")",
":",
"# pylint: disable=unused-argument",
"log",
".",
"info",
"(",
"'Calculating big-phi data for %s...'",
",",
"subsystem",
")",
"# Check for degenerate cases",
"# ===========================================================... | Return the minimal information partition of a subsystem.
Args:
subsystem (Subsystem): The candidate set of nodes.
Returns:
SystemIrreducibilityAnalysis: A nested structure containing all the
data from the intermediate calculations. The top level contains the
basic irreducibilit... | [
"Return",
"the",
"minimal",
"information",
"partition",
"of",
"a",
"subsystem",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/compute/subsystem.py#L214-L292 | train |
wmayner/pyphi | pyphi/compute/subsystem.py | _sia_cache_key | def _sia_cache_key(subsystem):
"""The cache key of the subsystem.
This includes the native hash of the subsystem and all configuration values
which change the results of ``sia``.
"""
return (
hash(subsystem),
config.ASSUME_CUTS_CANNOT_CREATE_NEW_CONCEPTS,
config.CUT_ONE_APPR... | python | def _sia_cache_key(subsystem):
"""The cache key of the subsystem.
This includes the native hash of the subsystem and all configuration values
which change the results of ``sia``.
"""
return (
hash(subsystem),
config.ASSUME_CUTS_CANNOT_CREATE_NEW_CONCEPTS,
config.CUT_ONE_APPR... | [
"def",
"_sia_cache_key",
"(",
"subsystem",
")",
":",
"return",
"(",
"hash",
"(",
"subsystem",
")",
",",
"config",
".",
"ASSUME_CUTS_CANNOT_CREATE_NEW_CONCEPTS",
",",
"config",
".",
"CUT_ONE_APPROXIMATION",
",",
"config",
".",
"MEASURE",
",",
"config",
".",
"PREC... | The cache key of the subsystem.
This includes the native hash of the subsystem and all configuration values
which change the results of ``sia``. | [
"The",
"cache",
"key",
"of",
"the",
"subsystem",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/compute/subsystem.py#L297-L312 | train |
wmayner/pyphi | pyphi/compute/subsystem.py | concept_cuts | def concept_cuts(direction, node_indices, node_labels=None):
"""Generator over all concept-syle cuts for these nodes."""
for partition in mip_partitions(node_indices, node_indices):
yield KCut(direction, partition, node_labels) | python | def concept_cuts(direction, node_indices, node_labels=None):
"""Generator over all concept-syle cuts for these nodes."""
for partition in mip_partitions(node_indices, node_indices):
yield KCut(direction, partition, node_labels) | [
"def",
"concept_cuts",
"(",
"direction",
",",
"node_indices",
",",
"node_labels",
"=",
"None",
")",
":",
"for",
"partition",
"in",
"mip_partitions",
"(",
"node_indices",
",",
"node_indices",
")",
":",
"yield",
"KCut",
"(",
"direction",
",",
"partition",
",",
... | Generator over all concept-syle cuts for these nodes. | [
"Generator",
"over",
"all",
"concept",
"-",
"syle",
"cuts",
"for",
"these",
"nodes",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/compute/subsystem.py#L390-L393 | train |
wmayner/pyphi | pyphi/compute/subsystem.py | directional_sia | def directional_sia(subsystem, direction, unpartitioned_ces=None):
"""Calculate a concept-style SystemIrreducibilityAnalysisCause or
SystemIrreducibilityAnalysisEffect.
"""
if unpartitioned_ces is None:
unpartitioned_ces = _ces(subsystem)
c_system = ConceptStyleSystem(subsystem, direction)
... | python | def directional_sia(subsystem, direction, unpartitioned_ces=None):
"""Calculate a concept-style SystemIrreducibilityAnalysisCause or
SystemIrreducibilityAnalysisEffect.
"""
if unpartitioned_ces is None:
unpartitioned_ces = _ces(subsystem)
c_system = ConceptStyleSystem(subsystem, direction)
... | [
"def",
"directional_sia",
"(",
"subsystem",
",",
"direction",
",",
"unpartitioned_ces",
"=",
"None",
")",
":",
"if",
"unpartitioned_ces",
"is",
"None",
":",
"unpartitioned_ces",
"=",
"_ces",
"(",
"subsystem",
")",
"c_system",
"=",
"ConceptStyleSystem",
"(",
"sub... | Calculate a concept-style SystemIrreducibilityAnalysisCause or
SystemIrreducibilityAnalysisEffect. | [
"Calculate",
"a",
"concept",
"-",
"style",
"SystemIrreducibilityAnalysisCause",
"or",
"SystemIrreducibilityAnalysisEffect",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/compute/subsystem.py#L396-L410 | train |
wmayner/pyphi | pyphi/compute/subsystem.py | sia_concept_style | def sia_concept_style(subsystem):
"""Compute a concept-style SystemIrreducibilityAnalysis"""
unpartitioned_ces = _ces(subsystem)
sia_cause = directional_sia(subsystem, Direction.CAUSE,
unpartitioned_ces)
sia_effect = directional_sia(subsystem, Direction.EFFECT,
... | python | def sia_concept_style(subsystem):
"""Compute a concept-style SystemIrreducibilityAnalysis"""
unpartitioned_ces = _ces(subsystem)
sia_cause = directional_sia(subsystem, Direction.CAUSE,
unpartitioned_ces)
sia_effect = directional_sia(subsystem, Direction.EFFECT,
... | [
"def",
"sia_concept_style",
"(",
"subsystem",
")",
":",
"unpartitioned_ces",
"=",
"_ces",
"(",
"subsystem",
")",
"sia_cause",
"=",
"directional_sia",
"(",
"subsystem",
",",
"Direction",
".",
"CAUSE",
",",
"unpartitioned_ces",
")",
"sia_effect",
"=",
"directional_s... | Compute a concept-style SystemIrreducibilityAnalysis | [
"Compute",
"a",
"concept",
"-",
"style",
"SystemIrreducibilityAnalysis"
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/compute/subsystem.py#L447-L456 | train |
wmayner/pyphi | pyphi/compute/subsystem.py | ComputeCauseEffectStructure.compute | def compute(mechanism, subsystem, purviews, cause_purviews,
effect_purviews):
"""Compute a |Concept| for a mechanism, in this |Subsystem| with the
provided purviews.
"""
concept = subsystem.concept(mechanism,
purviews=purviews,
... | python | def compute(mechanism, subsystem, purviews, cause_purviews,
effect_purviews):
"""Compute a |Concept| for a mechanism, in this |Subsystem| with the
provided purviews.
"""
concept = subsystem.concept(mechanism,
purviews=purviews,
... | [
"def",
"compute",
"(",
"mechanism",
",",
"subsystem",
",",
"purviews",
",",
"cause_purviews",
",",
"effect_purviews",
")",
":",
"concept",
"=",
"subsystem",
".",
"concept",
"(",
"mechanism",
",",
"purviews",
"=",
"purviews",
",",
"cause_purviews",
"=",
"cause_... | Compute a |Concept| for a mechanism, in this |Subsystem| with the
provided purviews. | [
"Compute",
"a",
"|Concept|",
"for",
"a",
"mechanism",
"in",
"this",
"|Subsystem|",
"with",
"the",
"provided",
"purviews",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/compute/subsystem.py#L39-L52 | train |
wmayner/pyphi | pyphi/compute/subsystem.py | ComputeCauseEffectStructure.process_result | def process_result(self, new_concept, concepts):
"""Save all concepts with non-zero |small_phi| to the
|CauseEffectStructure|.
"""
if new_concept.phi > 0:
# Replace the subsystem
new_concept.subsystem = self.subsystem
concepts.append(new_concept)
... | python | def process_result(self, new_concept, concepts):
"""Save all concepts with non-zero |small_phi| to the
|CauseEffectStructure|.
"""
if new_concept.phi > 0:
# Replace the subsystem
new_concept.subsystem = self.subsystem
concepts.append(new_concept)
... | [
"def",
"process_result",
"(",
"self",
",",
"new_concept",
",",
"concepts",
")",
":",
"if",
"new_concept",
".",
"phi",
">",
"0",
":",
"# Replace the subsystem",
"new_concept",
".",
"subsystem",
"=",
"self",
".",
"subsystem",
"concepts",
".",
"append",
"(",
"n... | Save all concepts with non-zero |small_phi| to the
|CauseEffectStructure|. | [
"Save",
"all",
"concepts",
"with",
"non",
"-",
"zero",
"|small_phi|",
"to",
"the",
"|CauseEffectStructure|",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/compute/subsystem.py#L54-L62 | train |
wmayner/pyphi | pyphi/compute/subsystem.py | ComputeSystemIrreducibility.process_result | def process_result(self, new_sia, min_sia):
"""Check if the new SIA has smaller |big_phi| than the standing
result.
"""
if new_sia.phi == 0:
self.done = True # Short-circuit
return new_sia
elif new_sia < min_sia:
return new_sia
retur... | python | def process_result(self, new_sia, min_sia):
"""Check if the new SIA has smaller |big_phi| than the standing
result.
"""
if new_sia.phi == 0:
self.done = True # Short-circuit
return new_sia
elif new_sia < min_sia:
return new_sia
retur... | [
"def",
"process_result",
"(",
"self",
",",
"new_sia",
",",
"min_sia",
")",
":",
"if",
"new_sia",
".",
"phi",
"==",
"0",
":",
"self",
".",
"done",
"=",
"True",
"# Short-circuit",
"return",
"new_sia",
"elif",
"new_sia",
"<",
"min_sia",
":",
"return",
"new_... | Check if the new SIA has smaller |big_phi| than the standing
result. | [
"Check",
"if",
"the",
"new",
"SIA",
"has",
"smaller",
"|big_phi|",
"than",
"the",
"standing",
"result",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/compute/subsystem.py#L170-L181 | train |
wmayner/pyphi | pyphi/compute/subsystem.py | ConceptStyleSystem.concept | def concept(self, mechanism, purviews=False, cause_purviews=False,
effect_purviews=False):
"""Compute a concept, using the appropriate system for each side of the
cut.
"""
cause = self.cause_system.mic(
mechanism, purviews=(cause_purviews or purviews))
... | python | def concept(self, mechanism, purviews=False, cause_purviews=False,
effect_purviews=False):
"""Compute a concept, using the appropriate system for each side of the
cut.
"""
cause = self.cause_system.mic(
mechanism, purviews=(cause_purviews or purviews))
... | [
"def",
"concept",
"(",
"self",
",",
"mechanism",
",",
"purviews",
"=",
"False",
",",
"cause_purviews",
"=",
"False",
",",
"effect_purviews",
"=",
"False",
")",
":",
"cause",
"=",
"self",
".",
"cause_system",
".",
"mic",
"(",
"mechanism",
",",
"purviews",
... | Compute a concept, using the appropriate system for each side of the
cut. | [
"Compute",
"a",
"concept",
"using",
"the",
"appropriate",
"system",
"for",
"each",
"side",
"of",
"the",
"cut",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/compute/subsystem.py#L372-L384 | train |
wmayner/pyphi | pyphi/labels.py | NodeLabels.coerce_to_indices | def coerce_to_indices(self, nodes):
"""Return the nodes indices for nodes, where ``nodes`` is either
already integer indices or node labels.
"""
if nodes is None:
return self.node_indices
if all(isinstance(node, str) for node in nodes):
indices = self.lab... | python | def coerce_to_indices(self, nodes):
"""Return the nodes indices for nodes, where ``nodes`` is either
already integer indices or node labels.
"""
if nodes is None:
return self.node_indices
if all(isinstance(node, str) for node in nodes):
indices = self.lab... | [
"def",
"coerce_to_indices",
"(",
"self",
",",
"nodes",
")",
":",
"if",
"nodes",
"is",
"None",
":",
"return",
"self",
".",
"node_indices",
"if",
"all",
"(",
"isinstance",
"(",
"node",
",",
"str",
")",
"for",
"node",
"in",
"nodes",
")",
":",
"indices",
... | Return the nodes indices for nodes, where ``nodes`` is either
already integer indices or node labels. | [
"Return",
"the",
"nodes",
"indices",
"for",
"nodes",
"where",
"nodes",
"is",
"either",
"already",
"integer",
"indices",
"or",
"node",
"labels",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/labels.py#L82-L93 | train |
wmayner/pyphi | pyphi/models/subsystem.py | _null_sia | def _null_sia(subsystem, phi=0.0):
"""Return a |SystemIrreducibilityAnalysis| with zero |big_phi| and empty
cause-effect structures.
This is the analysis result for a reducible subsystem.
"""
return SystemIrreducibilityAnalysis(subsystem=subsystem,
cut_subsys... | python | def _null_sia(subsystem, phi=0.0):
"""Return a |SystemIrreducibilityAnalysis| with zero |big_phi| and empty
cause-effect structures.
This is the analysis result for a reducible subsystem.
"""
return SystemIrreducibilityAnalysis(subsystem=subsystem,
cut_subsys... | [
"def",
"_null_sia",
"(",
"subsystem",
",",
"phi",
"=",
"0.0",
")",
":",
"return",
"SystemIrreducibilityAnalysis",
"(",
"subsystem",
"=",
"subsystem",
",",
"cut_subsystem",
"=",
"subsystem",
",",
"phi",
"=",
"phi",
",",
"ces",
"=",
"_null_ces",
"(",
"subsyste... | Return a |SystemIrreducibilityAnalysis| with zero |big_phi| and empty
cause-effect structures.
This is the analysis result for a reducible subsystem. | [
"Return",
"a",
"|SystemIrreducibilityAnalysis|",
"with",
"zero",
"|big_phi|",
"and",
"empty",
"cause",
"-",
"effect",
"structures",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/subsystem.py#L179-L189 | train |
wmayner/pyphi | pyphi/models/subsystem.py | CauseEffectStructure.labeled_mechanisms | def labeled_mechanisms(self):
"""The labeled mechanism of each concept."""
label = self.subsystem.node_labels.indices2labels
return tuple(list(label(mechanism)) for mechanism in self.mechanisms) | python | def labeled_mechanisms(self):
"""The labeled mechanism of each concept."""
label = self.subsystem.node_labels.indices2labels
return tuple(list(label(mechanism)) for mechanism in self.mechanisms) | [
"def",
"labeled_mechanisms",
"(",
"self",
")",
":",
"label",
"=",
"self",
".",
"subsystem",
".",
"node_labels",
".",
"indices2labels",
"return",
"tuple",
"(",
"list",
"(",
"label",
"(",
"mechanism",
")",
")",
"for",
"mechanism",
"in",
"self",
".",
"mechani... | The labeled mechanism of each concept. | [
"The",
"labeled",
"mechanism",
"of",
"each",
"concept",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/subsystem.py#L69-L72 | train |
wmayner/pyphi | pyphi/direction.py | Direction.order | def order(self, mechanism, purview):
"""Order the mechanism and purview in time.
If the direction is ``CAUSE``, then the purview is at |t-1| and the
mechanism is at time |t|. If the direction is ``EFFECT``, then the
mechanism is at time |t| and the purview is at |t+1|.
"""
... | python | def order(self, mechanism, purview):
"""Order the mechanism and purview in time.
If the direction is ``CAUSE``, then the purview is at |t-1| and the
mechanism is at time |t|. If the direction is ``EFFECT``, then the
mechanism is at time |t| and the purview is at |t+1|.
"""
... | [
"def",
"order",
"(",
"self",
",",
"mechanism",
",",
"purview",
")",
":",
"if",
"self",
"is",
"Direction",
".",
"CAUSE",
":",
"return",
"purview",
",",
"mechanism",
"elif",
"self",
"is",
"Direction",
".",
"EFFECT",
":",
"return",
"mechanism",
",",
"purvie... | Order the mechanism and purview in time.
If the direction is ``CAUSE``, then the purview is at |t-1| and the
mechanism is at time |t|. If the direction is ``EFFECT``, then the
mechanism is at time |t| and the purview is at |t+1|. | [
"Order",
"the",
"mechanism",
"and",
"purview",
"in",
"time",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/direction.py#L31-L44 | train |
wmayner/pyphi | pyphi/models/cmp.py | sametype | def sametype(func):
"""Method decorator to return ``NotImplemented`` if the args of the wrapped
method are of different types.
When wrapping a rich model comparison method this will delegate (reflect)
the comparison to the right-hand-side object, or fallback by passing it up
the inheritance tree.
... | python | def sametype(func):
"""Method decorator to return ``NotImplemented`` if the args of the wrapped
method are of different types.
When wrapping a rich model comparison method this will delegate (reflect)
the comparison to the right-hand-side object, or fallback by passing it up
the inheritance tree.
... | [
"def",
"sametype",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"self",
",",
"other",
")",
":",
"# pylint: disable=missing-docstring",
"if",
"type",
"(",
"other",
")",
"is",
"not",
"type",
"(",
"self",
... | Method decorator to return ``NotImplemented`` if the args of the wrapped
method are of different types.
When wrapping a rich model comparison method this will delegate (reflect)
the comparison to the right-hand-side object, or fallback by passing it up
the inheritance tree. | [
"Method",
"decorator",
"to",
"return",
"NotImplemented",
"if",
"the",
"args",
"of",
"the",
"wrapped",
"method",
"are",
"of",
"different",
"types",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/cmp.py#L19-L32 | train |
wmayner/pyphi | pyphi/models/cmp.py | general_eq | def general_eq(a, b, attributes):
"""Return whether two objects are equal up to the given attributes.
If an attribute is called ``'phi'``, it is compared up to |PRECISION|.
If an attribute is called ``'mechanism'`` or ``'purview'``, it is
compared using set equality. All other attributes are compared ... | python | def general_eq(a, b, attributes):
"""Return whether two objects are equal up to the given attributes.
If an attribute is called ``'phi'``, it is compared up to |PRECISION|.
If an attribute is called ``'mechanism'`` or ``'purview'``, it is
compared using set equality. All other attributes are compared ... | [
"def",
"general_eq",
"(",
"a",
",",
"b",
",",
"attributes",
")",
":",
"try",
":",
"for",
"attr",
"in",
"attributes",
":",
"_a",
",",
"_b",
"=",
"getattr",
"(",
"a",
",",
"attr",
")",
",",
"getattr",
"(",
"b",
",",
"attr",
")",
"if",
"attr",
"in... | Return whether two objects are equal up to the given attributes.
If an attribute is called ``'phi'``, it is compared up to |PRECISION|.
If an attribute is called ``'mechanism'`` or ``'purview'``, it is
compared using set equality. All other attributes are compared with
:func:`numpy_aware_eq`. | [
"Return",
"whether",
"two",
"objects",
"are",
"equal",
"up",
"to",
"the",
"given",
"attributes",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/models/cmp.py#L108-L133 | train |
wmayner/pyphi | benchmarks/time_emd.py | time_emd | def time_emd(emd_type, data):
"""Time an EMD command with the given data as arguments"""
emd = {
'cause': _CAUSE_EMD,
'effect': pyphi.subsystem.effect_emd,
'hamming': pyphi.utils.hamming_emd
}[emd_type]
def statement():
for (d1, d2) in data:
emd(d1, d2)
... | python | def time_emd(emd_type, data):
"""Time an EMD command with the given data as arguments"""
emd = {
'cause': _CAUSE_EMD,
'effect': pyphi.subsystem.effect_emd,
'hamming': pyphi.utils.hamming_emd
}[emd_type]
def statement():
for (d1, d2) in data:
emd(d1, d2)
... | [
"def",
"time_emd",
"(",
"emd_type",
",",
"data",
")",
":",
"emd",
"=",
"{",
"'cause'",
":",
"_CAUSE_EMD",
",",
"'effect'",
":",
"pyphi",
".",
"subsystem",
".",
"effect_emd",
",",
"'hamming'",
":",
"pyphi",
".",
"utils",
".",
"hamming_emd",
"}",
"[",
"e... | Time an EMD command with the given data as arguments | [
"Time",
"an",
"EMD",
"command",
"with",
"the",
"given",
"data",
"as",
"arguments"
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/benchmarks/time_emd.py#L320-L335 | train |
wmayner/pyphi | pyphi/distribution.py | marginal_zero | def marginal_zero(repertoire, node_index):
"""Return the marginal probability that the node is OFF."""
index = [slice(None)] * repertoire.ndim
index[node_index] = 0
return repertoire[tuple(index)].sum() | python | def marginal_zero(repertoire, node_index):
"""Return the marginal probability that the node is OFF."""
index = [slice(None)] * repertoire.ndim
index[node_index] = 0
return repertoire[tuple(index)].sum() | [
"def",
"marginal_zero",
"(",
"repertoire",
",",
"node_index",
")",
":",
"index",
"=",
"[",
"slice",
"(",
"None",
")",
"]",
"*",
"repertoire",
".",
"ndim",
"index",
"[",
"node_index",
"]",
"=",
"0",
"return",
"repertoire",
"[",
"tuple",
"(",
"index",
")... | Return the marginal probability that the node is OFF. | [
"Return",
"the",
"marginal",
"probability",
"that",
"the",
"node",
"is",
"OFF",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/distribution.py#L50-L55 | train |
wmayner/pyphi | pyphi/distribution.py | marginal | def marginal(repertoire, node_index):
"""Get the marginal distribution for a node."""
index = tuple(i for i in range(repertoire.ndim) if i != node_index)
return repertoire.sum(index, keepdims=True) | python | def marginal(repertoire, node_index):
"""Get the marginal distribution for a node."""
index = tuple(i for i in range(repertoire.ndim) if i != node_index)
return repertoire.sum(index, keepdims=True) | [
"def",
"marginal",
"(",
"repertoire",
",",
"node_index",
")",
":",
"index",
"=",
"tuple",
"(",
"i",
"for",
"i",
"in",
"range",
"(",
"repertoire",
".",
"ndim",
")",
"if",
"i",
"!=",
"node_index",
")",
"return",
"repertoire",
".",
"sum",
"(",
"index",
... | Get the marginal distribution for a node. | [
"Get",
"the",
"marginal",
"distribution",
"for",
"a",
"node",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/distribution.py#L58-L62 | train |
wmayner/pyphi | pyphi/distribution.py | independent | def independent(repertoire):
"""Check whether the repertoire is independent."""
marginals = [marginal(repertoire, i) for i in range(repertoire.ndim)]
# TODO: is there a way to do without an explicit iteration?
joint = marginals[0]
for m in marginals[1:]:
joint = joint * m
# TODO: shoul... | python | def independent(repertoire):
"""Check whether the repertoire is independent."""
marginals = [marginal(repertoire, i) for i in range(repertoire.ndim)]
# TODO: is there a way to do without an explicit iteration?
joint = marginals[0]
for m in marginals[1:]:
joint = joint * m
# TODO: shoul... | [
"def",
"independent",
"(",
"repertoire",
")",
":",
"marginals",
"=",
"[",
"marginal",
"(",
"repertoire",
",",
"i",
")",
"for",
"i",
"in",
"range",
"(",
"repertoire",
".",
"ndim",
")",
"]",
"# TODO: is there a way to do without an explicit iteration?",
"joint",
"... | Check whether the repertoire is independent. | [
"Check",
"whether",
"the",
"repertoire",
"is",
"independent",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/distribution.py#L65-L78 | train |
wmayner/pyphi | pyphi/distribution.py | purview | def purview(repertoire):
"""The purview of the repertoire.
Args:
repertoire (np.ndarray): A repertoire
Returns:
tuple[int]: The purview that the repertoire was computed over.
"""
if repertoire is None:
return None
return tuple(i for i, dim in enumerate(repertoire.shape... | python | def purview(repertoire):
"""The purview of the repertoire.
Args:
repertoire (np.ndarray): A repertoire
Returns:
tuple[int]: The purview that the repertoire was computed over.
"""
if repertoire is None:
return None
return tuple(i for i, dim in enumerate(repertoire.shape... | [
"def",
"purview",
"(",
"repertoire",
")",
":",
"if",
"repertoire",
"is",
"None",
":",
"return",
"None",
"return",
"tuple",
"(",
"i",
"for",
"i",
",",
"dim",
"in",
"enumerate",
"(",
"repertoire",
".",
"shape",
")",
"if",
"dim",
"==",
"2",
")"
] | The purview of the repertoire.
Args:
repertoire (np.ndarray): A repertoire
Returns:
tuple[int]: The purview that the repertoire was computed over. | [
"The",
"purview",
"of",
"the",
"repertoire",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/distribution.py#L81-L93 | train |
wmayner/pyphi | pyphi/distribution.py | flatten | def flatten(repertoire, big_endian=False):
"""Flatten a repertoire, removing empty dimensions.
By default, the flattened repertoire is returned in little-endian order.
Args:
repertoire (np.ndarray or None): A repertoire.
Keyword Args:
big_endian (boolean): If ``True``, flatten the rep... | python | def flatten(repertoire, big_endian=False):
"""Flatten a repertoire, removing empty dimensions.
By default, the flattened repertoire is returned in little-endian order.
Args:
repertoire (np.ndarray or None): A repertoire.
Keyword Args:
big_endian (boolean): If ``True``, flatten the rep... | [
"def",
"flatten",
"(",
"repertoire",
",",
"big_endian",
"=",
"False",
")",
":",
"if",
"repertoire",
"is",
"None",
":",
"return",
"None",
"order",
"=",
"'C'",
"if",
"big_endian",
"else",
"'F'",
"# For efficiency, use `ravel` (which returns a view of the array) instead"... | Flatten a repertoire, removing empty dimensions.
By default, the flattened repertoire is returned in little-endian order.
Args:
repertoire (np.ndarray or None): A repertoire.
Keyword Args:
big_endian (boolean): If ``True``, flatten the repertoire in big-endian
order.
Retu... | [
"Flatten",
"a",
"repertoire",
"removing",
"empty",
"dimensions",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/distribution.py#L130-L151 | train |
wmayner/pyphi | pyphi/distribution.py | max_entropy_distribution | def max_entropy_distribution(node_indices, number_of_nodes):
"""Return the maximum entropy distribution over a set of nodes.
This is different from the network's uniform distribution because nodes
outside ``node_indices`` are fixed and treated as if they have only 1
state.
Args:
node_indic... | python | def max_entropy_distribution(node_indices, number_of_nodes):
"""Return the maximum entropy distribution over a set of nodes.
This is different from the network's uniform distribution because nodes
outside ``node_indices`` are fixed and treated as if they have only 1
state.
Args:
node_indic... | [
"def",
"max_entropy_distribution",
"(",
"node_indices",
",",
"number_of_nodes",
")",
":",
"distribution",
"=",
"np",
".",
"ones",
"(",
"repertoire_shape",
"(",
"node_indices",
",",
"number_of_nodes",
")",
")",
"return",
"distribution",
"/",
"distribution",
".",
"s... | Return the maximum entropy distribution over a set of nodes.
This is different from the network's uniform distribution because nodes
outside ``node_indices`` are fixed and treated as if they have only 1
state.
Args:
node_indices (tuple[int]): The set of node indices over which to take
... | [
"Return",
"the",
"maximum",
"entropy",
"distribution",
"over",
"a",
"set",
"of",
"nodes",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/distribution.py#L155-L172 | train |
wmayner/pyphi | pyphi/macro.py | run_tpm | def run_tpm(system, steps, blackbox):
"""Iterate the TPM for the given number of timesteps.
Returns:
np.ndarray: tpm * (noise_tpm^(t-1))
"""
# Generate noised TPM
# Noise the connections from every output element to elements in other
# boxes.
node_tpms = []
for node in system.no... | python | def run_tpm(system, steps, blackbox):
"""Iterate the TPM for the given number of timesteps.
Returns:
np.ndarray: tpm * (noise_tpm^(t-1))
"""
# Generate noised TPM
# Noise the connections from every output element to elements in other
# boxes.
node_tpms = []
for node in system.no... | [
"def",
"run_tpm",
"(",
"system",
",",
"steps",
",",
"blackbox",
")",
":",
"# Generate noised TPM",
"# Noise the connections from every output element to elements in other",
"# boxes.",
"node_tpms",
"=",
"[",
"]",
"for",
"node",
"in",
"system",
".",
"nodes",
":",
"node... | Iterate the TPM for the given number of timesteps.
Returns:
np.ndarray: tpm * (noise_tpm^(t-1)) | [
"Iterate",
"the",
"TPM",
"for",
"the",
"given",
"number",
"of",
"timesteps",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L61-L88 | train |
wmayner/pyphi | pyphi/macro.py | _partitions_list | def _partitions_list(N):
"""Return a list of partitions of the |N| binary nodes.
Args:
N (int): The number of nodes under consideration.
Returns:
list[list]: A list of lists, where each inner list is the set of
micro-elements corresponding to a macro-element.
Example:
... | python | def _partitions_list(N):
"""Return a list of partitions of the |N| binary nodes.
Args:
N (int): The number of nodes under consideration.
Returns:
list[list]: A list of lists, where each inner list is the set of
micro-elements corresponding to a macro-element.
Example:
... | [
"def",
"_partitions_list",
"(",
"N",
")",
":",
"if",
"N",
"<",
"(",
"_NUM_PRECOMPUTED_PARTITION_LISTS",
")",
":",
"return",
"list",
"(",
"_partition_lists",
"[",
"N",
"]",
")",
"else",
":",
"raise",
"ValueError",
"(",
"'Partition lists not yet available for system... | Return a list of partitions of the |N| binary nodes.
Args:
N (int): The number of nodes under consideration.
Returns:
list[list]: A list of lists, where each inner list is the set of
micro-elements corresponding to a macro-element.
Example:
>>> _partitions_list(3)
... | [
"Return",
"a",
"list",
"of",
"partitions",
"of",
"the",
"|N|",
"binary",
"nodes",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L665-L684 | train |
wmayner/pyphi | pyphi/macro.py | all_partitions | def all_partitions(indices):
"""Return a list of all possible coarse grains of a network.
Args:
indices (tuple[int]): The micro indices to partition.
Yields:
tuple[tuple]: A possible partition. Each element of the tuple
is a tuple of micro-elements which correspond to macro-element... | python | def all_partitions(indices):
"""Return a list of all possible coarse grains of a network.
Args:
indices (tuple[int]): The micro indices to partition.
Yields:
tuple[tuple]: A possible partition. Each element of the tuple
is a tuple of micro-elements which correspond to macro-element... | [
"def",
"all_partitions",
"(",
"indices",
")",
":",
"n",
"=",
"len",
"(",
"indices",
")",
"partitions",
"=",
"_partitions_list",
"(",
"n",
")",
"if",
"n",
">",
"0",
":",
"partitions",
"[",
"-",
"1",
"]",
"=",
"[",
"list",
"(",
"range",
"(",
"n",
"... | Return a list of all possible coarse grains of a network.
Args:
indices (tuple[int]): The micro indices to partition.
Yields:
tuple[tuple]: A possible partition. Each element of the tuple
is a tuple of micro-elements which correspond to macro-elements. | [
"Return",
"a",
"list",
"of",
"all",
"possible",
"coarse",
"grains",
"of",
"a",
"network",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L687-L704 | train |
wmayner/pyphi | pyphi/macro.py | all_coarse_grains | def all_coarse_grains(indices):
"""Generator over all possible |CoarseGrains| of these indices.
Args:
indices (tuple[int]): Node indices to coarse grain.
Yields:
CoarseGrain: The next |CoarseGrain| for ``indices``.
"""
for partition in all_partitions(indices):
for grouping ... | python | def all_coarse_grains(indices):
"""Generator over all possible |CoarseGrains| of these indices.
Args:
indices (tuple[int]): Node indices to coarse grain.
Yields:
CoarseGrain: The next |CoarseGrain| for ``indices``.
"""
for partition in all_partitions(indices):
for grouping ... | [
"def",
"all_coarse_grains",
"(",
"indices",
")",
":",
"for",
"partition",
"in",
"all_partitions",
"(",
"indices",
")",
":",
"for",
"grouping",
"in",
"all_groupings",
"(",
"partition",
")",
":",
"yield",
"CoarseGrain",
"(",
"partition",
",",
"grouping",
")"
] | Generator over all possible |CoarseGrains| of these indices.
Args:
indices (tuple[int]): Node indices to coarse grain.
Yields:
CoarseGrain: The next |CoarseGrain| for ``indices``. | [
"Generator",
"over",
"all",
"possible",
"|CoarseGrains|",
"of",
"these",
"indices",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L734-L745 | train |
wmayner/pyphi | pyphi/macro.py | all_coarse_grains_for_blackbox | def all_coarse_grains_for_blackbox(blackbox):
"""Generator over all |CoarseGrains| for the given blackbox.
If a box has multiple outputs, those outputs are partitioned into the same
coarse-grain macro-element.
"""
for partition in all_partitions(blackbox.output_indices):
for grouping in all... | python | def all_coarse_grains_for_blackbox(blackbox):
"""Generator over all |CoarseGrains| for the given blackbox.
If a box has multiple outputs, those outputs are partitioned into the same
coarse-grain macro-element.
"""
for partition in all_partitions(blackbox.output_indices):
for grouping in all... | [
"def",
"all_coarse_grains_for_blackbox",
"(",
"blackbox",
")",
":",
"for",
"partition",
"in",
"all_partitions",
"(",
"blackbox",
".",
"output_indices",
")",
":",
"for",
"grouping",
"in",
"all_groupings",
"(",
"partition",
")",
":",
"coarse_grain",
"=",
"CoarseGrai... | Generator over all |CoarseGrains| for the given blackbox.
If a box has multiple outputs, those outputs are partitioned into the same
coarse-grain macro-element. | [
"Generator",
"over",
"all",
"|CoarseGrains|",
"for",
"the",
"given",
"blackbox",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L748-L761 | train |
wmayner/pyphi | pyphi/macro.py | all_blackboxes | def all_blackboxes(indices):
"""Generator over all possible blackboxings of these indices.
Args:
indices (tuple[int]): Nodes to blackbox.
Yields:
Blackbox: The next |Blackbox| of ``indices``.
"""
for partition in all_partitions(indices):
# TODO? don't consider the empty set... | python | def all_blackboxes(indices):
"""Generator over all possible blackboxings of these indices.
Args:
indices (tuple[int]): Nodes to blackbox.
Yields:
Blackbox: The next |Blackbox| of ``indices``.
"""
for partition in all_partitions(indices):
# TODO? don't consider the empty set... | [
"def",
"all_blackboxes",
"(",
"indices",
")",
":",
"for",
"partition",
"in",
"all_partitions",
"(",
"indices",
")",
":",
"# TODO? don't consider the empty set here",
"# (pass `nonempty=True` to `powerset`)",
"for",
"output_indices",
"in",
"utils",
".",
"powerset",
"(",
... | Generator over all possible blackboxings of these indices.
Args:
indices (tuple[int]): Nodes to blackbox.
Yields:
Blackbox: The next |Blackbox| of ``indices``. | [
"Generator",
"over",
"all",
"possible",
"blackboxings",
"of",
"these",
"indices",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L764-L782 | train |
wmayner/pyphi | pyphi/macro.py | coarse_graining | def coarse_graining(network, state, internal_indices):
"""Find the maximal coarse-graining of a micro-system.
Args:
network (Network): The network in question.
state (tuple[int]): The state of the network.
internal_indices (tuple[int]): Nodes in the micro-system.
Returns:
t... | python | def coarse_graining(network, state, internal_indices):
"""Find the maximal coarse-graining of a micro-system.
Args:
network (Network): The network in question.
state (tuple[int]): The state of the network.
internal_indices (tuple[int]): Nodes in the micro-system.
Returns:
t... | [
"def",
"coarse_graining",
"(",
"network",
",",
"state",
",",
"internal_indices",
")",
":",
"max_phi",
"=",
"float",
"(",
"'-inf'",
")",
"max_coarse_grain",
"=",
"CoarseGrain",
"(",
"(",
")",
",",
"(",
")",
")",
"for",
"coarse_grain",
"in",
"all_coarse_grains... | Find the maximal coarse-graining of a micro-system.
Args:
network (Network): The network in question.
state (tuple[int]): The state of the network.
internal_indices (tuple[int]): Nodes in the micro-system.
Returns:
tuple[int, CoarseGrain]: The phi-value of the maximal |CoarseGr... | [
"Find",
"the",
"maximal",
"coarse",
"-",
"graining",
"of",
"a",
"micro",
"-",
"system",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L827-L853 | train |
wmayner/pyphi | pyphi/macro.py | all_macro_systems | def all_macro_systems(network, state, do_blackbox=False, do_coarse_grain=False,
time_scales=None):
"""Generator over all possible macro-systems for the network."""
if time_scales is None:
time_scales = [1]
def blackboxes(system):
# Returns all blackboxes to evaluate
... | python | def all_macro_systems(network, state, do_blackbox=False, do_coarse_grain=False,
time_scales=None):
"""Generator over all possible macro-systems for the network."""
if time_scales is None:
time_scales = [1]
def blackboxes(system):
# Returns all blackboxes to evaluate
... | [
"def",
"all_macro_systems",
"(",
"network",
",",
"state",
",",
"do_blackbox",
"=",
"False",
",",
"do_coarse_grain",
"=",
"False",
",",
"time_scales",
"=",
"None",
")",
":",
"if",
"time_scales",
"is",
"None",
":",
"time_scales",
"=",
"[",
"1",
"]",
"def",
... | Generator over all possible macro-systems for the network. | [
"Generator",
"over",
"all",
"possible",
"macro",
"-",
"systems",
"for",
"the",
"network",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L857-L891 | train |
wmayner/pyphi | pyphi/macro.py | emergence | def emergence(network, state, do_blackbox=False, do_coarse_grain=True,
time_scales=None):
"""Check for the emergence of a micro-system into a macro-system.
Checks all possible blackboxings and coarse-grainings of a system to find
the spatial scale with maximum integrated information.
Use... | python | def emergence(network, state, do_blackbox=False, do_coarse_grain=True,
time_scales=None):
"""Check for the emergence of a micro-system into a macro-system.
Checks all possible blackboxings and coarse-grainings of a system to find
the spatial scale with maximum integrated information.
Use... | [
"def",
"emergence",
"(",
"network",
",",
"state",
",",
"do_blackbox",
"=",
"False",
",",
"do_coarse_grain",
"=",
"True",
",",
"time_scales",
"=",
"None",
")",
":",
"micro_phi",
"=",
"compute",
".",
"major_complex",
"(",
"network",
",",
"state",
")",
".",
... | Check for the emergence of a micro-system into a macro-system.
Checks all possible blackboxings and coarse-grainings of a system to find
the spatial scale with maximum integrated information.
Use the ``do_blackbox`` and ``do_coarse_grain`` args to specifiy whether to
use blackboxing, coarse-graining, ... | [
"Check",
"for",
"the",
"emergence",
"of",
"a",
"micro",
"-",
"system",
"into",
"a",
"macro",
"-",
"system",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L894-L940 | train |
wmayner/pyphi | pyphi/macro.py | effective_info | def effective_info(network):
"""Return the effective information of the given network.
.. note::
For details, see:
Hoel, Erik P., Larissa Albantakis, and Giulio Tononi.
“Quantifying causal emergence shows that macro can beat micro.”
Proceedings of the
National Academy o... | python | def effective_info(network):
"""Return the effective information of the given network.
.. note::
For details, see:
Hoel, Erik P., Larissa Albantakis, and Giulio Tononi.
“Quantifying causal emergence shows that macro can beat micro.”
Proceedings of the
National Academy o... | [
"def",
"effective_info",
"(",
"network",
")",
":",
"validate",
".",
"is_network",
"(",
"network",
")",
"sbs_tpm",
"=",
"convert",
".",
"state_by_node2state_by_state",
"(",
"network",
".",
"tpm",
")",
"avg_repertoire",
"=",
"np",
".",
"mean",
"(",
"sbs_tpm",
... | Return the effective information of the given network.
.. note::
For details, see:
Hoel, Erik P., Larissa Albantakis, and Giulio Tononi.
“Quantifying causal emergence shows that macro can beat micro.”
Proceedings of the
National Academy of Sciences 110.49 (2013): 19790-1979... | [
"Return",
"the",
"effective",
"information",
"of",
"the",
"given",
"network",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L969-L989 | train |
wmayner/pyphi | pyphi/macro.py | SystemAttrs.node_labels | def node_labels(self):
"""Return the labels for macro nodes."""
assert list(self.node_indices)[0] == 0
labels = list("m{}".format(i) for i in self.node_indices)
return NodeLabels(labels, self.node_indices) | python | def node_labels(self):
"""Return the labels for macro nodes."""
assert list(self.node_indices)[0] == 0
labels = list("m{}".format(i) for i in self.node_indices)
return NodeLabels(labels, self.node_indices) | [
"def",
"node_labels",
"(",
"self",
")",
":",
"assert",
"list",
"(",
"self",
".",
"node_indices",
")",
"[",
"0",
"]",
"==",
"0",
"labels",
"=",
"list",
"(",
"\"m{}\"",
".",
"format",
"(",
"i",
")",
"for",
"i",
"in",
"self",
".",
"node_indices",
")",... | Return the labels for macro nodes. | [
"Return",
"the",
"labels",
"for",
"macro",
"nodes",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L99-L103 | train |
wmayner/pyphi | pyphi/macro.py | MacroSubsystem._squeeze | def _squeeze(system):
"""Squeeze out all singleton dimensions in the Subsystem.
Reindexes the subsystem so that the nodes are ``0..n`` where ``n`` is
the number of internal indices in the system.
"""
assert system.node_indices == tpm_indices(system.tpm)
internal_indices... | python | def _squeeze(system):
"""Squeeze out all singleton dimensions in the Subsystem.
Reindexes the subsystem so that the nodes are ``0..n`` where ``n`` is
the number of internal indices in the system.
"""
assert system.node_indices == tpm_indices(system.tpm)
internal_indices... | [
"def",
"_squeeze",
"(",
"system",
")",
":",
"assert",
"system",
".",
"node_indices",
"==",
"tpm_indices",
"(",
"system",
".",
"tpm",
")",
"internal_indices",
"=",
"tpm_indices",
"(",
"system",
".",
"tpm",
")",
"tpm",
"=",
"remove_singleton_dimensions",
"(",
... | Squeeze out all singleton dimensions in the Subsystem.
Reindexes the subsystem so that the nodes are ``0..n`` where ``n`` is
the number of internal indices in the system. | [
"Squeeze",
"out",
"all",
"singleton",
"dimensions",
"in",
"the",
"Subsystem",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L199-L225 | train |
wmayner/pyphi | pyphi/macro.py | MacroSubsystem._blackbox_partial_noise | def _blackbox_partial_noise(blackbox, system):
"""Noise connections from hidden elements to other boxes."""
# Noise inputs from non-output elements hidden in other boxes
node_tpms = []
for node in system.nodes:
node_tpm = node.tpm_on
for input_node in node.inputs:... | python | def _blackbox_partial_noise(blackbox, system):
"""Noise connections from hidden elements to other boxes."""
# Noise inputs from non-output elements hidden in other boxes
node_tpms = []
for node in system.nodes:
node_tpm = node.tpm_on
for input_node in node.inputs:... | [
"def",
"_blackbox_partial_noise",
"(",
"blackbox",
",",
"system",
")",
":",
"# Noise inputs from non-output elements hidden in other boxes",
"node_tpms",
"=",
"[",
"]",
"for",
"node",
"in",
"system",
".",
"nodes",
":",
"node_tpm",
"=",
"node",
".",
"tpm_on",
"for",
... | Noise connections from hidden elements to other boxes. | [
"Noise",
"connections",
"from",
"hidden",
"elements",
"to",
"other",
"boxes",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L228-L242 | train |
wmayner/pyphi | pyphi/macro.py | MacroSubsystem._blackbox_time | def _blackbox_time(time_scale, blackbox, system):
"""Black box the CM and TPM over the given time_scale."""
blackbox = blackbox.reindex()
tpm = run_tpm(system, time_scale, blackbox)
# Universal connectivity, for now.
n = len(system.node_indices)
cm = np.ones((n, n))
... | python | def _blackbox_time(time_scale, blackbox, system):
"""Black box the CM and TPM over the given time_scale."""
blackbox = blackbox.reindex()
tpm = run_tpm(system, time_scale, blackbox)
# Universal connectivity, for now.
n = len(system.node_indices)
cm = np.ones((n, n))
... | [
"def",
"_blackbox_time",
"(",
"time_scale",
",",
"blackbox",
",",
"system",
")",
":",
"blackbox",
"=",
"blackbox",
".",
"reindex",
"(",
")",
"tpm",
"=",
"run_tpm",
"(",
"system",
",",
"time_scale",
",",
"blackbox",
")",
"# Universal connectivity, for now.",
"n... | Black box the CM and TPM over the given time_scale. | [
"Black",
"box",
"the",
"CM",
"and",
"TPM",
"over",
"the",
"given",
"time_scale",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L245-L255 | train |
wmayner/pyphi | pyphi/macro.py | MacroSubsystem._blackbox_space | def _blackbox_space(self, blackbox, system):
"""Blackbox the TPM and CM in space.
Conditions the TPM on the current value of the hidden nodes. The CM is
set to universal connectivity.
.. TODO: change this ^
This shrinks the size of the TPM by the number of hidden indices; now
... | python | def _blackbox_space(self, blackbox, system):
"""Blackbox the TPM and CM in space.
Conditions the TPM on the current value of the hidden nodes. The CM is
set to universal connectivity.
.. TODO: change this ^
This shrinks the size of the TPM by the number of hidden indices; now
... | [
"def",
"_blackbox_space",
"(",
"self",
",",
"blackbox",
",",
"system",
")",
":",
"tpm",
"=",
"marginalize_out",
"(",
"blackbox",
".",
"hidden_indices",
",",
"system",
".",
"tpm",
")",
"assert",
"blackbox",
".",
"output_indices",
"==",
"tpm_indices",
"(",
"tp... | Blackbox the TPM and CM in space.
Conditions the TPM on the current value of the hidden nodes. The CM is
set to universal connectivity.
.. TODO: change this ^
This shrinks the size of the TPM by the number of hidden indices; now
there is only `len(output_indices)` dimensions i... | [
"Blackbox",
"the",
"TPM",
"and",
"CM",
"in",
"space",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L257-L286 | train |
wmayner/pyphi | pyphi/macro.py | MacroSubsystem._coarsegrain_space | def _coarsegrain_space(coarse_grain, is_cut, system):
"""Spatially coarse-grain the TPM and CM."""
tpm = coarse_grain.macro_tpm(
system.tpm, check_independence=(not is_cut))
node_indices = coarse_grain.macro_indices
state = coarse_grain.macro_state(system.state)
# U... | python | def _coarsegrain_space(coarse_grain, is_cut, system):
"""Spatially coarse-grain the TPM and CM."""
tpm = coarse_grain.macro_tpm(
system.tpm, check_independence=(not is_cut))
node_indices = coarse_grain.macro_indices
state = coarse_grain.macro_state(system.state)
# U... | [
"def",
"_coarsegrain_space",
"(",
"coarse_grain",
",",
"is_cut",
",",
"system",
")",
":",
"tpm",
"=",
"coarse_grain",
".",
"macro_tpm",
"(",
"system",
".",
"tpm",
",",
"check_independence",
"=",
"(",
"not",
"is_cut",
")",
")",
"node_indices",
"=",
"coarse_gr... | Spatially coarse-grain the TPM and CM. | [
"Spatially",
"coarse",
"-",
"grain",
"the",
"TPM",
"and",
"CM",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L289-L301 | train |
wmayner/pyphi | pyphi/macro.py | MacroSubsystem.cut_mechanisms | def cut_mechanisms(self):
"""The mechanisms of this system that are currently cut.
Note that although ``cut_indices`` returns micro indices, this
returns macro mechanisms.
Yields:
tuple[int]
"""
for mechanism in utils.powerset(self.node_indices, nonempty=Tru... | python | def cut_mechanisms(self):
"""The mechanisms of this system that are currently cut.
Note that although ``cut_indices`` returns micro indices, this
returns macro mechanisms.
Yields:
tuple[int]
"""
for mechanism in utils.powerset(self.node_indices, nonempty=Tru... | [
"def",
"cut_mechanisms",
"(",
"self",
")",
":",
"for",
"mechanism",
"in",
"utils",
".",
"powerset",
"(",
"self",
".",
"node_indices",
",",
"nonempty",
"=",
"True",
")",
":",
"micro_mechanism",
"=",
"self",
".",
"macro2micro",
"(",
"mechanism",
")",
"if",
... | The mechanisms of this system that are currently cut.
Note that although ``cut_indices`` returns micro indices, this
returns macro mechanisms.
Yields:
tuple[int] | [
"The",
"mechanisms",
"of",
"this",
"system",
"that",
"are",
"currently",
"cut",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L313-L325 | train |
wmayner/pyphi | pyphi/macro.py | MacroSubsystem.apply_cut | def apply_cut(self, cut):
"""Return a cut version of this |MacroSubsystem|.
Args:
cut (Cut): The cut to apply to this |MacroSubsystem|.
Returns:
MacroSubsystem: The cut version of this |MacroSubsystem|.
"""
# TODO: is the MICE cache reusable?
ret... | python | def apply_cut(self, cut):
"""Return a cut version of this |MacroSubsystem|.
Args:
cut (Cut): The cut to apply to this |MacroSubsystem|.
Returns:
MacroSubsystem: The cut version of this |MacroSubsystem|.
"""
# TODO: is the MICE cache reusable?
ret... | [
"def",
"apply_cut",
"(",
"self",
",",
"cut",
")",
":",
"# TODO: is the MICE cache reusable?",
"return",
"MacroSubsystem",
"(",
"self",
".",
"network",
",",
"self",
".",
"network_state",
",",
"self",
".",
"micro_node_indices",
",",
"cut",
"=",
"cut",
",",
"time... | Return a cut version of this |MacroSubsystem|.
Args:
cut (Cut): The cut to apply to this |MacroSubsystem|.
Returns:
MacroSubsystem: The cut version of this |MacroSubsystem|. | [
"Return",
"a",
"cut",
"version",
"of",
"this",
"|MacroSubsystem|",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L335-L352 | train |
wmayner/pyphi | pyphi/macro.py | MacroSubsystem.potential_purviews | def potential_purviews(self, direction, mechanism, purviews=False):
"""Override Subsystem implementation using Network-level indices."""
all_purviews = utils.powerset(self.node_indices)
return irreducible_purviews(
self.cm, direction, mechanism, all_purviews) | python | def potential_purviews(self, direction, mechanism, purviews=False):
"""Override Subsystem implementation using Network-level indices."""
all_purviews = utils.powerset(self.node_indices)
return irreducible_purviews(
self.cm, direction, mechanism, all_purviews) | [
"def",
"potential_purviews",
"(",
"self",
",",
"direction",
",",
"mechanism",
",",
"purviews",
"=",
"False",
")",
":",
"all_purviews",
"=",
"utils",
".",
"powerset",
"(",
"self",
".",
"node_indices",
")",
"return",
"irreducible_purviews",
"(",
"self",
".",
"... | Override Subsystem implementation using Network-level indices. | [
"Override",
"Subsystem",
"implementation",
"using",
"Network",
"-",
"level",
"indices",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L354-L358 | train |
wmayner/pyphi | pyphi/macro.py | MacroSubsystem.macro2micro | def macro2micro(self, macro_indices):
"""Return all micro indices which compose the elements specified by
``macro_indices``.
"""
def from_partition(partition, macro_indices):
micro_indices = itertools.chain.from_iterable(
partition[i] for i in macro_indices)
... | python | def macro2micro(self, macro_indices):
"""Return all micro indices which compose the elements specified by
``macro_indices``.
"""
def from_partition(partition, macro_indices):
micro_indices = itertools.chain.from_iterable(
partition[i] for i in macro_indices)
... | [
"def",
"macro2micro",
"(",
"self",
",",
"macro_indices",
")",
":",
"def",
"from_partition",
"(",
"partition",
",",
"macro_indices",
")",
":",
"micro_indices",
"=",
"itertools",
".",
"chain",
".",
"from_iterable",
"(",
"partition",
"[",
"i",
"]",
"for",
"i",
... | Return all micro indices which compose the elements specified by
``macro_indices``. | [
"Return",
"all",
"micro",
"indices",
"which",
"compose",
"the",
"elements",
"specified",
"by",
"macro_indices",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L360-L378 | train |
wmayner/pyphi | pyphi/macro.py | MacroSubsystem.macro2blackbox_outputs | def macro2blackbox_outputs(self, macro_indices):
"""Given a set of macro elements, return the blackbox output elements
which compose these elements.
"""
if not self.blackbox:
raise ValueError('System is not blackboxed')
return tuple(sorted(set(
self.macro... | python | def macro2blackbox_outputs(self, macro_indices):
"""Given a set of macro elements, return the blackbox output elements
which compose these elements.
"""
if not self.blackbox:
raise ValueError('System is not blackboxed')
return tuple(sorted(set(
self.macro... | [
"def",
"macro2blackbox_outputs",
"(",
"self",
",",
"macro_indices",
")",
":",
"if",
"not",
"self",
".",
"blackbox",
":",
"raise",
"ValueError",
"(",
"'System is not blackboxed'",
")",
"return",
"tuple",
"(",
"sorted",
"(",
"set",
"(",
"self",
".",
"macro2micro... | Given a set of macro elements, return the blackbox output elements
which compose these elements. | [
"Given",
"a",
"set",
"of",
"macro",
"elements",
"return",
"the",
"blackbox",
"output",
"elements",
"which",
"compose",
"these",
"elements",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L380-L389 | train |
wmayner/pyphi | pyphi/macro.py | CoarseGrain.micro_indices | def micro_indices(self):
"""Indices of micro elements represented in this coarse-graining."""
return tuple(sorted(idx for part in self.partition for idx in part)) | python | def micro_indices(self):
"""Indices of micro elements represented in this coarse-graining."""
return tuple(sorted(idx for part in self.partition for idx in part)) | [
"def",
"micro_indices",
"(",
"self",
")",
":",
"return",
"tuple",
"(",
"sorted",
"(",
"idx",
"for",
"part",
"in",
"self",
".",
"partition",
"for",
"idx",
"in",
"part",
")",
")"
] | Indices of micro elements represented in this coarse-graining. | [
"Indices",
"of",
"micro",
"elements",
"represented",
"in",
"this",
"coarse",
"-",
"graining",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L430-L432 | train |
wmayner/pyphi | pyphi/macro.py | CoarseGrain.reindex | def reindex(self):
"""Re-index this coarse graining to use squeezed indices.
The output grouping is translated to use indices ``0..n``, where ``n``
is the number of micro indices in the coarse-graining. Re-indexing does
not effect the state grouping, which is already index-independent.
... | python | def reindex(self):
"""Re-index this coarse graining to use squeezed indices.
The output grouping is translated to use indices ``0..n``, where ``n``
is the number of micro indices in the coarse-graining. Re-indexing does
not effect the state grouping, which is already index-independent.
... | [
"def",
"reindex",
"(",
"self",
")",
":",
"_map",
"=",
"dict",
"(",
"zip",
"(",
"self",
".",
"micro_indices",
",",
"reindex",
"(",
"self",
".",
"micro_indices",
")",
")",
")",
"partition",
"=",
"tuple",
"(",
"tuple",
"(",
"_map",
"[",
"index",
"]",
... | Re-index this coarse graining to use squeezed indices.
The output grouping is translated to use indices ``0..n``, where ``n``
is the number of micro indices in the coarse-graining. Re-indexing does
not effect the state grouping, which is already index-independent.
Returns:
... | [
"Re",
"-",
"index",
"this",
"coarse",
"graining",
"to",
"use",
"squeezed",
"indices",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L442-L464 | train |
wmayner/pyphi | pyphi/macro.py | CoarseGrain.macro_state | def macro_state(self, micro_state):
"""Translate a micro state to a macro state
Args:
micro_state (tuple[int]): The state of the micro nodes in this
coarse-graining.
Returns:
tuple[int]: The state of the macro system, translated as specified
... | python | def macro_state(self, micro_state):
"""Translate a micro state to a macro state
Args:
micro_state (tuple[int]): The state of the micro nodes in this
coarse-graining.
Returns:
tuple[int]: The state of the macro system, translated as specified
... | [
"def",
"macro_state",
"(",
"self",
",",
"micro_state",
")",
":",
"assert",
"len",
"(",
"micro_state",
")",
"==",
"len",
"(",
"self",
".",
"micro_indices",
")",
"# TODO: only reindex if this coarse grain is not already from 0..n?",
"# make_mapping calls this in a tight loop ... | Translate a micro state to a macro state
Args:
micro_state (tuple[int]): The state of the micro nodes in this
coarse-graining.
Returns:
tuple[int]: The state of the macro system, translated as specified
by this coarse-graining.
Example:
... | [
"Translate",
"a",
"micro",
"state",
"to",
"a",
"macro",
"state"
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L466-L496 | train |
wmayner/pyphi | pyphi/macro.py | CoarseGrain.make_mapping | def make_mapping(self):
"""Return a mapping from micro-state to the macro-states based on the
partition and state grouping of this coarse-grain.
Return:
(nd.ndarray): A mapping from micro-states to macro-states. The
|ith| entry in the mapping is the macro-state correspon... | python | def make_mapping(self):
"""Return a mapping from micro-state to the macro-states based on the
partition and state grouping of this coarse-grain.
Return:
(nd.ndarray): A mapping from micro-states to macro-states. The
|ith| entry in the mapping is the macro-state correspon... | [
"def",
"make_mapping",
"(",
"self",
")",
":",
"micro_states",
"=",
"utils",
".",
"all_states",
"(",
"len",
"(",
"self",
".",
"micro_indices",
")",
")",
"# Find the corresponding macro-state for each micro-state.",
"# The i-th entry in the mapping is the macro-state correspond... | Return a mapping from micro-state to the macro-states based on the
partition and state grouping of this coarse-grain.
Return:
(nd.ndarray): A mapping from micro-states to macro-states. The
|ith| entry in the mapping is the macro-state corresponding to the
|ith| micro... | [
"Return",
"a",
"mapping",
"from",
"micro",
"-",
"state",
"to",
"the",
"macro",
"-",
"states",
"based",
"on",
"the",
"partition",
"and",
"state",
"grouping",
"of",
"this",
"coarse",
"-",
"grain",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L498-L514 | train |
wmayner/pyphi | pyphi/macro.py | CoarseGrain.macro_tpm_sbs | def macro_tpm_sbs(self, state_by_state_micro_tpm):
"""Create a state-by-state coarse-grained macro TPM.
Args:
micro_tpm (nd.array): The state-by-state TPM of the micro-system.
Returns:
np.ndarray: The state-by-state TPM of the macro-system.
"""
validate.... | python | def macro_tpm_sbs(self, state_by_state_micro_tpm):
"""Create a state-by-state coarse-grained macro TPM.
Args:
micro_tpm (nd.array): The state-by-state TPM of the micro-system.
Returns:
np.ndarray: The state-by-state TPM of the macro-system.
"""
validate.... | [
"def",
"macro_tpm_sbs",
"(",
"self",
",",
"state_by_state_micro_tpm",
")",
":",
"validate",
".",
"tpm",
"(",
"state_by_state_micro_tpm",
",",
"check_independence",
"=",
"False",
")",
"mapping",
"=",
"self",
".",
"make_mapping",
"(",
")",
"num_macro_states",
"=",
... | Create a state-by-state coarse-grained macro TPM.
Args:
micro_tpm (nd.array): The state-by-state TPM of the micro-system.
Returns:
np.ndarray: The state-by-state TPM of the macro-system. | [
"Create",
"a",
"state",
"-",
"by",
"-",
"state",
"coarse",
"-",
"grained",
"macro",
"TPM",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L516-L543 | train |
wmayner/pyphi | pyphi/macro.py | CoarseGrain.macro_tpm | def macro_tpm(self, micro_tpm, check_independence=True):
"""Create a coarse-grained macro TPM.
Args:
micro_tpm (nd.array): The TPM of the micro-system.
check_independence (bool): Whether to check that the macro TPM is
conditionally independent.
Raises:
... | python | def macro_tpm(self, micro_tpm, check_independence=True):
"""Create a coarse-grained macro TPM.
Args:
micro_tpm (nd.array): The TPM of the micro-system.
check_independence (bool): Whether to check that the macro TPM is
conditionally independent.
Raises:
... | [
"def",
"macro_tpm",
"(",
"self",
",",
"micro_tpm",
",",
"check_independence",
"=",
"True",
")",
":",
"if",
"not",
"is_state_by_state",
"(",
"micro_tpm",
")",
":",
"micro_tpm",
"=",
"convert",
".",
"state_by_node2state_by_state",
"(",
"micro_tpm",
")",
"macro_tpm... | Create a coarse-grained macro TPM.
Args:
micro_tpm (nd.array): The TPM of the micro-system.
check_independence (bool): Whether to check that the macro TPM is
conditionally independent.
Raises:
ConditionallyDependentError: If ``check_independence`` is... | [
"Create",
"a",
"coarse",
"-",
"grained",
"macro",
"TPM",
"."
] | deeca69a084d782a6fde7bf26f59e93b593c5d77 | https://github.com/wmayner/pyphi/blob/deeca69a084d782a6fde7bf26f59e93b593c5d77/pyphi/macro.py#L545-L568 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.