Switches and transitions
A lot of signals can have anomalies and special events that happen on specific timeframes:
- a promotion gives a temporary boost in sales
- an outage results in a loss of 90% of the data volume
- a device gets broken and generates more noise
- the creation of a new shop adds a new linear trend to the revenue of a company
- a holiday makes a seasonality pattern change
These events can happen in two ways:
- the signal suddenly changes: instant change.
- the signal gradually changes to reach a new value: change with transition period.
In mockseries, this kind of change is called a switch. Let's see how to create such switches, and how to create custom transitions.
#
Switch and revertConsider a simple switch: the base value is 0, and it changes to 1 after 2 days.
You can configure the switch to revert to the base value.
Let's revert 2 days after the change.
Thanks to signal combinations, this simple switch allows powerful simulations, for instance:
- the opening of a new shop adds a new constant value to the revenue of a company
- a device gets broken, it generates noise, then is fixed:
- an outage results in a loss of 90% of a seasonal data volume.
#
TransitionsFor the moment, we've only seen instant transitions. This is the default behavior of the Switch.
In real life, many change events have specific transitions behavior.
Imagine you drive at 90km/hour, and you enter an highway: you change your speed to 130km/hour.
At the end of the highway, you get back to 90km/hour. These changes are definitely not instant ! You accelerate: this is the transition.
A transition has:
- a window: for the car example, it's the time to change from 90 to 130k/hour
- a transition function: the shape of the change from 90 to 130km/hour (it most likely is not linear)
Those depends on the car and the way you drive.
#
Linear transitionFirst, let's consider the acceleration of the car is linear.
The timeseries will be:
- car is at 90km/hour
- car accelerates linearly, it reaches 130km/hour in 10 seconds
- car is at 130km/hour
- car decelerates linearly, reaches 90km/hour in 5 seconds
- car is at 90km/hour
To implement this in mockseries, we pass a Transition object to the switch signal. The Transition describes the time and the shape of the transition.
#
Lambda transitionAbove looks nice, but we want to use more complex transitions. The LambdaTransition allows to use custom transition functions.
The key idea of the lambda transition is that the transition behavior can be defined as a function such as
(the very beginning of the transition) and (the end of the transition).
This transition function is then rescaled to take into account the transition time and the base and switch values.
You just need a rough shape of the transition and define it on a [0-1] range.
Let's take the car example with:
- a perfect, smooth acceleration: accelerate a lot at the beginning then reach the new speed slowly
- a brutal deceleration: decelerate too much, then get back to the base speed
(believe me for this one)
That's it! You now know how to:
- define switches
- define complex transitions
To go further:
- implement more realistic transitions function (checkout some automotive course)
- change the transition window size and see how it impacts the timeseries
Go to the next page to explore random switches. This is helpful to simulate random outages.