Get Started with NeuroLang¶
First Steps With NeuroLang¶
NeuroLang is a unifying formalism to perform complex queries and explorations using heterogeneous data sources like tabular data, volumetric images, and ontologies. To perform this in sound manner, NeuroLang is a probabilistic logic programming language based on Datalog [abiteboul1995], [maier2018].
The whole idea of logic programming is to be able to make assertions of the style:
region x is a left hemisphere gyrus if the label of x in Destrieux et al’s atlas starts with “L G”.
which can be formalised in first order logic as
which, if we assume that being on Destrieux et al’s atlas means that is already a region, can be shortened as
Finally, for notation convenience, we will drop the quantifiers, assuming that all variable on the left of the arrow (such as ) is universally quantified, and all variable appearing only on the right of the arrow (such as ) will be existentially quantified [maier2018]. This leads to the expression
which we formalise in python as:
with neurolang.scope as e:
e.left_hemisphere_gyrus[e.x] = e.destrieux_atlas(e.l, e.x) & e.startswith('L G', e.l)
the full example is in our gallery in Loading and Querying the Destrieux et al. Atlas’ Left Hemisphere.
Negation can also be used in Neurolang. For instance
Disjunctions in Logic Programming¶
Disjunctions in logic programming merit are a very specific case. For instance, let’s say that all the regions in the left hemisphere’s cortex are either a sulcus or gyrus, or more specifically
x is a left hemisphere region if x is left sulcus or x is left gyrus
which in first order logic can be formalised as
alternatively, this can be written as a set of two propositions
which we formalise in Neurlang in the classical logical programming syntax:
with neurolang.scope as e:
e.left_hemisphere_region[e.x] = e.left_hemisphere_sulcus(x)
e.left_hemisphere_region[e.x] = e.left_hemisphere_gyrus(x)
or in a less verbose manner:
with neurolang.scope as e:
e.left_hemisphere_region[e.x] = e.left_hemisphere_sulcus(e.x) | e.left_hemisphere_gyrus(e.x)
Aggregations¶
Aggregations combine information from a set of tuples. A good example of an aggregation is the maximum. As a mathematical definition we could define an aggregation as
which in neurolang is expressed as
with neurolang.scope as e:
e.max_population_per_country[e.country, e.max(e.pop)] = e.population_per_country_province(e.country, e.province, e.pop)
Abiteboul, S., Hull, R. & Vianu, V. Foundations of databases. (Addison Wesley, 1995).