# Modeling and Reasoning of Contexts in Smart Spaces Based on Stochastic Analysis of Sensor Data +
## 4 Principles of Context Reasoning
### Context Graph Building Steps
#### 4.2.3 Discovering Context Conditions  
The centroid in context is representative and meaningful but has insufficient information to define the context. We observed that multiple sensors usually contribute to beginning a context. Principal components analysis (PCA) can discover these important sensors. Once we find the relevant sensors via the stochastic analysis of the sensors' high-dimensional data, the original dataset can be projected onto lower-dimensional data. The process is repeated for each cluster, and the remaining data are used to build context conditions. Principal components are sensors that show definite variance patterns that explicitly express a change of states. To discover these sensors, we should understand the pattern in which the dataset is scattered. For this, a matrix of covariances (\(\mathbf{cov}\)) is calculated first. In a \(\mathbf{\zeta}\)-dimensional dataset, covariance \(\mathbf{cov}\) is calculated by Equation (7):  
\[\mathbf{cov}\;(\hat{\mathbf{s}}^{i},\hat{\mathbf{s}}^{j})=\frac{\sum_{k=1}^{\omega}\;(\hat {\mathbf{s}}_{k}^{i}-\mathbf{\mu}_{i})(\hat{\mathbf{s}}_{k}^{j}-\mathbf{\mu}_{j})}{(\mathbf{\zeta}- 1)}, \tag{7}\]  
where \(\hat{\mathbf{s}}^{i}\) and \(\hat{\mathbf{s}}^{j}\) stand for the set of sensor values in \(i\)th state space and \(j\)th state space, respectively. \(i\)th state space and \(j\)th state space belong to the same context. Since the maximum number of state spaces in a context is \(\mathbf{\zeta}\), the total covariances establish a \(\mathbf{\zeta}\times\mathbf{\zeta}\) covaraince matrix \(\mathbf{R}\), shown in the Equation (8):  
\[\mathbf{R}(\hat{\mathbf{S}})=\left[ \begin{array}{ccc}\mathbf{cov}\;(\hat{\mathbf{s}}^{1}, \hat{\mathbf{s}}^{1})&\ldots&\mathbf{cov}\;(\hat{\mathbf{s}}^{1},\hat{\mathbf{s}}^{\xi})\\ \vdots&\ddots&\vdots\\ \mathbf{cov}\;(\hat{\mathbf{s}}^{\xi},\hat{\mathbf{s}}^{1})&\ldots&\mathbf{cov}\;(\hat{\mathbf{s}} ^{\xi},\hat{\mathbf{s}}^{\xi})\end{array} \right] \tag{8}\]  
From the covariance matrix \(\mathbf{R}\), we calculate the eigenvectors, which characterize the square matrix as linear equations, each of which can transform the matrix onto a new axis. Eigenvalues then measure how well the sensor data are scattered. Eigenvectors and eigenvalues are calculated by the following condition: \(\mathbf{R}\mathbf{\
u}=\mathbf{\lambda}\mathbf{\
u}\), where \(\mathbf{\
u}\) is the eigenvectors and \(\mathbf{\lambda}\) is the eigenvalues. As \(\mathbf{R}\) is a \(\mathbf{\zeta}\times\mathbf{\zeta}\) matrix, \(\mathbf{\
u}\) is also a \(\mathbf{\zeta}\times\mathbf{\zeta}\) matrix, that is \(\mathbf{\zeta}\) eigenvectors exist. Each eigenvector has its own eigenvalue; therefore, there are \(\mathbf{\zeta}\) eigenvalues in \(\mathbf{\lambda}\):  
\[\mathbf{\
u}=\left[ \begin{array}{cccc}\overset{\rightarrow}{\mathit{elg}_{1}} &\ldots&\overset{\rightarrow}{\mathit{elg}_{1}}&\ldots&\overset{ \rightarrow}{\mathit{elg}_{\xi}}\end{array} \right], \tag{9}\]  
where \(\overset{\rightarrow}{\mathit{elg}_{i}}\) is an eignevetor with \(\mathbf{\zeta}\) components. Next, we choose the eigenvectors with high eigenvalues as principal components. The challenge is in determining the threshold for which eigenvalues are high enough to be acceptable. We propose the threshold \(\theta_{e}\) for the average of eigenvalues of selected eigenvectors. In our approach, the eigenvectors are sorted by eigenvalues in descending order; then, eigenvectors with values that exceed \(\theta_{e}\) are chosen. Eigenvectors satisfying this condition establish a feature matrix \(\mathbf{F}\):  
\[\mathbf{F}=\left[ \begin{array}{cccc}\overset{\rightarrow}{\mathit{elg}_{1}}& \ldots&\overset{\rightarrow}{\mathit{elg}_{\kappa}}\end{array} \right], \tag{10}\]  
where \(\mathbf{\kappa}\leq\mathbf{\zeta}\), \(\sum_{t=1}^{\kappa}\mathbf{eiv}_{t}\leq\theta_{e}\), \(\mathbf{eiv}_{t}\) is an eigenvalue of \(\overset{\rightarrow}{\mathit{elg}_{t}}\). With a feature matrix \(\mathbf{F}\), a given dataset is transformed into lower-dimensional data with \(\mathbf{\kappa}\) sensors.