repo
stringlengths 7
55
| path
stringlengths 4
223
| func_name
stringlengths 1
134
| original_string
stringlengths 75
104k
| language
stringclasses 1
value | code
stringlengths 75
104k
| code_tokens
listlengths 19
28.4k
| docstring
stringlengths 1
46.9k
| docstring_tokens
listlengths 1
1.97k
| sha
stringlengths 40
40
| url
stringlengths 87
315
| partition
stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
opendns/pyinvestigate
|
investigate/investigate.py
|
Investigate.rr_history
|
def rr_history(self, query, query_type="A"):
'''Get the RR (Resource Record) History of the given domain or IP.
The default query type is for 'A' records, but the following query types
are supported:
A, NS, MX, TXT, CNAME
For details, see https://investigate.umbrella.com/docs/api#dnsrr_domain
'''
if query_type not in Investigate.SUPPORTED_DNS_TYPES:
raise Investigate.UNSUPPORTED_DNS_QUERY
# if this is an IP address, query the IP
if Investigate.IP_PATTERN.match(query):
return self._ip_rr_history(query, query_type)
# otherwise, query the domain
return self._domain_rr_history(query, query_type)
|
python
|
def rr_history(self, query, query_type="A"):
'''Get the RR (Resource Record) History of the given domain or IP.
The default query type is for 'A' records, but the following query types
are supported:
A, NS, MX, TXT, CNAME
For details, see https://investigate.umbrella.com/docs/api#dnsrr_domain
'''
if query_type not in Investigate.SUPPORTED_DNS_TYPES:
raise Investigate.UNSUPPORTED_DNS_QUERY
# if this is an IP address, query the IP
if Investigate.IP_PATTERN.match(query):
return self._ip_rr_history(query, query_type)
# otherwise, query the domain
return self._domain_rr_history(query, query_type)
|
[
"def",
"rr_history",
"(",
"self",
",",
"query",
",",
"query_type",
"=",
"\"A\"",
")",
":",
"if",
"query_type",
"not",
"in",
"Investigate",
".",
"SUPPORTED_DNS_TYPES",
":",
"raise",
"Investigate",
".",
"UNSUPPORTED_DNS_QUERY",
"# if this is an IP address, query the IP",
"if",
"Investigate",
".",
"IP_PATTERN",
".",
"match",
"(",
"query",
")",
":",
"return",
"self",
".",
"_ip_rr_history",
"(",
"query",
",",
"query_type",
")",
"# otherwise, query the domain",
"return",
"self",
".",
"_domain_rr_history",
"(",
"query",
",",
"query_type",
")"
] |
Get the RR (Resource Record) History of the given domain or IP.
The default query type is for 'A' records, but the following query types
are supported:
A, NS, MX, TXT, CNAME
For details, see https://investigate.umbrella.com/docs/api#dnsrr_domain
|
[
"Get",
"the",
"RR",
"(",
"Resource",
"Record",
")",
"History",
"of",
"the",
"given",
"domain",
"or",
"IP",
".",
"The",
"default",
"query",
"type",
"is",
"for",
"A",
"records",
"but",
"the",
"following",
"query",
"types",
"are",
"supported",
":"
] |
a182e73a750f03e906d9b25842d556db8d2fd54f
|
https://github.com/opendns/pyinvestigate/blob/a182e73a750f03e906d9b25842d556db8d2fd54f/investigate/investigate.py#L155-L172
|
train
|
opendns/pyinvestigate
|
investigate/investigate.py
|
Investigate.domain_whois
|
def domain_whois(self, domain):
'''Gets whois information for a domain'''
uri = self._uris["whois_domain"].format(domain)
resp_json = self.get_parse(uri)
return resp_json
|
python
|
def domain_whois(self, domain):
'''Gets whois information for a domain'''
uri = self._uris["whois_domain"].format(domain)
resp_json = self.get_parse(uri)
return resp_json
|
[
"def",
"domain_whois",
"(",
"self",
",",
"domain",
")",
":",
"uri",
"=",
"self",
".",
"_uris",
"[",
"\"whois_domain\"",
"]",
".",
"format",
"(",
"domain",
")",
"resp_json",
"=",
"self",
".",
"get_parse",
"(",
"uri",
")",
"return",
"resp_json"
] |
Gets whois information for a domain
|
[
"Gets",
"whois",
"information",
"for",
"a",
"domain"
] |
a182e73a750f03e906d9b25842d556db8d2fd54f
|
https://github.com/opendns/pyinvestigate/blob/a182e73a750f03e906d9b25842d556db8d2fd54f/investigate/investigate.py#L187-L191
|
train
|
opendns/pyinvestigate
|
investigate/investigate.py
|
Investigate.domain_whois_history
|
def domain_whois_history(self, domain, limit=None):
'''Gets whois history for a domain'''
params = dict()
if limit is not None:
params['limit'] = limit
uri = self._uris["whois_domain_history"].format(domain)
resp_json = self.get_parse(uri, params)
return resp_json
|
python
|
def domain_whois_history(self, domain, limit=None):
'''Gets whois history for a domain'''
params = dict()
if limit is not None:
params['limit'] = limit
uri = self._uris["whois_domain_history"].format(domain)
resp_json = self.get_parse(uri, params)
return resp_json
|
[
"def",
"domain_whois_history",
"(",
"self",
",",
"domain",
",",
"limit",
"=",
"None",
")",
":",
"params",
"=",
"dict",
"(",
")",
"if",
"limit",
"is",
"not",
"None",
":",
"params",
"[",
"'limit'",
"]",
"=",
"limit",
"uri",
"=",
"self",
".",
"_uris",
"[",
"\"whois_domain_history\"",
"]",
".",
"format",
"(",
"domain",
")",
"resp_json",
"=",
"self",
".",
"get_parse",
"(",
"uri",
",",
"params",
")",
"return",
"resp_json"
] |
Gets whois history for a domain
|
[
"Gets",
"whois",
"history",
"for",
"a",
"domain"
] |
a182e73a750f03e906d9b25842d556db8d2fd54f
|
https://github.com/opendns/pyinvestigate/blob/a182e73a750f03e906d9b25842d556db8d2fd54f/investigate/investigate.py#L193-L202
|
train
|
opendns/pyinvestigate
|
investigate/investigate.py
|
Investigate.ns_whois
|
def ns_whois(self, nameservers, limit=DEFAULT_LIMIT, offset=DEFAULT_OFFSET, sort_field=DEFAULT_SORT):
'''Gets the domains that have been registered with a nameserver or
nameservers'''
if not isinstance(nameservers, list):
uri = self._uris["whois_ns"].format(nameservers)
params = {'limit': limit, 'offset': offset, 'sortField': sort_field}
else:
uri = self._uris["whois_ns"].format('')
params = {'emailList' : ','.join(nameservers), 'limit': limit, 'offset': offset, 'sortField': sort_field}
resp_json = self.get_parse(uri, params=params)
return resp_json
|
python
|
def ns_whois(self, nameservers, limit=DEFAULT_LIMIT, offset=DEFAULT_OFFSET, sort_field=DEFAULT_SORT):
'''Gets the domains that have been registered with a nameserver or
nameservers'''
if not isinstance(nameservers, list):
uri = self._uris["whois_ns"].format(nameservers)
params = {'limit': limit, 'offset': offset, 'sortField': sort_field}
else:
uri = self._uris["whois_ns"].format('')
params = {'emailList' : ','.join(nameservers), 'limit': limit, 'offset': offset, 'sortField': sort_field}
resp_json = self.get_parse(uri, params=params)
return resp_json
|
[
"def",
"ns_whois",
"(",
"self",
",",
"nameservers",
",",
"limit",
"=",
"DEFAULT_LIMIT",
",",
"offset",
"=",
"DEFAULT_OFFSET",
",",
"sort_field",
"=",
"DEFAULT_SORT",
")",
":",
"if",
"not",
"isinstance",
"(",
"nameservers",
",",
"list",
")",
":",
"uri",
"=",
"self",
".",
"_uris",
"[",
"\"whois_ns\"",
"]",
".",
"format",
"(",
"nameservers",
")",
"params",
"=",
"{",
"'limit'",
":",
"limit",
",",
"'offset'",
":",
"offset",
",",
"'sortField'",
":",
"sort_field",
"}",
"else",
":",
"uri",
"=",
"self",
".",
"_uris",
"[",
"\"whois_ns\"",
"]",
".",
"format",
"(",
"''",
")",
"params",
"=",
"{",
"'emailList'",
":",
"','",
".",
"join",
"(",
"nameservers",
")",
",",
"'limit'",
":",
"limit",
",",
"'offset'",
":",
"offset",
",",
"'sortField'",
":",
"sort_field",
"}",
"resp_json",
"=",
"self",
".",
"get_parse",
"(",
"uri",
",",
"params",
"=",
"params",
")",
"return",
"resp_json"
] |
Gets the domains that have been registered with a nameserver or
nameservers
|
[
"Gets",
"the",
"domains",
"that",
"have",
"been",
"registered",
"with",
"a",
"nameserver",
"or",
"nameservers"
] |
a182e73a750f03e906d9b25842d556db8d2fd54f
|
https://github.com/opendns/pyinvestigate/blob/a182e73a750f03e906d9b25842d556db8d2fd54f/investigate/investigate.py#L204-L215
|
train
|
opendns/pyinvestigate
|
investigate/investigate.py
|
Investigate.search
|
def search(self, pattern, start=None, limit=None, include_category=None):
'''Searches for domains that match a given pattern'''
params = dict()
if start is None:
start = datetime.timedelta(days=30)
if isinstance(start, datetime.timedelta):
params['start'] = int(time.mktime((datetime.datetime.utcnow() - start).timetuple()) * 1000)
elif isinstance(start, datetime.datetime):
params['start'] = int(time.mktime(start.timetuple()) * 1000)
else:
raise Investigate.SEARCH_ERR
if limit is not None and isinstance(limit, int):
params['limit'] = limit
if include_category is not None and isinstance(include_category, bool):
params['includeCategory'] = str(include_category).lower()
uri = self._uris['search'].format(quote_plus(pattern))
return self.get_parse(uri, params)
|
python
|
def search(self, pattern, start=None, limit=None, include_category=None):
'''Searches for domains that match a given pattern'''
params = dict()
if start is None:
start = datetime.timedelta(days=30)
if isinstance(start, datetime.timedelta):
params['start'] = int(time.mktime((datetime.datetime.utcnow() - start).timetuple()) * 1000)
elif isinstance(start, datetime.datetime):
params['start'] = int(time.mktime(start.timetuple()) * 1000)
else:
raise Investigate.SEARCH_ERR
if limit is not None and isinstance(limit, int):
params['limit'] = limit
if include_category is not None and isinstance(include_category, bool):
params['includeCategory'] = str(include_category).lower()
uri = self._uris['search'].format(quote_plus(pattern))
return self.get_parse(uri, params)
|
[
"def",
"search",
"(",
"self",
",",
"pattern",
",",
"start",
"=",
"None",
",",
"limit",
"=",
"None",
",",
"include_category",
"=",
"None",
")",
":",
"params",
"=",
"dict",
"(",
")",
"if",
"start",
"is",
"None",
":",
"start",
"=",
"datetime",
".",
"timedelta",
"(",
"days",
"=",
"30",
")",
"if",
"isinstance",
"(",
"start",
",",
"datetime",
".",
"timedelta",
")",
":",
"params",
"[",
"'start'",
"]",
"=",
"int",
"(",
"time",
".",
"mktime",
"(",
"(",
"datetime",
".",
"datetime",
".",
"utcnow",
"(",
")",
"-",
"start",
")",
".",
"timetuple",
"(",
")",
")",
"*",
"1000",
")",
"elif",
"isinstance",
"(",
"start",
",",
"datetime",
".",
"datetime",
")",
":",
"params",
"[",
"'start'",
"]",
"=",
"int",
"(",
"time",
".",
"mktime",
"(",
"start",
".",
"timetuple",
"(",
")",
")",
"*",
"1000",
")",
"else",
":",
"raise",
"Investigate",
".",
"SEARCH_ERR",
"if",
"limit",
"is",
"not",
"None",
"and",
"isinstance",
"(",
"limit",
",",
"int",
")",
":",
"params",
"[",
"'limit'",
"]",
"=",
"limit",
"if",
"include_category",
"is",
"not",
"None",
"and",
"isinstance",
"(",
"include_category",
",",
"bool",
")",
":",
"params",
"[",
"'includeCategory'",
"]",
"=",
"str",
"(",
"include_category",
")",
".",
"lower",
"(",
")",
"uri",
"=",
"self",
".",
"_uris",
"[",
"'search'",
"]",
".",
"format",
"(",
"quote_plus",
"(",
"pattern",
")",
")",
"return",
"self",
".",
"get_parse",
"(",
"uri",
",",
"params",
")"
] |
Searches for domains that match a given pattern
|
[
"Searches",
"for",
"domains",
"that",
"match",
"a",
"given",
"pattern"
] |
a182e73a750f03e906d9b25842d556db8d2fd54f
|
https://github.com/opendns/pyinvestigate/blob/a182e73a750f03e906d9b25842d556db8d2fd54f/investigate/investigate.py#L231-L253
|
train
|
opendns/pyinvestigate
|
investigate/investigate.py
|
Investigate.samples
|
def samples(self, anystring, limit=None, offset=None, sortby=None):
'''Return an object representing the samples identified by the input domain, IP, or URL'''
uri = self._uris['samples'].format(anystring)
params = {'limit': limit, 'offset': offset, 'sortby': sortby}
return self.get_parse(uri, params)
|
python
|
def samples(self, anystring, limit=None, offset=None, sortby=None):
'''Return an object representing the samples identified by the input domain, IP, or URL'''
uri = self._uris['samples'].format(anystring)
params = {'limit': limit, 'offset': offset, 'sortby': sortby}
return self.get_parse(uri, params)
|
[
"def",
"samples",
"(",
"self",
",",
"anystring",
",",
"limit",
"=",
"None",
",",
"offset",
"=",
"None",
",",
"sortby",
"=",
"None",
")",
":",
"uri",
"=",
"self",
".",
"_uris",
"[",
"'samples'",
"]",
".",
"format",
"(",
"anystring",
")",
"params",
"=",
"{",
"'limit'",
":",
"limit",
",",
"'offset'",
":",
"offset",
",",
"'sortby'",
":",
"sortby",
"}",
"return",
"self",
".",
"get_parse",
"(",
"uri",
",",
"params",
")"
] |
Return an object representing the samples identified by the input domain, IP, or URL
|
[
"Return",
"an",
"object",
"representing",
"the",
"samples",
"identified",
"by",
"the",
"input",
"domain",
"IP",
"or",
"URL"
] |
a182e73a750f03e906d9b25842d556db8d2fd54f
|
https://github.com/opendns/pyinvestigate/blob/a182e73a750f03e906d9b25842d556db8d2fd54f/investigate/investigate.py#L255-L261
|
train
|
opendns/pyinvestigate
|
investigate/investigate.py
|
Investigate.sample
|
def sample(self, hash, limit=None, offset=None):
'''Return an object representing the sample identified by the input hash, or an empty object if that sample is not found'''
uri = self._uris['sample'].format(hash)
params = {'limit': limit, 'offset': offset}
return self.get_parse(uri, params)
|
python
|
def sample(self, hash, limit=None, offset=None):
'''Return an object representing the sample identified by the input hash, or an empty object if that sample is not found'''
uri = self._uris['sample'].format(hash)
params = {'limit': limit, 'offset': offset}
return self.get_parse(uri, params)
|
[
"def",
"sample",
"(",
"self",
",",
"hash",
",",
"limit",
"=",
"None",
",",
"offset",
"=",
"None",
")",
":",
"uri",
"=",
"self",
".",
"_uris",
"[",
"'sample'",
"]",
".",
"format",
"(",
"hash",
")",
"params",
"=",
"{",
"'limit'",
":",
"limit",
",",
"'offset'",
":",
"offset",
"}",
"return",
"self",
".",
"get_parse",
"(",
"uri",
",",
"params",
")"
] |
Return an object representing the sample identified by the input hash, or an empty object if that sample is not found
|
[
"Return",
"an",
"object",
"representing",
"the",
"sample",
"identified",
"by",
"the",
"input",
"hash",
"or",
"an",
"empty",
"object",
"if",
"that",
"sample",
"is",
"not",
"found"
] |
a182e73a750f03e906d9b25842d556db8d2fd54f
|
https://github.com/opendns/pyinvestigate/blob/a182e73a750f03e906d9b25842d556db8d2fd54f/investigate/investigate.py#L263-L269
|
train
|
opendns/pyinvestigate
|
investigate/investigate.py
|
Investigate.as_for_ip
|
def as_for_ip(self, ip):
'''Gets the AS information for a given IP address.'''
if not Investigate.IP_PATTERN.match(ip):
raise Investigate.IP_ERR
uri = self._uris["as_for_ip"].format(ip)
resp_json = self.get_parse(uri)
return resp_json
|
python
|
def as_for_ip(self, ip):
'''Gets the AS information for a given IP address.'''
if not Investigate.IP_PATTERN.match(ip):
raise Investigate.IP_ERR
uri = self._uris["as_for_ip"].format(ip)
resp_json = self.get_parse(uri)
return resp_json
|
[
"def",
"as_for_ip",
"(",
"self",
",",
"ip",
")",
":",
"if",
"not",
"Investigate",
".",
"IP_PATTERN",
".",
"match",
"(",
"ip",
")",
":",
"raise",
"Investigate",
".",
"IP_ERR",
"uri",
"=",
"self",
".",
"_uris",
"[",
"\"as_for_ip\"",
"]",
".",
"format",
"(",
"ip",
")",
"resp_json",
"=",
"self",
".",
"get_parse",
"(",
"uri",
")",
"return",
"resp_json"
] |
Gets the AS information for a given IP address.
|
[
"Gets",
"the",
"AS",
"information",
"for",
"a",
"given",
"IP",
"address",
"."
] |
a182e73a750f03e906d9b25842d556db8d2fd54f
|
https://github.com/opendns/pyinvestigate/blob/a182e73a750f03e906d9b25842d556db8d2fd54f/investigate/investigate.py#L298-L306
|
train
|
opendns/pyinvestigate
|
investigate/investigate.py
|
Investigate.prefixes_for_asn
|
def prefixes_for_asn(self, asn):
'''Gets the AS information for a given ASN. Return the CIDR and geolocation associated with the AS.'''
uri = self._uris["prefixes_for_asn"].format(asn)
resp_json = self.get_parse(uri)
return resp_json
|
python
|
def prefixes_for_asn(self, asn):
'''Gets the AS information for a given ASN. Return the CIDR and geolocation associated with the AS.'''
uri = self._uris["prefixes_for_asn"].format(asn)
resp_json = self.get_parse(uri)
return resp_json
|
[
"def",
"prefixes_for_asn",
"(",
"self",
",",
"asn",
")",
":",
"uri",
"=",
"self",
".",
"_uris",
"[",
"\"prefixes_for_asn\"",
"]",
".",
"format",
"(",
"asn",
")",
"resp_json",
"=",
"self",
".",
"get_parse",
"(",
"uri",
")",
"return",
"resp_json"
] |
Gets the AS information for a given ASN. Return the CIDR and geolocation associated with the AS.
|
[
"Gets",
"the",
"AS",
"information",
"for",
"a",
"given",
"ASN",
".",
"Return",
"the",
"CIDR",
"and",
"geolocation",
"associated",
"with",
"the",
"AS",
"."
] |
a182e73a750f03e906d9b25842d556db8d2fd54f
|
https://github.com/opendns/pyinvestigate/blob/a182e73a750f03e906d9b25842d556db8d2fd54f/investigate/investigate.py#L308-L314
|
train
|
opendns/pyinvestigate
|
investigate/investigate.py
|
Investigate.timeline
|
def timeline(self, uri):
'''Get the domain tagging timeline for a given uri.
Could be a domain, ip, or url.
For details, see https://docs.umbrella.com/investigate-api/docs/timeline
'''
uri = self._uris["timeline"].format(uri)
resp_json = self.get_parse(uri)
return resp_json
|
python
|
def timeline(self, uri):
'''Get the domain tagging timeline for a given uri.
Could be a domain, ip, or url.
For details, see https://docs.umbrella.com/investigate-api/docs/timeline
'''
uri = self._uris["timeline"].format(uri)
resp_json = self.get_parse(uri)
return resp_json
|
[
"def",
"timeline",
"(",
"self",
",",
"uri",
")",
":",
"uri",
"=",
"self",
".",
"_uris",
"[",
"\"timeline\"",
"]",
".",
"format",
"(",
"uri",
")",
"resp_json",
"=",
"self",
".",
"get_parse",
"(",
"uri",
")",
"return",
"resp_json"
] |
Get the domain tagging timeline for a given uri.
Could be a domain, ip, or url.
For details, see https://docs.umbrella.com/investigate-api/docs/timeline
|
[
"Get",
"the",
"domain",
"tagging",
"timeline",
"for",
"a",
"given",
"uri",
".",
"Could",
"be",
"a",
"domain",
"ip",
"or",
"url",
".",
"For",
"details",
"see",
"https",
":",
"//",
"docs",
".",
"umbrella",
".",
"com",
"/",
"investigate",
"-",
"api",
"/",
"docs",
"/",
"timeline"
] |
a182e73a750f03e906d9b25842d556db8d2fd54f
|
https://github.com/opendns/pyinvestigate/blob/a182e73a750f03e906d9b25842d556db8d2fd54f/investigate/investigate.py#L316-L324
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
abs
|
def abs(x):
"""
Absolute value
"""
if isinstance(x, UncertainFunction):
mcpts = np.abs(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.abs(x)
|
python
|
def abs(x):
"""
Absolute value
"""
if isinstance(x, UncertainFunction):
mcpts = np.abs(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.abs(x)
|
[
"def",
"abs",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"abs",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"abs",
"(",
"x",
")"
] |
Absolute value
|
[
"Absolute",
"value"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L18-L26
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
acos
|
def acos(x):
"""
Inverse cosine
"""
if isinstance(x, UncertainFunction):
mcpts = np.arccos(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.arccos(x)
|
python
|
def acos(x):
"""
Inverse cosine
"""
if isinstance(x, UncertainFunction):
mcpts = np.arccos(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.arccos(x)
|
[
"def",
"acos",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"arccos",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"arccos",
"(",
"x",
")"
] |
Inverse cosine
|
[
"Inverse",
"cosine"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L29-L37
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
acosh
|
def acosh(x):
"""
Inverse hyperbolic cosine
"""
if isinstance(x, UncertainFunction):
mcpts = np.arccosh(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.arccosh(x)
|
python
|
def acosh(x):
"""
Inverse hyperbolic cosine
"""
if isinstance(x, UncertainFunction):
mcpts = np.arccosh(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.arccosh(x)
|
[
"def",
"acosh",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"arccosh",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"arccosh",
"(",
"x",
")"
] |
Inverse hyperbolic cosine
|
[
"Inverse",
"hyperbolic",
"cosine"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L40-L48
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
asin
|
def asin(x):
"""
Inverse sine
"""
if isinstance(x, UncertainFunction):
mcpts = np.arcsin(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.arcsin(x)
|
python
|
def asin(x):
"""
Inverse sine
"""
if isinstance(x, UncertainFunction):
mcpts = np.arcsin(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.arcsin(x)
|
[
"def",
"asin",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"arcsin",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"arcsin",
"(",
"x",
")"
] |
Inverse sine
|
[
"Inverse",
"sine"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L51-L59
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
asinh
|
def asinh(x):
"""
Inverse hyperbolic sine
"""
if isinstance(x, UncertainFunction):
mcpts = np.arcsinh(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.arcsinh(x)
|
python
|
def asinh(x):
"""
Inverse hyperbolic sine
"""
if isinstance(x, UncertainFunction):
mcpts = np.arcsinh(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.arcsinh(x)
|
[
"def",
"asinh",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"arcsinh",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"arcsinh",
"(",
"x",
")"
] |
Inverse hyperbolic sine
|
[
"Inverse",
"hyperbolic",
"sine"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L62-L70
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
atan
|
def atan(x):
"""
Inverse tangent
"""
if isinstance(x, UncertainFunction):
mcpts = np.arctan(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.arctan(x)
|
python
|
def atan(x):
"""
Inverse tangent
"""
if isinstance(x, UncertainFunction):
mcpts = np.arctan(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.arctan(x)
|
[
"def",
"atan",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"arctan",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"arctan",
"(",
"x",
")"
] |
Inverse tangent
|
[
"Inverse",
"tangent"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L73-L81
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
atanh
|
def atanh(x):
"""
Inverse hyperbolic tangent
"""
if isinstance(x, UncertainFunction):
mcpts = np.arctanh(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.arctanh(x)
|
python
|
def atanh(x):
"""
Inverse hyperbolic tangent
"""
if isinstance(x, UncertainFunction):
mcpts = np.arctanh(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.arctanh(x)
|
[
"def",
"atanh",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"arctanh",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"arctanh",
"(",
"x",
")"
] |
Inverse hyperbolic tangent
|
[
"Inverse",
"hyperbolic",
"tangent"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L84-L92
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
ceil
|
def ceil(x):
"""
Ceiling function (round towards positive infinity)
"""
if isinstance(x, UncertainFunction):
mcpts = np.ceil(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.ceil(x)
|
python
|
def ceil(x):
"""
Ceiling function (round towards positive infinity)
"""
if isinstance(x, UncertainFunction):
mcpts = np.ceil(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.ceil(x)
|
[
"def",
"ceil",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"ceil",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"ceil",
"(",
"x",
")"
] |
Ceiling function (round towards positive infinity)
|
[
"Ceiling",
"function",
"(",
"round",
"towards",
"positive",
"infinity",
")"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L95-L103
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
cos
|
def cos(x):
"""
Cosine
"""
if isinstance(x, UncertainFunction):
mcpts = np.cos(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.cos(x)
|
python
|
def cos(x):
"""
Cosine
"""
if isinstance(x, UncertainFunction):
mcpts = np.cos(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.cos(x)
|
[
"def",
"cos",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"cos",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"cos",
"(",
"x",
")"
] |
Cosine
|
[
"Cosine"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L106-L114
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
cosh
|
def cosh(x):
"""
Hyperbolic cosine
"""
if isinstance(x, UncertainFunction):
mcpts = np.cosh(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.cosh(x)
|
python
|
def cosh(x):
"""
Hyperbolic cosine
"""
if isinstance(x, UncertainFunction):
mcpts = np.cosh(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.cosh(x)
|
[
"def",
"cosh",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"cosh",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"cosh",
"(",
"x",
")"
] |
Hyperbolic cosine
|
[
"Hyperbolic",
"cosine"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L117-L125
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
degrees
|
def degrees(x):
"""
Convert radians to degrees
"""
if isinstance(x, UncertainFunction):
mcpts = np.degrees(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.degrees(x)
|
python
|
def degrees(x):
"""
Convert radians to degrees
"""
if isinstance(x, UncertainFunction):
mcpts = np.degrees(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.degrees(x)
|
[
"def",
"degrees",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"degrees",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"degrees",
"(",
"x",
")"
] |
Convert radians to degrees
|
[
"Convert",
"radians",
"to",
"degrees"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L128-L136
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
exp
|
def exp(x):
"""
Exponential function
"""
if isinstance(x, UncertainFunction):
mcpts = np.exp(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.exp(x)
|
python
|
def exp(x):
"""
Exponential function
"""
if isinstance(x, UncertainFunction):
mcpts = np.exp(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.exp(x)
|
[
"def",
"exp",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"exp",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"exp",
"(",
"x",
")"
] |
Exponential function
|
[
"Exponential",
"function"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L139-L147
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
expm1
|
def expm1(x):
"""
Calculate exp(x) - 1
"""
if isinstance(x, UncertainFunction):
mcpts = np.expm1(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.expm1(x)
|
python
|
def expm1(x):
"""
Calculate exp(x) - 1
"""
if isinstance(x, UncertainFunction):
mcpts = np.expm1(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.expm1(x)
|
[
"def",
"expm1",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"expm1",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"expm1",
"(",
"x",
")"
] |
Calculate exp(x) - 1
|
[
"Calculate",
"exp",
"(",
"x",
")",
"-",
"1"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L150-L158
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
fabs
|
def fabs(x):
"""
Absolute value function
"""
if isinstance(x, UncertainFunction):
mcpts = np.fabs(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.fabs(x)
|
python
|
def fabs(x):
"""
Absolute value function
"""
if isinstance(x, UncertainFunction):
mcpts = np.fabs(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.fabs(x)
|
[
"def",
"fabs",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"fabs",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"fabs",
"(",
"x",
")"
] |
Absolute value function
|
[
"Absolute",
"value",
"function"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L161-L169
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
floor
|
def floor(x):
"""
Floor function (round towards negative infinity)
"""
if isinstance(x, UncertainFunction):
mcpts = np.floor(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.floor(x)
|
python
|
def floor(x):
"""
Floor function (round towards negative infinity)
"""
if isinstance(x, UncertainFunction):
mcpts = np.floor(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.floor(x)
|
[
"def",
"floor",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"floor",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"floor",
"(",
"x",
")"
] |
Floor function (round towards negative infinity)
|
[
"Floor",
"function",
"(",
"round",
"towards",
"negative",
"infinity",
")"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L172-L180
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
hypot
|
def hypot(x, y):
"""
Calculate the hypotenuse given two "legs" of a right triangle
"""
if isinstance(x, UncertainFunction) or isinstance(x, UncertainFunction):
ufx = to_uncertain_func(x)
ufy = to_uncertain_func(y)
mcpts = np.hypot(ufx._mcpts, ufy._mcpts)
return UncertainFunction(mcpts)
else:
return np.hypot(x, y)
|
python
|
def hypot(x, y):
"""
Calculate the hypotenuse given two "legs" of a right triangle
"""
if isinstance(x, UncertainFunction) or isinstance(x, UncertainFunction):
ufx = to_uncertain_func(x)
ufy = to_uncertain_func(y)
mcpts = np.hypot(ufx._mcpts, ufy._mcpts)
return UncertainFunction(mcpts)
else:
return np.hypot(x, y)
|
[
"def",
"hypot",
"(",
"x",
",",
"y",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
"or",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"ufx",
"=",
"to_uncertain_func",
"(",
"x",
")",
"ufy",
"=",
"to_uncertain_func",
"(",
"y",
")",
"mcpts",
"=",
"np",
".",
"hypot",
"(",
"ufx",
".",
"_mcpts",
",",
"ufy",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"hypot",
"(",
"x",
",",
"y",
")"
] |
Calculate the hypotenuse given two "legs" of a right triangle
|
[
"Calculate",
"the",
"hypotenuse",
"given",
"two",
"legs",
"of",
"a",
"right",
"triangle"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L183-L193
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
log
|
def log(x):
"""
Natural logarithm
"""
if isinstance(x, UncertainFunction):
mcpts = np.log(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.log(x)
|
python
|
def log(x):
"""
Natural logarithm
"""
if isinstance(x, UncertainFunction):
mcpts = np.log(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.log(x)
|
[
"def",
"log",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"log",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"log",
"(",
"x",
")"
] |
Natural logarithm
|
[
"Natural",
"logarithm"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L203-L211
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
log10
|
def log10(x):
"""
Base-10 logarithm
"""
if isinstance(x, UncertainFunction):
mcpts = np.log10(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.log10(x)
|
python
|
def log10(x):
"""
Base-10 logarithm
"""
if isinstance(x, UncertainFunction):
mcpts = np.log10(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.log10(x)
|
[
"def",
"log10",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"log10",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"log10",
"(",
"x",
")"
] |
Base-10 logarithm
|
[
"Base",
"-",
"10",
"logarithm"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L214-L222
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
log1p
|
def log1p(x):
"""
Natural logarithm of (1 + x)
"""
if isinstance(x, UncertainFunction):
mcpts = np.log1p(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.log1p(x)
|
python
|
def log1p(x):
"""
Natural logarithm of (1 + x)
"""
if isinstance(x, UncertainFunction):
mcpts = np.log1p(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.log1p(x)
|
[
"def",
"log1p",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"log1p",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"log1p",
"(",
"x",
")"
] |
Natural logarithm of (1 + x)
|
[
"Natural",
"logarithm",
"of",
"(",
"1",
"+",
"x",
")"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L225-L233
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
radians
|
def radians(x):
"""
Convert degrees to radians
"""
if isinstance(x, UncertainFunction):
mcpts = np.radians(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.radians(x)
|
python
|
def radians(x):
"""
Convert degrees to radians
"""
if isinstance(x, UncertainFunction):
mcpts = np.radians(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.radians(x)
|
[
"def",
"radians",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"radians",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"radians",
"(",
"x",
")"
] |
Convert degrees to radians
|
[
"Convert",
"degrees",
"to",
"radians"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L236-L244
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
sin
|
def sin(x):
"""
Sine
"""
if isinstance(x, UncertainFunction):
mcpts = np.sin(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.sin(x)
|
python
|
def sin(x):
"""
Sine
"""
if isinstance(x, UncertainFunction):
mcpts = np.sin(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.sin(x)
|
[
"def",
"sin",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"sin",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"sin",
"(",
"x",
")"
] |
Sine
|
[
"Sine"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L247-L255
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
sinh
|
def sinh(x):
"""
Hyperbolic sine
"""
if isinstance(x, UncertainFunction):
mcpts = np.sinh(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.sinh(x)
|
python
|
def sinh(x):
"""
Hyperbolic sine
"""
if isinstance(x, UncertainFunction):
mcpts = np.sinh(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.sinh(x)
|
[
"def",
"sinh",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"sinh",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"sinh",
"(",
"x",
")"
] |
Hyperbolic sine
|
[
"Hyperbolic",
"sine"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L258-L266
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
sqrt
|
def sqrt(x):
"""
Square-root function
"""
if isinstance(x, UncertainFunction):
mcpts = np.sqrt(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.sqrt(x)
|
python
|
def sqrt(x):
"""
Square-root function
"""
if isinstance(x, UncertainFunction):
mcpts = np.sqrt(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.sqrt(x)
|
[
"def",
"sqrt",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"sqrt",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"sqrt",
"(",
"x",
")"
] |
Square-root function
|
[
"Square",
"-",
"root",
"function"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L269-L277
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
tan
|
def tan(x):
"""
Tangent
"""
if isinstance(x, UncertainFunction):
mcpts = np.tan(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.tan(x)
|
python
|
def tan(x):
"""
Tangent
"""
if isinstance(x, UncertainFunction):
mcpts = np.tan(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.tan(x)
|
[
"def",
"tan",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"tan",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"tan",
"(",
"x",
")"
] |
Tangent
|
[
"Tangent"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L280-L288
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
tanh
|
def tanh(x):
"""
Hyperbolic tangent
"""
if isinstance(x, UncertainFunction):
mcpts = np.tanh(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.tanh(x)
|
python
|
def tanh(x):
"""
Hyperbolic tangent
"""
if isinstance(x, UncertainFunction):
mcpts = np.tanh(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.tanh(x)
|
[
"def",
"tanh",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"tanh",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"tanh",
"(",
"x",
")"
] |
Hyperbolic tangent
|
[
"Hyperbolic",
"tangent"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L291-L299
|
train
|
tisimst/mcerp
|
mcerp/umath.py
|
trunc
|
def trunc(x):
"""
Truncate the values to the integer value without rounding
"""
if isinstance(x, UncertainFunction):
mcpts = np.trunc(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.trunc(x)
|
python
|
def trunc(x):
"""
Truncate the values to the integer value without rounding
"""
if isinstance(x, UncertainFunction):
mcpts = np.trunc(x._mcpts)
return UncertainFunction(mcpts)
else:
return np.trunc(x)
|
[
"def",
"trunc",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"mcpts",
"=",
"np",
".",
"trunc",
"(",
"x",
".",
"_mcpts",
")",
"return",
"UncertainFunction",
"(",
"mcpts",
")",
"else",
":",
"return",
"np",
".",
"trunc",
"(",
"x",
")"
] |
Truncate the values to the integer value without rounding
|
[
"Truncate",
"the",
"values",
"to",
"the",
"integer",
"value",
"without",
"rounding"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/umath.py#L302-L310
|
train
|
tisimst/mcerp
|
mcerp/lhd.py
|
lhd
|
def lhd(
dist=None,
size=None,
dims=1,
form="randomized",
iterations=100,
showcorrelations=False,
):
"""
Create a Latin-Hypercube sample design based on distributions defined in the
`scipy.stats` module
Parameters
----------
dist: array_like
frozen scipy.stats.rv_continuous or rv_discrete distribution objects
that are defined previous to calling LHD
size: int
integer value for the number of samples to generate for each
distribution object
dims: int, optional
if dist is a single distribution object, and dims > 1, the one
distribution will be used to generate a size-by-dims sampled design
form: str, optional (non-functional at the moment)
determines how the sampling is to occur, with the following optional
values:
- 'randomized' - completely randomized sampling
- 'spacefilling' - space-filling sampling (generally gives a more
accurate sampling of the design when the number of sample points
is small)
- 'orthogonal' - balanced space-filling sampling (experimental)
The 'spacefilling' and 'orthogonal' forms require some iterations to
determine the optimal sampling pattern.
iterations: int, optional (non-functional at the moment)
used to control the number of allowable search iterations for generating
'spacefilling' and 'orthogonal' designs
Returns
-------
out: 2d-array,
A 2d-array where each column corresponds to each input distribution and
each row is a sample in the design
Examples
--------
Single distribution:
- uniform distribution, low = -1, width = 2
>>> import scipy.stats as ss
>>> d0 = ss.uniform(loc=-1,scale=2)
>>> print lhd(dist=d0,size=5)
[[ 0.51031081]
[-0.28961427]
[-0.68342107]
[ 0.69784371]
[ 0.12248842]]
Single distribution for multiple variables:
- normal distribution, mean = 0, stdev = 1
>>> d1 = ss.norm(loc=0,scale=1)
>>> print lhd(dist=d1,size=7,dims=5)
[[-0.8612785 0.23034412 0.21808001]
[ 0.0455778 0.07001606 0.31586419]
[-0.978553 0.30394663 0.78483995]
[-0.26415983 0.15235896 0.51462024]
[ 0.80805686 0.38891031 0.02076505]
[ 1.63028931 0.52104917 1.48016008]]
Multiple distributions:
- beta distribution, alpha = 2, beta = 5
- exponential distribution, lambda = 1.5
>>> d2 = ss.beta(2,5)
>>> d3 = ss.expon(scale=1/1.5)
>>> print lhd(dist=(d1,d2,d3),size=6)
[[-0.8612785 0.23034412 0.21808001]
[ 0.0455778 0.07001606 0.31586419]
[-0.978553 0.30394663 0.78483995]
[-0.26415983 0.15235896 0.51462024]
[ 0.80805686 0.38891031 0.02076505]
[ 1.63028931 0.52104917 1.48016008]]
"""
assert dims > 0, 'kwarg "dims" must be at least 1'
if not size or not dist:
return None
def _lhs(x, samples=20):
"""
_lhs(x) returns a latin-hypercube matrix (each row is a different
set of sample inputs) using a default sample size of 20 for each column
of X. X must be a 2xN matrix that contains the lower and upper bounds of
each column. The lower bound(s) should be in the first row and the upper
bound(s) should be in the second row.
_lhs(x,samples=N) uses the sample size of N instead of the default (20).
Example:
>>> x = np.array([[0,-1,3],[1,2,6]])
>>> print 'x:'; print x
x:
[[ 0 -1 3]
[ 1 2 6]]
>>> print 'lhs(x):'; print _lhs(x)
lhs(x):
[[ 0.02989122 -0.93918734 3.14432618]
[ 0.08869833 -0.82140706 3.19875152]
[ 0.10627442 -0.66999234 3.33814979]
[ 0.15202861 -0.44157763 3.57036894]
[ 0.2067089 -0.34845384 3.66930908]
[ 0.26542056 -0.23706445 3.76361414]
[ 0.34201421 -0.00779306 3.90818257]
[ 0.37891646 0.15458423 4.15031708]
[ 0.43501575 0.23561118 4.20320064]
[ 0.4865449 0.36350601 4.45792314]
[ 0.54804367 0.56069855 4.60911539]
[ 0.59400712 0.7468415 4.69923486]
[ 0.63708876 0.9159176 4.83611204]
[ 0.68819855 0.98596354 4.97659182]
[ 0.7368695 1.18923511 5.11135111]
[ 0.78885724 1.28369441 5.2900157 ]
[ 0.80966513 1.47415703 5.4081971 ]
[ 0.86196731 1.57844205 5.61067689]
[ 0.94784517 1.71823504 5.78021164]
[ 0.96739728 1.94169017 5.88604772]]
>>> print 'lhs(x,samples=5):'; print _lhs(x,samples=5)
lhs(x,samples=5):
[[ 0.1949127 -0.54124725 3.49238369]
[ 0.21128576 -0.13439798 3.65652016]
[ 0.47516308 0.39957406 4.5797308 ]
[ 0.64400392 0.90890999 4.92379431]
[ 0.96279472 1.79415307 5.52028238]]
"""
# determine the segment size
segmentSize = 1.0 / samples
# get the number of dimensions to sample (number of columns)
numVars = x.shape[1]
# populate each dimension
out = np.zeros((samples, numVars))
pointValue = np.zeros(samples)
for n in range(numVars):
for i in range(samples):
segmentMin = i * segmentSize
point = segmentMin + (np.random.random() * segmentSize)
pointValue[i] = (point * (x[1, n] - x[0, n])) + x[0, n]
out[:, n] = pointValue
# now randomly arrange the different segments
return _mix(out)
def _mix(data, dim="cols"):
"""
Takes a data matrix and mixes up the values along dim (either "rows" or
"cols"). In other words, if dim='rows', then each row's data is mixed
ONLY WITHIN ITSELF. Likewise, if dim='cols', then each column's data is
mixed ONLY WITHIN ITSELF.
"""
data = np.atleast_2d(data)
n = data.shape[0]
if dim == "rows":
data = data.T
data_rank = list(range(n))
for i in range(data.shape[1]):
new_data_rank = np.random.permutation(data_rank)
vals, order = np.unique(
np.hstack((data_rank, new_data_rank)), return_inverse=True
)
old_order = order[:n]
new_order = order[-n:]
tmp = data[np.argsort(old_order), i][new_order]
data[:, i] = tmp[:]
if dim == "rows":
data = data.T
return data
if form is "randomized":
if hasattr(dist, "__getitem__"): # if multiple distributions were input
nvars = len(dist)
x = np.vstack((np.zeros(nvars), np.ones(nvars)))
unif_data = _lhs(x, samples=size)
dist_data = np.empty_like(unif_data)
for i, d in enumerate(dist):
dist_data[:, i] = d.ppf(unif_data[:, i])
else: # if a single distribution was input
nvars = dims
x = np.vstack((np.zeros(nvars), np.ones(nvars)))
unif_data = _lhs(x, samples=size)
dist_data = np.empty_like(unif_data)
for i in range(nvars):
dist_data[:, i] = dist.ppf(unif_data[:, i])
elif form is "spacefilling":
def euclid_distance(arr):
n = arr.shape[0]
ans = 0.0
for i in range(n - 1):
for j in range(i + 1, n):
d = np.sqrt(
np.sum(
[(arr[i, k] - arr[j, k]) ** 2 for k in range(arr.shape[1])]
)
)
ans += 1.0 / d ** 2
return ans
def fill_space(data):
best = 1e8
for it in range(iterations):
d = euclid_distance(data)
if d < best:
d_opt = d
data_opt = data.copy()
data = _mix(data)
print("Optimized Distance:", d_opt)
return data_opt
if hasattr(dist, "__getitem__"): # if multiple distributions were input
nvars = len(dist)
x = np.vstack((np.zeros(nvars), np.ones(nvars)))
unif_data = fill_space(_lhs(x, samples=size))
dist_data = np.empty_like(unif_data)
for i, d in enumerate(dist):
dist_data[:, i] = d.ppf(unif_data[:, i])
else: # if a single distribution was input
nvars = dims
x = np.vstack((np.zeros(nvars), np.ones(nvars)))
unif_data = fill_space(_lhs(x, samples=size))
dist_data = np.empty_like(unif_data)
for i in range(nvars):
dist_data[:, i] = dist.ppf(unif_data[:, i])
elif form is "orthogonal":
raise NotImplementedError(
"Sorry. The orthogonal space-filling algorithm hasn't been implemented yet."
)
else:
raise ValueError('Invalid "form" value: %s' % (form))
if dist_data.shape[1] > 1:
cor_matrix = np.zeros((nvars, nvars))
for i in range(nvars):
for j in range(nvars):
x_data = dist_data[:, i].copy()
y_data = dist_data[:, j].copy()
x_mean = x_data.mean()
y_mean = y_data.mean()
num = np.sum((x_data - x_mean) * (y_data - y_mean))
den = np.sqrt(
np.sum((x_data - x_mean) ** 2) * np.sum((y_data - y_mean) ** 2)
)
cor_matrix[i, j] = num / den
cor_matrix[j, i] = num / den
inv_cor_matrix = np.linalg.pinv(cor_matrix)
VIF = np.max(np.diag(inv_cor_matrix))
if showcorrelations:
print("Correlation Matrix:\n", cor_matrix)
print("Inverted Correlation Matrix:\n", inv_cor_matrix)
print("Variance Inflation Factor (VIF):", VIF)
return dist_data
|
python
|
def lhd(
dist=None,
size=None,
dims=1,
form="randomized",
iterations=100,
showcorrelations=False,
):
"""
Create a Latin-Hypercube sample design based on distributions defined in the
`scipy.stats` module
Parameters
----------
dist: array_like
frozen scipy.stats.rv_continuous or rv_discrete distribution objects
that are defined previous to calling LHD
size: int
integer value for the number of samples to generate for each
distribution object
dims: int, optional
if dist is a single distribution object, and dims > 1, the one
distribution will be used to generate a size-by-dims sampled design
form: str, optional (non-functional at the moment)
determines how the sampling is to occur, with the following optional
values:
- 'randomized' - completely randomized sampling
- 'spacefilling' - space-filling sampling (generally gives a more
accurate sampling of the design when the number of sample points
is small)
- 'orthogonal' - balanced space-filling sampling (experimental)
The 'spacefilling' and 'orthogonal' forms require some iterations to
determine the optimal sampling pattern.
iterations: int, optional (non-functional at the moment)
used to control the number of allowable search iterations for generating
'spacefilling' and 'orthogonal' designs
Returns
-------
out: 2d-array,
A 2d-array where each column corresponds to each input distribution and
each row is a sample in the design
Examples
--------
Single distribution:
- uniform distribution, low = -1, width = 2
>>> import scipy.stats as ss
>>> d0 = ss.uniform(loc=-1,scale=2)
>>> print lhd(dist=d0,size=5)
[[ 0.51031081]
[-0.28961427]
[-0.68342107]
[ 0.69784371]
[ 0.12248842]]
Single distribution for multiple variables:
- normal distribution, mean = 0, stdev = 1
>>> d1 = ss.norm(loc=0,scale=1)
>>> print lhd(dist=d1,size=7,dims=5)
[[-0.8612785 0.23034412 0.21808001]
[ 0.0455778 0.07001606 0.31586419]
[-0.978553 0.30394663 0.78483995]
[-0.26415983 0.15235896 0.51462024]
[ 0.80805686 0.38891031 0.02076505]
[ 1.63028931 0.52104917 1.48016008]]
Multiple distributions:
- beta distribution, alpha = 2, beta = 5
- exponential distribution, lambda = 1.5
>>> d2 = ss.beta(2,5)
>>> d3 = ss.expon(scale=1/1.5)
>>> print lhd(dist=(d1,d2,d3),size=6)
[[-0.8612785 0.23034412 0.21808001]
[ 0.0455778 0.07001606 0.31586419]
[-0.978553 0.30394663 0.78483995]
[-0.26415983 0.15235896 0.51462024]
[ 0.80805686 0.38891031 0.02076505]
[ 1.63028931 0.52104917 1.48016008]]
"""
assert dims > 0, 'kwarg "dims" must be at least 1'
if not size or not dist:
return None
def _lhs(x, samples=20):
"""
_lhs(x) returns a latin-hypercube matrix (each row is a different
set of sample inputs) using a default sample size of 20 for each column
of X. X must be a 2xN matrix that contains the lower and upper bounds of
each column. The lower bound(s) should be in the first row and the upper
bound(s) should be in the second row.
_lhs(x,samples=N) uses the sample size of N instead of the default (20).
Example:
>>> x = np.array([[0,-1,3],[1,2,6]])
>>> print 'x:'; print x
x:
[[ 0 -1 3]
[ 1 2 6]]
>>> print 'lhs(x):'; print _lhs(x)
lhs(x):
[[ 0.02989122 -0.93918734 3.14432618]
[ 0.08869833 -0.82140706 3.19875152]
[ 0.10627442 -0.66999234 3.33814979]
[ 0.15202861 -0.44157763 3.57036894]
[ 0.2067089 -0.34845384 3.66930908]
[ 0.26542056 -0.23706445 3.76361414]
[ 0.34201421 -0.00779306 3.90818257]
[ 0.37891646 0.15458423 4.15031708]
[ 0.43501575 0.23561118 4.20320064]
[ 0.4865449 0.36350601 4.45792314]
[ 0.54804367 0.56069855 4.60911539]
[ 0.59400712 0.7468415 4.69923486]
[ 0.63708876 0.9159176 4.83611204]
[ 0.68819855 0.98596354 4.97659182]
[ 0.7368695 1.18923511 5.11135111]
[ 0.78885724 1.28369441 5.2900157 ]
[ 0.80966513 1.47415703 5.4081971 ]
[ 0.86196731 1.57844205 5.61067689]
[ 0.94784517 1.71823504 5.78021164]
[ 0.96739728 1.94169017 5.88604772]]
>>> print 'lhs(x,samples=5):'; print _lhs(x,samples=5)
lhs(x,samples=5):
[[ 0.1949127 -0.54124725 3.49238369]
[ 0.21128576 -0.13439798 3.65652016]
[ 0.47516308 0.39957406 4.5797308 ]
[ 0.64400392 0.90890999 4.92379431]
[ 0.96279472 1.79415307 5.52028238]]
"""
# determine the segment size
segmentSize = 1.0 / samples
# get the number of dimensions to sample (number of columns)
numVars = x.shape[1]
# populate each dimension
out = np.zeros((samples, numVars))
pointValue = np.zeros(samples)
for n in range(numVars):
for i in range(samples):
segmentMin = i * segmentSize
point = segmentMin + (np.random.random() * segmentSize)
pointValue[i] = (point * (x[1, n] - x[0, n])) + x[0, n]
out[:, n] = pointValue
# now randomly arrange the different segments
return _mix(out)
def _mix(data, dim="cols"):
"""
Takes a data matrix and mixes up the values along dim (either "rows" or
"cols"). In other words, if dim='rows', then each row's data is mixed
ONLY WITHIN ITSELF. Likewise, if dim='cols', then each column's data is
mixed ONLY WITHIN ITSELF.
"""
data = np.atleast_2d(data)
n = data.shape[0]
if dim == "rows":
data = data.T
data_rank = list(range(n))
for i in range(data.shape[1]):
new_data_rank = np.random.permutation(data_rank)
vals, order = np.unique(
np.hstack((data_rank, new_data_rank)), return_inverse=True
)
old_order = order[:n]
new_order = order[-n:]
tmp = data[np.argsort(old_order), i][new_order]
data[:, i] = tmp[:]
if dim == "rows":
data = data.T
return data
if form is "randomized":
if hasattr(dist, "__getitem__"): # if multiple distributions were input
nvars = len(dist)
x = np.vstack((np.zeros(nvars), np.ones(nvars)))
unif_data = _lhs(x, samples=size)
dist_data = np.empty_like(unif_data)
for i, d in enumerate(dist):
dist_data[:, i] = d.ppf(unif_data[:, i])
else: # if a single distribution was input
nvars = dims
x = np.vstack((np.zeros(nvars), np.ones(nvars)))
unif_data = _lhs(x, samples=size)
dist_data = np.empty_like(unif_data)
for i in range(nvars):
dist_data[:, i] = dist.ppf(unif_data[:, i])
elif form is "spacefilling":
def euclid_distance(arr):
n = arr.shape[0]
ans = 0.0
for i in range(n - 1):
for j in range(i + 1, n):
d = np.sqrt(
np.sum(
[(arr[i, k] - arr[j, k]) ** 2 for k in range(arr.shape[1])]
)
)
ans += 1.0 / d ** 2
return ans
def fill_space(data):
best = 1e8
for it in range(iterations):
d = euclid_distance(data)
if d < best:
d_opt = d
data_opt = data.copy()
data = _mix(data)
print("Optimized Distance:", d_opt)
return data_opt
if hasattr(dist, "__getitem__"): # if multiple distributions were input
nvars = len(dist)
x = np.vstack((np.zeros(nvars), np.ones(nvars)))
unif_data = fill_space(_lhs(x, samples=size))
dist_data = np.empty_like(unif_data)
for i, d in enumerate(dist):
dist_data[:, i] = d.ppf(unif_data[:, i])
else: # if a single distribution was input
nvars = dims
x = np.vstack((np.zeros(nvars), np.ones(nvars)))
unif_data = fill_space(_lhs(x, samples=size))
dist_data = np.empty_like(unif_data)
for i in range(nvars):
dist_data[:, i] = dist.ppf(unif_data[:, i])
elif form is "orthogonal":
raise NotImplementedError(
"Sorry. The orthogonal space-filling algorithm hasn't been implemented yet."
)
else:
raise ValueError('Invalid "form" value: %s' % (form))
if dist_data.shape[1] > 1:
cor_matrix = np.zeros((nvars, nvars))
for i in range(nvars):
for j in range(nvars):
x_data = dist_data[:, i].copy()
y_data = dist_data[:, j].copy()
x_mean = x_data.mean()
y_mean = y_data.mean()
num = np.sum((x_data - x_mean) * (y_data - y_mean))
den = np.sqrt(
np.sum((x_data - x_mean) ** 2) * np.sum((y_data - y_mean) ** 2)
)
cor_matrix[i, j] = num / den
cor_matrix[j, i] = num / den
inv_cor_matrix = np.linalg.pinv(cor_matrix)
VIF = np.max(np.diag(inv_cor_matrix))
if showcorrelations:
print("Correlation Matrix:\n", cor_matrix)
print("Inverted Correlation Matrix:\n", inv_cor_matrix)
print("Variance Inflation Factor (VIF):", VIF)
return dist_data
|
[
"def",
"lhd",
"(",
"dist",
"=",
"None",
",",
"size",
"=",
"None",
",",
"dims",
"=",
"1",
",",
"form",
"=",
"\"randomized\"",
",",
"iterations",
"=",
"100",
",",
"showcorrelations",
"=",
"False",
",",
")",
":",
"assert",
"dims",
">",
"0",
",",
"'kwarg \"dims\" must be at least 1'",
"if",
"not",
"size",
"or",
"not",
"dist",
":",
"return",
"None",
"def",
"_lhs",
"(",
"x",
",",
"samples",
"=",
"20",
")",
":",
"\"\"\"\n _lhs(x) returns a latin-hypercube matrix (each row is a different\n set of sample inputs) using a default sample size of 20 for each column\n of X. X must be a 2xN matrix that contains the lower and upper bounds of\n each column. The lower bound(s) should be in the first row and the upper\n bound(s) should be in the second row.\n \n _lhs(x,samples=N) uses the sample size of N instead of the default (20).\n \n Example:\n >>> x = np.array([[0,-1,3],[1,2,6]])\n >>> print 'x:'; print x\n x:\n [[ 0 -1 3]\n [ 1 2 6]]\n\n >>> print 'lhs(x):'; print _lhs(x)\n lhs(x):\n [[ 0.02989122 -0.93918734 3.14432618]\n [ 0.08869833 -0.82140706 3.19875152]\n [ 0.10627442 -0.66999234 3.33814979]\n [ 0.15202861 -0.44157763 3.57036894]\n [ 0.2067089 -0.34845384 3.66930908]\n [ 0.26542056 -0.23706445 3.76361414]\n [ 0.34201421 -0.00779306 3.90818257]\n [ 0.37891646 0.15458423 4.15031708]\n [ 0.43501575 0.23561118 4.20320064]\n [ 0.4865449 0.36350601 4.45792314]\n [ 0.54804367 0.56069855 4.60911539]\n [ 0.59400712 0.7468415 4.69923486]\n [ 0.63708876 0.9159176 4.83611204]\n [ 0.68819855 0.98596354 4.97659182]\n [ 0.7368695 1.18923511 5.11135111]\n [ 0.78885724 1.28369441 5.2900157 ]\n [ 0.80966513 1.47415703 5.4081971 ]\n [ 0.86196731 1.57844205 5.61067689]\n [ 0.94784517 1.71823504 5.78021164]\n [ 0.96739728 1.94169017 5.88604772]]\n\n >>> print 'lhs(x,samples=5):'; print _lhs(x,samples=5)\n lhs(x,samples=5):\n [[ 0.1949127 -0.54124725 3.49238369]\n [ 0.21128576 -0.13439798 3.65652016]\n [ 0.47516308 0.39957406 4.5797308 ]\n [ 0.64400392 0.90890999 4.92379431]\n [ 0.96279472 1.79415307 5.52028238]] \n \"\"\"",
"# determine the segment size",
"segmentSize",
"=",
"1.0",
"/",
"samples",
"# get the number of dimensions to sample (number of columns)",
"numVars",
"=",
"x",
".",
"shape",
"[",
"1",
"]",
"# populate each dimension",
"out",
"=",
"np",
".",
"zeros",
"(",
"(",
"samples",
",",
"numVars",
")",
")",
"pointValue",
"=",
"np",
".",
"zeros",
"(",
"samples",
")",
"for",
"n",
"in",
"range",
"(",
"numVars",
")",
":",
"for",
"i",
"in",
"range",
"(",
"samples",
")",
":",
"segmentMin",
"=",
"i",
"*",
"segmentSize",
"point",
"=",
"segmentMin",
"+",
"(",
"np",
".",
"random",
".",
"random",
"(",
")",
"*",
"segmentSize",
")",
"pointValue",
"[",
"i",
"]",
"=",
"(",
"point",
"*",
"(",
"x",
"[",
"1",
",",
"n",
"]",
"-",
"x",
"[",
"0",
",",
"n",
"]",
")",
")",
"+",
"x",
"[",
"0",
",",
"n",
"]",
"out",
"[",
":",
",",
"n",
"]",
"=",
"pointValue",
"# now randomly arrange the different segments",
"return",
"_mix",
"(",
"out",
")",
"def",
"_mix",
"(",
"data",
",",
"dim",
"=",
"\"cols\"",
")",
":",
"\"\"\"\n Takes a data matrix and mixes up the values along dim (either \"rows\" or \n \"cols\"). In other words, if dim='rows', then each row's data is mixed\n ONLY WITHIN ITSELF. Likewise, if dim='cols', then each column's data is\n mixed ONLY WITHIN ITSELF.\n \"\"\"",
"data",
"=",
"np",
".",
"atleast_2d",
"(",
"data",
")",
"n",
"=",
"data",
".",
"shape",
"[",
"0",
"]",
"if",
"dim",
"==",
"\"rows\"",
":",
"data",
"=",
"data",
".",
"T",
"data_rank",
"=",
"list",
"(",
"range",
"(",
"n",
")",
")",
"for",
"i",
"in",
"range",
"(",
"data",
".",
"shape",
"[",
"1",
"]",
")",
":",
"new_data_rank",
"=",
"np",
".",
"random",
".",
"permutation",
"(",
"data_rank",
")",
"vals",
",",
"order",
"=",
"np",
".",
"unique",
"(",
"np",
".",
"hstack",
"(",
"(",
"data_rank",
",",
"new_data_rank",
")",
")",
",",
"return_inverse",
"=",
"True",
")",
"old_order",
"=",
"order",
"[",
":",
"n",
"]",
"new_order",
"=",
"order",
"[",
"-",
"n",
":",
"]",
"tmp",
"=",
"data",
"[",
"np",
".",
"argsort",
"(",
"old_order",
")",
",",
"i",
"]",
"[",
"new_order",
"]",
"data",
"[",
":",
",",
"i",
"]",
"=",
"tmp",
"[",
":",
"]",
"if",
"dim",
"==",
"\"rows\"",
":",
"data",
"=",
"data",
".",
"T",
"return",
"data",
"if",
"form",
"is",
"\"randomized\"",
":",
"if",
"hasattr",
"(",
"dist",
",",
"\"__getitem__\"",
")",
":",
"# if multiple distributions were input",
"nvars",
"=",
"len",
"(",
"dist",
")",
"x",
"=",
"np",
".",
"vstack",
"(",
"(",
"np",
".",
"zeros",
"(",
"nvars",
")",
",",
"np",
".",
"ones",
"(",
"nvars",
")",
")",
")",
"unif_data",
"=",
"_lhs",
"(",
"x",
",",
"samples",
"=",
"size",
")",
"dist_data",
"=",
"np",
".",
"empty_like",
"(",
"unif_data",
")",
"for",
"i",
",",
"d",
"in",
"enumerate",
"(",
"dist",
")",
":",
"dist_data",
"[",
":",
",",
"i",
"]",
"=",
"d",
".",
"ppf",
"(",
"unif_data",
"[",
":",
",",
"i",
"]",
")",
"else",
":",
"# if a single distribution was input",
"nvars",
"=",
"dims",
"x",
"=",
"np",
".",
"vstack",
"(",
"(",
"np",
".",
"zeros",
"(",
"nvars",
")",
",",
"np",
".",
"ones",
"(",
"nvars",
")",
")",
")",
"unif_data",
"=",
"_lhs",
"(",
"x",
",",
"samples",
"=",
"size",
")",
"dist_data",
"=",
"np",
".",
"empty_like",
"(",
"unif_data",
")",
"for",
"i",
"in",
"range",
"(",
"nvars",
")",
":",
"dist_data",
"[",
":",
",",
"i",
"]",
"=",
"dist",
".",
"ppf",
"(",
"unif_data",
"[",
":",
",",
"i",
"]",
")",
"elif",
"form",
"is",
"\"spacefilling\"",
":",
"def",
"euclid_distance",
"(",
"arr",
")",
":",
"n",
"=",
"arr",
".",
"shape",
"[",
"0",
"]",
"ans",
"=",
"0.0",
"for",
"i",
"in",
"range",
"(",
"n",
"-",
"1",
")",
":",
"for",
"j",
"in",
"range",
"(",
"i",
"+",
"1",
",",
"n",
")",
":",
"d",
"=",
"np",
".",
"sqrt",
"(",
"np",
".",
"sum",
"(",
"[",
"(",
"arr",
"[",
"i",
",",
"k",
"]",
"-",
"arr",
"[",
"j",
",",
"k",
"]",
")",
"**",
"2",
"for",
"k",
"in",
"range",
"(",
"arr",
".",
"shape",
"[",
"1",
"]",
")",
"]",
")",
")",
"ans",
"+=",
"1.0",
"/",
"d",
"**",
"2",
"return",
"ans",
"def",
"fill_space",
"(",
"data",
")",
":",
"best",
"=",
"1e8",
"for",
"it",
"in",
"range",
"(",
"iterations",
")",
":",
"d",
"=",
"euclid_distance",
"(",
"data",
")",
"if",
"d",
"<",
"best",
":",
"d_opt",
"=",
"d",
"data_opt",
"=",
"data",
".",
"copy",
"(",
")",
"data",
"=",
"_mix",
"(",
"data",
")",
"print",
"(",
"\"Optimized Distance:\"",
",",
"d_opt",
")",
"return",
"data_opt",
"if",
"hasattr",
"(",
"dist",
",",
"\"__getitem__\"",
")",
":",
"# if multiple distributions were input",
"nvars",
"=",
"len",
"(",
"dist",
")",
"x",
"=",
"np",
".",
"vstack",
"(",
"(",
"np",
".",
"zeros",
"(",
"nvars",
")",
",",
"np",
".",
"ones",
"(",
"nvars",
")",
")",
")",
"unif_data",
"=",
"fill_space",
"(",
"_lhs",
"(",
"x",
",",
"samples",
"=",
"size",
")",
")",
"dist_data",
"=",
"np",
".",
"empty_like",
"(",
"unif_data",
")",
"for",
"i",
",",
"d",
"in",
"enumerate",
"(",
"dist",
")",
":",
"dist_data",
"[",
":",
",",
"i",
"]",
"=",
"d",
".",
"ppf",
"(",
"unif_data",
"[",
":",
",",
"i",
"]",
")",
"else",
":",
"# if a single distribution was input",
"nvars",
"=",
"dims",
"x",
"=",
"np",
".",
"vstack",
"(",
"(",
"np",
".",
"zeros",
"(",
"nvars",
")",
",",
"np",
".",
"ones",
"(",
"nvars",
")",
")",
")",
"unif_data",
"=",
"fill_space",
"(",
"_lhs",
"(",
"x",
",",
"samples",
"=",
"size",
")",
")",
"dist_data",
"=",
"np",
".",
"empty_like",
"(",
"unif_data",
")",
"for",
"i",
"in",
"range",
"(",
"nvars",
")",
":",
"dist_data",
"[",
":",
",",
"i",
"]",
"=",
"dist",
".",
"ppf",
"(",
"unif_data",
"[",
":",
",",
"i",
"]",
")",
"elif",
"form",
"is",
"\"orthogonal\"",
":",
"raise",
"NotImplementedError",
"(",
"\"Sorry. The orthogonal space-filling algorithm hasn't been implemented yet.\"",
")",
"else",
":",
"raise",
"ValueError",
"(",
"'Invalid \"form\" value: %s'",
"%",
"(",
"form",
")",
")",
"if",
"dist_data",
".",
"shape",
"[",
"1",
"]",
">",
"1",
":",
"cor_matrix",
"=",
"np",
".",
"zeros",
"(",
"(",
"nvars",
",",
"nvars",
")",
")",
"for",
"i",
"in",
"range",
"(",
"nvars",
")",
":",
"for",
"j",
"in",
"range",
"(",
"nvars",
")",
":",
"x_data",
"=",
"dist_data",
"[",
":",
",",
"i",
"]",
".",
"copy",
"(",
")",
"y_data",
"=",
"dist_data",
"[",
":",
",",
"j",
"]",
".",
"copy",
"(",
")",
"x_mean",
"=",
"x_data",
".",
"mean",
"(",
")",
"y_mean",
"=",
"y_data",
".",
"mean",
"(",
")",
"num",
"=",
"np",
".",
"sum",
"(",
"(",
"x_data",
"-",
"x_mean",
")",
"*",
"(",
"y_data",
"-",
"y_mean",
")",
")",
"den",
"=",
"np",
".",
"sqrt",
"(",
"np",
".",
"sum",
"(",
"(",
"x_data",
"-",
"x_mean",
")",
"**",
"2",
")",
"*",
"np",
".",
"sum",
"(",
"(",
"y_data",
"-",
"y_mean",
")",
"**",
"2",
")",
")",
"cor_matrix",
"[",
"i",
",",
"j",
"]",
"=",
"num",
"/",
"den",
"cor_matrix",
"[",
"j",
",",
"i",
"]",
"=",
"num",
"/",
"den",
"inv_cor_matrix",
"=",
"np",
".",
"linalg",
".",
"pinv",
"(",
"cor_matrix",
")",
"VIF",
"=",
"np",
".",
"max",
"(",
"np",
".",
"diag",
"(",
"inv_cor_matrix",
")",
")",
"if",
"showcorrelations",
":",
"print",
"(",
"\"Correlation Matrix:\\n\"",
",",
"cor_matrix",
")",
"print",
"(",
"\"Inverted Correlation Matrix:\\n\"",
",",
"inv_cor_matrix",
")",
"print",
"(",
"\"Variance Inflation Factor (VIF):\"",
",",
"VIF",
")",
"return",
"dist_data"
] |
Create a Latin-Hypercube sample design based on distributions defined in the
`scipy.stats` module
Parameters
----------
dist: array_like
frozen scipy.stats.rv_continuous or rv_discrete distribution objects
that are defined previous to calling LHD
size: int
integer value for the number of samples to generate for each
distribution object
dims: int, optional
if dist is a single distribution object, and dims > 1, the one
distribution will be used to generate a size-by-dims sampled design
form: str, optional (non-functional at the moment)
determines how the sampling is to occur, with the following optional
values:
- 'randomized' - completely randomized sampling
- 'spacefilling' - space-filling sampling (generally gives a more
accurate sampling of the design when the number of sample points
is small)
- 'orthogonal' - balanced space-filling sampling (experimental)
The 'spacefilling' and 'orthogonal' forms require some iterations to
determine the optimal sampling pattern.
iterations: int, optional (non-functional at the moment)
used to control the number of allowable search iterations for generating
'spacefilling' and 'orthogonal' designs
Returns
-------
out: 2d-array,
A 2d-array where each column corresponds to each input distribution and
each row is a sample in the design
Examples
--------
Single distribution:
- uniform distribution, low = -1, width = 2
>>> import scipy.stats as ss
>>> d0 = ss.uniform(loc=-1,scale=2)
>>> print lhd(dist=d0,size=5)
[[ 0.51031081]
[-0.28961427]
[-0.68342107]
[ 0.69784371]
[ 0.12248842]]
Single distribution for multiple variables:
- normal distribution, mean = 0, stdev = 1
>>> d1 = ss.norm(loc=0,scale=1)
>>> print lhd(dist=d1,size=7,dims=5)
[[-0.8612785 0.23034412 0.21808001]
[ 0.0455778 0.07001606 0.31586419]
[-0.978553 0.30394663 0.78483995]
[-0.26415983 0.15235896 0.51462024]
[ 0.80805686 0.38891031 0.02076505]
[ 1.63028931 0.52104917 1.48016008]]
Multiple distributions:
- beta distribution, alpha = 2, beta = 5
- exponential distribution, lambda = 1.5
>>> d2 = ss.beta(2,5)
>>> d3 = ss.expon(scale=1/1.5)
>>> print lhd(dist=(d1,d2,d3),size=6)
[[-0.8612785 0.23034412 0.21808001]
[ 0.0455778 0.07001606 0.31586419]
[-0.978553 0.30394663 0.78483995]
[-0.26415983 0.15235896 0.51462024]
[ 0.80805686 0.38891031 0.02076505]
[ 1.63028931 0.52104917 1.48016008]]
|
[
"Create",
"a",
"Latin",
"-",
"Hypercube",
"sample",
"design",
"based",
"on",
"distributions",
"defined",
"in",
"the",
"scipy",
".",
"stats",
"module",
"Parameters",
"----------",
"dist",
":",
"array_like",
"frozen",
"scipy",
".",
"stats",
".",
"rv_continuous",
"or",
"rv_discrete",
"distribution",
"objects",
"that",
"are",
"defined",
"previous",
"to",
"calling",
"LHD"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/lhd.py#L5-L286
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
to_uncertain_func
|
def to_uncertain_func(x):
"""
Transforms x into an UncertainFunction-compatible object,
unless it is already an UncertainFunction (in which case x is returned
unchanged).
Raises an exception unless 'x' belongs to some specific classes of
objects that are known not to depend on UncertainFunction objects
(which then cannot be considered as constants).
"""
if isinstance(x, UncertainFunction):
return x
# ! In Python 2.6+, numbers.Number could be used instead, here:
elif isinstance(x, CONSTANT_TYPES):
# No variable => no derivative to define:
return UncertainFunction([x] * npts)
raise NotUpcast("%s cannot be converted to a number with" " uncertainty" % type(x))
|
python
|
def to_uncertain_func(x):
"""
Transforms x into an UncertainFunction-compatible object,
unless it is already an UncertainFunction (in which case x is returned
unchanged).
Raises an exception unless 'x' belongs to some specific classes of
objects that are known not to depend on UncertainFunction objects
(which then cannot be considered as constants).
"""
if isinstance(x, UncertainFunction):
return x
# ! In Python 2.6+, numbers.Number could be used instead, here:
elif isinstance(x, CONSTANT_TYPES):
# No variable => no derivative to define:
return UncertainFunction([x] * npts)
raise NotUpcast("%s cannot be converted to a number with" " uncertainty" % type(x))
|
[
"def",
"to_uncertain_func",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"UncertainFunction",
")",
":",
"return",
"x",
"# ! In Python 2.6+, numbers.Number could be used instead, here:",
"elif",
"isinstance",
"(",
"x",
",",
"CONSTANT_TYPES",
")",
":",
"# No variable => no derivative to define:",
"return",
"UncertainFunction",
"(",
"[",
"x",
"]",
"*",
"npts",
")",
"raise",
"NotUpcast",
"(",
"\"%s cannot be converted to a number with\"",
"\" uncertainty\"",
"%",
"type",
"(",
"x",
")",
")"
] |
Transforms x into an UncertainFunction-compatible object,
unless it is already an UncertainFunction (in which case x is returned
unchanged).
Raises an exception unless 'x' belongs to some specific classes of
objects that are known not to depend on UncertainFunction objects
(which then cannot be considered as constants).
|
[
"Transforms",
"x",
"into",
"an",
"UncertainFunction",
"-",
"compatible",
"object",
"unless",
"it",
"is",
"already",
"an",
"UncertainFunction",
"(",
"in",
"which",
"case",
"x",
"is",
"returned",
"unchanged",
")",
"."
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L31-L49
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Beta
|
def Beta(alpha, beta, low=0, high=1, tag=None):
"""
A Beta random variate
Parameters
----------
alpha : scalar
The first shape parameter
beta : scalar
The second shape parameter
Optional
--------
low : scalar
Lower bound of the distribution support (default=0)
high : scalar
Upper bound of the distribution support (default=1)
"""
assert (
alpha > 0 and beta > 0
), 'Beta "alpha" and "beta" parameters must be greater than zero'
assert low < high, 'Beta "low" must be less than "high"'
return uv(ss.beta(alpha, beta, loc=low, scale=high - low), tag=tag)
|
python
|
def Beta(alpha, beta, low=0, high=1, tag=None):
"""
A Beta random variate
Parameters
----------
alpha : scalar
The first shape parameter
beta : scalar
The second shape parameter
Optional
--------
low : scalar
Lower bound of the distribution support (default=0)
high : scalar
Upper bound of the distribution support (default=1)
"""
assert (
alpha > 0 and beta > 0
), 'Beta "alpha" and "beta" parameters must be greater than zero'
assert low < high, 'Beta "low" must be less than "high"'
return uv(ss.beta(alpha, beta, loc=low, scale=high - low), tag=tag)
|
[
"def",
"Beta",
"(",
"alpha",
",",
"beta",
",",
"low",
"=",
"0",
",",
"high",
"=",
"1",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"(",
"alpha",
">",
"0",
"and",
"beta",
">",
"0",
")",
",",
"'Beta \"alpha\" and \"beta\" parameters must be greater than zero'",
"assert",
"low",
"<",
"high",
",",
"'Beta \"low\" must be less than \"high\"'",
"return",
"uv",
"(",
"ss",
".",
"beta",
"(",
"alpha",
",",
"beta",
",",
"loc",
"=",
"low",
",",
"scale",
"=",
"high",
"-",
"low",
")",
",",
"tag",
"=",
"tag",
")"
] |
A Beta random variate
Parameters
----------
alpha : scalar
The first shape parameter
beta : scalar
The second shape parameter
Optional
--------
low : scalar
Lower bound of the distribution support (default=0)
high : scalar
Upper bound of the distribution support (default=1)
|
[
"A",
"Beta",
"random",
"variate",
"Parameters",
"----------",
"alpha",
":",
"scalar",
"The",
"first",
"shape",
"parameter",
"beta",
":",
"scalar",
"The",
"second",
"shape",
"parameter",
"Optional",
"--------",
"low",
":",
"scalar",
"Lower",
"bound",
"of",
"the",
"distribution",
"support",
"(",
"default",
"=",
"0",
")",
"high",
":",
"scalar",
"Upper",
"bound",
"of",
"the",
"distribution",
"support",
"(",
"default",
"=",
"1",
")"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L721-L743
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
BetaPrime
|
def BetaPrime(alpha, beta, tag=None):
"""
A BetaPrime random variate
Parameters
----------
alpha : scalar
The first shape parameter
beta : scalar
The second shape parameter
"""
assert (
alpha > 0 and beta > 0
), 'BetaPrime "alpha" and "beta" parameters must be greater than zero'
x = Beta(alpha, beta, tag)
return x / (1 - x)
|
python
|
def BetaPrime(alpha, beta, tag=None):
"""
A BetaPrime random variate
Parameters
----------
alpha : scalar
The first shape parameter
beta : scalar
The second shape parameter
"""
assert (
alpha > 0 and beta > 0
), 'BetaPrime "alpha" and "beta" parameters must be greater than zero'
x = Beta(alpha, beta, tag)
return x / (1 - x)
|
[
"def",
"BetaPrime",
"(",
"alpha",
",",
"beta",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"(",
"alpha",
">",
"0",
"and",
"beta",
">",
"0",
")",
",",
"'BetaPrime \"alpha\" and \"beta\" parameters must be greater than zero'",
"x",
"=",
"Beta",
"(",
"alpha",
",",
"beta",
",",
"tag",
")",
"return",
"x",
"/",
"(",
"1",
"-",
"x",
")"
] |
A BetaPrime random variate
Parameters
----------
alpha : scalar
The first shape parameter
beta : scalar
The second shape parameter
|
[
"A",
"BetaPrime",
"random",
"variate",
"Parameters",
"----------",
"alpha",
":",
"scalar",
"The",
"first",
"shape",
"parameter",
"beta",
":",
"scalar",
"The",
"second",
"shape",
"parameter"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L746-L762
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Bradford
|
def Bradford(q, low=0, high=1, tag=None):
"""
A Bradford random variate
Parameters
----------
q : scalar
The shape parameter
low : scalar
The lower bound of the distribution (default=0)
high : scalar
The upper bound of the distribution (default=1)
"""
assert q > 0, 'Bradford "q" parameter must be greater than zero'
assert low < high, 'Bradford "low" parameter must be less than "high"'
return uv(ss.bradford(q, loc=low, scale=high - low), tag=tag)
|
python
|
def Bradford(q, low=0, high=1, tag=None):
"""
A Bradford random variate
Parameters
----------
q : scalar
The shape parameter
low : scalar
The lower bound of the distribution (default=0)
high : scalar
The upper bound of the distribution (default=1)
"""
assert q > 0, 'Bradford "q" parameter must be greater than zero'
assert low < high, 'Bradford "low" parameter must be less than "high"'
return uv(ss.bradford(q, loc=low, scale=high - low), tag=tag)
|
[
"def",
"Bradford",
"(",
"q",
",",
"low",
"=",
"0",
",",
"high",
"=",
"1",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"q",
">",
"0",
",",
"'Bradford \"q\" parameter must be greater than zero'",
"assert",
"low",
"<",
"high",
",",
"'Bradford \"low\" parameter must be less than \"high\"'",
"return",
"uv",
"(",
"ss",
".",
"bradford",
"(",
"q",
",",
"loc",
"=",
"low",
",",
"scale",
"=",
"high",
"-",
"low",
")",
",",
"tag",
"=",
"tag",
")"
] |
A Bradford random variate
Parameters
----------
q : scalar
The shape parameter
low : scalar
The lower bound of the distribution (default=0)
high : scalar
The upper bound of the distribution (default=1)
|
[
"A",
"Bradford",
"random",
"variate",
"Parameters",
"----------",
"q",
":",
"scalar",
"The",
"shape",
"parameter",
"low",
":",
"scalar",
"The",
"lower",
"bound",
"of",
"the",
"distribution",
"(",
"default",
"=",
"0",
")",
"high",
":",
"scalar",
"The",
"upper",
"bound",
"of",
"the",
"distribution",
"(",
"default",
"=",
"1",
")"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L765-L780
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Burr
|
def Burr(c, k, tag=None):
"""
A Burr random variate
Parameters
----------
c : scalar
The first shape parameter
k : scalar
The second shape parameter
"""
assert c > 0 and k > 0, 'Burr "c" and "k" parameters must be greater than zero'
return uv(ss.burr(c, k), tag=tag)
|
python
|
def Burr(c, k, tag=None):
"""
A Burr random variate
Parameters
----------
c : scalar
The first shape parameter
k : scalar
The second shape parameter
"""
assert c > 0 and k > 0, 'Burr "c" and "k" parameters must be greater than zero'
return uv(ss.burr(c, k), tag=tag)
|
[
"def",
"Burr",
"(",
"c",
",",
"k",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"c",
">",
"0",
"and",
"k",
">",
"0",
",",
"'Burr \"c\" and \"k\" parameters must be greater than zero'",
"return",
"uv",
"(",
"ss",
".",
"burr",
"(",
"c",
",",
"k",
")",
",",
"tag",
"=",
"tag",
")"
] |
A Burr random variate
Parameters
----------
c : scalar
The first shape parameter
k : scalar
The second shape parameter
|
[
"A",
"Burr",
"random",
"variate",
"Parameters",
"----------",
"c",
":",
"scalar",
"The",
"first",
"shape",
"parameter",
"k",
":",
"scalar",
"The",
"second",
"shape",
"parameter"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L783-L796
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
ChiSquared
|
def ChiSquared(k, tag=None):
"""
A Chi-Squared random variate
Parameters
----------
k : int
The degrees of freedom of the distribution (must be greater than one)
"""
assert int(k) == k and k >= 1, 'Chi-Squared "k" must be an integer greater than 0'
return uv(ss.chi2(k), tag=tag)
|
python
|
def ChiSquared(k, tag=None):
"""
A Chi-Squared random variate
Parameters
----------
k : int
The degrees of freedom of the distribution (must be greater than one)
"""
assert int(k) == k and k >= 1, 'Chi-Squared "k" must be an integer greater than 0'
return uv(ss.chi2(k), tag=tag)
|
[
"def",
"ChiSquared",
"(",
"k",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"int",
"(",
"k",
")",
"==",
"k",
"and",
"k",
">=",
"1",
",",
"'Chi-Squared \"k\" must be an integer greater than 0'",
"return",
"uv",
"(",
"ss",
".",
"chi2",
"(",
"k",
")",
",",
"tag",
"=",
"tag",
")"
] |
A Chi-Squared random variate
Parameters
----------
k : int
The degrees of freedom of the distribution (must be greater than one)
|
[
"A",
"Chi",
"-",
"Squared",
"random",
"variate",
"Parameters",
"----------",
"k",
":",
"int",
"The",
"degrees",
"of",
"freedom",
"of",
"the",
"distribution",
"(",
"must",
"be",
"greater",
"than",
"one",
")"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L799-L809
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Erlang
|
def Erlang(k, lamda, tag=None):
"""
An Erlang random variate.
This distribution is the same as a Gamma(k, theta) distribution, but
with the restriction that k must be a positive integer. This
is provided for greater compatibility with other simulation tools, but
provides no advantage over the Gamma distribution in its applications.
Parameters
----------
k : int
The shape parameter (must be a positive integer)
lamda : scalar
The scale parameter (must be greater than zero)
"""
assert int(k) == k and k > 0, 'Erlang "k" must be a positive integer'
assert lamda > 0, 'Erlang "lamda" must be greater than zero'
return Gamma(k, lamda, tag)
|
python
|
def Erlang(k, lamda, tag=None):
"""
An Erlang random variate.
This distribution is the same as a Gamma(k, theta) distribution, but
with the restriction that k must be a positive integer. This
is provided for greater compatibility with other simulation tools, but
provides no advantage over the Gamma distribution in its applications.
Parameters
----------
k : int
The shape parameter (must be a positive integer)
lamda : scalar
The scale parameter (must be greater than zero)
"""
assert int(k) == k and k > 0, 'Erlang "k" must be a positive integer'
assert lamda > 0, 'Erlang "lamda" must be greater than zero'
return Gamma(k, lamda, tag)
|
[
"def",
"Erlang",
"(",
"k",
",",
"lamda",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"int",
"(",
"k",
")",
"==",
"k",
"and",
"k",
">",
"0",
",",
"'Erlang \"k\" must be a positive integer'",
"assert",
"lamda",
">",
"0",
",",
"'Erlang \"lamda\" must be greater than zero'",
"return",
"Gamma",
"(",
"k",
",",
"lamda",
",",
"tag",
")"
] |
An Erlang random variate.
This distribution is the same as a Gamma(k, theta) distribution, but
with the restriction that k must be a positive integer. This
is provided for greater compatibility with other simulation tools, but
provides no advantage over the Gamma distribution in its applications.
Parameters
----------
k : int
The shape parameter (must be a positive integer)
lamda : scalar
The scale parameter (must be greater than zero)
|
[
"An",
"Erlang",
"random",
"variate",
".",
"This",
"distribution",
"is",
"the",
"same",
"as",
"a",
"Gamma",
"(",
"k",
"theta",
")",
"distribution",
"but",
"with",
"the",
"restriction",
"that",
"k",
"must",
"be",
"a",
"positive",
"integer",
".",
"This",
"is",
"provided",
"for",
"greater",
"compatibility",
"with",
"other",
"simulation",
"tools",
"but",
"provides",
"no",
"advantage",
"over",
"the",
"Gamma",
"distribution",
"in",
"its",
"applications",
".",
"Parameters",
"----------",
"k",
":",
"int",
"The",
"shape",
"parameter",
"(",
"must",
"be",
"a",
"positive",
"integer",
")",
"lamda",
":",
"scalar",
"The",
"scale",
"parameter",
"(",
"must",
"be",
"greater",
"than",
"zero",
")"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L832-L850
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Exponential
|
def Exponential(lamda, tag=None):
"""
An Exponential random variate
Parameters
----------
lamda : scalar
The inverse scale (as shown on Wikipedia). (FYI: mu = 1/lamda.)
"""
assert lamda > 0, 'Exponential "lamda" must be greater than zero'
return uv(ss.expon(scale=1.0 / lamda), tag=tag)
|
python
|
def Exponential(lamda, tag=None):
"""
An Exponential random variate
Parameters
----------
lamda : scalar
The inverse scale (as shown on Wikipedia). (FYI: mu = 1/lamda.)
"""
assert lamda > 0, 'Exponential "lamda" must be greater than zero'
return uv(ss.expon(scale=1.0 / lamda), tag=tag)
|
[
"def",
"Exponential",
"(",
"lamda",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"lamda",
">",
"0",
",",
"'Exponential \"lamda\" must be greater than zero'",
"return",
"uv",
"(",
"ss",
".",
"expon",
"(",
"scale",
"=",
"1.0",
"/",
"lamda",
")",
",",
"tag",
"=",
"tag",
")"
] |
An Exponential random variate
Parameters
----------
lamda : scalar
The inverse scale (as shown on Wikipedia). (FYI: mu = 1/lamda.)
|
[
"An",
"Exponential",
"random",
"variate",
"Parameters",
"----------",
"lamda",
":",
"scalar",
"The",
"inverse",
"scale",
"(",
"as",
"shown",
"on",
"Wikipedia",
")",
".",
"(",
"FYI",
":",
"mu",
"=",
"1",
"/",
"lamda",
".",
")"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L853-L863
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
ExtValueMax
|
def ExtValueMax(mu, sigma, tag=None):
"""
An Extreme Value Maximum random variate.
Parameters
----------
mu : scalar
The location parameter
sigma : scalar
The scale parameter (must be greater than zero)
"""
assert sigma > 0, 'ExtremeValueMax "sigma" must be greater than zero'
p = U(0, 1)._mcpts[:]
return UncertainFunction(mu - sigma * np.log(-np.log(p)), tag=tag)
|
python
|
def ExtValueMax(mu, sigma, tag=None):
"""
An Extreme Value Maximum random variate.
Parameters
----------
mu : scalar
The location parameter
sigma : scalar
The scale parameter (must be greater than zero)
"""
assert sigma > 0, 'ExtremeValueMax "sigma" must be greater than zero'
p = U(0, 1)._mcpts[:]
return UncertainFunction(mu - sigma * np.log(-np.log(p)), tag=tag)
|
[
"def",
"ExtValueMax",
"(",
"mu",
",",
"sigma",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"sigma",
">",
"0",
",",
"'ExtremeValueMax \"sigma\" must be greater than zero'",
"p",
"=",
"U",
"(",
"0",
",",
"1",
")",
".",
"_mcpts",
"[",
":",
"]",
"return",
"UncertainFunction",
"(",
"mu",
"-",
"sigma",
"*",
"np",
".",
"log",
"(",
"-",
"np",
".",
"log",
"(",
"p",
")",
")",
",",
"tag",
"=",
"tag",
")"
] |
An Extreme Value Maximum random variate.
Parameters
----------
mu : scalar
The location parameter
sigma : scalar
The scale parameter (must be greater than zero)
|
[
"An",
"Extreme",
"Value",
"Maximum",
"random",
"variate",
".",
"Parameters",
"----------",
"mu",
":",
"scalar",
"The",
"location",
"parameter",
"sigma",
":",
"scalar",
"The",
"scale",
"parameter",
"(",
"must",
"be",
"greater",
"than",
"zero",
")"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L869-L882
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Fisher
|
def Fisher(d1, d2, tag=None):
"""
An F (fisher) random variate
Parameters
----------
d1 : int
Numerator degrees of freedom
d2 : int
Denominator degrees of freedom
"""
assert (
int(d1) == d1 and d1 >= 1
), 'Fisher (F) "d1" must be an integer greater than 0'
assert (
int(d2) == d2 and d2 >= 1
), 'Fisher (F) "d2" must be an integer greater than 0'
return uv(ss.f(d1, d2), tag=tag)
|
python
|
def Fisher(d1, d2, tag=None):
"""
An F (fisher) random variate
Parameters
----------
d1 : int
Numerator degrees of freedom
d2 : int
Denominator degrees of freedom
"""
assert (
int(d1) == d1 and d1 >= 1
), 'Fisher (F) "d1" must be an integer greater than 0'
assert (
int(d2) == d2 and d2 >= 1
), 'Fisher (F) "d2" must be an integer greater than 0'
return uv(ss.f(d1, d2), tag=tag)
|
[
"def",
"Fisher",
"(",
"d1",
",",
"d2",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"(",
"int",
"(",
"d1",
")",
"==",
"d1",
"and",
"d1",
">=",
"1",
")",
",",
"'Fisher (F) \"d1\" must be an integer greater than 0'",
"assert",
"(",
"int",
"(",
"d2",
")",
"==",
"d2",
"and",
"d2",
">=",
"1",
")",
",",
"'Fisher (F) \"d2\" must be an integer greater than 0'",
"return",
"uv",
"(",
"ss",
".",
"f",
"(",
"d1",
",",
"d2",
")",
",",
"tag",
"=",
"tag",
")"
] |
An F (fisher) random variate
Parameters
----------
d1 : int
Numerator degrees of freedom
d2 : int
Denominator degrees of freedom
|
[
"An",
"F",
"(",
"fisher",
")",
"random",
"variate",
"Parameters",
"----------",
"d1",
":",
"int",
"Numerator",
"degrees",
"of",
"freedom",
"d2",
":",
"int",
"Denominator",
"degrees",
"of",
"freedom"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L907-L924
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Gamma
|
def Gamma(k, theta, tag=None):
"""
A Gamma random variate
Parameters
----------
k : scalar
The shape parameter (must be positive and non-zero)
theta : scalar
The scale parameter (must be positive and non-zero)
"""
assert (
k > 0 and theta > 0
), 'Gamma "k" and "theta" parameters must be greater than zero'
return uv(ss.gamma(k, scale=theta), tag=tag)
|
python
|
def Gamma(k, theta, tag=None):
"""
A Gamma random variate
Parameters
----------
k : scalar
The shape parameter (must be positive and non-zero)
theta : scalar
The scale parameter (must be positive and non-zero)
"""
assert (
k > 0 and theta > 0
), 'Gamma "k" and "theta" parameters must be greater than zero'
return uv(ss.gamma(k, scale=theta), tag=tag)
|
[
"def",
"Gamma",
"(",
"k",
",",
"theta",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"(",
"k",
">",
"0",
"and",
"theta",
">",
"0",
")",
",",
"'Gamma \"k\" and \"theta\" parameters must be greater than zero'",
"return",
"uv",
"(",
"ss",
".",
"gamma",
"(",
"k",
",",
"scale",
"=",
"theta",
")",
",",
"tag",
"=",
"tag",
")"
] |
A Gamma random variate
Parameters
----------
k : scalar
The shape parameter (must be positive and non-zero)
theta : scalar
The scale parameter (must be positive and non-zero)
|
[
"A",
"Gamma",
"random",
"variate",
"Parameters",
"----------",
"k",
":",
"scalar",
"The",
"shape",
"parameter",
"(",
"must",
"be",
"positive",
"and",
"non",
"-",
"zero",
")",
"theta",
":",
"scalar",
"The",
"scale",
"parameter",
"(",
"must",
"be",
"positive",
"and",
"non",
"-",
"zero",
")"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L930-L944
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
LogNormal
|
def LogNormal(mu, sigma, tag=None):
"""
A Log-Normal random variate
Parameters
----------
mu : scalar
The location parameter
sigma : scalar
The scale parameter (must be positive and non-zero)
"""
assert sigma > 0, 'Log-Normal "sigma" must be positive'
return uv(ss.lognorm(sigma, loc=mu), tag=tag)
|
python
|
def LogNormal(mu, sigma, tag=None):
"""
A Log-Normal random variate
Parameters
----------
mu : scalar
The location parameter
sigma : scalar
The scale parameter (must be positive and non-zero)
"""
assert sigma > 0, 'Log-Normal "sigma" must be positive'
return uv(ss.lognorm(sigma, loc=mu), tag=tag)
|
[
"def",
"LogNormal",
"(",
"mu",
",",
"sigma",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"sigma",
">",
"0",
",",
"'Log-Normal \"sigma\" must be positive'",
"return",
"uv",
"(",
"ss",
".",
"lognorm",
"(",
"sigma",
",",
"loc",
"=",
"mu",
")",
",",
"tag",
"=",
"tag",
")"
] |
A Log-Normal random variate
Parameters
----------
mu : scalar
The location parameter
sigma : scalar
The scale parameter (must be positive and non-zero)
|
[
"A",
"Log",
"-",
"Normal",
"random",
"variate",
"Parameters",
"----------",
"mu",
":",
"scalar",
"The",
"location",
"parameter",
"sigma",
":",
"scalar",
"The",
"scale",
"parameter",
"(",
"must",
"be",
"positive",
"and",
"non",
"-",
"zero",
")"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L947-L959
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Normal
|
def Normal(mu, sigma, tag=None):
"""
A Normal (or Gaussian) random variate
Parameters
----------
mu : scalar
The mean value of the distribution
sigma : scalar
The standard deviation (must be positive and non-zero)
"""
assert sigma > 0, 'Normal "sigma" must be greater than zero'
return uv(ss.norm(loc=mu, scale=sigma), tag=tag)
|
python
|
def Normal(mu, sigma, tag=None):
"""
A Normal (or Gaussian) random variate
Parameters
----------
mu : scalar
The mean value of the distribution
sigma : scalar
The standard deviation (must be positive and non-zero)
"""
assert sigma > 0, 'Normal "sigma" must be greater than zero'
return uv(ss.norm(loc=mu, scale=sigma), tag=tag)
|
[
"def",
"Normal",
"(",
"mu",
",",
"sigma",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"sigma",
">",
"0",
",",
"'Normal \"sigma\" must be greater than zero'",
"return",
"uv",
"(",
"ss",
".",
"norm",
"(",
"loc",
"=",
"mu",
",",
"scale",
"=",
"sigma",
")",
",",
"tag",
"=",
"tag",
")"
] |
A Normal (or Gaussian) random variate
Parameters
----------
mu : scalar
The mean value of the distribution
sigma : scalar
The standard deviation (must be positive and non-zero)
|
[
"A",
"Normal",
"(",
"or",
"Gaussian",
")",
"random",
"variate",
"Parameters",
"----------",
"mu",
":",
"scalar",
"The",
"mean",
"value",
"of",
"the",
"distribution",
"sigma",
":",
"scalar",
"The",
"standard",
"deviation",
"(",
"must",
"be",
"positive",
"and",
"non",
"-",
"zero",
")"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L965-L977
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Pareto
|
def Pareto(q, a, tag=None):
"""
A Pareto random variate (first kind)
Parameters
----------
q : scalar
The scale parameter
a : scalar
The shape parameter (the minimum possible value)
"""
assert q > 0 and a > 0, 'Pareto "q" and "a" must be positive scalars'
p = Uniform(0, 1, tag)
return a * (1 - p) ** (-1.0 / q)
|
python
|
def Pareto(q, a, tag=None):
"""
A Pareto random variate (first kind)
Parameters
----------
q : scalar
The scale parameter
a : scalar
The shape parameter (the minimum possible value)
"""
assert q > 0 and a > 0, 'Pareto "q" and "a" must be positive scalars'
p = Uniform(0, 1, tag)
return a * (1 - p) ** (-1.0 / q)
|
[
"def",
"Pareto",
"(",
"q",
",",
"a",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"q",
">",
"0",
"and",
"a",
">",
"0",
",",
"'Pareto \"q\" and \"a\" must be positive scalars'",
"p",
"=",
"Uniform",
"(",
"0",
",",
"1",
",",
"tag",
")",
"return",
"a",
"*",
"(",
"1",
"-",
"p",
")",
"**",
"(",
"-",
"1.0",
"/",
"q",
")"
] |
A Pareto random variate (first kind)
Parameters
----------
q : scalar
The scale parameter
a : scalar
The shape parameter (the minimum possible value)
|
[
"A",
"Pareto",
"random",
"variate",
"(",
"first",
"kind",
")",
"Parameters",
"----------",
"q",
":",
"scalar",
"The",
"scale",
"parameter",
"a",
":",
"scalar",
"The",
"shape",
"parameter",
"(",
"the",
"minimum",
"possible",
"value",
")"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L983-L996
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Pareto2
|
def Pareto2(q, b, tag=None):
"""
A Pareto random variate (second kind). This form always starts at the
origin.
Parameters
----------
q : scalar
The scale parameter
b : scalar
The shape parameter
"""
assert q > 0 and b > 0, 'Pareto2 "q" and "b" must be positive scalars'
return Pareto(q, b, tag) - b
|
python
|
def Pareto2(q, b, tag=None):
"""
A Pareto random variate (second kind). This form always starts at the
origin.
Parameters
----------
q : scalar
The scale parameter
b : scalar
The shape parameter
"""
assert q > 0 and b > 0, 'Pareto2 "q" and "b" must be positive scalars'
return Pareto(q, b, tag) - b
|
[
"def",
"Pareto2",
"(",
"q",
",",
"b",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"q",
">",
"0",
"and",
"b",
">",
"0",
",",
"'Pareto2 \"q\" and \"b\" must be positive scalars'",
"return",
"Pareto",
"(",
"q",
",",
"b",
",",
"tag",
")",
"-",
"b"
] |
A Pareto random variate (second kind). This form always starts at the
origin.
Parameters
----------
q : scalar
The scale parameter
b : scalar
The shape parameter
|
[
"A",
"Pareto",
"random",
"variate",
"(",
"second",
"kind",
")",
".",
"This",
"form",
"always",
"starts",
"at",
"the",
"origin",
".",
"Parameters",
"----------",
"q",
":",
"scalar",
"The",
"scale",
"parameter",
"b",
":",
"scalar",
"The",
"shape",
"parameter"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L999-L1012
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
PERT
|
def PERT(low, peak, high, g=4.0, tag=None):
"""
A PERT random variate
Parameters
----------
low : scalar
Lower bound of the distribution support
peak : scalar
The location of the distribution's peak (low <= peak <= high)
high : scalar
Upper bound of the distribution support
Optional
--------
g : scalar
Controls the uncertainty of the distribution around the peak. Smaller
values make the distribution flatter and more uncertain around the
peak while larger values make it focused and less uncertain around
the peak. (Default: 4)
"""
a, b, c = [float(x) for x in [low, peak, high]]
assert a <= b <= c, 'PERT "peak" must be greater than "low" and less than "high"'
assert g >= 0, 'PERT "g" must be non-negative'
mu = (a + g * b + c) / (g + 2)
if mu == b:
a1 = a2 = 3.0
else:
a1 = ((mu - a) * (2 * b - a - c)) / ((b - mu) * (c - a))
a2 = a1 * (c - mu) / (mu - a)
return Beta(a1, a2, a, c, tag)
|
python
|
def PERT(low, peak, high, g=4.0, tag=None):
"""
A PERT random variate
Parameters
----------
low : scalar
Lower bound of the distribution support
peak : scalar
The location of the distribution's peak (low <= peak <= high)
high : scalar
Upper bound of the distribution support
Optional
--------
g : scalar
Controls the uncertainty of the distribution around the peak. Smaller
values make the distribution flatter and more uncertain around the
peak while larger values make it focused and less uncertain around
the peak. (Default: 4)
"""
a, b, c = [float(x) for x in [low, peak, high]]
assert a <= b <= c, 'PERT "peak" must be greater than "low" and less than "high"'
assert g >= 0, 'PERT "g" must be non-negative'
mu = (a + g * b + c) / (g + 2)
if mu == b:
a1 = a2 = 3.0
else:
a1 = ((mu - a) * (2 * b - a - c)) / ((b - mu) * (c - a))
a2 = a1 * (c - mu) / (mu - a)
return Beta(a1, a2, a, c, tag)
|
[
"def",
"PERT",
"(",
"low",
",",
"peak",
",",
"high",
",",
"g",
"=",
"4.0",
",",
"tag",
"=",
"None",
")",
":",
"a",
",",
"b",
",",
"c",
"=",
"[",
"float",
"(",
"x",
")",
"for",
"x",
"in",
"[",
"low",
",",
"peak",
",",
"high",
"]",
"]",
"assert",
"a",
"<=",
"b",
"<=",
"c",
",",
"'PERT \"peak\" must be greater than \"low\" and less than \"high\"'",
"assert",
"g",
">=",
"0",
",",
"'PERT \"g\" must be non-negative'",
"mu",
"=",
"(",
"a",
"+",
"g",
"*",
"b",
"+",
"c",
")",
"/",
"(",
"g",
"+",
"2",
")",
"if",
"mu",
"==",
"b",
":",
"a1",
"=",
"a2",
"=",
"3.0",
"else",
":",
"a1",
"=",
"(",
"(",
"mu",
"-",
"a",
")",
"*",
"(",
"2",
"*",
"b",
"-",
"a",
"-",
"c",
")",
")",
"/",
"(",
"(",
"b",
"-",
"mu",
")",
"*",
"(",
"c",
"-",
"a",
")",
")",
"a2",
"=",
"a1",
"*",
"(",
"c",
"-",
"mu",
")",
"/",
"(",
"mu",
"-",
"a",
")",
"return",
"Beta",
"(",
"a1",
",",
"a2",
",",
"a",
",",
"c",
",",
"tag",
")"
] |
A PERT random variate
Parameters
----------
low : scalar
Lower bound of the distribution support
peak : scalar
The location of the distribution's peak (low <= peak <= high)
high : scalar
Upper bound of the distribution support
Optional
--------
g : scalar
Controls the uncertainty of the distribution around the peak. Smaller
values make the distribution flatter and more uncertain around the
peak while larger values make it focused and less uncertain around
the peak. (Default: 4)
|
[
"A",
"PERT",
"random",
"variate",
"Parameters",
"----------",
"low",
":",
"scalar",
"Lower",
"bound",
"of",
"the",
"distribution",
"support",
"peak",
":",
"scalar",
"The",
"location",
"of",
"the",
"distribution",
"s",
"peak",
"(",
"low",
"<",
"=",
"peak",
"<",
"=",
"high",
")",
"high",
":",
"scalar",
"Upper",
"bound",
"of",
"the",
"distribution",
"support",
"Optional",
"--------",
"g",
":",
"scalar",
"Controls",
"the",
"uncertainty",
"of",
"the",
"distribution",
"around",
"the",
"peak",
".",
"Smaller",
"values",
"make",
"the",
"distribution",
"flatter",
"and",
"more",
"uncertain",
"around",
"the",
"peak",
"while",
"larger",
"values",
"make",
"it",
"focused",
"and",
"less",
"uncertain",
"around",
"the",
"peak",
".",
"(",
"Default",
":",
"4",
")"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L1015-L1046
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
StudentT
|
def StudentT(v, tag=None):
"""
A Student-T random variate
Parameters
----------
v : int
The degrees of freedom of the distribution (must be greater than one)
"""
assert int(v) == v and v >= 1, 'Student-T "v" must be an integer greater than 0'
return uv(ss.t(v), tag=tag)
|
python
|
def StudentT(v, tag=None):
"""
A Student-T random variate
Parameters
----------
v : int
The degrees of freedom of the distribution (must be greater than one)
"""
assert int(v) == v and v >= 1, 'Student-T "v" must be an integer greater than 0'
return uv(ss.t(v), tag=tag)
|
[
"def",
"StudentT",
"(",
"v",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"int",
"(",
"v",
")",
"==",
"v",
"and",
"v",
">=",
"1",
",",
"'Student-T \"v\" must be an integer greater than 0'",
"return",
"uv",
"(",
"ss",
".",
"t",
"(",
"v",
")",
",",
"tag",
"=",
"tag",
")"
] |
A Student-T random variate
Parameters
----------
v : int
The degrees of freedom of the distribution (must be greater than one)
|
[
"A",
"Student",
"-",
"T",
"random",
"variate",
"Parameters",
"----------",
"v",
":",
"int",
"The",
"degrees",
"of",
"freedom",
"of",
"the",
"distribution",
"(",
"must",
"be",
"greater",
"than",
"one",
")"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L1049-L1059
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Triangular
|
def Triangular(low, peak, high, tag=None):
"""
A triangular random variate
Parameters
----------
low : scalar
Lower bound of the distribution support
peak : scalar
The location of the triangle's peak (low <= peak <= high)
high : scalar
Upper bound of the distribution support
"""
assert low <= peak <= high, 'Triangular "peak" must lie between "low" and "high"'
low, peak, high = [float(x) for x in [low, peak, high]]
return uv(
ss.triang((1.0 * peak - low) / (high - low), loc=low, scale=(high - low)),
tag=tag,
)
|
python
|
def Triangular(low, peak, high, tag=None):
"""
A triangular random variate
Parameters
----------
low : scalar
Lower bound of the distribution support
peak : scalar
The location of the triangle's peak (low <= peak <= high)
high : scalar
Upper bound of the distribution support
"""
assert low <= peak <= high, 'Triangular "peak" must lie between "low" and "high"'
low, peak, high = [float(x) for x in [low, peak, high]]
return uv(
ss.triang((1.0 * peak - low) / (high - low), loc=low, scale=(high - low)),
tag=tag,
)
|
[
"def",
"Triangular",
"(",
"low",
",",
"peak",
",",
"high",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"low",
"<=",
"peak",
"<=",
"high",
",",
"'Triangular \"peak\" must lie between \"low\" and \"high\"'",
"low",
",",
"peak",
",",
"high",
"=",
"[",
"float",
"(",
"x",
")",
"for",
"x",
"in",
"[",
"low",
",",
"peak",
",",
"high",
"]",
"]",
"return",
"uv",
"(",
"ss",
".",
"triang",
"(",
"(",
"1.0",
"*",
"peak",
"-",
"low",
")",
"/",
"(",
"high",
"-",
"low",
")",
",",
"loc",
"=",
"low",
",",
"scale",
"=",
"(",
"high",
"-",
"low",
")",
")",
",",
"tag",
"=",
"tag",
",",
")"
] |
A triangular random variate
Parameters
----------
low : scalar
Lower bound of the distribution support
peak : scalar
The location of the triangle's peak (low <= peak <= high)
high : scalar
Upper bound of the distribution support
|
[
"A",
"triangular",
"random",
"variate",
"Parameters",
"----------",
"low",
":",
"scalar",
"Lower",
"bound",
"of",
"the",
"distribution",
"support",
"peak",
":",
"scalar",
"The",
"location",
"of",
"the",
"triangle",
"s",
"peak",
"(",
"low",
"<",
"=",
"peak",
"<",
"=",
"high",
")",
"high",
":",
"scalar",
"Upper",
"bound",
"of",
"the",
"distribution",
"support"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L1065-L1083
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Uniform
|
def Uniform(low, high, tag=None):
"""
A Uniform random variate
Parameters
----------
low : scalar
Lower bound of the distribution support.
high : scalar
Upper bound of the distribution support.
"""
assert low < high, 'Uniform "low" must be less than "high"'
return uv(ss.uniform(loc=low, scale=high - low), tag=tag)
|
python
|
def Uniform(low, high, tag=None):
"""
A Uniform random variate
Parameters
----------
low : scalar
Lower bound of the distribution support.
high : scalar
Upper bound of the distribution support.
"""
assert low < high, 'Uniform "low" must be less than "high"'
return uv(ss.uniform(loc=low, scale=high - low), tag=tag)
|
[
"def",
"Uniform",
"(",
"low",
",",
"high",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"low",
"<",
"high",
",",
"'Uniform \"low\" must be less than \"high\"'",
"return",
"uv",
"(",
"ss",
".",
"uniform",
"(",
"loc",
"=",
"low",
",",
"scale",
"=",
"high",
"-",
"low",
")",
",",
"tag",
"=",
"tag",
")"
] |
A Uniform random variate
Parameters
----------
low : scalar
Lower bound of the distribution support.
high : scalar
Upper bound of the distribution support.
|
[
"A",
"Uniform",
"random",
"variate",
"Parameters",
"----------",
"low",
":",
"scalar",
"Lower",
"bound",
"of",
"the",
"distribution",
"support",
".",
"high",
":",
"scalar",
"Upper",
"bound",
"of",
"the",
"distribution",
"support",
"."
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L1089-L1101
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Weibull
|
def Weibull(lamda, k, tag=None):
"""
A Weibull random variate
Parameters
----------
lamda : scalar
The scale parameter
k : scalar
The shape parameter
"""
assert (
lamda > 0 and k > 0
), 'Weibull "lamda" and "k" parameters must be greater than zero'
return uv(ss.exponweib(lamda, k), tag=tag)
|
python
|
def Weibull(lamda, k, tag=None):
"""
A Weibull random variate
Parameters
----------
lamda : scalar
The scale parameter
k : scalar
The shape parameter
"""
assert (
lamda > 0 and k > 0
), 'Weibull "lamda" and "k" parameters must be greater than zero'
return uv(ss.exponweib(lamda, k), tag=tag)
|
[
"def",
"Weibull",
"(",
"lamda",
",",
"k",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"(",
"lamda",
">",
"0",
"and",
"k",
">",
"0",
")",
",",
"'Weibull \"lamda\" and \"k\" parameters must be greater than zero'",
"return",
"uv",
"(",
"ss",
".",
"exponweib",
"(",
"lamda",
",",
"k",
")",
",",
"tag",
"=",
"tag",
")"
] |
A Weibull random variate
Parameters
----------
lamda : scalar
The scale parameter
k : scalar
The shape parameter
|
[
"A",
"Weibull",
"random",
"variate",
"Parameters",
"----------",
"lamda",
":",
"scalar",
"The",
"scale",
"parameter",
"k",
":",
"scalar",
"The",
"shape",
"parameter"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L1107-L1121
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Bernoulli
|
def Bernoulli(p, tag=None):
"""
A Bernoulli random variate
Parameters
----------
p : scalar
The probability of success
"""
assert (
0 < p < 1
), 'Bernoulli probability "p" must be between zero and one, non-inclusive'
return uv(ss.bernoulli(p), tag=tag)
|
python
|
def Bernoulli(p, tag=None):
"""
A Bernoulli random variate
Parameters
----------
p : scalar
The probability of success
"""
assert (
0 < p < 1
), 'Bernoulli probability "p" must be between zero and one, non-inclusive'
return uv(ss.bernoulli(p), tag=tag)
|
[
"def",
"Bernoulli",
"(",
"p",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"(",
"0",
"<",
"p",
"<",
"1",
")",
",",
"'Bernoulli probability \"p\" must be between zero and one, non-inclusive'",
"return",
"uv",
"(",
"ss",
".",
"bernoulli",
"(",
"p",
")",
",",
"tag",
"=",
"tag",
")"
] |
A Bernoulli random variate
Parameters
----------
p : scalar
The probability of success
|
[
"A",
"Bernoulli",
"random",
"variate",
"Parameters",
"----------",
"p",
":",
"scalar",
"The",
"probability",
"of",
"success"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L1132-L1144
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Binomial
|
def Binomial(n, p, tag=None):
"""
A Binomial random variate
Parameters
----------
n : int
The number of trials
p : scalar
The probability of success
"""
assert (
int(n) == n and n > 0
), 'Binomial number of trials "n" must be an integer greater than zero'
assert (
0 < p < 1
), 'Binomial probability "p" must be between zero and one, non-inclusive'
return uv(ss.binom(n, p), tag=tag)
|
python
|
def Binomial(n, p, tag=None):
"""
A Binomial random variate
Parameters
----------
n : int
The number of trials
p : scalar
The probability of success
"""
assert (
int(n) == n and n > 0
), 'Binomial number of trials "n" must be an integer greater than zero'
assert (
0 < p < 1
), 'Binomial probability "p" must be between zero and one, non-inclusive'
return uv(ss.binom(n, p), tag=tag)
|
[
"def",
"Binomial",
"(",
"n",
",",
"p",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"(",
"int",
"(",
"n",
")",
"==",
"n",
"and",
"n",
">",
"0",
")",
",",
"'Binomial number of trials \"n\" must be an integer greater than zero'",
"assert",
"(",
"0",
"<",
"p",
"<",
"1",
")",
",",
"'Binomial probability \"p\" must be between zero and one, non-inclusive'",
"return",
"uv",
"(",
"ss",
".",
"binom",
"(",
"n",
",",
"p",
")",
",",
"tag",
"=",
"tag",
")"
] |
A Binomial random variate
Parameters
----------
n : int
The number of trials
p : scalar
The probability of success
|
[
"A",
"Binomial",
"random",
"variate",
"Parameters",
"----------",
"n",
":",
"int",
"The",
"number",
"of",
"trials",
"p",
":",
"scalar",
"The",
"probability",
"of",
"success"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L1150-L1167
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Geometric
|
def Geometric(p, tag=None):
"""
A Geometric random variate
Parameters
----------
p : scalar
The probability of success
"""
assert (
0 < p < 1
), 'Geometric probability "p" must be between zero and one, non-inclusive'
return uv(ss.geom(p), tag=tag)
|
python
|
def Geometric(p, tag=None):
"""
A Geometric random variate
Parameters
----------
p : scalar
The probability of success
"""
assert (
0 < p < 1
), 'Geometric probability "p" must be between zero and one, non-inclusive'
return uv(ss.geom(p), tag=tag)
|
[
"def",
"Geometric",
"(",
"p",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"(",
"0",
"<",
"p",
"<",
"1",
")",
",",
"'Geometric probability \"p\" must be between zero and one, non-inclusive'",
"return",
"uv",
"(",
"ss",
".",
"geom",
"(",
"p",
")",
",",
"tag",
"=",
"tag",
")"
] |
A Geometric random variate
Parameters
----------
p : scalar
The probability of success
|
[
"A",
"Geometric",
"random",
"variate",
"Parameters",
"----------",
"p",
":",
"scalar",
"The",
"probability",
"of",
"success"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L1173-L1185
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Hypergeometric
|
def Hypergeometric(N, n, K, tag=None):
"""
A Hypergeometric random variate
Parameters
----------
N : int
The total population size
n : int
The number of individuals of interest in the population
K : int
The number of individuals that will be chosen from the population
Example
-------
(Taken from the wikipedia page) Assume we have an urn with two types of
marbles, 45 black ones and 5 white ones. Standing next to the urn, you
close your eyes and draw 10 marbles without replacement. What is the
probability that exactly 4 of the 10 are white?
::
>>> black = 45
>>> white = 5
>>> draw = 10
# Now we create the distribution
>>> h = H(black + white, white, draw)
# To check the probability, in this case, we can use the underlying
# scipy.stats object
>>> h.rv.pmf(4) # What is the probability that white count = 4?
0.0039645830580151975
"""
assert (
int(N) == N and N > 0
), 'Hypergeometric total population size "N" must be an integer greater than zero.'
assert (
int(n) == n and 0 < n <= N
), 'Hypergeometric interest population size "n" must be an integer greater than zero and no more than the total population size.'
assert (
int(K) == K and 0 < K <= N
), 'Hypergeometric chosen population size "K" must be an integer greater than zero and no more than the total population size.'
return uv(ss.hypergeom(N, n, K), tag=tag)
|
python
|
def Hypergeometric(N, n, K, tag=None):
"""
A Hypergeometric random variate
Parameters
----------
N : int
The total population size
n : int
The number of individuals of interest in the population
K : int
The number of individuals that will be chosen from the population
Example
-------
(Taken from the wikipedia page) Assume we have an urn with two types of
marbles, 45 black ones and 5 white ones. Standing next to the urn, you
close your eyes and draw 10 marbles without replacement. What is the
probability that exactly 4 of the 10 are white?
::
>>> black = 45
>>> white = 5
>>> draw = 10
# Now we create the distribution
>>> h = H(black + white, white, draw)
# To check the probability, in this case, we can use the underlying
# scipy.stats object
>>> h.rv.pmf(4) # What is the probability that white count = 4?
0.0039645830580151975
"""
assert (
int(N) == N and N > 0
), 'Hypergeometric total population size "N" must be an integer greater than zero.'
assert (
int(n) == n and 0 < n <= N
), 'Hypergeometric interest population size "n" must be an integer greater than zero and no more than the total population size.'
assert (
int(K) == K and 0 < K <= N
), 'Hypergeometric chosen population size "K" must be an integer greater than zero and no more than the total population size.'
return uv(ss.hypergeom(N, n, K), tag=tag)
|
[
"def",
"Hypergeometric",
"(",
"N",
",",
"n",
",",
"K",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"(",
"int",
"(",
"N",
")",
"==",
"N",
"and",
"N",
">",
"0",
")",
",",
"'Hypergeometric total population size \"N\" must be an integer greater than zero.'",
"assert",
"(",
"int",
"(",
"n",
")",
"==",
"n",
"and",
"0",
"<",
"n",
"<=",
"N",
")",
",",
"'Hypergeometric interest population size \"n\" must be an integer greater than zero and no more than the total population size.'",
"assert",
"(",
"int",
"(",
"K",
")",
"==",
"K",
"and",
"0",
"<",
"K",
"<=",
"N",
")",
",",
"'Hypergeometric chosen population size \"K\" must be an integer greater than zero and no more than the total population size.'",
"return",
"uv",
"(",
"ss",
".",
"hypergeom",
"(",
"N",
",",
"n",
",",
"K",
")",
",",
"tag",
"=",
"tag",
")"
] |
A Hypergeometric random variate
Parameters
----------
N : int
The total population size
n : int
The number of individuals of interest in the population
K : int
The number of individuals that will be chosen from the population
Example
-------
(Taken from the wikipedia page) Assume we have an urn with two types of
marbles, 45 black ones and 5 white ones. Standing next to the urn, you
close your eyes and draw 10 marbles without replacement. What is the
probability that exactly 4 of the 10 are white?
::
>>> black = 45
>>> white = 5
>>> draw = 10
# Now we create the distribution
>>> h = H(black + white, white, draw)
# To check the probability, in this case, we can use the underlying
# scipy.stats object
>>> h.rv.pmf(4) # What is the probability that white count = 4?
0.0039645830580151975
|
[
"A",
"Hypergeometric",
"random",
"variate",
"Parameters",
"----------",
"N",
":",
"int",
"The",
"total",
"population",
"size",
"n",
":",
"int",
"The",
"number",
"of",
"individuals",
"of",
"interest",
"in",
"the",
"population",
"K",
":",
"int",
"The",
"number",
"of",
"individuals",
"that",
"will",
"be",
"chosen",
"from",
"the",
"population",
"Example",
"-------",
"(",
"Taken",
"from",
"the",
"wikipedia",
"page",
")",
"Assume",
"we",
"have",
"an",
"urn",
"with",
"two",
"types",
"of",
"marbles",
"45",
"black",
"ones",
"and",
"5",
"white",
"ones",
".",
"Standing",
"next",
"to",
"the",
"urn",
"you",
"close",
"your",
"eyes",
"and",
"draw",
"10",
"marbles",
"without",
"replacement",
".",
"What",
"is",
"the",
"probability",
"that",
"exactly",
"4",
"of",
"the",
"10",
"are",
"white?",
"::",
">>>",
"black",
"=",
"45",
">>>",
"white",
"=",
"5",
">>>",
"draw",
"=",
"10",
"#",
"Now",
"we",
"create",
"the",
"distribution",
">>>",
"h",
"=",
"H",
"(",
"black",
"+",
"white",
"white",
"draw",
")",
"#",
"To",
"check",
"the",
"probability",
"in",
"this",
"case",
"we",
"can",
"use",
"the",
"underlying",
"#",
"scipy",
".",
"stats",
"object",
">>>",
"h",
".",
"rv",
".",
"pmf",
"(",
"4",
")",
"#",
"What",
"is",
"the",
"probability",
"that",
"white",
"count",
"=",
"4?",
"0",
".",
"0039645830580151975"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L1191-L1234
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
Poisson
|
def Poisson(lamda, tag=None):
"""
A Poisson random variate
Parameters
----------
lamda : scalar
The rate of an occurance within a specified interval of time or space.
"""
assert lamda > 0, 'Poisson "lamda" must be greater than zero.'
return uv(ss.poisson(lamda), tag=tag)
|
python
|
def Poisson(lamda, tag=None):
"""
A Poisson random variate
Parameters
----------
lamda : scalar
The rate of an occurance within a specified interval of time or space.
"""
assert lamda > 0, 'Poisson "lamda" must be greater than zero.'
return uv(ss.poisson(lamda), tag=tag)
|
[
"def",
"Poisson",
"(",
"lamda",
",",
"tag",
"=",
"None",
")",
":",
"assert",
"lamda",
">",
"0",
",",
"'Poisson \"lamda\" must be greater than zero.'",
"return",
"uv",
"(",
"ss",
".",
"poisson",
"(",
"lamda",
")",
",",
"tag",
"=",
"tag",
")"
] |
A Poisson random variate
Parameters
----------
lamda : scalar
The rate of an occurance within a specified interval of time or space.
|
[
"A",
"Poisson",
"random",
"variate",
"Parameters",
"----------",
"lamda",
":",
"scalar",
"The",
"rate",
"of",
"an",
"occurance",
"within",
"a",
"specified",
"interval",
"of",
"time",
"or",
"space",
"."
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L1240-L1250
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
covariance_matrix
|
def covariance_matrix(nums_with_uncert):
"""
Calculate the covariance matrix of uncertain variables, oriented by the
order of the inputs
Parameters
----------
nums_with_uncert : array-like
A list of variables that have an associated uncertainty
Returns
-------
cov_matrix : 2d-array-like
A nested list containing covariance values
Example
-------
>>> x = N(1, 0.1)
>>> y = N(10, 0.1)
>>> z = x + 2*y
>>> covariance_matrix([x,y,z])
[[ 9.99694861e-03 2.54000840e-05 1.00477488e-02]
[ 2.54000840e-05 9.99823207e-03 2.00218642e-02]
[ 1.00477488e-02 2.00218642e-02 5.00914772e-02]]
"""
ufuncs = list(map(to_uncertain_func, nums_with_uncert))
cov_matrix = []
for (i1, expr1) in enumerate(ufuncs):
coefs_expr1 = []
mean1 = expr1.mean
for (i2, expr2) in enumerate(ufuncs[: i1 + 1]):
mean2 = expr2.mean
coef = np.mean((expr1._mcpts - mean1) * (expr2._mcpts - mean2))
coefs_expr1.append(coef)
cov_matrix.append(coefs_expr1)
# We symmetrize the matrix:
for (i, covariance_coefs) in enumerate(cov_matrix):
covariance_coefs.extend(cov_matrix[j][i] for j in range(i + 1, len(cov_matrix)))
return cov_matrix
|
python
|
def covariance_matrix(nums_with_uncert):
"""
Calculate the covariance matrix of uncertain variables, oriented by the
order of the inputs
Parameters
----------
nums_with_uncert : array-like
A list of variables that have an associated uncertainty
Returns
-------
cov_matrix : 2d-array-like
A nested list containing covariance values
Example
-------
>>> x = N(1, 0.1)
>>> y = N(10, 0.1)
>>> z = x + 2*y
>>> covariance_matrix([x,y,z])
[[ 9.99694861e-03 2.54000840e-05 1.00477488e-02]
[ 2.54000840e-05 9.99823207e-03 2.00218642e-02]
[ 1.00477488e-02 2.00218642e-02 5.00914772e-02]]
"""
ufuncs = list(map(to_uncertain_func, nums_with_uncert))
cov_matrix = []
for (i1, expr1) in enumerate(ufuncs):
coefs_expr1 = []
mean1 = expr1.mean
for (i2, expr2) in enumerate(ufuncs[: i1 + 1]):
mean2 = expr2.mean
coef = np.mean((expr1._mcpts - mean1) * (expr2._mcpts - mean2))
coefs_expr1.append(coef)
cov_matrix.append(coefs_expr1)
# We symmetrize the matrix:
for (i, covariance_coefs) in enumerate(cov_matrix):
covariance_coefs.extend(cov_matrix[j][i] for j in range(i + 1, len(cov_matrix)))
return cov_matrix
|
[
"def",
"covariance_matrix",
"(",
"nums_with_uncert",
")",
":",
"ufuncs",
"=",
"list",
"(",
"map",
"(",
"to_uncertain_func",
",",
"nums_with_uncert",
")",
")",
"cov_matrix",
"=",
"[",
"]",
"for",
"(",
"i1",
",",
"expr1",
")",
"in",
"enumerate",
"(",
"ufuncs",
")",
":",
"coefs_expr1",
"=",
"[",
"]",
"mean1",
"=",
"expr1",
".",
"mean",
"for",
"(",
"i2",
",",
"expr2",
")",
"in",
"enumerate",
"(",
"ufuncs",
"[",
":",
"i1",
"+",
"1",
"]",
")",
":",
"mean2",
"=",
"expr2",
".",
"mean",
"coef",
"=",
"np",
".",
"mean",
"(",
"(",
"expr1",
".",
"_mcpts",
"-",
"mean1",
")",
"*",
"(",
"expr2",
".",
"_mcpts",
"-",
"mean2",
")",
")",
"coefs_expr1",
".",
"append",
"(",
"coef",
")",
"cov_matrix",
".",
"append",
"(",
"coefs_expr1",
")",
"# We symmetrize the matrix:",
"for",
"(",
"i",
",",
"covariance_coefs",
")",
"in",
"enumerate",
"(",
"cov_matrix",
")",
":",
"covariance_coefs",
".",
"extend",
"(",
"cov_matrix",
"[",
"j",
"]",
"[",
"i",
"]",
"for",
"j",
"in",
"range",
"(",
"i",
"+",
"1",
",",
"len",
"(",
"cov_matrix",
")",
")",
")",
"return",
"cov_matrix"
] |
Calculate the covariance matrix of uncertain variables, oriented by the
order of the inputs
Parameters
----------
nums_with_uncert : array-like
A list of variables that have an associated uncertainty
Returns
-------
cov_matrix : 2d-array-like
A nested list containing covariance values
Example
-------
>>> x = N(1, 0.1)
>>> y = N(10, 0.1)
>>> z = x + 2*y
>>> covariance_matrix([x,y,z])
[[ 9.99694861e-03 2.54000840e-05 1.00477488e-02]
[ 2.54000840e-05 9.99823207e-03 2.00218642e-02]
[ 1.00477488e-02 2.00218642e-02 5.00914772e-02]]
|
[
"Calculate",
"the",
"covariance",
"matrix",
"of",
"uncertain",
"variables",
"oriented",
"by",
"the",
"order",
"of",
"the",
"inputs",
"Parameters",
"----------",
"nums_with_uncert",
":",
"array",
"-",
"like",
"A",
"list",
"of",
"variables",
"that",
"have",
"an",
"associated",
"uncertainty",
"Returns",
"-------",
"cov_matrix",
":",
"2d",
"-",
"array",
"-",
"like",
"A",
"nested",
"list",
"containing",
"covariance",
"values",
"Example",
"-------",
">>>",
"x",
"=",
"N",
"(",
"1",
"0",
".",
"1",
")",
">>>",
"y",
"=",
"N",
"(",
"10",
"0",
".",
"1",
")",
">>>",
"z",
"=",
"x",
"+",
"2",
"*",
"y",
">>>",
"covariance_matrix",
"(",
"[",
"x",
"y",
"z",
"]",
")",
"[[",
"9",
".",
"99694861e",
"-",
"03",
"2",
".",
"54000840e",
"-",
"05",
"1",
".",
"00477488e",
"-",
"02",
"]",
"[",
"2",
".",
"54000840e",
"-",
"05",
"9",
".",
"99823207e",
"-",
"03",
"2",
".",
"00218642e",
"-",
"02",
"]",
"[",
"1",
".",
"00477488e",
"-",
"02",
"2",
".",
"00218642e",
"-",
"02",
"5",
".",
"00914772e",
"-",
"02",
"]]"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L1261-L1303
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
correlation_matrix
|
def correlation_matrix(nums_with_uncert):
"""
Calculate the correlation matrix of uncertain variables, oriented by the
order of the inputs
Parameters
----------
nums_with_uncert : array-like
A list of variables that have an associated uncertainty
Returns
-------
corr_matrix : 2d-array-like
A nested list containing covariance values
Example
-------
>>> x = N(1, 0.1)
>>> y = N(10, 0.1)
>>> z = x + 2*y
>>> correlation_matrix([x,y,z])
[[ 0.99969486 0.00254001 0.4489385 ]
[ 0.00254001 0.99982321 0.89458702]
[ 0.4489385 0.89458702 1. ]]
"""
ufuncs = list(map(to_uncertain_func, nums_with_uncert))
data = np.vstack([ufunc._mcpts for ufunc in ufuncs])
return np.corrcoef(data.T, rowvar=0)
|
python
|
def correlation_matrix(nums_with_uncert):
"""
Calculate the correlation matrix of uncertain variables, oriented by the
order of the inputs
Parameters
----------
nums_with_uncert : array-like
A list of variables that have an associated uncertainty
Returns
-------
corr_matrix : 2d-array-like
A nested list containing covariance values
Example
-------
>>> x = N(1, 0.1)
>>> y = N(10, 0.1)
>>> z = x + 2*y
>>> correlation_matrix([x,y,z])
[[ 0.99969486 0.00254001 0.4489385 ]
[ 0.00254001 0.99982321 0.89458702]
[ 0.4489385 0.89458702 1. ]]
"""
ufuncs = list(map(to_uncertain_func, nums_with_uncert))
data = np.vstack([ufunc._mcpts for ufunc in ufuncs])
return np.corrcoef(data.T, rowvar=0)
|
[
"def",
"correlation_matrix",
"(",
"nums_with_uncert",
")",
":",
"ufuncs",
"=",
"list",
"(",
"map",
"(",
"to_uncertain_func",
",",
"nums_with_uncert",
")",
")",
"data",
"=",
"np",
".",
"vstack",
"(",
"[",
"ufunc",
".",
"_mcpts",
"for",
"ufunc",
"in",
"ufuncs",
"]",
")",
"return",
"np",
".",
"corrcoef",
"(",
"data",
".",
"T",
",",
"rowvar",
"=",
"0",
")"
] |
Calculate the correlation matrix of uncertain variables, oriented by the
order of the inputs
Parameters
----------
nums_with_uncert : array-like
A list of variables that have an associated uncertainty
Returns
-------
corr_matrix : 2d-array-like
A nested list containing covariance values
Example
-------
>>> x = N(1, 0.1)
>>> y = N(10, 0.1)
>>> z = x + 2*y
>>> correlation_matrix([x,y,z])
[[ 0.99969486 0.00254001 0.4489385 ]
[ 0.00254001 0.99982321 0.89458702]
[ 0.4489385 0.89458702 1. ]]
|
[
"Calculate",
"the",
"correlation",
"matrix",
"of",
"uncertain",
"variables",
"oriented",
"by",
"the",
"order",
"of",
"the",
"inputs",
"Parameters",
"----------",
"nums_with_uncert",
":",
"array",
"-",
"like",
"A",
"list",
"of",
"variables",
"that",
"have",
"an",
"associated",
"uncertainty",
"Returns",
"-------",
"corr_matrix",
":",
"2d",
"-",
"array",
"-",
"like",
"A",
"nested",
"list",
"containing",
"covariance",
"values",
"Example",
"-------",
">>>",
"x",
"=",
"N",
"(",
"1",
"0",
".",
"1",
")",
">>>",
"y",
"=",
"N",
"(",
"10",
"0",
".",
"1",
")",
">>>",
"z",
"=",
"x",
"+",
"2",
"*",
"y",
">>>",
"correlation_matrix",
"(",
"[",
"x",
"y",
"z",
"]",
")",
"[[",
"0",
".",
"99969486",
"0",
".",
"00254001",
"0",
".",
"4489385",
"]",
"[",
"0",
".",
"00254001",
"0",
".",
"99982321",
"0",
".",
"89458702",
"]",
"[",
"0",
".",
"4489385",
"0",
".",
"89458702",
"1",
".",
"]]"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L1306-L1335
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
UncertainFunction.var
|
def var(self):
"""
Variance value as a result of an uncertainty calculation
"""
mn = self.mean
vr = np.mean((self._mcpts - mn) ** 2)
return vr
|
python
|
def var(self):
"""
Variance value as a result of an uncertainty calculation
"""
mn = self.mean
vr = np.mean((self._mcpts - mn) ** 2)
return vr
|
[
"def",
"var",
"(",
"self",
")",
":",
"mn",
"=",
"self",
".",
"mean",
"vr",
"=",
"np",
".",
"mean",
"(",
"(",
"self",
".",
"_mcpts",
"-",
"mn",
")",
"**",
"2",
")",
"return",
"vr"
] |
Variance value as a result of an uncertainty calculation
|
[
"Variance",
"value",
"as",
"a",
"result",
"of",
"an",
"uncertainty",
"calculation"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L74-L80
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
UncertainFunction.skew
|
def skew(self):
r"""
Skewness coefficient value as a result of an uncertainty calculation,
defined as::
_____ m3
\/beta1 = ------
std**3
where m3 is the third central moment and std is the standard deviation
"""
mn = self.mean
sd = self.std
sk = 0.0 if abs(sd) <= 1e-8 else np.mean((self._mcpts - mn) ** 3) / sd ** 3
return sk
|
python
|
def skew(self):
r"""
Skewness coefficient value as a result of an uncertainty calculation,
defined as::
_____ m3
\/beta1 = ------
std**3
where m3 is the third central moment and std is the standard deviation
"""
mn = self.mean
sd = self.std
sk = 0.0 if abs(sd) <= 1e-8 else np.mean((self._mcpts - mn) ** 3) / sd ** 3
return sk
|
[
"def",
"skew",
"(",
"self",
")",
":",
"mn",
"=",
"self",
".",
"mean",
"sd",
"=",
"self",
".",
"std",
"sk",
"=",
"0.0",
"if",
"abs",
"(",
"sd",
")",
"<=",
"1e-8",
"else",
"np",
".",
"mean",
"(",
"(",
"self",
".",
"_mcpts",
"-",
"mn",
")",
"**",
"3",
")",
"/",
"sd",
"**",
"3",
"return",
"sk"
] |
r"""
Skewness coefficient value as a result of an uncertainty calculation,
defined as::
_____ m3
\/beta1 = ------
std**3
where m3 is the third central moment and std is the standard deviation
|
[
"r",
"Skewness",
"coefficient",
"value",
"as",
"a",
"result",
"of",
"an",
"uncertainty",
"calculation",
"defined",
"as",
"::",
"_____",
"m3",
"\\",
"/",
"beta1",
"=",
"------",
"std",
"**",
"3",
"where",
"m3",
"is",
"the",
"third",
"central",
"moment",
"and",
"std",
"is",
"the",
"standard",
"deviation"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L95-L109
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
UncertainFunction.kurt
|
def kurt(self):
"""
Kurtosis coefficient value as a result of an uncertainty calculation,
defined as::
m4
beta2 = ------
std**4
where m4 is the fourth central moment and std is the standard deviation
"""
mn = self.mean
sd = self.std
kt = 0.0 if abs(sd) <= 1e-8 else np.mean((self._mcpts - mn) ** 4) / sd ** 4
return kt
|
python
|
def kurt(self):
"""
Kurtosis coefficient value as a result of an uncertainty calculation,
defined as::
m4
beta2 = ------
std**4
where m4 is the fourth central moment and std is the standard deviation
"""
mn = self.mean
sd = self.std
kt = 0.0 if abs(sd) <= 1e-8 else np.mean((self._mcpts - mn) ** 4) / sd ** 4
return kt
|
[
"def",
"kurt",
"(",
"self",
")",
":",
"mn",
"=",
"self",
".",
"mean",
"sd",
"=",
"self",
".",
"std",
"kt",
"=",
"0.0",
"if",
"abs",
"(",
"sd",
")",
"<=",
"1e-8",
"else",
"np",
".",
"mean",
"(",
"(",
"self",
".",
"_mcpts",
"-",
"mn",
")",
"**",
"4",
")",
"/",
"sd",
"**",
"4",
"return",
"kt"
] |
Kurtosis coefficient value as a result of an uncertainty calculation,
defined as::
m4
beta2 = ------
std**4
where m4 is the fourth central moment and std is the standard deviation
|
[
"Kurtosis",
"coefficient",
"value",
"as",
"a",
"result",
"of",
"an",
"uncertainty",
"calculation",
"defined",
"as",
"::",
"m4",
"beta2",
"=",
"------",
"std",
"**",
"4"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L112-L126
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
UncertainFunction.stats
|
def stats(self):
"""
The first four standard moments of a distribution: mean, variance, and
standardized skewness and kurtosis coefficients.
"""
mn = self.mean
vr = self.var
sk = self.skew
kt = self.kurt
return [mn, vr, sk, kt]
|
python
|
def stats(self):
"""
The first four standard moments of a distribution: mean, variance, and
standardized skewness and kurtosis coefficients.
"""
mn = self.mean
vr = self.var
sk = self.skew
kt = self.kurt
return [mn, vr, sk, kt]
|
[
"def",
"stats",
"(",
"self",
")",
":",
"mn",
"=",
"self",
".",
"mean",
"vr",
"=",
"self",
".",
"var",
"sk",
"=",
"self",
".",
"skew",
"kt",
"=",
"self",
".",
"kurt",
"return",
"[",
"mn",
",",
"vr",
",",
"sk",
",",
"kt",
"]"
] |
The first four standard moments of a distribution: mean, variance, and
standardized skewness and kurtosis coefficients.
|
[
"The",
"first",
"four",
"standard",
"moments",
"of",
"a",
"distribution",
":",
"mean",
"variance",
"and",
"standardized",
"skewness",
"and",
"kurtosis",
"coefficients",
"."
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L129-L138
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
UncertainFunction.percentile
|
def percentile(self, val):
"""
Get the distribution value at a given percentile or set of percentiles.
This follows the NIST method for calculating percentiles.
Parameters
----------
val : scalar or array
Either a single value or an array of values between 0 and 1.
Returns
-------
out : scalar or array
The actual distribution value that appears at the requested
percentile value or values
"""
try:
# test to see if an input is given as an array
out = [self.percentile(vi) for vi in val]
except (ValueError, TypeError):
if val <= 0:
out = float(min(self._mcpts))
elif val >= 1:
out = float(max(self._mcpts))
else:
tmp = np.sort(self._mcpts)
n = val * (len(tmp) + 1)
k, d = int(n), n - int(n)
out = float(tmp[k] + d * (tmp[k + 1] - tmp[k]))
if isinstance(val, np.ndarray):
out = np.array(out)
return out
|
python
|
def percentile(self, val):
"""
Get the distribution value at a given percentile or set of percentiles.
This follows the NIST method for calculating percentiles.
Parameters
----------
val : scalar or array
Either a single value or an array of values between 0 and 1.
Returns
-------
out : scalar or array
The actual distribution value that appears at the requested
percentile value or values
"""
try:
# test to see if an input is given as an array
out = [self.percentile(vi) for vi in val]
except (ValueError, TypeError):
if val <= 0:
out = float(min(self._mcpts))
elif val >= 1:
out = float(max(self._mcpts))
else:
tmp = np.sort(self._mcpts)
n = val * (len(tmp) + 1)
k, d = int(n), n - int(n)
out = float(tmp[k] + d * (tmp[k + 1] - tmp[k]))
if isinstance(val, np.ndarray):
out = np.array(out)
return out
|
[
"def",
"percentile",
"(",
"self",
",",
"val",
")",
":",
"try",
":",
"# test to see if an input is given as an array",
"out",
"=",
"[",
"self",
".",
"percentile",
"(",
"vi",
")",
"for",
"vi",
"in",
"val",
"]",
"except",
"(",
"ValueError",
",",
"TypeError",
")",
":",
"if",
"val",
"<=",
"0",
":",
"out",
"=",
"float",
"(",
"min",
"(",
"self",
".",
"_mcpts",
")",
")",
"elif",
"val",
">=",
"1",
":",
"out",
"=",
"float",
"(",
"max",
"(",
"self",
".",
"_mcpts",
")",
")",
"else",
":",
"tmp",
"=",
"np",
".",
"sort",
"(",
"self",
".",
"_mcpts",
")",
"n",
"=",
"val",
"*",
"(",
"len",
"(",
"tmp",
")",
"+",
"1",
")",
"k",
",",
"d",
"=",
"int",
"(",
"n",
")",
",",
"n",
"-",
"int",
"(",
"n",
")",
"out",
"=",
"float",
"(",
"tmp",
"[",
"k",
"]",
"+",
"d",
"*",
"(",
"tmp",
"[",
"k",
"+",
"1",
"]",
"-",
"tmp",
"[",
"k",
"]",
")",
")",
"if",
"isinstance",
"(",
"val",
",",
"np",
".",
"ndarray",
")",
":",
"out",
"=",
"np",
".",
"array",
"(",
"out",
")",
"return",
"out"
] |
Get the distribution value at a given percentile or set of percentiles.
This follows the NIST method for calculating percentiles.
Parameters
----------
val : scalar or array
Either a single value or an array of values between 0 and 1.
Returns
-------
out : scalar or array
The actual distribution value that appears at the requested
percentile value or values
|
[
"Get",
"the",
"distribution",
"value",
"at",
"a",
"given",
"percentile",
"or",
"set",
"of",
"percentiles",
".",
"This",
"follows",
"the",
"NIST",
"method",
"for",
"calculating",
"percentiles",
".",
"Parameters",
"----------",
"val",
":",
"scalar",
"or",
"array",
"Either",
"a",
"single",
"value",
"or",
"an",
"array",
"of",
"values",
"between",
"0",
"and",
"1",
".",
"Returns",
"-------",
"out",
":",
"scalar",
"or",
"array",
"The",
"actual",
"distribution",
"value",
"that",
"appears",
"at",
"the",
"requested",
"percentile",
"value",
"or",
"values"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L140-L172
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
UncertainFunction.describe
|
def describe(self, name=None):
"""
Cleanly show what the four displayed distribution moments are:
- Mean
- Variance
- Standardized Skewness Coefficient
- Standardized Kurtosis Coefficient
For a standard Normal distribution, these are [0, 1, 0, 3].
If the object has an associated tag, this is presented. If the optional
``name`` kwarg is utilized, this is presented as with the moments.
Otherwise, no unique name is presented.
Example
=======
::
>>> x = N(0, 1, 'x')
>>> x.describe() # print tag since assigned
MCERP Uncertain Value (x):
...
>>> x.describe('foobar') # 'name' kwarg takes precedence
MCERP Uncertain Value (foobar):
...
>>> y = x**2
>>> y.describe('y') # print name since assigned
MCERP Uncertain Value (y):
...
>>> y.describe() # print nothing since no tag
MCERP Uncertain Value:
...
"""
mn, vr, sk, kt = self.stats
if name is not None:
s = "MCERP Uncertain Value (" + name + "):\n"
elif self.tag is not None:
s = "MCERP Uncertain Value (" + self.tag + "):\n"
else:
s = "MCERP Uncertain Value:\n"
s += " > Mean................... {: }\n".format(mn)
s += " > Variance............... {: }\n".format(vr)
s += " > Skewness Coefficient... {: }\n".format(sk)
s += " > Kurtosis Coefficient... {: }\n".format(kt)
print(s)
|
python
|
def describe(self, name=None):
"""
Cleanly show what the four displayed distribution moments are:
- Mean
- Variance
- Standardized Skewness Coefficient
- Standardized Kurtosis Coefficient
For a standard Normal distribution, these are [0, 1, 0, 3].
If the object has an associated tag, this is presented. If the optional
``name`` kwarg is utilized, this is presented as with the moments.
Otherwise, no unique name is presented.
Example
=======
::
>>> x = N(0, 1, 'x')
>>> x.describe() # print tag since assigned
MCERP Uncertain Value (x):
...
>>> x.describe('foobar') # 'name' kwarg takes precedence
MCERP Uncertain Value (foobar):
...
>>> y = x**2
>>> y.describe('y') # print name since assigned
MCERP Uncertain Value (y):
...
>>> y.describe() # print nothing since no tag
MCERP Uncertain Value:
...
"""
mn, vr, sk, kt = self.stats
if name is not None:
s = "MCERP Uncertain Value (" + name + "):\n"
elif self.tag is not None:
s = "MCERP Uncertain Value (" + self.tag + "):\n"
else:
s = "MCERP Uncertain Value:\n"
s += " > Mean................... {: }\n".format(mn)
s += " > Variance............... {: }\n".format(vr)
s += " > Skewness Coefficient... {: }\n".format(sk)
s += " > Kurtosis Coefficient... {: }\n".format(kt)
print(s)
|
[
"def",
"describe",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"mn",
",",
"vr",
",",
"sk",
",",
"kt",
"=",
"self",
".",
"stats",
"if",
"name",
"is",
"not",
"None",
":",
"s",
"=",
"\"MCERP Uncertain Value (\"",
"+",
"name",
"+",
"\"):\\n\"",
"elif",
"self",
".",
"tag",
"is",
"not",
"None",
":",
"s",
"=",
"\"MCERP Uncertain Value (\"",
"+",
"self",
".",
"tag",
"+",
"\"):\\n\"",
"else",
":",
"s",
"=",
"\"MCERP Uncertain Value:\\n\"",
"s",
"+=",
"\" > Mean................... {: }\\n\"",
".",
"format",
"(",
"mn",
")",
"s",
"+=",
"\" > Variance............... {: }\\n\"",
".",
"format",
"(",
"vr",
")",
"s",
"+=",
"\" > Skewness Coefficient... {: }\\n\"",
".",
"format",
"(",
"sk",
")",
"s",
"+=",
"\" > Kurtosis Coefficient... {: }\\n\"",
".",
"format",
"(",
"kt",
")",
"print",
"(",
"s",
")"
] |
Cleanly show what the four displayed distribution moments are:
- Mean
- Variance
- Standardized Skewness Coefficient
- Standardized Kurtosis Coefficient
For a standard Normal distribution, these are [0, 1, 0, 3].
If the object has an associated tag, this is presented. If the optional
``name`` kwarg is utilized, this is presented as with the moments.
Otherwise, no unique name is presented.
Example
=======
::
>>> x = N(0, 1, 'x')
>>> x.describe() # print tag since assigned
MCERP Uncertain Value (x):
...
>>> x.describe('foobar') # 'name' kwarg takes precedence
MCERP Uncertain Value (foobar):
...
>>> y = x**2
>>> y.describe('y') # print name since assigned
MCERP Uncertain Value (y):
...
>>> y.describe() # print nothing since no tag
MCERP Uncertain Value:
...
|
[
"Cleanly",
"show",
"what",
"the",
"four",
"displayed",
"distribution",
"moments",
"are",
":",
"-",
"Mean",
"-",
"Variance",
"-",
"Standardized",
"Skewness",
"Coefficient",
"-",
"Standardized",
"Kurtosis",
"Coefficient",
"For",
"a",
"standard",
"Normal",
"distribution",
"these",
"are",
"[",
"0",
"1",
"0",
"3",
"]",
".",
"If",
"the",
"object",
"has",
"an",
"associated",
"tag",
"this",
"is",
"presented",
".",
"If",
"the",
"optional",
"name",
"kwarg",
"is",
"utilized",
"this",
"is",
"presented",
"as",
"with",
"the",
"moments",
".",
"Otherwise",
"no",
"unique",
"name",
"is",
"presented",
".",
"Example",
"=======",
"::",
">>>",
"x",
"=",
"N",
"(",
"0",
"1",
"x",
")",
">>>",
"x",
".",
"describe",
"()",
"#",
"print",
"tag",
"since",
"assigned",
"MCERP",
"Uncertain",
"Value",
"(",
"x",
")",
":",
"..."
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L191-L239
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
UncertainFunction.plot
|
def plot(self, hist=False, show=False, **kwargs):
"""
Plot the distribution of the UncertainFunction. By default, the
distribution is shown with a kernel density estimate (kde).
Optional
--------
hist : bool
If true, a density histogram is displayed (histtype='stepfilled')
show : bool
If ``True``, the figure will be displayed after plotting the
distribution. If ``False``, an explicit call to ``plt.show()`` is
required to display the figure.
kwargs : any valid matplotlib.pyplot.plot or .hist kwarg
"""
import matplotlib.pyplot as plt
vals = self._mcpts
low = min(vals)
high = max(vals)
p = ss.kde.gaussian_kde(vals)
xp = np.linspace(low, high, 100)
if hist:
h = plt.hist(
vals,
bins=int(np.sqrt(len(vals)) + 0.5),
histtype="stepfilled",
normed=True,
**kwargs
)
plt.ylim(0, 1.1 * h[0].max())
else:
plt.plot(xp, p.evaluate(xp), **kwargs)
plt.xlim(low - (high - low) * 0.1, high + (high - low) * 0.1)
if show:
self.show()
|
python
|
def plot(self, hist=False, show=False, **kwargs):
"""
Plot the distribution of the UncertainFunction. By default, the
distribution is shown with a kernel density estimate (kde).
Optional
--------
hist : bool
If true, a density histogram is displayed (histtype='stepfilled')
show : bool
If ``True``, the figure will be displayed after plotting the
distribution. If ``False``, an explicit call to ``plt.show()`` is
required to display the figure.
kwargs : any valid matplotlib.pyplot.plot or .hist kwarg
"""
import matplotlib.pyplot as plt
vals = self._mcpts
low = min(vals)
high = max(vals)
p = ss.kde.gaussian_kde(vals)
xp = np.linspace(low, high, 100)
if hist:
h = plt.hist(
vals,
bins=int(np.sqrt(len(vals)) + 0.5),
histtype="stepfilled",
normed=True,
**kwargs
)
plt.ylim(0, 1.1 * h[0].max())
else:
plt.plot(xp, p.evaluate(xp), **kwargs)
plt.xlim(low - (high - low) * 0.1, high + (high - low) * 0.1)
if show:
self.show()
|
[
"def",
"plot",
"(",
"self",
",",
"hist",
"=",
"False",
",",
"show",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"import",
"matplotlib",
".",
"pyplot",
"as",
"plt",
"vals",
"=",
"self",
".",
"_mcpts",
"low",
"=",
"min",
"(",
"vals",
")",
"high",
"=",
"max",
"(",
"vals",
")",
"p",
"=",
"ss",
".",
"kde",
".",
"gaussian_kde",
"(",
"vals",
")",
"xp",
"=",
"np",
".",
"linspace",
"(",
"low",
",",
"high",
",",
"100",
")",
"if",
"hist",
":",
"h",
"=",
"plt",
".",
"hist",
"(",
"vals",
",",
"bins",
"=",
"int",
"(",
"np",
".",
"sqrt",
"(",
"len",
"(",
"vals",
")",
")",
"+",
"0.5",
")",
",",
"histtype",
"=",
"\"stepfilled\"",
",",
"normed",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
"plt",
".",
"ylim",
"(",
"0",
",",
"1.1",
"*",
"h",
"[",
"0",
"]",
".",
"max",
"(",
")",
")",
"else",
":",
"plt",
".",
"plot",
"(",
"xp",
",",
"p",
".",
"evaluate",
"(",
"xp",
")",
",",
"*",
"*",
"kwargs",
")",
"plt",
".",
"xlim",
"(",
"low",
"-",
"(",
"high",
"-",
"low",
")",
"*",
"0.1",
",",
"high",
"+",
"(",
"high",
"-",
"low",
")",
"*",
"0.1",
")",
"if",
"show",
":",
"self",
".",
"show",
"(",
")"
] |
Plot the distribution of the UncertainFunction. By default, the
distribution is shown with a kernel density estimate (kde).
Optional
--------
hist : bool
If true, a density histogram is displayed (histtype='stepfilled')
show : bool
If ``True``, the figure will be displayed after plotting the
distribution. If ``False``, an explicit call to ``plt.show()`` is
required to display the figure.
kwargs : any valid matplotlib.pyplot.plot or .hist kwarg
|
[
"Plot",
"the",
"distribution",
"of",
"the",
"UncertainFunction",
".",
"By",
"default",
"the",
"distribution",
"is",
"shown",
"with",
"a",
"kernel",
"density",
"estimate",
"(",
"kde",
")",
".",
"Optional",
"--------",
"hist",
":",
"bool",
"If",
"true",
"a",
"density",
"histogram",
"is",
"displayed",
"(",
"histtype",
"=",
"stepfilled",
")",
"show",
":",
"bool",
"If",
"True",
"the",
"figure",
"will",
"be",
"displayed",
"after",
"plotting",
"the",
"distribution",
".",
"If",
"False",
"an",
"explicit",
"call",
"to",
"plt",
".",
"show",
"()",
"is",
"required",
"to",
"display",
"the",
"figure",
".",
"kwargs",
":",
"any",
"valid",
"matplotlib",
".",
"pyplot",
".",
"plot",
"or",
".",
"hist",
"kwarg"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L241-L281
|
train
|
tisimst/mcerp
|
mcerp/__init__.py
|
UncertainVariable.plot
|
def plot(self, hist=False, show=False, **kwargs):
"""
Plot the distribution of the UncertainVariable. Continuous
distributions are plotted with a line plot and discrete distributions
are plotted with discrete circles.
Optional
--------
hist : bool
If true, a histogram is displayed
show : bool
If ``True``, the figure will be displayed after plotting the
distribution. If ``False``, an explicit call to ``plt.show()`` is
required to display the figure.
kwargs : any valid matplotlib.pyplot.plot kwarg
"""
import matplotlib.pyplot as plt
if hist:
vals = self._mcpts
low = vals.min()
high = vals.max()
h = plt.hist(
vals,
bins=int(np.sqrt(len(vals)) + 0.5),
histtype="stepfilled",
normed=True,
**kwargs
)
plt.ylim(0, 1.1 * h[0].max())
else:
bound = 0.0001
low = self.rv.ppf(bound)
high = self.rv.ppf(1 - bound)
if hasattr(self.rv.dist, "pmf"):
low = int(low)
high = int(high)
vals = list(range(low, high + 1))
plt.plot(vals, self.rv.pmf(vals), "o", **kwargs)
else:
vals = np.linspace(low, high, 500)
plt.plot(vals, self.rv.pdf(vals), **kwargs)
plt.xlim(low - (high - low) * 0.1, high + (high - low) * 0.1)
if show:
self.show()
|
python
|
def plot(self, hist=False, show=False, **kwargs):
"""
Plot the distribution of the UncertainVariable. Continuous
distributions are plotted with a line plot and discrete distributions
are plotted with discrete circles.
Optional
--------
hist : bool
If true, a histogram is displayed
show : bool
If ``True``, the figure will be displayed after plotting the
distribution. If ``False``, an explicit call to ``plt.show()`` is
required to display the figure.
kwargs : any valid matplotlib.pyplot.plot kwarg
"""
import matplotlib.pyplot as plt
if hist:
vals = self._mcpts
low = vals.min()
high = vals.max()
h = plt.hist(
vals,
bins=int(np.sqrt(len(vals)) + 0.5),
histtype="stepfilled",
normed=True,
**kwargs
)
plt.ylim(0, 1.1 * h[0].max())
else:
bound = 0.0001
low = self.rv.ppf(bound)
high = self.rv.ppf(1 - bound)
if hasattr(self.rv.dist, "pmf"):
low = int(low)
high = int(high)
vals = list(range(low, high + 1))
plt.plot(vals, self.rv.pmf(vals), "o", **kwargs)
else:
vals = np.linspace(low, high, 500)
plt.plot(vals, self.rv.pdf(vals), **kwargs)
plt.xlim(low - (high - low) * 0.1, high + (high - low) * 0.1)
if show:
self.show()
|
[
"def",
"plot",
"(",
"self",
",",
"hist",
"=",
"False",
",",
"show",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"import",
"matplotlib",
".",
"pyplot",
"as",
"plt",
"if",
"hist",
":",
"vals",
"=",
"self",
".",
"_mcpts",
"low",
"=",
"vals",
".",
"min",
"(",
")",
"high",
"=",
"vals",
".",
"max",
"(",
")",
"h",
"=",
"plt",
".",
"hist",
"(",
"vals",
",",
"bins",
"=",
"int",
"(",
"np",
".",
"sqrt",
"(",
"len",
"(",
"vals",
")",
")",
"+",
"0.5",
")",
",",
"histtype",
"=",
"\"stepfilled\"",
",",
"normed",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
"plt",
".",
"ylim",
"(",
"0",
",",
"1.1",
"*",
"h",
"[",
"0",
"]",
".",
"max",
"(",
")",
")",
"else",
":",
"bound",
"=",
"0.0001",
"low",
"=",
"self",
".",
"rv",
".",
"ppf",
"(",
"bound",
")",
"high",
"=",
"self",
".",
"rv",
".",
"ppf",
"(",
"1",
"-",
"bound",
")",
"if",
"hasattr",
"(",
"self",
".",
"rv",
".",
"dist",
",",
"\"pmf\"",
")",
":",
"low",
"=",
"int",
"(",
"low",
")",
"high",
"=",
"int",
"(",
"high",
")",
"vals",
"=",
"list",
"(",
"range",
"(",
"low",
",",
"high",
"+",
"1",
")",
")",
"plt",
".",
"plot",
"(",
"vals",
",",
"self",
".",
"rv",
".",
"pmf",
"(",
"vals",
")",
",",
"\"o\"",
",",
"*",
"*",
"kwargs",
")",
"else",
":",
"vals",
"=",
"np",
".",
"linspace",
"(",
"low",
",",
"high",
",",
"500",
")",
"plt",
".",
"plot",
"(",
"vals",
",",
"self",
".",
"rv",
".",
"pdf",
"(",
"vals",
")",
",",
"*",
"*",
"kwargs",
")",
"plt",
".",
"xlim",
"(",
"low",
"-",
"(",
"high",
"-",
"low",
")",
"*",
"0.1",
",",
"high",
"+",
"(",
"high",
"-",
"low",
")",
"*",
"0.1",
")",
"if",
"show",
":",
"self",
".",
"show",
"(",
")"
] |
Plot the distribution of the UncertainVariable. Continuous
distributions are plotted with a line plot and discrete distributions
are plotted with discrete circles.
Optional
--------
hist : bool
If true, a histogram is displayed
show : bool
If ``True``, the figure will be displayed after plotting the
distribution. If ``False``, an explicit call to ``plt.show()`` is
required to display the figure.
kwargs : any valid matplotlib.pyplot.plot kwarg
|
[
"Plot",
"the",
"distribution",
"of",
"the",
"UncertainVariable",
".",
"Continuous",
"distributions",
"are",
"plotted",
"with",
"a",
"line",
"plot",
"and",
"discrete",
"distributions",
"are",
"plotted",
"with",
"discrete",
"circles",
".",
"Optional",
"--------",
"hist",
":",
"bool",
"If",
"true",
"a",
"histogram",
"is",
"displayed",
"show",
":",
"bool",
"If",
"True",
"the",
"figure",
"will",
"be",
"displayed",
"after",
"plotting",
"the",
"distribution",
".",
"If",
"False",
"an",
"explicit",
"call",
"to",
"plt",
".",
"show",
"()",
"is",
"required",
"to",
"display",
"the",
"figure",
".",
"kwargs",
":",
"any",
"valid",
"matplotlib",
".",
"pyplot",
".",
"plot",
"kwarg"
] |
2bb8260c9ad2d58a806847f1b627b6451e407de1
|
https://github.com/tisimst/mcerp/blob/2bb8260c9ad2d58a806847f1b627b6451e407de1/mcerp/__init__.py#L652-L698
|
train
|
shoeffner/cvloop
|
cvloop/functions.py
|
DrawHat.load_hat
|
def load_hat(self, path): # pylint: disable=no-self-use
"""Loads the hat from a picture at path.
Args:
path: The path to load from
Returns:
The hat data.
"""
hat = cv2.imread(path, cv2.IMREAD_UNCHANGED)
if hat is None:
raise ValueError('No hat image found at `{}`'.format(path))
b, g, r, a = cv2.split(hat)
return cv2.merge((r, g, b, a))
|
python
|
def load_hat(self, path): # pylint: disable=no-self-use
"""Loads the hat from a picture at path.
Args:
path: The path to load from
Returns:
The hat data.
"""
hat = cv2.imread(path, cv2.IMREAD_UNCHANGED)
if hat is None:
raise ValueError('No hat image found at `{}`'.format(path))
b, g, r, a = cv2.split(hat)
return cv2.merge((r, g, b, a))
|
[
"def",
"load_hat",
"(",
"self",
",",
"path",
")",
":",
"# pylint: disable=no-self-use",
"hat",
"=",
"cv2",
".",
"imread",
"(",
"path",
",",
"cv2",
".",
"IMREAD_UNCHANGED",
")",
"if",
"hat",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"'No hat image found at `{}`'",
".",
"format",
"(",
"path",
")",
")",
"b",
",",
"g",
",",
"r",
",",
"a",
"=",
"cv2",
".",
"split",
"(",
"hat",
")",
"return",
"cv2",
".",
"merge",
"(",
"(",
"r",
",",
"g",
",",
"b",
",",
"a",
")",
")"
] |
Loads the hat from a picture at path.
Args:
path: The path to load from
Returns:
The hat data.
|
[
"Loads",
"the",
"hat",
"from",
"a",
"picture",
"at",
"path",
"."
] |
3ddd311e9b679d16c8fd36779931380374de343c
|
https://github.com/shoeffner/cvloop/blob/3ddd311e9b679d16c8fd36779931380374de343c/cvloop/functions.py#L173-L186
|
train
|
shoeffner/cvloop
|
cvloop/functions.py
|
DrawHat.find_faces
|
def find_faces(self, image, draw_box=False):
"""Uses a haarcascade to detect faces inside an image.
Args:
image: The image.
draw_box: If True, the image will be marked with a rectangle.
Return:
The faces as returned by OpenCV's detectMultiScale method for
cascades.
"""
frame_gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
faces = self.cascade.detectMultiScale(
frame_gray,
scaleFactor=1.3,
minNeighbors=5,
minSize=(50, 50),
flags=0)
if draw_box:
for x, y, w, h in faces:
cv2.rectangle(image, (x, y),
(x + w, y + h), (0, 255, 0), 2)
return faces
|
python
|
def find_faces(self, image, draw_box=False):
"""Uses a haarcascade to detect faces inside an image.
Args:
image: The image.
draw_box: If True, the image will be marked with a rectangle.
Return:
The faces as returned by OpenCV's detectMultiScale method for
cascades.
"""
frame_gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
faces = self.cascade.detectMultiScale(
frame_gray,
scaleFactor=1.3,
minNeighbors=5,
minSize=(50, 50),
flags=0)
if draw_box:
for x, y, w, h in faces:
cv2.rectangle(image, (x, y),
(x + w, y + h), (0, 255, 0), 2)
return faces
|
[
"def",
"find_faces",
"(",
"self",
",",
"image",
",",
"draw_box",
"=",
"False",
")",
":",
"frame_gray",
"=",
"cv2",
".",
"cvtColor",
"(",
"image",
",",
"cv2",
".",
"COLOR_RGB2GRAY",
")",
"faces",
"=",
"self",
".",
"cascade",
".",
"detectMultiScale",
"(",
"frame_gray",
",",
"scaleFactor",
"=",
"1.3",
",",
"minNeighbors",
"=",
"5",
",",
"minSize",
"=",
"(",
"50",
",",
"50",
")",
",",
"flags",
"=",
"0",
")",
"if",
"draw_box",
":",
"for",
"x",
",",
"y",
",",
"w",
",",
"h",
"in",
"faces",
":",
"cv2",
".",
"rectangle",
"(",
"image",
",",
"(",
"x",
",",
"y",
")",
",",
"(",
"x",
"+",
"w",
",",
"y",
"+",
"h",
")",
",",
"(",
"0",
",",
"255",
",",
"0",
")",
",",
"2",
")",
"return",
"faces"
] |
Uses a haarcascade to detect faces inside an image.
Args:
image: The image.
draw_box: If True, the image will be marked with a rectangle.
Return:
The faces as returned by OpenCV's detectMultiScale method for
cascades.
|
[
"Uses",
"a",
"haarcascade",
"to",
"detect",
"faces",
"inside",
"an",
"image",
"."
] |
3ddd311e9b679d16c8fd36779931380374de343c
|
https://github.com/shoeffner/cvloop/blob/3ddd311e9b679d16c8fd36779931380374de343c/cvloop/functions.py#L188-L211
|
train
|
uber-archive/h1-python
|
h1/client.py
|
HackerOneClient.find_resources
|
def find_resources(self, rsrc_type, sort=None, yield_pages=False, **kwargs):
"""Find instances of `rsrc_type` that match the filter in `**kwargs`"""
return rsrc_type.find(self, sort=sort, yield_pages=yield_pages, **kwargs)
|
python
|
def find_resources(self, rsrc_type, sort=None, yield_pages=False, **kwargs):
"""Find instances of `rsrc_type` that match the filter in `**kwargs`"""
return rsrc_type.find(self, sort=sort, yield_pages=yield_pages, **kwargs)
|
[
"def",
"find_resources",
"(",
"self",
",",
"rsrc_type",
",",
"sort",
"=",
"None",
",",
"yield_pages",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"rsrc_type",
".",
"find",
"(",
"self",
",",
"sort",
"=",
"sort",
",",
"yield_pages",
"=",
"yield_pages",
",",
"*",
"*",
"kwargs",
")"
] |
Find instances of `rsrc_type` that match the filter in `**kwargs`
|
[
"Find",
"instances",
"of",
"rsrc_type",
"that",
"match",
"the",
"filter",
"in",
"**",
"kwargs"
] |
c91aec6a26887e453106af39e96ec6d5c7b00c9d
|
https://github.com/uber-archive/h1-python/blob/c91aec6a26887e453106af39e96ec6d5c7b00c9d/h1/client.py#L111-L113
|
train
|
edelooff/sqlalchemy-json
|
sqlalchemy_json/track.py
|
TrackedObject.changed
|
def changed(self, message=None, *args):
"""Marks the object as changed.
If a `parent` attribute is set, the `changed()` method on the parent
will be called, propagating the change notification up the chain.
The message (if provided) will be debug logged.
"""
if message is not None:
self.logger.debug('%s: %s', self._repr(), message % args)
self.logger.debug('%s: changed', self._repr())
if self.parent is not None:
self.parent.changed()
elif isinstance(self, Mutable):
super(TrackedObject, self).changed()
|
python
|
def changed(self, message=None, *args):
"""Marks the object as changed.
If a `parent` attribute is set, the `changed()` method on the parent
will be called, propagating the change notification up the chain.
The message (if provided) will be debug logged.
"""
if message is not None:
self.logger.debug('%s: %s', self._repr(), message % args)
self.logger.debug('%s: changed', self._repr())
if self.parent is not None:
self.parent.changed()
elif isinstance(self, Mutable):
super(TrackedObject, self).changed()
|
[
"def",
"changed",
"(",
"self",
",",
"message",
"=",
"None",
",",
"*",
"args",
")",
":",
"if",
"message",
"is",
"not",
"None",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"'%s: %s'",
",",
"self",
".",
"_repr",
"(",
")",
",",
"message",
"%",
"args",
")",
"self",
".",
"logger",
".",
"debug",
"(",
"'%s: changed'",
",",
"self",
".",
"_repr",
"(",
")",
")",
"if",
"self",
".",
"parent",
"is",
"not",
"None",
":",
"self",
".",
"parent",
".",
"changed",
"(",
")",
"elif",
"isinstance",
"(",
"self",
",",
"Mutable",
")",
":",
"super",
"(",
"TrackedObject",
",",
"self",
")",
".",
"changed",
"(",
")"
] |
Marks the object as changed.
If a `parent` attribute is set, the `changed()` method on the parent
will be called, propagating the change notification up the chain.
The message (if provided) will be debug logged.
|
[
"Marks",
"the",
"object",
"as",
"changed",
"."
] |
4e5df0d61dc09ed9a52e24ab291a1f1e14aa95cc
|
https://github.com/edelooff/sqlalchemy-json/blob/4e5df0d61dc09ed9a52e24ab291a1f1e14aa95cc/sqlalchemy_json/track.py#L25-L39
|
train
|
edelooff/sqlalchemy-json
|
sqlalchemy_json/track.py
|
TrackedObject.register
|
def register(cls, origin_type):
"""Decorator for mutation tracker registration.
The provided `origin_type` is mapped to the decorated class such that
future calls to `convert()` will convert the object of `origin_type`
to an instance of the decorated class.
"""
def decorator(tracked_type):
"""Adds the decorated class to the `_type_mapping` dictionary."""
cls._type_mapping[origin_type] = tracked_type
return tracked_type
return decorator
|
python
|
def register(cls, origin_type):
"""Decorator for mutation tracker registration.
The provided `origin_type` is mapped to the decorated class such that
future calls to `convert()` will convert the object of `origin_type`
to an instance of the decorated class.
"""
def decorator(tracked_type):
"""Adds the decorated class to the `_type_mapping` dictionary."""
cls._type_mapping[origin_type] = tracked_type
return tracked_type
return decorator
|
[
"def",
"register",
"(",
"cls",
",",
"origin_type",
")",
":",
"def",
"decorator",
"(",
"tracked_type",
")",
":",
"\"\"\"Adds the decorated class to the `_type_mapping` dictionary.\"\"\"",
"cls",
".",
"_type_mapping",
"[",
"origin_type",
"]",
"=",
"tracked_type",
"return",
"tracked_type",
"return",
"decorator"
] |
Decorator for mutation tracker registration.
The provided `origin_type` is mapped to the decorated class such that
future calls to `convert()` will convert the object of `origin_type`
to an instance of the decorated class.
|
[
"Decorator",
"for",
"mutation",
"tracker",
"registration",
"."
] |
4e5df0d61dc09ed9a52e24ab291a1f1e14aa95cc
|
https://github.com/edelooff/sqlalchemy-json/blob/4e5df0d61dc09ed9a52e24ab291a1f1e14aa95cc/sqlalchemy_json/track.py#L42-L53
|
train
|
edelooff/sqlalchemy-json
|
sqlalchemy_json/track.py
|
TrackedObject.convert
|
def convert(cls, obj, parent):
"""Converts objects to registered tracked types
This checks the type of the given object against the registered tracked
types. When a match is found, the given object will be converted to the
tracked type, its parent set to the provided parent, and returned.
If its type does not occur in the registered types mapping, the object
is returned unchanged.
"""
replacement_type = cls._type_mapping.get(type(obj))
if replacement_type is not None:
new = replacement_type(obj)
new.parent = parent
return new
return obj
|
python
|
def convert(cls, obj, parent):
"""Converts objects to registered tracked types
This checks the type of the given object against the registered tracked
types. When a match is found, the given object will be converted to the
tracked type, its parent set to the provided parent, and returned.
If its type does not occur in the registered types mapping, the object
is returned unchanged.
"""
replacement_type = cls._type_mapping.get(type(obj))
if replacement_type is not None:
new = replacement_type(obj)
new.parent = parent
return new
return obj
|
[
"def",
"convert",
"(",
"cls",
",",
"obj",
",",
"parent",
")",
":",
"replacement_type",
"=",
"cls",
".",
"_type_mapping",
".",
"get",
"(",
"type",
"(",
"obj",
")",
")",
"if",
"replacement_type",
"is",
"not",
"None",
":",
"new",
"=",
"replacement_type",
"(",
"obj",
")",
"new",
".",
"parent",
"=",
"parent",
"return",
"new",
"return",
"obj"
] |
Converts objects to registered tracked types
This checks the type of the given object against the registered tracked
types. When a match is found, the given object will be converted to the
tracked type, its parent set to the provided parent, and returned.
If its type does not occur in the registered types mapping, the object
is returned unchanged.
|
[
"Converts",
"objects",
"to",
"registered",
"tracked",
"types"
] |
4e5df0d61dc09ed9a52e24ab291a1f1e14aa95cc
|
https://github.com/edelooff/sqlalchemy-json/blob/4e5df0d61dc09ed9a52e24ab291a1f1e14aa95cc/sqlalchemy_json/track.py#L56-L71
|
train
|
edelooff/sqlalchemy-json
|
sqlalchemy_json/track.py
|
TrackedObject.convert_items
|
def convert_items(self, items):
"""Generator like `convert_iterable`, but for 2-tuple iterators."""
return ((key, self.convert(value, self)) for key, value in items)
|
python
|
def convert_items(self, items):
"""Generator like `convert_iterable`, but for 2-tuple iterators."""
return ((key, self.convert(value, self)) for key, value in items)
|
[
"def",
"convert_items",
"(",
"self",
",",
"items",
")",
":",
"return",
"(",
"(",
"key",
",",
"self",
".",
"convert",
"(",
"value",
",",
"self",
")",
")",
"for",
"key",
",",
"value",
"in",
"items",
")"
] |
Generator like `convert_iterable`, but for 2-tuple iterators.
|
[
"Generator",
"like",
"convert_iterable",
"but",
"for",
"2",
"-",
"tuple",
"iterators",
"."
] |
4e5df0d61dc09ed9a52e24ab291a1f1e14aa95cc
|
https://github.com/edelooff/sqlalchemy-json/blob/4e5df0d61dc09ed9a52e24ab291a1f1e14aa95cc/sqlalchemy_json/track.py#L77-L79
|
train
|
edelooff/sqlalchemy-json
|
sqlalchemy_json/track.py
|
TrackedObject.convert_mapping
|
def convert_mapping(self, mapping):
"""Convenience method to track either a dict or a 2-tuple iterator."""
if isinstance(mapping, dict):
return self.convert_items(iteritems(mapping))
return self.convert_items(mapping)
|
python
|
def convert_mapping(self, mapping):
"""Convenience method to track either a dict or a 2-tuple iterator."""
if isinstance(mapping, dict):
return self.convert_items(iteritems(mapping))
return self.convert_items(mapping)
|
[
"def",
"convert_mapping",
"(",
"self",
",",
"mapping",
")",
":",
"if",
"isinstance",
"(",
"mapping",
",",
"dict",
")",
":",
"return",
"self",
".",
"convert_items",
"(",
"iteritems",
"(",
"mapping",
")",
")",
"return",
"self",
".",
"convert_items",
"(",
"mapping",
")"
] |
Convenience method to track either a dict or a 2-tuple iterator.
|
[
"Convenience",
"method",
"to",
"track",
"either",
"a",
"dict",
"or",
"a",
"2",
"-",
"tuple",
"iterator",
"."
] |
4e5df0d61dc09ed9a52e24ab291a1f1e14aa95cc
|
https://github.com/edelooff/sqlalchemy-json/blob/4e5df0d61dc09ed9a52e24ab291a1f1e14aa95cc/sqlalchemy_json/track.py#L81-L85
|
train
|
praekelt/django-preferences
|
preferences/admin.py
|
PreferencesAdmin.changelist_view
|
def changelist_view(self, request, extra_context=None):
"""
If we only have a single preference object redirect to it,
otherwise display listing.
"""
model = self.model
if model.objects.all().count() > 1:
return super(PreferencesAdmin, self).changelist_view(request)
else:
obj = model.singleton.get()
return redirect(
reverse(
'admin:%s_%s_change' % (
model._meta.app_label, model._meta.model_name
),
args=(obj.id,)
)
)
|
python
|
def changelist_view(self, request, extra_context=None):
"""
If we only have a single preference object redirect to it,
otherwise display listing.
"""
model = self.model
if model.objects.all().count() > 1:
return super(PreferencesAdmin, self).changelist_view(request)
else:
obj = model.singleton.get()
return redirect(
reverse(
'admin:%s_%s_change' % (
model._meta.app_label, model._meta.model_name
),
args=(obj.id,)
)
)
|
[
"def",
"changelist_view",
"(",
"self",
",",
"request",
",",
"extra_context",
"=",
"None",
")",
":",
"model",
"=",
"self",
".",
"model",
"if",
"model",
".",
"objects",
".",
"all",
"(",
")",
".",
"count",
"(",
")",
">",
"1",
":",
"return",
"super",
"(",
"PreferencesAdmin",
",",
"self",
")",
".",
"changelist_view",
"(",
"request",
")",
"else",
":",
"obj",
"=",
"model",
".",
"singleton",
".",
"get",
"(",
")",
"return",
"redirect",
"(",
"reverse",
"(",
"'admin:%s_%s_change'",
"%",
"(",
"model",
".",
"_meta",
".",
"app_label",
",",
"model",
".",
"_meta",
".",
"model_name",
")",
",",
"args",
"=",
"(",
"obj",
".",
"id",
",",
")",
")",
")"
] |
If we only have a single preference object redirect to it,
otherwise display listing.
|
[
"If",
"we",
"only",
"have",
"a",
"single",
"preference",
"object",
"redirect",
"to",
"it",
"otherwise",
"display",
"listing",
"."
] |
724f23da45449e96feb5179cb34e3d380cf151a1
|
https://github.com/praekelt/django-preferences/blob/724f23da45449e96feb5179cb34e3d380cf151a1/preferences/admin.py#L13-L30
|
train
|
voyages-sncf-technologies/nexus_uploader
|
setup.py
|
md2rst
|
def md2rst(md_lines):
'Only converts headers'
lvl2header_char = {1: '=', 2: '-', 3: '~'}
for md_line in md_lines:
if md_line.startswith('#'):
header_indent, header_text = md_line.split(' ', 1)
yield header_text
header_char = lvl2header_char[len(header_indent)]
yield header_char * len(header_text)
else:
yield md_line
|
python
|
def md2rst(md_lines):
'Only converts headers'
lvl2header_char = {1: '=', 2: '-', 3: '~'}
for md_line in md_lines:
if md_line.startswith('#'):
header_indent, header_text = md_line.split(' ', 1)
yield header_text
header_char = lvl2header_char[len(header_indent)]
yield header_char * len(header_text)
else:
yield md_line
|
[
"def",
"md2rst",
"(",
"md_lines",
")",
":",
"lvl2header_char",
"=",
"{",
"1",
":",
"'='",
",",
"2",
":",
"'-'",
",",
"3",
":",
"'~'",
"}",
"for",
"md_line",
"in",
"md_lines",
":",
"if",
"md_line",
".",
"startswith",
"(",
"'#'",
")",
":",
"header_indent",
",",
"header_text",
"=",
"md_line",
".",
"split",
"(",
"' '",
",",
"1",
")",
"yield",
"header_text",
"header_char",
"=",
"lvl2header_char",
"[",
"len",
"(",
"header_indent",
")",
"]",
"yield",
"header_char",
"*",
"len",
"(",
"header_text",
")",
"else",
":",
"yield",
"md_line"
] |
Only converts headers
|
[
"Only",
"converts",
"headers"
] |
dca654f9080264b1dcaabfc2fd19f26b1c4f59fe
|
https://github.com/voyages-sncf-technologies/nexus_uploader/blob/dca654f9080264b1dcaabfc2fd19f26b1c4f59fe/setup.py#L24-L34
|
train
|
voyages-sncf-technologies/nexus_uploader
|
nexus_uploader/utils.py
|
aslist
|
def aslist(generator):
'Function decorator to transform a generator into a list'
def wrapper(*args, **kwargs):
return list(generator(*args, **kwargs))
return wrapper
|
python
|
def aslist(generator):
'Function decorator to transform a generator into a list'
def wrapper(*args, **kwargs):
return list(generator(*args, **kwargs))
return wrapper
|
[
"def",
"aslist",
"(",
"generator",
")",
":",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"list",
"(",
"generator",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
")",
"return",
"wrapper"
] |
Function decorator to transform a generator into a list
|
[
"Function",
"decorator",
"to",
"transform",
"a",
"generator",
"into",
"a",
"list"
] |
dca654f9080264b1dcaabfc2fd19f26b1c4f59fe
|
https://github.com/voyages-sncf-technologies/nexus_uploader/blob/dca654f9080264b1dcaabfc2fd19f26b1c4f59fe/nexus_uploader/utils.py#L17-L21
|
train
|
voyages-sncf-technologies/nexus_uploader
|
nexus_uploader/pypi.py
|
get_package_release_from_pypi
|
def get_package_release_from_pypi(pkg_name, version, pypi_json_api_url, allowed_classifiers):
"""
No classifier-based selection of Python packages is currently implemented: for now we don't fetch any .whl or .egg
Eventually, we should select the best release available, based on the classifier & PEP 425: https://www.python.org/dev/peps/pep-0425/
E.g. a wheel when available but NOT for tornado 4.3 for example, where available wheels are only for Windows.
Note also that some packages don't have .whl distributed, e.g. https://bugs.launchpad.net/lxml/+bug/1176147
"""
matching_releases = get_package_releases_matching_version(pkg_name, version, pypi_json_api_url)
src_releases = [release for release in matching_releases if release['python_version'] == 'source']
if src_releases:
return select_src_release(src_releases, pkg_name, target_classifiers=('py2.py3-none-any',), select_arbitrary_version_if_none_match=True)
if allowed_classifiers:
return select_src_release(matching_releases, pkg_name, target_classifiers=allowed_classifiers)
raise PypiQueryError('No source supported found for package {} version {}'.format(pkg_name, version))
|
python
|
def get_package_release_from_pypi(pkg_name, version, pypi_json_api_url, allowed_classifiers):
"""
No classifier-based selection of Python packages is currently implemented: for now we don't fetch any .whl or .egg
Eventually, we should select the best release available, based on the classifier & PEP 425: https://www.python.org/dev/peps/pep-0425/
E.g. a wheel when available but NOT for tornado 4.3 for example, where available wheels are only for Windows.
Note also that some packages don't have .whl distributed, e.g. https://bugs.launchpad.net/lxml/+bug/1176147
"""
matching_releases = get_package_releases_matching_version(pkg_name, version, pypi_json_api_url)
src_releases = [release for release in matching_releases if release['python_version'] == 'source']
if src_releases:
return select_src_release(src_releases, pkg_name, target_classifiers=('py2.py3-none-any',), select_arbitrary_version_if_none_match=True)
if allowed_classifiers:
return select_src_release(matching_releases, pkg_name, target_classifiers=allowed_classifiers)
raise PypiQueryError('No source supported found for package {} version {}'.format(pkg_name, version))
|
[
"def",
"get_package_release_from_pypi",
"(",
"pkg_name",
",",
"version",
",",
"pypi_json_api_url",
",",
"allowed_classifiers",
")",
":",
"matching_releases",
"=",
"get_package_releases_matching_version",
"(",
"pkg_name",
",",
"version",
",",
"pypi_json_api_url",
")",
"src_releases",
"=",
"[",
"release",
"for",
"release",
"in",
"matching_releases",
"if",
"release",
"[",
"'python_version'",
"]",
"==",
"'source'",
"]",
"if",
"src_releases",
":",
"return",
"select_src_release",
"(",
"src_releases",
",",
"pkg_name",
",",
"target_classifiers",
"=",
"(",
"'py2.py3-none-any'",
",",
")",
",",
"select_arbitrary_version_if_none_match",
"=",
"True",
")",
"if",
"allowed_classifiers",
":",
"return",
"select_src_release",
"(",
"matching_releases",
",",
"pkg_name",
",",
"target_classifiers",
"=",
"allowed_classifiers",
")",
"raise",
"PypiQueryError",
"(",
"'No source supported found for package {} version {}'",
".",
"format",
"(",
"pkg_name",
",",
"version",
")",
")"
] |
No classifier-based selection of Python packages is currently implemented: for now we don't fetch any .whl or .egg
Eventually, we should select the best release available, based on the classifier & PEP 425: https://www.python.org/dev/peps/pep-0425/
E.g. a wheel when available but NOT for tornado 4.3 for example, where available wheels are only for Windows.
Note also that some packages don't have .whl distributed, e.g. https://bugs.launchpad.net/lxml/+bug/1176147
|
[
"No",
"classifier",
"-",
"based",
"selection",
"of",
"Python",
"packages",
"is",
"currently",
"implemented",
":",
"for",
"now",
"we",
"don",
"t",
"fetch",
"any",
".",
"whl",
"or",
".",
"egg",
"Eventually",
"we",
"should",
"select",
"the",
"best",
"release",
"available",
"based",
"on",
"the",
"classifier",
"&",
"PEP",
"425",
":",
"https",
":",
"//",
"www",
".",
"python",
".",
"org",
"/",
"dev",
"/",
"peps",
"/",
"pep",
"-",
"0425",
"/",
"E",
".",
"g",
".",
"a",
"wheel",
"when",
"available",
"but",
"NOT",
"for",
"tornado",
"4",
".",
"3",
"for",
"example",
"where",
"available",
"wheels",
"are",
"only",
"for",
"Windows",
".",
"Note",
"also",
"that",
"some",
"packages",
"don",
"t",
"have",
".",
"whl",
"distributed",
"e",
".",
"g",
".",
"https",
":",
"//",
"bugs",
".",
"launchpad",
".",
"net",
"/",
"lxml",
"/",
"+",
"bug",
"/",
"1176147"
] |
dca654f9080264b1dcaabfc2fd19f26b1c4f59fe
|
https://github.com/voyages-sncf-technologies/nexus_uploader/blob/dca654f9080264b1dcaabfc2fd19f26b1c4f59fe/nexus_uploader/pypi.py#L27-L40
|
train
|
voyages-sncf-technologies/nexus_uploader
|
nexus_uploader/pypi.py
|
extract_classifier_and_extension
|
def extract_classifier_and_extension(pkg_name, filename):
"""
Returns a PEP425-compliant classifier (or 'py2.py3-none-any' if it cannot be extracted),
and the file extension
TODO: return a classifier 3-members namedtuple instead of a single string
"""
basename, _, extension = filename.rpartition('.')
if extension == 'gz' and filename.endswith('.tar.gz'):
extension = 'tar.gz'
basename = filename[:-7]
if basename == pkg_name or basename[len(pkg_name)] != '-':
return 'py2.py3-none-any', extension
basename = basename[len(pkg_name)+1:]
classifier_parts = basename.split('-')
if len(classifier_parts) < 3:
return 'py2.py3-none-any', extension
if len(classifier_parts) == 3:
_, _, classifier_parts[0] = classifier_parts[0].rpartition('.')
return '-'.join(classifier_parts[-3:]), extension
|
python
|
def extract_classifier_and_extension(pkg_name, filename):
"""
Returns a PEP425-compliant classifier (or 'py2.py3-none-any' if it cannot be extracted),
and the file extension
TODO: return a classifier 3-members namedtuple instead of a single string
"""
basename, _, extension = filename.rpartition('.')
if extension == 'gz' and filename.endswith('.tar.gz'):
extension = 'tar.gz'
basename = filename[:-7]
if basename == pkg_name or basename[len(pkg_name)] != '-':
return 'py2.py3-none-any', extension
basename = basename[len(pkg_name)+1:]
classifier_parts = basename.split('-')
if len(classifier_parts) < 3:
return 'py2.py3-none-any', extension
if len(classifier_parts) == 3:
_, _, classifier_parts[0] = classifier_parts[0].rpartition('.')
return '-'.join(classifier_parts[-3:]), extension
|
[
"def",
"extract_classifier_and_extension",
"(",
"pkg_name",
",",
"filename",
")",
":",
"basename",
",",
"_",
",",
"extension",
"=",
"filename",
".",
"rpartition",
"(",
"'.'",
")",
"if",
"extension",
"==",
"'gz'",
"and",
"filename",
".",
"endswith",
"(",
"'.tar.gz'",
")",
":",
"extension",
"=",
"'tar.gz'",
"basename",
"=",
"filename",
"[",
":",
"-",
"7",
"]",
"if",
"basename",
"==",
"pkg_name",
"or",
"basename",
"[",
"len",
"(",
"pkg_name",
")",
"]",
"!=",
"'-'",
":",
"return",
"'py2.py3-none-any'",
",",
"extension",
"basename",
"=",
"basename",
"[",
"len",
"(",
"pkg_name",
")",
"+",
"1",
":",
"]",
"classifier_parts",
"=",
"basename",
".",
"split",
"(",
"'-'",
")",
"if",
"len",
"(",
"classifier_parts",
")",
"<",
"3",
":",
"return",
"'py2.py3-none-any'",
",",
"extension",
"if",
"len",
"(",
"classifier_parts",
")",
"==",
"3",
":",
"_",
",",
"_",
",",
"classifier_parts",
"[",
"0",
"]",
"=",
"classifier_parts",
"[",
"0",
"]",
".",
"rpartition",
"(",
"'.'",
")",
"return",
"'-'",
".",
"join",
"(",
"classifier_parts",
"[",
"-",
"3",
":",
"]",
")",
",",
"extension"
] |
Returns a PEP425-compliant classifier (or 'py2.py3-none-any' if it cannot be extracted),
and the file extension
TODO: return a classifier 3-members namedtuple instead of a single string
|
[
"Returns",
"a",
"PEP425",
"-",
"compliant",
"classifier",
"(",
"or",
"py2",
".",
"py3",
"-",
"none",
"-",
"any",
"if",
"it",
"cannot",
"be",
"extracted",
")",
"and",
"the",
"file",
"extension",
"TODO",
":",
"return",
"a",
"classifier",
"3",
"-",
"members",
"namedtuple",
"instead",
"of",
"a",
"single",
"string"
] |
dca654f9080264b1dcaabfc2fd19f26b1c4f59fe
|
https://github.com/voyages-sncf-technologies/nexus_uploader/blob/dca654f9080264b1dcaabfc2fd19f26b1c4f59fe/nexus_uploader/pypi.py#L62-L80
|
train
|
edelooff/sqlalchemy-json
|
sqlalchemy_json/__init__.py
|
NestedMutable.coerce
|
def coerce(cls, key, value):
"""Convert plain dictionary to NestedMutable."""
if value is None:
return value
if isinstance(value, cls):
return value
if isinstance(value, dict):
return NestedMutableDict.coerce(key, value)
if isinstance(value, list):
return NestedMutableList.coerce(key, value)
return super(cls).coerce(key, value)
|
python
|
def coerce(cls, key, value):
"""Convert plain dictionary to NestedMutable."""
if value is None:
return value
if isinstance(value, cls):
return value
if isinstance(value, dict):
return NestedMutableDict.coerce(key, value)
if isinstance(value, list):
return NestedMutableList.coerce(key, value)
return super(cls).coerce(key, value)
|
[
"def",
"coerce",
"(",
"cls",
",",
"key",
",",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"return",
"value",
"if",
"isinstance",
"(",
"value",
",",
"cls",
")",
":",
"return",
"value",
"if",
"isinstance",
"(",
"value",
",",
"dict",
")",
":",
"return",
"NestedMutableDict",
".",
"coerce",
"(",
"key",
",",
"value",
")",
"if",
"isinstance",
"(",
"value",
",",
"list",
")",
":",
"return",
"NestedMutableList",
".",
"coerce",
"(",
"key",
",",
"value",
")",
"return",
"super",
"(",
"cls",
")",
".",
"coerce",
"(",
"key",
",",
"value",
")"
] |
Convert plain dictionary to NestedMutable.
|
[
"Convert",
"plain",
"dictionary",
"to",
"NestedMutable",
"."
] |
4e5df0d61dc09ed9a52e24ab291a1f1e14aa95cc
|
https://github.com/edelooff/sqlalchemy-json/blob/4e5df0d61dc09ed9a52e24ab291a1f1e14aa95cc/sqlalchemy_json/__init__.py#L36-L46
|
train
|
shoeffner/cvloop
|
tools/create_functions_ipynb.py
|
is_mod_function
|
def is_mod_function(mod, fun):
"""Checks if a function in a module was declared in that module.
http://stackoverflow.com/a/1107150/3004221
Args:
mod: the module
fun: the function
"""
return inspect.isfunction(fun) and inspect.getmodule(fun) == mod
|
python
|
def is_mod_function(mod, fun):
"""Checks if a function in a module was declared in that module.
http://stackoverflow.com/a/1107150/3004221
Args:
mod: the module
fun: the function
"""
return inspect.isfunction(fun) and inspect.getmodule(fun) == mod
|
[
"def",
"is_mod_function",
"(",
"mod",
",",
"fun",
")",
":",
"return",
"inspect",
".",
"isfunction",
"(",
"fun",
")",
"and",
"inspect",
".",
"getmodule",
"(",
"fun",
")",
"==",
"mod"
] |
Checks if a function in a module was declared in that module.
http://stackoverflow.com/a/1107150/3004221
Args:
mod: the module
fun: the function
|
[
"Checks",
"if",
"a",
"function",
"in",
"a",
"module",
"was",
"declared",
"in",
"that",
"module",
"."
] |
3ddd311e9b679d16c8fd36779931380374de343c
|
https://github.com/shoeffner/cvloop/blob/3ddd311e9b679d16c8fd36779931380374de343c/tools/create_functions_ipynb.py#L15-L24
|
train
|
shoeffner/cvloop
|
tools/create_functions_ipynb.py
|
is_mod_class
|
def is_mod_class(mod, cls):
"""Checks if a class in a module was declared in that module.
Args:
mod: the module
cls: the class
"""
return inspect.isclass(cls) and inspect.getmodule(cls) == mod
|
python
|
def is_mod_class(mod, cls):
"""Checks if a class in a module was declared in that module.
Args:
mod: the module
cls: the class
"""
return inspect.isclass(cls) and inspect.getmodule(cls) == mod
|
[
"def",
"is_mod_class",
"(",
"mod",
",",
"cls",
")",
":",
"return",
"inspect",
".",
"isclass",
"(",
"cls",
")",
"and",
"inspect",
".",
"getmodule",
"(",
"cls",
")",
"==",
"mod"
] |
Checks if a class in a module was declared in that module.
Args:
mod: the module
cls: the class
|
[
"Checks",
"if",
"a",
"class",
"in",
"a",
"module",
"was",
"declared",
"in",
"that",
"module",
"."
] |
3ddd311e9b679d16c8fd36779931380374de343c
|
https://github.com/shoeffner/cvloop/blob/3ddd311e9b679d16c8fd36779931380374de343c/tools/create_functions_ipynb.py#L27-L34
|
train
|
shoeffner/cvloop
|
tools/create_functions_ipynb.py
|
list_functions
|
def list_functions(mod_name):
"""Lists all functions declared in a module.
http://stackoverflow.com/a/1107150/3004221
Args:
mod_name: the module name
Returns:
A list of functions declared in that module.
"""
mod = sys.modules[mod_name]
return [func.__name__ for func in mod.__dict__.values()
if is_mod_function(mod, func)]
|
python
|
def list_functions(mod_name):
"""Lists all functions declared in a module.
http://stackoverflow.com/a/1107150/3004221
Args:
mod_name: the module name
Returns:
A list of functions declared in that module.
"""
mod = sys.modules[mod_name]
return [func.__name__ for func in mod.__dict__.values()
if is_mod_function(mod, func)]
|
[
"def",
"list_functions",
"(",
"mod_name",
")",
":",
"mod",
"=",
"sys",
".",
"modules",
"[",
"mod_name",
"]",
"return",
"[",
"func",
".",
"__name__",
"for",
"func",
"in",
"mod",
".",
"__dict__",
".",
"values",
"(",
")",
"if",
"is_mod_function",
"(",
"mod",
",",
"func",
")",
"]"
] |
Lists all functions declared in a module.
http://stackoverflow.com/a/1107150/3004221
Args:
mod_name: the module name
Returns:
A list of functions declared in that module.
|
[
"Lists",
"all",
"functions",
"declared",
"in",
"a",
"module",
"."
] |
3ddd311e9b679d16c8fd36779931380374de343c
|
https://github.com/shoeffner/cvloop/blob/3ddd311e9b679d16c8fd36779931380374de343c/tools/create_functions_ipynb.py#L37-L49
|
train
|
shoeffner/cvloop
|
tools/create_functions_ipynb.py
|
list_classes
|
def list_classes(mod_name):
"""Lists all classes declared in a module.
Args:
mod_name: the module name
Returns:
A list of functions declared in that module.
"""
mod = sys.modules[mod_name]
return [cls.__name__ for cls in mod.__dict__.values()
if is_mod_class(mod, cls)]
|
python
|
def list_classes(mod_name):
"""Lists all classes declared in a module.
Args:
mod_name: the module name
Returns:
A list of functions declared in that module.
"""
mod = sys.modules[mod_name]
return [cls.__name__ for cls in mod.__dict__.values()
if is_mod_class(mod, cls)]
|
[
"def",
"list_classes",
"(",
"mod_name",
")",
":",
"mod",
"=",
"sys",
".",
"modules",
"[",
"mod_name",
"]",
"return",
"[",
"cls",
".",
"__name__",
"for",
"cls",
"in",
"mod",
".",
"__dict__",
".",
"values",
"(",
")",
"if",
"is_mod_class",
"(",
"mod",
",",
"cls",
")",
"]"
] |
Lists all classes declared in a module.
Args:
mod_name: the module name
Returns:
A list of functions declared in that module.
|
[
"Lists",
"all",
"classes",
"declared",
"in",
"a",
"module",
"."
] |
3ddd311e9b679d16c8fd36779931380374de343c
|
https://github.com/shoeffner/cvloop/blob/3ddd311e9b679d16c8fd36779931380374de343c/tools/create_functions_ipynb.py#L52-L62
|
train
|
shoeffner/cvloop
|
tools/create_functions_ipynb.py
|
get_linenumbers
|
def get_linenumbers(functions, module, searchstr='def {}(image):\n'):
"""Returns a dictionary which maps function names to line numbers.
Args:
functions: a list of function names
module: the module to look the functions up
searchstr: the string to search for
Returns:
A dictionary with functions as keys and their line numbers as values.
"""
lines = inspect.getsourcelines(module)[0]
line_numbers = {}
for function in functions:
try:
line_numbers[function] = lines.index(
searchstr.format(function)) + 1
except ValueError:
print(r'Can not find `{}`'.format(searchstr.format(function)))
line_numbers[function] = 0
return line_numbers
|
python
|
def get_linenumbers(functions, module, searchstr='def {}(image):\n'):
"""Returns a dictionary which maps function names to line numbers.
Args:
functions: a list of function names
module: the module to look the functions up
searchstr: the string to search for
Returns:
A dictionary with functions as keys and their line numbers as values.
"""
lines = inspect.getsourcelines(module)[0]
line_numbers = {}
for function in functions:
try:
line_numbers[function] = lines.index(
searchstr.format(function)) + 1
except ValueError:
print(r'Can not find `{}`'.format(searchstr.format(function)))
line_numbers[function] = 0
return line_numbers
|
[
"def",
"get_linenumbers",
"(",
"functions",
",",
"module",
",",
"searchstr",
"=",
"'def {}(image):\\n'",
")",
":",
"lines",
"=",
"inspect",
".",
"getsourcelines",
"(",
"module",
")",
"[",
"0",
"]",
"line_numbers",
"=",
"{",
"}",
"for",
"function",
"in",
"functions",
":",
"try",
":",
"line_numbers",
"[",
"function",
"]",
"=",
"lines",
".",
"index",
"(",
"searchstr",
".",
"format",
"(",
"function",
")",
")",
"+",
"1",
"except",
"ValueError",
":",
"print",
"(",
"r'Can not find `{}`'",
".",
"format",
"(",
"searchstr",
".",
"format",
"(",
"function",
")",
")",
")",
"line_numbers",
"[",
"function",
"]",
"=",
"0",
"return",
"line_numbers"
] |
Returns a dictionary which maps function names to line numbers.
Args:
functions: a list of function names
module: the module to look the functions up
searchstr: the string to search for
Returns:
A dictionary with functions as keys and their line numbers as values.
|
[
"Returns",
"a",
"dictionary",
"which",
"maps",
"function",
"names",
"to",
"line",
"numbers",
"."
] |
3ddd311e9b679d16c8fd36779931380374de343c
|
https://github.com/shoeffner/cvloop/blob/3ddd311e9b679d16c8fd36779931380374de343c/tools/create_functions_ipynb.py#L65-L84
|
train
|
shoeffner/cvloop
|
tools/create_functions_ipynb.py
|
format_doc
|
def format_doc(fun):
"""Formats the documentation in a nicer way and for notebook cells."""
SEPARATOR = '============================='
func = cvloop.functions.__dict__[fun]
doc_lines = ['{}'.format(l).strip() for l in func.__doc__.split('\n')]
if hasattr(func, '__init__'):
doc_lines.append(SEPARATOR)
doc_lines += ['{}'.format(l).strip() for l in
func.__init__.__doc__.split('\n')]
mod_lines = []
argblock = False
returnblock = False
for line in doc_lines:
if line == SEPARATOR:
mod_lines.append('\n#### `{}.__init__(...)`:\n\n'.format(fun))
elif 'Args:' in line:
argblock = True
if GENERATE_ARGS:
mod_lines.append('**{}**\n'.format(line))
elif 'Returns:' in line:
returnblock = True
mod_lines.append('\n**{}**'.format(line))
elif not argblock and not returnblock:
mod_lines.append('{}\n'.format(line))
elif argblock and not returnblock and ':' in line:
if GENERATE_ARGS:
mod_lines.append('- *{}:* {}\n'.format(
*line.split(':')))
elif returnblock:
mod_lines.append(line)
else:
mod_lines.append('{}\n'.format(line))
return mod_lines
|
python
|
def format_doc(fun):
"""Formats the documentation in a nicer way and for notebook cells."""
SEPARATOR = '============================='
func = cvloop.functions.__dict__[fun]
doc_lines = ['{}'.format(l).strip() for l in func.__doc__.split('\n')]
if hasattr(func, '__init__'):
doc_lines.append(SEPARATOR)
doc_lines += ['{}'.format(l).strip() for l in
func.__init__.__doc__.split('\n')]
mod_lines = []
argblock = False
returnblock = False
for line in doc_lines:
if line == SEPARATOR:
mod_lines.append('\n#### `{}.__init__(...)`:\n\n'.format(fun))
elif 'Args:' in line:
argblock = True
if GENERATE_ARGS:
mod_lines.append('**{}**\n'.format(line))
elif 'Returns:' in line:
returnblock = True
mod_lines.append('\n**{}**'.format(line))
elif not argblock and not returnblock:
mod_lines.append('{}\n'.format(line))
elif argblock and not returnblock and ':' in line:
if GENERATE_ARGS:
mod_lines.append('- *{}:* {}\n'.format(
*line.split(':')))
elif returnblock:
mod_lines.append(line)
else:
mod_lines.append('{}\n'.format(line))
return mod_lines
|
[
"def",
"format_doc",
"(",
"fun",
")",
":",
"SEPARATOR",
"=",
"'============================='",
"func",
"=",
"cvloop",
".",
"functions",
".",
"__dict__",
"[",
"fun",
"]",
"doc_lines",
"=",
"[",
"'{}'",
".",
"format",
"(",
"l",
")",
".",
"strip",
"(",
")",
"for",
"l",
"in",
"func",
".",
"__doc__",
".",
"split",
"(",
"'\\n'",
")",
"]",
"if",
"hasattr",
"(",
"func",
",",
"'__init__'",
")",
":",
"doc_lines",
".",
"append",
"(",
"SEPARATOR",
")",
"doc_lines",
"+=",
"[",
"'{}'",
".",
"format",
"(",
"l",
")",
".",
"strip",
"(",
")",
"for",
"l",
"in",
"func",
".",
"__init__",
".",
"__doc__",
".",
"split",
"(",
"'\\n'",
")",
"]",
"mod_lines",
"=",
"[",
"]",
"argblock",
"=",
"False",
"returnblock",
"=",
"False",
"for",
"line",
"in",
"doc_lines",
":",
"if",
"line",
"==",
"SEPARATOR",
":",
"mod_lines",
".",
"append",
"(",
"'\\n#### `{}.__init__(...)`:\\n\\n'",
".",
"format",
"(",
"fun",
")",
")",
"elif",
"'Args:'",
"in",
"line",
":",
"argblock",
"=",
"True",
"if",
"GENERATE_ARGS",
":",
"mod_lines",
".",
"append",
"(",
"'**{}**\\n'",
".",
"format",
"(",
"line",
")",
")",
"elif",
"'Returns:'",
"in",
"line",
":",
"returnblock",
"=",
"True",
"mod_lines",
".",
"append",
"(",
"'\\n**{}**'",
".",
"format",
"(",
"line",
")",
")",
"elif",
"not",
"argblock",
"and",
"not",
"returnblock",
":",
"mod_lines",
".",
"append",
"(",
"'{}\\n'",
".",
"format",
"(",
"line",
")",
")",
"elif",
"argblock",
"and",
"not",
"returnblock",
"and",
"':'",
"in",
"line",
":",
"if",
"GENERATE_ARGS",
":",
"mod_lines",
".",
"append",
"(",
"'- *{}:* {}\\n'",
".",
"format",
"(",
"*",
"line",
".",
"split",
"(",
"':'",
")",
")",
")",
"elif",
"returnblock",
":",
"mod_lines",
".",
"append",
"(",
"line",
")",
"else",
":",
"mod_lines",
".",
"append",
"(",
"'{}\\n'",
".",
"format",
"(",
"line",
")",
")",
"return",
"mod_lines"
] |
Formats the documentation in a nicer way and for notebook cells.
|
[
"Formats",
"the",
"documentation",
"in",
"a",
"nicer",
"way",
"and",
"for",
"notebook",
"cells",
"."
] |
3ddd311e9b679d16c8fd36779931380374de343c
|
https://github.com/shoeffner/cvloop/blob/3ddd311e9b679d16c8fd36779931380374de343c/tools/create_functions_ipynb.py#L87-L121
|
train
|
shoeffner/cvloop
|
tools/create_functions_ipynb.py
|
main
|
def main():
"""Main function creates the cvloop.functions example notebook."""
notebook = {
'cells': [
{
'cell_type': 'markdown',
'metadata': {},
'source': [
'# cvloop functions\n\n',
'This notebook shows an overview over all cvloop ',
'functions provided in the [`cvloop.functions` module](',
'https://github.com/shoeffner/cvloop/blob/',
'develop/cvloop/functions.py).'
]
},
],
'nbformat': 4,
'nbformat_minor': 1,
'metadata': {
'language_info': {
'codemirror_mode': {
'name': 'ipython',
'version': 3
},
'file_extension': '.py',
'mimetype': 'text/x-python',
'name': 'python',
'nbconvert_exporter': 'python',
'pygments_lexer': 'ipython3',
'version': '3.5.1+'
}
}
}
classes = list_classes('cvloop.functions')
functions = list_functions('cvloop.functions')
line_numbers_cls = get_linenumbers(classes, cvloop.functions,
'class {}:\n')
line_numbers = get_linenumbers(functions, cvloop.functions)
for cls in classes:
line_number = line_numbers_cls[cls]
notebook['cells'].append(create_description_cell(cls, line_number))
notebook['cells'].append(create_code_cell(cls, isclass=True))
for func in functions:
line_number = line_numbers[func]
notebook['cells'].append(create_description_cell(func, line_number))
notebook['cells'].append(create_code_cell(func))
with open(sys.argv[1], 'w') as nfile:
json.dump(notebook, nfile, indent=4)
|
python
|
def main():
"""Main function creates the cvloop.functions example notebook."""
notebook = {
'cells': [
{
'cell_type': 'markdown',
'metadata': {},
'source': [
'# cvloop functions\n\n',
'This notebook shows an overview over all cvloop ',
'functions provided in the [`cvloop.functions` module](',
'https://github.com/shoeffner/cvloop/blob/',
'develop/cvloop/functions.py).'
]
},
],
'nbformat': 4,
'nbformat_minor': 1,
'metadata': {
'language_info': {
'codemirror_mode': {
'name': 'ipython',
'version': 3
},
'file_extension': '.py',
'mimetype': 'text/x-python',
'name': 'python',
'nbconvert_exporter': 'python',
'pygments_lexer': 'ipython3',
'version': '3.5.1+'
}
}
}
classes = list_classes('cvloop.functions')
functions = list_functions('cvloop.functions')
line_numbers_cls = get_linenumbers(classes, cvloop.functions,
'class {}:\n')
line_numbers = get_linenumbers(functions, cvloop.functions)
for cls in classes:
line_number = line_numbers_cls[cls]
notebook['cells'].append(create_description_cell(cls, line_number))
notebook['cells'].append(create_code_cell(cls, isclass=True))
for func in functions:
line_number = line_numbers[func]
notebook['cells'].append(create_description_cell(func, line_number))
notebook['cells'].append(create_code_cell(func))
with open(sys.argv[1], 'w') as nfile:
json.dump(notebook, nfile, indent=4)
|
[
"def",
"main",
"(",
")",
":",
"notebook",
"=",
"{",
"'cells'",
":",
"[",
"{",
"'cell_type'",
":",
"'markdown'",
",",
"'metadata'",
":",
"{",
"}",
",",
"'source'",
":",
"[",
"'# cvloop functions\\n\\n'",
",",
"'This notebook shows an overview over all cvloop '",
",",
"'functions provided in the [`cvloop.functions` module]('",
",",
"'https://github.com/shoeffner/cvloop/blob/'",
",",
"'develop/cvloop/functions.py).'",
"]",
"}",
",",
"]",
",",
"'nbformat'",
":",
"4",
",",
"'nbformat_minor'",
":",
"1",
",",
"'metadata'",
":",
"{",
"'language_info'",
":",
"{",
"'codemirror_mode'",
":",
"{",
"'name'",
":",
"'ipython'",
",",
"'version'",
":",
"3",
"}",
",",
"'file_extension'",
":",
"'.py'",
",",
"'mimetype'",
":",
"'text/x-python'",
",",
"'name'",
":",
"'python'",
",",
"'nbconvert_exporter'",
":",
"'python'",
",",
"'pygments_lexer'",
":",
"'ipython3'",
",",
"'version'",
":",
"'3.5.1+'",
"}",
"}",
"}",
"classes",
"=",
"list_classes",
"(",
"'cvloop.functions'",
")",
"functions",
"=",
"list_functions",
"(",
"'cvloop.functions'",
")",
"line_numbers_cls",
"=",
"get_linenumbers",
"(",
"classes",
",",
"cvloop",
".",
"functions",
",",
"'class {}:\\n'",
")",
"line_numbers",
"=",
"get_linenumbers",
"(",
"functions",
",",
"cvloop",
".",
"functions",
")",
"for",
"cls",
"in",
"classes",
":",
"line_number",
"=",
"line_numbers_cls",
"[",
"cls",
"]",
"notebook",
"[",
"'cells'",
"]",
".",
"append",
"(",
"create_description_cell",
"(",
"cls",
",",
"line_number",
")",
")",
"notebook",
"[",
"'cells'",
"]",
".",
"append",
"(",
"create_code_cell",
"(",
"cls",
",",
"isclass",
"=",
"True",
")",
")",
"for",
"func",
"in",
"functions",
":",
"line_number",
"=",
"line_numbers",
"[",
"func",
"]",
"notebook",
"[",
"'cells'",
"]",
".",
"append",
"(",
"create_description_cell",
"(",
"func",
",",
"line_number",
")",
")",
"notebook",
"[",
"'cells'",
"]",
".",
"append",
"(",
"create_code_cell",
"(",
"func",
")",
")",
"with",
"open",
"(",
"sys",
".",
"argv",
"[",
"1",
"]",
",",
"'w'",
")",
"as",
"nfile",
":",
"json",
".",
"dump",
"(",
"notebook",
",",
"nfile",
",",
"indent",
"=",
"4",
")"
] |
Main function creates the cvloop.functions example notebook.
|
[
"Main",
"function",
"creates",
"the",
"cvloop",
".",
"functions",
"example",
"notebook",
"."
] |
3ddd311e9b679d16c8fd36779931380374de343c
|
https://github.com/shoeffner/cvloop/blob/3ddd311e9b679d16c8fd36779931380374de343c/tools/create_functions_ipynb.py#L161-L212
|
train
|
shoeffner/cvloop
|
cvloop/cvloop.py
|
prepare_axes
|
def prepare_axes(axes, title, size, cmap=None):
"""Prepares an axes object for clean plotting.
Removes x and y axes labels and ticks, sets the aspect ratio to be
equal, uses the size to determine the drawing area and fills the image
with random colors as visual feedback.
Creates an AxesImage to be shown inside the axes object and sets the
needed properties.
Args:
axes: The axes object to modify.
title: The title.
size: The size of the expected image.
cmap: The colormap if a custom color map is needed.
(Default: None)
Returns:
The AxesImage's handle.
"""
if axes is None:
return None
# prepare axis itself
axes.set_xlim([0, size[1]])
axes.set_ylim([size[0], 0])
axes.set_aspect('equal')
axes.axis('off')
if isinstance(cmap, str):
title = '{} (cmap: {})'.format(title, cmap)
axes.set_title(title)
# prepare image data
axes_image = image.AxesImage(axes, cmap=cmap,
extent=(0, size[1], size[0], 0))
axes_image.set_data(np.random.random((size[0], size[1], 3)))
axes.add_image(axes_image)
return axes_image
|
python
|
def prepare_axes(axes, title, size, cmap=None):
"""Prepares an axes object for clean plotting.
Removes x and y axes labels and ticks, sets the aspect ratio to be
equal, uses the size to determine the drawing area and fills the image
with random colors as visual feedback.
Creates an AxesImage to be shown inside the axes object and sets the
needed properties.
Args:
axes: The axes object to modify.
title: The title.
size: The size of the expected image.
cmap: The colormap if a custom color map is needed.
(Default: None)
Returns:
The AxesImage's handle.
"""
if axes is None:
return None
# prepare axis itself
axes.set_xlim([0, size[1]])
axes.set_ylim([size[0], 0])
axes.set_aspect('equal')
axes.axis('off')
if isinstance(cmap, str):
title = '{} (cmap: {})'.format(title, cmap)
axes.set_title(title)
# prepare image data
axes_image = image.AxesImage(axes, cmap=cmap,
extent=(0, size[1], size[0], 0))
axes_image.set_data(np.random.random((size[0], size[1], 3)))
axes.add_image(axes_image)
return axes_image
|
[
"def",
"prepare_axes",
"(",
"axes",
",",
"title",
",",
"size",
",",
"cmap",
"=",
"None",
")",
":",
"if",
"axes",
"is",
"None",
":",
"return",
"None",
"# prepare axis itself",
"axes",
".",
"set_xlim",
"(",
"[",
"0",
",",
"size",
"[",
"1",
"]",
"]",
")",
"axes",
".",
"set_ylim",
"(",
"[",
"size",
"[",
"0",
"]",
",",
"0",
"]",
")",
"axes",
".",
"set_aspect",
"(",
"'equal'",
")",
"axes",
".",
"axis",
"(",
"'off'",
")",
"if",
"isinstance",
"(",
"cmap",
",",
"str",
")",
":",
"title",
"=",
"'{} (cmap: {})'",
".",
"format",
"(",
"title",
",",
"cmap",
")",
"axes",
".",
"set_title",
"(",
"title",
")",
"# prepare image data",
"axes_image",
"=",
"image",
".",
"AxesImage",
"(",
"axes",
",",
"cmap",
"=",
"cmap",
",",
"extent",
"=",
"(",
"0",
",",
"size",
"[",
"1",
"]",
",",
"size",
"[",
"0",
"]",
",",
"0",
")",
")",
"axes_image",
".",
"set_data",
"(",
"np",
".",
"random",
".",
"random",
"(",
"(",
"size",
"[",
"0",
"]",
",",
"size",
"[",
"1",
"]",
",",
"3",
")",
")",
")",
"axes",
".",
"add_image",
"(",
"axes_image",
")",
"return",
"axes_image"
] |
Prepares an axes object for clean plotting.
Removes x and y axes labels and ticks, sets the aspect ratio to be
equal, uses the size to determine the drawing area and fills the image
with random colors as visual feedback.
Creates an AxesImage to be shown inside the axes object and sets the
needed properties.
Args:
axes: The axes object to modify.
title: The title.
size: The size of the expected image.
cmap: The colormap if a custom color map is needed.
(Default: None)
Returns:
The AxesImage's handle.
|
[
"Prepares",
"an",
"axes",
"object",
"for",
"clean",
"plotting",
"."
] |
3ddd311e9b679d16c8fd36779931380374de343c
|
https://github.com/shoeffner/cvloop/blob/3ddd311e9b679d16c8fd36779931380374de343c/cvloop/cvloop.py#L29-L67
|
train
|
shoeffner/cvloop
|
cvloop/cvloop.py
|
cvloop.connect_event_handlers
|
def connect_event_handlers(self):
"""Connects event handlers to the figure."""
self.figure.canvas.mpl_connect('close_event', self.evt_release)
self.figure.canvas.mpl_connect('pause_event', self.evt_toggle_pause)
|
python
|
def connect_event_handlers(self):
"""Connects event handlers to the figure."""
self.figure.canvas.mpl_connect('close_event', self.evt_release)
self.figure.canvas.mpl_connect('pause_event', self.evt_toggle_pause)
|
[
"def",
"connect_event_handlers",
"(",
"self",
")",
":",
"self",
".",
"figure",
".",
"canvas",
".",
"mpl_connect",
"(",
"'close_event'",
",",
"self",
".",
"evt_release",
")",
"self",
".",
"figure",
".",
"canvas",
".",
"mpl_connect",
"(",
"'pause_event'",
",",
"self",
".",
"evt_toggle_pause",
")"
] |
Connects event handlers to the figure.
|
[
"Connects",
"event",
"handlers",
"to",
"the",
"figure",
"."
] |
3ddd311e9b679d16c8fd36779931380374de343c
|
https://github.com/shoeffner/cvloop/blob/3ddd311e9b679d16c8fd36779931380374de343c/cvloop/cvloop.py#L237-L240
|
train
|
shoeffner/cvloop
|
cvloop/cvloop.py
|
cvloop.evt_toggle_pause
|
def evt_toggle_pause(self, *args): # pylint: disable=unused-argument
"""Pauses and resumes the video source."""
if self.event_source._timer is None: # noqa: e501 pylint: disable=protected-access
self.event_source.start()
else:
self.event_source.stop()
|
python
|
def evt_toggle_pause(self, *args): # pylint: disable=unused-argument
"""Pauses and resumes the video source."""
if self.event_source._timer is None: # noqa: e501 pylint: disable=protected-access
self.event_source.start()
else:
self.event_source.stop()
|
[
"def",
"evt_toggle_pause",
"(",
"self",
",",
"*",
"args",
")",
":",
"# pylint: disable=unused-argument",
"if",
"self",
".",
"event_source",
".",
"_timer",
"is",
"None",
":",
"# noqa: e501 pylint: disable=protected-access",
"self",
".",
"event_source",
".",
"start",
"(",
")",
"else",
":",
"self",
".",
"event_source",
".",
"stop",
"(",
")"
] |
Pauses and resumes the video source.
|
[
"Pauses",
"and",
"resumes",
"the",
"video",
"source",
"."
] |
3ddd311e9b679d16c8fd36779931380374de343c
|
https://github.com/shoeffner/cvloop/blob/3ddd311e9b679d16c8fd36779931380374de343c/cvloop/cvloop.py#L249-L254
|
train
|
shoeffner/cvloop
|
cvloop/cvloop.py
|
cvloop.print_info
|
def print_info(self, capture):
"""Prints information about the unprocessed image.
Reads one frame from the source to determine image colors, dimensions
and data types.
Args:
capture: the source to read from.
"""
self.frame_offset += 1
ret, frame = capture.read()
if ret:
print('Capture Information')
print('\tDimensions (HxW): {}x{}'.format(*frame.shape[0:2]))
print('\tColor channels: {}'.format(frame.shape[2] if
len(frame.shape) > 2 else 1))
print('\tColor range: {}-{}'.format(np.min(frame),
np.max(frame)))
print('\tdtype: {}'.format(frame.dtype))
else:
print('No source found.')
|
python
|
def print_info(self, capture):
"""Prints information about the unprocessed image.
Reads one frame from the source to determine image colors, dimensions
and data types.
Args:
capture: the source to read from.
"""
self.frame_offset += 1
ret, frame = capture.read()
if ret:
print('Capture Information')
print('\tDimensions (HxW): {}x{}'.format(*frame.shape[0:2]))
print('\tColor channels: {}'.format(frame.shape[2] if
len(frame.shape) > 2 else 1))
print('\tColor range: {}-{}'.format(np.min(frame),
np.max(frame)))
print('\tdtype: {}'.format(frame.dtype))
else:
print('No source found.')
|
[
"def",
"print_info",
"(",
"self",
",",
"capture",
")",
":",
"self",
".",
"frame_offset",
"+=",
"1",
"ret",
",",
"frame",
"=",
"capture",
".",
"read",
"(",
")",
"if",
"ret",
":",
"print",
"(",
"'Capture Information'",
")",
"print",
"(",
"'\\tDimensions (HxW): {}x{}'",
".",
"format",
"(",
"*",
"frame",
".",
"shape",
"[",
"0",
":",
"2",
"]",
")",
")",
"print",
"(",
"'\\tColor channels: {}'",
".",
"format",
"(",
"frame",
".",
"shape",
"[",
"2",
"]",
"if",
"len",
"(",
"frame",
".",
"shape",
")",
">",
"2",
"else",
"1",
")",
")",
"print",
"(",
"'\\tColor range: {}-{}'",
".",
"format",
"(",
"np",
".",
"min",
"(",
"frame",
")",
",",
"np",
".",
"max",
"(",
"frame",
")",
")",
")",
"print",
"(",
"'\\tdtype: {}'",
".",
"format",
"(",
"frame",
".",
"dtype",
")",
")",
"else",
":",
"print",
"(",
"'No source found.'",
")"
] |
Prints information about the unprocessed image.
Reads one frame from the source to determine image colors, dimensions
and data types.
Args:
capture: the source to read from.
|
[
"Prints",
"information",
"about",
"the",
"unprocessed",
"image",
"."
] |
3ddd311e9b679d16c8fd36779931380374de343c
|
https://github.com/shoeffner/cvloop/blob/3ddd311e9b679d16c8fd36779931380374de343c/cvloop/cvloop.py#L256-L276
|
train
|
shoeffner/cvloop
|
cvloop/cvloop.py
|
cvloop.determine_size
|
def determine_size(self, capture):
"""Determines the height and width of the image source.
If no dimensions are available, this method defaults to a resolution of
640x480, thus returns (480, 640).
If capture has a get method it is assumed to understand
`cv2.CAP_PROP_FRAME_WIDTH` and `cv2.CAP_PROP_FRAME_HEIGHT` to get the
information. Otherwise it reads one frame from the source to determine
image dimensions.
Args:
capture: the source to read from.
Returns:
A tuple containing integers of height and width (simple casts).
"""
width = 640
height = 480
if capture and hasattr(capture, 'get'):
width = capture.get(cv2.CAP_PROP_FRAME_WIDTH)
height = capture.get(cv2.CAP_PROP_FRAME_HEIGHT)
else:
self.frame_offset += 1
ret, frame = capture.read()
if ret:
width = frame.shape[1]
height = frame.shape[0]
return (int(height), int(width))
|
python
|
def determine_size(self, capture):
"""Determines the height and width of the image source.
If no dimensions are available, this method defaults to a resolution of
640x480, thus returns (480, 640).
If capture has a get method it is assumed to understand
`cv2.CAP_PROP_FRAME_WIDTH` and `cv2.CAP_PROP_FRAME_HEIGHT` to get the
information. Otherwise it reads one frame from the source to determine
image dimensions.
Args:
capture: the source to read from.
Returns:
A tuple containing integers of height and width (simple casts).
"""
width = 640
height = 480
if capture and hasattr(capture, 'get'):
width = capture.get(cv2.CAP_PROP_FRAME_WIDTH)
height = capture.get(cv2.CAP_PROP_FRAME_HEIGHT)
else:
self.frame_offset += 1
ret, frame = capture.read()
if ret:
width = frame.shape[1]
height = frame.shape[0]
return (int(height), int(width))
|
[
"def",
"determine_size",
"(",
"self",
",",
"capture",
")",
":",
"width",
"=",
"640",
"height",
"=",
"480",
"if",
"capture",
"and",
"hasattr",
"(",
"capture",
",",
"'get'",
")",
":",
"width",
"=",
"capture",
".",
"get",
"(",
"cv2",
".",
"CAP_PROP_FRAME_WIDTH",
")",
"height",
"=",
"capture",
".",
"get",
"(",
"cv2",
".",
"CAP_PROP_FRAME_HEIGHT",
")",
"else",
":",
"self",
".",
"frame_offset",
"+=",
"1",
"ret",
",",
"frame",
"=",
"capture",
".",
"read",
"(",
")",
"if",
"ret",
":",
"width",
"=",
"frame",
".",
"shape",
"[",
"1",
"]",
"height",
"=",
"frame",
".",
"shape",
"[",
"0",
"]",
"return",
"(",
"int",
"(",
"height",
")",
",",
"int",
"(",
"width",
")",
")"
] |
Determines the height and width of the image source.
If no dimensions are available, this method defaults to a resolution of
640x480, thus returns (480, 640).
If capture has a get method it is assumed to understand
`cv2.CAP_PROP_FRAME_WIDTH` and `cv2.CAP_PROP_FRAME_HEIGHT` to get the
information. Otherwise it reads one frame from the source to determine
image dimensions.
Args:
capture: the source to read from.
Returns:
A tuple containing integers of height and width (simple casts).
|
[
"Determines",
"the",
"height",
"and",
"width",
"of",
"the",
"image",
"source",
"."
] |
3ddd311e9b679d16c8fd36779931380374de343c
|
https://github.com/shoeffner/cvloop/blob/3ddd311e9b679d16c8fd36779931380374de343c/cvloop/cvloop.py#L278-L305
|
train
|
shoeffner/cvloop
|
cvloop/cvloop.py
|
cvloop._init_draw
|
def _init_draw(self):
"""Initializes the drawing of the frames by setting the images to
random colors.
This function is called by TimedAnimation.
"""
if self.original is not None:
self.original.set_data(np.random.random((10, 10, 3)))
self.processed.set_data(np.random.random((10, 10, 3)))
|
python
|
def _init_draw(self):
"""Initializes the drawing of the frames by setting the images to
random colors.
This function is called by TimedAnimation.
"""
if self.original is not None:
self.original.set_data(np.random.random((10, 10, 3)))
self.processed.set_data(np.random.random((10, 10, 3)))
|
[
"def",
"_init_draw",
"(",
"self",
")",
":",
"if",
"self",
".",
"original",
"is",
"not",
"None",
":",
"self",
".",
"original",
".",
"set_data",
"(",
"np",
".",
"random",
".",
"random",
"(",
"(",
"10",
",",
"10",
",",
"3",
")",
")",
")",
"self",
".",
"processed",
".",
"set_data",
"(",
"np",
".",
"random",
".",
"random",
"(",
"(",
"10",
",",
"10",
",",
"3",
")",
")",
")"
] |
Initializes the drawing of the frames by setting the images to
random colors.
This function is called by TimedAnimation.
|
[
"Initializes",
"the",
"drawing",
"of",
"the",
"frames",
"by",
"setting",
"the",
"images",
"to",
"random",
"colors",
"."
] |
3ddd311e9b679d16c8fd36779931380374de343c
|
https://github.com/shoeffner/cvloop/blob/3ddd311e9b679d16c8fd36779931380374de343c/cvloop/cvloop.py#L320-L328
|
train
|
shoeffner/cvloop
|
cvloop/cvloop.py
|
cvloop.read_frame
|
def read_frame(self):
"""Reads a frame and converts the color if needed.
In case no frame is available, i.e. self.capture.read() returns False
as the first return value, the event_source of the TimedAnimation is
stopped, and if possible the capture source released.
Returns:
None if stopped, otherwise the color converted source image.
"""
ret, frame = self.capture.read()
if not ret:
self.event_source.stop()
try:
self.capture.release()
except AttributeError:
# has no release method, thus just pass
pass
return None
if self.convert_color != -1 and is_color_image(frame):
return cv2.cvtColor(frame, self.convert_color)
return frame
|
python
|
def read_frame(self):
"""Reads a frame and converts the color if needed.
In case no frame is available, i.e. self.capture.read() returns False
as the first return value, the event_source of the TimedAnimation is
stopped, and if possible the capture source released.
Returns:
None if stopped, otherwise the color converted source image.
"""
ret, frame = self.capture.read()
if not ret:
self.event_source.stop()
try:
self.capture.release()
except AttributeError:
# has no release method, thus just pass
pass
return None
if self.convert_color != -1 and is_color_image(frame):
return cv2.cvtColor(frame, self.convert_color)
return frame
|
[
"def",
"read_frame",
"(",
"self",
")",
":",
"ret",
",",
"frame",
"=",
"self",
".",
"capture",
".",
"read",
"(",
")",
"if",
"not",
"ret",
":",
"self",
".",
"event_source",
".",
"stop",
"(",
")",
"try",
":",
"self",
".",
"capture",
".",
"release",
"(",
")",
"except",
"AttributeError",
":",
"# has no release method, thus just pass",
"pass",
"return",
"None",
"if",
"self",
".",
"convert_color",
"!=",
"-",
"1",
"and",
"is_color_image",
"(",
"frame",
")",
":",
"return",
"cv2",
".",
"cvtColor",
"(",
"frame",
",",
"self",
".",
"convert_color",
")",
"return",
"frame"
] |
Reads a frame and converts the color if needed.
In case no frame is available, i.e. self.capture.read() returns False
as the first return value, the event_source of the TimedAnimation is
stopped, and if possible the capture source released.
Returns:
None if stopped, otherwise the color converted source image.
|
[
"Reads",
"a",
"frame",
"and",
"converts",
"the",
"color",
"if",
"needed",
"."
] |
3ddd311e9b679d16c8fd36779931380374de343c
|
https://github.com/shoeffner/cvloop/blob/3ddd311e9b679d16c8fd36779931380374de343c/cvloop/cvloop.py#L330-L351
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.