interactive.py contains some sample code on how to use the new Indra system. This notebook will illustrate its contents.
Right now we have three types of entity at play here:
Entity: the base "thingie" from which all else descends. Operations on entities act like vector operations.Composite: an Entity that can hold other entities. Because it is itself an entity, we can nest composites. Operations on composites act like set operations.Time: a Composite that loops over its members when acting, giving rise to "periods" of action.Let's import interactive and see what we can do:
In [ ]:
from indra.interactive import *
Now let's have a look at some of the things we get from that import:
In [2]:
newton
Out[2]:
newton is an Entity. The base Entity has a name, a lifespan (duration), and an arbitrary number of attributes.
hardy is another entity. Here's how easy it is to make a group out of two entities:
In [3]:
great_mathematicians = newton + hardy
great_mathematicians
Out[3]:
Oops, we forgot Leibniz and Ramanujan:
In [7]:
forgotten = leibniz + ramanujan
forgotten
great_mathematicians += forgotten
great_mathematicians
Out[7]:
In [ ]:
We can also do set intersection:
In [8]:
great_mathematicians *= forgotten
great_mathematicians
Out[8]:
And take subsets, using a predicate:
In [4]:
calc_founders = newton + leibniz
just_l = calc.subset(max_duration, 25, name="Just Leibniz!")
just_l
Out[4]:
In that particular case, our predicate selected just the set members with a duration of less than 25, and so we got only Leibniz. The function signature for subset is:
def subset(self, predicate, *args, name=None):
*args is a list of arguments to pass to the predicate function, so it can take an arbitrary number. The optional name parameter will name the new subset.
In [ ]:
calc_founder