neurolang.frontend.probabilistic_frontend module¶
Probabilistic Frontend¶
Complements QueryBuilderDatalog class with probabilistic capabilities 1- add extensional probabilistic facts and choices 2- sove probabilistic queries
- class neurolang.frontend.probabilistic_frontend.NeurolangPDL(chase_class: ~typing.Type[~neurolang.datalog.chase.Chase] = <class 'neurolang.datalog.chase.Chase'>, probabilistic_solvers: ~typing.Tuple[~typing.Callable] = (<function solve_succ_query>, <function solve_succ_query>, <function solve_succ_query_sdd_direct>), probabilistic_marg_solvers: ~typing.Tuple[~typing.Callable] = (<function solve_marg_query>, <function solve_marg_query>, <function solve_marg_query>), check_qbased_pfact_tuple_unicity=False)¶
Bases:
QueryBuilderDatalog
Complements QueryBuilderDatalog class with probabilistic capabilities 1- add extensional probabilistic facts and choices 2- sove probabilistic queries
- Attributes:
current_program
Returns the list of Front End Expressions that have
environment
Dynamic context that can be used to create symbols to write a Datalog program.
functions
Returns the list of symbols corresponding to callables
region_names
Returns the list of symbol names with Region type
region_set_names
Returns the list of symbol names with set_type
scope
Dynamic context that can be used to create symbols to write a Datalog program.
symbol_table
Projector to the program_ir’s symbol_table
symbols
Iterator through the symbol’s names
types
Returns a list of the types of the symbols currently
Methods
add_atlas_set
(name, atlas_labels, spatial_image)Creates an atlas set: 1- for each region specified by a label and name in atlas_labels, creates associated ExplicitVBR and symbols Tuple[region_name: str, Region] 2- groups regions in an AbstractSet[Tuple[str, Region]] symbol with specified name
add_constraint
(antecedent, consequent)Creates an right implication of the consequent by the antecedent and adds the rule to the current program: antecedent -> consequent
add_probabilistic_choice_from_tuples
(iterable)Add probabilistic choice from tuples whose first element contains the probability label attached to that tuple.
add_probabilistic_facts_from_tuples
(iterable)Add probabilistic facts from tuples whose first element contains the probability label attached to that tuple.
add_region
(region[, name])Adds region fe.Symbol to symbol_table
add_region_set
(region_set[, name])Creates an AbstractSet fe.Symbol containing the elements specified in the iterable with a List[Tuple[Region]] format
add_symbol
(value[, name, type_])Creates a symbol with given value and adds it to the current symbol_table.
add_tuple_set
(iterable[, type_, name])Creates an AbstractSet fe.Symbol containing the elements specified in the iterable with a List[Tuple[Any, ...]] format (see examples).
Add uniform probabilistic choice over values in the iterable.
all
(quantified_variable, body)Universal predicate on the body.
create_region
(spatial_image[, label, ...])Creates an ExplicitVBR out of the voxels of a dense spatial_image with specified label
del_symbol
(name)Deletes the symbol with parameter name from the symbol_table
execute_datalog_program
(code)Execute a Datalog program in classical syntax.
exists
(quantified_variable, body)Existential predicate on the body.
get_symbol
(symbol_name)Retrieves symbol via its name, either providing a fe.Expression with the correct name or the name itself
load_neurosynth_mni_peaks_reported
(data_dir)Load the coordinates for the peaks reported by studies in the Neurosynth dataset.
load_neurosynth_study_ids
(data_dir[, name, ...])Load all study ids (PMIDs) that are part of the Neurosynth database.
load_neurosynth_term_study_associations
(data_dir)Load TF-IDF values for each (term, study) association within the Neurosynth database.
load_ontology
(paths[, connector_symbol_name])Loads and parses ontology stored at the specified paths, and store them into attributes
make_implicit_regions_explicit
(affine, dim)Raises NotImplementedError for now
new_region_symbol
([name])Returns symbol with type Region
new_symbol
([type_, name])Creates a symbol and associated expression, optionally specifying it's type and/or name
predicate_parameter_names
(predicate_name)Get the names of the parameters for the given predicate
query
(*args)Performs an inferential query on the database.
reset_program
()Clears current symbol table
Returns a dictionary of "predicate_name": "Content" for all elements in the solution of the Datalog program.
sphere
(center, radius[, name])Creates a Region symbol associated with the spherical volume described by its center and volume
magic_sets_rewrite_program
- add_probabilistic_choice_from_tuples(iterable: ~typing.Iterable[~typing.Tuple[~typing.Any, ...]], type_: ~typing.Type = <class 'neurolang.type_system.Unknown'>, name: str | None = None) Symbol ¶
Add probabilistic choice from tuples whose first element contains the probability label attached to that tuple. In the tuple (p, a, b, …), p is the float probability of tuple (a, b, …) to be True and all remaining tuples to be False in any possible world.
Note that, contrary to a list of probabilistic facts, this represents a choice among possible values for the predicate, meaning that tuples in the set are mutually exclusive. See example for details.
- Parameters:
- iterableIterable[Tuple[Any, …]]
the first float number represents the probability of the tuple constituted of the remaining elements Note that the float probabilities must sum to 1.
- type_Type, optional
type for resulting AbstractSet if None will be inferred from the data, by default ir.Unknown
- nameOptional[str], optional
name for the resulting fe.Symbol, if None will be fresh, by default None
- Returns:
- fe.Symbol
see description
- Raises:
- DistributionDoesNotSumToOneError
if float probabilities do not sum to 1.
- add_probabilistic_facts_from_tuples(iterable: ~typing.Iterable[~typing.Tuple[~typing.Any, ...]], type_: ~typing.Type = <class 'neurolang.type_system.Unknown'>, name: str | None = None) Symbol ¶
Add probabilistic facts from tuples whose first element contains the probability label attached to that tuple. In the tuple (p, a, b, …), p is the float probability of tuple (a, b, …) to be True in any possible world.
Note that each tuple from the iterable is independant from the others, meaning that multiple tuples can be True in the same possible world, contrary to a probabilistic choice. See example for details.
- Parameters:
- iterableIterable[Tuple[Any, …]]
the first float number represents the probability of the tuple constituted of the remaining elements
- type_Type, optional
type for resulting AbstractSet if None will be inferred from the data, by default ir.Unknown
- nameOptional[str], optional
name for the resulting fe.Symbol, if None will be fresh, by default None
- Returns:
- fe.Symbol
see description
- add_uniform_probabilistic_choice_over_set(iterable: ~typing.Iterable[~typing.Tuple[~typing.Any, ...]], type_: ~typing.Type = <class 'neurolang.type_system.Unknown'>, name: str | None = None) Symbol ¶
Add uniform probabilistic choice over values in the iterable.
Every tuple in the iterable will be assigned the same probability to be True, with all remaning tuples False, in any possible world.
Note that, contrary to a list of probabilistic facts, this represents a choice among possible values for the predicate, meaning that tuples in the set are mutually exclusive.
See example for details.
- Parameters:
- iterableIterable[Tuple[Any, …]]
typically List[Tuple[Any, …]], other types of Iterable will be cast as lists
- type_Type, optional
type for resulting AbstractSet if None will be inferred from the data, by default ir.Unknown
- nameOptional[str], optional
name for the resulting fe.Symbol, if None will be fresh, by default None
- Returns:
- fe.Symbol
see description
- property current_program: List[Expression]¶
Returns the list of Front End Expressions that have currently been declared in the program, or through the program’s constraints
- Returns:
- List[fe.Expression]
see description
- load_ontology(paths: str | List[str], connector_symbol_name=None) None ¶
Loads and parses ontology stored at the specified paths, and store them into attributes
- Parameters:
- pathstyping.Union[str, List[str]]
where the ontology files are stored
- connector_symbol_namestr
name to be used in the connector_symbol. if None, the name is randomly generated
- Returns:
- Expression
the new connector_symbol, to be used in the query program.
- solve_all() Dict[str, NamedRelationalAlgebraFrozenSet] ¶
Returns a dictionary of “predicate_name”: “Content” for all elements in the solution of the Datalog program. Typically, probabilities are abstracted and processed similar to symbols, though of different nature (see examples)
- Returns:
- Dict[str, NamedRelationalAlgebraFrozenSet]
extensional and intentional facts that have been derived through the current program, optionally with probabilities
- class neurolang.frontend.probabilistic_frontend.RegionFrontendCPLogicSolver(*args, **kwargs)¶
Bases:
EqualitySymbolLeftHandSideNormaliseMixin
,TranslateProbabilisticQueryMixin
,TranslateToLogicWithAggregation
,TranslateQueryBasedProbabilisticFactMixin
,TranslateEuclideanDistanceBoundMatrixMixin
,QueryBasedProbFactToDetRule
,ProbFol2DatalogMixin
,RegionSolver
,CommandsMixin
,NumpyFunctionsMixin
,CPLogicMixin
,DatalogWithAggregationMixin
,BuiltinAggregationMixin
,DatalogProgramNegationMixin
,DatalogConstraintsProgram
,TypedSymbolTableMixin
,ExpressionBasicEvaluator
- Attributes:
- included_constants
- included_functions
patterns
Property holding an iterator of triplets
(pattern, guard, action)
.- pchoice_pred_symbs
- pfact_pred_symbs
- predicate_symbols
- probabilistic_predicate_symbols
Methods
add_probabilistic_choice_from_tuples
(symbol, ...)Add a probabilistic choice from a predicate symbol and a set of tuples where the first element is the probability label attached to a head predicate and the other elements are the constant terms of the head predicate.
add_probabilistic_facts_from_tuples
(symbol, ...)Add probabilistic facts from tuples whose first element contains the probability label attached to that tuple.
constant_cos
(x, /[, out, where, casting, ...])constant_equals
constant_exp
(x, /[, out, where, casting, ...])constant_log
(x, /[, out, where, casting, ...])constant_log10
(x, /[, out, where, casting, ...])constant_max
constant_mean
constant_sin
(x, /[, out, where, casting, ...])constant_std
constant_sum
constant_tan
(x, /[, out, where, casting, ...])constraints
()Function that returns the constraints contained in the Datalog program.
get_constraints
()Returns the contraints in a dictionary, where the key is the functor of the consequent of each of the rules.
infer_iterable_type
(iterable)Infer the type of iterable elements without modifying the iterable.
load_atlas
(command)Process the .load_atlas command.
load_csv
(command)Process the .load_csv command.
match
(expression)Find the action for a given expression by going through the
patterns
.pattern_match
(pattern, expression)Return
True
ifpattern
matchesexpression
.pchoice_pred_symb_set_symb
pfact_pred_symb_set_symb
probabilistic_choices
()Return probabilistic choices of the symbol table.
probabilistic_facts
()Return probabilistic facts of the symbol table.
query_based_probabilistic_choice
(implication)Construct probabilistic choices from deterministic queries.
query_based_probabilistic_fact
(implication)Construct probabilistic facts from deterministic queries.
query_based_probabilistic_predicate
(implication)Left for backward compatibility.
rewrite_conditional_query
(impl)Translate an expression of the form
set_constraints
(categorized_constraints)This function receives a dictionary with the contraints organized according to the functor of its consequent and is in charge of setting it both in the symbol table and in the global variable categorized_contraints, useful for XRewriter optimizations.
union_of_cq
(expression)This pattern is here to avoid processing the full program when one rule is rewritten.
add_existential_rules
add_extensional_predicate_from_tuples
add_included_constants_and_functions_to_symbol_table
add_logic_constraint
build_conjunction
build_conjunction_from_expression_block
build_disjunction
build_negation
builtins
conditional_query
euclidean_spatial_bound
eval_lambda
evaluate_function
evaluate_function_infer_type
evaluate_projection
extensional_database
fact
function_anatomical_anterior_of
function_anatomical_inferior_of
function_anatomical_posterior_of
function_anatomical_superior_of
function_anterior_of
function_count
function_inferior_of
function_left_of
function_overlapping
function_posterior_of
function_regexp
function_region_union
function_right_of
function_superior_of
intensional_database
marg_implication
negation_constant
negative_fact
new_set
pattern_match_expression
pattern_match_expression_parameters
pattern_match_expression_tuple
pattern_match_tuple
pop_scope
predicate_terms
probabilistic_fact
process_expression
process_iterable_argument
push_scope
query_based_probafact
query_based_probchoice_wannabe
query_based_probfact_wannabe
reverse_equality
safe_range_pred_to_coord_set
solve_spatial_bound
sort_antecedent_equalities
statement_intensional
statement_intensional_aggregation
symbol
transform_function_application_consequent_to_aggregation
translate_implication
translate_logic_operator
translate_marg_query
translate_true_implication
type
union_with_probabilistic_facts
union_with_query_based_pfact
upper_bound_to_max_dist
walk
within_language_marg_query
within_language_prob_queries
within_language_prob_query
within_language_succ_query
- protected_keywords = {'PROB', '__constraints__', '__pchoice_pred_symb_set_symb__', '__pfact_pred_symb_set_symb__'}¶