Logistic function - convert values to probabilities
In many home automation scenarios we have an observed value, maybe a sensor reading, maybe a time interval since something happened and we want to convert that value to a probability, e.g. what's the probability that someone left the room given how long it's been since any activity there.
Previously I described using the atan function for that purpose. The logistic function has a similar shape and can be used as an alternative. There's an interesting discussion here on their
differences. In summary: atan has a 'fatter tail'.
I've used both for converting distances or errors to probabilities and most recently I've used the logistic function to compute the probability that two distances belong to the same observation. For example, if something measures as being 5m away, how likely is it that it's in a room that's measured as being 7m away?
Let's take the difference between a measured distance and a recorded distance. Using y = 1 - 2 / (1 + e^((5-x)*1)) we map that difference onto the logisic curve and then values above zero can be used as the probability that the device matches the recording for this distance, and values below zero can be used (in the negative) as the probability that the device does not match the distance. Around 4m we want the probability of either to be about zero - essentially at this error the data isn't telling us anything.
double error = fabs(measured_distance - recording_distance);
// Use a sigmoid function: the logistic curve
double prob = 1 - 1 / (1 + exp((4-error)*1));
if (prob > 0)
// use positive probability to increase probability that
// the device IS here
...
else
// use negative value to increase probability that
// the device is NOT here
...
We can shift the logistic curve with the offset (4) and scale and invert it as necessary to get whatever probability curve we want from an observed value.
I've been working on home automation for over 15 years and I'm close to achieving my goal which is a house that understands where everyone is at all times, can predict where you are going next and can control lighting, heating and other systems without you having to do or say anything. That's a true "smart home".
My year long Bluetooth project that won the $20,000 HCI and Microsoft competition during lockdown has continued to grow and now reliably tracks how many people are in the house and outside and can locate any device down to room level.
Digital Twin are an online representation of a real world object, a copy of its properties in the digital world and a way to send updated and commands to it. In effect I've been making them for years but now they have a trendy name.
An overview of the many sensors I've experimented with for home automation including my favorite under-floor strain gauge, through all the usual PIR, beam and contact sensors to some more esoteric devices like an 8x8 thermal camera.
Why automated learning is hard for a smart home. The perils of over-fitting, under-fitting and how the general unpredictable nature of life makes it hard to build a system that learns your behavior.
One way to reduce the volume of sensor data is to remove redundant points. In a system with timestamped data recorded on an irregular interval we can achieve this by removing co-linear points.
ESP32 provides a great platform for sensors around the house but by the time you've added a USB power brick, cable and enclosure it's quite messy. I wanted a device that I could just plug in with no exposed wires and no mounting needed so I designed one in OpenSCAD.
Bluetooth sensing for home automation is a great proxy for people counting as it can detect and locate each cellphone in the house. iBeacons attached to tools, cars and pets can provide a 'find my anything' feature too.
Microwave doppler sensors can be found in some alarm sensors but there are also available very cheaply as a separate component. They offer exceptional range but suffer from false triggers requiring a probailistic approach to people sensing.
Optical-beam sensors are reliable and can cover a long-distance such as across a garage or aisle-way. When they include multiple-beams they have good false-trigger rejection.
Home automation systems need to respond to events in the real world. Sometimes it's an analog value, sometimes it's binary, rarely is it clean and not susceptible to problems. Let's discuss some of the ways to convert these inputs into actions.
In a home automation system we often want to convert a measurement into a probability. The ATAN curve is one of my favorite curves for this as it's easy to map overything onto a 0.0-1.0 range.
Several years ago we did a major remodel. I did all of the finish electrical myself and supervised all of the rough-in electrical. I also put in all of the electrical system and water in our barn. I have opinions ...
An if-this-then-that style rules machine is insufficient for lighting control. This state machine accomplishes 90% of the correct behavior for a light that is controlled automatically and manually in a home automation system.