# Pattern Recognition in Older Adults' Activities of Daily Living
## 3 Materials and Methods
### Pattern Recognition
It was the most accurate value through various comparisons, as shown in Table 2.  
``` Data:\(\mathcal{D}\)\(\triangleleft\) Set of all recorded data \(\mathcal{D}=\{d_{i}\},i=1\dots 26,000\) Data:\(\mathcal{C}\)\(\triangleleft\) Set of Compartments \(\mathcal{C}=\{c_{i}\},i=1\dots 5\) Data:\(\mathcal{B}\)\(\triangleleft\) Set of Beacons \(\mathcal{B}=\{b_{i}\},i=1\dots 6\) Result:\(\mathcal{P}\)\(\triangleleft\mathcal{P}=\{p_{i}\},i=1\dots 10,800\) (pattern.csv file) begin\(\mathcal{D}\gets ReadData(``train.csv\")\)\(\mathcal{B}\gets\)\(\mathit{RierieveBeaconInfo}()\)foreach\((b_{i}\in\mathcal{B})\)do\(Comp(b_{i})\gets GetCompartment(UUID(b_{i}))\)\(s_{i}\gets Comp(b_{i})\)\(\triangleleft S_{i}\) string associated to \(b_{i}\)
1 end foreach\(((b_{i},b_{j})\in\mathcal{B})\)doif\(Eq(s_{i},s_{j})>0.85\)then\(Concatenate(s_{i},s_{j})\)
2 end foreach\((c_{i}\in\mathcal{C})\)do\(m_{b}\gets GetSmaller(UUID(b_{j}))\)\(\triangleleft b_{j}\in c_{i}\)\(\triangleleft\) Redirect\(Data(b_{j},m_{b})\)\(\triangleleft\) redirect\(b_{j}\) to \(m_{b}\)
3 end foreach\((d_{i}\in\mathcal{D})\)do\(earliestD\gets Min(d_{i})\)\(latestD\gets Max(d_{i})\)if\(numDays(earliestD,latestD)<7\)then\(out\leftarrow``InsufficientData\"\)
4 else\(t_{i}\leftarrow(earliestD,latestD)\)foreach\((t_{i}\in\mathcal{S}\mathcal{S}\)\(c_{j}\in\mathcal{C})\)do\(prb\gets Prob(c_{i},t_{i})\)\(avg\gets Avg(RSSI_{b_{i}},c_{j},t_{i})\)\(std\gets StDev(RSSI_{b_{i}},c_{j},t_{i})\)\(perc25\gets Perc(RSSI_{b_{i}},c_{j},t_{i},25)\)\(perc75\gets Perc(RSSI_{b_{i}},c_{j},t_{i},75)\)\(\mathcal{P}\gets Store(prb,std,perc25,perc75)\)
5 end foreach
6 end foreach
7 end foreach
8 end foreach\((d_{i},d_{i})\gets GetSmaller(d_{i})The algorithm stores the correspondence of beacons in a separate structure upon recognizing that they are located in the same compartment. It then selects the \"master\" beacon, \(m_{b}\), for that compartment based on the alphabetical order of each beacon's UUID. The beacon with the smaller UUID is designated as the master beacon. Consequently, all other beacons within the same compartment are configured to point to the \"master\" beacon. For instance, if the living room has three associated beacons (\(b_{1}\), \(b_{2}\), and \(b_{3}\)), \(b_{1}\) is chosen as the master beacon. This means that \(b_{1}\) points to itself, while \(b_{2}\) and \(b_{3}\) point to \(b_{1}\). Thus, when data from \(b_{2}\) or \(b_{3}\) are detected, the algorithm interprets them as originating from \(b_{1}\), enabling a more accurate calculation of the user's location. The system then examines the structure containing chronologically ordered data corresponding to the older person's daily activities. It searches for the earliest and latest dates within this structure. Subsequently, it verifies if the difference in days between the latest and earliest dates exceeds seven days. If not, the algorithm cannot recognize a pattern, as the minimum required duration for pattern recognition is seven days. In such cases, the algorithm initiates a reorganization of all data. Consequently, the structure is reconstructed, where each date (including date and hour) encompasses all information related to BLE beacons and their RSSI values recorded by the smartwatch at a specific time. This approach facilitates the assessment of the volume of data obtained daily, allowing for improved organization based on date discrepancies. Furthermore, all available beacon data are included for each date to ensure comprehensive data organization. After organizing the data, it is necessary to verify which days do not meet the minimum criteria set by the algorithm, as detailed in Section 3.6. Then, the system initiates a new re-verification process if at least seven consecutive days of relatively stable data are available for pattern recognition. This precaution is essential because the elimination of certain days may lead to situations where there are insufficient days to meet this requirement.