Belief Engine (indra.belief)

class indra.belief.BeliefEngine(scorer=None)[source]

Assigns beliefs to INDRA Statements based on supporting evidence.

scorer

BeliefScorer – A BeliefScorer object that computes the prior probability of a statement given its its statment type and evidence. Must implement the score_statement method which takes Statements and computes the belief score of a statement, and the check_prior_probs method which takes a list of INDRA Statements and verifies that the scorer has all the information it needs to score every statement in the list, and raises an exception if not.

set_hierarchy_probs(statements)[source]

Sets hierarchical belief probabilities for INDRA Statements.

The Statements are assumed to be in a hierarchical relation graph with the supports and supported_by attribute of each Statement object having been set. The hierarchical belief probability of each Statement is calculated based on its prior probability and the probabilities propagated from Statements supporting it in the hierarchy graph.

Parameters:statements (list[indra.statements.Statement]) – A list of INDRA Statements whose belief scores are to be calculated. Each Statement object’s belief attribute is updated by this function.
set_linked_probs(linked_statements)[source]

Sets the belief probabilities for a list of linked INDRA Statements.

The list of LinkedStatement objects is assumed to come from the MechanismLinker. The belief probability of the inferred Statement is assigned the joint probability of its source Statements.

Parameters:linked_statements (list[indra.mechlinker.LinkedStatement]) – A list of INDRA LinkedStatements whose belief scores are to be calculated. The belief attribute of the inferred Statement in the LinkedStatement object is updated by this function.
set_prior_probs(statements)[source]

Sets the prior belief probabilities for a list of INDRA Statements.

The Statements are assumed to be de-duplicated. In other words, each Statement in the list passed to this function is assumed to have a list of Evidence objects that support it. The prior probability of each Statement is calculated based on the number of Evidences it has and their sources.

Parameters:statements (list[indra.statements.Statement]) – A list of INDRA Statements whose belief scores are to be calculated. Each Statement object’s belief attribute is updated by this function.
class indra.belief.BeliefPackage(statement_key, evidences)
evidences

Alias for field number 1

statement_key

Alias for field number 0

class indra.belief.BeliefScorer[source]

Base class for a belief engine scorer, which computes the prior probability of a statement given its type and evidence.

To use with the belief engine, make a subclass with methods implemented.

check_prior_probs(statements)[source]

Make sure the scorer has all the information needed to compute belief scores of each statement in the provided list, and raises an exception otherwise.

Parameters:statements (list<indra.statements.Statement>) – List of statements to check
score_statement(st, extra_evidence=None)[source]

Computes the prior belief probability for an INDRA Statement.

The Statement is assumed to be de-duplicated. In other words, the Statement is assumed to have a list of Evidence objects that supports it. The prior probability of the Statement is calculated based on the number of Evidences it has and their sources.

Parameters:
  • st (indra.statements.Statement) – An INDRA Statements whose belief scores are to be calculated.
  • extra_evidence (list[indra.statements.Evidence]) – A list of Evidences that are supporting the Statement (that aren’t already included in the Statement’s own evidence list.
Returns:

belief_score – The computed prior probability for the statement

Return type:

float

class indra.belief.SimpleScorer(prior_probs=None, subtype_probs=None)[source]

Computes the prior probability of a statement given its type and evidence.

Parameters:
  • prior_probs (dict[dict]) – A dictionary of prior probabilities used to override/extend the default ones. There are two types of prior probabilities: rand and syst corresponding to random error and systematic error rate for each knowledge source. The prior_probs dictionary has the general structure {‘rand’: {‘s1’: pr1, …, ‘sn’: prn}, ‘syst’: {‘s1’: ps1, …, ‘sn’: psn}} where ‘s1’ … ‘sn’ are names of input sources and pr1 … prn and ps1 … psn are error probabilities. Examples: {‘rand’: {‘some_source’: 0.1}} sets the random error rate for some_source to 0.1; {‘rand’: {‘’}}
  • subtype_probs (dict[dict]) – A dictionary of random error probabilities for knowledge sources. When a subtype random error probability is not specified, will just use the overall type prior in prior_probs. If None, will only use the priors for each rule.
check_prior_probs(statements)[source]

Throw Exception if BeliefEngine parameter is missing.

Make sure the scorer has all the information needed to compute belief scores of each statement in the provided list, and raises an exception otherwise.

Parameters:statements (list[indra.statements.Statement]) – List of statements to check
score_statement(st, extra_evidence=None)[source]

Computes the prior belief probability for an INDRA Statement.

The Statement is assumed to be de-duplicated. In other words, the Statement is assumed to have a list of Evidence objects that supports it. The prior probability of the Statement is calculated based on the number of Evidences it has and their sources.

Parameters:
  • st (indra.statements.Statement) – An INDRA Statements whose belief scores are to be calculated.
  • extra_evidence (list[indra.statements.Evidence]) – A list of Evidences that are supporting the Statement (that aren’t already included in the Statement’s own evidence list.
Returns:

belief_score – The computed prior probability for the statement

Return type:

float

indra.belief.evidence_random_noise_prior(evidence, type_probs, subtype_probs)[source]

Determines the random-noise prior probability for this evidence.

If the evidence corresponds to a subtype, and that subtype has a curated prior noise probability, use that.

Otherwise, gives the random-noise prior for the overall rule type.

indra.belief.sample_statements(stmts, seed=None)[source]

Return statements sampled according to belief.

Statements are sampled independently according to their belief scores. For instance, a Staement with a belief score of 0.7 will end up in the returned Statement list with probability 0.7.

Parameters:
  • stmts (list[indra.statements.Statement]) – A list of INDRA Statements to sample.
  • seed (Optional[int]) – A seed for the random number generator used for sampling.
Returns:

new_stmts – A list of INDRA Statements that were chosen by random sampling according to their respective belief scores.

Return type:

list[indra.statements.Statement]

indra.belief.tag_evidence_subtype(evidence)[source]

Returns the type and subtype of an evidence object as a string, typically the extraction rule or database from which the statement was generated.

For biopax, this is just the database name.

Parameters:statement (indra.statements.Evidence) – The statement which we wish to subtype
Returns:types – A tuple with (type, subtype), both strings Returns (type, None) if the type of statement is not yet handled in this function.
Return type:tuple