**4. Results**

Our approach has been validated in a domestic environment equipped with smart sensors using the BRIDGe platform [52]. Data have been recorded for 14 days in a house with four people (a family with two adult children). In the apartment, there are frequent guests, especially from Friday to Sunday (typically in the evening). Six is the maximum number of people at a Saturday dinner (on the other days, the typical number is less or equal to four).

### *4.1. House Layout and Sensor Setting*

Figure 8 shows the layout of the house. It includes a kitchen (open view), a living room, two bathrooms, three bedrooms, and a corridor. The corridor connects bedrooms, bathrooms, and the living room. The entrance door of the house is in the living room.

**Figure 8.** The Layout of Smart Environment with PIR sensors positions. The positions of the PIRs are highlighted with red circles in the pictures of the rooms. On the map represent, they are positioned in corresponding of the red circles, while the red sectors indicate the general direction of the sensors' sensing areas, not the actual sensing range.

The apartment is instrumented with one PIR per room (therefore eight PIRs) and a contact sensor on the main door. Data are collected by the FIBARO control unit (model HC2); all FIBARO sensors, Z-Wave protocol (868 MHz), are mesh networked to the FIBARO control panel. It is worth noting that the WiFi (there is a connection in the apartment) and Z-Wave connection do not interfere because they operate on different frequencies. Data transmission from the central unit to the cloud operates by events. Whenever a sensor changes state (the state—ON or OFF—and time in which the state change occurred), the record related to the sensor (SensorID, State, Time) is sent to the cloud. The PIRs are FIBARO Motion Sensors, type FGMS-001 (multi-sensor: PIR, vibration, temperature, and light), configured as follows: 2 s blocking time, 2 moves sensibility (number of moves required for the PIR sensor to report motion), and 12 s window time (period of time during which the number of moves must be detected for the PIR sensor to report motion). The PIRs are sensitive to direct sunlight. The PIRs were put in a condition not to be directly affected by the sun. There are no other particular and critical situations to take into account. The PIRS in the bathrooms are positioned far from water. By construction, they tolerate humidity; this characteristic is particularly important in Bathroom Small, where a shower is present and where it is possible to detect variations of 30% RH when taking showers in winter. Possible overlap cases exist in this smart environment as shown in Table 2. As described in Section 3.2.2, OT rooms are the correct rooms to be considered when the person is in the overlap area. For example, the first line indicates that when the person is in the corridor, there is an area where they may also be detected by the living room sensor.


**Table 2.** Possible Overlap Cases in Validation Dataset.

There are four permanent residents, and they have private environments. In particular, there are two single rooms (Room person A and Room person L) and one master bedroom (Room persons F and S). Bathroom Big is used mainly by A, L, and F, while Bathroom Small is used mainly by S. In Bathroom Small, there is a shower used by all four family members. In the living room, there are two sofas and a television; there is no table. The table is only in the kitchen. For the ground truth, the arrival and leaving of people have been recorded manually, including in/out events, the change of people number, and the time when they were in or out. The time has been recorded manually and accurately (hours and minutes). The total people number changes when the door is opened; then, it may be distributed in different ways in the different rooms. Because the record of the contact sensor installed at the door is accurate to seconds, we used it to align the in/out time to reach second-level accuracy.

### *4.2. Indicators Design*

To measure the performance of our approach, two kinds of indicators have been considered: the accuracy of the number of people and the stability of the number change.

### 4.2.1. Accuracy Design

The accuracy represents the percentage of the time with a correct estimation with respect to ground truth. As shown in Equation (4), *TTotalTime* is the total time we measured, and the unit is in seconds.

$$Accuracy = \frac{\sum\_{i=0}^{n} TP\_i}{T\_{TotalTime}} \tag{4}$$

$$T\_{TotalTime} = t - t\_{beyin} \tag{5}$$

$$T\_{\text{CorrectEstimate}} + = \left[\hbar\_{\text{I}} = n\_{\text{I}}\right] \times \left(t - t\_{\text{prevv}}\right) \tag{6}$$

*Accuracy* is the overall accuracy of the validation dataset. *TPi* is the total time that the algorithm makes a correct estimation when the ground-truth number is *i*. *TTotalTime* stands for the total time from which the system begins to the current moment. *t* and *tbegin* are the current timestamp and the moment when the system started, respectively. In the last equation, *n*ˆ*t* is the estimated people number at the current moment, *nt* is the true people number, *t* is the current time, and *tprev* is the previous timestamp when the sensor data have been received.

### 4.2.2. Stability Indicator Design

Stability can be represented by using the notion of information entropy. The information entropy is used to measure the uncertainty of inferred numbers. We take the last 10 min of the inference results to calculate the entropy because the earlier change of numbers may possibly be caused by people's movements. The less the entropy, the better the system performance.

$$Total\\_Entropy = \frac{\sumEntropy(t)}{N} \tag{7}$$

$$Entropy(t) = -\sum\_{k=0}^{\max(h\_t)} \left( p\_{h\_t=k,t} \ln(p\_{h\_t=k,t}) \right) \tag{8}$$

$$p\_{\hbar\_{\ell}=k,t} = \frac{\sum \mathbf{1}\_{\hbar=k}}{T/F\_{\mathbf{s}}} \tag{9}$$

*Total* \_*Entropy* is the average entropy of every moment. *N* is the total number of the received data from the validation dataset. *Entropy*(*t*) is the calculated entropy in the 10 min before time *t*. *n*ˆ*t* is the estimated people number at the current moment, *pn*<sup>ˆ</sup>*t*<sup>=</sup>*k*,*<sup>t</sup>* is the probability that the algorithm estimates the people number is equal to k in the 10 min before time *t*, *T* is the sample period, and *Fs* is the sample frequency; here, we set it to 1 Hz.

Notice that entropy alone is not enough to represent the stability. For example, if there are two people-counting results, such as (2,1,2,1,2,1) and (2,2,2,1,1,1), they have the same entropy value, but the former result is worse. Therefore, a measure of the frequency of changes in the estimated numbers is introduced, called *Changecost*(). The less the changes cost, the better the system performance.

$$\text{Total\\_ChangeCost} = \frac{\sum \text{ChangeCost}(t)}{N} \tag{10}$$

$$\text{ChangeCost}(t) = \sum\_{t=0}^{T} |\hat{m}\_t - \hat{m}\_{t-1}| \tag{11}$$

*Total* \_*ChangeCost* is the average *ChangeCost* of the whole dataset. *ChangeCost*(*t*) is the calculated entropy in the 10 min before time *t*.
