# Guessing Human Intentions to Avoid Dangerous Situations in Caregiving Robots
## 3 Methodology
### Simulation-Based Approach to Artificial Theory of Mind
#### 3.2.2. Intention Assignment and Simulation  
According to the \(ctx\) information, for each person \(h_{i}\in H\) and object \(o_{j}\in O\) within the person's field of view, we generate intentions for each possible action \(a_{k}\in A\) and sampled gaze direction \(g_{l}\in G\):  
\[int_{ijkl}=intention(h_{i},o_{j},a_{k},g_{l}) \tag{8}\]  
Each intention is then simulated:  
\[c=sim(ctx,int_{ijkl}) \tag{9}\]  
where \(c\) is a flag indicating whether a collision occurred during the simulation. Algorithm 1 formalizes the process of intention guessing and enacting.  
Algorithm 1 starts by accessing the current context \(ctx\) provided by \(\mathcal{W}\) and the lists of people \(H\) and objects \(O\) in the robot's environment. For each person, \(h_{i}\), the list of objects entering their field of view (\(Tgts\)) is obtained using a simple geometric inclusion test over a predefined frustum (line 5). Each object is assumed to be a potential interaction target for the person. Thus, for each person and target, intentions enacted by potential actions must be simulated to predict risky situations. An intention is considered dangerous if its enactment entails a collision. Since the risk assessment depends on the person's ability to perceive the situation, the person's gaze is also considered during the simulation. We assume the robot cannot estimate this from its position, so the predefined range in \(Gaze\) is uniformly sampled (line 8). According to the person (\(p_{i}\)), the object (\(t_{j}\)), the action (\(act_{k}\)), and the gaze (\(gaze_{l}\)), an intention \(int_{ijkl}\) is finally generated (line 9).  
```
0:\(W\), \(Gaze\), Actions
0:\(W\)
1:\(ctx\gets getContext(W)\)
2:\(People\gets getPeople(ctx)\)
3:\(Objects\gets getObjects(ctx)\)
4:for all\(p_{i}\in People\)do
5:\(Tgts\gets fov(p_{i},Objects)\)
6:for all\(t_{j}\in Tgts\)do
7:for all\(act_{k}\in Actions\)do
8:for all\(gaze_{l}\in sample(Gaze)\)do
9:\(int_{ijkl}\gets intention(p_{i},t_{j},act_{k},gaze_{l})\)
10:\(c\gets sim(ctx,int_{ijkl})\)
11:\(W\gets addToW(W,(int_{ijkl},c))\)
12:endfor
13:endfor
14:endfor
15:endfor
```  
**Algorithm 1** Intention guessing and enacting  
The simulator is then called to execute that intention given the current context (\(ctx\)) (line 10). This call implies freezing the current context so changes can be made without interfering with the perception of reality. The simulation proceeds by executing action \(act_{k}\) under the constrained access to objects in the scene given by \(gaze_{l}\). In this experiment, the robot's only action is _goto(x)_, so the simulator proceeds in two steps: (a) a path-planning action to compute a safe route from the person to the target object, in which the occupancy grid is modified to include only the objects in the person's field of view; and (b) the displacement of the person along that path in the unmodified scene. The first step corresponds to the question \"how does the person move through her environment given the assigned gaze?\" and the second to \"how does the robot imagine from its point of view what the person will do?\" The path is executed using a copy of the robot's path-following controller. The simulation provides the answers to the two questions, returning a flag \(c\) signaling theoccurrence of a collision. Finally, in line 11, \(\mathcal{W}\) is updated to include the new intention with the attribute \(c\), possibly marking a risky situation.