id int32 0 252k | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
225,200 | google/transitfeed | transitfeed/trip.py | Trip.GetStopTimes | def GetStopTimes(self, problems=None):
"""Return a sorted list of StopTime objects for this trip."""
# In theory problems=None should be safe because data from database has been
# validated. See comment in _LoadStopTimes for why this isn't always true.
cursor = self._schedule._connection.cursor()
cu... | python | def GetStopTimes(self, problems=None):
"""Return a sorted list of StopTime objects for this trip."""
# In theory problems=None should be safe because data from database has been
# validated. See comment in _LoadStopTimes for why this isn't always true.
cursor = self._schedule._connection.cursor()
cu... | [
"def",
"GetStopTimes",
"(",
"self",
",",
"problems",
"=",
"None",
")",
":",
"# In theory problems=None should be safe because data from database has been",
"# validated. See comment in _LoadStopTimes for why this isn't always true.",
"cursor",
"=",
"self",
".",
"_schedule",
".",
... | Return a sorted list of StopTime objects for this trip. | [
"Return",
"a",
"sorted",
"list",
"of",
"StopTime",
"objects",
"for",
"this",
"trip",
"."
] | eb2991a3747ba541b2cb66502b305b6304a1f85f | https://github.com/google/transitfeed/blob/eb2991a3747ba541b2cb66502b305b6304a1f85f/transitfeed/trip.py#L227-L256 |
225,201 | google/transitfeed | transitfeed/trip.py | Trip.GetFrequencyStopTimes | def GetFrequencyStopTimes(self, problems=None):
"""Return a list of StopTime objects for each headway-based run.
Returns:
a list of list of StopTime objects. Each list of StopTime objects
represents one run. If this trip doesn't have headways returns an empty
list.
"""
stoptimes_list ... | python | def GetFrequencyStopTimes(self, problems=None):
"""Return a list of StopTime objects for each headway-based run.
Returns:
a list of list of StopTime objects. Each list of StopTime objects
represents one run. If this trip doesn't have headways returns an empty
list.
"""
stoptimes_list ... | [
"def",
"GetFrequencyStopTimes",
"(",
"self",
",",
"problems",
"=",
"None",
")",
":",
"stoptimes_list",
"=",
"[",
"]",
"# list of stoptime lists to be returned",
"stoptime_pattern",
"=",
"self",
".",
"GetStopTimes",
"(",
")",
"first_secs",
"=",
"stoptime_pattern",
"[... | Return a list of StopTime objects for each headway-based run.
Returns:
a list of list of StopTime objects. Each list of StopTime objects
represents one run. If this trip doesn't have headways returns an empty
list. | [
"Return",
"a",
"list",
"of",
"StopTime",
"objects",
"for",
"each",
"headway",
"-",
"based",
"run",
"."
] | eb2991a3747ba541b2cb66502b305b6304a1f85f | https://github.com/google/transitfeed/blob/eb2991a3747ba541b2cb66502b305b6304a1f85f/transitfeed/trip.py#L265-L301 |
225,202 | google/transitfeed | transitfeed/trip.py | Trip.GetFrequencyStartTimes | def GetFrequencyStartTimes(self):
"""Return a list of start time for each headway-based run.
Returns:
a sorted list of seconds since midnight, the start time of each run. If
this trip doesn't have headways returns an empty list."""
start_times = []
# for each headway period of the trip
... | python | def GetFrequencyStartTimes(self):
"""Return a list of start time for each headway-based run.
Returns:
a sorted list of seconds since midnight, the start time of each run. If
this trip doesn't have headways returns an empty list."""
start_times = []
# for each headway period of the trip
... | [
"def",
"GetFrequencyStartTimes",
"(",
"self",
")",
":",
"start_times",
"=",
"[",
"]",
"# for each headway period of the trip",
"for",
"freq_tuple",
"in",
"self",
".",
"GetFrequencyTuples",
"(",
")",
":",
"(",
"start_secs",
",",
"end_secs",
",",
"headway_secs",
")"... | Return a list of start time for each headway-based run.
Returns:
a sorted list of seconds since midnight, the start time of each run. If
this trip doesn't have headways returns an empty list. | [
"Return",
"a",
"list",
"of",
"start",
"time",
"for",
"each",
"headway",
"-",
"based",
"run",
"."
] | eb2991a3747ba541b2cb66502b305b6304a1f85f | https://github.com/google/transitfeed/blob/eb2991a3747ba541b2cb66502b305b6304a1f85f/transitfeed/trip.py#L327-L343 |
225,203 | google/transitfeed | transitfeed/trip.py | Trip._GenerateStopTimesTuples | def _GenerateStopTimesTuples(self):
"""Generator for rows of the stop_times file"""
stoptimes = self.GetStopTimes()
for i, st in enumerate(stoptimes):
yield st.GetFieldValuesTuple(self.trip_id) | python | def _GenerateStopTimesTuples(self):
"""Generator for rows of the stop_times file"""
stoptimes = self.GetStopTimes()
for i, st in enumerate(stoptimes):
yield st.GetFieldValuesTuple(self.trip_id) | [
"def",
"_GenerateStopTimesTuples",
"(",
"self",
")",
":",
"stoptimes",
"=",
"self",
".",
"GetStopTimes",
"(",
")",
"for",
"i",
",",
"st",
"in",
"enumerate",
"(",
"stoptimes",
")",
":",
"yield",
"st",
".",
"GetFieldValuesTuple",
"(",
"self",
".",
"trip_id",... | Generator for rows of the stop_times file | [
"Generator",
"for",
"rows",
"of",
"the",
"stop_times",
"file"
] | eb2991a3747ba541b2cb66502b305b6304a1f85f | https://github.com/google/transitfeed/blob/eb2991a3747ba541b2cb66502b305b6304a1f85f/transitfeed/trip.py#L362-L366 |
225,204 | google/transitfeed | transitfeed/trip.py | Trip.GetPattern | def GetPattern(self):
"""Return a tuple of Stop objects, in the order visited"""
stoptimes = self.GetStopTimes()
return tuple(st.stop for st in stoptimes) | python | def GetPattern(self):
"""Return a tuple of Stop objects, in the order visited"""
stoptimes = self.GetStopTimes()
return tuple(st.stop for st in stoptimes) | [
"def",
"GetPattern",
"(",
"self",
")",
":",
"stoptimes",
"=",
"self",
".",
"GetStopTimes",
"(",
")",
"return",
"tuple",
"(",
"st",
".",
"stop",
"for",
"st",
"in",
"stoptimes",
")"
] | Return a tuple of Stop objects, in the order visited | [
"Return",
"a",
"tuple",
"of",
"Stop",
"objects",
"in",
"the",
"order",
"visited"
] | eb2991a3747ba541b2cb66502b305b6304a1f85f | https://github.com/google/transitfeed/blob/eb2991a3747ba541b2cb66502b305b6304a1f85f/transitfeed/trip.py#L374-L377 |
225,205 | google/transitfeed | transitfeed/trip.py | Trip.AddHeadwayPeriodObject | def AddHeadwayPeriodObject(self, headway_period, problem_reporter):
"""Deprecated. Please use AddFrequencyObject instead."""
warnings.warn("No longer supported. The HeadwayPeriod class was renamed to "
"Frequency, and all related functions were renamed "
"accordingly.", Depre... | python | def AddHeadwayPeriodObject(self, headway_period, problem_reporter):
"""Deprecated. Please use AddFrequencyObject instead."""
warnings.warn("No longer supported. The HeadwayPeriod class was renamed to "
"Frequency, and all related functions were renamed "
"accordingly.", Depre... | [
"def",
"AddHeadwayPeriodObject",
"(",
"self",
",",
"headway_period",
",",
"problem_reporter",
")",
":",
"warnings",
".",
"warn",
"(",
"\"No longer supported. The HeadwayPeriod class was renamed to \"",
"\"Frequency, and all related functions were renamed \"",
"\"accordingly.\"",
",... | Deprecated. Please use AddFrequencyObject instead. | [
"Deprecated",
".",
"Please",
"use",
"AddFrequencyObject",
"instead",
"."
] | eb2991a3747ba541b2cb66502b305b6304a1f85f | https://github.com/google/transitfeed/blob/eb2991a3747ba541b2cb66502b305b6304a1f85f/transitfeed/trip.py#L379-L384 |
225,206 | google/transitfeed | transitfeed/trip.py | Trip.AddFrequencyObject | def AddFrequencyObject(self, frequency, problem_reporter):
"""Add a Frequency object to this trip's list of Frequencies."""
if frequency is not None:
self.AddFrequency(frequency.StartTime(),
frequency.EndTime(),
frequency.HeadwaySecs(),
... | python | def AddFrequencyObject(self, frequency, problem_reporter):
"""Add a Frequency object to this trip's list of Frequencies."""
if frequency is not None:
self.AddFrequency(frequency.StartTime(),
frequency.EndTime(),
frequency.HeadwaySecs(),
... | [
"def",
"AddFrequencyObject",
"(",
"self",
",",
"frequency",
",",
"problem_reporter",
")",
":",
"if",
"frequency",
"is",
"not",
"None",
":",
"self",
".",
"AddFrequency",
"(",
"frequency",
".",
"StartTime",
"(",
")",
",",
"frequency",
".",
"EndTime",
"(",
")... | Add a Frequency object to this trip's list of Frequencies. | [
"Add",
"a",
"Frequency",
"object",
"to",
"this",
"trip",
"s",
"list",
"of",
"Frequencies",
"."
] | eb2991a3747ba541b2cb66502b305b6304a1f85f | https://github.com/google/transitfeed/blob/eb2991a3747ba541b2cb66502b305b6304a1f85f/transitfeed/trip.py#L386-L393 |
225,207 | google/transitfeed | transitfeed/trip.py | Trip.AddHeadwayPeriod | def AddHeadwayPeriod(self, start_time, end_time, headway_secs,
problem_reporter=problems_module.default_problem_reporter):
"""Deprecated. Please use AddFrequency instead."""
warnings.warn("No longer supported. The HeadwayPeriod class was renamed to "
"Frequency, and all related functions... | python | def AddHeadwayPeriod(self, start_time, end_time, headway_secs,
problem_reporter=problems_module.default_problem_reporter):
"""Deprecated. Please use AddFrequency instead."""
warnings.warn("No longer supported. The HeadwayPeriod class was renamed to "
"Frequency, and all related functions... | [
"def",
"AddHeadwayPeriod",
"(",
"self",
",",
"start_time",
",",
"end_time",
",",
"headway_secs",
",",
"problem_reporter",
"=",
"problems_module",
".",
"default_problem_reporter",
")",
":",
"warnings",
".",
"warn",
"(",
"\"No longer supported. The HeadwayPeriod class was r... | Deprecated. Please use AddFrequency instead. | [
"Deprecated",
".",
"Please",
"use",
"AddFrequency",
"instead",
"."
] | eb2991a3747ba541b2cb66502b305b6304a1f85f | https://github.com/google/transitfeed/blob/eb2991a3747ba541b2cb66502b305b6304a1f85f/transitfeed/trip.py#L395-L401 |
225,208 | google/transitfeed | transitfeed/trip.py | Trip.Validate | def Validate(self, problems, validate_children=True):
"""Validate attributes of this object.
Check that this object has all required values set to a valid value without
reference to the rest of the schedule. If the _schedule attribute is set
then check that references such as route_id and service_id ar... | python | def Validate(self, problems, validate_children=True):
"""Validate attributes of this object.
Check that this object has all required values set to a valid value without
reference to the rest of the schedule. If the _schedule attribute is set
then check that references such as route_id and service_id ar... | [
"def",
"Validate",
"(",
"self",
",",
"problems",
",",
"validate_children",
"=",
"True",
")",
":",
"self",
".",
"ValidateRouteId",
"(",
"problems",
")",
"self",
".",
"ValidateServicePeriod",
"(",
"problems",
")",
"self",
".",
"ValidateDirectionId",
"(",
"proble... | Validate attributes of this object.
Check that this object has all required values set to a valid value without
reference to the rest of the schedule. If the _schedule attribute is set
then check that references such as route_id and service_id are correct.
Args:
problems: A ProblemReporter objec... | [
"Validate",
"attributes",
"of",
"this",
"object",
"."
] | eb2991a3747ba541b2cb66502b305b6304a1f85f | https://github.com/google/transitfeed/blob/eb2991a3747ba541b2cb66502b305b6304a1f85f/transitfeed/trip.py#L551-L573 |
225,209 | google/transitfeed | transitfeed/trip.py | Trip.ValidateChildren | def ValidateChildren(self, problems):
"""Validate StopTimes and headways of this trip."""
assert self._schedule, "Trip must be in a schedule to ValidateChildren"
# TODO: validate distance values in stop times (if applicable)
self.ValidateNoDuplicateStopSequences(problems)
stoptimes = self.GetStopTi... | python | def ValidateChildren(self, problems):
"""Validate StopTimes and headways of this trip."""
assert self._schedule, "Trip must be in a schedule to ValidateChildren"
# TODO: validate distance values in stop times (if applicable)
self.ValidateNoDuplicateStopSequences(problems)
stoptimes = self.GetStopTi... | [
"def",
"ValidateChildren",
"(",
"self",
",",
"problems",
")",
":",
"assert",
"self",
".",
"_schedule",
",",
"\"Trip must be in a schedule to ValidateChildren\"",
"# TODO: validate distance values in stop times (if applicable)",
"self",
".",
"ValidateNoDuplicateStopSequences",
"("... | Validate StopTimes and headways of this trip. | [
"Validate",
"StopTimes",
"and",
"headways",
"of",
"this",
"trip",
"."
] | eb2991a3747ba541b2cb66502b305b6304a1f85f | https://github.com/google/transitfeed/blob/eb2991a3747ba541b2cb66502b305b6304a1f85f/transitfeed/trip.py#L697-L711 |
225,210 | google/transitfeed | transitfeed/stoptime.py | StopTime.GetFieldValuesTuple | def GetFieldValuesTuple(self, trip_id):
"""Return a tuple that outputs a row of _FIELD_NAMES to be written to a
GTFS file.
Arguments:
trip_id: The trip_id of the trip to which this StopTime corresponds.
It must be provided, as it is not stored in StopTime.
"""
result = [... | python | def GetFieldValuesTuple(self, trip_id):
"""Return a tuple that outputs a row of _FIELD_NAMES to be written to a
GTFS file.
Arguments:
trip_id: The trip_id of the trip to which this StopTime corresponds.
It must be provided, as it is not stored in StopTime.
"""
result = [... | [
"def",
"GetFieldValuesTuple",
"(",
"self",
",",
"trip_id",
")",
":",
"result",
"=",
"[",
"]",
"for",
"fn",
"in",
"self",
".",
"_FIELD_NAMES",
":",
"if",
"fn",
"==",
"'trip_id'",
":",
"result",
".",
"append",
"(",
"trip_id",
")",
"else",
":",
"# Since w... | Return a tuple that outputs a row of _FIELD_NAMES to be written to a
GTFS file.
Arguments:
trip_id: The trip_id of the trip to which this StopTime corresponds.
It must be provided, as it is not stored in StopTime. | [
"Return",
"a",
"tuple",
"that",
"outputs",
"a",
"row",
"of",
"_FIELD_NAMES",
"to",
"be",
"written",
"to",
"a",
"GTFS",
"file",
"."
] | eb2991a3747ba541b2cb66502b305b6304a1f85f | https://github.com/google/transitfeed/blob/eb2991a3747ba541b2cb66502b305b6304a1f85f/transitfeed/stoptime.py#L165-L181 |
225,211 | google/transitfeed | transitfeed/stoptime.py | StopTime.GetSqlValuesTuple | def GetSqlValuesTuple(self, trip_id):
"""Return a tuple that outputs a row of _FIELD_NAMES to be written to a
SQLite database.
Arguments:
trip_id: The trip_id of the trip to which this StopTime corresponds.
It must be provided, as it is not stored in StopTime.
"""
resul... | python | def GetSqlValuesTuple(self, trip_id):
"""Return a tuple that outputs a row of _FIELD_NAMES to be written to a
SQLite database.
Arguments:
trip_id: The trip_id of the trip to which this StopTime corresponds.
It must be provided, as it is not stored in StopTime.
"""
resul... | [
"def",
"GetSqlValuesTuple",
"(",
"self",
",",
"trip_id",
")",
":",
"result",
"=",
"[",
"]",
"for",
"fn",
"in",
"self",
".",
"_SQL_FIELD_NAMES",
":",
"if",
"fn",
"==",
"'trip_id'",
":",
"result",
".",
"append",
"(",
"trip_id",
")",
"else",
":",
"# Since... | Return a tuple that outputs a row of _FIELD_NAMES to be written to a
SQLite database.
Arguments:
trip_id: The trip_id of the trip to which this StopTime corresponds.
It must be provided, as it is not stored in StopTime. | [
"Return",
"a",
"tuple",
"that",
"outputs",
"a",
"row",
"of",
"_FIELD_NAMES",
"to",
"be",
"written",
"to",
"a",
"SQLite",
"database",
"."
] | eb2991a3747ba541b2cb66502b305b6304a1f85f | https://github.com/google/transitfeed/blob/eb2991a3747ba541b2cb66502b305b6304a1f85f/transitfeed/stoptime.py#L183-L201 |
225,212 | google/transitfeed | transitfeed/stoptime.py | StopTime.GetTimeSecs | def GetTimeSecs(self):
"""Return the first of arrival_secs and departure_secs that is not None.
If both are None return None."""
if self.arrival_secs != None:
return self.arrival_secs
elif self.departure_secs != None:
return self.departure_secs
else:
return None | python | def GetTimeSecs(self):
"""Return the first of arrival_secs and departure_secs that is not None.
If both are None return None."""
if self.arrival_secs != None:
return self.arrival_secs
elif self.departure_secs != None:
return self.departure_secs
else:
return None | [
"def",
"GetTimeSecs",
"(",
"self",
")",
":",
"if",
"self",
".",
"arrival_secs",
"!=",
"None",
":",
"return",
"self",
".",
"arrival_secs",
"elif",
"self",
".",
"departure_secs",
"!=",
"None",
":",
"return",
"self",
".",
"departure_secs",
"else",
":",
"retur... | Return the first of arrival_secs and departure_secs that is not None.
If both are None return None. | [
"Return",
"the",
"first",
"of",
"arrival_secs",
"and",
"departure_secs",
"that",
"is",
"not",
"None",
".",
"If",
"both",
"are",
"None",
"return",
"None",
"."
] | eb2991a3747ba541b2cb66502b305b6304a1f85f | https://github.com/google/transitfeed/blob/eb2991a3747ba541b2cb66502b305b6304a1f85f/transitfeed/stoptime.py#L203-L211 |
225,213 | equinor/segyio | python/segyio/create.py | create | def create(filename, spec):
"""Create a new segy file.
Create a new segy file with the geometry and properties given by `spec`.
This enables creating SEGY files from your data. The created file supports
all segyio modes, but has an emphasis on writing. The spec must be
complete, otherwise an except... | python | def create(filename, spec):
"""Create a new segy file.
Create a new segy file with the geometry and properties given by `spec`.
This enables creating SEGY files from your data. The created file supports
all segyio modes, but has an emphasis on writing. The spec must be
complete, otherwise an except... | [
"def",
"create",
"(",
"filename",
",",
"spec",
")",
":",
"from",
".",
"import",
"_segyio",
"if",
"not",
"structured",
"(",
"spec",
")",
":",
"tracecount",
"=",
"spec",
".",
"tracecount",
"else",
":",
"tracecount",
"=",
"len",
"(",
"spec",
".",
"ilines"... | Create a new segy file.
Create a new segy file with the geometry and properties given by `spec`.
This enables creating SEGY files from your data. The created file supports
all segyio modes, but has an emphasis on writing. The spec must be
complete, otherwise an exception will be raised. A default, empt... | [
"Create",
"a",
"new",
"segy",
"file",
"."
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/create.py#L38-L246 |
225,214 | equinor/segyio | python/segyio/su/file.py | open | def open(filename, mode = 'r', iline = 189,
xline = 193,
strict = True,
ignore_geometry = False,
endian = 'big' ):
"""Open a seismic unix file.
Behaves identically to open(), except it ex... | python | def open(filename, mode = 'r', iline = 189,
xline = 193,
strict = True,
ignore_geometry = False,
endian = 'big' ):
"""Open a seismic unix file.
Behaves identically to open(), except it ex... | [
"def",
"open",
"(",
"filename",
",",
"mode",
"=",
"'r'",
",",
"iline",
"=",
"189",
",",
"xline",
"=",
"193",
",",
"strict",
"=",
"True",
",",
"ignore_geometry",
"=",
"False",
",",
"endian",
"=",
"'big'",
")",
":",
"if",
"'w'",
"in",
"mode",
":",
... | Open a seismic unix file.
Behaves identically to open(), except it expects the seismic unix format,
not SEG-Y.
Parameters
----------
filename : str
Path to file to open
mode : {'r', 'r+'}
File access mode, read-only ('r', default) or read-write ('r+')
iline : int or segyi... | [
"Open",
"a",
"seismic",
"unix",
"file",
"."
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/su/file.py#L23-L118 |
225,215 | equinor/segyio | python/segyio/tools.py | create_text_header | def create_text_header(lines):
"""Format textual header
Create a "correct" SEG-Y textual header. Every line will be prefixed with
C## and there are 40 lines. The input must be a dictionary with the line
number[1-40] as a key. The value for each key should be up to 76 character
long string.
Pa... | python | def create_text_header(lines):
"""Format textual header
Create a "correct" SEG-Y textual header. Every line will be prefixed with
C## and there are 40 lines. The input must be a dictionary with the line
number[1-40] as a key. The value for each key should be up to 76 character
long string.
Pa... | [
"def",
"create_text_header",
"(",
"lines",
")",
":",
"rows",
"=",
"[",
"]",
"for",
"line_no",
"in",
"range",
"(",
"1",
",",
"41",
")",
":",
"line",
"=",
"\"\"",
"if",
"line_no",
"in",
"lines",
":",
"line",
"=",
"lines",
"[",
"line_no",
"]",
"row",
... | Format textual header
Create a "correct" SEG-Y textual header. Every line will be prefixed with
C## and there are 40 lines. The input must be a dictionary with the line
number[1-40] as a key. The value for each key should be up to 76 character
long string.
Parameters
----------
lines : d... | [
"Format",
"textual",
"header"
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/tools.py#L65-L98 |
225,216 | equinor/segyio | python/segyio/tools.py | wrap | def wrap(s, width=80):
"""
Formats the text input with newlines given the user specified width for
each line.
Parameters
----------
s : str
width : int
Returns
-------
text : str
Notes
-----
.. versionadded:: 1.1
"""
return '\n'.join(textwrap.wrap(str(s... | python | def wrap(s, width=80):
"""
Formats the text input with newlines given the user specified width for
each line.
Parameters
----------
s : str
width : int
Returns
-------
text : str
Notes
-----
.. versionadded:: 1.1
"""
return '\n'.join(textwrap.wrap(str(s... | [
"def",
"wrap",
"(",
"s",
",",
"width",
"=",
"80",
")",
":",
"return",
"'\\n'",
".",
"join",
"(",
"textwrap",
".",
"wrap",
"(",
"str",
"(",
"s",
")",
",",
"width",
"=",
"width",
")",
")"
] | Formats the text input with newlines given the user specified width for
each line.
Parameters
----------
s : str
width : int
Returns
-------
text : str
Notes
-----
.. versionadded:: 1.1 | [
"Formats",
"the",
"text",
"input",
"with",
"newlines",
"given",
"the",
"user",
"specified",
"width",
"for",
"each",
"line",
"."
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/tools.py#L100-L122 |
225,217 | equinor/segyio | python/segyio/tools.py | native | def native(data,
format = segyio.SegySampleFormat.IBM_FLOAT_4_BYTE,
copy = True):
"""Convert numpy array to native float
Converts a numpy array from raw segy trace data to native floats. Works for numpy ndarrays.
Parameters
----------
data : numpy.ndarray
format : int or... | python | def native(data,
format = segyio.SegySampleFormat.IBM_FLOAT_4_BYTE,
copy = True):
"""Convert numpy array to native float
Converts a numpy array from raw segy trace data to native floats. Works for numpy ndarrays.
Parameters
----------
data : numpy.ndarray
format : int or... | [
"def",
"native",
"(",
"data",
",",
"format",
"=",
"segyio",
".",
"SegySampleFormat",
".",
"IBM_FLOAT_4_BYTE",
",",
"copy",
"=",
"True",
")",
":",
"data",
"=",
"data",
".",
"view",
"(",
"dtype",
"=",
"np",
".",
"single",
")",
"if",
"copy",
":",
"data"... | Convert numpy array to native float
Converts a numpy array from raw segy trace data to native floats. Works for numpy ndarrays.
Parameters
----------
data : numpy.ndarray
format : int or segyio.SegySampleFormat
copy : bool
If True, convert on a copy, and leave the input array unmodifi... | [
"Convert",
"numpy",
"array",
"to",
"native",
"float"
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/tools.py#L125-L166 |
225,218 | equinor/segyio | python/segyio/tools.py | cube | def cube(f):
"""Read a full cube from a file
Takes an open segy file (created with segyio.open) or a file name.
If the file is a prestack file, the cube returned has the dimensions
``(fast, slow, offset, sample)``. If it is post-stack (only the one
offset), the dimensions are normalised to ``(fast... | python | def cube(f):
"""Read a full cube from a file
Takes an open segy file (created with segyio.open) or a file name.
If the file is a prestack file, the cube returned has the dimensions
``(fast, slow, offset, sample)``. If it is post-stack (only the one
offset), the dimensions are normalised to ``(fast... | [
"def",
"cube",
"(",
"f",
")",
":",
"if",
"not",
"isinstance",
"(",
"f",
",",
"segyio",
".",
"SegyFile",
")",
":",
"with",
"segyio",
".",
"open",
"(",
"f",
")",
"as",
"fl",
":",
"return",
"cube",
"(",
"fl",
")",
"ilsort",
"=",
"f",
".",
"sorting... | Read a full cube from a file
Takes an open segy file (created with segyio.open) or a file name.
If the file is a prestack file, the cube returned has the dimensions
``(fast, slow, offset, sample)``. If it is post-stack (only the one
offset), the dimensions are normalised to ``(fast, slow, sample)``
... | [
"Read",
"a",
"full",
"cube",
"from",
"a",
"file"
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/tools.py#L203-L239 |
225,219 | equinor/segyio | python/segyio/tools.py | rotation | def rotation(f, line = 'fast'):
""" Find rotation of the survey
Find the clock-wise rotation and origin of `line` as ``(rot, cdpx, cdpy)``
The clock-wise rotation is defined as the angle in radians between line
given by the first and last trace of the first line and the axis that gives
increasing ... | python | def rotation(f, line = 'fast'):
""" Find rotation of the survey
Find the clock-wise rotation and origin of `line` as ``(rot, cdpx, cdpy)``
The clock-wise rotation is defined as the angle in radians between line
given by the first and last trace of the first line and the axis that gives
increasing ... | [
"def",
"rotation",
"(",
"f",
",",
"line",
"=",
"'fast'",
")",
":",
"if",
"f",
".",
"unstructured",
":",
"raise",
"ValueError",
"(",
"\"Rotation requires a structured file\"",
")",
"lines",
"=",
"{",
"'fast'",
":",
"f",
".",
"fast",
",",
"'slow'",
":",
"f... | Find rotation of the survey
Find the clock-wise rotation and origin of `line` as ``(rot, cdpx, cdpy)``
The clock-wise rotation is defined as the angle in radians between line
given by the first and last trace of the first line and the axis that gives
increasing CDP-Y, in the direction that gives incre... | [
"Find",
"rotation",
"of",
"the",
"survey"
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/tools.py#L241-L297 |
225,220 | equinor/segyio | python/segyio/tools.py | metadata | def metadata(f):
"""Get survey structural properties and metadata
Create a description object that, when passed to ``segyio.create()``, would
create a new file with the same structure, dimensions, and metadata as
``f``.
Takes an open segy file (created with segyio.open) or a file name.
Parame... | python | def metadata(f):
"""Get survey structural properties and metadata
Create a description object that, when passed to ``segyio.create()``, would
create a new file with the same structure, dimensions, and metadata as
``f``.
Takes an open segy file (created with segyio.open) or a file name.
Parame... | [
"def",
"metadata",
"(",
"f",
")",
":",
"if",
"not",
"isinstance",
"(",
"f",
",",
"segyio",
".",
"SegyFile",
")",
":",
"with",
"segyio",
".",
"open",
"(",
"f",
")",
"as",
"fl",
":",
"return",
"metadata",
"(",
"fl",
")",
"spec",
"=",
"segyio",
".",... | Get survey structural properties and metadata
Create a description object that, when passed to ``segyio.create()``, would
create a new file with the same structure, dimensions, and metadata as
``f``.
Takes an open segy file (created with segyio.open) or a file name.
Parameters
----------
... | [
"Get",
"survey",
"structural",
"properties",
"and",
"metadata"
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/tools.py#L299-L345 |
225,221 | equinor/segyio | python/segyio/tools.py | resample | def resample(f, rate = None, delay = None, micro = False,
trace = True,
binary = True):
"""Resample a file
Resample all data traces, and update the file handle to reflect the new
sample rate. No actual samples (data trace... | python | def resample(f, rate = None, delay = None, micro = False,
trace = True,
binary = True):
"""Resample a file
Resample all data traces, and update the file handle to reflect the new
sample rate. No actual samples (data trace... | [
"def",
"resample",
"(",
"f",
",",
"rate",
"=",
"None",
",",
"delay",
"=",
"None",
",",
"micro",
"=",
"False",
",",
"trace",
"=",
"True",
",",
"binary",
"=",
"True",
")",
":",
"if",
"rate",
"is",
"not",
"None",
":",
"if",
"not",
"micro",
":",
"r... | Resample a file
Resample all data traces, and update the file handle to reflect the new
sample rate. No actual samples (data traces) are modified, only the header
fields and interpretation.
By default, the rate and the delay are in millseconds - if you need higher
resolution, passing micro=True in... | [
"Resample",
"a",
"file"
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/tools.py#L347-L408 |
225,222 | equinor/segyio | python/segyio/tools.py | from_array3D | def from_array3D(filename, data, iline=189,
xline=193,
format=SegySampleFormat.IBM_FLOAT_4_BYTE,
dt=4000,
delrt=0):
""" Create a new SEGY file from a 3D array
Create an structured ... | python | def from_array3D(filename, data, iline=189,
xline=193,
format=SegySampleFormat.IBM_FLOAT_4_BYTE,
dt=4000,
delrt=0):
""" Create a new SEGY file from a 3D array
Create an structured ... | [
"def",
"from_array3D",
"(",
"filename",
",",
"data",
",",
"iline",
"=",
"189",
",",
"xline",
"=",
"193",
",",
"format",
"=",
"SegySampleFormat",
".",
"IBM_FLOAT_4_BYTE",
",",
"dt",
"=",
"4000",
",",
"delrt",
"=",
"0",
")",
":",
"data",
"=",
"np",
"."... | Create a new SEGY file from a 3D array
Create an structured SEGY file with defaulted headers from a 3-dimensional
array. The file is inline-sorted. ilines, xlines and samples are inferred
from the array. Structure-defining fields in the binary header and
in the traceheaders are set accordingly. Such fie... | [
"Create",
"a",
"new",
"SEGY",
"file",
"from",
"a",
"3D",
"array",
"Create",
"an",
"structured",
"SEGY",
"file",
"with",
"defaulted",
"headers",
"from",
"a",
"3",
"-",
"dimensional",
"array",
".",
"The",
"file",
"is",
"inline",
"-",
"sorted",
".",
"ilines... | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/tools.py#L592-L662 |
225,223 | equinor/segyio | python/segyio/open.py | open | def open(filename, mode="r", iline = 189,
xline = 193,
strict = True,
ignore_geometry = False,
endian = 'big'):
"""Open a segy file.
Opens a segy file and tries to figure out its sorting, inline ... | python | def open(filename, mode="r", iline = 189,
xline = 193,
strict = True,
ignore_geometry = False,
endian = 'big'):
"""Open a segy file.
Opens a segy file and tries to figure out its sorting, inline ... | [
"def",
"open",
"(",
"filename",
",",
"mode",
"=",
"\"r\"",
",",
"iline",
"=",
"189",
",",
"xline",
"=",
"193",
",",
"strict",
"=",
"True",
",",
"ignore_geometry",
"=",
"False",
",",
"endian",
"=",
"'big'",
")",
":",
"if",
"'w'",
"in",
"mode",
":",
... | Open a segy file.
Opens a segy file and tries to figure out its sorting, inline numbers,
crossline numbers, and offsets, and enables reading and writing to this
file in a simple manner.
For reading, the access mode `r` is preferred. All write operations will
raise an exception. For writing, the mo... | [
"Open",
"a",
"segy",
"file",
"."
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/open.py#L33-L187 |
225,224 | equinor/segyio | python/segyio/field.py | Field.fetch | def fetch(self, buf = None, traceno = None):
"""Fetch the header from disk
This object will read header when it is constructed, which means it
might be out-of-date if the file is updated through some other handle.
This method is largely meant for internal use - if you need to reload
... | python | def fetch(self, buf = None, traceno = None):
"""Fetch the header from disk
This object will read header when it is constructed, which means it
might be out-of-date if the file is updated through some other handle.
This method is largely meant for internal use - if you need to reload
... | [
"def",
"fetch",
"(",
"self",
",",
"buf",
"=",
"None",
",",
"traceno",
"=",
"None",
")",
":",
"if",
"buf",
"is",
"None",
":",
"buf",
"=",
"self",
".",
"buf",
"if",
"traceno",
"is",
"None",
":",
"traceno",
"=",
"self",
".",
"traceno",
"try",
":",
... | Fetch the header from disk
This object will read header when it is constructed, which means it
might be out-of-date if the file is updated through some other handle.
This method is largely meant for internal use - if you need to reload
disk contents, use ``reload``.
Fetch does ... | [
"Fetch",
"the",
"header",
"from",
"disk"
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/field.py#L183-L243 |
225,225 | equinor/segyio | python/segyio/field.py | Field.reload | def reload(self):
"""
This object will read header when it is constructed, which means it
might be out-of-date if the file is updated through some other handle.
It's rarely required to call this method, and it's a symptom of fragile
code. However, if you have multiple handles to... | python | def reload(self):
"""
This object will read header when it is constructed, which means it
might be out-of-date if the file is updated through some other handle.
It's rarely required to call this method, and it's a symptom of fragile
code. However, if you have multiple handles to... | [
"def",
"reload",
"(",
"self",
")",
":",
"self",
".",
"buf",
"=",
"self",
".",
"fetch",
"(",
"buf",
"=",
"self",
".",
"buf",
")",
"return",
"self"
] | This object will read header when it is constructed, which means it
might be out-of-date if the file is updated through some other handle.
It's rarely required to call this method, and it's a symptom of fragile
code. However, if you have multiple handles to the same header, it
might be ... | [
"This",
"object",
"will",
"read",
"header",
"when",
"it",
"is",
"constructed",
"which",
"means",
"it",
"might",
"be",
"out",
"-",
"of",
"-",
"date",
"if",
"the",
"file",
"is",
"updated",
"through",
"some",
"other",
"handle",
"."
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/field.py#L245-L288 |
225,226 | equinor/segyio | python/segyio/field.py | Field.flush | def flush(self):
"""Commit backing storage to disk
This method is largely internal, and it is not necessary to call this
from user code. It should not be explicitly invoked and may be removed
in future versions.
"""
if self.kind == TraceField:
self.filehandl... | python | def flush(self):
"""Commit backing storage to disk
This method is largely internal, and it is not necessary to call this
from user code. It should not be explicitly invoked and may be removed
in future versions.
"""
if self.kind == TraceField:
self.filehandl... | [
"def",
"flush",
"(",
"self",
")",
":",
"if",
"self",
".",
"kind",
"==",
"TraceField",
":",
"self",
".",
"filehandle",
".",
"putth",
"(",
"self",
".",
"traceno",
",",
"self",
".",
"buf",
")",
"elif",
"self",
".",
"kind",
"==",
"BinField",
":",
"self... | Commit backing storage to disk
This method is largely internal, and it is not necessary to call this
from user code. It should not be explicitly invoked and may be removed
in future versions. | [
"Commit",
"backing",
"storage",
"to",
"disk"
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/field.py#L290-L306 |
225,227 | equinor/segyio | python/segyio/trace.py | Trace.raw | def raw(self):
"""
An eager version of Trace
Returns
-------
raw : RawTrace
"""
return RawTrace(self.filehandle,
self.dtype,
len(self),
self.shape,
self.readonly,
... | python | def raw(self):
"""
An eager version of Trace
Returns
-------
raw : RawTrace
"""
return RawTrace(self.filehandle,
self.dtype,
len(self),
self.shape,
self.readonly,
... | [
"def",
"raw",
"(",
"self",
")",
":",
"return",
"RawTrace",
"(",
"self",
".",
"filehandle",
",",
"self",
".",
"dtype",
",",
"len",
"(",
"self",
")",
",",
"self",
".",
"shape",
",",
"self",
".",
"readonly",
",",
")"
] | An eager version of Trace
Returns
-------
raw : RawTrace | [
"An",
"eager",
"version",
"of",
"Trace"
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/trace.py#L253-L266 |
225,228 | equinor/segyio | python/segyio/trace.py | Trace.ref | def ref(self):
"""
A write-back version of Trace
Returns
-------
ref : RefTrace
`ref` is returned in a context manager, and must be in a ``with``
statement
Notes
-----
.. versionadded:: 1.6
Examples
--------
... | python | def ref(self):
"""
A write-back version of Trace
Returns
-------
ref : RefTrace
`ref` is returned in a context manager, and must be in a ``with``
statement
Notes
-----
.. versionadded:: 1.6
Examples
--------
... | [
"def",
"ref",
"(",
"self",
")",
":",
"x",
"=",
"RefTrace",
"(",
"self",
".",
"filehandle",
",",
"self",
".",
"dtype",
",",
"len",
"(",
"self",
")",
",",
"self",
".",
"shape",
",",
"self",
".",
"readonly",
",",
")",
"yield",
"x",
"x",
".",
"flus... | A write-back version of Trace
Returns
-------
ref : RefTrace
`ref` is returned in a context manager, and must be in a ``with``
statement
Notes
-----
.. versionadded:: 1.6
Examples
--------
>>> with trace.ref as ref:
... | [
"A",
"write",
"-",
"back",
"version",
"of",
"Trace"
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/trace.py#L270-L297 |
225,229 | equinor/segyio | python/segyio/trace.py | RefTrace.flush | def flush(self):
"""
Commit cached writes to the file handle. Does not flush libc buffers or
notifies the kernel, so these changes may not immediately be visible to
other processes.
Updates the fingerprints whena writes happen, so successive ``flush()``
invocations are n... | python | def flush(self):
"""
Commit cached writes to the file handle. Does not flush libc buffers or
notifies the kernel, so these changes may not immediately be visible to
other processes.
Updates the fingerprints whena writes happen, so successive ``flush()``
invocations are n... | [
"def",
"flush",
"(",
"self",
")",
":",
"garbage",
"=",
"[",
"]",
"for",
"i",
",",
"(",
"x",
",",
"signature",
")",
"in",
"self",
".",
"refs",
".",
"items",
"(",
")",
":",
"if",
"sys",
".",
"getrefcount",
"(",
"x",
")",
"==",
"3",
":",
"garbag... | Commit cached writes to the file handle. Does not flush libc buffers or
notifies the kernel, so these changes may not immediately be visible to
other processes.
Updates the fingerprints whena writes happen, so successive ``flush()``
invocations are no-ops.
It is not necessary t... | [
"Commit",
"cached",
"writes",
"to",
"the",
"file",
"handle",
".",
"Does",
"not",
"flush",
"libc",
"buffers",
"or",
"notifies",
"the",
"kernel",
"so",
"these",
"changes",
"may",
"not",
"immediately",
"be",
"visible",
"to",
"other",
"processes",
"."
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/trace.py#L376-L408 |
225,230 | equinor/segyio | python/segyio/segy.py | SegyFile.iline | def iline(self):
"""
Interact with segy in inline mode
Returns
-------
iline : Line or None
Raises
------
ValueError
If the file is unstructured
Notes
-----
.. versionadded:: 1.1
"""
if self.unstructu... | python | def iline(self):
"""
Interact with segy in inline mode
Returns
-------
iline : Line or None
Raises
------
ValueError
If the file is unstructured
Notes
-----
.. versionadded:: 1.1
"""
if self.unstructu... | [
"def",
"iline",
"(",
"self",
")",
":",
"if",
"self",
".",
"unstructured",
":",
"raise",
"ValueError",
"(",
"self",
".",
"_unstructured_errmsg",
")",
"if",
"self",
".",
"_iline",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_iline",
"self",
".",
"_... | Interact with segy in inline mode
Returns
-------
iline : Line or None
Raises
------
ValueError
If the file is unstructured
Notes
-----
.. versionadded:: 1.1 | [
"Interact",
"with",
"segy",
"in",
"inline",
"mode"
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/segy.py#L501-L532 |
225,231 | equinor/segyio | python/segyio/segy.py | SegyFile.xline | def xline(self):
"""
Interact with segy in crossline mode
Returns
-------
xline : Line or None
Raises
------
ValueError
If the file is unstructured
Notes
-----
.. versionadded:: 1.1
"""
if self.unstruc... | python | def xline(self):
"""
Interact with segy in crossline mode
Returns
-------
xline : Line or None
Raises
------
ValueError
If the file is unstructured
Notes
-----
.. versionadded:: 1.1
"""
if self.unstruc... | [
"def",
"xline",
"(",
"self",
")",
":",
"if",
"self",
".",
"unstructured",
":",
"raise",
"ValueError",
"(",
"self",
".",
"_unstructured_errmsg",
")",
"if",
"self",
".",
"_xline",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_xline",
"self",
".",
"_... | Interact with segy in crossline mode
Returns
-------
xline : Line or None
Raises
------
ValueError
If the file is unstructured
Notes
-----
.. versionadded:: 1.1 | [
"Interact",
"with",
"segy",
"in",
"crossline",
"mode"
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/segy.py#L573-L603 |
225,232 | equinor/segyio | python/segyio/segy.py | SegyFile.fast | def fast(self):
"""Access the 'fast' dimension
This mode yields iline or xline mode, depending on which one is laid
out `faster`, i.e. the line with linear disk layout. Use this mode if
the inline/crossline distinction isn't as interesting as traversing in
a fast manner (typical... | python | def fast(self):
"""Access the 'fast' dimension
This mode yields iline or xline mode, depending on which one is laid
out `faster`, i.e. the line with linear disk layout. Use this mode if
the inline/crossline distinction isn't as interesting as traversing in
a fast manner (typical... | [
"def",
"fast",
"(",
"self",
")",
":",
"if",
"self",
".",
"sorting",
"==",
"TraceSortingFormat",
".",
"INLINE_SORTING",
":",
"return",
"self",
".",
"iline",
"elif",
"self",
".",
"sorting",
"==",
"TraceSortingFormat",
".",
"CROSSLINE_SORTING",
":",
"return",
"... | Access the 'fast' dimension
This mode yields iline or xline mode, depending on which one is laid
out `faster`, i.e. the line with linear disk layout. Use this mode if
the inline/crossline distinction isn't as interesting as traversing in
a fast manner (typically when you want to apply a... | [
"Access",
"the",
"fast",
"dimension"
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/segy.py#L630-L653 |
225,233 | equinor/segyio | python/segyio/segy.py | SegyFile.gather | def gather(self):
"""
Interact with segy in gather mode
Returns
-------
gather : Gather
"""
if self.unstructured:
raise ValueError(self._unstructured_errmsg)
if self._gather is not None:
return self._gather
self._gather =... | python | def gather(self):
"""
Interact with segy in gather mode
Returns
-------
gather : Gather
"""
if self.unstructured:
raise ValueError(self._unstructured_errmsg)
if self._gather is not None:
return self._gather
self._gather =... | [
"def",
"gather",
"(",
"self",
")",
":",
"if",
"self",
".",
"unstructured",
":",
"raise",
"ValueError",
"(",
"self",
".",
"_unstructured_errmsg",
")",
"if",
"self",
".",
"_gather",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_gather",
"self",
".",
... | Interact with segy in gather mode
Returns
-------
gather : Gather | [
"Interact",
"with",
"segy",
"in",
"gather",
"mode"
] | 58fd449947ccd330b9af0699d6b8710550d34e8e | https://github.com/equinor/segyio/blob/58fd449947ccd330b9af0699d6b8710550d34e8e/python/segyio/segy.py#L729-L744 |
225,234 | pymc-devs/pymc | pymc/StepMethods.py | pick_best_methods | def pick_best_methods(stochastic):
"""
Picks the StepMethods best suited to handle
a stochastic variable.
"""
# Keep track of most competent methohd
max_competence = 0
# Empty set of appropriate StepMethods
best_candidates = set([])
# Loop over StepMethodRegistry
for method in ... | python | def pick_best_methods(stochastic):
"""
Picks the StepMethods best suited to handle
a stochastic variable.
"""
# Keep track of most competent methohd
max_competence = 0
# Empty set of appropriate StepMethods
best_candidates = set([])
# Loop over StepMethodRegistry
for method in ... | [
"def",
"pick_best_methods",
"(",
"stochastic",
")",
":",
"# Keep track of most competent methohd",
"max_competence",
"=",
"0",
"# Empty set of appropriate StepMethods",
"best_candidates",
"=",
"set",
"(",
"[",
"]",
")",
"# Loop over StepMethodRegistry",
"for",
"method",
"in... | Picks the StepMethods best suited to handle
a stochastic variable. | [
"Picks",
"the",
"StepMethods",
"best",
"suited",
"to",
"handle",
"a",
"stochastic",
"variable",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L59-L94 |
225,235 | pymc-devs/pymc | pymc/StepMethods.py | StepMethod.loglike | def loglike(self):
'''
The summed log-probability of all stochastic variables that depend on
self.stochastics, with self.stochastics removed.
'''
sum = logp_of_set(self.children)
if self.verbose > 2:
print_('\t' + self._id + ' Current log-likelihood ', sum)
... | python | def loglike(self):
'''
The summed log-probability of all stochastic variables that depend on
self.stochastics, with self.stochastics removed.
'''
sum = logp_of_set(self.children)
if self.verbose > 2:
print_('\t' + self._id + ' Current log-likelihood ', sum)
... | [
"def",
"loglike",
"(",
"self",
")",
":",
"sum",
"=",
"logp_of_set",
"(",
"self",
".",
"children",
")",
"if",
"self",
".",
"verbose",
">",
"2",
":",
"print_",
"(",
"'\\t'",
"+",
"self",
".",
"_id",
"+",
"' Current log-likelihood '",
",",
"sum",
")",
"... | The summed log-probability of all stochastic variables that depend on
self.stochastics, with self.stochastics removed. | [
"The",
"summed",
"log",
"-",
"probability",
"of",
"all",
"stochastic",
"variables",
"that",
"depend",
"on",
"self",
".",
"stochastics",
"with",
"self",
".",
"stochastics",
"removed",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L292-L300 |
225,236 | pymc-devs/pymc | pymc/StepMethods.py | StepMethod.logp_plus_loglike | def logp_plus_loglike(self):
'''
The summed log-probability of all stochastic variables that depend on
self.stochastics, and self.stochastics.
'''
sum = logp_of_set(self.markov_blanket)
if self.verbose > 2:
print_('\t' + self._id +
' Current... | python | def logp_plus_loglike(self):
'''
The summed log-probability of all stochastic variables that depend on
self.stochastics, and self.stochastics.
'''
sum = logp_of_set(self.markov_blanket)
if self.verbose > 2:
print_('\t' + self._id +
' Current... | [
"def",
"logp_plus_loglike",
"(",
"self",
")",
":",
"sum",
"=",
"logp_of_set",
"(",
"self",
".",
"markov_blanket",
")",
"if",
"self",
".",
"verbose",
">",
"2",
":",
"print_",
"(",
"'\\t'",
"+",
"self",
".",
"_id",
"+",
"' Current log-likelihood plus current l... | The summed log-probability of all stochastic variables that depend on
self.stochastics, and self.stochastics. | [
"The",
"summed",
"log",
"-",
"probability",
"of",
"all",
"stochastic",
"variables",
"that",
"depend",
"on",
"self",
".",
"stochastics",
"and",
"self",
".",
"stochastics",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L303-L312 |
225,237 | pymc-devs/pymc | pymc/StepMethods.py | StepMethod.current_state | def current_state(self):
"""Return a dictionary with the current value of the variables defining
the state of the step method."""
state = {}
for s in self._state:
state[s] = getattr(self, s)
return state | python | def current_state(self):
"""Return a dictionary with the current value of the variables defining
the state of the step method."""
state = {}
for s in self._state:
state[s] = getattr(self, s)
return state | [
"def",
"current_state",
"(",
"self",
")",
":",
"state",
"=",
"{",
"}",
"for",
"s",
"in",
"self",
".",
"_state",
":",
"state",
"[",
"s",
"]",
"=",
"getattr",
"(",
"self",
",",
"s",
")",
"return",
"state"
] | Return a dictionary with the current value of the variables defining
the state of the step method. | [
"Return",
"a",
"dictionary",
"with",
"the",
"current",
"value",
"of",
"the",
"variables",
"defining",
"the",
"state",
"of",
"the",
"step",
"method",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L318-L324 |
225,238 | pymc-devs/pymc | pymc/StepMethods.py | Metropolis.step | def step(self):
"""
The default step method applies if the variable is floating-point
valued, and is not being proposed from its prior.
"""
# Probability and likelihood for s's current value:
if self.verbose > 2:
print_()
print_(self._id + ' gett... | python | def step(self):
"""
The default step method applies if the variable is floating-point
valued, and is not being proposed from its prior.
"""
# Probability and likelihood for s's current value:
if self.verbose > 2:
print_()
print_(self._id + ' gett... | [
"def",
"step",
"(",
"self",
")",
":",
"# Probability and likelihood for s's current value:",
"if",
"self",
".",
"verbose",
">",
"2",
":",
"print_",
"(",
")",
"print_",
"(",
"self",
".",
"_id",
"+",
"' getting initial logp.'",
")",
"if",
"self",
".",
"proposal_... | The default step method applies if the variable is floating-point
valued, and is not being proposed from its prior. | [
"The",
"default",
"step",
"method",
"applies",
"if",
"the",
"variable",
"is",
"floating",
"-",
"point",
"valued",
"and",
"is",
"not",
"being",
"proposed",
"from",
"its",
"prior",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L470-L539 |
225,239 | pymc-devs/pymc | pymc/StepMethods.py | PDMatrixMetropolis.competence | def competence(s):
"""
The competence function for MatrixMetropolis
"""
# MatrixMetropolis handles the Wishart family, which are valued as
# _symmetric_ matrices.
if any([isinstance(s, cls)
for cls in [distributions.Wishart, distributions.WishartCov]]):
... | python | def competence(s):
"""
The competence function for MatrixMetropolis
"""
# MatrixMetropolis handles the Wishart family, which are valued as
# _symmetric_ matrices.
if any([isinstance(s, cls)
for cls in [distributions.Wishart, distributions.WishartCov]]):
... | [
"def",
"competence",
"(",
"s",
")",
":",
"# MatrixMetropolis handles the Wishart family, which are valued as",
"# _symmetric_ matrices.",
"if",
"any",
"(",
"[",
"isinstance",
"(",
"s",
",",
"cls",
")",
"for",
"cls",
"in",
"[",
"distributions",
".",
"Wishart",
",",
... | The competence function for MatrixMetropolis | [
"The",
"competence",
"function",
"for",
"MatrixMetropolis"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L657-L667 |
225,240 | pymc-devs/pymc | pymc/StepMethods.py | PDMatrixMetropolis.propose | def propose(self):
"""
Proposals for positive definite matrix using random walk deviations on the Cholesky
factor of the current value.
"""
# Locally store size of matrix
dims = self.stochastic.value.shape
# Add normal deviate to value and symmetrize
dev... | python | def propose(self):
"""
Proposals for positive definite matrix using random walk deviations on the Cholesky
factor of the current value.
"""
# Locally store size of matrix
dims = self.stochastic.value.shape
# Add normal deviate to value and symmetrize
dev... | [
"def",
"propose",
"(",
"self",
")",
":",
"# Locally store size of matrix",
"dims",
"=",
"self",
".",
"stochastic",
".",
"value",
".",
"shape",
"# Add normal deviate to value and symmetrize",
"dev",
"=",
"rnormal",
"(",
"0",
",",
"self",
".",
"adaptive_scale_factor",... | Proposals for positive definite matrix using random walk deviations on the Cholesky
factor of the current value. | [
"Proposals",
"for",
"positive",
"definite",
"matrix",
"using",
"random",
"walk",
"deviations",
"on",
"the",
"Cholesky",
"factor",
"of",
"the",
"current",
"value",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L669-L687 |
225,241 | pymc-devs/pymc | pymc/StepMethods.py | BinaryMetropolis.competence | def competence(stochastic):
"""
The competence function for Binary One-At-A-Time Metropolis
"""
if stochastic.dtype in bool_dtypes:
return 2
elif isinstance(stochastic, distributions.Bernoulli):
return 2
elif (isinstance(stochastic, d... | python | def competence(stochastic):
"""
The competence function for Binary One-At-A-Time Metropolis
"""
if stochastic.dtype in bool_dtypes:
return 2
elif isinstance(stochastic, distributions.Bernoulli):
return 2
elif (isinstance(stochastic, d... | [
"def",
"competence",
"(",
"stochastic",
")",
":",
"if",
"stochastic",
".",
"dtype",
"in",
"bool_dtypes",
":",
"return",
"2",
"elif",
"isinstance",
"(",
"stochastic",
",",
"distributions",
".",
"Bernoulli",
")",
":",
"return",
"2",
"elif",
"(",
"isinstance",
... | The competence function for Binary One-At-A-Time Metropolis | [
"The",
"competence",
"function",
"for",
"Binary",
"One",
"-",
"At",
"-",
"A",
"-",
"Time",
"Metropolis"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L901-L916 |
225,242 | pymc-devs/pymc | pymc/StepMethods.py | AdaptiveMetropolis.cov_from_value | def cov_from_value(self, scaling):
"""Return a covariance matrix for the jump distribution using
the actual value of the stochastic as a guess of their variance,
divided by the `scaling` argument.
Note that this is likely to return a poor guess.
"""
rv = []
for s... | python | def cov_from_value(self, scaling):
"""Return a covariance matrix for the jump distribution using
the actual value of the stochastic as a guess of their variance,
divided by the `scaling` argument.
Note that this is likely to return a poor guess.
"""
rv = []
for s... | [
"def",
"cov_from_value",
"(",
"self",
",",
"scaling",
")",
":",
"rv",
"=",
"[",
"]",
"for",
"s",
"in",
"self",
".",
"stochastics",
":",
"rv",
".",
"extend",
"(",
"np",
".",
"ravel",
"(",
"s",
".",
"value",
")",
".",
"copy",
"(",
")",
")",
"# Re... | Return a covariance matrix for the jump distribution using
the actual value of the stochastic as a guess of their variance,
divided by the `scaling` argument.
Note that this is likely to return a poor guess. | [
"Return",
"a",
"covariance",
"matrix",
"for",
"the",
"jump",
"distribution",
"using",
"the",
"actual",
"value",
"of",
"the",
"stochastic",
"as",
"a",
"guess",
"of",
"their",
"variance",
"divided",
"by",
"the",
"scaling",
"argument",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1135-L1151 |
225,243 | pymc-devs/pymc | pymc/StepMethods.py | AdaptiveMetropolis.cov_from_scales | def cov_from_scales(self, scales):
"""Return a covariance matrix built from a dictionary of scales.
`scales` is a dictionary keyed by stochastic instances, and the
values refer are the variance of the jump distribution for each
stochastic. If a stochastic is a sequence, the variance mus... | python | def cov_from_scales(self, scales):
"""Return a covariance matrix built from a dictionary of scales.
`scales` is a dictionary keyed by stochastic instances, and the
values refer are the variance of the jump distribution for each
stochastic. If a stochastic is a sequence, the variance mus... | [
"def",
"cov_from_scales",
"(",
"self",
",",
"scales",
")",
":",
"# Get array of scales",
"ord_sc",
"=",
"[",
"]",
"for",
"stochastic",
"in",
"self",
".",
"stochastics",
":",
"ord_sc",
".",
"append",
"(",
"np",
".",
"ravel",
"(",
"scales",
"[",
"stochastic"... | Return a covariance matrix built from a dictionary of scales.
`scales` is a dictionary keyed by stochastic instances, and the
values refer are the variance of the jump distribution for each
stochastic. If a stochastic is a sequence, the variance must
have the same length. | [
"Return",
"a",
"covariance",
"matrix",
"built",
"from",
"a",
"dictionary",
"of",
"scales",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1153-L1173 |
225,244 | pymc-devs/pymc | pymc/StepMethods.py | AdaptiveMetropolis.cov_from_trace | def cov_from_trace(self, trace=slice(None)):
"""Define the jump distribution covariance matrix from the object's
stored trace.
:Parameters:
- `trace` : slice or int
A slice for the stochastic object's trace in the last chain, or a
an integer indicating the how many o... | python | def cov_from_trace(self, trace=slice(None)):
"""Define the jump distribution covariance matrix from the object's
stored trace.
:Parameters:
- `trace` : slice or int
A slice for the stochastic object's trace in the last chain, or a
an integer indicating the how many o... | [
"def",
"cov_from_trace",
"(",
"self",
",",
"trace",
"=",
"slice",
"(",
"None",
")",
")",
":",
"n",
"=",
"[",
"]",
"for",
"s",
"in",
"self",
".",
"stochastics",
":",
"n",
".",
"append",
"(",
"s",
".",
"trace",
".",
"length",
"(",
")",
")",
"n",
... | Define the jump distribution covariance matrix from the object's
stored trace.
:Parameters:
- `trace` : slice or int
A slice for the stochastic object's trace in the last chain, or a
an integer indicating the how many of the last samples will be used. | [
"Define",
"the",
"jump",
"distribution",
"covariance",
"matrix",
"from",
"the",
"object",
"s",
"stored",
"trace",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1175-L1202 |
225,245 | pymc-devs/pymc | pymc/StepMethods.py | AdaptiveMetropolis.check_type | def check_type(self):
"""Make sure each stochastic has a correct type, and identify discrete stochastics."""
self.isdiscrete = {}
for stochastic in self.stochastics:
if stochastic.dtype in integer_dtypes:
self.isdiscrete[stochastic] = True
elif stochastic.... | python | def check_type(self):
"""Make sure each stochastic has a correct type, and identify discrete stochastics."""
self.isdiscrete = {}
for stochastic in self.stochastics:
if stochastic.dtype in integer_dtypes:
self.isdiscrete[stochastic] = True
elif stochastic.... | [
"def",
"check_type",
"(",
"self",
")",
":",
"self",
".",
"isdiscrete",
"=",
"{",
"}",
"for",
"stochastic",
"in",
"self",
".",
"stochastics",
":",
"if",
"stochastic",
".",
"dtype",
"in",
"integer_dtypes",
":",
"self",
".",
"isdiscrete",
"[",
"stochastic",
... | Make sure each stochastic has a correct type, and identify discrete stochastics. | [
"Make",
"sure",
"each",
"stochastic",
"has",
"a",
"correct",
"type",
"and",
"identify",
"discrete",
"stochastics",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1204-L1214 |
225,246 | pymc-devs/pymc | pymc/StepMethods.py | AdaptiveMetropolis.dimension | def dimension(self):
"""Compute the dimension of the sampling space and identify the slices
belonging to each stochastic.
"""
self.dim = 0
self._slices = {}
for stochastic in self.stochastics:
if isinstance(stochastic.value, np.matrix):
p_len =... | python | def dimension(self):
"""Compute the dimension of the sampling space and identify the slices
belonging to each stochastic.
"""
self.dim = 0
self._slices = {}
for stochastic in self.stochastics:
if isinstance(stochastic.value, np.matrix):
p_len =... | [
"def",
"dimension",
"(",
"self",
")",
":",
"self",
".",
"dim",
"=",
"0",
"self",
".",
"_slices",
"=",
"{",
"}",
"for",
"stochastic",
"in",
"self",
".",
"stochastics",
":",
"if",
"isinstance",
"(",
"stochastic",
".",
"value",
",",
"np",
".",
"matrix",... | Compute the dimension of the sampling space and identify the slices
belonging to each stochastic. | [
"Compute",
"the",
"dimension",
"of",
"the",
"sampling",
"space",
"and",
"identify",
"the",
"slices",
"belonging",
"to",
"each",
"stochastic",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1216-L1230 |
225,247 | pymc-devs/pymc | pymc/StepMethods.py | AdaptiveMetropolis.update_cov | def update_cov(self):
"""Recursively compute the covariance matrix for the multivariate normal
proposal distribution.
This method is called every self.interval once self.delay iterations
have been performed.
"""
scaling = (2.4) ** 2 / self.dim # Gelman et al. 1996.
... | python | def update_cov(self):
"""Recursively compute the covariance matrix for the multivariate normal
proposal distribution.
This method is called every self.interval once self.delay iterations
have been performed.
"""
scaling = (2.4) ** 2 / self.dim # Gelman et al. 1996.
... | [
"def",
"update_cov",
"(",
"self",
")",
":",
"scaling",
"=",
"(",
"2.4",
")",
"**",
"2",
"/",
"self",
".",
"dim",
"# Gelman et al. 1996.",
"epsilon",
"=",
"1.0e-5",
"chain",
"=",
"np",
".",
"asarray",
"(",
"self",
".",
"_trace",
")",
"# Recursively comput... | Recursively compute the covariance matrix for the multivariate normal
proposal distribution.
This method is called every self.interval once self.delay iterations
have been performed. | [
"Recursively",
"compute",
"the",
"covariance",
"matrix",
"for",
"the",
"multivariate",
"normal",
"proposal",
"distribution",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1232-L1286 |
225,248 | pymc-devs/pymc | pymc/StepMethods.py | AdaptiveMetropolis.recursive_cov | def recursive_cov(self, cov, length, mean, chain, scaling=1, epsilon=0):
r"""Compute the covariance recursively.
Return the new covariance and the new mean.
.. math::
C_k & = \frac{1}{k-1} (\sum_{i=1}^k x_i x_i^T - k\bar{x_k}\bar{x_k}^T)
C_n & = \frac{1}{n-1} (\sum_{i=1... | python | def recursive_cov(self, cov, length, mean, chain, scaling=1, epsilon=0):
r"""Compute the covariance recursively.
Return the new covariance and the new mean.
.. math::
C_k & = \frac{1}{k-1} (\sum_{i=1}^k x_i x_i^T - k\bar{x_k}\bar{x_k}^T)
C_n & = \frac{1}{n-1} (\sum_{i=1... | [
"def",
"recursive_cov",
"(",
"self",
",",
"cov",
",",
"length",
",",
"mean",
",",
"chain",
",",
"scaling",
"=",
"1",
",",
"epsilon",
"=",
"0",
")",
":",
"n",
"=",
"length",
"+",
"len",
"(",
"chain",
")",
"k",
"=",
"length",
"new_mean",
"=",
"self... | r"""Compute the covariance recursively.
Return the new covariance and the new mean.
.. math::
C_k & = \frac{1}{k-1} (\sum_{i=1}^k x_i x_i^T - k\bar{x_k}\bar{x_k}^T)
C_n & = \frac{1}{n-1} (\sum_{i=1}^k x_i x_i^T + \sum_{i=k+1}^n x_i x_i^T - n\bar{x_n}\bar{x_n}^T)
... | [
"r",
"Compute",
"the",
"covariance",
"recursively",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1297-L1335 |
225,249 | pymc-devs/pymc | pymc/StepMethods.py | AdaptiveMetropolis.recursive_mean | def recursive_mean(self, mean, length, chain):
r"""Compute the chain mean recursively.
Instead of computing the mean :math:`\bar{x_n}` of the entire chain,
use the last computed mean :math:`bar{x_j}` and the tail of the chain
to recursively estimate the mean.
.. math::
... | python | def recursive_mean(self, mean, length, chain):
r"""Compute the chain mean recursively.
Instead of computing the mean :math:`\bar{x_n}` of the entire chain,
use the last computed mean :math:`bar{x_j}` and the tail of the chain
to recursively estimate the mean.
.. math::
... | [
"def",
"recursive_mean",
"(",
"self",
",",
"mean",
",",
"length",
",",
"chain",
")",
":",
"n",
"=",
"length",
"+",
"len",
"(",
"chain",
")",
"return",
"length",
"*",
"mean",
"/",
"n",
"+",
"chain",
".",
"sum",
"(",
"0",
")",
"/",
"n"
] | r"""Compute the chain mean recursively.
Instead of computing the mean :math:`\bar{x_n}` of the entire chain,
use the last computed mean :math:`bar{x_j}` and the tail of the chain
to recursively estimate the mean.
.. math::
\bar{x_n} & = \frac{1}{n} \sum_{i=1}^n x_i
... | [
"r",
"Compute",
"the",
"chain",
"mean",
"recursively",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1337-L1358 |
225,250 | pymc-devs/pymc | pymc/StepMethods.py | AdaptiveMetropolis.propose | def propose(self):
"""
This method proposes values for stochastics based on the empirical
covariance of the values sampled so far.
The proposal jumps are drawn from a multivariate normal distribution.
"""
arrayjump = np.dot(
self.proposal_sd,
np.... | python | def propose(self):
"""
This method proposes values for stochastics based on the empirical
covariance of the values sampled so far.
The proposal jumps are drawn from a multivariate normal distribution.
"""
arrayjump = np.dot(
self.proposal_sd,
np.... | [
"def",
"propose",
"(",
"self",
")",
":",
"arrayjump",
"=",
"np",
".",
"dot",
"(",
"self",
".",
"proposal_sd",
",",
"np",
".",
"random",
".",
"normal",
"(",
"size",
"=",
"self",
".",
"proposal_sd",
".",
"shape",
"[",
"0",
"]",
")",
")",
"if",
"sel... | This method proposes values for stochastics based on the empirical
covariance of the values sampled so far.
The proposal jumps are drawn from a multivariate normal distribution. | [
"This",
"method",
"proposes",
"values",
"for",
"stochastics",
"based",
"on",
"the",
"empirical",
"covariance",
"of",
"the",
"values",
"sampled",
"so",
"far",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1360-L1388 |
225,251 | pymc-devs/pymc | pymc/StepMethods.py | AdaptiveMetropolis.step | def step(self):
"""
Perform a Metropolis step.
Stochastic parameters are block-updated using a multivariate normal
distribution whose covariance is updated every self.interval once
self.delay steps have been performed.
The AM instance keeps a local copy of the stochasti... | python | def step(self):
"""
Perform a Metropolis step.
Stochastic parameters are block-updated using a multivariate normal
distribution whose covariance is updated every self.interval once
self.delay steps have been performed.
The AM instance keeps a local copy of the stochasti... | [
"def",
"step",
"(",
"self",
")",
":",
"# Probability and likelihood for stochastic's current value:",
"logp",
"=",
"self",
".",
"logp_plus_loglike",
"if",
"self",
".",
"verbose",
">",
"1",
":",
"print_",
"(",
"'Current value: '",
",",
"self",
".",
"stoch2array",
"... | Perform a Metropolis step.
Stochastic parameters are block-updated using a multivariate normal
distribution whose covariance is updated every self.interval once
self.delay steps have been performed.
The AM instance keeps a local copy of the stochastic parameter's trace.
This tr... | [
"Perform",
"a",
"Metropolis",
"step",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1390-L1470 |
225,252 | pymc-devs/pymc | pymc/StepMethods.py | AdaptiveMetropolis.internal_tally | def internal_tally(self):
"""Store the trace of stochastics for the computation of the covariance.
This trace is completely independent from the backend used by the
sampler to store the samples."""
chain = []
for stochastic in self.stochastics:
chain.append(np.ravel(s... | python | def internal_tally(self):
"""Store the trace of stochastics for the computation of the covariance.
This trace is completely independent from the backend used by the
sampler to store the samples."""
chain = []
for stochastic in self.stochastics:
chain.append(np.ravel(s... | [
"def",
"internal_tally",
"(",
"self",
")",
":",
"chain",
"=",
"[",
"]",
"for",
"stochastic",
"in",
"self",
".",
"stochastics",
":",
"chain",
".",
"append",
"(",
"np",
".",
"ravel",
"(",
"stochastic",
".",
"value",
")",
")",
"self",
".",
"_trace",
"."... | Store the trace of stochastics for the computation of the covariance.
This trace is completely independent from the backend used by the
sampler to store the samples. | [
"Store",
"the",
"trace",
"of",
"stochastics",
"for",
"the",
"computation",
"of",
"the",
"covariance",
".",
"This",
"trace",
"is",
"completely",
"independent",
"from",
"the",
"backend",
"used",
"by",
"the",
"sampler",
"to",
"store",
"the",
"samples",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1479-L1486 |
225,253 | pymc-devs/pymc | pymc/StepMethods.py | AdaptiveMetropolis.trace2array | def trace2array(self, sl):
"""Return an array with the trace of all stochastics, sliced by sl."""
chain = []
for stochastic in self.stochastics:
tr = stochastic.trace.gettrace(slicing=sl)
if tr is None:
raise AttributeError
chain.append(tr)
... | python | def trace2array(self, sl):
"""Return an array with the trace of all stochastics, sliced by sl."""
chain = []
for stochastic in self.stochastics:
tr = stochastic.trace.gettrace(slicing=sl)
if tr is None:
raise AttributeError
chain.append(tr)
... | [
"def",
"trace2array",
"(",
"self",
",",
"sl",
")",
":",
"chain",
"=",
"[",
"]",
"for",
"stochastic",
"in",
"self",
".",
"stochastics",
":",
"tr",
"=",
"stochastic",
".",
"trace",
".",
"gettrace",
"(",
"slicing",
"=",
"sl",
")",
"if",
"tr",
"is",
"N... | Return an array with the trace of all stochastics, sliced by sl. | [
"Return",
"an",
"array",
"with",
"the",
"trace",
"of",
"all",
"stochastics",
"sliced",
"by",
"sl",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1488-L1496 |
225,254 | pymc-devs/pymc | pymc/StepMethods.py | AdaptiveMetropolis.stoch2array | def stoch2array(self):
"""Return the stochastic objects as an array."""
a = np.empty(self.dim)
for stochastic in self.stochastics:
a[self._slices[stochastic]] = stochastic.value
return a | python | def stoch2array(self):
"""Return the stochastic objects as an array."""
a = np.empty(self.dim)
for stochastic in self.stochastics:
a[self._slices[stochastic]] = stochastic.value
return a | [
"def",
"stoch2array",
"(",
"self",
")",
":",
"a",
"=",
"np",
".",
"empty",
"(",
"self",
".",
"dim",
")",
"for",
"stochastic",
"in",
"self",
".",
"stochastics",
":",
"a",
"[",
"self",
".",
"_slices",
"[",
"stochastic",
"]",
"]",
"=",
"stochastic",
"... | Return the stochastic objects as an array. | [
"Return",
"the",
"stochastic",
"objects",
"as",
"an",
"array",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1498-L1503 |
225,255 | pymc-devs/pymc | pymc/StepMethods.py | TWalk.walk | def walk(self):
"""Walk proposal kernel"""
if self.verbose > 1:
print_('\t' + self._id + ' Running Walk proposal kernel')
# Mask for values to move
phi = self.phi
theta = self.walk_theta
u = random(len(phi))
z = (theta / (1 + theta)) * (theta * u *... | python | def walk(self):
"""Walk proposal kernel"""
if self.verbose > 1:
print_('\t' + self._id + ' Running Walk proposal kernel')
# Mask for values to move
phi = self.phi
theta = self.walk_theta
u = random(len(phi))
z = (theta / (1 + theta)) * (theta * u *... | [
"def",
"walk",
"(",
"self",
")",
":",
"if",
"self",
".",
"verbose",
">",
"1",
":",
"print_",
"(",
"'\\t'",
"+",
"self",
".",
"_id",
"+",
"' Running Walk proposal kernel'",
")",
"# Mask for values to move",
"phi",
"=",
"self",
".",
"phi",
"theta",
"=",
"s... | Walk proposal kernel | [
"Walk",
"proposal",
"kernel"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1631-L1661 |
225,256 | pymc-devs/pymc | pymc/StepMethods.py | TWalk.traverse | def traverse(self):
"""Traverse proposal kernel"""
if self.verbose > 1:
print_('\t' + self._id + ' Running Traverse proposal kernel')
# Mask for values to move
phi = self.phi
theta = self.traverse_theta
# Calculate beta
if (random() < (theta - 1) /... | python | def traverse(self):
"""Traverse proposal kernel"""
if self.verbose > 1:
print_('\t' + self._id + ' Running Traverse proposal kernel')
# Mask for values to move
phi = self.phi
theta = self.traverse_theta
# Calculate beta
if (random() < (theta - 1) /... | [
"def",
"traverse",
"(",
"self",
")",
":",
"if",
"self",
".",
"verbose",
">",
"1",
":",
"print_",
"(",
"'\\t'",
"+",
"self",
".",
"_id",
"+",
"' Running Traverse proposal kernel'",
")",
"# Mask for values to move",
"phi",
"=",
"self",
".",
"phi",
"theta",
"... | Traverse proposal kernel | [
"Traverse",
"proposal",
"kernel"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1663-L1696 |
225,257 | pymc-devs/pymc | pymc/StepMethods.py | TWalk.blow | def blow(self):
"""Blow proposal kernel"""
if self.verbose > 1:
print_('\t' + self._id + ' Running Blow proposal kernel')
# Mask for values to move
phi = self.phi
if self._prime:
xp, x = self.values
else:
x, xp = self.values
... | python | def blow(self):
"""Blow proposal kernel"""
if self.verbose > 1:
print_('\t' + self._id + ' Running Blow proposal kernel')
# Mask for values to move
phi = self.phi
if self._prime:
xp, x = self.values
else:
x, xp = self.values
... | [
"def",
"blow",
"(",
"self",
")",
":",
"if",
"self",
".",
"verbose",
">",
"1",
":",
"print_",
"(",
"'\\t'",
"+",
"self",
".",
"_id",
"+",
"' Running Blow proposal kernel'",
")",
"# Mask for values to move",
"phi",
"=",
"self",
".",
"phi",
"if",
"self",
".... | Blow proposal kernel | [
"Blow",
"proposal",
"kernel"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1698-L1730 |
225,258 | pymc-devs/pymc | pymc/StepMethods.py | TWalk._g | def _g(self, h, xp, s):
"""Density function for blow and hop moves"""
nphi = sum(self.phi)
return (nphi / 2.0) * log(2 * pi) + nphi * \
log(s) + 0.5 * sum((h - xp) ** 2) / (s ** 2) | python | def _g(self, h, xp, s):
"""Density function for blow and hop moves"""
nphi = sum(self.phi)
return (nphi / 2.0) * log(2 * pi) + nphi * \
log(s) + 0.5 * sum((h - xp) ** 2) / (s ** 2) | [
"def",
"_g",
"(",
"self",
",",
"h",
",",
"xp",
",",
"s",
")",
":",
"nphi",
"=",
"sum",
"(",
"self",
".",
"phi",
")",
"return",
"(",
"nphi",
"/",
"2.0",
")",
"*",
"log",
"(",
"2",
"*",
"pi",
")",
"+",
"nphi",
"*",
"log",
"(",
"s",
")",
"... | Density function for blow and hop moves | [
"Density",
"function",
"for",
"blow",
"and",
"hop",
"moves"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1732-L1738 |
225,259 | pymc-devs/pymc | pymc/StepMethods.py | TWalk.reject | def reject(self):
"""Sets current s value to the last accepted value"""
self.stochastic.revert()
# Increment rejected count
self.rejected[self.current_kernel] += 1
if self.verbose > 1:
print_(
self._id,
"rejected, reverting to value =... | python | def reject(self):
"""Sets current s value to the last accepted value"""
self.stochastic.revert()
# Increment rejected count
self.rejected[self.current_kernel] += 1
if self.verbose > 1:
print_(
self._id,
"rejected, reverting to value =... | [
"def",
"reject",
"(",
"self",
")",
":",
"self",
".",
"stochastic",
".",
"revert",
"(",
")",
"# Increment rejected count",
"self",
".",
"rejected",
"[",
"self",
".",
"current_kernel",
"]",
"+=",
"1",
"if",
"self",
".",
"verbose",
">",
"1",
":",
"print_",
... | Sets current s value to the last accepted value | [
"Sets",
"current",
"s",
"value",
"to",
"the",
"last",
"accepted",
"value"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1774-L1785 |
225,260 | pymc-devs/pymc | pymc/StepMethods.py | TWalk.step | def step(self):
"""Single iteration of t-walk algorithm"""
valid_proposal = False
# Use x or xprime as pivot
self._prime = (random() < 0.5)
if self.verbose > 1:
print_("\n\nUsing x%s as pivot" % (" prime" * self._prime or ""))
if self._prime:
#... | python | def step(self):
"""Single iteration of t-walk algorithm"""
valid_proposal = False
# Use x or xprime as pivot
self._prime = (random() < 0.5)
if self.verbose > 1:
print_("\n\nUsing x%s as pivot" % (" prime" * self._prime or ""))
if self._prime:
#... | [
"def",
"step",
"(",
"self",
")",
":",
"valid_proposal",
"=",
"False",
"# Use x or xprime as pivot",
"self",
".",
"_prime",
"=",
"(",
"random",
"(",
")",
"<",
"0.5",
")",
"if",
"self",
".",
"verbose",
">",
"1",
":",
"print_",
"(",
"\"\\n\\nUsing x%s as pivo... | Single iteration of t-walk algorithm | [
"Single",
"iteration",
"of",
"t",
"-",
"walk",
"algorithm"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1800-L1896 |
225,261 | pymc-devs/pymc | pymc/StepMethods.py | Slicer.step | def step(self):
"""
Slice step method
From Neal 2003 (doi:10.1214/aos/1056562461)
"""
logy = self.loglike - rexponential(1)
L = self.stochastic.value - runiform(0, self.w)
R = L + self.w
if self.doubling:
# Doubling procedure
K =... | python | def step(self):
"""
Slice step method
From Neal 2003 (doi:10.1214/aos/1056562461)
"""
logy = self.loglike - rexponential(1)
L = self.stochastic.value - runiform(0, self.w)
R = L + self.w
if self.doubling:
# Doubling procedure
K =... | [
"def",
"step",
"(",
"self",
")",
":",
"logy",
"=",
"self",
".",
"loglike",
"-",
"rexponential",
"(",
"1",
")",
"L",
"=",
"self",
".",
"stochastic",
".",
"value",
"-",
"runiform",
"(",
"0",
",",
"self",
".",
"w",
")",
"R",
"=",
"L",
"+",
"self",... | Slice step method
From Neal 2003 (doi:10.1214/aos/1056562461) | [
"Slice",
"step",
"method"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L1960-L2007 |
225,262 | pymc-devs/pymc | pymc/StepMethods.py | Slicer.fll | def fll(self, value):
"""
Returns loglike of value
"""
self.stochastic.value = value
try:
ll = self.loglike
except ZeroProbability:
ll = -np.infty
self.stochastic.revert()
return ll | python | def fll(self, value):
"""
Returns loglike of value
"""
self.stochastic.value = value
try:
ll = self.loglike
except ZeroProbability:
ll = -np.infty
self.stochastic.revert()
return ll | [
"def",
"fll",
"(",
"self",
",",
"value",
")",
":",
"self",
".",
"stochastic",
".",
"value",
"=",
"value",
"try",
":",
"ll",
"=",
"self",
".",
"loglike",
"except",
"ZeroProbability",
":",
"ll",
"=",
"-",
"np",
".",
"infty",
"self",
".",
"stochastic",
... | Returns loglike of value | [
"Returns",
"loglike",
"of",
"value"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L2009-L2019 |
225,263 | pymc-devs/pymc | pymc/StepMethods.py | Slicer.tune | def tune(self, verbose=None):
"""
Tuning initial slice width parameter
"""
if not self._tune:
return False
else:
self.w_tune.append(
abs(self.stochastic.last_value - self.stochastic.value))
self.w = 2 * (sum(self.w_tune) / len(s... | python | def tune(self, verbose=None):
"""
Tuning initial slice width parameter
"""
if not self._tune:
return False
else:
self.w_tune.append(
abs(self.stochastic.last_value - self.stochastic.value))
self.w = 2 * (sum(self.w_tune) / len(s... | [
"def",
"tune",
"(",
"self",
",",
"verbose",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"_tune",
":",
"return",
"False",
"else",
":",
"self",
".",
"w_tune",
".",
"append",
"(",
"abs",
"(",
"self",
".",
"stochastic",
".",
"last_value",
"-",
"se... | Tuning initial slice width parameter | [
"Tuning",
"initial",
"slice",
"width",
"parameter"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/StepMethods.py#L2021-L2031 |
225,264 | pymc-devs/pymc | pymc/database/ram.py | Trace.tally | def tally(self, chain):
"""Store the object's current value to a chain.
:Parameters:
chain : integer
Chain index.
"""
value = self._getfunc()
try:
self._trace[chain][self._index[chain]] = value.copy()
except AttributeError:
sel... | python | def tally(self, chain):
"""Store the object's current value to a chain.
:Parameters:
chain : integer
Chain index.
"""
value = self._getfunc()
try:
self._trace[chain][self._index[chain]] = value.copy()
except AttributeError:
sel... | [
"def",
"tally",
"(",
"self",
",",
"chain",
")",
":",
"value",
"=",
"self",
".",
"_getfunc",
"(",
")",
"try",
":",
"self",
".",
"_trace",
"[",
"chain",
"]",
"[",
"self",
".",
"_index",
"[",
"chain",
"]",
"]",
"=",
"value",
".",
"copy",
"(",
")",... | Store the object's current value to a chain.
:Parameters:
chain : integer
Chain index. | [
"Store",
"the",
"object",
"s",
"current",
"value",
"to",
"a",
"chain",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/ram.py#L86-L100 |
225,265 | pymc-devs/pymc | pymc/database/ram.py | Trace.truncate | def truncate(self, index, chain):
"""
Truncate the trace array to some index.
:Parameters:
index : int
The index within the chain after which all values will be removed.
chain : int
The chain index (>=0).
"""
self._trace[chain] = self._trace[c... | python | def truncate(self, index, chain):
"""
Truncate the trace array to some index.
:Parameters:
index : int
The index within the chain after which all values will be removed.
chain : int
The chain index (>=0).
"""
self._trace[chain] = self._trace[c... | [
"def",
"truncate",
"(",
"self",
",",
"index",
",",
"chain",
")",
":",
"self",
".",
"_trace",
"[",
"chain",
"]",
"=",
"self",
".",
"_trace",
"[",
"chain",
"]",
"[",
":",
"index",
"]"
] | Truncate the trace array to some index.
:Parameters:
index : int
The index within the chain after which all values will be removed.
chain : int
The chain index (>=0). | [
"Truncate",
"the",
"trace",
"array",
"to",
"some",
"index",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/ram.py#L102-L112 |
225,266 | pymc-devs/pymc | pymc/database/ram.py | Trace.gettrace | def gettrace(self, burn=0, thin=1, chain=-1, slicing=None):
"""Return the trace.
:Stochastics:
- burn (int): The number of transient steps to skip.
- thin (int): Keep one in thin.
- chain (int): The index of the chain to fetch. If None, return all chains.
- slici... | python | def gettrace(self, burn=0, thin=1, chain=-1, slicing=None):
"""Return the trace.
:Stochastics:
- burn (int): The number of transient steps to skip.
- thin (int): Keep one in thin.
- chain (int): The index of the chain to fetch. If None, return all chains.
- slici... | [
"def",
"gettrace",
"(",
"self",
",",
"burn",
"=",
"0",
",",
"thin",
"=",
"1",
",",
"chain",
"=",
"-",
"1",
",",
"slicing",
"=",
"None",
")",
":",
"if",
"slicing",
"is",
"None",
":",
"slicing",
"=",
"slice",
"(",
"burn",
",",
"None",
",",
"thin"... | Return the trace.
:Stochastics:
- burn (int): The number of transient steps to skip.
- thin (int): Keep one in thin.
- chain (int): The index of the chain to fetch. If None, return all chains.
- slicing: A slice, overriding burn and thin assignement. | [
"Return",
"the",
"trace",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/ram.py#L114-L130 |
225,267 | pymc-devs/pymc | pymc/database/hdf5ea.py | load | def load(dbname, dbmode='a'):
"""Load an existing hdf5 database.
Return a Database instance.
:Parameters:
filename : string
Name of the hdf5 database to open.
mode : 'a', 'r'
File mode : 'a': append, 'r': read-only.
"""
if dbmode == 'w':
raise AttributeError("db... | python | def load(dbname, dbmode='a'):
"""Load an existing hdf5 database.
Return a Database instance.
:Parameters:
filename : string
Name of the hdf5 database to open.
mode : 'a', 'r'
File mode : 'a': append, 'r': read-only.
"""
if dbmode == 'w':
raise AttributeError("db... | [
"def",
"load",
"(",
"dbname",
",",
"dbmode",
"=",
"'a'",
")",
":",
"if",
"dbmode",
"==",
"'w'",
":",
"raise",
"AttributeError",
"(",
"\"dbmode='w' not allowed for load.\"",
")",
"db",
"=",
"Database",
"(",
"dbname",
",",
"dbmode",
"=",
"dbmode",
")",
"retu... | Load an existing hdf5 database.
Return a Database instance.
:Parameters:
filename : string
Name of the hdf5 database to open.
mode : 'a', 'r'
File mode : 'a': append, 'r': read-only. | [
"Load",
"an",
"existing",
"hdf5",
"database",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/hdf5ea.py#L300-L315 |
225,268 | pymc-devs/pymc | pymc/database/txt.py | load | def load(dirname):
"""Create a Database instance from the data stored in the directory."""
if not os.path.exists(dirname):
raise AttributeError('No txt database named %s' % dirname)
db = Database(dirname, dbmode='a')
chain_folders = [os.path.join(dirname, c) for c in db.get_chains()]
db.cha... | python | def load(dirname):
"""Create a Database instance from the data stored in the directory."""
if not os.path.exists(dirname):
raise AttributeError('No txt database named %s' % dirname)
db = Database(dirname, dbmode='a')
chain_folders = [os.path.join(dirname, c) for c in db.get_chains()]
db.cha... | [
"def",
"load",
"(",
"dirname",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"dirname",
")",
":",
"raise",
"AttributeError",
"(",
"'No txt database named %s'",
"%",
"dirname",
")",
"db",
"=",
"Database",
"(",
"dirname",
",",
"dbmode",
"="... | Create a Database instance from the data stored in the directory. | [
"Create",
"a",
"Database",
"instance",
"from",
"the",
"data",
"stored",
"in",
"the",
"directory",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/txt.py#L148-L195 |
225,269 | pymc-devs/pymc | pymc/database/txt.py | funname | def funname(file):
"""Return variable names from file names."""
if isinstance(file, str):
files = [file]
else:
files = file
bases = [os.path.basename(f) for f in files]
names = [os.path.splitext(b)[0] for b in bases]
if isinstance(file, str):
return names[0]
else:
... | python | def funname(file):
"""Return variable names from file names."""
if isinstance(file, str):
files = [file]
else:
files = file
bases = [os.path.basename(f) for f in files]
names = [os.path.splitext(b)[0] for b in bases]
if isinstance(file, str):
return names[0]
else:
... | [
"def",
"funname",
"(",
"file",
")",
":",
"if",
"isinstance",
"(",
"file",
",",
"str",
")",
":",
"files",
"=",
"[",
"file",
"]",
"else",
":",
"files",
"=",
"file",
"bases",
"=",
"[",
"os",
".",
"path",
".",
"basename",
"(",
"f",
")",
"for",
"f",... | Return variable names from file names. | [
"Return",
"variable",
"names",
"from",
"file",
"names",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/txt.py#L198-L209 |
225,270 | pymc-devs/pymc | pymc/database/txt.py | Trace._finalize | def _finalize(self, chain):
"""Write the trace to an ASCII file.
:Parameter:
chain : int
The chain index.
"""
path = os.path.join(
self.db._directory,
self.db.get_chains()[chain],
self.name + '.txt')
arr = self.gettrace(chain... | python | def _finalize(self, chain):
"""Write the trace to an ASCII file.
:Parameter:
chain : int
The chain index.
"""
path = os.path.join(
self.db._directory,
self.db.get_chains()[chain],
self.name + '.txt')
arr = self.gettrace(chain... | [
"def",
"_finalize",
"(",
"self",
",",
"chain",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"db",
".",
"_directory",
",",
"self",
".",
"db",
".",
"get_chains",
"(",
")",
"[",
"chain",
"]",
",",
"self",
".",
"name",
"... | Write the trace to an ASCII file.
:Parameter:
chain : int
The chain index. | [
"Write",
"the",
"trace",
"to",
"an",
"ASCII",
"file",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/txt.py#L59-L81 |
225,271 | pymc-devs/pymc | pymc/database/txt.py | Database._initialize | def _initialize(self, funs_to_tally, length):
"""Create folder to store simulation results."""
dir = os.path.join(self._directory, CHAIN_NAME % self.chains)
os.mkdir(dir)
base.Database._initialize(self, funs_to_tally, length) | python | def _initialize(self, funs_to_tally, length):
"""Create folder to store simulation results."""
dir = os.path.join(self._directory, CHAIN_NAME % self.chains)
os.mkdir(dir)
base.Database._initialize(self, funs_to_tally, length) | [
"def",
"_initialize",
"(",
"self",
",",
"funs_to_tally",
",",
"length",
")",
":",
"dir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"_directory",
",",
"CHAIN_NAME",
"%",
"self",
".",
"chains",
")",
"os",
".",
"mkdir",
"(",
"dir",
")",
"... | Create folder to store simulation results. | [
"Create",
"folder",
"to",
"store",
"simulation",
"results",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/txt.py#L129-L135 |
225,272 | pymc-devs/pymc | pymc/database/txt.py | Database.savestate | def savestate(self, state):
"""Save the sampler's state in a state.txt file."""
oldstate = np.get_printoptions()
np.set_printoptions(threshold=1e6)
try:
with open(os.path.join(self._directory, 'state.txt'), 'w') as f:
print_(state, file=f)
finally:
... | python | def savestate(self, state):
"""Save the sampler's state in a state.txt file."""
oldstate = np.get_printoptions()
np.set_printoptions(threshold=1e6)
try:
with open(os.path.join(self._directory, 'state.txt'), 'w') as f:
print_(state, file=f)
finally:
... | [
"def",
"savestate",
"(",
"self",
",",
"state",
")",
":",
"oldstate",
"=",
"np",
".",
"get_printoptions",
"(",
")",
"np",
".",
"set_printoptions",
"(",
"threshold",
"=",
"1e6",
")",
"try",
":",
"with",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",... | Save the sampler's state in a state.txt file. | [
"Save",
"the",
"sampler",
"s",
"state",
"in",
"a",
"state",
".",
"txt",
"file",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/txt.py#L137-L145 |
225,273 | pymc-devs/pymc | pymc/examples/disaster_model_missing.py | rate | def rate(s=switch, e=early_mean, l=late_mean):
"""Allocate appropriate mean to time series"""
out = np.empty(len(disasters_array))
# Early mean prior to switchpoint
out[:s] = e
# Late mean following switchpoint
out[s:] = l
return out | python | def rate(s=switch, e=early_mean, l=late_mean):
"""Allocate appropriate mean to time series"""
out = np.empty(len(disasters_array))
# Early mean prior to switchpoint
out[:s] = e
# Late mean following switchpoint
out[s:] = l
return out | [
"def",
"rate",
"(",
"s",
"=",
"switch",
",",
"e",
"=",
"early_mean",
",",
"l",
"=",
"late_mean",
")",
":",
"out",
"=",
"np",
".",
"empty",
"(",
"len",
"(",
"disasters_array",
")",
")",
"# Early mean prior to switchpoint",
"out",
"[",
":",
"s",
"]",
"... | Allocate appropriate mean to time series | [
"Allocate",
"appropriate",
"mean",
"to",
"time",
"series"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/examples/disaster_model_missing.py#L36-L43 |
225,274 | pymc-devs/pymc | pymc/gp/GPutils.py | fast_matrix_copy | def fast_matrix_copy(f, t=None, n_threads=1):
"""
Not any faster than a serial copy so far.
"""
if not f.flags['F_CONTIGUOUS']:
raise RuntimeError(
'This will not be fast unless input array f is Fortran-contiguous.')
if t is None:
t = asmatrix(empty(f.shape, order='F'))
... | python | def fast_matrix_copy(f, t=None, n_threads=1):
"""
Not any faster than a serial copy so far.
"""
if not f.flags['F_CONTIGUOUS']:
raise RuntimeError(
'This will not be fast unless input array f is Fortran-contiguous.')
if t is None:
t = asmatrix(empty(f.shape, order='F'))
... | [
"def",
"fast_matrix_copy",
"(",
"f",
",",
"t",
"=",
"None",
",",
"n_threads",
"=",
"1",
")",
":",
"if",
"not",
"f",
".",
"flags",
"[",
"'F_CONTIGUOUS'",
"]",
":",
"raise",
"RuntimeError",
"(",
"'This will not be fast unless input array f is Fortran-contiguous.'",
... | Not any faster than a serial copy so far. | [
"Not",
"any",
"faster",
"than",
"a",
"serial",
"copy",
"so",
"far",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/gp/GPutils.py#L34-L50 |
225,275 | pymc-devs/pymc | pymc/gp/GPutils.py | vecs_to_datmesh | def vecs_to_datmesh(x, y):
"""
Converts input arguments x and y to a 2d meshgrid,
suitable for calling Means, Covariances and Realizations.
"""
x, y = meshgrid(x, y)
out = zeros(x.shape + (2,), dtype=float)
out[:, :, 0] = x
out[:, :, 1] = y
return out | python | def vecs_to_datmesh(x, y):
"""
Converts input arguments x and y to a 2d meshgrid,
suitable for calling Means, Covariances and Realizations.
"""
x, y = meshgrid(x, y)
out = zeros(x.shape + (2,), dtype=float)
out[:, :, 0] = x
out[:, :, 1] = y
return out | [
"def",
"vecs_to_datmesh",
"(",
"x",
",",
"y",
")",
":",
"x",
",",
"y",
"=",
"meshgrid",
"(",
"x",
",",
"y",
")",
"out",
"=",
"zeros",
"(",
"x",
".",
"shape",
"+",
"(",
"2",
",",
")",
",",
"dtype",
"=",
"float",
")",
"out",
"[",
":",
",",
... | Converts input arguments x and y to a 2d meshgrid,
suitable for calling Means, Covariances and Realizations. | [
"Converts",
"input",
"arguments",
"x",
"and",
"y",
"to",
"a",
"2d",
"meshgrid",
"suitable",
"for",
"calling",
"Means",
"Covariances",
"and",
"Realizations",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/gp/GPutils.py#L150-L159 |
225,276 | pymc-devs/pymc | pymc/database/base.py | batchsd | def batchsd(trace, batches=5):
"""
Calculates the simulation standard error, accounting for non-independent
samples. The trace is divided into batches, and the standard deviation of
the batch means is calculated.
"""
if len(np.shape(trace)) > 1:
dims = np.shape(trace)
# ttrace ... | python | def batchsd(trace, batches=5):
"""
Calculates the simulation standard error, accounting for non-independent
samples. The trace is divided into batches, and the standard deviation of
the batch means is calculated.
"""
if len(np.shape(trace)) > 1:
dims = np.shape(trace)
# ttrace ... | [
"def",
"batchsd",
"(",
"trace",
",",
"batches",
"=",
"5",
")",
":",
"if",
"len",
"(",
"np",
".",
"shape",
"(",
"trace",
")",
")",
">",
"1",
":",
"dims",
"=",
"np",
".",
"shape",
"(",
"trace",
")",
"# ttrace = np.transpose(np.reshape(trace, (dims[0], sum(... | Calculates the simulation standard error, accounting for non-independent
samples. The trace is divided into batches, and the standard deviation of
the batch means is calculated. | [
"Calculates",
"the",
"simulation",
"standard",
"error",
"accounting",
"for",
"non",
"-",
"independent",
"samples",
".",
"The",
"trace",
"is",
"divided",
"into",
"batches",
"and",
"the",
"standard",
"deviation",
"of",
"the",
"batch",
"means",
"is",
"calculated",
... | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/base.py#L395-L424 |
225,277 | pymc-devs/pymc | pymc/database/base.py | Trace._initialize | def _initialize(self, chain, length):
"""Prepare for tallying. Create a new chain."""
# If this db was loaded from the disk, it may not have its
# tallied step methods' getfuncs yet.
if self._getfunc is None:
self._getfunc = self.db.model._funs_to_tally[self.name] | python | def _initialize(self, chain, length):
"""Prepare for tallying. Create a new chain."""
# If this db was loaded from the disk, it may not have its
# tallied step methods' getfuncs yet.
if self._getfunc is None:
self._getfunc = self.db.model._funs_to_tally[self.name] | [
"def",
"_initialize",
"(",
"self",
",",
"chain",
",",
"length",
")",
":",
"# If this db was loaded from the disk, it may not have its",
"# tallied step methods' getfuncs yet.",
"if",
"self",
".",
"_getfunc",
"is",
"None",
":",
"self",
".",
"_getfunc",
"=",
"self",
"."... | Prepare for tallying. Create a new chain. | [
"Prepare",
"for",
"tallying",
".",
"Create",
"a",
"new",
"chain",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/base.py#L88-L93 |
225,278 | pymc-devs/pymc | pymc/database/base.py | Database._initialize | def _initialize(self, funs_to_tally, length=None):
"""Initialize the tallyable objects.
Makes sure a Trace object exists for each variable and then initialize
the Traces.
:Parameters:
funs_to_tally : dict
Name- function pairs.
length : int
The expect... | python | def _initialize(self, funs_to_tally, length=None):
"""Initialize the tallyable objects.
Makes sure a Trace object exists for each variable and then initialize
the Traces.
:Parameters:
funs_to_tally : dict
Name- function pairs.
length : int
The expect... | [
"def",
"_initialize",
"(",
"self",
",",
"funs_to_tally",
",",
"length",
"=",
"None",
")",
":",
"for",
"name",
",",
"fun",
"in",
"six",
".",
"iteritems",
"(",
"funs_to_tally",
")",
":",
"if",
"name",
"not",
"in",
"self",
".",
"_traces",
":",
"self",
"... | Initialize the tallyable objects.
Makes sure a Trace object exists for each variable and then initialize
the Traces.
:Parameters:
funs_to_tally : dict
Name- function pairs.
length : int
The expected length of the chain. Some database may need the argument
... | [
"Initialize",
"the",
"tallyable",
"objects",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/base.py#L232-L258 |
225,279 | pymc-devs/pymc | pymc/database/base.py | Database._finalize | def _finalize(self, chain=-1):
"""Finalize the chain for all tallyable objects."""
chain = range(self.chains)[chain]
for name in self.trace_names[chain]:
self._traces[name]._finalize(chain)
self.commit() | python | def _finalize(self, chain=-1):
"""Finalize the chain for all tallyable objects."""
chain = range(self.chains)[chain]
for name in self.trace_names[chain]:
self._traces[name]._finalize(chain)
self.commit() | [
"def",
"_finalize",
"(",
"self",
",",
"chain",
"=",
"-",
"1",
")",
":",
"chain",
"=",
"range",
"(",
"self",
".",
"chains",
")",
"[",
"chain",
"]",
"for",
"name",
"in",
"self",
".",
"trace_names",
"[",
"chain",
"]",
":",
"self",
".",
"_traces",
"[... | Finalize the chain for all tallyable objects. | [
"Finalize",
"the",
"chain",
"for",
"all",
"tallyable",
"objects",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/base.py#L332-L337 |
225,280 | pymc-devs/pymc | pymc/database/base.py | Database.truncate | def truncate(self, index, chain=-1):
"""Tell the traces to truncate themselves at the given index."""
chain = range(self.chains)[chain]
for name in self.trace_names[chain]:
self._traces[name].truncate(index, chain) | python | def truncate(self, index, chain=-1):
"""Tell the traces to truncate themselves at the given index."""
chain = range(self.chains)[chain]
for name in self.trace_names[chain]:
self._traces[name].truncate(index, chain) | [
"def",
"truncate",
"(",
"self",
",",
"index",
",",
"chain",
"=",
"-",
"1",
")",
":",
"chain",
"=",
"range",
"(",
"self",
".",
"chains",
")",
"[",
"chain",
"]",
"for",
"name",
"in",
"self",
".",
"trace_names",
"[",
"chain",
"]",
":",
"self",
".",
... | Tell the traces to truncate themselves at the given index. | [
"Tell",
"the",
"traces",
"to",
"truncate",
"themselves",
"at",
"the",
"given",
"index",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/base.py#L339-L343 |
225,281 | pymc-devs/pymc | pymc/gp/Mean.py | Mean.observe | def observe(self, C, obs_mesh_new, obs_vals_new, mean_under=None):
"""
Synchronizes self's observation status with C's.
Values of observation are given by obs_vals.
obs_mesh_new and obs_vals_new should already have
been sliced, as Covariance.observe(..., output_type='o') does.
... | python | def observe(self, C, obs_mesh_new, obs_vals_new, mean_under=None):
"""
Synchronizes self's observation status with C's.
Values of observation are given by obs_vals.
obs_mesh_new and obs_vals_new should already have
been sliced, as Covariance.observe(..., output_type='o') does.
... | [
"def",
"observe",
"(",
"self",
",",
"C",
",",
"obs_mesh_new",
",",
"obs_vals_new",
",",
"mean_under",
"=",
"None",
")",
":",
"self",
".",
"C",
"=",
"C",
"self",
".",
"obs_mesh",
"=",
"C",
".",
"obs_mesh",
"self",
".",
"obs_len",
"=",
"C",
".",
"obs... | Synchronizes self's observation status with C's.
Values of observation are given by obs_vals.
obs_mesh_new and obs_vals_new should already have
been sliced, as Covariance.observe(..., output_type='o') does. | [
"Synchronizes",
"self",
"s",
"observation",
"status",
"with",
"C",
"s",
".",
"Values",
"of",
"observation",
"are",
"given",
"by",
"obs_vals",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/gp/Mean.py#L49-L93 |
225,282 | pymc-devs/pymc | pymc/InstantiationDecorators.py | _extract | def _extract(__func__, kwds, keys, classname, probe=True):
"""
Used by decorators stochastic and deterministic to inspect declarations
"""
# Add docs and name
kwds['doc'] = __func__.__doc__
if not 'name' in kwds:
kwds['name'] = __func__.__name__
# kwds.update({'doc':__func__.__doc__... | python | def _extract(__func__, kwds, keys, classname, probe=True):
"""
Used by decorators stochastic and deterministic to inspect declarations
"""
# Add docs and name
kwds['doc'] = __func__.__doc__
if not 'name' in kwds:
kwds['name'] = __func__.__name__
# kwds.update({'doc':__func__.__doc__... | [
"def",
"_extract",
"(",
"__func__",
",",
"kwds",
",",
"keys",
",",
"classname",
",",
"probe",
"=",
"True",
")",
":",
"# Add docs and name",
"kwds",
"[",
"'doc'",
"]",
"=",
"__func__",
".",
"__doc__",
"if",
"not",
"'name'",
"in",
"kwds",
":",
"kwds",
"[... | Used by decorators stochastic and deterministic to inspect declarations | [
"Used",
"by",
"decorators",
"stochastic",
"and",
"deterministic",
"to",
"inspect",
"declarations"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/InstantiationDecorators.py#L47-L126 |
225,283 | pymc-devs/pymc | pymc/InstantiationDecorators.py | observed | def observed(obj=None, **kwds):
"""
Decorator function to instantiate data objects.
If given a Stochastic, sets a the observed flag to True.
Can be used as
@observed
def A(value = ., parent_name = ., ...):
return foo(value, parent_name, ...)
or as
@stochastic(observed=True)
... | python | def observed(obj=None, **kwds):
"""
Decorator function to instantiate data objects.
If given a Stochastic, sets a the observed flag to True.
Can be used as
@observed
def A(value = ., parent_name = ., ...):
return foo(value, parent_name, ...)
or as
@stochastic(observed=True)
... | [
"def",
"observed",
"(",
"obj",
"=",
"None",
",",
"*",
"*",
"kwds",
")",
":",
"if",
"obj",
"is",
"not",
"None",
":",
"if",
"isinstance",
"(",
"obj",
",",
"Stochastic",
")",
":",
"obj",
".",
"_observed",
"=",
"True",
"return",
"obj",
"else",
":",
"... | Decorator function to instantiate data objects.
If given a Stochastic, sets a the observed flag to True.
Can be used as
@observed
def A(value = ., parent_name = ., ...):
return foo(value, parent_name, ...)
or as
@stochastic(observed=True)
def A(value = ., parent_name = ., ...):... | [
"Decorator",
"function",
"to",
"instantiate",
"data",
"objects",
".",
"If",
"given",
"a",
"Stochastic",
"sets",
"a",
"the",
"observed",
"flag",
"to",
"True",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/InstantiationDecorators.py#L259-L295 |
225,284 | pymc-devs/pymc | pymc/InstantiationDecorators.py | robust_init | def robust_init(stochclass, tries, *args, **kwds):
"""Robust initialization of a Stochastic.
If the evaluation of the log-probability returns a ZeroProbability
error, due for example to a parent being outside of the support for
this Stochastic, the values of parents are randomly sampled until
a val... | python | def robust_init(stochclass, tries, *args, **kwds):
"""Robust initialization of a Stochastic.
If the evaluation of the log-probability returns a ZeroProbability
error, due for example to a parent being outside of the support for
this Stochastic, the values of parents are randomly sampled until
a val... | [
"def",
"robust_init",
"(",
"stochclass",
",",
"tries",
",",
"*",
"args",
",",
"*",
"*",
"kwds",
")",
":",
"# Find the direct parents",
"stochs",
"=",
"[",
"arg",
"for",
"arg",
"in",
"(",
"list",
"(",
"args",
")",
"+",
"list",
"(",
"kwds",
".",
"value... | Robust initialization of a Stochastic.
If the evaluation of the log-probability returns a ZeroProbability
error, due for example to a parent being outside of the support for
this Stochastic, the values of parents are randomly sampled until
a valid log-probability is obtained.
If the log-probabilit... | [
"Robust",
"initialization",
"of",
"a",
"Stochastic",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/InstantiationDecorators.py#L300-L351 |
225,285 | pymc-devs/pymc | pymc/examples/gp/more_examples/MKMsalmon/salmon.py | salmon.plot | def plot(self):
"""
Plot posterior from simple nonstochetric regression.
"""
figure()
plot_envelope(self.M, self.C, self.xplot)
for i in range(3):
f = Realization(self.M, self.C)
plot(self.xplot,f(self.xplot))
plot(self.abundance, self.fry... | python | def plot(self):
"""
Plot posterior from simple nonstochetric regression.
"""
figure()
plot_envelope(self.M, self.C, self.xplot)
for i in range(3):
f = Realization(self.M, self.C)
plot(self.xplot,f(self.xplot))
plot(self.abundance, self.fry... | [
"def",
"plot",
"(",
"self",
")",
":",
"figure",
"(",
")",
"plot_envelope",
"(",
"self",
".",
"M",
",",
"self",
".",
"C",
",",
"self",
".",
"xplot",
")",
"for",
"i",
"in",
"range",
"(",
"3",
")",
":",
"f",
"=",
"Realization",
"(",
"self",
".",
... | Plot posterior from simple nonstochetric regression. | [
"Plot",
"posterior",
"from",
"simple",
"nonstochetric",
"regression",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/examples/gp/more_examples/MKMsalmon/salmon.py#L54-L68 |
225,286 | pymc-devs/pymc | pymc/examples/melanoma.py | survival | def survival(value=t, lam=lam, f=failure):
"""Exponential survival likelihood, accounting for censoring"""
return sum(f * log(lam) - lam * value) | python | def survival(value=t, lam=lam, f=failure):
"""Exponential survival likelihood, accounting for censoring"""
return sum(f * log(lam) - lam * value) | [
"def",
"survival",
"(",
"value",
"=",
"t",
",",
"lam",
"=",
"lam",
",",
"f",
"=",
"failure",
")",
":",
"return",
"sum",
"(",
"f",
"*",
"log",
"(",
"lam",
")",
"-",
"lam",
"*",
"value",
")"
] | Exponential survival likelihood, accounting for censoring | [
"Exponential",
"survival",
"likelihood",
"accounting",
"for",
"censoring"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/examples/melanoma.py#L43-L45 |
225,287 | pymc-devs/pymc | pymc/examples/disaster_model_gof.py | disasters_sim | def disasters_sim(early_mean=early_mean,
late_mean=late_mean,
switchpoint=switchpoint):
"""Coal mining disasters sampled from the posterior predictive distribution"""
return concatenate((pm.rpoisson(early_mean, size=switchpoint), pm.rpoisson(
late_mean, size=n - switc... | python | def disasters_sim(early_mean=early_mean,
late_mean=late_mean,
switchpoint=switchpoint):
"""Coal mining disasters sampled from the posterior predictive distribution"""
return concatenate((pm.rpoisson(early_mean, size=switchpoint), pm.rpoisson(
late_mean, size=n - switc... | [
"def",
"disasters_sim",
"(",
"early_mean",
"=",
"early_mean",
",",
"late_mean",
"=",
"late_mean",
",",
"switchpoint",
"=",
"switchpoint",
")",
":",
"return",
"concatenate",
"(",
"(",
"pm",
".",
"rpoisson",
"(",
"early_mean",
",",
"size",
"=",
"switchpoint",
... | Coal mining disasters sampled from the posterior predictive distribution | [
"Coal",
"mining",
"disasters",
"sampled",
"from",
"the",
"posterior",
"predictive",
"distribution"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/examples/disaster_model_gof.py#L50-L55 |
225,288 | pymc-devs/pymc | pymc/examples/disaster_model_gof.py | expected_values | def expected_values(early_mean=early_mean,
late_mean=late_mean,
switchpoint=switchpoint):
"""Discrepancy measure for GOF using the Freeman-Tukey statistic"""
# Sample size
n = len(disasters_array)
# Expected values
return concatenate(
(ones(switchpoin... | python | def expected_values(early_mean=early_mean,
late_mean=late_mean,
switchpoint=switchpoint):
"""Discrepancy measure for GOF using the Freeman-Tukey statistic"""
# Sample size
n = len(disasters_array)
# Expected values
return concatenate(
(ones(switchpoin... | [
"def",
"expected_values",
"(",
"early_mean",
"=",
"early_mean",
",",
"late_mean",
"=",
"late_mean",
",",
"switchpoint",
"=",
"switchpoint",
")",
":",
"# Sample size",
"n",
"=",
"len",
"(",
"disasters_array",
")",
"# Expected values",
"return",
"concatenate",
"(",
... | Discrepancy measure for GOF using the Freeman-Tukey statistic | [
"Discrepancy",
"measure",
"for",
"GOF",
"using",
"the",
"Freeman",
"-",
"Tukey",
"statistic"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/examples/disaster_model_gof.py#L59-L68 |
225,289 | pymc-devs/pymc | pymc/database/pickle.py | load | def load(filename):
"""Load a pickled database.
Return a Database instance.
"""
file = open(filename, 'rb')
container = std_pickle.load(file)
file.close()
db = Database(file.name)
chains = 0
funs = set()
for k, v in six.iteritems(container):
if k == '_state_':
... | python | def load(filename):
"""Load a pickled database.
Return a Database instance.
"""
file = open(filename, 'rb')
container = std_pickle.load(file)
file.close()
db = Database(file.name)
chains = 0
funs = set()
for k, v in six.iteritems(container):
if k == '_state_':
... | [
"def",
"load",
"(",
"filename",
")",
":",
"file",
"=",
"open",
"(",
"filename",
",",
"'rb'",
")",
"container",
"=",
"std_pickle",
".",
"load",
"(",
"file",
")",
"file",
".",
"close",
"(",
")",
"db",
"=",
"Database",
"(",
"file",
".",
"name",
")",
... | Load a pickled database.
Return a Database instance. | [
"Load",
"a",
"pickled",
"database",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/pickle.py#L77-L100 |
225,290 | pymc-devs/pymc | pymc/database/pickle.py | Database._finalize | def _finalize(self):
"""Dump traces using cPickle."""
container = {}
try:
for name in self._traces:
container[name] = self._traces[name]._trace
container['_state_'] = self._state_
file = open(self.filename, 'w+b')
std_pickle.dump(c... | python | def _finalize(self):
"""Dump traces using cPickle."""
container = {}
try:
for name in self._traces:
container[name] = self._traces[name]._trace
container['_state_'] = self._state_
file = open(self.filename, 'w+b')
std_pickle.dump(c... | [
"def",
"_finalize",
"(",
"self",
")",
":",
"container",
"=",
"{",
"}",
"try",
":",
"for",
"name",
"in",
"self",
".",
"_traces",
":",
"container",
"[",
"name",
"]",
"=",
"self",
".",
"_traces",
"[",
"name",
"]",
".",
"_trace",
"container",
"[",
"'_s... | Dump traces using cPickle. | [
"Dump",
"traces",
"using",
"cPickle",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/database/pickle.py#L62-L74 |
225,291 | pymc-devs/pymc | pymc/diagnostics.py | geweke | def geweke(x, first=.1, last=.5, intervals=20, maxlag=20):
"""Return z-scores for convergence diagnostics.
Compare the mean of the first % of series with the mean of the last % of
series. x is divided into a number of segments for which this difference is
computed. If the series is converged, this scor... | python | def geweke(x, first=.1, last=.5, intervals=20, maxlag=20):
"""Return z-scores for convergence diagnostics.
Compare the mean of the first % of series with the mean of the last % of
series. x is divided into a number of segments for which this difference is
computed. If the series is converged, this scor... | [
"def",
"geweke",
"(",
"x",
",",
"first",
"=",
".1",
",",
"last",
"=",
".5",
",",
"intervals",
"=",
"20",
",",
"maxlag",
"=",
"20",
")",
":",
"if",
"not",
"has_sm",
":",
"print",
"(",
"\"statsmodels not available. Geweke diagnostic cannot be calculated.\"",
"... | Return z-scores for convergence diagnostics.
Compare the mean of the first % of series with the mean of the last % of
series. x is divided into a number of segments for which this difference is
computed. If the series is converged, this score should oscillate between
-1 and 1.
Parameters
-----... | [
"Return",
"z",
"-",
"scores",
"for",
"convergence",
"diagnostics",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/diagnostics.py#L236-L315 |
225,292 | pymc-devs/pymc | pymc/diagnostics.py | raftery_lewis | def raftery_lewis(x, q, r, s=.95, epsilon=.001, verbose=1):
"""
Return the number of iterations needed to achieve a given
precision.
:Parameters:
x : sequence
Sampled series.
q : float
Quantile.
r : float
Accuracy requested for quantile.
... | python | def raftery_lewis(x, q, r, s=.95, epsilon=.001, verbose=1):
"""
Return the number of iterations needed to achieve a given
precision.
:Parameters:
x : sequence
Sampled series.
q : float
Quantile.
r : float
Accuracy requested for quantile.
... | [
"def",
"raftery_lewis",
"(",
"x",
",",
"q",
",",
"r",
",",
"s",
"=",
".95",
",",
"epsilon",
"=",
".001",
",",
"verbose",
"=",
"1",
")",
":",
"if",
"np",
".",
"ndim",
"(",
"x",
")",
">",
"1",
":",
"return",
"[",
"raftery_lewis",
"(",
"y",
",",... | Return the number of iterations needed to achieve a given
precision.
:Parameters:
x : sequence
Sampled series.
q : float
Quantile.
r : float
Accuracy requested for quantile.
s (optional) : float
Probability of attaining the request... | [
"Return",
"the",
"number",
"of",
"iterations",
"needed",
"to",
"achieve",
"a",
"given",
"precision",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/diagnostics.py#L321-L400 |
225,293 | pymc-devs/pymc | pymc/diagnostics.py | effective_n | def effective_n(x):
""" Returns estimate of the effective sample size of a set of traces.
Parameters
----------
x : array-like
An array containing the 2 or more traces of a stochastic parameter. That is, an array of dimension m x n x k, where m is the number of traces, n the number of samples, an... | python | def effective_n(x):
""" Returns estimate of the effective sample size of a set of traces.
Parameters
----------
x : array-like
An array containing the 2 or more traces of a stochastic parameter. That is, an array of dimension m x n x k, where m is the number of traces, n the number of samples, an... | [
"def",
"effective_n",
"(",
"x",
")",
":",
"if",
"np",
".",
"shape",
"(",
"x",
")",
"<",
"(",
"2",
",",
")",
":",
"raise",
"ValueError",
"(",
"'Calculation of effective sample size requires multiple chains of the same length.'",
")",
"try",
":",
"m",
",",
"n",
... | Returns estimate of the effective sample size of a set of traces.
Parameters
----------
x : array-like
An array containing the 2 or more traces of a stochastic parameter. That is, an array of dimension m x n x k, where m is the number of traces, n the number of samples, and k the dimension of the sto... | [
"Returns",
"estimate",
"of",
"the",
"effective",
"sample",
"size",
"of",
"a",
"set",
"of",
"traces",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/diagnostics.py#L497-L552 |
225,294 | pymc-devs/pymc | pymc/diagnostics.py | gelman_rubin | def gelman_rubin(x, return_var=False):
""" Returns estimate of R for a set of traces.
The Gelman-Rubin diagnostic tests for lack of convergence by comparing
the variance between multiple chains to the variance within each chain.
If convergence has been achieved, the between-chain and within-chain
v... | python | def gelman_rubin(x, return_var=False):
""" Returns estimate of R for a set of traces.
The Gelman-Rubin diagnostic tests for lack of convergence by comparing
the variance between multiple chains to the variance within each chain.
If convergence has been achieved, the between-chain and within-chain
v... | [
"def",
"gelman_rubin",
"(",
"x",
",",
"return_var",
"=",
"False",
")",
":",
"if",
"np",
".",
"shape",
"(",
"x",
")",
"<",
"(",
"2",
",",
")",
":",
"raise",
"ValueError",
"(",
"'Gelman-Rubin diagnostic requires multiple chains of the same length.'",
")",
"try",... | Returns estimate of R for a set of traces.
The Gelman-Rubin diagnostic tests for lack of convergence by comparing
the variance between multiple chains to the variance within each chain.
If convergence has been achieved, the between-chain and within-chain
variances should be identical. To be most effect... | [
"Returns",
"estimate",
"of",
"R",
"for",
"a",
"set",
"of",
"traces",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/diagnostics.py#L556-L627 |
225,295 | pymc-devs/pymc | pymc/diagnostics.py | _find_max_lag | def _find_max_lag(x, rho_limit=0.05, maxmaxlag=20000, verbose=0):
"""Automatically find an appropriate maximum lag to calculate IAT"""
# Fetch autocovariance matrix
acv = autocov(x)
# Calculate rho
rho = acv[0, 1] / acv[0, 0]
lam = -1. / np.log(abs(rho))
# Initial guess at 1.5 times lambd... | python | def _find_max_lag(x, rho_limit=0.05, maxmaxlag=20000, verbose=0):
"""Automatically find an appropriate maximum lag to calculate IAT"""
# Fetch autocovariance matrix
acv = autocov(x)
# Calculate rho
rho = acv[0, 1] / acv[0, 0]
lam = -1. / np.log(abs(rho))
# Initial guess at 1.5 times lambd... | [
"def",
"_find_max_lag",
"(",
"x",
",",
"rho_limit",
"=",
"0.05",
",",
"maxmaxlag",
"=",
"20000",
",",
"verbose",
"=",
"0",
")",
":",
"# Fetch autocovariance matrix",
"acv",
"=",
"autocov",
"(",
"x",
")",
"# Calculate rho",
"rho",
"=",
"acv",
"[",
"0",
",... | Automatically find an appropriate maximum lag to calculate IAT | [
"Automatically",
"find",
"an",
"appropriate",
"maximum",
"lag",
"to",
"calculate",
"IAT"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/diagnostics.py#L630-L668 |
225,296 | pymc-devs/pymc | pymc/diagnostics.py | ppp_value | def ppp_value(simdata, trueval, round=3):
"""
Calculates posterior predictive p-values on data simulated from the posterior
predictive distribution, returning the quantile of the observed data relative to
simulated.
The posterior predictive p-value is computed by:
.. math:: Pr(T(y^{\text... | python | def ppp_value(simdata, trueval, round=3):
"""
Calculates posterior predictive p-values on data simulated from the posterior
predictive distribution, returning the quantile of the observed data relative to
simulated.
The posterior predictive p-value is computed by:
.. math:: Pr(T(y^{\text... | [
"def",
"ppp_value",
"(",
"simdata",
",",
"trueval",
",",
"round",
"=",
"3",
")",
":",
"if",
"ndim",
"(",
"trueval",
")",
"==",
"1",
"and",
"ndim",
"(",
"simdata",
"==",
"2",
")",
":",
"# Iterate over more than one set of data",
"return",
"[",
"post_pred_ch... | Calculates posterior predictive p-values on data simulated from the posterior
predictive distribution, returning the quantile of the observed data relative to
simulated.
The posterior predictive p-value is computed by:
.. math:: Pr(T(y^{\text{sim}} > T(y) | y)
where T is a test statistic o... | [
"Calculates",
"posterior",
"predictive",
"p",
"-",
"values",
"on",
"data",
"simulated",
"from",
"the",
"posterior",
"predictive",
"distribution",
"returning",
"the",
"quantile",
"of",
"the",
"observed",
"data",
"relative",
"to",
"simulated",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/diagnostics.py#L705-L735 |
225,297 | pymc-devs/pymc | pymc/Model.py | check_valid_object_name | def check_valid_object_name(sequence):
"""Check that the names of the objects are all different."""
names = []
for o in sequence:
if o.__name__ in names:
raise ValueError(
'A tallyable PyMC object called %s already exists. This will cause problems for some database backen... | python | def check_valid_object_name(sequence):
"""Check that the names of the objects are all different."""
names = []
for o in sequence:
if o.__name__ in names:
raise ValueError(
'A tallyable PyMC object called %s already exists. This will cause problems for some database backen... | [
"def",
"check_valid_object_name",
"(",
"sequence",
")",
":",
"names",
"=",
"[",
"]",
"for",
"o",
"in",
"sequence",
":",
"if",
"o",
".",
"__name__",
"in",
"names",
":",
"raise",
"ValueError",
"(",
"'A tallyable PyMC object called %s already exists. This will cause pr... | Check that the names of the objects are all different. | [
"Check",
"that",
"the",
"names",
"of",
"the",
"objects",
"are",
"all",
"different",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L847-L856 |
225,298 | pymc-devs/pymc | pymc/Model.py | Model.seed | def seed(self):
"""
Seed new initial values for the stochastics.
"""
for generation in self.generations:
for s in generation:
try:
if s.rseed is not None:
value = s.random(**s.parents.value)
except:
... | python | def seed(self):
"""
Seed new initial values for the stochastics.
"""
for generation in self.generations:
for s in generation:
try:
if s.rseed is not None:
value = s.random(**s.parents.value)
except:
... | [
"def",
"seed",
"(",
"self",
")",
":",
"for",
"generation",
"in",
"self",
".",
"generations",
":",
"for",
"s",
"in",
"generation",
":",
"try",
":",
"if",
"s",
".",
"rseed",
"is",
"not",
"None",
":",
"value",
"=",
"s",
".",
"random",
"(",
"*",
"*",... | Seed new initial values for the stochastics. | [
"Seed",
"new",
"initial",
"values",
"for",
"the",
"stochastics",
"."
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L114-L125 |
225,299 | pymc-devs/pymc | pymc/Model.py | Model.get_node | def get_node(self, node_name):
"""Retrieve node with passed name"""
for node in self.nodes:
if node.__name__ == node_name:
return node | python | def get_node(self, node_name):
"""Retrieve node with passed name"""
for node in self.nodes:
if node.__name__ == node_name:
return node | [
"def",
"get_node",
"(",
"self",
",",
"node_name",
")",
":",
"for",
"node",
"in",
"self",
".",
"nodes",
":",
"if",
"node",
".",
"__name__",
"==",
"node_name",
":",
"return",
"node"
] | Retrieve node with passed name | [
"Retrieve",
"node",
"with",
"passed",
"name"
] | c6e530210bff4c0d7189b35b2c971bc53f93f7cd | https://github.com/pymc-devs/pymc/blob/c6e530210bff4c0d7189b35b2c971bc53f93f7cd/pymc/Model.py#L127-L131 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.