partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | BitCondition.cover | Create a new bit condition that matches the provided bit string,
with the indicated per-index wildcard probability.
Usage:
condition = BitCondition.cover(bitstring, .33)
assert condition(bitstring)
Arguments:
bits: A BitString which the resulting condition m... | xcs/bitstrings.py | def cover(cls, bits, wildcard_probability):
"""Create a new bit condition that matches the provided bit string,
with the indicated per-index wildcard probability.
Usage:
condition = BitCondition.cover(bitstring, .33)
assert condition(bitstring)
Arguments:
... | def cover(cls, bits, wildcard_probability):
"""Create a new bit condition that matches the provided bit string,
with the indicated per-index wildcard probability.
Usage:
condition = BitCondition.cover(bitstring, .33)
assert condition(bitstring)
Arguments:
... | [
"Create",
"a",
"new",
"bit",
"condition",
"that",
"matches",
"the",
"provided",
"bit",
"string",
"with",
"the",
"indicated",
"per",
"-",
"index",
"wildcard",
"probability",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/bitstrings.py#L455-L480 | [
"def",
"cover",
"(",
"cls",
",",
"bits",
",",
"wildcard_probability",
")",
":",
"if",
"not",
"isinstance",
"(",
"bits",
",",
"BitString",
")",
":",
"bits",
"=",
"BitString",
"(",
"bits",
")",
"mask",
"=",
"BitString",
"(",
"[",
"random",
".",
"random",... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | BitCondition.crossover_with | Perform 2-point crossover on this bit condition and another of
the same length, returning the two resulting children.
Usage:
offspring1, offspring2 = condition1.crossover_with(condition2)
Arguments:
other: A second BitCondition of the same length as this one.
... | xcs/bitstrings.py | def crossover_with(self, other, points=2):
"""Perform 2-point crossover on this bit condition and another of
the same length, returning the two resulting children.
Usage:
offspring1, offspring2 = condition1.crossover_with(condition2)
Arguments:
other: A second B... | def crossover_with(self, other, points=2):
"""Perform 2-point crossover on this bit condition and another of
the same length, returning the two resulting children.
Usage:
offspring1, offspring2 = condition1.crossover_with(condition2)
Arguments:
other: A second B... | [
"Perform",
"2",
"-",
"point",
"crossover",
"on",
"this",
"bit",
"condition",
"and",
"another",
"of",
"the",
"same",
"length",
"returning",
"the",
"two",
"resulting",
"children",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/bitstrings.py#L652-L682 | [
"def",
"crossover_with",
"(",
"self",
",",
"other",
",",
"points",
"=",
"2",
")",
":",
"assert",
"isinstance",
"(",
"other",
",",
"BitCondition",
")",
"assert",
"len",
"(",
"self",
")",
"==",
"len",
"(",
"other",
")",
"template",
"=",
"BitString",
".",... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | BrokerConnection.get_backend_cls | Get the currently used backend class. | carrot/connection.py | def get_backend_cls(self):
"""Get the currently used backend class."""
backend_cls = self.backend_cls
if not backend_cls or isinstance(backend_cls, basestring):
backend_cls = get_backend_cls(backend_cls)
return backend_cls | def get_backend_cls(self):
"""Get the currently used backend class."""
backend_cls = self.backend_cls
if not backend_cls or isinstance(backend_cls, basestring):
backend_cls = get_backend_cls(backend_cls)
return backend_cls | [
"Get",
"the",
"currently",
"used",
"backend",
"class",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/connection.py#L152-L157 | [
"def",
"get_backend_cls",
"(",
"self",
")",
":",
"backend_cls",
"=",
"self",
".",
"backend_cls",
"if",
"not",
"backend_cls",
"or",
"isinstance",
"(",
"backend_cls",
",",
"basestring",
")",
":",
"backend_cls",
"=",
"get_backend_cls",
"(",
"backend_cls",
")",
"r... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | BrokerConnection.ensure_connection | Ensure we have a connection to the server.
If not retry establishing the connection with the settings
specified.
:keyword errback: Optional callback called each time the connection
can't be established. Arguments provided are the exception
raised and the interval that will ... | carrot/connection.py | def ensure_connection(self, errback=None, max_retries=None,
interval_start=2, interval_step=2, interval_max=30):
"""Ensure we have a connection to the server.
If not retry establishing the connection with the settings
specified.
:keyword errback: Optional callback called ea... | def ensure_connection(self, errback=None, max_retries=None,
interval_start=2, interval_step=2, interval_max=30):
"""Ensure we have a connection to the server.
If not retry establishing the connection with the settings
specified.
:keyword errback: Optional callback called ea... | [
"Ensure",
"we",
"have",
"a",
"connection",
"to",
"the",
"server",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/connection.py#L181-L205 | [
"def",
"ensure_connection",
"(",
"self",
",",
"errback",
"=",
"None",
",",
"max_retries",
"=",
"None",
",",
"interval_start",
"=",
"2",
",",
"interval_step",
"=",
"2",
",",
"interval_max",
"=",
"30",
")",
":",
"retry_over_time",
"(",
"self",
".",
"connect"... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | BrokerConnection.close | Close the currently open connection. | carrot/connection.py | def close(self):
"""Close the currently open connection."""
try:
if self._connection:
backend = self.create_backend()
backend.close_connection(self._connection)
except socket.error:
pass
self._closed = True | def close(self):
"""Close the currently open connection."""
try:
if self._connection:
backend = self.create_backend()
backend.close_connection(self._connection)
except socket.error:
pass
self._closed = True | [
"Close",
"the",
"currently",
"open",
"connection",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/connection.py#L207-L215 | [
"def",
"close",
"(",
"self",
")",
":",
"try",
":",
"if",
"self",
".",
"_connection",
":",
"backend",
"=",
"self",
".",
"create_backend",
"(",
")",
"backend",
".",
"close_connection",
"(",
"self",
".",
"_connection",
")",
"except",
"socket",
".",
"error",... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | BrokerConnection.info | Get connection info. | carrot/connection.py | def info(self):
"""Get connection info."""
backend_cls = self.backend_cls or "amqplib"
port = self.port or self.create_backend().default_port
return {"hostname": self.hostname,
"userid": self.userid,
"password": self.password,
"virtual_host... | def info(self):
"""Get connection info."""
backend_cls = self.backend_cls or "amqplib"
port = self.port or self.create_backend().default_port
return {"hostname": self.hostname,
"userid": self.userid,
"password": self.password,
"virtual_host... | [
"Get",
"connection",
"info",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/connection.py#L223-L236 | [
"def",
"info",
"(",
"self",
")",
":",
"backend_cls",
"=",
"self",
".",
"backend_cls",
"or",
"\"amqplib\"",
"port",
"=",
"self",
".",
"port",
"or",
"self",
".",
"create_backend",
"(",
")",
".",
"default_port",
"return",
"{",
"\"hostname\"",
":",
"self",
"... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | BaseMessage.decode | Deserialize the message body, returning the original
python structure sent by the publisher. | carrot/backends/base.py | def decode(self):
"""Deserialize the message body, returning the original
python structure sent by the publisher."""
return serialization.decode(self.body, self.content_type,
self.content_encoding) | def decode(self):
"""Deserialize the message body, returning the original
python structure sent by the publisher."""
return serialization.decode(self.body, self.content_type,
self.content_encoding) | [
"Deserialize",
"the",
"message",
"body",
"returning",
"the",
"original",
"python",
"structure",
"sent",
"by",
"the",
"publisher",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/backends/base.py#L31-L35 | [
"def",
"decode",
"(",
"self",
")",
":",
"return",
"serialization",
".",
"decode",
"(",
"self",
".",
"body",
",",
"self",
".",
"content_type",
",",
"self",
".",
"content_encoding",
")"
] | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | BaseMessage.payload | The decoded message. | carrot/backends/base.py | def payload(self):
"""The decoded message."""
if not self._decoded_cache:
self._decoded_cache = self.decode()
return self._decoded_cache | def payload(self):
"""The decoded message."""
if not self._decoded_cache:
self._decoded_cache = self.decode()
return self._decoded_cache | [
"The",
"decoded",
"message",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/backends/base.py#L38-L42 | [
"def",
"payload",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_decoded_cache",
":",
"self",
".",
"_decoded_cache",
"=",
"self",
".",
"decode",
"(",
")",
"return",
"self",
".",
"_decoded_cache"
] | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | BaseMessage.ack | Acknowledge this message as being processed.,
This will remove the message from the queue.
:raises MessageStateError: If the message has already been
acknowledged/requeued/rejected. | carrot/backends/base.py | def ack(self):
"""Acknowledge this message as being processed.,
This will remove the message from the queue.
:raises MessageStateError: If the message has already been
acknowledged/requeued/rejected.
"""
if self.acknowledged:
raise self.MessageStateError... | def ack(self):
"""Acknowledge this message as being processed.,
This will remove the message from the queue.
:raises MessageStateError: If the message has already been
acknowledged/requeued/rejected.
"""
if self.acknowledged:
raise self.MessageStateError... | [
"Acknowledge",
"this",
"message",
"as",
"being",
"processed",
".",
"This",
"will",
"remove",
"the",
"message",
"from",
"the",
"queue",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/backends/base.py#L44-L56 | [
"def",
"ack",
"(",
"self",
")",
":",
"if",
"self",
".",
"acknowledged",
":",
"raise",
"self",
".",
"MessageStateError",
"(",
"\"Message already acknowledged with state: %s\"",
"%",
"self",
".",
"_state",
")",
"self",
".",
"backend",
".",
"ack",
"(",
"self",
... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | BaseMessage.reject | Reject this message.
The message will be discarded by the server.
:raises MessageStateError: If the message has already been
acknowledged/requeued/rejected. | carrot/backends/base.py | def reject(self):
"""Reject this message.
The message will be discarded by the server.
:raises MessageStateError: If the message has already been
acknowledged/requeued/rejected.
"""
if self.acknowledged:
raise self.MessageStateError(
"Me... | def reject(self):
"""Reject this message.
The message will be discarded by the server.
:raises MessageStateError: If the message has already been
acknowledged/requeued/rejected.
"""
if self.acknowledged:
raise self.MessageStateError(
"Me... | [
"Reject",
"this",
"message",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/backends/base.py#L58-L71 | [
"def",
"reject",
"(",
"self",
")",
":",
"if",
"self",
".",
"acknowledged",
":",
"raise",
"self",
".",
"MessageStateError",
"(",
"\"Message already acknowledged with state: %s\"",
"%",
"self",
".",
"_state",
")",
"self",
".",
"backend",
".",
"reject",
"(",
"sel... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | BaseMessage.requeue | Reject this message and put it back on the queue.
You must not use this method as a means of selecting messages
to process.
:raises MessageStateError: If the message has already been
acknowledged/requeued/rejected. | carrot/backends/base.py | def requeue(self):
"""Reject this message and put it back on the queue.
You must not use this method as a means of selecting messages
to process.
:raises MessageStateError: If the message has already been
acknowledged/requeued/rejected.
"""
if self.acknowle... | def requeue(self):
"""Reject this message and put it back on the queue.
You must not use this method as a means of selecting messages
to process.
:raises MessageStateError: If the message has already been
acknowledged/requeued/rejected.
"""
if self.acknowle... | [
"Reject",
"this",
"message",
"and",
"put",
"it",
"back",
"on",
"the",
"queue",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/backends/base.py#L73-L87 | [
"def",
"requeue",
"(",
"self",
")",
":",
"if",
"self",
".",
"acknowledged",
":",
"raise",
"self",
".",
"MessageStateError",
"(",
"\"Message already acknowledged with state: %s\"",
"%",
"self",
".",
"_state",
")",
"self",
".",
"backend",
".",
"requeue",
"(",
"s... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | gen_unique_id | Generate a unique id, having - hopefully - a very small chance of
collission.
For now this is provided by :func:`uuid.uuid4`. | carrot/utils.py | def gen_unique_id():
"""Generate a unique id, having - hopefully - a very small chance of
collission.
For now this is provided by :func:`uuid.uuid4`.
"""
# Workaround for http://bugs.python.org/issue4607
if ctypes and _uuid_generate_random:
buffer = ctypes.create_string_buffer(16)
... | def gen_unique_id():
"""Generate a unique id, having - hopefully - a very small chance of
collission.
For now this is provided by :func:`uuid.uuid4`.
"""
# Workaround for http://bugs.python.org/issue4607
if ctypes and _uuid_generate_random:
buffer = ctypes.create_string_buffer(16)
... | [
"Generate",
"a",
"unique",
"id",
"having",
"-",
"hopefully",
"-",
"a",
"very",
"small",
"chance",
"of",
"collission",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/utils.py#L8-L19 | [
"def",
"gen_unique_id",
"(",
")",
":",
"# Workaround for http://bugs.python.org/issue4607",
"if",
"ctypes",
"and",
"_uuid_generate_random",
":",
"buffer",
"=",
"ctypes",
".",
"create_string_buffer",
"(",
"16",
")",
"_uuid_generate_random",
"(",
"buffer",
")",
"return",
... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | retry_over_time | Retry the function over and over until max retries is exceeded.
For each retry we sleep a for a while before we try again, this interval
is increased for every retry until the max seconds is reached.
:param fun: The function to try
:param catch: Exceptions to catch, can be either tuple or a single
... | carrot/utils.py | def retry_over_time(fun, catch, args=[], kwargs={}, errback=None,
max_retries=None, interval_start=2, interval_step=2, interval_max=30):
"""Retry the function over and over until max retries is exceeded.
For each retry we sleep a for a while before we try again, this interval
is increased for every... | def retry_over_time(fun, catch, args=[], kwargs={}, errback=None,
max_retries=None, interval_start=2, interval_step=2, interval_max=30):
"""Retry the function over and over until max retries is exceeded.
For each retry we sleep a for a while before we try again, this interval
is increased for every... | [
"Retry",
"the",
"function",
"over",
"and",
"over",
"until",
"max",
"retries",
"is",
"exceeded",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/utils.py#L78-L118 | [
"def",
"retry_over_time",
"(",
"fun",
",",
"catch",
",",
"args",
"=",
"[",
"]",
",",
"kwargs",
"=",
"{",
"}",
",",
"errback",
"=",
"None",
",",
"max_retries",
"=",
"None",
",",
"interval_start",
"=",
"2",
",",
"interval_step",
"=",
"2",
",",
"interva... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Backend.get | Get the next waiting message from the queue.
:returns: A :class:`Message` instance, or ``None`` if there is
no messages waiting. | carrot/backends/queue.py | def get(self, *args, **kwargs):
"""Get the next waiting message from the queue.
:returns: A :class:`Message` instance, or ``None`` if there is
no messages waiting.
"""
if not mqueue.qsize():
return None
message_data, content_type, content_encoding = mque... | def get(self, *args, **kwargs):
"""Get the next waiting message from the queue.
:returns: A :class:`Message` instance, or ``None`` if there is
no messages waiting.
"""
if not mqueue.qsize():
return None
message_data, content_type, content_encoding = mque... | [
"Get",
"the",
"next",
"waiting",
"message",
"from",
"the",
"queue",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/backends/queue.py#L33-L45 | [
"def",
"get",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"mqueue",
".",
"qsize",
"(",
")",
":",
"return",
"None",
"message_data",
",",
"content_type",
",",
"content_encoding",
"=",
"mqueue",
".",
"get",
"(",
")",
... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Backend.queue_purge | Discard all messages in the queue. | carrot/backends/queue.py | def queue_purge(self, queue, **kwargs):
"""Discard all messages in the queue."""
qsize = mqueue.qsize()
mqueue.queue.clear()
return qsize | def queue_purge(self, queue, **kwargs):
"""Discard all messages in the queue."""
qsize = mqueue.qsize()
mqueue.queue.clear()
return qsize | [
"Discard",
"all",
"messages",
"in",
"the",
"queue",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/backends/queue.py#L74-L78 | [
"def",
"queue_purge",
"(",
"self",
",",
"queue",
",",
"*",
"*",
"kwargs",
")",
":",
"qsize",
"=",
"mqueue",
".",
"qsize",
"(",
")",
"mqueue",
".",
"queue",
".",
"clear",
"(",
")",
"return",
"qsize"
] | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Backend.prepare_message | Prepare message for sending. | carrot/backends/queue.py | def prepare_message(self, message_data, delivery_mode,
content_type, content_encoding, **kwargs):
"""Prepare message for sending."""
return (message_data, content_type, content_encoding) | def prepare_message(self, message_data, delivery_mode,
content_type, content_encoding, **kwargs):
"""Prepare message for sending."""
return (message_data, content_type, content_encoding) | [
"Prepare",
"message",
"for",
"sending",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/backends/queue.py#L80-L83 | [
"def",
"prepare_message",
"(",
"self",
",",
"message_data",
",",
"delivery_mode",
",",
"content_type",
",",
"content_encoding",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"(",
"message_data",
",",
"content_type",
",",
"content_encoding",
")"
] | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | XCSAlgorithm.get_future_expectation | Return a numerical value representing the expected future payoff
of the previously selected action, given only the current match
set. The match_set argument is a MatchSet instance representing the
current match set.
Usage:
match_set = model.match(situation)
expec... | xcs/algorithms/xcs.py | def get_future_expectation(self, match_set):
"""Return a numerical value representing the expected future payoff
of the previously selected action, given only the current match
set. The match_set argument is a MatchSet instance representing the
current match set.
Usage:
... | def get_future_expectation(self, match_set):
"""Return a numerical value representing the expected future payoff
of the previously selected action, given only the current match
set. The match_set argument is a MatchSet instance representing the
current match set.
Usage:
... | [
"Return",
"a",
"numerical",
"value",
"representing",
"the",
"expected",
"future",
"payoff",
"of",
"the",
"previously",
"selected",
"action",
"given",
"only",
"the",
"current",
"match",
"set",
".",
"The",
"match_set",
"argument",
"is",
"a",
"MatchSet",
"instance"... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/algorithms/xcs.py#L383-L408 | [
"def",
"get_future_expectation",
"(",
"self",
",",
"match_set",
")",
":",
"assert",
"isinstance",
"(",
"match_set",
",",
"MatchSet",
")",
"assert",
"match_set",
".",
"algorithm",
"is",
"self",
"return",
"self",
".",
"discount_factor",
"*",
"(",
"self",
".",
... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | XCSAlgorithm.covering_is_required | Return a Boolean indicating whether covering is required for the
current match set. The match_set argument is a MatchSet instance
representing the current match set before covering is applied.
Usage:
match_set = model.match(situation)
if model.algorithm.covering_is_requi... | xcs/algorithms/xcs.py | def covering_is_required(self, match_set):
"""Return a Boolean indicating whether covering is required for the
current match set. The match_set argument is a MatchSet instance
representing the current match set before covering is applied.
Usage:
match_set = model.match(situa... | def covering_is_required(self, match_set):
"""Return a Boolean indicating whether covering is required for the
current match set. The match_set argument is a MatchSet instance
representing the current match set before covering is applied.
Usage:
match_set = model.match(situa... | [
"Return",
"a",
"Boolean",
"indicating",
"whether",
"covering",
"is",
"required",
"for",
"the",
"current",
"match",
"set",
".",
"The",
"match_set",
"argument",
"is",
"a",
"MatchSet",
"instance",
"representing",
"the",
"current",
"match",
"set",
"before",
"coverin... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/algorithms/xcs.py#L410-L436 | [
"def",
"covering_is_required",
"(",
"self",
",",
"match_set",
")",
":",
"assert",
"isinstance",
"(",
"match_set",
",",
"MatchSet",
")",
"assert",
"match_set",
".",
"algorithm",
"is",
"self",
"if",
"self",
".",
"minimum_actions",
"is",
"None",
":",
"return",
... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | XCSAlgorithm.cover | Return a new classifier rule that can be added to the match set,
with a condition that matches the situation of the match set and an
action selected to avoid duplication of the actions already
contained therein. The match_set argument is a MatchSet instance
representing the match set to ... | xcs/algorithms/xcs.py | def cover(self, match_set):
"""Return a new classifier rule that can be added to the match set,
with a condition that matches the situation of the match set and an
action selected to avoid duplication of the actions already
contained therein. The match_set argument is a MatchSet instance... | def cover(self, match_set):
"""Return a new classifier rule that can be added to the match set,
with a condition that matches the situation of the match set and an
action selected to avoid duplication of the actions already
contained therein. The match_set argument is a MatchSet instance... | [
"Return",
"a",
"new",
"classifier",
"rule",
"that",
"can",
"be",
"added",
"to",
"the",
"match",
"set",
"with",
"a",
"condition",
"that",
"matches",
"the",
"situation",
"of",
"the",
"match",
"set",
"and",
"an",
"action",
"selected",
"to",
"avoid",
"duplicat... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/algorithms/xcs.py#L438-L486 | [
"def",
"cover",
"(",
"self",
",",
"match_set",
")",
":",
"assert",
"isinstance",
"(",
"match_set",
",",
"MatchSet",
")",
"assert",
"match_set",
".",
"model",
".",
"algorithm",
"is",
"self",
"# Create a new condition that matches the situation.",
"condition",
"=",
... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | XCSAlgorithm.distribute_payoff | Distribute the payoff received in response to the selected
action of the given match set among the rules in the action set
which deserve credit for recommending the action. The match_set
argument is the MatchSet instance which suggested the selected
action and earned the payoff.
... | xcs/algorithms/xcs.py | def distribute_payoff(self, match_set):
"""Distribute the payoff received in response to the selected
action of the given match set among the rules in the action set
which deserve credit for recommending the action. The match_set
argument is the MatchSet instance which suggested the sele... | def distribute_payoff(self, match_set):
"""Distribute the payoff received in response to the selected
action of the given match set among the rules in the action set
which deserve credit for recommending the action. The match_set
argument is the MatchSet instance which suggested the sele... | [
"Distribute",
"the",
"payoff",
"received",
"in",
"response",
"to",
"the",
"selected",
"action",
"of",
"the",
"given",
"match",
"set",
"among",
"the",
"rules",
"in",
"the",
"action",
"set",
"which",
"deserve",
"credit",
"for",
"recommending",
"the",
"action",
... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/algorithms/xcs.py#L488-L544 | [
"def",
"distribute_payoff",
"(",
"self",
",",
"match_set",
")",
":",
"assert",
"isinstance",
"(",
"match_set",
",",
"MatchSet",
")",
"assert",
"match_set",
".",
"algorithm",
"is",
"self",
"assert",
"match_set",
".",
"selected_action",
"is",
"not",
"None",
"pay... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | XCSAlgorithm.update | Update the classifier set from which the match set was drawn,
e.g. by applying a genetic algorithm. The match_set argument is the
MatchSet instance whose classifier set should be updated.
Usage:
match_set = model.match(situation)
match_set.select_action()
mat... | xcs/algorithms/xcs.py | def update(self, match_set):
"""Update the classifier set from which the match set was drawn,
e.g. by applying a genetic algorithm. The match_set argument is the
MatchSet instance whose classifier set should be updated.
Usage:
match_set = model.match(situation)
m... | def update(self, match_set):
"""Update the classifier set from which the match set was drawn,
e.g. by applying a genetic algorithm. The match_set argument is the
MatchSet instance whose classifier set should be updated.
Usage:
match_set = model.match(situation)
m... | [
"Update",
"the",
"classifier",
"set",
"from",
"which",
"the",
"match",
"set",
"was",
"drawn",
"e",
".",
"g",
".",
"by",
"applying",
"a",
"genetic",
"algorithm",
".",
"The",
"match_set",
"argument",
"is",
"the",
"MatchSet",
"instance",
"whose",
"classifier",
... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/algorithms/xcs.py#L546-L676 | [
"def",
"update",
"(",
"self",
",",
"match_set",
")",
":",
"assert",
"isinstance",
"(",
"match_set",
",",
"MatchSet",
")",
"assert",
"match_set",
".",
"model",
".",
"algorithm",
"is",
"self",
"assert",
"match_set",
".",
"selected_action",
"is",
"not",
"None",... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | XCSAlgorithm.prune | Reduce the classifier set's population size, if necessary, by
removing lower-quality *rules. Return a list containing any rules
whose numerosities dropped to zero as a result of this call. (The
list may be empty, if no rule's numerosity dropped to 0.) The
model argument is a ClassifierSe... | xcs/algorithms/xcs.py | def prune(self, model):
"""Reduce the classifier set's population size, if necessary, by
removing lower-quality *rules. Return a list containing any rules
whose numerosities dropped to zero as a result of this call. (The
list may be empty, if no rule's numerosity dropped to 0.) The
... | def prune(self, model):
"""Reduce the classifier set's population size, if necessary, by
removing lower-quality *rules. Return a list containing any rules
whose numerosities dropped to zero as a result of this call. (The
list may be empty, if no rule's numerosity dropped to 0.) The
... | [
"Reduce",
"the",
"classifier",
"set",
"s",
"population",
"size",
"if",
"necessary",
"by",
"removing",
"lower",
"-",
"quality",
"*",
"rules",
".",
"Return",
"a",
"list",
"containing",
"any",
"rules",
"whose",
"numerosities",
"dropped",
"to",
"zero",
"as",
"a"... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/algorithms/xcs.py#L678-L744 | [
"def",
"prune",
"(",
"self",
",",
"model",
")",
":",
"assert",
"isinstance",
"(",
"model",
",",
"ClassifierSet",
")",
"assert",
"model",
".",
"algorithm",
"is",
"self",
"# Determine the (virtual) population size.",
"total_numerosity",
"=",
"sum",
"(",
"rule",
".... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | XCSAlgorithm._update_fitness | Update the fitness values of the rules belonging to this action
set. | xcs/algorithms/xcs.py | def _update_fitness(self, action_set):
"""Update the fitness values of the rules belonging to this action
set."""
# Compute the accuracy of each rule. Accuracy is inversely
# proportional to error. Below a certain error threshold, accuracy
# becomes constant. Accuracy values rang... | def _update_fitness(self, action_set):
"""Update the fitness values of the rules belonging to this action
set."""
# Compute the accuracy of each rule. Accuracy is inversely
# proportional to error. Below a certain error threshold, accuracy
# becomes constant. Accuracy values rang... | [
"Update",
"the",
"fitness",
"values",
"of",
"the",
"rules",
"belonging",
"to",
"this",
"action",
"set",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/algorithms/xcs.py#L746-L777 | [
"def",
"_update_fitness",
"(",
"self",
",",
"action_set",
")",
":",
"# Compute the accuracy of each rule. Accuracy is inversely",
"# proportional to error. Below a certain error threshold, accuracy",
"# becomes constant. Accuracy values range over (0, 1].",
"total_accuracy",
"=",
"0",
"a... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | XCSAlgorithm._action_set_subsumption | Perform action set subsumption. | xcs/algorithms/xcs.py | def _action_set_subsumption(self, action_set):
"""Perform action set subsumption."""
# Select a condition with maximum bit count among those having
# sufficient experience and sufficiently low error.
selected_rule = None
selected_bit_count = None
for rule in action_set:
... | def _action_set_subsumption(self, action_set):
"""Perform action set subsumption."""
# Select a condition with maximum bit count among those having
# sufficient experience and sufficiently low error.
selected_rule = None
selected_bit_count = None
for rule in action_set:
... | [
"Perform",
"action",
"set",
"subsumption",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/algorithms/xcs.py#L779-L813 | [
"def",
"_action_set_subsumption",
"(",
"self",
",",
"action_set",
")",
":",
"# Select a condition with maximum bit count among those having",
"# sufficient experience and sufficiently low error.",
"selected_rule",
"=",
"None",
"selected_bit_count",
"=",
"None",
"for",
"rule",
"in... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | XCSAlgorithm._get_average_time_stamp | Return the average time stamp for the rules in this action
set. | xcs/algorithms/xcs.py | def _get_average_time_stamp(action_set):
"""Return the average time stamp for the rules in this action
set."""
# This is the average value of the iteration counter upon the most
# recent update of each rule in this action set.
total_time_stamps = sum(rule.time_stamp * rule.numero... | def _get_average_time_stamp(action_set):
"""Return the average time stamp for the rules in this action
set."""
# This is the average value of the iteration counter upon the most
# recent update of each rule in this action set.
total_time_stamps = sum(rule.time_stamp * rule.numero... | [
"Return",
"the",
"average",
"time",
"stamp",
"for",
"the",
"rules",
"in",
"this",
"action",
"set",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/algorithms/xcs.py#L816-L824 | [
"def",
"_get_average_time_stamp",
"(",
"action_set",
")",
":",
"# This is the average value of the iteration counter upon the most",
"# recent update of each rule in this action set.",
"total_time_stamps",
"=",
"sum",
"(",
"rule",
".",
"time_stamp",
"*",
"rule",
".",
"numerosity"... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | XCSAlgorithm._select_parent | Select a rule from this action set, with probability
proportionate to its fitness, to act as a parent for a new rule in
the classifier set. Return the selected rule. | xcs/algorithms/xcs.py | def _select_parent(action_set):
"""Select a rule from this action set, with probability
proportionate to its fitness, to act as a parent for a new rule in
the classifier set. Return the selected rule."""
total_fitness = sum(rule.fitness for rule in action_set)
selector = random.u... | def _select_parent(action_set):
"""Select a rule from this action set, with probability
proportionate to its fitness, to act as a parent for a new rule in
the classifier set. Return the selected rule."""
total_fitness = sum(rule.fitness for rule in action_set)
selector = random.u... | [
"Select",
"a",
"rule",
"from",
"this",
"action",
"set",
"with",
"probability",
"proportionate",
"to",
"its",
"fitness",
"to",
"act",
"as",
"a",
"parent",
"for",
"a",
"new",
"rule",
"in",
"the",
"classifier",
"set",
".",
"Return",
"the",
"selected",
"rule",... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/algorithms/xcs.py#L835-L847 | [
"def",
"_select_parent",
"(",
"action_set",
")",
":",
"total_fitness",
"=",
"sum",
"(",
"rule",
".",
"fitness",
"for",
"rule",
"in",
"action_set",
")",
"selector",
"=",
"random",
".",
"uniform",
"(",
"0",
",",
"total_fitness",
")",
"for",
"rule",
"in",
"... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | XCSAlgorithm._mutate | Create a new condition from the given one by probabilistically
applying point-wise mutations. Bits that were originally wildcarded
in the parent condition acquire their values from the provided
situation, to ensure the child condition continues to match it. | xcs/algorithms/xcs.py | def _mutate(self, condition, situation):
"""Create a new condition from the given one by probabilistically
applying point-wise mutations. Bits that were originally wildcarded
in the parent condition acquire their values from the provided
situation, to ensure the child condition continues... | def _mutate(self, condition, situation):
"""Create a new condition from the given one by probabilistically
applying point-wise mutations. Bits that were originally wildcarded
in the parent condition acquire their values from the provided
situation, to ensure the child condition continues... | [
"Create",
"a",
"new",
"condition",
"from",
"the",
"given",
"one",
"by",
"probabilistically",
"applying",
"point",
"-",
"wise",
"mutations",
".",
"Bits",
"that",
"were",
"originally",
"wildcarded",
"in",
"the",
"parent",
"condition",
"acquire",
"their",
"values",... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/algorithms/xcs.py#L849-L871 | [
"def",
"_mutate",
"(",
"self",
",",
"condition",
",",
"situation",
")",
":",
"# Go through each position in the condition, randomly flipping",
"# whether the position is a value (0 or 1) or a wildcard (#). We do",
"# this in a new list because the original condition's mask is",
"# immutabl... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | SyncBackend.establish_connection | Establish connection to the AMQP broker. | carrot/backends/pikachu.py | def establish_connection(self):
"""Establish connection to the AMQP broker."""
conninfo = self.connection
if not conninfo.port:
conninfo.port = self.default_port
credentials = pika.PlainCredentials(conninfo.userid,
conninfo.password... | def establish_connection(self):
"""Establish connection to the AMQP broker."""
conninfo = self.connection
if not conninfo.port:
conninfo.port = self.default_port
credentials = pika.PlainCredentials(conninfo.userid,
conninfo.password... | [
"Establish",
"connection",
"to",
"the",
"AMQP",
"broker",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/backends/pikachu.py#L57-L68 | [
"def",
"establish_connection",
"(",
"self",
")",
":",
"conninfo",
"=",
"self",
".",
"connection",
"if",
"not",
"conninfo",
".",
"port",
":",
"conninfo",
".",
"port",
"=",
"self",
".",
"default_port",
"credentials",
"=",
"pika",
".",
"PlainCredentials",
"(",
... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | SyncBackend.queue_purge | Discard all messages in the queue. This will delete the messages
and results in an empty queue. | carrot/backends/pikachu.py | def queue_purge(self, queue, **kwargs):
"""Discard all messages in the queue. This will delete the messages
and results in an empty queue."""
return self.channel.queue_purge(queue=queue).message_count | def queue_purge(self, queue, **kwargs):
"""Discard all messages in the queue. This will delete the messages
and results in an empty queue."""
return self.channel.queue_purge(queue=queue).message_count | [
"Discard",
"all",
"messages",
"in",
"the",
"queue",
".",
"This",
"will",
"delete",
"the",
"messages",
"and",
"results",
"in",
"an",
"empty",
"queue",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/backends/pikachu.py#L82-L85 | [
"def",
"queue_purge",
"(",
"self",
",",
"queue",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"channel",
".",
"queue_purge",
"(",
"queue",
"=",
"queue",
")",
".",
"message_count"
] | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | SyncBackend.queue_declare | Declare a named queue. | carrot/backends/pikachu.py | def queue_declare(self, queue, durable, exclusive, auto_delete,
warn_if_exists=False, arguments=None):
"""Declare a named queue."""
return self.channel.queue_declare(queue=queue,
durable=durable,
exclusive=e... | def queue_declare(self, queue, durable, exclusive, auto_delete,
warn_if_exists=False, arguments=None):
"""Declare a named queue."""
return self.channel.queue_declare(queue=queue,
durable=durable,
exclusive=e... | [
"Declare",
"a",
"named",
"queue",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/backends/pikachu.py#L87-L95 | [
"def",
"queue_declare",
"(",
"self",
",",
"queue",
",",
"durable",
",",
"exclusive",
",",
"auto_delete",
",",
"warn_if_exists",
"=",
"False",
",",
"arguments",
"=",
"None",
")",
":",
"return",
"self",
".",
"channel",
".",
"queue_declare",
"(",
"queue",
"="... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | SyncBackend.declare_consumer | Declare a consumer. | carrot/backends/pikachu.py | def declare_consumer(self, queue, no_ack, callback, consumer_tag,
nowait=False):
"""Declare a consumer."""
@functools.wraps(callback)
def _callback_decode(channel, method, header, body):
return callback((channel, method, header, body))
return self.channel.basic_... | def declare_consumer(self, queue, no_ack, callback, consumer_tag,
nowait=False):
"""Declare a consumer."""
@functools.wraps(callback)
def _callback_decode(channel, method, header, body):
return callback((channel, method, header, body))
return self.channel.basic_... | [
"Declare",
"a",
"consumer",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/backends/pikachu.py#L130-L141 | [
"def",
"declare_consumer",
"(",
"self",
",",
"queue",
",",
"no_ack",
",",
"callback",
",",
"consumer_tag",
",",
"nowait",
"=",
"False",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"callback",
")",
"def",
"_callback_decode",
"(",
"channel",
",",
"method"... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | SyncBackend.close | Close the channel if open. | carrot/backends/pikachu.py | def close(self):
"""Close the channel if open."""
if self._channel and not self._channel.handler.channel_close:
self._channel.close()
self._channel_ref = None | def close(self):
"""Close the channel if open."""
if self._channel and not self._channel.handler.channel_close:
self._channel.close()
self._channel_ref = None | [
"Close",
"the",
"channel",
"if",
"open",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/backends/pikachu.py#L157-L161 | [
"def",
"close",
"(",
"self",
")",
":",
"if",
"self",
".",
"_channel",
"and",
"not",
"self",
".",
"_channel",
".",
"handler",
".",
"channel_close",
":",
"self",
".",
"_channel",
".",
"close",
"(",
")",
"self",
".",
"_channel_ref",
"=",
"None"
] | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | SyncBackend.prepare_message | Encapsulate data into a AMQP message. | carrot/backends/pikachu.py | def prepare_message(self, message_data, delivery_mode, priority=None,
content_type=None, content_encoding=None):
"""Encapsulate data into a AMQP message."""
properties = pika.BasicProperties(priority=priority,
content_type=content_type,
... | def prepare_message(self, message_data, delivery_mode, priority=None,
content_type=None, content_encoding=None):
"""Encapsulate data into a AMQP message."""
properties = pika.BasicProperties(priority=priority,
content_type=content_type,
... | [
"Encapsulate",
"data",
"into",
"a",
"AMQP",
"message",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/backends/pikachu.py#L175-L182 | [
"def",
"prepare_message",
"(",
"self",
",",
"message_data",
",",
"delivery_mode",
",",
"priority",
"=",
"None",
",",
"content_type",
"=",
"None",
",",
"content_encoding",
"=",
"None",
")",
":",
"properties",
"=",
"pika",
".",
"BasicProperties",
"(",
"priority"... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | SyncBackend.publish | Publish a message to a named exchange. | carrot/backends/pikachu.py | def publish(self, message, exchange, routing_key, mandatory=None,
immediate=None, headers=None):
"""Publish a message to a named exchange."""
body, properties = message
if headers:
properties.headers = headers
ret = self.channel.basic_publish(body=body,
... | def publish(self, message, exchange, routing_key, mandatory=None,
immediate=None, headers=None):
"""Publish a message to a named exchange."""
body, properties = message
if headers:
properties.headers = headers
ret = self.channel.basic_publish(body=body,
... | [
"Publish",
"a",
"message",
"to",
"a",
"named",
"exchange",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/backends/pikachu.py#L184-L199 | [
"def",
"publish",
"(",
"self",
",",
"message",
",",
"exchange",
",",
"routing_key",
",",
"mandatory",
"=",
"None",
",",
"immediate",
"=",
"None",
",",
"headers",
"=",
"None",
")",
":",
"body",
",",
"properties",
"=",
"message",
"if",
"headers",
":",
"p... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Consumer._generate_consumer_tag | Generate a unique consumer tag.
:rtype string: | carrot/messaging.py | def _generate_consumer_tag(self):
"""Generate a unique consumer tag.
:rtype string:
"""
return "%s.%s%s" % (
self.__class__.__module__,
self.__class__.__name__,
self._next_consumer_tag()) | def _generate_consumer_tag(self):
"""Generate a unique consumer tag.
:rtype string:
"""
return "%s.%s%s" % (
self.__class__.__module__,
self.__class__.__name__,
self._next_consumer_tag()) | [
"Generate",
"a",
"unique",
"consumer",
"tag",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L247-L256 | [
"def",
"_generate_consumer_tag",
"(",
"self",
")",
":",
"return",
"\"%s.%s%s\"",
"%",
"(",
"self",
".",
"__class__",
".",
"__module__",
",",
"self",
".",
"__class__",
".",
"__name__",
",",
"self",
".",
"_next_consumer_tag",
"(",
")",
")"
] | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Consumer.declare | Declares the queue, the exchange and binds the queue to
the exchange. | carrot/messaging.py | def declare(self):
"""Declares the queue, the exchange and binds the queue to
the exchange."""
arguments = None
routing_key = self.routing_key
if self.exchange_type == "headers":
arguments, routing_key = routing_key, ""
if self.queue:
self.backend... | def declare(self):
"""Declares the queue, the exchange and binds the queue to
the exchange."""
arguments = None
routing_key = self.routing_key
if self.exchange_type == "headers":
arguments, routing_key = routing_key, ""
if self.queue:
self.backend... | [
"Declares",
"the",
"queue",
"the",
"exchange",
"and",
"binds",
"the",
"queue",
"to",
"the",
"exchange",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L258-L283 | [
"def",
"declare",
"(",
"self",
")",
":",
"arguments",
"=",
"None",
"routing_key",
"=",
"self",
".",
"routing_key",
"if",
"self",
".",
"exchange_type",
"==",
"\"headers\"",
":",
"arguments",
",",
"routing_key",
"=",
"routing_key",
",",
"\"\"",
"if",
"self",
... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Consumer._receive_callback | Internal method used when a message is received in consume mode. | carrot/messaging.py | def _receive_callback(self, raw_message):
"""Internal method used when a message is received in consume mode."""
message = self.backend.message_to_python(raw_message)
if self.auto_ack and not message.acknowledged:
message.ack()
self.receive(message.payload, message) | def _receive_callback(self, raw_message):
"""Internal method used when a message is received in consume mode."""
message = self.backend.message_to_python(raw_message)
if self.auto_ack and not message.acknowledged:
message.ack()
self.receive(message.payload, message) | [
"Internal",
"method",
"used",
"when",
"a",
"message",
"is",
"received",
"in",
"consume",
"mode",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L285-L291 | [
"def",
"_receive_callback",
"(",
"self",
",",
"raw_message",
")",
":",
"message",
"=",
"self",
".",
"backend",
".",
"message_to_python",
"(",
"raw_message",
")",
"if",
"self",
".",
"auto_ack",
"and",
"not",
"message",
".",
"acknowledged",
":",
"message",
"."... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Consumer.fetch | Receive the next message waiting on the queue.
:returns: A :class:`carrot.backends.base.BaseMessage` instance,
or ``None`` if there's no messages to be received.
:keyword enable_callbacks: Enable callbacks. The message will be
processed with all registered callbacks. Default is... | carrot/messaging.py | def fetch(self, no_ack=None, auto_ack=None, enable_callbacks=False):
"""Receive the next message waiting on the queue.
:returns: A :class:`carrot.backends.base.BaseMessage` instance,
or ``None`` if there's no messages to be received.
:keyword enable_callbacks: Enable callbacks. The... | def fetch(self, no_ack=None, auto_ack=None, enable_callbacks=False):
"""Receive the next message waiting on the queue.
:returns: A :class:`carrot.backends.base.BaseMessage` instance,
or ``None`` if there's no messages to be received.
:keyword enable_callbacks: Enable callbacks. The... | [
"Receive",
"the",
"next",
"message",
"waiting",
"on",
"the",
"queue",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L293-L313 | [
"def",
"fetch",
"(",
"self",
",",
"no_ack",
"=",
"None",
",",
"auto_ack",
"=",
"None",
",",
"enable_callbacks",
"=",
"False",
")",
":",
"no_ack",
"=",
"no_ack",
"or",
"self",
".",
"no_ack",
"auto_ack",
"=",
"auto_ack",
"or",
"self",
".",
"auto_ack",
"m... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Consumer.receive | This method is called when a new message is received by
running :meth:`wait`, :meth:`process_next` or :meth:`iterqueue`.
When a message is received, it passes the message on to the
callbacks listed in the :attr:`callbacks` attribute.
You can register callbacks using :meth:`register_call... | carrot/messaging.py | def receive(self, message_data, message):
"""This method is called when a new message is received by
running :meth:`wait`, :meth:`process_next` or :meth:`iterqueue`.
When a message is received, it passes the message on to the
callbacks listed in the :attr:`callbacks` attribute.
... | def receive(self, message_data, message):
"""This method is called when a new message is received by
running :meth:`wait`, :meth:`process_next` or :meth:`iterqueue`.
When a message is received, it passes the message on to the
callbacks listed in the :attr:`callbacks` attribute.
... | [
"This",
"method",
"is",
"called",
"when",
"a",
"new",
"message",
"is",
"received",
"by",
"running",
":",
"meth",
":",
"wait",
":",
"meth",
":",
"process_next",
"or",
":",
"meth",
":",
"iterqueue",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L326-L344 | [
"def",
"receive",
"(",
"self",
",",
"message_data",
",",
"message",
")",
":",
"if",
"not",
"self",
".",
"callbacks",
":",
"raise",
"NotImplementedError",
"(",
"\"No consumer callbacks registered\"",
")",
"for",
"callback",
"in",
"self",
".",
"callbacks",
":",
... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Consumer.discard_all | Discard all waiting messages.
:param filterfunc: A filter function to only discard the messages this
filter returns.
:returns: the number of messages discarded.
*WARNING*: All incoming messages will be ignored and not processed.
Example using filter:
>>> def ... | carrot/messaging.py | def discard_all(self, filterfunc=None):
"""Discard all waiting messages.
:param filterfunc: A filter function to only discard the messages this
filter returns.
:returns: the number of messages discarded.
*WARNING*: All incoming messages will be ignored and not processed.
... | def discard_all(self, filterfunc=None):
"""Discard all waiting messages.
:param filterfunc: A filter function to only discard the messages this
filter returns.
:returns: the number of messages discarded.
*WARNING*: All incoming messages will be ignored and not processed.
... | [
"Discard",
"all",
"waiting",
"messages",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L364-L401 | [
"def",
"discard_all",
"(",
"self",
",",
"filterfunc",
"=",
"None",
")",
":",
"if",
"not",
"filterfunc",
":",
"return",
"self",
".",
"backend",
".",
"queue_purge",
"(",
"self",
".",
"queue",
")",
"if",
"self",
".",
"no_ack",
"or",
"self",
".",
"auto_ack... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Consumer.consume | Declare consumer. | carrot/messaging.py | def consume(self, no_ack=None):
"""Declare consumer."""
no_ack = no_ack or self.no_ack
self.backend.declare_consumer(queue=self.queue, no_ack=no_ack,
callback=self._receive_callback,
consumer_tag=self.consumer_tag,
... | def consume(self, no_ack=None):
"""Declare consumer."""
no_ack = no_ack or self.no_ack
self.backend.declare_consumer(queue=self.queue, no_ack=no_ack,
callback=self._receive_callback,
consumer_tag=self.consumer_tag,
... | [
"Declare",
"consumer",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L427-L434 | [
"def",
"consume",
"(",
"self",
",",
"no_ack",
"=",
"None",
")",
":",
"no_ack",
"=",
"no_ack",
"or",
"self",
".",
"no_ack",
"self",
".",
"backend",
".",
"declare_consumer",
"(",
"queue",
"=",
"self",
".",
"queue",
",",
"no_ack",
"=",
"no_ack",
",",
"c... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Consumer.wait | Go into consume mode.
Mostly for testing purposes and simple programs, you probably
want :meth:`iterconsume` or :meth:`iterqueue` instead.
This runs an infinite loop, processing all incoming messages
using :meth:`receive` to apply the message to all registered
callbacks. | carrot/messaging.py | def wait(self, limit=None):
"""Go into consume mode.
Mostly for testing purposes and simple programs, you probably
want :meth:`iterconsume` or :meth:`iterqueue` instead.
This runs an infinite loop, processing all incoming messages
using :meth:`receive` to apply the message to a... | def wait(self, limit=None):
"""Go into consume mode.
Mostly for testing purposes and simple programs, you probably
want :meth:`iterconsume` or :meth:`iterqueue` instead.
This runs an infinite loop, processing all incoming messages
using :meth:`receive` to apply the message to a... | [
"Go",
"into",
"consume",
"mode",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L436-L449 | [
"def",
"wait",
"(",
"self",
",",
"limit",
"=",
"None",
")",
":",
"it",
"=",
"self",
".",
"iterconsume",
"(",
"limit",
")",
"while",
"True",
":",
"it",
".",
"next",
"(",
")"
] | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Consumer.iterqueue | Infinite iterator yielding pending messages, by using
synchronous direct access to the queue (``basic_get``).
:meth:`iterqueue` is used where synchronous functionality is more
important than performance. If you can, use :meth:`iterconsume`
instead.
:keyword limit: If set, the i... | carrot/messaging.py | def iterqueue(self, limit=None, infinite=False):
"""Infinite iterator yielding pending messages, by using
synchronous direct access to the queue (``basic_get``).
:meth:`iterqueue` is used where synchronous functionality is more
important than performance. If you can, use :meth:`itercons... | def iterqueue(self, limit=None, infinite=False):
"""Infinite iterator yielding pending messages, by using
synchronous direct access to the queue (``basic_get``).
:meth:`iterqueue` is used where synchronous functionality is more
important than performance. If you can, use :meth:`itercons... | [
"Infinite",
"iterator",
"yielding",
"pending",
"messages",
"by",
"using",
"synchronous",
"direct",
"access",
"to",
"the",
"queue",
"(",
"basic_get",
")",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L451-L476 | [
"def",
"iterqueue",
"(",
"self",
",",
"limit",
"=",
"None",
",",
"infinite",
"=",
"False",
")",
":",
"for",
"items_since_start",
"in",
"count",
"(",
")",
":",
"item",
"=",
"self",
".",
"fetch",
"(",
")",
"if",
"(",
"not",
"infinite",
"and",
"item",
... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Consumer.cancel | Cancel a running :meth:`iterconsume` session. | carrot/messaging.py | def cancel(self):
"""Cancel a running :meth:`iterconsume` session."""
if self.channel_open:
try:
self.backend.cancel(self.consumer_tag)
except KeyError:
pass | def cancel(self):
"""Cancel a running :meth:`iterconsume` session."""
if self.channel_open:
try:
self.backend.cancel(self.consumer_tag)
except KeyError:
pass | [
"Cancel",
"a",
"running",
":",
"meth",
":",
"iterconsume",
"session",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L478-L484 | [
"def",
"cancel",
"(",
"self",
")",
":",
"if",
"self",
".",
"channel_open",
":",
"try",
":",
"self",
".",
"backend",
".",
"cancel",
"(",
"self",
".",
"consumer_tag",
")",
"except",
"KeyError",
":",
"pass"
] | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Consumer.close | Close the channel to the queue. | carrot/messaging.py | def close(self):
"""Close the channel to the queue."""
self.cancel()
self.backend.close()
self._closed = True | def close(self):
"""Close the channel to the queue."""
self.cancel()
self.backend.close()
self._closed = True | [
"Close",
"the",
"channel",
"to",
"the",
"queue",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L486-L490 | [
"def",
"close",
"(",
"self",
")",
":",
"self",
".",
"cancel",
"(",
")",
"self",
".",
"backend",
".",
"close",
"(",
")",
"self",
".",
"_closed",
"=",
"True"
] | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Consumer.qos | Request specific Quality of Service.
This method requests a specific quality of service. The QoS
can be specified for the current channel or for all channels
on the connection. The particular properties and semantics of
a qos method always depend on the content class semantics.
... | carrot/messaging.py | def qos(self, prefetch_size=0, prefetch_count=0, apply_global=False):
"""Request specific Quality of Service.
This method requests a specific quality of service. The QoS
can be specified for the current channel or for all channels
on the connection. The particular properties and seman... | def qos(self, prefetch_size=0, prefetch_count=0, apply_global=False):
"""Request specific Quality of Service.
This method requests a specific quality of service. The QoS
can be specified for the current channel or for all channels
on the connection. The particular properties and seman... | [
"Request",
"specific",
"Quality",
"of",
"Service",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L507-L544 | [
"def",
"qos",
"(",
"self",
",",
"prefetch_size",
"=",
"0",
",",
"prefetch_count",
"=",
"0",
",",
"apply_global",
"=",
"False",
")",
":",
"return",
"self",
".",
"backend",
".",
"qos",
"(",
"prefetch_size",
",",
"prefetch_count",
",",
"apply_global",
")"
] | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Publisher.declare | Declare the exchange.
Creates the exchange on the broker. | carrot/messaging.py | def declare(self):
"""Declare the exchange.
Creates the exchange on the broker.
"""
self.backend.exchange_declare(exchange=self.exchange,
type=self.exchange_type,
durable=self.durable,
... | def declare(self):
"""Declare the exchange.
Creates the exchange on the broker.
"""
self.backend.exchange_declare(exchange=self.exchange,
type=self.exchange_type,
durable=self.durable,
... | [
"Declare",
"the",
"exchange",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L663-L672 | [
"def",
"declare",
"(",
"self",
")",
":",
"self",
".",
"backend",
".",
"exchange_declare",
"(",
"exchange",
"=",
"self",
".",
"exchange",
",",
"type",
"=",
"self",
".",
"exchange_type",
",",
"durable",
"=",
"self",
".",
"durable",
",",
"auto_delete",
"=",... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Publisher.create_message | With any data, serialize it and encapsulate it in a AMQP
message with the proper headers set. | carrot/messaging.py | def create_message(self, message_data, delivery_mode=None, priority=None,
content_type=None, content_encoding=None,
serializer=None):
"""With any data, serialize it and encapsulate it in a AMQP
message with the proper headers set."""
delivery_mode =... | def create_message(self, message_data, delivery_mode=None, priority=None,
content_type=None, content_encoding=None,
serializer=None):
"""With any data, serialize it and encapsulate it in a AMQP
message with the proper headers set."""
delivery_mode =... | [
"With",
"any",
"data",
"serialize",
"it",
"and",
"encapsulate",
"it",
"in",
"a",
"AMQP",
"message",
"with",
"the",
"proper",
"headers",
"set",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L680-L710 | [
"def",
"create_message",
"(",
"self",
",",
"message_data",
",",
"delivery_mode",
"=",
"None",
",",
"priority",
"=",
"None",
",",
"content_type",
"=",
"None",
",",
"content_encoding",
"=",
"None",
",",
"serializer",
"=",
"None",
")",
":",
"delivery_mode",
"="... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Publisher.send | Send a message.
:param message_data: The message data to send. Can be a list,
dictionary or a string.
:keyword routing_key: A custom routing key for the message.
If not set, the default routing key set in the :attr:`routing_key`
attribute is used.
:keyword ... | carrot/messaging.py | def send(self, message_data, routing_key=None, delivery_mode=None,
mandatory=False, immediate=False, priority=0, content_type=None,
content_encoding=None, serializer=None, exchange=None):
"""Send a message.
:param message_data: The message data to send. Can be a list,
... | def send(self, message_data, routing_key=None, delivery_mode=None,
mandatory=False, immediate=False, priority=0, content_type=None,
content_encoding=None, serializer=None, exchange=None):
"""Send a message.
:param message_data: The message data to send. Can be a list,
... | [
"Send",
"a",
"message",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L712-L772 | [
"def",
"send",
"(",
"self",
",",
"message_data",
",",
"routing_key",
"=",
"None",
",",
"delivery_mode",
"=",
"None",
",",
"mandatory",
"=",
"False",
",",
"immediate",
"=",
"False",
",",
"priority",
"=",
"0",
",",
"content_type",
"=",
"None",
",",
"conten... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Messaging.send | See :meth:`Publisher.send` | carrot/messaging.py | def send(self, message_data, delivery_mode=None):
"""See :meth:`Publisher.send`"""
self.publisher.send(message_data, delivery_mode=delivery_mode) | def send(self, message_data, delivery_mode=None):
"""See :meth:`Publisher.send`"""
self.publisher.send(message_data, delivery_mode=delivery_mode) | [
"See",
":",
"meth",
":",
"Publisher",
".",
"send"
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L821-L823 | [
"def",
"send",
"(",
"self",
",",
"message_data",
",",
"delivery_mode",
"=",
"None",
")",
":",
"self",
".",
"publisher",
".",
"send",
"(",
"message_data",
",",
"delivery_mode",
"=",
"delivery_mode",
")"
] | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | Messaging.close | Close any open channels. | carrot/messaging.py | def close(self):
"""Close any open channels."""
self.consumer.close()
self.publisher.close()
self._closed = True | def close(self):
"""Close any open channels."""
self.consumer.close()
self.publisher.close()
self._closed = True | [
"Close",
"any",
"open",
"channels",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L829-L833 | [
"def",
"close",
"(",
"self",
")",
":",
"self",
".",
"consumer",
".",
"close",
"(",
")",
"self",
".",
"publisher",
".",
"close",
"(",
")",
"self",
".",
"_closed",
"=",
"True"
] | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | ConsumerSet._receive_callback | Internal method used when a message is received in consume mode. | carrot/messaging.py | def _receive_callback(self, raw_message):
"""Internal method used when a message is received in consume mode."""
message = self.backend.message_to_python(raw_message)
if self.auto_ack and not message.acknowledged:
message.ack()
try:
decoded = message.decode()
... | def _receive_callback(self, raw_message):
"""Internal method used when a message is received in consume mode."""
message = self.backend.message_to_python(raw_message)
if self.auto_ack and not message.acknowledged:
message.ack()
try:
decoded = message.decode()
... | [
"Internal",
"method",
"used",
"when",
"a",
"message",
"is",
"received",
"in",
"consume",
"mode",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L914-L926 | [
"def",
"_receive_callback",
"(",
"self",
",",
"raw_message",
")",
":",
"message",
"=",
"self",
".",
"backend",
".",
"message_to_python",
"(",
"raw_message",
")",
"if",
"self",
".",
"auto_ack",
"and",
"not",
"message",
".",
"acknowledged",
":",
"message",
"."... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | ConsumerSet.add_consumer_from_dict | Add another consumer from dictionary configuration. | carrot/messaging.py | def add_consumer_from_dict(self, queue, **options):
"""Add another consumer from dictionary configuration."""
options.setdefault("routing_key", options.pop("binding_key", None))
consumer = Consumer(self.connection, queue=queue,
backend=self.backend, **options)
... | def add_consumer_from_dict(self, queue, **options):
"""Add another consumer from dictionary configuration."""
options.setdefault("routing_key", options.pop("binding_key", None))
consumer = Consumer(self.connection, queue=queue,
backend=self.backend, **options)
... | [
"Add",
"another",
"consumer",
"from",
"dictionary",
"configuration",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L928-L934 | [
"def",
"add_consumer_from_dict",
"(",
"self",
",",
"queue",
",",
"*",
"*",
"options",
")",
":",
"options",
".",
"setdefault",
"(",
"\"routing_key\"",
",",
"options",
".",
"pop",
"(",
"\"binding_key\"",
",",
"None",
")",
")",
"consumer",
"=",
"Consumer",
"(... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | ConsumerSet.add_consumer | Add another consumer from a :class:`Consumer` instance. | carrot/messaging.py | def add_consumer(self, consumer):
"""Add another consumer from a :class:`Consumer` instance."""
consumer.backend = self.backend
self.consumers.append(consumer) | def add_consumer(self, consumer):
"""Add another consumer from a :class:`Consumer` instance."""
consumer.backend = self.backend
self.consumers.append(consumer) | [
"Add",
"another",
"consumer",
"from",
"a",
":",
"class",
":",
"Consumer",
"instance",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L936-L939 | [
"def",
"add_consumer",
"(",
"self",
",",
"consumer",
")",
":",
"consumer",
".",
"backend",
"=",
"self",
".",
"backend",
"self",
".",
"consumers",
".",
"append",
"(",
"consumer",
")"
] | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | ConsumerSet._declare_consumer | Declare consumer so messages can be received from it using
:meth:`iterconsume`. | carrot/messaging.py | def _declare_consumer(self, consumer, nowait=False):
"""Declare consumer so messages can be received from it using
:meth:`iterconsume`."""
if consumer.queue not in self._open_consumers:
# Use the ConsumerSet's consumer by default, but if the
# child consumer has a callbac... | def _declare_consumer(self, consumer, nowait=False):
"""Declare consumer so messages can be received from it using
:meth:`iterconsume`."""
if consumer.queue not in self._open_consumers:
# Use the ConsumerSet's consumer by default, but if the
# child consumer has a callbac... | [
"Declare",
"consumer",
"so",
"messages",
"can",
"be",
"received",
"from",
"it",
"using",
":",
"meth",
":",
"iterconsume",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L954-L967 | [
"def",
"_declare_consumer",
"(",
"self",
",",
"consumer",
",",
"nowait",
"=",
"False",
")",
":",
"if",
"consumer",
".",
"queue",
"not",
"in",
"self",
".",
"_open_consumers",
":",
"# Use the ConsumerSet's consumer by default, but if the",
"# child consumer has a callback... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | ConsumerSet.consume | Declare consumers. | carrot/messaging.py | def consume(self):
"""Declare consumers."""
head = self.consumers[:-1]
tail = self.consumers[-1]
[self._declare_consumer(consumer, nowait=True)
for consumer in head]
self._declare_consumer(tail, nowait=False) | def consume(self):
"""Declare consumers."""
head = self.consumers[:-1]
tail = self.consumers[-1]
[self._declare_consumer(consumer, nowait=True)
for consumer in head]
self._declare_consumer(tail, nowait=False) | [
"Declare",
"consumers",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L969-L975 | [
"def",
"consume",
"(",
"self",
")",
":",
"head",
"=",
"self",
".",
"consumers",
"[",
":",
"-",
"1",
"]",
"tail",
"=",
"self",
".",
"consumers",
"[",
"-",
"1",
"]",
"[",
"self",
".",
"_declare_consumer",
"(",
"consumer",
",",
"nowait",
"=",
"True",
... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | ConsumerSet.iterconsume | Cycle between all consumers in consume mode.
See :meth:`Consumer.iterconsume`. | carrot/messaging.py | def iterconsume(self, limit=None):
"""Cycle between all consumers in consume mode.
See :meth:`Consumer.iterconsume`.
"""
self.consume()
return self.backend.consume(limit=limit) | def iterconsume(self, limit=None):
"""Cycle between all consumers in consume mode.
See :meth:`Consumer.iterconsume`.
"""
self.consume()
return self.backend.consume(limit=limit) | [
"Cycle",
"between",
"all",
"consumers",
"in",
"consume",
"mode",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L977-L983 | [
"def",
"iterconsume",
"(",
"self",
",",
"limit",
"=",
"None",
")",
":",
"self",
".",
"consume",
"(",
")",
"return",
"self",
".",
"backend",
".",
"consume",
"(",
"limit",
"=",
"limit",
")"
] | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | ConsumerSet.cancel | Cancel a running :meth:`iterconsume` session. | carrot/messaging.py | def cancel(self):
"""Cancel a running :meth:`iterconsume` session."""
for consumer_tag in self._open_consumers.values():
try:
self.backend.cancel(consumer_tag)
except KeyError:
pass
self._open_consumers.clear() | def cancel(self):
"""Cancel a running :meth:`iterconsume` session."""
for consumer_tag in self._open_consumers.values():
try:
self.backend.cancel(consumer_tag)
except KeyError:
pass
self._open_consumers.clear() | [
"Cancel",
"a",
"running",
":",
"meth",
":",
"iterconsume",
"session",
"."
] | ask/carrot | python | https://github.com/ask/carrot/blob/5889a25cd2e274642071c9bba39772f4b3e3d9da/carrot/messaging.py#L1008-L1015 | [
"def",
"cancel",
"(",
"self",
")",
":",
"for",
"consumer_tag",
"in",
"self",
".",
"_open_consumers",
".",
"values",
"(",
")",
":",
"try",
":",
"self",
".",
"backend",
".",
"cancel",
"(",
"consumer_tag",
")",
"except",
"KeyError",
":",
"pass",
"self",
"... | 5889a25cd2e274642071c9bba39772f4b3e3d9da |
train | convert_md_to_rst | Try to convert the source, an .md (markdown) file, to an .rst
(reStructuredText) file at the destination. If the destination isn't
provided, it defaults to be the same as the source path except for the
filename extension. If the destination file already exists, it will be
overwritten. In the event of an... | build_readme.py | def convert_md_to_rst(source, destination=None, backup_dir=None):
"""Try to convert the source, an .md (markdown) file, to an .rst
(reStructuredText) file at the destination. If the destination isn't
provided, it defaults to be the same as the source path except for the
filename extension. If the destin... | def convert_md_to_rst(source, destination=None, backup_dir=None):
"""Try to convert the source, an .md (markdown) file, to an .rst
(reStructuredText) file at the destination. If the destination isn't
provided, it defaults to be the same as the source path except for the
filename extension. If the destin... | [
"Try",
"to",
"convert",
"the",
"source",
"an",
".",
"md",
"(",
"markdown",
")",
"file",
"to",
"an",
".",
"rst",
"(",
"reStructuredText",
")",
"file",
"at",
"the",
"destination",
".",
"If",
"the",
"destination",
"isn",
"t",
"provided",
"it",
"defaults",
... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/build_readme.py#L17-L68 | [
"def",
"convert_md_to_rst",
"(",
"source",
",",
"destination",
"=",
"None",
",",
"backup_dir",
"=",
"None",
")",
":",
"# Doing this in the function instead of the module level ensures the",
"# error occurs when the function is called, rather than when the module",
"# is evaluated.",
... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | build_readme | Call the conversion routine on README.md to generate README.rst.
Why do all this? Because pypi requires reStructuredText, but markdown
is friendlier to work with and is nicer for GitHub. | build_readme.py | def build_readme(base_path=None):
"""Call the conversion routine on README.md to generate README.rst.
Why do all this? Because pypi requires reStructuredText, but markdown
is friendlier to work with and is nicer for GitHub."""
if base_path:
path = os.path.join(base_path, 'README.md')
else:
... | def build_readme(base_path=None):
"""Call the conversion routine on README.md to generate README.rst.
Why do all this? Because pypi requires reStructuredText, but markdown
is friendlier to work with and is nicer for GitHub."""
if base_path:
path = os.path.join(base_path, 'README.md')
else:
... | [
"Call",
"the",
"conversion",
"routine",
"on",
"README",
".",
"md",
"to",
"generate",
"README",
".",
"rst",
".",
"Why",
"do",
"all",
"this?",
"Because",
"pypi",
"requires",
"reStructuredText",
"but",
"markdown",
"is",
"friendlier",
"to",
"work",
"with",
"and"... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/build_readme.py#L75-L84 | [
"def",
"build_readme",
"(",
"base_path",
"=",
"None",
")",
":",
"if",
"base_path",
":",
"path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"base_path",
",",
"'README.md'",
")",
"else",
":",
"path",
"=",
"'README.md'",
"convert_md_to_rst",
"(",
"path",
")"... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | MUXProblem.sense | Return a situation, encoded as a bit string, which represents
the observable state of the environment.
Usage:
situation = scenario.sense()
assert isinstance(situation, BitString)
Arguments: None
Return:
The current situation. | xcs/scenarios.py | def sense(self):
"""Return a situation, encoded as a bit string, which represents
the observable state of the environment.
Usage:
situation = scenario.sense()
assert isinstance(situation, BitString)
Arguments: None
Return:
The current situati... | def sense(self):
"""Return a situation, encoded as a bit string, which represents
the observable state of the environment.
Usage:
situation = scenario.sense()
assert isinstance(situation, BitString)
Arguments: None
Return:
The current situati... | [
"Return",
"a",
"situation",
"encoded",
"as",
"a",
"bit",
"string",
"which",
"represents",
"the",
"observable",
"state",
"of",
"the",
"environment",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/scenarios.py#L264-L280 | [
"def",
"sense",
"(",
"self",
")",
":",
"self",
".",
"current_situation",
"=",
"bitstrings",
".",
"BitString",
"(",
"[",
"random",
".",
"randrange",
"(",
"2",
")",
"for",
"_",
"in",
"range",
"(",
"self",
".",
"address_size",
"+",
"(",
"1",
"<<",
"self... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | MUXProblem.execute | Execute the indicated action within the environment and
return the resulting immediate reward dictated by the reward
program.
Usage:
immediate_reward = scenario.execute(selected_action)
Arguments:
action: The action to be executed within the current situation.
... | xcs/scenarios.py | def execute(self, action):
"""Execute the indicated action within the environment and
return the resulting immediate reward dictated by the reward
program.
Usage:
immediate_reward = scenario.execute(selected_action)
Arguments:
action: The action to be ex... | def execute(self, action):
"""Execute the indicated action within the environment and
return the resulting immediate reward dictated by the reward
program.
Usage:
immediate_reward = scenario.execute(selected_action)
Arguments:
action: The action to be ex... | [
"Execute",
"the",
"indicated",
"action",
"within",
"the",
"environment",
"and",
"return",
"the",
"resulting",
"immediate",
"reward",
"dictated",
"by",
"the",
"reward",
"program",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/scenarios.py#L282-L304 | [
"def",
"execute",
"(",
"self",
",",
"action",
")",
":",
"assert",
"action",
"in",
"self",
".",
"possible_actions",
"self",
".",
"remaining_cycles",
"-=",
"1",
"index",
"=",
"int",
"(",
"bitstrings",
".",
"BitString",
"(",
"self",
".",
"current_situation",
... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | HaystackProblem.reset | Reset the scenario, starting it over for a new run.
Usage:
if not scenario.more():
scenario.reset()
Arguments: None
Return: None | xcs/scenarios.py | def reset(self):
"""Reset the scenario, starting it over for a new run.
Usage:
if not scenario.more():
scenario.reset()
Arguments: None
Return: None
"""
self.remaining_cycles = self.initial_training_cycles
self.needle_index = random.r... | def reset(self):
"""Reset the scenario, starting it over for a new run.
Usage:
if not scenario.more():
scenario.reset()
Arguments: None
Return: None
"""
self.remaining_cycles = self.initial_training_cycles
self.needle_index = random.r... | [
"Reset",
"the",
"scenario",
"starting",
"it",
"over",
"for",
"a",
"new",
"run",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/scenarios.py#L372-L383 | [
"def",
"reset",
"(",
"self",
")",
":",
"self",
".",
"remaining_cycles",
"=",
"self",
".",
"initial_training_cycles",
"self",
".",
"needle_index",
"=",
"random",
".",
"randrange",
"(",
"self",
".",
"input_size",
")"
] | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | HaystackProblem.sense | Return a situation, encoded as a bit string, which represents
the observable state of the environment.
Usage:
situation = scenario.sense()
assert isinstance(situation, BitString)
Arguments: None
Return:
The current situation. | xcs/scenarios.py | def sense(self):
"""Return a situation, encoded as a bit string, which represents
the observable state of the environment.
Usage:
situation = scenario.sense()
assert isinstance(situation, BitString)
Arguments: None
Return:
The current situati... | def sense(self):
"""Return a situation, encoded as a bit string, which represents
the observable state of the environment.
Usage:
situation = scenario.sense()
assert isinstance(situation, BitString)
Arguments: None
Return:
The current situati... | [
"Return",
"a",
"situation",
"encoded",
"as",
"a",
"bit",
"string",
"which",
"represents",
"the",
"observable",
"state",
"of",
"the",
"environment",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/scenarios.py#L385-L399 | [
"def",
"sense",
"(",
"self",
")",
":",
"haystack",
"=",
"bitstrings",
".",
"BitString",
".",
"random",
"(",
"self",
".",
"input_size",
")",
"self",
".",
"needle_value",
"=",
"haystack",
"[",
"self",
".",
"needle_index",
"]",
"return",
"haystack"
] | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | HaystackProblem.execute | Execute the indicated action within the environment and
return the resulting immediate reward dictated by the reward
program.
Usage:
immediate_reward = scenario.execute(selected_action)
Arguments:
action: The action to be executed within the current situation.
... | xcs/scenarios.py | def execute(self, action):
"""Execute the indicated action within the environment and
return the resulting immediate reward dictated by the reward
program.
Usage:
immediate_reward = scenario.execute(selected_action)
Arguments:
action: The action to be ex... | def execute(self, action):
"""Execute the indicated action within the environment and
return the resulting immediate reward dictated by the reward
program.
Usage:
immediate_reward = scenario.execute(selected_action)
Arguments:
action: The action to be ex... | [
"Execute",
"the",
"indicated",
"action",
"within",
"the",
"environment",
"and",
"return",
"the",
"resulting",
"immediate",
"reward",
"dictated",
"by",
"the",
"reward",
"program",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/scenarios.py#L401-L419 | [
"def",
"execute",
"(",
"self",
",",
"action",
")",
":",
"assert",
"action",
"in",
"self",
".",
"possible_actions",
"self",
".",
"remaining_cycles",
"-=",
"1",
"return",
"action",
"==",
"self",
".",
"needle_value"
] | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | ScenarioObserver.get_possible_actions | Return a sequence containing the possible actions that can be
executed within the environment.
Usage:
possible_actions = scenario.get_possible_actions()
Arguments: None
Return:
A sequence containing the possible actions which can be
executed within t... | xcs/scenarios.py | def get_possible_actions(self):
"""Return a sequence containing the possible actions that can be
executed within the environment.
Usage:
possible_actions = scenario.get_possible_actions()
Arguments: None
Return:
A sequence containing the possible actions... | def get_possible_actions(self):
"""Return a sequence containing the possible actions that can be
executed within the environment.
Usage:
possible_actions = scenario.get_possible_actions()
Arguments: None
Return:
A sequence containing the possible actions... | [
"Return",
"a",
"sequence",
"containing",
"the",
"possible",
"actions",
"that",
"can",
"be",
"executed",
"within",
"the",
"environment",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/scenarios.py#L466-L501 | [
"def",
"get_possible_actions",
"(",
"self",
")",
":",
"possible_actions",
"=",
"self",
".",
"wrapped",
".",
"get_possible_actions",
"(",
")",
"if",
"len",
"(",
"possible_actions",
")",
"<=",
"20",
":",
"# Try to ensure that the possible actions are unique. Also, put",
... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | ScenarioObserver.sense | Return a situation, encoded as a bit string, which represents
the observable state of the environment.
Usage:
situation = scenario.sense()
assert isinstance(situation, BitString)
Arguments: None
Return:
The current situation. | xcs/scenarios.py | def sense(self):
"""Return a situation, encoded as a bit string, which represents
the observable state of the environment.
Usage:
situation = scenario.sense()
assert isinstance(situation, BitString)
Arguments: None
Return:
The current situati... | def sense(self):
"""Return a situation, encoded as a bit string, which represents
the observable state of the environment.
Usage:
situation = scenario.sense()
assert isinstance(situation, BitString)
Arguments: None
Return:
The current situati... | [
"Return",
"a",
"situation",
"encoded",
"as",
"a",
"bit",
"string",
"which",
"represents",
"the",
"observable",
"state",
"of",
"the",
"environment",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/scenarios.py#L516-L532 | [
"def",
"sense",
"(",
"self",
")",
":",
"situation",
"=",
"self",
".",
"wrapped",
".",
"sense",
"(",
")",
"self",
".",
"logger",
".",
"debug",
"(",
"'Situation: %s'",
",",
"situation",
")",
"return",
"situation"
] | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | ScenarioObserver.execute | Execute the indicated action within the environment and
return the resulting immediate reward dictated by the reward
program.
Usage:
immediate_reward = scenario.execute(selected_action)
Arguments:
action: The action to be executed within the current situation.
... | xcs/scenarios.py | def execute(self, action):
"""Execute the indicated action within the environment and
return the resulting immediate reward dictated by the reward
program.
Usage:
immediate_reward = scenario.execute(selected_action)
Arguments:
action: The action to be ex... | def execute(self, action):
"""Execute the indicated action within the environment and
return the resulting immediate reward dictated by the reward
program.
Usage:
immediate_reward = scenario.execute(selected_action)
Arguments:
action: The action to be ex... | [
"Execute",
"the",
"indicated",
"action",
"within",
"the",
"environment",
"and",
"return",
"the",
"resulting",
"immediate",
"reward",
"dictated",
"by",
"the",
"reward",
"program",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/scenarios.py#L534-L561 | [
"def",
"execute",
"(",
"self",
",",
"action",
")",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"'Executing action: %s'",
",",
"action",
")",
"reward",
"=",
"self",
".",
"wrapped",
".",
"execute",
"(",
"action",
")",
"if",
"reward",
":",
"self",
".",... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | ScenarioObserver.more | Return a Boolean indicating whether additional actions may be
executed, per the reward program.
Usage:
while scenario.more():
situation = scenario.sense()
selected_action = choice(possible_actions)
reward = scenario.execute(selected_action)
... | xcs/scenarios.py | def more(self):
"""Return a Boolean indicating whether additional actions may be
executed, per the reward program.
Usage:
while scenario.more():
situation = scenario.sense()
selected_action = choice(possible_actions)
reward = scenario.... | def more(self):
"""Return a Boolean indicating whether additional actions may be
executed, per the reward program.
Usage:
while scenario.more():
situation = scenario.sense()
selected_action = choice(possible_actions)
reward = scenario.... | [
"Return",
"a",
"Boolean",
"indicating",
"whether",
"additional",
"actions",
"may",
"be",
"executed",
"per",
"the",
"reward",
"program",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/scenarios.py#L563-L592 | [
"def",
"more",
"(",
"self",
")",
":",
"more",
"=",
"self",
".",
"wrapped",
".",
"more",
"(",
")",
"if",
"not",
"self",
".",
"steps",
"%",
"100",
":",
"self",
".",
"logger",
".",
"info",
"(",
"'Steps completed: %d'",
",",
"self",
".",
"steps",
")",
... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | PreClassifiedData.execute | Execute the indicated action within the environment and
return the resulting immediate reward dictated by the reward
program.
Usage:
immediate_reward = scenario.execute(selected_action)
Arguments:
action: The action to be executed within the current situation.
... | xcs/scenarios.py | def execute(self, action):
"""Execute the indicated action within the environment and
return the resulting immediate reward dictated by the reward
program.
Usage:
immediate_reward = scenario.execute(selected_action)
Arguments:
action: The action to be ex... | def execute(self, action):
"""Execute the indicated action within the environment and
return the resulting immediate reward dictated by the reward
program.
Usage:
immediate_reward = scenario.execute(selected_action)
Arguments:
action: The action to be ex... | [
"Execute",
"the",
"indicated",
"action",
"within",
"the",
"environment",
"and",
"return",
"the",
"resulting",
"immediate",
"reward",
"dictated",
"by",
"the",
"reward",
"program",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/scenarios.py#L730-L750 | [
"def",
"execute",
"(",
"self",
",",
"action",
")",
":",
"reward",
"=",
"self",
".",
"reward_function",
"(",
"action",
",",
"self",
".",
"classifications",
"[",
"self",
".",
"steps",
"]",
")",
"self",
".",
"total_reward",
"+=",
"reward",
"self",
".",
"s... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | UnclassifiedData.get_classifications | Return the classifications made by the algorithm for this
scenario.
Usage:
model.run(scenario, learn=False)
classifications = scenario.get_classifications()
Arguments: None
Return:
An indexable sequence containing the classifications made by
... | xcs/scenarios.py | def get_classifications(self):
"""Return the classifications made by the algorithm for this
scenario.
Usage:
model.run(scenario, learn=False)
classifications = scenario.get_classifications()
Arguments: None
Return:
An indexable sequence conta... | def get_classifications(self):
"""Return the classifications made by the algorithm for this
scenario.
Usage:
model.run(scenario, learn=False)
classifications = scenario.get_classifications()
Arguments: None
Return:
An indexable sequence conta... | [
"Return",
"the",
"classifications",
"made",
"by",
"the",
"algorithm",
"for",
"this",
"scenario",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/scenarios.py#L898-L915 | [
"def",
"get_classifications",
"(",
"self",
")",
":",
"if",
"bitstrings",
".",
"using_numpy",
"(",
")",
":",
"return",
"numpy",
".",
"array",
"(",
"self",
".",
"classifications",
")",
"else",
":",
"return",
"self",
".",
"classifications"
] | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | LCSAlgorithm.new_model | Create and return a new classifier set initialized for handling
the given scenario.
Usage:
scenario = MUXProblem()
model = algorithm.new_model(scenario)
model.run(scenario, learn=True)
Arguments:
scenario: A Scenario instance.
Return:
... | xcs/framework.py | def new_model(self, scenario):
"""Create and return a new classifier set initialized for handling
the given scenario.
Usage:
scenario = MUXProblem()
model = algorithm.new_model(scenario)
model.run(scenario, learn=True)
Arguments:
scenario... | def new_model(self, scenario):
"""Create and return a new classifier set initialized for handling
the given scenario.
Usage:
scenario = MUXProblem()
model = algorithm.new_model(scenario)
model.run(scenario, learn=True)
Arguments:
scenario... | [
"Create",
"and",
"return",
"a",
"new",
"classifier",
"set",
"initialized",
"for",
"handling",
"the",
"given",
"scenario",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L166-L181 | [
"def",
"new_model",
"(",
"self",
",",
"scenario",
")",
":",
"assert",
"isinstance",
"(",
"scenario",
",",
"scenarios",
".",
"Scenario",
")",
"return",
"ClassifierSet",
"(",
"self",
",",
"scenario",
".",
"get_possible_actions",
"(",
")",
")"
] | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | LCSAlgorithm.run | Run the algorithm, utilizing a classifier set to choose the
most appropriate action for each situation produced by the
scenario. Improve the situation/action mapping on each reward
cycle to maximize reward. Return the classifier set that was
created.
Usage:
scenario ... | xcs/framework.py | def run(self, scenario):
"""Run the algorithm, utilizing a classifier set to choose the
most appropriate action for each situation produced by the
scenario. Improve the situation/action mapping on each reward
cycle to maximize reward. Return the classifier set that was
created.
... | def run(self, scenario):
"""Run the algorithm, utilizing a classifier set to choose the
most appropriate action for each situation produced by the
scenario. Improve the situation/action mapping on each reward
cycle to maximize reward. Return the classifier set that was
created.
... | [
"Run",
"the",
"algorithm",
"utilizing",
"a",
"classifier",
"set",
"to",
"choose",
"the",
"most",
"appropriate",
"action",
"for",
"each",
"situation",
"produced",
"by",
"the",
"scenario",
".",
"Improve",
"the",
"situation",
"/",
"action",
"mapping",
"on",
"each... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L183-L202 | [
"def",
"run",
"(",
"self",
",",
"scenario",
")",
":",
"assert",
"isinstance",
"(",
"scenario",
",",
"scenarios",
".",
"Scenario",
")",
"model",
"=",
"self",
".",
"new_model",
"(",
"scenario",
")",
"model",
".",
"run",
"(",
"scenario",
",",
"learn",
"="... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | ActionSet._compute_prediction | Compute the combined prediction and prediction weight for this
action set. The combined prediction is the weighted average of the
individual predictions of the classifiers. The combined prediction
weight is the sum of the individual prediction weights of the
classifiers.
Usage:
... | xcs/framework.py | def _compute_prediction(self):
"""Compute the combined prediction and prediction weight for this
action set. The combined prediction is the weighted average of the
individual predictions of the classifiers. The combined prediction
weight is the sum of the individual prediction weights of... | def _compute_prediction(self):
"""Compute the combined prediction and prediction weight for this
action set. The combined prediction is the weighted average of the
individual predictions of the classifiers. The combined prediction
weight is the sum of the individual prediction weights of... | [
"Compute",
"the",
"combined",
"prediction",
"and",
"prediction",
"weight",
"for",
"this",
"action",
"set",
".",
"The",
"combined",
"prediction",
"is",
"the",
"weighted",
"average",
"of",
"the",
"individual",
"predictions",
"of",
"the",
"classifiers",
".",
"The",... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L430-L451 | [
"def",
"_compute_prediction",
"(",
"self",
")",
":",
"total_weight",
"=",
"0",
"total_prediction",
"=",
"0",
"for",
"rule",
"in",
"self",
".",
"_rules",
".",
"values",
"(",
")",
":",
"total_weight",
"+=",
"rule",
".",
"prediction_weight",
"total_prediction",
... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | MatchSet.best_prediction | The highest value from among the predictions made by the action
sets in this match set. | xcs/framework.py | def best_prediction(self):
"""The highest value from among the predictions made by the action
sets in this match set."""
if self._best_prediction is None and self._action_sets:
self._best_prediction = max(
action_set.prediction
for action_set in self._... | def best_prediction(self):
"""The highest value from among the predictions made by the action
sets in this match set."""
if self._best_prediction is None and self._action_sets:
self._best_prediction = max(
action_set.prediction
for action_set in self._... | [
"The",
"highest",
"value",
"from",
"among",
"the",
"predictions",
"made",
"by",
"the",
"action",
"sets",
"in",
"this",
"match",
"set",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L614-L622 | [
"def",
"best_prediction",
"(",
"self",
")",
":",
"if",
"self",
".",
"_best_prediction",
"is",
"None",
"and",
"self",
".",
"_action_sets",
":",
"self",
".",
"_best_prediction",
"=",
"max",
"(",
"action_set",
".",
"prediction",
"for",
"action_set",
"in",
"self... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | MatchSet.best_actions | A tuple containing the actions whose action sets have the best
prediction. | xcs/framework.py | def best_actions(self):
"""A tuple containing the actions whose action sets have the best
prediction."""
if self._best_actions is None:
best_prediction = self.best_prediction
self._best_actions = tuple(
action
for action, action_set in self... | def best_actions(self):
"""A tuple containing the actions whose action sets have the best
prediction."""
if self._best_actions is None:
best_prediction = self.best_prediction
self._best_actions = tuple(
action
for action, action_set in self... | [
"A",
"tuple",
"containing",
"the",
"actions",
"whose",
"action",
"sets",
"have",
"the",
"best",
"prediction",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L625-L635 | [
"def",
"best_actions",
"(",
"self",
")",
":",
"if",
"self",
".",
"_best_actions",
"is",
"None",
":",
"best_prediction",
"=",
"self",
".",
"best_prediction",
"self",
".",
"_best_actions",
"=",
"tuple",
"(",
"action",
"for",
"action",
",",
"action_set",
"in",
... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | MatchSet.select_action | Select an action according to the action selection strategy of
the associated algorithm. If an action has already been selected,
raise a ValueError instead.
Usage:
if match_set.selected_action is None:
match_set.select_action()
Arguments: None
Return... | xcs/framework.py | def select_action(self):
"""Select an action according to the action selection strategy of
the associated algorithm. If an action has already been selected,
raise a ValueError instead.
Usage:
if match_set.selected_action is None:
match_set.select_action()
... | def select_action(self):
"""Select an action according to the action selection strategy of
the associated algorithm. If an action has already been selected,
raise a ValueError instead.
Usage:
if match_set.selected_action is None:
match_set.select_action()
... | [
"Select",
"an",
"action",
"according",
"to",
"the",
"action",
"selection",
"strategy",
"of",
"the",
"associated",
"algorithm",
".",
"If",
"an",
"action",
"has",
"already",
"been",
"selected",
"raise",
"a",
"ValueError",
"instead",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L637-L654 | [
"def",
"select_action",
"(",
"self",
")",
":",
"if",
"self",
".",
"_selected_action",
"is",
"not",
"None",
":",
"raise",
"ValueError",
"(",
"\"The action has already been selected.\"",
")",
"strategy",
"=",
"self",
".",
"_algorithm",
".",
"action_selection_strategy"... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | MatchSet._set_selected_action | Setter method for the selected_action property. | xcs/framework.py | def _set_selected_action(self, action):
"""Setter method for the selected_action property."""
assert action in self._action_sets
if self._selected_action is not None:
raise ValueError("The action has already been selected.")
self._selected_action = action | def _set_selected_action(self, action):
"""Setter method for the selected_action property."""
assert action in self._action_sets
if self._selected_action is not None:
raise ValueError("The action has already been selected.")
self._selected_action = action | [
"Setter",
"method",
"for",
"the",
"selected_action",
"property",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L660-L666 | [
"def",
"_set_selected_action",
"(",
"self",
",",
"action",
")",
":",
"assert",
"action",
"in",
"self",
".",
"_action_sets",
"if",
"self",
".",
"_selected_action",
"is",
"not",
"None",
":",
"raise",
"ValueError",
"(",
"\"The action has already been selected.\"",
")... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | MatchSet._set_payoff | Setter method for the payoff property. | xcs/framework.py | def _set_payoff(self, payoff):
"""Setter method for the payoff property."""
if self._selected_action is None:
raise ValueError("The action has not been selected yet.")
if self._closed:
raise ValueError("The payoff for this match set has already"
... | def _set_payoff(self, payoff):
"""Setter method for the payoff property."""
if self._selected_action is None:
raise ValueError("The action has not been selected yet.")
if self._closed:
raise ValueError("The payoff for this match set has already"
... | [
"Setter",
"method",
"for",
"the",
"payoff",
"property",
"."
] | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L692-L699 | [
"def",
"_set_payoff",
"(",
"self",
",",
"payoff",
")",
":",
"if",
"self",
".",
"_selected_action",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"The action has not been selected yet.\"",
")",
"if",
"self",
".",
"_closed",
":",
"raise",
"ValueError",
"(",
"... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | MatchSet.pay | If the predecessor is not None, gives the appropriate amount of
payoff to the predecessor in payment for its contribution to this
match set's expected future payoff. The predecessor argument should
be either None or a MatchSet instance whose selected action led
directly to this match set... | xcs/framework.py | def pay(self, predecessor):
"""If the predecessor is not None, gives the appropriate amount of
payoff to the predecessor in payment for its contribution to this
match set's expected future payoff. The predecessor argument should
be either None or a MatchSet instance whose selected action... | def pay(self, predecessor):
"""If the predecessor is not None, gives the appropriate amount of
payoff to the predecessor in payment for its contribution to this
match set's expected future payoff. The predecessor argument should
be either None or a MatchSet instance whose selected action... | [
"If",
"the",
"predecessor",
"is",
"not",
"None",
"gives",
"the",
"appropriate",
"amount",
"of",
"payoff",
"to",
"the",
"predecessor",
"in",
"payment",
"for",
"its",
"contribution",
"to",
"this",
"match",
"set",
"s",
"expected",
"future",
"payoff",
".",
"The"... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L713-L735 | [
"def",
"pay",
"(",
"self",
",",
"predecessor",
")",
":",
"assert",
"predecessor",
"is",
"None",
"or",
"isinstance",
"(",
"predecessor",
",",
"MatchSet",
")",
"if",
"predecessor",
"is",
"not",
"None",
":",
"expectation",
"=",
"self",
".",
"_algorithm",
".",... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | MatchSet.apply_payoff | Apply the payoff that has been accumulated from immediate
reward and/or payments from successor match sets. Attempting to
call this method before an action has been selected or after it
has already been called for the same match set will result in a
ValueError.
Usage:
... | xcs/framework.py | def apply_payoff(self):
"""Apply the payoff that has been accumulated from immediate
reward and/or payments from successor match sets. Attempting to
call this method before an action has been selected or after it
has already been called for the same match set will result in a
Val... | def apply_payoff(self):
"""Apply the payoff that has been accumulated from immediate
reward and/or payments from successor match sets. Attempting to
call this method before an action has been selected or after it
has already been called for the same match set will result in a
Val... | [
"Apply",
"the",
"payoff",
"that",
"has",
"been",
"accumulated",
"from",
"immediate",
"reward",
"and",
"/",
"or",
"payments",
"from",
"successor",
"match",
"sets",
".",
"Attempting",
"to",
"call",
"this",
"method",
"before",
"an",
"action",
"has",
"been",
"se... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L737-L760 | [
"def",
"apply_payoff",
"(",
"self",
")",
":",
"if",
"self",
".",
"_selected_action",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"The action has not been selected yet.\"",
")",
"if",
"self",
".",
"_closed",
":",
"raise",
"ValueError",
"(",
"\"The payoff for t... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | ClassifierSet.match | Accept a situation (input) and return a MatchSet containing the
classifier rules whose conditions match the situation. If
appropriate per the algorithm managing this classifier set, create
new rules to ensure sufficient coverage of the possible actions.
Usage:
match_set = mo... | xcs/framework.py | def match(self, situation):
"""Accept a situation (input) and return a MatchSet containing the
classifier rules whose conditions match the situation. If
appropriate per the algorithm managing this classifier set, create
new rules to ensure sufficient coverage of the possible actions.
... | def match(self, situation):
"""Accept a situation (input) and return a MatchSet containing the
classifier rules whose conditions match the situation. If
appropriate per the algorithm managing this classifier set, create
new rules to ensure sufficient coverage of the possible actions.
... | [
"Accept",
"a",
"situation",
"(",
"input",
")",
"and",
"return",
"a",
"MatchSet",
"containing",
"the",
"classifier",
"rules",
"whose",
"conditions",
"match",
"the",
"situation",
".",
"If",
"appropriate",
"per",
"the",
"algorithm",
"managing",
"this",
"classifier"... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L865-L938 | [
"def",
"match",
"(",
"self",
",",
"situation",
")",
":",
"# Find the conditions that match against the current situation, and",
"# group them according to which action(s) they recommend.",
"by_action",
"=",
"{",
"}",
"for",
"condition",
",",
"actions",
"in",
"self",
".",
"_... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | ClassifierSet.add | Add a new classifier rule to the classifier set. Return a list
containing zero or more rules that were deleted from the classifier
by the algorithm in order to make room for the new rule. The rule
argument should be a ClassifierRule instance. The behavior of this
method depends on whethe... | xcs/framework.py | def add(self, rule):
"""Add a new classifier rule to the classifier set. Return a list
containing zero or more rules that were deleted from the classifier
by the algorithm in order to make room for the new rule. The rule
argument should be a ClassifierRule instance. The behavior of this
... | def add(self, rule):
"""Add a new classifier rule to the classifier set. Return a list
containing zero or more rules that were deleted from the classifier
by the algorithm in order to make room for the new rule. The rule
argument should be a ClassifierRule instance. The behavior of this
... | [
"Add",
"a",
"new",
"classifier",
"rule",
"to",
"the",
"classifier",
"set",
".",
"Return",
"a",
"list",
"containing",
"zero",
"or",
"more",
"rules",
"that",
"were",
"deleted",
"from",
"the",
"classifier",
"by",
"the",
"algorithm",
"in",
"order",
"to",
"make... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L940-L986 | [
"def",
"add",
"(",
"self",
",",
"rule",
")",
":",
"assert",
"isinstance",
"(",
"rule",
",",
"ClassifierRule",
")",
"condition",
"=",
"rule",
".",
"condition",
"action",
"=",
"rule",
".",
"action",
"# If the rule already exists in the population, then we virtually",
... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | ClassifierSet.discard | Remove one or more instances of a rule from the classifier set.
Return a Boolean indicating whether the rule's numerosity dropped
to zero. (If the rule's numerosity was already zero, do nothing and
return False.)
Usage:
if rule in model and model.discard(rule, count=3):
... | xcs/framework.py | def discard(self, rule, count=1):
"""Remove one or more instances of a rule from the classifier set.
Return a Boolean indicating whether the rule's numerosity dropped
to zero. (If the rule's numerosity was already zero, do nothing and
return False.)
Usage:
if rule in... | def discard(self, rule, count=1):
"""Remove one or more instances of a rule from the classifier set.
Return a Boolean indicating whether the rule's numerosity dropped
to zero. (If the rule's numerosity was already zero, do nothing and
return False.)
Usage:
if rule in... | [
"Remove",
"one",
"or",
"more",
"instances",
"of",
"a",
"rule",
"from",
"the",
"classifier",
"set",
".",
"Return",
"a",
"Boolean",
"indicating",
"whether",
"the",
"rule",
"s",
"numerosity",
"dropped",
"to",
"zero",
".",
"(",
"If",
"the",
"rule",
"s",
"num... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L988-L1027 | [
"def",
"discard",
"(",
"self",
",",
"rule",
",",
"count",
"=",
"1",
")",
":",
"assert",
"isinstance",
"(",
"rule",
",",
"ClassifierRule",
")",
"assert",
"isinstance",
"(",
"count",
",",
"int",
")",
"and",
"count",
">=",
"0",
"rule",
"=",
"self",
".",... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | ClassifierSet.get | Return the existing version of the given rule. If the rule is
not present in the classifier set, return the default. If no
default was given, use None. This is useful for eliminating
duplicate copies of rules.
Usage:
unique_rule = model.get(possible_duplicate, possible_dupli... | xcs/framework.py | def get(self, rule, default=None):
"""Return the existing version of the given rule. If the rule is
not present in the classifier set, return the default. If no
default was given, use None. This is useful for eliminating
duplicate copies of rules.
Usage:
unique_rule ... | def get(self, rule, default=None):
"""Return the existing version of the given rule. If the rule is
not present in the classifier set, return the default. If no
default was given, use None. This is useful for eliminating
duplicate copies of rules.
Usage:
unique_rule ... | [
"Return",
"the",
"existing",
"version",
"of",
"the",
"given",
"rule",
".",
"If",
"the",
"rule",
"is",
"not",
"present",
"in",
"the",
"classifier",
"set",
"return",
"the",
"default",
".",
"If",
"no",
"default",
"was",
"given",
"use",
"None",
".",
"This",
... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L1029-L1053 | [
"def",
"get",
"(",
"self",
",",
"rule",
",",
"default",
"=",
"None",
")",
":",
"assert",
"isinstance",
"(",
"rule",
",",
"ClassifierRule",
")",
"if",
"(",
"rule",
".",
"condition",
"not",
"in",
"self",
".",
"_population",
"or",
"rule",
".",
"action",
... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | ClassifierSet.run | Run the algorithm, utilizing the classifier set to choose the
most appropriate action for each situation produced by the
scenario. If learn is True, improve the situation/action mapping to
maximize reward. Otherwise, ignore any reward received.
Usage:
model.run(scenario, lea... | xcs/framework.py | def run(self, scenario, learn=True):
"""Run the algorithm, utilizing the classifier set to choose the
most appropriate action for each situation produced by the
scenario. If learn is True, improve the situation/action mapping to
maximize reward. Otherwise, ignore any reward received.
... | def run(self, scenario, learn=True):
"""Run the algorithm, utilizing the classifier set to choose the
most appropriate action for each situation produced by the
scenario. If learn is True, improve the situation/action mapping to
maximize reward. Otherwise, ignore any reward received.
... | [
"Run",
"the",
"algorithm",
"utilizing",
"the",
"classifier",
"set",
"to",
"choose",
"the",
"most",
"appropriate",
"action",
"for",
"each",
"situation",
"produced",
"by",
"the",
"scenario",
".",
"If",
"learn",
"is",
"True",
"improve",
"the",
"situation",
"/",
... | hosford42/xcs | python | https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L1068-L1140 | [
"def",
"run",
"(",
"self",
",",
"scenario",
",",
"learn",
"=",
"True",
")",
":",
"assert",
"isinstance",
"(",
"scenario",
",",
"scenarios",
".",
"Scenario",
")",
"previous_match_set",
"=",
"None",
"# Repeat until the scenario has run its course.",
"while",
"scenar... | 183bdd0dd339e19ded3be202f86e1b38bdb9f1e5 |
train | ls | List configuration files detected (and/or examined paths). | dwave/cloud/cli.py | def ls(system, user, local, include_missing):
"""List configuration files detected (and/or examined paths)."""
# default action is to list *all* auto-detected files
if not (system or user or local):
system = user = local = True
for path in get_configfile_paths(system=system, user=user, local=l... | def ls(system, user, local, include_missing):
"""List configuration files detected (and/or examined paths)."""
# default action is to list *all* auto-detected files
if not (system or user or local):
system = user = local = True
for path in get_configfile_paths(system=system, user=user, local=l... | [
"List",
"configuration",
"files",
"detected",
"(",
"and",
"/",
"or",
"examined",
"paths",
")",
"."
] | dwavesystems/dwave-cloud-client | python | https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/cli.py#L74-L83 | [
"def",
"ls",
"(",
"system",
",",
"user",
",",
"local",
",",
"include_missing",
")",
":",
"# default action is to list *all* auto-detected files",
"if",
"not",
"(",
"system",
"or",
"user",
"or",
"local",
")",
":",
"system",
"=",
"user",
"=",
"local",
"=",
"Tr... | df3221a8385dc0c04d7b4d84f740bf3ad6706230 |
train | inspect | Inspect existing configuration/profile. | dwave/cloud/cli.py | def inspect(config_file, profile):
"""Inspect existing configuration/profile."""
try:
section = load_profile_from_files(
[config_file] if config_file else None, profile)
click.echo("Configuration file: {}".format(config_file if config_file else "auto-detected"))
click.echo(... | def inspect(config_file, profile):
"""Inspect existing configuration/profile."""
try:
section = load_profile_from_files(
[config_file] if config_file else None, profile)
click.echo("Configuration file: {}".format(config_file if config_file else "auto-detected"))
click.echo(... | [
"Inspect",
"existing",
"configuration",
"/",
"profile",
"."
] | dwavesystems/dwave-cloud-client | python | https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/cli.py#L91-L105 | [
"def",
"inspect",
"(",
"config_file",
",",
"profile",
")",
":",
"try",
":",
"section",
"=",
"load_profile_from_files",
"(",
"[",
"config_file",
"]",
"if",
"config_file",
"else",
"None",
",",
"profile",
")",
"click",
".",
"echo",
"(",
"\"Configuration file: {}\... | df3221a8385dc0c04d7b4d84f740bf3ad6706230 |
train | create | Create and/or update cloud client configuration file. | dwave/cloud/cli.py | def create(config_file, profile):
"""Create and/or update cloud client configuration file."""
# determine the config file path
if config_file:
click.echo("Using configuration file: {}".format(config_file))
else:
# path not given, try to detect; or use default, but allow user to override... | def create(config_file, profile):
"""Create and/or update cloud client configuration file."""
# determine the config file path
if config_file:
click.echo("Using configuration file: {}".format(config_file))
else:
# path not given, try to detect; or use default, but allow user to override... | [
"Create",
"and",
"/",
"or",
"update",
"cloud",
"client",
"configuration",
"file",
"."
] | dwavesystems/dwave-cloud-client | python | https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/cli.py#L113-L184 | [
"def",
"create",
"(",
"config_file",
",",
"profile",
")",
":",
"# determine the config file path",
"if",
"config_file",
":",
"click",
".",
"echo",
"(",
"\"Using configuration file: {}\"",
".",
"format",
"(",
"config_file",
")",
")",
"else",
":",
"# path not given, t... | df3221a8385dc0c04d7b4d84f740bf3ad6706230 |
train | _ping | Helper method for the ping command that uses `output()` for info output
and raises `CLIError()` on handled errors.
This function is invariant to output format and/or error signaling mechanism. | dwave/cloud/cli.py | def _ping(config_file, profile, solver_def, request_timeout, polling_timeout, output):
"""Helper method for the ping command that uses `output()` for info output
and raises `CLIError()` on handled errors.
This function is invariant to output format and/or error signaling mechanism.
"""
config = di... | def _ping(config_file, profile, solver_def, request_timeout, polling_timeout, output):
"""Helper method for the ping command that uses `output()` for info output
and raises `CLIError()` on handled errors.
This function is invariant to output format and/or error signaling mechanism.
"""
config = di... | [
"Helper",
"method",
"for",
"the",
"ping",
"command",
"that",
"uses",
"output",
"()",
"for",
"info",
"output",
"and",
"raises",
"CLIError",
"()",
"on",
"handled",
"errors",
"."
] | dwavesystems/dwave-cloud-client | python | https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/cli.py#L187-L259 | [
"def",
"_ping",
"(",
"config_file",
",",
"profile",
",",
"solver_def",
",",
"request_timeout",
",",
"polling_timeout",
",",
"output",
")",
":",
"config",
"=",
"dict",
"(",
"config_file",
"=",
"config_file",
",",
"profile",
"=",
"profile",
",",
"solver",
"=",... | df3221a8385dc0c04d7b4d84f740bf3ad6706230 |
train | ping | Ping the QPU by submitting a single-qubit problem. | dwave/cloud/cli.py | def ping(config_file, profile, solver_def, json_output, request_timeout, polling_timeout):
"""Ping the QPU by submitting a single-qubit problem."""
now = utcnow()
info = dict(datetime=now.isoformat(), timestamp=datetime_to_timestamp(now), code=0)
def output(fmt, **kwargs):
info.update(kwargs)
... | def ping(config_file, profile, solver_def, json_output, request_timeout, polling_timeout):
"""Ping the QPU by submitting a single-qubit problem."""
now = utcnow()
info = dict(datetime=now.isoformat(), timestamp=datetime_to_timestamp(now), code=0)
def output(fmt, **kwargs):
info.update(kwargs)
... | [
"Ping",
"the",
"QPU",
"by",
"submitting",
"a",
"single",
"-",
"qubit",
"problem",
"."
] | dwavesystems/dwave-cloud-client | python | https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/cli.py#L274-L298 | [
"def",
"ping",
"(",
"config_file",
",",
"profile",
",",
"solver_def",
",",
"json_output",
",",
"request_timeout",
",",
"polling_timeout",
")",
":",
"now",
"=",
"utcnow",
"(",
")",
"info",
"=",
"dict",
"(",
"datetime",
"=",
"now",
".",
"isoformat",
"(",
"... | df3221a8385dc0c04d7b4d84f740bf3ad6706230 |
train | solvers | Get solver details.
Unless solver name/id specified, fetch and display details for
all online solvers available on the configured endpoint. | dwave/cloud/cli.py | def solvers(config_file, profile, solver_def, list_solvers):
"""Get solver details.
Unless solver name/id specified, fetch and display details for
all online solvers available on the configured endpoint.
"""
with Client.from_config(
config_file=config_file, profile=profile, solver=solv... | def solvers(config_file, profile, solver_def, list_solvers):
"""Get solver details.
Unless solver name/id specified, fetch and display details for
all online solvers available on the configured endpoint.
"""
with Client.from_config(
config_file=config_file, profile=profile, solver=solv... | [
"Get",
"solver",
"details",
"."
] | dwavesystems/dwave-cloud-client | python | https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/cli.py#L308-L342 | [
"def",
"solvers",
"(",
"config_file",
",",
"profile",
",",
"solver_def",
",",
"list_solvers",
")",
":",
"with",
"Client",
".",
"from_config",
"(",
"config_file",
"=",
"config_file",
",",
"profile",
"=",
"profile",
",",
"solver",
"=",
"solver_def",
")",
"as",... | df3221a8385dc0c04d7b4d84f740bf3ad6706230 |
train | sample | Submit Ising-formulated problem and return samples. | dwave/cloud/cli.py | def sample(config_file, profile, solver_def, biases, couplings, random_problem,
num_reads, verbose):
"""Submit Ising-formulated problem and return samples."""
# TODO: de-dup wrt ping
def echo(s, maxlen=100):
click.echo(s if verbose else strtrunc(s, maxlen))
try:
client = Cl... | def sample(config_file, profile, solver_def, biases, couplings, random_problem,
num_reads, verbose):
"""Submit Ising-formulated problem and return samples."""
# TODO: de-dup wrt ping
def echo(s, maxlen=100):
click.echo(s if verbose else strtrunc(s, maxlen))
try:
client = Cl... | [
"Submit",
"Ising",
"-",
"formulated",
"problem",
"and",
"return",
"samples",
"."
] | dwavesystems/dwave-cloud-client | python | https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/cli.py#L362-L424 | [
"def",
"sample",
"(",
"config_file",
",",
"profile",
",",
"solver_def",
",",
"biases",
",",
"couplings",
",",
"random_problem",
",",
"num_reads",
",",
"verbose",
")",
":",
"# TODO: de-dup wrt ping",
"def",
"echo",
"(",
"s",
",",
"maxlen",
"=",
"100",
")",
... | df3221a8385dc0c04d7b4d84f740bf3ad6706230 |
train | get_input_callback | Return a function that produces samples of a sine.
Parameters
----------
samplerate : float
The sample rate.
params : dict
Parameters for FM generation.
num_samples : int, optional
Number of samples to be generated on each call. | examples/play_modulation.py | def get_input_callback(samplerate, params, num_samples=256):
"""Return a function that produces samples of a sine.
Parameters
----------
samplerate : float
The sample rate.
params : dict
Parameters for FM generation.
num_samples : int, optional
Number of samples to be ge... | def get_input_callback(samplerate, params, num_samples=256):
"""Return a function that produces samples of a sine.
Parameters
----------
samplerate : float
The sample rate.
params : dict
Parameters for FM generation.
num_samples : int, optional
Number of samples to be ge... | [
"Return",
"a",
"function",
"that",
"produces",
"samples",
"of",
"a",
"sine",
"."
] | tuxu/python-samplerate | python | https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/examples/play_modulation.py#L27-L57 | [
"def",
"get_input_callback",
"(",
"samplerate",
",",
"params",
",",
"num_samples",
"=",
"256",
")",
":",
"amplitude",
"=",
"params",
"[",
"'mod_amplitude'",
"]",
"frequency",
"=",
"params",
"[",
"'mod_frequency'",
"]",
"def",
"producer",
"(",
")",
":",
"\"\"... | ed73d7a39e61bfb34b03dade14ffab59aa27922a |
train | get_playback_callback | Return a sound playback callback.
Parameters
----------
resampler
The resampler from which samples are read.
samplerate : float
The sample rate.
params : dict
Parameters for FM generation. | examples/play_modulation.py | def get_playback_callback(resampler, samplerate, params):
"""Return a sound playback callback.
Parameters
----------
resampler
The resampler from which samples are read.
samplerate : float
The sample rate.
params : dict
Parameters for FM generation.
"""
def call... | def get_playback_callback(resampler, samplerate, params):
"""Return a sound playback callback.
Parameters
----------
resampler
The resampler from which samples are read.
samplerate : float
The sample rate.
params : dict
Parameters for FM generation.
"""
def call... | [
"Return",
"a",
"sound",
"playback",
"callback",
"."
] | tuxu/python-samplerate | python | https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/examples/play_modulation.py#L60-L88 | [
"def",
"get_playback_callback",
"(",
"resampler",
",",
"samplerate",
",",
"params",
")",
":",
"def",
"callback",
"(",
"outdata",
",",
"frames",
",",
"time",
",",
"_",
")",
":",
"\"\"\"Playback callback.\n\n Read samples from the resampler and modulate them onto a c... | ed73d7a39e61bfb34b03dade14ffab59aa27922a |
train | main | Setup the resampling and audio output callbacks and start playback. | examples/play_modulation.py | def main(source_samplerate, target_samplerate, params, converter_type):
"""Setup the resampling and audio output callbacks and start playback."""
from time import sleep
ratio = target_samplerate / source_samplerate
with sr.CallbackResampler(get_input_callback(source_samplerate, params),
... | def main(source_samplerate, target_samplerate, params, converter_type):
"""Setup the resampling and audio output callbacks and start playback."""
from time import sleep
ratio = target_samplerate / source_samplerate
with sr.CallbackResampler(get_input_callback(source_samplerate, params),
... | [
"Setup",
"the",
"resampling",
"and",
"audio",
"output",
"callbacks",
"and",
"start",
"playback",
"."
] | tuxu/python-samplerate | python | https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/examples/play_modulation.py#L91-L107 | [
"def",
"main",
"(",
"source_samplerate",
",",
"target_samplerate",
",",
"params",
",",
"converter_type",
")",
":",
"from",
"time",
"import",
"sleep",
"ratio",
"=",
"target_samplerate",
"/",
"source_samplerate",
"with",
"sr",
".",
"CallbackResampler",
"(",
"get_inp... | ed73d7a39e61bfb34b03dade14ffab59aa27922a |
train | Solver.max_num_reads | Returns the maximum number of reads for the given solver parameters.
Args:
**params:
Parameters for the sampling method. Relevant to num_reads:
- annealing_time
- readout_thermalization
- num_reads
- programming_therma... | dwave/cloud/solver.py | def max_num_reads(self, **params):
"""Returns the maximum number of reads for the given solver parameters.
Args:
**params:
Parameters for the sampling method. Relevant to num_reads:
- annealing_time
- readout_thermalization
- ... | def max_num_reads(self, **params):
"""Returns the maximum number of reads for the given solver parameters.
Args:
**params:
Parameters for the sampling method. Relevant to num_reads:
- annealing_time
- readout_thermalization
- ... | [
"Returns",
"the",
"maximum",
"number",
"of",
"reads",
"for",
"the",
"given",
"solver",
"parameters",
"."
] | dwavesystems/dwave-cloud-client | python | https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/solver.py#L227-L267 | [
"def",
"max_num_reads",
"(",
"self",
",",
"*",
"*",
"params",
")",
":",
"# dev note: in the future it would be good to have a way of doing this",
"# server-side, as we are duplicating logic here.",
"properties",
"=",
"self",
".",
"properties",
"if",
"self",
".",
"software",
... | df3221a8385dc0c04d7b4d84f740bf3ad6706230 |
train | Solver.sample_ising | Sample from the specified Ising model.
Args:
linear (list/dict): Linear terms of the model (h).
quadratic (dict of (int, int):float): Quadratic terms of the model (J).
**params: Parameters for the sampling method, specified per solver.
Returns:
:obj:`Fut... | dwave/cloud/solver.py | def sample_ising(self, linear, quadratic, **params):
"""Sample from the specified Ising model.
Args:
linear (list/dict): Linear terms of the model (h).
quadratic (dict of (int, int):float): Quadratic terms of the model (J).
**params: Parameters for the sampling metho... | def sample_ising(self, linear, quadratic, **params):
"""Sample from the specified Ising model.
Args:
linear (list/dict): Linear terms of the model (h).
quadratic (dict of (int, int):float): Quadratic terms of the model (J).
**params: Parameters for the sampling metho... | [
"Sample",
"from",
"the",
"specified",
"Ising",
"model",
"."
] | dwavesystems/dwave-cloud-client | python | https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/solver.py#L271-L306 | [
"def",
"sample_ising",
"(",
"self",
",",
"linear",
",",
"quadratic",
",",
"*",
"*",
"params",
")",
":",
"# Our linear and quadratic objective terms are already separated in an",
"# ising model so we can just directly call `_sample`.",
"return",
"self",
".",
"_sample",
"(",
... | df3221a8385dc0c04d7b4d84f740bf3ad6706230 |
train | Solver.sample_qubo | Sample from the specified QUBO.
Args:
qubo (dict of (int, int):float): Coefficients of a quadratic unconstrained binary
optimization (QUBO) model.
**params: Parameters for the sampling method, specified per solver.
Returns:
:obj:`Future`
Exa... | dwave/cloud/solver.py | def sample_qubo(self, qubo, **params):
"""Sample from the specified QUBO.
Args:
qubo (dict of (int, int):float): Coefficients of a quadratic unconstrained binary
optimization (QUBO) model.
**params: Parameters for the sampling method, specified per solver.
... | def sample_qubo(self, qubo, **params):
"""Sample from the specified QUBO.
Args:
qubo (dict of (int, int):float): Coefficients of a quadratic unconstrained binary
optimization (QUBO) model.
**params: Parameters for the sampling method, specified per solver.
... | [
"Sample",
"from",
"the",
"specified",
"QUBO",
"."
] | dwavesystems/dwave-cloud-client | python | https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/solver.py#L308-L346 | [
"def",
"sample_qubo",
"(",
"self",
",",
"qubo",
",",
"*",
"*",
"params",
")",
":",
"# In a QUBO the linear and quadratic terms in the objective are mixed into",
"# a matrix. For the sake of encoding, we will separate them before calling `_sample`",
"linear",
"=",
"{",
"i1",
":",
... | df3221a8385dc0c04d7b4d84f740bf3ad6706230 |
train | Solver._sample | Internal method for both sample_ising and sample_qubo.
Args:
linear (list/dict): Linear terms of the model.
quadratic (dict of (int, int):float): Quadratic terms of the model.
**params: Parameters for the sampling method, specified per solver.
Returns:
:... | dwave/cloud/solver.py | def _sample(self, type_, linear, quadratic, params):
"""Internal method for both sample_ising and sample_qubo.
Args:
linear (list/dict): Linear terms of the model.
quadratic (dict of (int, int):float): Quadratic terms of the model.
**params: Parameters for the sampli... | def _sample(self, type_, linear, quadratic, params):
"""Internal method for both sample_ising and sample_qubo.
Args:
linear (list/dict): Linear terms of the model.
quadratic (dict of (int, int):float): Quadratic terms of the model.
**params: Parameters for the sampli... | [
"Internal",
"method",
"for",
"both",
"sample_ising",
"and",
"sample_qubo",
"."
] | dwavesystems/dwave-cloud-client | python | https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/solver.py#L348-L388 | [
"def",
"_sample",
"(",
"self",
",",
"type_",
",",
"linear",
",",
"quadratic",
",",
"params",
")",
":",
"# Check the problem",
"if",
"not",
"self",
".",
"check_problem",
"(",
"linear",
",",
"quadratic",
")",
":",
"raise",
"ValueError",
"(",
"\"Problem graph i... | df3221a8385dc0c04d7b4d84f740bf3ad6706230 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.