Tag: Bonsai

  • Arithmetic Operations in Bonsai

    Arithmetic Operations in Bonsai

    Bonsai is widely used for designing experiments in neuroscience and other fields.
    With Bonsai you can build sophisticated programs without writing code, and run them with precise synchronization.

    Because it is so simple, however, operations that would be trivial in ordinary programming—such as basic arithmetic—have to be done in a somewhat unintuitive way.
    Here I explain how to perform arithmetic in Bonsai, using MouseMove as an example.

    Below is what these arithmetic operations actually look like: from top to bottom, addition, subtraction, multiplication, and division.

    For clarity, I used the X and Y values of MouseMove as the example here.
    In practice, though, you can perform calculations on values obtained from other sensors as well.

    The key point in Bonsai is that, before performing an operation, you need to combine the two values using “Zip”.

    The contents of “Zip” take the form (value 1, value 2); its role is to bundle the two values at that moment into one.
    Each operation then computes on value 1 and value 2 accordingly.

    This is hard to explain in words, so try to get a rough intuition for it.
    Without “Zip”, the program would not know which value to multiply with which, so the calculation could not be performed. That is why the X and Y values must first be combined so that they correspond to each other.

    The names of the operators for each arithmetic operation are listed below.

    • Addition => Add
    • Subtraction => Subtract
    • Multiplication => Multiply
    • Division => Divide

    I have posted a demonstration below, so please take a look.

    <Example in action>

  • Bonsai as a visual programming language

    Bonsai as a visual programming language

    Bonsai is a visual programming language introduced in a 2015 paper.
    It allows you to acquire data from sensors and process it at the same time.

    A key feature of Bonsai is that complex processing pipelines can be assembled easily, much like putting together a puzzle, and the results of that processing can be checked in real time.

    Bonsai can also be combined with other analysis software (DeepLabCut, Open Ephys, BonVision, and so on) and with hardware (cameras, controllers, microcontrollers, etc.), making it highly extensible.

    Because you can carry out complex analysis and processing intuitively without having to learn a programming language that looks intimidating, anyone can use it easily, and it broadens the range of experiments you can run.

    The paper describing Bonsai is available here.
    You can install Bonsai from here.

    Image taken from the paper.
    Each circle is called a node and represents an individual operation.

    This is what the screen looks like when Bonsai is actually running (taken from the paper).
    On the left you can search for nodes and add the one you need; in the central panel you arrange nodes to build up a pipeline while visualizing what it does; and on the right are the detailed settings for each node.

    The windows popping up in the main panel show the execution status of each node; for a camera capture node, for example, the live camera image can be displayed.

    It may look difficult at first glance, but seen this way it turns out to be surprisingly straightforward.

    Now let’s actually install it.
    That said, all you need to do is download it from this site.
    Just open the downloaded “Bonsai-*.*.*.exe” file and run the installer.
    Note that security software such as Trend Micro may block the installation.

    Once Bonsai is installed, both Bonsai and Bonsai (x86) will appear in your list of applications.
    For normal use either one is fine, but occasionally one of them will fail to run; in that case, trying the other one often works.

    One drawback is that Bonsai currently runs on Windows only, and is not supported on Linux or macOS.
    That may change in the future, but it is something to keep in mind.

    From the next post, I’ll start actually using Bonsai.