ANY-maze Help > The ANY-maze reference > The Protocol page > The elements of a protocol > Behaviour > Virtual switches > An introduction to virtual switches

An introduction to virtual switches

Introduction

As the name implies, a virtual switch is something which is either on or off. But why 'virtual'? Well, a virtual switch doesn't really exist; it's just something you create to determine when other things (which do exist) are in a state you want to consider as being on or off.

For example, ANY-maze can determine the speed of the animal as it moves about during a test. Let's say that you would like to know when the animal is moving 'fast'. Well, obviously, this requires that you decide what 'fast' actually means. So let's say that you choose a speed of 1 m/s; when the animal is moving faster than this, it's 'fast', and when it's moving slower than this, it isn't 'fast'. So, we have a switch (on when fast, off when not fast) and it's based on something ANY-maze already knows - the speed of the animal. What we have is a virtual switch!

 Thresholding instantaneous values 
 Grouping on/off values 
 Virtual switches and zones 
 Using virtual switches in events  

Thresholding instantaneous values

As the example in the introduction shows, a virtual switch can be used to threshold instantaneous values within ANY-maze (in the example, we used the value of 1 m/s to threshold the animal's speed).

In this context, I am using the term instantaneous to refer to something which has a value at an instant in time - like the animal's speed. Compare this to something like the distance the animal has travelled; this has no value at an instant, but rather it has a cumulative value over a period of time.

In the example, we used a virtual switch to apply a threshold to the animal's speed, such that the switch was 'on' when the animal was moving faster than the threshold value. But what if you wanted to know when it was moving slower? Well, you can do that too - in fact, you have three types of threshold: greater than a value, less than a value and between two values. So, for example, you could use three virtual switches to classify the animal's speed as:

 Fast - Moving faster than 1.0 m/s 
 Medium - Moving between 0.3 m/s and 1.0 m/s 
 Slow - Moving slower than 0.3 m/s  

As this classification shows, you can create multiple virtual switches to threshold the same value.

Although the above description makes it sound like a 'greater than a value' virtual switch will always turn on when the value is greater than the threshold and turn off when it is less, this isn't necessarily the case because you can optionally include some hysteresis. This is explained fully in the help topic Using hysteresis with a virtual switch, but in brief, the idea is that you specify a upper threshold and a lower threshold. To turn the switch on, the value must be greater than the upper threshold and to turn it off, it must be less than the lower threshold. And what's the benefit of that? Well, it avoids rapid on/off switching when the value is very close to the threshold, which could create artificially high values for the 'count' of switch activations, and that  might be a problem in some applications.

There are a number of instantaneous values that can be thresholded using virtual switches in ANY-maze, and we will gladly add more if requested - you'll find the full list here: Instantaneous values that can be threshold by a virtual switch

Grouping on/off values

Another way to turn a virtual switch on and off is to use other on/off items within ANY-maze. For example, you could specify that a switch should be on when either a photobeam is broken, or a key on the keyboard is pressed.

This may seem a little esoteric at first, but let's consider a real example. Imagine you are observing a mother and some pups and you are using ANY-maze to score 6 behaviours using keys on the keyboard of your computer. Three of these behaviours you classify as 'maternal' and three you classify as 'general' (i.e. not benefiting the pups). You run your tests and you press the keys when each behaviour is occurring.

Now you want to see how much time the mother spent exhibiting maternal behaviour. You might choose to simply sum the time of the three individual maternal behaviours, but what if the mother could exhibit more than one at the same time (for example simultaneously suckling and cleaning a pup). In this case, if you sum the total for each behaviour you would get an erroneous result.

Instead, you should create a virtual switch, call it 'Maternal behaviour' and specify that it is on when any of the three maternal behaviour keys is pressed. The total 'on' time of this virtual switch will tell you the amount of time the mother was exhibiting maternal behaviour.

In this example, we used one way of grouping on/off items - we said the virtual switch is on when any of the constituent keys was on. However, you can also specify that a virtual switch should be on only when all the constituent items are on - for example, this could be used to find out how often two maternal behaviours were being exhibited at the same time.

Any combination of the following items can be used to switch a 'grouped' virtual switch on and off:

 Whether the animal is in a specific zone 
 Whether or not the animal is oriented towards a specific zone 
 Whether or not the animal is oriented towards a specific point 
 Whether the animal is mobile 
 Whether the animal is freezing 
 Whether the animal is rearing 
 Whether a key (being used to manually score behaviours) is pressed 
 Whether an on/off input is active (for example, a switch or photobeam) 
 Whether a movement detector is seeing the animal as moving 
 Whether an output switch is active 
 Whether a syringe pump is running 
 Whether a shocker is active 
 Whether another virtual switch (whether a 'threshold' or 'group' type) is active 
 Whether an ON/OFF type plug-in is active  

Virtual switches and zones

Virtual switches are automatically analysed both for the apparatus as a whole and also within zones. This means, for example, that a virtual switch which 'thresholds' the animal's speed would allow you to see how much time the animal spent moving 'fast' not just in the entire apparatus, but also in each zone individually.

This also applies to switches that 'threshold' the distance from a zone. Thus, you could see how far the animal is from one zone when it is in other zones. For example, imagine you have divided your apparatus into two zones; one is well-lit, the other less so. In the middle of the apparatus, you have a zone with a novel object in it. You could then look at the distance from the novel object (using a virtual switch), and assess whether it is different when the animal is in the well-lit zone to when it is in the poorly lit one.

Using virtual switches in procedures

Like many protocol elements in ANY-maze, you can use virtual switches in procedures. This means that a procedure can do such things as turn on a sound if the animal is moving faster than a certain speed; start the video recorder whenever the animal is closer than a certain distance to a zone; or end the test if the combined sum of time 'on' of a number of keys is above a certain value.

Of course, there are many more options than just these, and you can find out more about how to use virtual switches in this way, in the Procedures section of the help.

Note that some virtual switches will not be available to procedures - to find out why this is, see Why some virtual switches are only available after the test has finished.

See also:

 Setting up a virtual switch 
 Editing a virtual switch 
 Deleting a virtual switch 
 Virtual switch measures 

© Copyright 2003-2026 Stoelting Co. All rights reserved

ANY-maze help topic T0374