repo
stringlengths
7
55
path
stringlengths
4
223
func_name
stringlengths
1
134
original_string
stringlengths
75
104k
language
stringclasses
1 value
code
stringlengths
75
104k
code_tokens
listlengths
19
28.4k
docstring
stringlengths
1
46.9k
docstring_tokens
listlengths
1
1.97k
sha
stringlengths
40
40
url
stringlengths
87
315
partition
stringclasses
1 value
hosford42/xcs
xcs/framework.py
MatchSet.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() ...
python
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", ")", ":", "if", "self", ".", "_selected_action", "is", "not", "None", ":", "raise", "ValueError", "(", "\"The action has already been selected.\"", ")", "strategy", "=", "self", ".", "_algorithm", ".", "action_selection_strategy"...
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...
[ "Select", "an", "action", "according", "to", "the", "action", "selection", "strategy", "of", "the", "associated", "algorithm", ".", "If", "an", "action", "has", "already", "been", "selected", "raise", "a", "ValueError", "instead", "." ]
183bdd0dd339e19ded3be202f86e1b38bdb9f1e5
https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L637-L654
train
hosford42/xcs
xcs/framework.py
MatchSet._set_selected_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
python
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", ")", ":", "assert", "action", "in", "self", ".", "_action_sets", "if", "self", ".", "_selected_action", "is", "not", "None", ":", "raise", "ValueError", "(", "\"The action has already been selected.\"", ")...
Setter method for the selected_action property.
[ "Setter", "method", "for", "the", "selected_action", "property", "." ]
183bdd0dd339e19ded3be202f86e1b38bdb9f1e5
https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L660-L666
train
hosford42/xcs
xcs/framework.py
MatchSet._set_payoff
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" ...
python
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", ")", ":", "if", "self", ".", "_selected_action", "is", "None", ":", "raise", "ValueError", "(", "\"The action has not been selected yet.\"", ")", "if", "self", ".", "_closed", ":", "raise", "ValueError", "(", "...
Setter method for the payoff property.
[ "Setter", "method", "for", "the", "payoff", "property", "." ]
183bdd0dd339e19ded3be202f86e1b38bdb9f1e5
https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L692-L699
train
hosford42/xcs
xcs/framework.py
MatchSet.pay
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...
python
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", ")", ":", "assert", "predecessor", "is", "None", "or", "isinstance", "(", "predecessor", ",", "MatchSet", ")", "if", "predecessor", "is", "not", "None", ":", "expectation", "=", "self", ".", "_algorithm", ".",...
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...
[ "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"...
183bdd0dd339e19ded3be202f86e1b38bdb9f1e5
https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L713-L735
train
hosford42/xcs
xcs/framework.py
MatchSet.apply_payoff
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...
python
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", ")", ":", "if", "self", ".", "_selected_action", "is", "None", ":", "raise", "ValueError", "(", "\"The action has not been selected yet.\"", ")", "if", "self", ".", "_closed", ":", "raise", "ValueError", "(", "\"The payoff for t...
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: ...
[ "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...
183bdd0dd339e19ded3be202f86e1b38bdb9f1e5
https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L737-L760
train
hosford42/xcs
xcs/framework.py
ClassifierSet.match
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. ...
python
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", ")", ":", "# 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", ".", "_...
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...
[ "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"...
183bdd0dd339e19ded3be202f86e1b38bdb9f1e5
https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L865-L938
train
hosford42/xcs
xcs/framework.py
ClassifierSet.add
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 ...
python
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", ")", ":", "assert", "isinstance", "(", "rule", ",", "ClassifierRule", ")", "condition", "=", "rule", ".", "condition", "action", "=", "rule", ".", "action", "# If the rule already exists in the population, then we virtually", ...
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...
[ "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...
183bdd0dd339e19ded3be202f86e1b38bdb9f1e5
https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L940-L986
train
hosford42/xcs
xcs/framework.py
ClassifierSet.discard
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...
python
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", ")", ":", "assert", "isinstance", "(", "rule", ",", "ClassifierRule", ")", "assert", "isinstance", "(", "count", ",", "int", ")", "and", "count", ">=", "0", "rule", "=", "self", ".",...
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): ...
[ "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...
183bdd0dd339e19ded3be202f86e1b38bdb9f1e5
https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L988-L1027
train
hosford42/xcs
xcs/framework.py
ClassifierSet.get
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 ...
python
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", ")", ":", "assert", "isinstance", "(", "rule", ",", "ClassifierRule", ")", "if", "(", "rule", ".", "condition", "not", "in", "self", ".", "_population", "or", "rule", ".", "action", ...
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...
[ "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", ...
183bdd0dd339e19ded3be202f86e1b38bdb9f1e5
https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L1029-L1053
train
hosford42/xcs
xcs/framework.py
ClassifierSet.run
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. ...
python
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", ")", ":", "assert", "isinstance", "(", "scenario", ",", "scenarios", ".", "Scenario", ")", "previous_match_set", "=", "None", "# Repeat until the scenario has run its course.", "while", "scenar...
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...
[ "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", "/", ...
183bdd0dd339e19ded3be202f86e1b38bdb9f1e5
https://github.com/hosford42/xcs/blob/183bdd0dd339e19ded3be202f86e1b38bdb9f1e5/xcs/framework.py#L1068-L1140
train
dwavesystems/dwave-cloud-client
dwave/cloud/cli.py
ls
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...
python
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", ")", ":", "# default action is to list *all* auto-detected files", "if", "not", "(", "system", "or", "user", "or", "local", ")", ":", "system", "=", "user", "=", "local", "=", "Tr...
List configuration files detected (and/or examined paths).
[ "List", "configuration", "files", "detected", "(", "and", "/", "or", "examined", "paths", ")", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/cli.py#L74-L83
train
dwavesystems/dwave-cloud-client
dwave/cloud/cli.py
inspect
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(...
python
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", ")", ":", "try", ":", "section", "=", "load_profile_from_files", "(", "[", "config_file", "]", "if", "config_file", "else", "None", ",", "profile", ")", "click", ".", "echo", "(", "\"Configuration file: {}\...
Inspect existing configuration/profile.
[ "Inspect", "existing", "configuration", "/", "profile", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/cli.py#L91-L105
train
dwavesystems/dwave-cloud-client
dwave/cloud/cli.py
create
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...
python
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", ")", ":", "# determine the config file path", "if", "config_file", ":", "click", ".", "echo", "(", "\"Using configuration file: {}\"", ".", "format", "(", "config_file", ")", ")", "else", ":", "# path not given, t...
Create and/or update cloud client configuration file.
[ "Create", "and", "/", "or", "update", "cloud", "client", "configuration", "file", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/cli.py#L113-L184
train
dwavesystems/dwave-cloud-client
dwave/cloud/cli.py
_ping
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...
python
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", ")", ":", "config", "=", "dict", "(", "config_file", "=", "config_file", ",", "profile", "=", "profile", ",", "solver", "=",...
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.
[ "Helper", "method", "for", "the", "ping", "command", "that", "uses", "output", "()", "for", "info", "output", "and", "raises", "CLIError", "()", "on", "handled", "errors", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/cli.py#L187-L259
train
dwavesystems/dwave-cloud-client
dwave/cloud/cli.py
ping
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) ...
python
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", ")", ":", "now", "=", "utcnow", "(", ")", "info", "=", "dict", "(", "datetime", "=", "now", ".", "isoformat", "(", "...
Ping the QPU by submitting a single-qubit problem.
[ "Ping", "the", "QPU", "by", "submitting", "a", "single", "-", "qubit", "problem", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/cli.py#L274-L298
train
dwavesystems/dwave-cloud-client
dwave/cloud/cli.py
solvers
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...
python
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", ")", ":", "with", "Client", ".", "from_config", "(", "config_file", "=", "config_file", ",", "profile", "=", "profile", ",", "solver", "=", "solver_def", ")", "as",...
Get solver details. Unless solver name/id specified, fetch and display details for all online solvers available on the configured endpoint.
[ "Get", "solver", "details", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/cli.py#L308-L342
train
dwavesystems/dwave-cloud-client
dwave/cloud/cli.py
sample
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...
python
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", ")", ":", "# TODO: de-dup wrt ping", "def", "echo", "(", "s", ",", "maxlen", "=", "100", ")", ...
Submit Ising-formulated problem and return samples.
[ "Submit", "Ising", "-", "formulated", "problem", "and", "return", "samples", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/cli.py#L362-L424
train
tuxu/python-samplerate
examples/play_modulation.py
get_input_callback
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...
python
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", ")", ":", "amplitude", "=", "params", "[", "'mod_amplitude'", "]", "frequency", "=", "params", "[", "'mod_frequency'", "]", "def", "producer", "(", ")", ":", "\"\"...
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.
[ "Return", "a", "function", "that", "produces", "samples", "of", "a", "sine", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/examples/play_modulation.py#L27-L57
train
tuxu/python-samplerate
examples/play_modulation.py
get_playback_callback
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...
python
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", ")", ":", "def", "callback", "(", "outdata", ",", "frames", ",", "time", ",", "_", ")", ":", "\"\"\"Playback callback.\n\n Read samples from the resampler and modulate them onto a c...
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.
[ "Return", "a", "sound", "playback", "callback", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/examples/play_modulation.py#L60-L88
train
tuxu/python-samplerate
examples/play_modulation.py
main
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), ...
python
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", ")", ":", "from", "time", "import", "sleep", "ratio", "=", "target_samplerate", "/", "source_samplerate", "with", "sr", ".", "CallbackResampler", "(", "get_inp...
Setup the resampling and audio output callbacks and start playback.
[ "Setup", "the", "resampling", "and", "audio", "output", "callbacks", "and", "start", "playback", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/examples/play_modulation.py#L91-L107
train
dwavesystems/dwave-cloud-client
dwave/cloud/solver.py
Solver.max_num_reads
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 - ...
python
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", ")", ":", "# 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", ...
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...
[ "Returns", "the", "maximum", "number", "of", "reads", "for", "the", "given", "solver", "parameters", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/solver.py#L227-L267
train
dwavesystems/dwave-cloud-client
dwave/cloud/solver.py
Solver.sample_ising
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...
python
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", ")", ":", "# Our linear and quadratic objective terms are already separated in an", "# ising model so we can just directly call `_sample`.", "return", "self", ".", "_sample", "(", ...
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...
[ "Sample", "from", "the", "specified", "Ising", "model", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/solver.py#L271-L306
train
dwavesystems/dwave-cloud-client
dwave/cloud/solver.py
Solver.sample_qubo
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. ...
python
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", ")", ":", "# 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", ":", ...
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...
[ "Sample", "from", "the", "specified", "QUBO", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/solver.py#L308-L346
train
dwavesystems/dwave-cloud-client
dwave/cloud/solver.py
Solver._sample
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...
python
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", ")", ":", "# Check the problem", "if", "not", "self", ".", "check_problem", "(", "linear", ",", "quadratic", ")", ":", "raise", "ValueError", "(", "\"Problem graph i...
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: :...
[ "Internal", "method", "for", "both", "sample_ising", "and", "sample_qubo", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/solver.py#L348-L388
train
dwavesystems/dwave-cloud-client
dwave/cloud/solver.py
Solver._format_params
def _format_params(self, type_, params): """Reformat some of the parameters for sapi.""" if 'initial_state' in params: # NB: at this moment the error raised when initial_state does not match lin/quad (in # active qubits) is not very informative, but there is also no clean way to ...
python
def _format_params(self, type_, params): """Reformat some of the parameters for sapi.""" if 'initial_state' in params: # NB: at this moment the error raised when initial_state does not match lin/quad (in # active qubits) is not very informative, but there is also no clean way to ...
[ "def", "_format_params", "(", "self", ",", "type_", ",", "params", ")", ":", "if", "'initial_state'", "in", "params", ":", "# NB: at this moment the error raised when initial_state does not match lin/quad (in", "# active qubits) is not very informative, but there is also no clean way...
Reformat some of the parameters for sapi.
[ "Reformat", "some", "of", "the", "parameters", "for", "sapi", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/solver.py#L390-L412
train
dwavesystems/dwave-cloud-client
dwave/cloud/solver.py
Solver.check_problem
def check_problem(self, linear, quadratic): """Test if an Ising model matches the graph provided by the solver. Args: linear (list/dict): Linear terms of the model (h). quadratic (dict of (int, int):float): Quadratic terms of the model (J). Returns: boolean ...
python
def check_problem(self, linear, quadratic): """Test if an Ising model matches the graph provided by the solver. Args: linear (list/dict): Linear terms of the model (h). quadratic (dict of (int, int):float): Quadratic terms of the model (J). Returns: boolean ...
[ "def", "check_problem", "(", "self", ",", "linear", ",", "quadratic", ")", ":", "for", "key", ",", "value", "in", "uniform_iterator", "(", "linear", ")", ":", "if", "value", "!=", "0", "and", "key", "not", "in", "self", ".", "nodes", ":", "return", "...
Test if an Ising model matches the graph provided by the solver. Args: linear (list/dict): Linear terms of the model (h). quadratic (dict of (int, int):float): Quadratic terms of the model (J). Returns: boolean Examples: This example creates a c...
[ "Test", "if", "an", "Ising", "model", "matches", "the", "graph", "provided", "by", "the", "solver", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/solver.py#L415-L451
train
dwavesystems/dwave-cloud-client
dwave/cloud/solver.py
Solver._retrieve_problem
def _retrieve_problem(self, id_): """Resume polling for a problem previously submitted. Args: id_: Identification of the query. Returns: :obj: `Future` """ future = Future(self, id_, self.return_matrix, None) self.client._poll(future) ret...
python
def _retrieve_problem(self, id_): """Resume polling for a problem previously submitted. Args: id_: Identification of the query. Returns: :obj: `Future` """ future = Future(self, id_, self.return_matrix, None) self.client._poll(future) ret...
[ "def", "_retrieve_problem", "(", "self", ",", "id_", ")", ":", "future", "=", "Future", "(", "self", ",", "id_", ",", "self", ".", "return_matrix", ",", "None", ")", "self", ".", "client", ".", "_poll", "(", "future", ")", "return", "future" ]
Resume polling for a problem previously submitted. Args: id_: Identification of the query. Returns: :obj: `Future`
[ "Resume", "polling", "for", "a", "problem", "previously", "submitted", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/solver.py#L453-L464
train
tuxu/python-samplerate
samplerate/converters.py
_get_converter_type
def _get_converter_type(identifier): """Return the converter type for `identifier`.""" if isinstance(identifier, str): return ConverterType[identifier] if isinstance(identifier, ConverterType): return identifier return ConverterType(identifier)
python
def _get_converter_type(identifier): """Return the converter type for `identifier`.""" if isinstance(identifier, str): return ConverterType[identifier] if isinstance(identifier, ConverterType): return identifier return ConverterType(identifier)
[ "def", "_get_converter_type", "(", "identifier", ")", ":", "if", "isinstance", "(", "identifier", ",", "str", ")", ":", "return", "ConverterType", "[", "identifier", "]", "if", "isinstance", "(", "identifier", ",", "ConverterType", ")", ":", "return", "identif...
Return the converter type for `identifier`.
[ "Return", "the", "converter", "type", "for", "identifier", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/samplerate/converters.py#L22-L28
train
tuxu/python-samplerate
samplerate/converters.py
resample
def resample(input_data, ratio, converter_type='sinc_best', verbose=False): """Resample the signal in `input_data` at once. Parameters ---------- input_data : ndarray Input data. A single channel is provided as a 1D array of `num_frames` length. Input data with several channels is repre...
python
def resample(input_data, ratio, converter_type='sinc_best', verbose=False): """Resample the signal in `input_data` at once. Parameters ---------- input_data : ndarray Input data. A single channel is provided as a 1D array of `num_frames` length. Input data with several channels is repre...
[ "def", "resample", "(", "input_data", ",", "ratio", ",", "converter_type", "=", "'sinc_best'", ",", "verbose", "=", "False", ")", ":", "from", "samplerate", ".", "lowlevel", "import", "src_simple", "from", "samplerate", ".", "exceptions", "import", "ResamplingEr...
Resample the signal in `input_data` at once. Parameters ---------- input_data : ndarray Input data. A single channel is provided as a 1D array of `num_frames` length. Input data with several channels is represented as a 2D array of shape (`num_frames`, `num_channels`). For use with ...
[ "Resample", "the", "signal", "in", "input_data", "at", "once", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/samplerate/converters.py#L31-L90
train
tuxu/python-samplerate
samplerate/converters.py
Resampler.set_ratio
def set_ratio(self, new_ratio): """Set a new conversion ratio immediately.""" from samplerate.lowlevel import src_set_ratio return src_set_ratio(self._state, new_ratio)
python
def set_ratio(self, new_ratio): """Set a new conversion ratio immediately.""" from samplerate.lowlevel import src_set_ratio return src_set_ratio(self._state, new_ratio)
[ "def", "set_ratio", "(", "self", ",", "new_ratio", ")", ":", "from", "samplerate", ".", "lowlevel", "import", "src_set_ratio", "return", "src_set_ratio", "(", "self", ".", "_state", ",", "new_ratio", ")" ]
Set a new conversion ratio immediately.
[ "Set", "a", "new", "conversion", "ratio", "immediately", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/samplerate/converters.py#L130-L133
train
tuxu/python-samplerate
samplerate/converters.py
Resampler.process
def process(self, input_data, ratio, end_of_input=False, verbose=False): """Resample the signal in `input_data`. Parameters ---------- input_data : ndarray Input data. A single channel is provided as a 1D array of `num_frames` length. Input data with several chan...
python
def process(self, input_data, ratio, end_of_input=False, verbose=False): """Resample the signal in `input_data`. Parameters ---------- input_data : ndarray Input data. A single channel is provided as a 1D array of `num_frames` length. Input data with several chan...
[ "def", "process", "(", "self", ",", "input_data", ",", "ratio", ",", "end_of_input", "=", "False", ",", "verbose", "=", "False", ")", ":", "from", "samplerate", ".", "lowlevel", "import", "src_process", "from", "samplerate", ".", "exceptions", "import", "Res...
Resample the signal in `input_data`. Parameters ---------- input_data : ndarray Input data. A single channel is provided as a 1D array of `num_frames` length. Input data with several channels is represented as a 2D array of shape (`num_frames`, `num_channels`...
[ "Resample", "the", "signal", "in", "input_data", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/samplerate/converters.py#L135-L189
train
tuxu/python-samplerate
samplerate/converters.py
CallbackResampler._create
def _create(self): """Create new callback resampler.""" from samplerate.lowlevel import ffi, src_callback_new, src_delete from samplerate.exceptions import ResamplingError state, handle, error = src_callback_new( self._callback, self._converter_type.value, self._channels) ...
python
def _create(self): """Create new callback resampler.""" from samplerate.lowlevel import ffi, src_callback_new, src_delete from samplerate.exceptions import ResamplingError state, handle, error = src_callback_new( self._callback, self._converter_type.value, self._channels) ...
[ "def", "_create", "(", "self", ")", ":", "from", "samplerate", ".", "lowlevel", "import", "ffi", ",", "src_callback_new", ",", "src_delete", "from", "samplerate", ".", "exceptions", "import", "ResamplingError", "state", ",", "handle", ",", "error", "=", "src_c...
Create new callback resampler.
[ "Create", "new", "callback", "resampler", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/samplerate/converters.py#L222-L232
train
tuxu/python-samplerate
samplerate/converters.py
CallbackResampler.set_starting_ratio
def set_starting_ratio(self, ratio): """ Set the starting conversion ratio for the next `read` call. """ from samplerate.lowlevel import src_set_ratio if self._state is None: self._create() src_set_ratio(self._state, ratio) self.ratio = ratio
python
def set_starting_ratio(self, ratio): """ Set the starting conversion ratio for the next `read` call. """ from samplerate.lowlevel import src_set_ratio if self._state is None: self._create() src_set_ratio(self._state, ratio) self.ratio = ratio
[ "def", "set_starting_ratio", "(", "self", ",", "ratio", ")", ":", "from", "samplerate", ".", "lowlevel", "import", "src_set_ratio", "if", "self", ".", "_state", "is", "None", ":", "self", ".", "_create", "(", ")", "src_set_ratio", "(", "self", ".", "_state...
Set the starting conversion ratio for the next `read` call.
[ "Set", "the", "starting", "conversion", "ratio", "for", "the", "next", "read", "call", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/samplerate/converters.py#L246-L252
train
tuxu/python-samplerate
samplerate/converters.py
CallbackResampler.reset
def reset(self): """Reset state.""" from samplerate.lowlevel import src_reset if self._state is None: self._create() src_reset(self._state)
python
def reset(self): """Reset state.""" from samplerate.lowlevel import src_reset if self._state is None: self._create() src_reset(self._state)
[ "def", "reset", "(", "self", ")", ":", "from", "samplerate", ".", "lowlevel", "import", "src_reset", "if", "self", ".", "_state", "is", "None", ":", "self", ".", "_create", "(", ")", "src_reset", "(", "self", ".", "_state", ")" ]
Reset state.
[ "Reset", "state", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/samplerate/converters.py#L254-L259
train
tuxu/python-samplerate
samplerate/converters.py
CallbackResampler.read
def read(self, num_frames): """Read a number of frames from the resampler. Parameters ---------- num_frames : int Number of frames to read. Returns ------- output_data : ndarray Resampled frames as a (`num_output_frames`, `num_channels`) ...
python
def read(self, num_frames): """Read a number of frames from the resampler. Parameters ---------- num_frames : int Number of frames to read. Returns ------- output_data : ndarray Resampled frames as a (`num_output_frames`, `num_channels`) ...
[ "def", "read", "(", "self", ",", "num_frames", ")", ":", "from", "samplerate", ".", "lowlevel", "import", "src_callback_read", ",", "src_error", "from", "samplerate", ".", "exceptions", "import", "ResamplingError", "if", "self", ".", "_state", "is", "None", ":...
Read a number of frames from the resampler. Parameters ---------- num_frames : int Number of frames to read. Returns ------- output_data : ndarray Resampled frames as a (`num_output_frames`, `num_channels`) or (`num_output_frames`,) a...
[ "Read", "a", "number", "of", "frames", "from", "the", "resampler", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/samplerate/converters.py#L270-L304
train
chrisspen/dtree
dtree.py
get_variance
def get_variance(seq): """ Batch variance calculation. """ m = get_mean(seq) return sum((v-m)**2 for v in seq)/float(len(seq))
python
def get_variance(seq): """ Batch variance calculation. """ m = get_mean(seq) return sum((v-m)**2 for v in seq)/float(len(seq))
[ "def", "get_variance", "(", "seq", ")", ":", "m", "=", "get_mean", "(", "seq", ")", "return", "sum", "(", "(", "v", "-", "m", ")", "**", "2", "for", "v", "in", "seq", ")", "/", "float", "(", "len", "(", "seq", ")", ")" ]
Batch variance calculation.
[ "Batch", "variance", "calculation", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L91-L96
train
chrisspen/dtree
dtree.py
mean_absolute_error
def mean_absolute_error(seq, correct): """ Batch mean absolute error calculation. """ assert len(seq) == len(correct) diffs = [abs(a-b) for a, b in zip(seq, correct)] return sum(diffs)/float(len(diffs))
python
def mean_absolute_error(seq, correct): """ Batch mean absolute error calculation. """ assert len(seq) == len(correct) diffs = [abs(a-b) for a, b in zip(seq, correct)] return sum(diffs)/float(len(diffs))
[ "def", "mean_absolute_error", "(", "seq", ",", "correct", ")", ":", "assert", "len", "(", "seq", ")", "==", "len", "(", "correct", ")", "diffs", "=", "[", "abs", "(", "a", "-", "b", ")", "for", "a", ",", "b", "in", "zip", "(", "seq", ",", "corr...
Batch mean absolute error calculation.
[ "Batch", "mean", "absolute", "error", "calculation", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L101-L107
train
chrisspen/dtree
dtree.py
normalize
def normalize(seq): """ Scales each number in the sequence so that the sum of all numbers equals 1. """ s = float(sum(seq)) return [v/s for v in seq]
python
def normalize(seq): """ Scales each number in the sequence so that the sum of all numbers equals 1. """ s = float(sum(seq)) return [v/s for v in seq]
[ "def", "normalize", "(", "seq", ")", ":", "s", "=", "float", "(", "sum", "(", "seq", ")", ")", "return", "[", "v", "/", "s", "for", "v", "in", "seq", "]" ]
Scales each number in the sequence so that the sum of all numbers equals 1.
[ "Scales", "each", "number", "in", "the", "sequence", "so", "that", "the", "sum", "of", "all", "numbers", "equals", "1", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L109-L114
train
chrisspen/dtree
dtree.py
normcdf
def normcdf(x, mu, sigma): """ Describes the probability that a real-valued random variable X with a given probability distribution will be found at a value less than or equal to X in a normal distribution. http://en.wikipedia.org/wiki/Cumulative_distribution_function """ t = x-mu y...
python
def normcdf(x, mu, sigma): """ Describes the probability that a real-valued random variable X with a given probability distribution will be found at a value less than or equal to X in a normal distribution. http://en.wikipedia.org/wiki/Cumulative_distribution_function """ t = x-mu y...
[ "def", "normcdf", "(", "x", ",", "mu", ",", "sigma", ")", ":", "t", "=", "x", "-", "mu", "y", "=", "0.5", "*", "erfcc", "(", "-", "t", "/", "(", "sigma", "*", "math", ".", "sqrt", "(", "2.0", ")", ")", ")", "if", "y", ">", "1.0", ":", "...
Describes the probability that a real-valued random variable X with a given probability distribution will be found at a value less than or equal to X in a normal distribution. http://en.wikipedia.org/wiki/Cumulative_distribution_function
[ "Describes", "the", "probability", "that", "a", "real", "-", "valued", "random", "variable", "X", "with", "a", "given", "probability", "distribution", "will", "be", "found", "at", "a", "value", "less", "than", "or", "equal", "to", "X", "in", "a", "normal",...
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L131-L143
train
chrisspen/dtree
dtree.py
normpdf
def normpdf(x, mu, sigma): """ Describes the relative likelihood that a real-valued random variable X will take on a given value. http://en.wikipedia.org/wiki/Probability_density_function """ u = (x-mu)/abs(sigma) y = (1/(math.sqrt(2*pi)*abs(sigma)))*math.exp(-u*u/2) return y
python
def normpdf(x, mu, sigma): """ Describes the relative likelihood that a real-valued random variable X will take on a given value. http://en.wikipedia.org/wiki/Probability_density_function """ u = (x-mu)/abs(sigma) y = (1/(math.sqrt(2*pi)*abs(sigma)))*math.exp(-u*u/2) return y
[ "def", "normpdf", "(", "x", ",", "mu", ",", "sigma", ")", ":", "u", "=", "(", "x", "-", "mu", ")", "/", "abs", "(", "sigma", ")", "y", "=", "(", "1", "/", "(", "math", ".", "sqrt", "(", "2", "*", "pi", ")", "*", "abs", "(", "sigma", ")"...
Describes the relative likelihood that a real-valued random variable X will take on a given value. http://en.wikipedia.org/wiki/Probability_density_function
[ "Describes", "the", "relative", "likelihood", "that", "a", "real", "-", "valued", "random", "variable", "X", "will", "take", "on", "a", "given", "value", ".", "http", ":", "//", "en", ".", "wikipedia", ".", "org", "/", "wiki", "/", "Probability_density_fun...
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L145-L154
train
chrisspen/dtree
dtree.py
entropy
def entropy(data, class_attr=None, method=DEFAULT_DISCRETE_METRIC): """ Calculates the entropy of the attribute attr in given data set data. Parameters: data<dict|list> := if dict, treated as value counts of the given attribute name if list, treated as a raw list from which the valu...
python
def entropy(data, class_attr=None, method=DEFAULT_DISCRETE_METRIC): """ Calculates the entropy of the attribute attr in given data set data. Parameters: data<dict|list> := if dict, treated as value counts of the given attribute name if list, treated as a raw list from which the valu...
[ "def", "entropy", "(", "data", ",", "class_attr", "=", "None", ",", "method", "=", "DEFAULT_DISCRETE_METRIC", ")", ":", "assert", "(", "class_attr", "is", "None", "and", "isinstance", "(", "data", ",", "dict", ")", ")", "or", "(", "class_attr", "is", "no...
Calculates the entropy of the attribute attr in given data set data. Parameters: data<dict|list> := if dict, treated as value counts of the given attribute name if list, treated as a raw list from which the value counts will be generated attr<string> := the name of the class attribute
[ "Calculates", "the", "entropy", "of", "the", "attribute", "attr", "in", "given", "data", "set", "data", ".", "Parameters", ":", "data<dict|list", ">", ":", "=", "if", "dict", "treated", "as", "value", "counts", "of", "the", "given", "attribute", "name", "i...
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L374-L412
train
chrisspen/dtree
dtree.py
entropy_variance
def entropy_variance(data, class_attr=None, method=DEFAULT_CONTINUOUS_METRIC): """ Calculates the variance fo a continuous class attribute, to be used as an entropy metric. """ assert method in CONTINUOUS_METRICS, "Unknown entropy variance metric: %s" % (method,) assert (class_attr is None a...
python
def entropy_variance(data, class_attr=None, method=DEFAULT_CONTINUOUS_METRIC): """ Calculates the variance fo a continuous class attribute, to be used as an entropy metric. """ assert method in CONTINUOUS_METRICS, "Unknown entropy variance metric: %s" % (method,) assert (class_attr is None a...
[ "def", "entropy_variance", "(", "data", ",", "class_attr", "=", "None", ",", "method", "=", "DEFAULT_CONTINUOUS_METRIC", ")", ":", "assert", "method", "in", "CONTINUOUS_METRICS", ",", "\"Unknown entropy variance metric: %s\"", "%", "(", "method", ",", ")", "assert",...
Calculates the variance fo a continuous class attribute, to be used as an entropy metric.
[ "Calculates", "the", "variance", "fo", "a", "continuous", "class", "attribute", "to", "be", "used", "as", "an", "entropy", "metric", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L414-L427
train
chrisspen/dtree
dtree.py
get_gain
def get_gain(data, attr, class_attr, method=DEFAULT_DISCRETE_METRIC, only_sub=0, prefer_fewer_values=False, entropy_func=None): """ Calculates the information gain (reduction in entropy) that would result by splitting the data on the chosen attribute (attr). Parameters: prefer_fewe...
python
def get_gain(data, attr, class_attr, method=DEFAULT_DISCRETE_METRIC, only_sub=0, prefer_fewer_values=False, entropy_func=None): """ Calculates the information gain (reduction in entropy) that would result by splitting the data on the chosen attribute (attr). Parameters: prefer_fewe...
[ "def", "get_gain", "(", "data", ",", "attr", ",", "class_attr", ",", "method", "=", "DEFAULT_DISCRETE_METRIC", ",", "only_sub", "=", "0", ",", "prefer_fewer_values", "=", "False", ",", "entropy_func", "=", "None", ")", ":", "entropy_func", "=", "entropy_func",...
Calculates the information gain (reduction in entropy) that would result by splitting the data on the chosen attribute (attr). Parameters: prefer_fewer_values := Weights the gain by the count of the attribute's unique values. If multiple attributes have the same gain, but one has s...
[ "Calculates", "the", "information", "gain", "(", "reduction", "in", "entropy", ")", "that", "would", "result", "by", "splitting", "the", "data", "on", "the", "chosen", "attribute", "(", "attr", ")", ".", "Parameters", ":", "prefer_fewer_values", ":", "=", "W...
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L429-L473
train
chrisspen/dtree
dtree.py
majority_value
def majority_value(data, class_attr): """ Creates a list of all values in the target attribute for each record in the data list object, and returns the value that appears in this list the most frequently. """ if is_continuous(data[0][class_attr]): return CDist(seq=[record[class_attr] for...
python
def majority_value(data, class_attr): """ Creates a list of all values in the target attribute for each record in the data list object, and returns the value that appears in this list the most frequently. """ if is_continuous(data[0][class_attr]): return CDist(seq=[record[class_attr] for...
[ "def", "majority_value", "(", "data", ",", "class_attr", ")", ":", "if", "is_continuous", "(", "data", "[", "0", "]", "[", "class_attr", "]", ")", ":", "return", "CDist", "(", "seq", "=", "[", "record", "[", "class_attr", "]", "for", "record", "in", ...
Creates a list of all values in the target attribute for each record in the data list object, and returns the value that appears in this list the most frequently.
[ "Creates", "a", "list", "of", "all", "values", "in", "the", "target", "attribute", "for", "each", "record", "in", "the", "data", "list", "object", "and", "returns", "the", "value", "that", "appears", "in", "this", "list", "the", "most", "frequently", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L481-L490
train
chrisspen/dtree
dtree.py
most_frequent
def most_frequent(lst): """ Returns the item that appears most frequently in the given list. """ lst = lst[:] highest_freq = 0 most_freq = None for val in unique(lst): if lst.count(val) > highest_freq: most_freq = val highest_freq = lst.count(val) ...
python
def most_frequent(lst): """ Returns the item that appears most frequently in the given list. """ lst = lst[:] highest_freq = 0 most_freq = None for val in unique(lst): if lst.count(val) > highest_freq: most_freq = val highest_freq = lst.count(val) ...
[ "def", "most_frequent", "(", "lst", ")", ":", "lst", "=", "lst", "[", ":", "]", "highest_freq", "=", "0", "most_freq", "=", "None", "for", "val", "in", "unique", "(", "lst", ")", ":", "if", "lst", ".", "count", "(", "val", ")", ">", "highest_freq",...
Returns the item that appears most frequently in the given list.
[ "Returns", "the", "item", "that", "appears", "most", "frequently", "in", "the", "given", "list", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L492-L505
train
chrisspen/dtree
dtree.py
unique
def unique(lst): """ Returns a list made up of the unique values found in lst. i.e., it removes the redundant values in lst. """ lst = lst[:] unique_lst = [] # Cycle through the list and add each value to the unique list only once. for item in lst: if unique_lst.count(item) <= ...
python
def unique(lst): """ Returns a list made up of the unique values found in lst. i.e., it removes the redundant values in lst. """ lst = lst[:] unique_lst = [] # Cycle through the list and add each value to the unique list only once. for item in lst: if unique_lst.count(item) <= ...
[ "def", "unique", "(", "lst", ")", ":", "lst", "=", "lst", "[", ":", "]", "unique_lst", "=", "[", "]", "# Cycle through the list and add each value to the unique list only once.", "for", "item", "in", "lst", ":", "if", "unique_lst", ".", "count", "(", "item", "...
Returns a list made up of the unique values found in lst. i.e., it removes the redundant values in lst.
[ "Returns", "a", "list", "made", "up", "of", "the", "unique", "values", "found", "in", "lst", ".", "i", ".", "e", ".", "it", "removes", "the", "redundant", "values", "in", "lst", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L507-L521
train
chrisspen/dtree
dtree.py
choose_attribute
def choose_attribute(data, attributes, class_attr, fitness, method): """ Cycles through all the attributes and returns the attribute with the highest information gain (or lowest entropy). """ best = (-1e999999, None) for attr in attributes: if attr == class_attr: continue ...
python
def choose_attribute(data, attributes, class_attr, fitness, method): """ Cycles through all the attributes and returns the attribute with the highest information gain (or lowest entropy). """ best = (-1e999999, None) for attr in attributes: if attr == class_attr: continue ...
[ "def", "choose_attribute", "(", "data", ",", "attributes", ",", "class_attr", ",", "fitness", ",", "method", ")", ":", "best", "=", "(", "-", "1e999999", ",", "None", ")", "for", "attr", "in", "attributes", ":", "if", "attr", "==", "class_attr", ":", "...
Cycles through all the attributes and returns the attribute with the highest information gain (or lowest entropy).
[ "Cycles", "through", "all", "the", "attributes", "and", "returns", "the", "attribute", "with", "the", "highest", "information", "gain", "(", "or", "lowest", "entropy", ")", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L530-L541
train
chrisspen/dtree
dtree.py
create_decision_tree
def create_decision_tree(data, attributes, class_attr, fitness_func, wrapper, **kwargs): """ Returns a new decision tree based on the examples given. """ split_attr = kwargs.get('split_attr', None) split_val = kwargs.get('split_val', None) assert class_attr not in attributes node =...
python
def create_decision_tree(data, attributes, class_attr, fitness_func, wrapper, **kwargs): """ Returns a new decision tree based on the examples given. """ split_attr = kwargs.get('split_attr', None) split_val = kwargs.get('split_val', None) assert class_attr not in attributes node =...
[ "def", "create_decision_tree", "(", "data", ",", "attributes", ",", "class_attr", ",", "fitness_func", ",", "wrapper", ",", "*", "*", "kwargs", ")", ":", "split_attr", "=", "kwargs", ".", "get", "(", "'split_attr'", ",", "None", ")", "split_val", "=", "kwa...
Returns a new decision tree based on the examples given.
[ "Returns", "a", "new", "decision", "tree", "based", "on", "the", "examples", "given", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L546-L619
train
chrisspen/dtree
dtree.py
DDist.add
def add(self, k, count=1): """ Increments the count for the given element. """ self.counts[k] += count self.total += count
python
def add(self, k, count=1): """ Increments the count for the given element. """ self.counts[k] += count self.total += count
[ "def", "add", "(", "self", ",", "k", ",", "count", "=", "1", ")", ":", "self", ".", "counts", "[", "k", "]", "+=", "count", "self", ".", "total", "+=", "count" ]
Increments the count for the given element.
[ "Increments", "the", "count", "for", "the", "given", "element", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L215-L220
train
chrisspen/dtree
dtree.py
DDist.best
def best(self): """ Returns the element with the highest probability. """ b = (-1e999999, None) for k, c in iteritems(self.counts): b = max(b, (c, k)) return b[1]
python
def best(self): """ Returns the element with the highest probability. """ b = (-1e999999, None) for k, c in iteritems(self.counts): b = max(b, (c, k)) return b[1]
[ "def", "best", "(", "self", ")", ":", "b", "=", "(", "-", "1e999999", ",", "None", ")", "for", "k", ",", "c", "in", "iteritems", "(", "self", ".", "counts", ")", ":", "b", "=", "max", "(", "b", ",", "(", "c", ",", "k", ")", ")", "return", ...
Returns the element with the highest probability.
[ "Returns", "the", "element", "with", "the", "highest", "probability", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L223-L230
train
chrisspen/dtree
dtree.py
DDist.probs
def probs(self): """ Returns a list of probabilities for all elements in the form [(value1,prob1),(value2,prob2),...]. """ return [ (k, self.counts[k]/float(self.total)) for k in iterkeys(self.counts) ]
python
def probs(self): """ Returns a list of probabilities for all elements in the form [(value1,prob1),(value2,prob2),...]. """ return [ (k, self.counts[k]/float(self.total)) for k in iterkeys(self.counts) ]
[ "def", "probs", "(", "self", ")", ":", "return", "[", "(", "k", ",", "self", ".", "counts", "[", "k", "]", "/", "float", "(", "self", ".", "total", ")", ")", "for", "k", "in", "iterkeys", "(", "self", ".", "counts", ")", "]" ]
Returns a list of probabilities for all elements in the form [(value1,prob1),(value2,prob2),...].
[ "Returns", "a", "list", "of", "probabilities", "for", "all", "elements", "in", "the", "form", "[", "(", "value1", "prob1", ")", "(", "value2", "prob2", ")", "...", "]", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L260-L268
train
chrisspen/dtree
dtree.py
DDist.update
def update(self, dist): """ Adds the given distribution's counts to the current distribution. """ assert isinstance(dist, DDist) for k, c in iteritems(dist.counts): self.counts[k] += c self.total += dist.total
python
def update(self, dist): """ Adds the given distribution's counts to the current distribution. """ assert isinstance(dist, DDist) for k, c in iteritems(dist.counts): self.counts[k] += c self.total += dist.total
[ "def", "update", "(", "self", ",", "dist", ")", ":", "assert", "isinstance", "(", "dist", ",", "DDist", ")", "for", "k", ",", "c", "in", "iteritems", "(", "dist", ".", "counts", ")", ":", "self", ".", "counts", "[", "k", "]", "+=", "c", "self", ...
Adds the given distribution's counts to the current distribution.
[ "Adds", "the", "given", "distribution", "s", "counts", "to", "the", "current", "distribution", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L270-L277
train
chrisspen/dtree
dtree.py
CDist.probability_lt
def probability_lt(self, x): """ Returns the probability of a random variable being less than the given value. """ if self.mean is None: return return normdist(x=x, mu=self.mean, sigma=self.standard_deviation)
python
def probability_lt(self, x): """ Returns the probability of a random variable being less than the given value. """ if self.mean is None: return return normdist(x=x, mu=self.mean, sigma=self.standard_deviation)
[ "def", "probability_lt", "(", "self", ",", "x", ")", ":", "if", "self", ".", "mean", "is", "None", ":", "return", "return", "normdist", "(", "x", "=", "x", ",", "mu", "=", "self", ".", "mean", ",", "sigma", "=", "self", ".", "standard_deviation", "...
Returns the probability of a random variable being less than the given value.
[ "Returns", "the", "probability", "of", "a", "random", "variable", "being", "less", "than", "the", "given", "value", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L344-L351
train
chrisspen/dtree
dtree.py
CDist.probability_in
def probability_in(self, a, b): """ Returns the probability of a random variable falling between the given values. """ if self.mean is None: return p1 = normdist(x=a, mu=self.mean, sigma=self.standard_deviation) p2 = normdist(x=b, mu=self.mean, sigma=s...
python
def probability_in(self, a, b): """ Returns the probability of a random variable falling between the given values. """ if self.mean is None: return p1 = normdist(x=a, mu=self.mean, sigma=self.standard_deviation) p2 = normdist(x=b, mu=self.mean, sigma=s...
[ "def", "probability_in", "(", "self", ",", "a", ",", "b", ")", ":", "if", "self", ".", "mean", "is", "None", ":", "return", "p1", "=", "normdist", "(", "x", "=", "a", ",", "mu", "=", "self", ".", "mean", ",", "sigma", "=", "self", ".", "standar...
Returns the probability of a random variable falling between the given values.
[ "Returns", "the", "probability", "of", "a", "random", "variable", "falling", "between", "the", "given", "values", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L353-L362
train
chrisspen/dtree
dtree.py
CDist.probability_gt
def probability_gt(self, x): """ Returns the probability of a random variable being greater than the given value. """ if self.mean is None: return p = normdist(x=x, mu=self.mean, sigma=self.standard_deviation) return 1-p
python
def probability_gt(self, x): """ Returns the probability of a random variable being greater than the given value. """ if self.mean is None: return p = normdist(x=x, mu=self.mean, sigma=self.standard_deviation) return 1-p
[ "def", "probability_gt", "(", "self", ",", "x", ")", ":", "if", "self", ".", "mean", "is", "None", ":", "return", "p", "=", "normdist", "(", "x", "=", "x", ",", "mu", "=", "self", ".", "mean", ",", "sigma", "=", "self", ".", "standard_deviation", ...
Returns the probability of a random variable being greater than the given value.
[ "Returns", "the", "probability", "of", "a", "random", "variable", "being", "greater", "than", "the", "given", "value", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L364-L372
train
chrisspen/dtree
dtree.py
Data.copy_no_data
def copy_no_data(self): """ Returns a copy of the object without any data. """ return type(self)( [], order=list(self.header_modes), types=self.header_types.copy(), modes=self.header_modes.copy())
python
def copy_no_data(self): """ Returns a copy of the object without any data. """ return type(self)( [], order=list(self.header_modes), types=self.header_types.copy(), modes=self.header_modes.copy())
[ "def", "copy_no_data", "(", "self", ")", ":", "return", "type", "(", "self", ")", "(", "[", "]", ",", "order", "=", "list", "(", "self", ".", "header_modes", ")", ",", "types", "=", "self", ".", "header_types", ".", "copy", "(", ")", ",", "modes", ...
Returns a copy of the object without any data.
[ "Returns", "a", "copy", "of", "the", "object", "without", "any", "data", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L667-L675
train
chrisspen/dtree
dtree.py
Data.is_valid
def is_valid(self, name, value): """ Returns true if the given value matches the type for the given name according to the schema. Returns false otherwise. """ if name not in self.header_types: return False t = self.header_types[name] if t == AT...
python
def is_valid(self, name, value): """ Returns true if the given value matches the type for the given name according to the schema. Returns false otherwise. """ if name not in self.header_types: return False t = self.header_types[name] if t == AT...
[ "def", "is_valid", "(", "self", ",", "name", ",", "value", ")", ":", "if", "name", "not", "in", "self", ".", "header_types", ":", "return", "False", "t", "=", "self", ".", "header_types", "[", "name", "]", "if", "t", "==", "ATTR_TYPE_DISCRETE", ":", ...
Returns true if the given value matches the type for the given name according to the schema. Returns false otherwise.
[ "Returns", "true", "if", "the", "given", "value", "matches", "the", "type", "for", "the", "given", "name", "according", "to", "the", "schema", ".", "Returns", "false", "otherwise", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L710-L723
train
chrisspen/dtree
dtree.py
Data._read_header
def _read_header(self): """ When a CSV file is given, extracts header information the file. Otherwise, this header data must be explicitly given when the object is instantiated. """ if not self.filename or self.header_types: return rows = csv.reader(op...
python
def _read_header(self): """ When a CSV file is given, extracts header information the file. Otherwise, this header data must be explicitly given when the object is instantiated. """ if not self.filename or self.header_types: return rows = csv.reader(op...
[ "def", "_read_header", "(", "self", ")", ":", "if", "not", "self", ".", "filename", "or", "self", ".", "header_types", ":", "return", "rows", "=", "csv", ".", "reader", "(", "open", "(", "self", ".", "filename", ")", ")", "#header = rows.next()", "header...
When a CSV file is given, extracts header information the file. Otherwise, this header data must be explicitly given when the object is instantiated.
[ "When", "a", "CSV", "file", "is", "given", "extracts", "header", "information", "the", "file", ".", "Otherwise", "this", "header", "data", "must", "be", "explicitly", "given", "when", "the", "object", "is", "instantiated", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L725-L753
train
chrisspen/dtree
dtree.py
Data.validate_row
def validate_row(self, row): """ Ensure each element in the row matches the schema. """ clean_row = {} if isinstance(row, (tuple, list)): assert self.header_order, "No attribute order specified." assert len(row) == len(self.header_order), \ ...
python
def validate_row(self, row): """ Ensure each element in the row matches the schema. """ clean_row = {} if isinstance(row, (tuple, list)): assert self.header_order, "No attribute order specified." assert len(row) == len(self.header_order), \ ...
[ "def", "validate_row", "(", "self", ",", "row", ")", ":", "clean_row", "=", "{", "}", "if", "isinstance", "(", "row", ",", "(", "tuple", ",", "list", ")", ")", ":", "assert", "self", ".", "header_order", ",", "\"No attribute order specified.\"", "assert", ...
Ensure each element in the row matches the schema.
[ "Ensure", "each", "element", "in", "the", "row", "matches", "the", "schema", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L755-L775
train
chrisspen/dtree
dtree.py
Data.split
def split(self, ratio=0.5, leave_one_out=False): """ Returns two Data instances, containing the data randomly split between the two according to the given ratio. The first instance will contain the ratio of data specified. The second instance will contain the remaining r...
python
def split(self, ratio=0.5, leave_one_out=False): """ Returns two Data instances, containing the data randomly split between the two according to the given ratio. The first instance will contain the ratio of data specified. The second instance will contain the remaining r...
[ "def", "split", "(", "self", ",", "ratio", "=", "0.5", ",", "leave_one_out", "=", "False", ")", ":", "a_labels", "=", "set", "(", ")", "a", "=", "self", ".", "copy_no_data", "(", ")", "b", "=", "self", ".", "copy_no_data", "(", ")", "for", "row", ...
Returns two Data instances, containing the data randomly split between the two according to the given ratio. The first instance will contain the ratio of data specified. The second instance will contain the remaining ratio of data. If leave_one_out is True, the ratio wi...
[ "Returns", "two", "Data", "instances", "containing", "the", "data", "randomly", "split", "between", "the", "two", "according", "to", "the", "given", "ratio", ".", "The", "first", "instance", "will", "contain", "the", "ratio", "of", "data", "specified", ".", ...
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L791-L822
train
chrisspen/dtree
dtree.py
Node._get_attribute_value_for_node
def _get_attribute_value_for_node(self, record): """ Gets the closest value for the current node's attribute matching the given record. """ # Abort if this node has not get split on an attribute. if self.attr_name is None: return # O...
python
def _get_attribute_value_for_node(self, record): """ Gets the closest value for the current node's attribute matching the given record. """ # Abort if this node has not get split on an attribute. if self.attr_name is None: return # O...
[ "def", "_get_attribute_value_for_node", "(", "self", ",", "record", ")", ":", "# Abort if this node has not get split on an attribute. ", "if", "self", ".", "attr_name", "is", "None", ":", "return", "# Otherwise, lookup the attribute value for this node in the", "# given record."...
Gets the closest value for the current node's attribute matching the given record.
[ "Gets", "the", "closest", "value", "for", "the", "current", "node", "s", "attribute", "matching", "the", "given", "record", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L896-L935
train
chrisspen/dtree
dtree.py
Node.get_values
def get_values(self, attr_name): """ Retrieves the unique set of values seen for the given attribute at this node. """ ret = list(self._attr_value_cdist[attr_name].keys()) \ + list(self._attr_value_counts[attr_name].keys()) \ + list(self._branches.keys()) ...
python
def get_values(self, attr_name): """ Retrieves the unique set of values seen for the given attribute at this node. """ ret = list(self._attr_value_cdist[attr_name].keys()) \ + list(self._attr_value_counts[attr_name].keys()) \ + list(self._branches.keys()) ...
[ "def", "get_values", "(", "self", ",", "attr_name", ")", ":", "ret", "=", "list", "(", "self", ".", "_attr_value_cdist", "[", "attr_name", "]", ".", "keys", "(", ")", ")", "+", "list", "(", "self", ".", "_attr_value_counts", "[", "attr_name", "]", ".",...
Retrieves the unique set of values seen for the given attribute at this node.
[ "Retrieves", "the", "unique", "set", "of", "values", "seen", "for", "the", "given", "attribute", "at", "this", "node", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L941-L950
train
chrisspen/dtree
dtree.py
Node.get_best_splitting_attr
def get_best_splitting_attr(self): """ Returns the name of the attribute with the highest gain. """ best = (-1e999999, None) for attr in self.attributes: best = max(best, (self.get_gain(attr), attr)) best_gain, best_attr = best return best_attr
python
def get_best_splitting_attr(self): """ Returns the name of the attribute with the highest gain. """ best = (-1e999999, None) for attr in self.attributes: best = max(best, (self.get_gain(attr), attr)) best_gain, best_attr = best return best_attr
[ "def", "get_best_splitting_attr", "(", "self", ")", ":", "best", "=", "(", "-", "1e999999", ",", "None", ")", "for", "attr", "in", "self", ".", "attributes", ":", "best", "=", "max", "(", "best", ",", "(", "self", ".", "get_gain", "(", "attr", ")", ...
Returns the name of the attribute with the highest gain.
[ "Returns", "the", "name", "of", "the", "attribute", "with", "the", "highest", "gain", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L956-L964
train
chrisspen/dtree
dtree.py
Node.get_entropy
def get_entropy(self, attr_name=None, attr_value=None): """ Calculates the entropy of a specific attribute/value combination. """ is_con = self.tree.data.is_continuous_class if is_con: if attr_name is None: # Calculate variance of class attribute. ...
python
def get_entropy(self, attr_name=None, attr_value=None): """ Calculates the entropy of a specific attribute/value combination. """ is_con = self.tree.data.is_continuous_class if is_con: if attr_name is None: # Calculate variance of class attribute. ...
[ "def", "get_entropy", "(", "self", ",", "attr_name", "=", "None", ",", "attr_value", "=", "None", ")", ":", "is_con", "=", "self", ".", "tree", ".", "data", ".", "is_continuous_class", "if", "is_con", ":", "if", "attr_name", "is", "None", ":", "# Calcula...
Calculates the entropy of a specific attribute/value combination.
[ "Calculates", "the", "entropy", "of", "a", "specific", "attribute", "/", "value", "combination", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L966-L1026
train
chrisspen/dtree
dtree.py
Node.get_gain
def get_gain(self, attr_name): """ Calculates the information gain from splitting on the given attribute. """ subset_entropy = 0.0 for value in iterkeys(self._attr_value_counts[attr_name]): value_prob = self.get_value_prob(attr_name, value) e = self.get_en...
python
def get_gain(self, attr_name): """ Calculates the information gain from splitting on the given attribute. """ subset_entropy = 0.0 for value in iterkeys(self._attr_value_counts[attr_name]): value_prob = self.get_value_prob(attr_name, value) e = self.get_en...
[ "def", "get_gain", "(", "self", ",", "attr_name", ")", ":", "subset_entropy", "=", "0.0", "for", "value", "in", "iterkeys", "(", "self", ".", "_attr_value_counts", "[", "attr_name", "]", ")", ":", "value_prob", "=", "self", ".", "get_value_prob", "(", "att...
Calculates the information gain from splitting on the given attribute.
[ "Calculates", "the", "information", "gain", "from", "splitting", "on", "the", "given", "attribute", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1028-L1037
train
chrisspen/dtree
dtree.py
Node.get_value_ddist
def get_value_ddist(self, attr_name, attr_value): """ Returns the class value probability distribution of the given attribute value. """ assert not self.tree.data.is_continuous_class, \ "Discrete distributions are only maintained for " + \ "discrete class ...
python
def get_value_ddist(self, attr_name, attr_value): """ Returns the class value probability distribution of the given attribute value. """ assert not self.tree.data.is_continuous_class, \ "Discrete distributions are only maintained for " + \ "discrete class ...
[ "def", "get_value_ddist", "(", "self", ",", "attr_name", ",", "attr_value", ")", ":", "assert", "not", "self", ".", "tree", ".", "data", ".", "is_continuous_class", ",", "\"Discrete distributions are only maintained for \"", "+", "\"discrete class types.\"", "ddist", ...
Returns the class value probability distribution of the given attribute value.
[ "Returns", "the", "class", "value", "probability", "distribution", "of", "the", "given", "attribute", "value", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1039-L1051
train
chrisspen/dtree
dtree.py
Node.get_value_prob
def get_value_prob(self, attr_name, value): """ Returns the value probability of the given attribute at this node. """ if attr_name not in self._attr_value_count_totals: return n = self._attr_value_counts[attr_name][value] d = self._attr_value_count_totals[att...
python
def get_value_prob(self, attr_name, value): """ Returns the value probability of the given attribute at this node. """ if attr_name not in self._attr_value_count_totals: return n = self._attr_value_counts[attr_name][value] d = self._attr_value_count_totals[att...
[ "def", "get_value_prob", "(", "self", ",", "attr_name", ",", "value", ")", ":", "if", "attr_name", "not", "in", "self", ".", "_attr_value_count_totals", ":", "return", "n", "=", "self", ".", "_attr_value_counts", "[", "attr_name", "]", "[", "value", "]", "...
Returns the value probability of the given attribute at this node.
[ "Returns", "the", "value", "probability", "of", "the", "given", "attribute", "at", "this", "node", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1053-L1061
train
chrisspen/dtree
dtree.py
Node.predict
def predict(self, record, depth=0): """ Returns the estimated value of the class attribute for the given record. """ # Check if we're ready to predict. if not self.ready_to_predict: raise NodeNotReadyToPredict # Lookup attribute value...
python
def predict(self, record, depth=0): """ Returns the estimated value of the class attribute for the given record. """ # Check if we're ready to predict. if not self.ready_to_predict: raise NodeNotReadyToPredict # Lookup attribute value...
[ "def", "predict", "(", "self", ",", "record", ",", "depth", "=", "0", ")", ":", "# Check if we're ready to predict.", "if", "not", "self", ".", "ready_to_predict", ":", "raise", "NodeNotReadyToPredict", "# Lookup attribute value.", "attr_value", "=", "self", ".", ...
Returns the estimated value of the class attribute for the given record.
[ "Returns", "the", "estimated", "value", "of", "the", "class", "attribute", "for", "the", "given", "record", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1070-L1105
train
chrisspen/dtree
dtree.py
Node.ready_to_split
def ready_to_split(self): """ Returns true if this node is ready to branch off additional nodes. Returns false otherwise. """ # Never split if we're a leaf that predicts adequately. threshold = self._tree.leaf_threshold if self._tree.data.is_continuous_class: ...
python
def ready_to_split(self): """ Returns true if this node is ready to branch off additional nodes. Returns false otherwise. """ # Never split if we're a leaf that predicts adequately. threshold = self._tree.leaf_threshold if self._tree.data.is_continuous_class: ...
[ "def", "ready_to_split", "(", "self", ")", ":", "# Never split if we're a leaf that predicts adequately.", "threshold", "=", "self", ".", "_tree", ".", "leaf_threshold", "if", "self", ".", "_tree", ".", "data", ".", "is_continuous_class", ":", "var", "=", "self", ...
Returns true if this node is ready to branch off additional nodes. Returns false otherwise.
[ "Returns", "true", "if", "this", "node", "is", "ready", "to", "branch", "off", "additional", "nodes", ".", "Returns", "false", "otherwise", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1112-L1132
train
chrisspen/dtree
dtree.py
Node.set_leaf_dist
def set_leaf_dist(self, attr_value, dist): """ Sets the probability distribution at a leaf node. """ assert self.attr_name assert self.tree.data.is_valid(self.attr_name, attr_value), \ "Value %s is invalid for attribute %s." \ % (attr_value, self.attr_...
python
def set_leaf_dist(self, attr_value, dist): """ Sets the probability distribution at a leaf node. """ assert self.attr_name assert self.tree.data.is_valid(self.attr_name, attr_value), \ "Value %s is invalid for attribute %s." \ % (attr_value, self.attr_...
[ "def", "set_leaf_dist", "(", "self", ",", "attr_value", ",", "dist", ")", ":", "assert", "self", ".", "attr_name", "assert", "self", ".", "tree", ".", "data", ".", "is_valid", "(", "self", ".", "attr_name", ",", "attr_value", ")", ",", "\"Value %s is inval...
Sets the probability distribution at a leaf node.
[ "Sets", "the", "probability", "distribution", "at", "a", "leaf", "node", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1134-L1156
train
chrisspen/dtree
dtree.py
Node.train
def train(self, record): """ Incrementally update the statistics at this node. """ self.n += 1 class_attr = self.tree.data.class_attribute_name class_value = record[class_attr] # Update class statistics. is_con = self.tree.data.is_continuous_class...
python
def train(self, record): """ Incrementally update the statistics at this node. """ self.n += 1 class_attr = self.tree.data.class_attribute_name class_value = record[class_attr] # Update class statistics. is_con = self.tree.data.is_continuous_class...
[ "def", "train", "(", "self", ",", "record", ")", ":", "self", ".", "n", "+=", "1", "class_attr", "=", "self", ".", "tree", ".", "data", ".", "class_attribute_name", "class_value", "=", "record", "[", "class_attr", "]", "# Update class statistics.", "is_con",...
Incrementally update the statistics at this node.
[ "Incrementally", "update", "the", "statistics", "at", "this", "node", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1184-L1224
train
chrisspen/dtree
dtree.py
Tree.build
def build(cls, data, *args, **kwargs): """ Constructs a classification or regression tree in a single batch by analyzing the given data. """ assert isinstance(data, Data) if data.is_continuous_class: fitness_func = gain_variance else: fitne...
python
def build(cls, data, *args, **kwargs): """ Constructs a classification or regression tree in a single batch by analyzing the given data. """ assert isinstance(data, Data) if data.is_continuous_class: fitness_func = gain_variance else: fitne...
[ "def", "build", "(", "cls", ",", "data", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "assert", "isinstance", "(", "data", ",", "Data", ")", "if", "data", ".", "is_continuous_class", ":", "fitness_func", "=", "gain_variance", "else", ":", "fitn...
Constructs a classification or regression tree in a single batch by analyzing the given data.
[ "Constructs", "a", "classification", "or", "regression", "tree", "in", "a", "single", "batch", "by", "analyzing", "the", "given", "data", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1293-L1314
train
chrisspen/dtree
dtree.py
Tree.out_of_bag_mae
def out_of_bag_mae(self): """ Returns the mean absolute error for predictions on the out-of-bag samples. """ if not self._out_of_bag_mae_clean: try: self._out_of_bag_mae = self.test(self.out_of_bag_samples) self._out_of_bag_mae_clean = ...
python
def out_of_bag_mae(self): """ Returns the mean absolute error for predictions on the out-of-bag samples. """ if not self._out_of_bag_mae_clean: try: self._out_of_bag_mae = self.test(self.out_of_bag_samples) self._out_of_bag_mae_clean = ...
[ "def", "out_of_bag_mae", "(", "self", ")", ":", "if", "not", "self", ".", "_out_of_bag_mae_clean", ":", "try", ":", "self", ".", "_out_of_bag_mae", "=", "self", ".", "test", "(", "self", ".", "out_of_bag_samples", ")", "self", ".", "_out_of_bag_mae_clean", "...
Returns the mean absolute error for predictions on the out-of-bag samples.
[ "Returns", "the", "mean", "absolute", "error", "for", "predictions", "on", "the", "out", "-", "of", "-", "bag", "samples", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1331-L1342
train
chrisspen/dtree
dtree.py
Tree.out_of_bag_samples
def out_of_bag_samples(self): """ Returns the out-of-bag samples list, inside a wrapper to keep track of modifications. """ #TODO:replace with more a generic pass-through wrapper? class O(object): def __init__(self, tree): self.tree = tree ...
python
def out_of_bag_samples(self): """ Returns the out-of-bag samples list, inside a wrapper to keep track of modifications. """ #TODO:replace with more a generic pass-through wrapper? class O(object): def __init__(self, tree): self.tree = tree ...
[ "def", "out_of_bag_samples", "(", "self", ")", ":", "#TODO:replace with more a generic pass-through wrapper?", "class", "O", "(", "object", ")", ":", "def", "__init__", "(", "self", ",", "tree", ")", ":", "self", ".", "tree", "=", "tree", "def", "__len__", "("...
Returns the out-of-bag samples list, inside a wrapper to keep track of modifications.
[ "Returns", "the", "out", "-", "of", "-", "bag", "samples", "list", "inside", "a", "wrapper", "to", "keep", "track", "of", "modifications", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1345-L1365
train
chrisspen/dtree
dtree.py
Tree.set_missing_value_policy
def set_missing_value_policy(self, policy, target_attr_name=None): """ Sets the behavior for one or all attributes to use when traversing the tree using a query vector and it encounters a branch that does not exist. """ assert policy in MISSING_VALUE_POLICIES, \ ...
python
def set_missing_value_policy(self, policy, target_attr_name=None): """ Sets the behavior for one or all attributes to use when traversing the tree using a query vector and it encounters a branch that does not exist. """ assert policy in MISSING_VALUE_POLICIES, \ ...
[ "def", "set_missing_value_policy", "(", "self", ",", "policy", ",", "target_attr_name", "=", "None", ")", ":", "assert", "policy", "in", "MISSING_VALUE_POLICIES", ",", "\"Unknown policy: %s\"", "%", "(", "policy", ",", ")", "for", "attr_name", "in", "self", ".",...
Sets the behavior for one or all attributes to use when traversing the tree using a query vector and it encounters a branch that does not exist.
[ "Sets", "the", "behavior", "for", "one", "or", "all", "attributes", "to", "use", "when", "traversing", "the", "tree", "using", "a", "query", "vector", "and", "it", "encounters", "a", "branch", "that", "does", "not", "exist", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1374-L1385
train
chrisspen/dtree
dtree.py
Tree.train
def train(self, record): """ Incrementally updates the tree with the given sample record. """ assert self.data.class_attribute_name in record, \ "The class attribute must be present in the record." record = record.copy() self.sample_count += 1 self.tre...
python
def train(self, record): """ Incrementally updates the tree with the given sample record. """ assert self.data.class_attribute_name in record, \ "The class attribute must be present in the record." record = record.copy() self.sample_count += 1 self.tre...
[ "def", "train", "(", "self", ",", "record", ")", ":", "assert", "self", ".", "data", ".", "class_attribute_name", "in", "record", ",", "\"The class attribute must be present in the record.\"", "record", "=", "record", ".", "copy", "(", ")", "self", ".", "sample_...
Incrementally updates the tree with the given sample record.
[ "Incrementally", "updates", "the", "tree", "with", "the", "given", "sample", "record", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1415-L1423
train
chrisspen/dtree
dtree.py
Forest._fell_trees
def _fell_trees(self): """ Removes trees from the forest according to the specified fell method. """ if callable(self.fell_method): for tree in self.fell_method(list(self.trees)): self.trees.remove(tree)
python
def _fell_trees(self): """ Removes trees from the forest according to the specified fell method. """ if callable(self.fell_method): for tree in self.fell_method(list(self.trees)): self.trees.remove(tree)
[ "def", "_fell_trees", "(", "self", ")", ":", "if", "callable", "(", "self", ".", "fell_method", ")", ":", "for", "tree", "in", "self", ".", "fell_method", "(", "list", "(", "self", ".", "trees", ")", ")", ":", "self", ".", "trees", ".", "remove", "...
Removes trees from the forest according to the specified fell method.
[ "Removes", "trees", "from", "the", "forest", "according", "to", "the", "specified", "fell", "method", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1470-L1476
train
chrisspen/dtree
dtree.py
Forest._get_best_prediction
def _get_best_prediction(self, record, train=True): """ Gets the prediction from the tree with the lowest mean absolute error. """ if not self.trees: return best = (+1e999999, None) for tree in self.trees: best = min(best, (tree.mae.mean, tree)) ...
python
def _get_best_prediction(self, record, train=True): """ Gets the prediction from the tree with the lowest mean absolute error. """ if not self.trees: return best = (+1e999999, None) for tree in self.trees: best = min(best, (tree.mae.mean, tree)) ...
[ "def", "_get_best_prediction", "(", "self", ",", "record", ",", "train", "=", "True", ")", ":", "if", "not", "self", ".", "trees", ":", "return", "best", "=", "(", "+", "1e999999", ",", "None", ")", "for", "tree", "in", "self", ".", "trees", ":", "...
Gets the prediction from the tree with the lowest mean absolute error.
[ "Gets", "the", "prediction", "from", "the", "tree", "with", "the", "lowest", "mean", "absolute", "error", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1478-L1489
train
chrisspen/dtree
dtree.py
Forest.best_oob_mae_weight
def best_oob_mae_weight(trees): """ Returns weights so that the tree with smallest out-of-bag mean absolute error """ best = (+1e999999, None) for tree in trees: oob_mae = tree.out_of_bag_mae if oob_mae is None or oob_mae.mean is None: cont...
python
def best_oob_mae_weight(trees): """ Returns weights so that the tree with smallest out-of-bag mean absolute error """ best = (+1e999999, None) for tree in trees: oob_mae = tree.out_of_bag_mae if oob_mae is None or oob_mae.mean is None: cont...
[ "def", "best_oob_mae_weight", "(", "trees", ")", ":", "best", "=", "(", "+", "1e999999", ",", "None", ")", "for", "tree", "in", "trees", ":", "oob_mae", "=", "tree", ".", "out_of_bag_mae", "if", "oob_mae", "is", "None", "or", "oob_mae", ".", "mean", "i...
Returns weights so that the tree with smallest out-of-bag mean absolute error
[ "Returns", "weights", "so", "that", "the", "tree", "with", "smallest", "out", "-", "of", "-", "bag", "mean", "absolute", "error" ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1492-L1505
train
chrisspen/dtree
dtree.py
Forest.mean_oob_mae_weight
def mean_oob_mae_weight(trees): """ Returns weights proportional to the out-of-bag mean absolute error for each tree. """ weights = [] active_trees = [] for tree in trees: oob_mae = tree.out_of_bag_mae if oob_mae is None or oob_mae.mean is None: ...
python
def mean_oob_mae_weight(trees): """ Returns weights proportional to the out-of-bag mean absolute error for each tree. """ weights = [] active_trees = [] for tree in trees: oob_mae = tree.out_of_bag_mae if oob_mae is None or oob_mae.mean is None: ...
[ "def", "mean_oob_mae_weight", "(", "trees", ")", ":", "weights", "=", "[", "]", "active_trees", "=", "[", "]", "for", "tree", "in", "trees", ":", "oob_mae", "=", "tree", ".", "out_of_bag_mae", "if", "oob_mae", "is", "None", "or", "oob_mae", ".", "mean", ...
Returns weights proportional to the out-of-bag mean absolute error for each tree.
[ "Returns", "weights", "proportional", "to", "the", "out", "-", "of", "-", "bag", "mean", "absolute", "error", "for", "each", "tree", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1508-L1523
train
chrisspen/dtree
dtree.py
Forest._grow_trees
def _grow_trees(self): """ Adds new trees to the forest according to the specified growth method. """ if self.grow_method == GROW_AUTO_INCREMENTAL: self.tree_kwargs['auto_grow'] = True while len(self.trees) < self.size: self.trees.append(Tree(data...
python
def _grow_trees(self): """ Adds new trees to the forest according to the specified growth method. """ if self.grow_method == GROW_AUTO_INCREMENTAL: self.tree_kwargs['auto_grow'] = True while len(self.trees) < self.size: self.trees.append(Tree(data...
[ "def", "_grow_trees", "(", "self", ")", ":", "if", "self", ".", "grow_method", "==", "GROW_AUTO_INCREMENTAL", ":", "self", ".", "tree_kwargs", "[", "'auto_grow'", "]", "=", "True", "while", "len", "(", "self", ".", "trees", ")", "<", "self", ".", "size",...
Adds new trees to the forest according to the specified growth method.
[ "Adds", "new", "trees", "to", "the", "forest", "according", "to", "the", "specified", "growth", "method", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1525-L1533
train
chrisspen/dtree
dtree.py
Forest.predict
def predict(self, record): """ Attempts to predict the value of the class attribute by aggregating the predictions of each tree. Parameters: weighting_formula := a callable that takes a list of trees and returns a list of weights. """ ...
python
def predict(self, record): """ Attempts to predict the value of the class attribute by aggregating the predictions of each tree. Parameters: weighting_formula := a callable that takes a list of trees and returns a list of weights. """ ...
[ "def", "predict", "(", "self", ",", "record", ")", ":", "# Get raw predictions.", "# {tree:raw prediction}", "predictions", "=", "{", "}", "for", "tree", "in", "self", ".", "trees", ":", "_p", "=", "tree", ".", "predict", "(", "record", ")", "if", "_p", ...
Attempts to predict the value of the class attribute by aggregating the predictions of each tree. Parameters: weighting_formula := a callable that takes a list of trees and returns a list of weights.
[ "Attempts", "to", "predict", "the", "value", "of", "the", "class", "attribute", "by", "aggregating", "the", "predictions", "of", "each", "tree", ".", "Parameters", ":", "weighting_formula", ":", "=", "a", "callable", "that", "takes", "a", "list", "of", "tree...
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1539-L1582
train
chrisspen/dtree
dtree.py
Forest.train
def train(self, record): """ Updates the trees with the given training record. """ self._fell_trees() self._grow_trees() for tree in self.trees: if random.random() < self.sample_ratio: tree.train(record) else: tree.o...
python
def train(self, record): """ Updates the trees with the given training record. """ self._fell_trees() self._grow_trees() for tree in self.trees: if random.random() < self.sample_ratio: tree.train(record) else: tree.o...
[ "def", "train", "(", "self", ",", "record", ")", ":", "self", ".", "_fell_trees", "(", ")", "self", ".", "_grow_trees", "(", ")", "for", "tree", "in", "self", ".", "trees", ":", "if", "random", ".", "random", "(", ")", "<", "self", ".", "sample_rat...
Updates the trees with the given training record.
[ "Updates", "the", "trees", "with", "the", "given", "training", "record", "." ]
9e9c9992b22ad9a7e296af7e6837666b05db43ef
https://github.com/chrisspen/dtree/blob/9e9c9992b22ad9a7e296af7e6837666b05db43ef/dtree.py#L1613-L1625
train
dwavesystems/dwave-cloud-client
dwave/cloud/config.py
get_configfile_paths
def get_configfile_paths(system=True, user=True, local=True, only_existing=True): """Return a list of local configuration file paths. Search paths for configuration files on the local system are based on homebase_ and depend on operating system; for example, for Linux systems these might include ``dwav...
python
def get_configfile_paths(system=True, user=True, local=True, only_existing=True): """Return a list of local configuration file paths. Search paths for configuration files on the local system are based on homebase_ and depend on operating system; for example, for Linux systems these might include ``dwav...
[ "def", "get_configfile_paths", "(", "system", "=", "True", ",", "user", "=", "True", ",", "local", "=", "True", ",", "only_existing", "=", "True", ")", ":", "candidates", "=", "[", "]", "# system-wide has the lowest priority, `/etc/dwave/dwave.conf`", "if", "syste...
Return a list of local configuration file paths. Search paths for configuration files on the local system are based on homebase_ and depend on operating system; for example, for Linux systems these might include ``dwave.conf`` in the current working directory (CWD), user-local ``.config/dwave/``, and s...
[ "Return", "a", "list", "of", "local", "configuration", "file", "paths", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/config.py#L239-L304
train
dwavesystems/dwave-cloud-client
dwave/cloud/config.py
get_default_configfile_path
def get_default_configfile_path(): """Return the default configuration-file path. Typically returns a user-local configuration file; e.g: ``~/.config/dwave/dwave.conf``. Returns: str: Configuration file path. Examples: This example displays the default configuration fi...
python
def get_default_configfile_path(): """Return the default configuration-file path. Typically returns a user-local configuration file; e.g: ``~/.config/dwave/dwave.conf``. Returns: str: Configuration file path. Examples: This example displays the default configuration fi...
[ "def", "get_default_configfile_path", "(", ")", ":", "base", "=", "homebase", ".", "user_config_dir", "(", "app_author", "=", "CONF_AUTHOR", ",", "app_name", "=", "CONF_APP", ",", "roaming", "=", "False", ",", "use_virtualenv", "=", "False", ",", "create", "="...
Return the default configuration-file path. Typically returns a user-local configuration file; e.g: ``~/.config/dwave/dwave.conf``. Returns: str: Configuration file path. Examples: This example displays the default configuration file on an Ubuntu Unix system runnin...
[ "Return", "the", "default", "configuration", "-", "file", "path", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/config.py#L336-L367
train
dwavesystems/dwave-cloud-client
dwave/cloud/config.py
load_config_from_files
def load_config_from_files(filenames=None): """Load D-Wave Cloud Client configuration from a list of files. .. note:: This method is not standardly used to set up D-Wave Cloud Client configuration. It is recommended you use :meth:`.Client.from_config` or :meth:`.config.load_config` instead. ...
python
def load_config_from_files(filenames=None): """Load D-Wave Cloud Client configuration from a list of files. .. note:: This method is not standardly used to set up D-Wave Cloud Client configuration. It is recommended you use :meth:`.Client.from_config` or :meth:`.config.load_config` instead. ...
[ "def", "load_config_from_files", "(", "filenames", "=", "None", ")", ":", "if", "filenames", "is", "None", ":", "filenames", "=", "get_configfile_paths", "(", ")", "config", "=", "configparser", ".", "ConfigParser", "(", "default_section", "=", "\"defaults\"", "...
Load D-Wave Cloud Client configuration from a list of files. .. note:: This method is not standardly used to set up D-Wave Cloud Client configuration. It is recommended you use :meth:`.Client.from_config` or :meth:`.config.load_config` instead. Configuration files comply with standard Windows ...
[ "Load", "D", "-", "Wave", "Cloud", "Client", "configuration", "from", "a", "list", "of", "files", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/config.py#L370-L468
train
dwavesystems/dwave-cloud-client
dwave/cloud/config.py
load_profile_from_files
def load_profile_from_files(filenames=None, profile=None): """Load a profile from a list of D-Wave Cloud Client configuration files. .. note:: This method is not standardly used to set up D-Wave Cloud Client configuration. It is recommended you use :meth:`.Client.from_config` or :meth:`.config....
python
def load_profile_from_files(filenames=None, profile=None): """Load a profile from a list of D-Wave Cloud Client configuration files. .. note:: This method is not standardly used to set up D-Wave Cloud Client configuration. It is recommended you use :meth:`.Client.from_config` or :meth:`.config....
[ "def", "load_profile_from_files", "(", "filenames", "=", "None", ",", "profile", "=", "None", ")", ":", "# progressively build config from a file, or a list of auto-detected files", "# raises ConfigFileReadError/ConfigFileParseError on error", "config", "=", "load_config_from_files",...
Load a profile from a list of D-Wave Cloud Client configuration files. .. note:: This method is not standardly used to set up D-Wave Cloud Client configuration. It is recommended you use :meth:`.Client.from_config` or :meth:`.config.load_config` instead. Configuration files comply with standar...
[ "Load", "a", "profile", "from", "a", "list", "of", "D", "-", "Wave", "Cloud", "Client", "configuration", "files", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/config.py#L471-L584
train
dwavesystems/dwave-cloud-client
dwave/cloud/config.py
load_config
def load_config(config_file=None, profile=None, client=None, endpoint=None, token=None, solver=None, proxy=None): """Load D-Wave Cloud Client configuration based on a configuration file. Configuration values can be specified in multiple ways, ranked in the following order (with 1 the highes...
python
def load_config(config_file=None, profile=None, client=None, endpoint=None, token=None, solver=None, proxy=None): """Load D-Wave Cloud Client configuration based on a configuration file. Configuration values can be specified in multiple ways, ranked in the following order (with 1 the highes...
[ "def", "load_config", "(", "config_file", "=", "None", ",", "profile", "=", "None", ",", "client", "=", "None", ",", "endpoint", "=", "None", ",", "token", "=", "None", ",", "solver", "=", "None", ",", "proxy", "=", "None", ")", ":", "if", "profile",...
Load D-Wave Cloud Client configuration based on a configuration file. Configuration values can be specified in multiple ways, ranked in the following order (with 1 the highest ranked): 1. Values specified as keyword arguments in :func:`load_config()`. These values replace values read from a configu...
[ "Load", "D", "-", "Wave", "Cloud", "Client", "configuration", "based", "on", "a", "configuration", "file", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/config.py#L619-L778
train
dwavesystems/dwave-cloud-client
dwave/cloud/config.py
legacy_load_config
def legacy_load_config(profile=None, endpoint=None, token=None, solver=None, proxy=None, **kwargs): """Load configured URLs and token for the SAPI server. .. warning:: Included only for backward compatibility. Please use :func:`load_config` or the client factory :meth:`~d...
python
def legacy_load_config(profile=None, endpoint=None, token=None, solver=None, proxy=None, **kwargs): """Load configured URLs and token for the SAPI server. .. warning:: Included only for backward compatibility. Please use :func:`load_config` or the client factory :meth:`~d...
[ "def", "legacy_load_config", "(", "profile", "=", "None", ",", "endpoint", "=", "None", ",", "token", "=", "None", ",", "solver", "=", "None", ",", "proxy", "=", "None", ",", "*", "*", "kwargs", ")", ":", "def", "_parse_config", "(", "fp", ",", "file...
Load configured URLs and token for the SAPI server. .. warning:: Included only for backward compatibility. Please use :func:`load_config` or the client factory :meth:`~dwave.cloud.client.Client.from_config` instead. This method tries to load a legacy configuration file from ``~/.dwrc``, select...
[ "Load", "configured", "URLs", "and", "token", "for", "the", "SAPI", "server", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/config.py#L781-L925
train
tuxu/python-samplerate
samplerate/lowlevel.py
_check_data
def _check_data(data): """Check whether `data` is a valid input/output for libsamplerate. Returns ------- num_frames Number of frames in `data`. channels Number of channels in `data`. Raises ------ ValueError: If invalid data is supplied. """ if not (data.dt...
python
def _check_data(data): """Check whether `data` is a valid input/output for libsamplerate. Returns ------- num_frames Number of frames in `data`. channels Number of channels in `data`. Raises ------ ValueError: If invalid data is supplied. """ if not (data.dt...
[ "def", "_check_data", "(", "data", ")", ":", "if", "not", "(", "data", ".", "dtype", "==", "_np", ".", "float32", "and", "data", ".", "flags", ".", "c_contiguous", ")", ":", "raise", "ValueError", "(", "'supplied data must be float32 and C contiguous'", ")", ...
Check whether `data` is a valid input/output for libsamplerate. Returns ------- num_frames Number of frames in `data`. channels Number of channels in `data`. Raises ------ ValueError: If invalid data is supplied.
[ "Check", "whether", "data", "is", "a", "valid", "input", "/", "output", "for", "libsamplerate", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/samplerate/lowlevel.py#L41-L63
train
tuxu/python-samplerate
samplerate/lowlevel.py
src_simple
def src_simple(input_data, output_data, ratio, converter_type, channels): """Perform a single conversion from an input buffer to an output buffer. Simple interface for performing a single conversion from input buffer to output buffer at a fixed conversion ratio. Simple interface does not require initia...
python
def src_simple(input_data, output_data, ratio, converter_type, channels): """Perform a single conversion from an input buffer to an output buffer. Simple interface for performing a single conversion from input buffer to output buffer at a fixed conversion ratio. Simple interface does not require initia...
[ "def", "src_simple", "(", "input_data", ",", "output_data", ",", "ratio", ",", "converter_type", ",", "channels", ")", ":", "input_frames", ",", "_", "=", "_check_data", "(", "input_data", ")", "output_frames", ",", "_", "=", "_check_data", "(", "output_data",...
Perform a single conversion from an input buffer to an output buffer. Simple interface for performing a single conversion from input buffer to output buffer at a fixed conversion ratio. Simple interface does not require initialisation as it can only operate on a single buffer worth of audio.
[ "Perform", "a", "single", "conversion", "from", "an", "input", "buffer", "to", "an", "output", "buffer", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/samplerate/lowlevel.py#L86-L102
train
tuxu/python-samplerate
samplerate/lowlevel.py
src_new
def src_new(converter_type, channels): """Initialise a new sample rate converter. Parameters ---------- converter_type : int Converter to be used. channels : int Number of channels. Returns ------- state An anonymous pointer to the internal state of the converte...
python
def src_new(converter_type, channels): """Initialise a new sample rate converter. Parameters ---------- converter_type : int Converter to be used. channels : int Number of channels. Returns ------- state An anonymous pointer to the internal state of the converte...
[ "def", "src_new", "(", "converter_type", ",", "channels", ")", ":", "error", "=", "ffi", ".", "new", "(", "'int*'", ")", "state", "=", "_lib", ".", "src_new", "(", "converter_type", ",", "channels", ",", "error", ")", "return", "state", ",", "error", "...
Initialise a new sample rate converter. Parameters ---------- converter_type : int Converter to be used. channels : int Number of channels. Returns ------- state An anonymous pointer to the internal state of the converter. error : int Error code.
[ "Initialise", "a", "new", "sample", "rate", "converter", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/samplerate/lowlevel.py#L105-L124
train
tuxu/python-samplerate
samplerate/lowlevel.py
src_process
def src_process(state, input_data, output_data, ratio, end_of_input=0): """Standard processing function. Returns non zero on error. """ input_frames, _ = _check_data(input_data) output_frames, _ = _check_data(output_data) data = ffi.new('SRC_DATA*') data.input_frames = input_frames data...
python
def src_process(state, input_data, output_data, ratio, end_of_input=0): """Standard processing function. Returns non zero on error. """ input_frames, _ = _check_data(input_data) output_frames, _ = _check_data(output_data) data = ffi.new('SRC_DATA*') data.input_frames = input_frames data...
[ "def", "src_process", "(", "state", ",", "input_data", ",", "output_data", ",", "ratio", ",", "end_of_input", "=", "0", ")", ":", "input_frames", ",", "_", "=", "_check_data", "(", "input_data", ")", "output_frames", ",", "_", "=", "_check_data", "(", "out...
Standard processing function. Returns non zero on error.
[ "Standard", "processing", "function", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/samplerate/lowlevel.py#L135-L150
train
tuxu/python-samplerate
samplerate/lowlevel.py
_src_input_callback
def _src_input_callback(cb_data, data): """Internal callback function to be used with the callback API. Pulls the Python callback function from the handle contained in `cb_data` and calls it to fetch frames. Frames are converted to the format required by the API (float, interleaved channels). A referen...
python
def _src_input_callback(cb_data, data): """Internal callback function to be used with the callback API. Pulls the Python callback function from the handle contained in `cb_data` and calls it to fetch frames. Frames are converted to the format required by the API (float, interleaved channels). A referen...
[ "def", "_src_input_callback", "(", "cb_data", ",", "data", ")", ":", "cb_data", "=", "ffi", ".", "from_handle", "(", "cb_data", ")", "ret", "=", "cb_data", "[", "'callback'", "]", "(", ")", "if", "ret", "is", "None", ":", "cb_data", "[", "'last_input'", ...
Internal callback function to be used with the callback API. Pulls the Python callback function from the handle contained in `cb_data` and calls it to fetch frames. Frames are converted to the format required by the API (float, interleaved channels). A reference to these data is kept internally. R...
[ "Internal", "callback", "function", "to", "be", "used", "with", "the", "callback", "API", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/samplerate/lowlevel.py#L184-L214
train
tuxu/python-samplerate
samplerate/lowlevel.py
src_callback_new
def src_callback_new(callback, converter_type, channels): """Initialisation for the callback based API. Parameters ---------- callback : function Called whenever new frames are to be read. Must return a NumPy array of shape (num_frames, channels). converter_type : int Conver...
python
def src_callback_new(callback, converter_type, channels): """Initialisation for the callback based API. Parameters ---------- callback : function Called whenever new frames are to be read. Must return a NumPy array of shape (num_frames, channels). converter_type : int Conver...
[ "def", "src_callback_new", "(", "callback", ",", "converter_type", ",", "channels", ")", ":", "cb_data", "=", "{", "'callback'", ":", "callback", ",", "'channels'", ":", "channels", "}", "handle", "=", "ffi", ".", "new_handle", "(", "cb_data", ")", "error", ...
Initialisation for the callback based API. Parameters ---------- callback : function Called whenever new frames are to be read. Must return a NumPy array of shape (num_frames, channels). converter_type : int Converter to be used. channels : int Number of channels. ...
[ "Initialisation", "for", "the", "callback", "based", "API", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/samplerate/lowlevel.py#L217-L247
train
tuxu/python-samplerate
samplerate/lowlevel.py
src_callback_read
def src_callback_read(state, ratio, frames, data): """Read up to `frames` worth of data using the callback API. Returns ------- frames : int Number of frames read or -1 on error. """ data_ptr = ffi.cast('float*f', ffi.from_buffer(data)) return _lib.src_callback_read(state, ratio, fr...
python
def src_callback_read(state, ratio, frames, data): """Read up to `frames` worth of data using the callback API. Returns ------- frames : int Number of frames read or -1 on error. """ data_ptr = ffi.cast('float*f', ffi.from_buffer(data)) return _lib.src_callback_read(state, ratio, fr...
[ "def", "src_callback_read", "(", "state", ",", "ratio", ",", "frames", ",", "data", ")", ":", "data_ptr", "=", "ffi", ".", "cast", "(", "'float*f'", ",", "ffi", ".", "from_buffer", "(", "data", ")", ")", "return", "_lib", ".", "src_callback_read", "(", ...
Read up to `frames` worth of data using the callback API. Returns ------- frames : int Number of frames read or -1 on error.
[ "Read", "up", "to", "frames", "worth", "of", "data", "using", "the", "callback", "API", "." ]
ed73d7a39e61bfb34b03dade14ffab59aa27922a
https://github.com/tuxu/python-samplerate/blob/ed73d7a39e61bfb34b03dade14ffab59aa27922a/samplerate/lowlevel.py#L250-L259
train
dwavesystems/dwave-cloud-client
dwave/cloud/client.py
Client.from_config
def from_config(cls, config_file=None, profile=None, client=None, endpoint=None, token=None, solver=None, proxy=None, legacy_config_fallback=False, **kwargs): """Client factory method to instantiate a client instance from configuration. Configuration values can b...
python
def from_config(cls, config_file=None, profile=None, client=None, endpoint=None, token=None, solver=None, proxy=None, legacy_config_fallback=False, **kwargs): """Client factory method to instantiate a client instance from configuration. Configuration values can b...
[ "def", "from_config", "(", "cls", ",", "config_file", "=", "None", ",", "profile", "=", "None", ",", "client", "=", "None", ",", "endpoint", "=", "None", ",", "token", "=", "None", ",", "solver", "=", "None", ",", "proxy", "=", "None", ",", "legacy_c...
Client factory method to instantiate a client instance from configuration. Configuration values can be specified in multiple ways, ranked in the following order (with 1 the highest ranked): 1. Values specified as keyword arguments in :func:`from_config()` 2. Values specified as environ...
[ "Client", "factory", "method", "to", "instantiate", "a", "client", "instance", "from", "configuration", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/client.py#L168-L318
train
dwavesystems/dwave-cloud-client
dwave/cloud/client.py
Client.close
def close(self): """Perform a clean shutdown. Waits for all the currently scheduled work to finish, kills the workers, and closes the connection pool. .. note:: Ensure your code does not submit new work while the connection is closing. Where possible, it is recommended you use...
python
def close(self): """Perform a clean shutdown. Waits for all the currently scheduled work to finish, kills the workers, and closes the connection pool. .. note:: Ensure your code does not submit new work while the connection is closing. Where possible, it is recommended you use...
[ "def", "close", "(", "self", ")", ":", "# Finish all the work that requires the connection", "_LOGGER", ".", "debug", "(", "\"Joining submission queue\"", ")", "self", ".", "_submission_queue", ".", "join", "(", ")", "_LOGGER", ".", "debug", "(", "\"Joining cancel que...
Perform a clean shutdown. Waits for all the currently scheduled work to finish, kills the workers, and closes the connection pool. .. note:: Ensure your code does not submit new work while the connection is closing. Where possible, it is recommended you use a context manager (a :code:...
[ "Perform", "a", "clean", "shutdown", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/client.py#L427-L476
train
dwavesystems/dwave-cloud-client
dwave/cloud/client.py
Client.get_solvers
def get_solvers(self, refresh=False, order_by='avg_load', **filters): """Return a filtered list of solvers handled by this client. Args: refresh (bool, default=False): Force refresh of cached list of solvers/properties. order_by (callable/str/None, default='avg_...
python
def get_solvers(self, refresh=False, order_by='avg_load', **filters): """Return a filtered list of solvers handled by this client. Args: refresh (bool, default=False): Force refresh of cached list of solvers/properties. order_by (callable/str/None, default='avg_...
[ "def", "get_solvers", "(", "self", ",", "refresh", "=", "False", ",", "order_by", "=", "'avg_load'", ",", "*", "*", "filters", ")", ":", "def", "covers_op", "(", "prop", ",", "val", ")", ":", "\"\"\"Does LHS `prop` (range) fully cover RHS `val` (range or item)?\"\...
Return a filtered list of solvers handled by this client. Args: refresh (bool, default=False): Force refresh of cached list of solvers/properties. order_by (callable/str/None, default='avg_load'): Solver sorting key function (or :class:`Solver` attribute...
[ "Return", "a", "filtered", "list", "of", "solvers", "handled", "by", "this", "client", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/client.py#L553-L885
train
dwavesystems/dwave-cloud-client
dwave/cloud/client.py
Client.solvers
def solvers(self, refresh=False, **filters): """Deprecated in favor of :meth:`.get_solvers`.""" warnings.warn("'solvers' is deprecated in favor of 'get_solvers'.", DeprecationWarning) return self.get_solvers(refresh=refresh, **filters)
python
def solvers(self, refresh=False, **filters): """Deprecated in favor of :meth:`.get_solvers`.""" warnings.warn("'solvers' is deprecated in favor of 'get_solvers'.", DeprecationWarning) return self.get_solvers(refresh=refresh, **filters)
[ "def", "solvers", "(", "self", ",", "refresh", "=", "False", ",", "*", "*", "filters", ")", ":", "warnings", ".", "warn", "(", "\"'solvers' is deprecated in favor of 'get_solvers'.\"", ",", "DeprecationWarning", ")", "return", "self", ".", "get_solvers", "(", "r...
Deprecated in favor of :meth:`.get_solvers`.
[ "Deprecated", "in", "favor", "of", ":", "meth", ":", ".", "get_solvers", "." ]
df3221a8385dc0c04d7b4d84f740bf3ad6706230
https://github.com/dwavesystems/dwave-cloud-client/blob/df3221a8385dc0c04d7b4d84f740bf3ad6706230/dwave/cloud/client.py#L887-L890
train