A Fuzzy Recommendation System for the Automatic Personalization of Physical Rehabilitation Exercises in Stroke Patients

: Stroke is among the top 10 leading causes of death and disability around the world. Patients who suffer from this disease usually perform physical exercises at home to improve their condition. These exercises are recommended by therapists based on the patient’s progress level, and may be remotely supervised by them if technology is an option for both. At this point, two major challenges must be faced. The ﬁrst one is the lack of specialized medical staff to remotely handle the growing number of stroke patients. The second one is the difﬁculty of dynamically adapt the patient’s therapy plan in real time whilst they rehabilitate at home, since their evolution varies as the rehabilitation process progresses. In this context, we present a fuzzy system that is able to automatically adapt the rehabilitation plan of stroke patients. The use of fuzzy logic greatly facilitates the monitoring and guidance of stroke patients. Moreover, the system is capable of automatically generating modiﬁcations of existent exercises whilst considering their particularities at any given time. A preliminary experiment was conducted to show the advantages of the proposal, and the results suggest that the application of fuzzy logic may help make correct decisions based on the patient’s progress level.


Introduction
One in six people will suffer a stroke during their lifetime. Globally, stroke causes more than 6 million deaths each year, according to statistics provided by the World Health Organization [1]. Approximately two-thirds of stroke survivors leave hospital with some form of disability. Current predictions for the coming years are, unfortunately, negative, due to factors such as the incidence of stroke in middle-income countries [2]. In fact, 70% of strokes globally occur in low-and middle-income countries. This figure has doubled in recent decades, while in high-income countries, it has fallen by 42% [1]. The impact of this unresolved clinical challenge on health systems is enormous, due to issues such as the continuous need for physical rehabilitation and face-to-face supervision by qualified medical staff. In addition, stroke often affects people who are at the productive peak of their working careers, which can also have an impact on a country's socioeconomic development [3].
Much of the post-stroke rehabilitation process focuses on the physical rehabilitation of patients. In this process, both physiotherapists and occupational therapists guide the patient to regain day-to-day autonomy by addressing the movement and mobility difficulties resulting from stroke. In this sense, rehabilitation plans are usually designed around the concept of self-care, i.e., based on activities and exercises that the patient can progressively perform at home and in an independent way, whenever possible. The intensity of rehabilitation will depend on the condition of each patient, although it is quite common to carry out daily sessions of 45 min for periods of between 2 and 6 weeks. In more severe cases of stroke, rehabilitation may last several months.
In recent years, a significant number of applied research studies have appeared in which technology has been used to deploy virtual home rehabilitation systems [4,5]. These pursue the dual goal of facilitating patient monitoring and motivating patients to carry out rehabilitation exercises at home. These systems generally provide natural interaction mechanisms in a 3D virtual environment, guiding and helping patients to perform rehabilitation exercises in a playful and enjoyable way. Typically, a system offering such features will consist of (i) a device that can detect the patient's movements by means of a tracking system that calculates the positions and orientations of the joints in 3D space; (ii) a laptop running the system's software; and (iii) a monitor that provides visual feedback. It should be noted that technological solutions based on the low-cost Microsoft Kinect TM device have underpinned much of the research work conducted in recent years [6], with numerous studies giving credit to the clinical validity of the generated tools [7,8]. However, this device has already been replaced by more modern and scalable alternatives.
In order for a remote rehabilitation system to be used effectively from home, different aspects need to be considered. Firstly, usability is essential. If the underlying technology involves an entry barrier for the patient, then the system will be discontinued. Such a system can be considered usable when technology becomes transparent and natural for the patient. In this sense, natural interfaces based on gesture and movement detection are particularly relevant. At the same time, the system must be able to offer continuous assistance to the patient, making it as easy as possible to use the system, especially when approaching the system for the first time. Secondly, the ability to motivate the patient is another fundamental element to guarantee the continuous use of the system, since rehabilitation routines are usually based on the systematic repetition of a limited set of exercises. The integration of gamification techniques has been used in recent years to increase patient motivation [9]. Thirdly, the system must be able to recognize, with a certain precision and in an automatic way, the movements or exercises performed by the patient, which are usually previously assigned by the therapist. Home rehabilitation systems are often designed to encourage the patient to complete the entire routine, even if the execution is not perfect. In this regard, it is often desirable to strike a balance between the economic cost of the tracking system and the accuracy of the system.
A system that integrates these three fundamental characteristics will maximize the chances of successful use, guiding the patient through the rehabilitation process at home, facilitating the therapist's work, and ultimately, improving the quality and effectiveness of remote rehabilitation. However, the therapist would still be responsible for the individualized supervision of each patient according to their inherent condition (considering aspects such as their age, physical condition, or severity of the stroke) and their level of progress according to the assigned rehabilitation routine. Ideally, a remote rehabilitation system may incorporate an intelligent module that would automatically and dynamically adapt this routine for each patient, thus incorporating the notion of personalization. This adaptation would serve, among other things, to recommend more difficult exercises or to suggest variations of exercises based on the patient's performance.
In the previously introduced research context, our work has been essentially focused on the creation of a comprehensive remote rehabilitation system capable of automatically evaluating and classifying rehabilitation exercises [10]. On these foundations, we also designed a language whose sentences are processed by a software that can automatically generate personalized exergames that motivate the patient to perform rehabilitation exercises. In this article, we focus on the automated and intelligent personalization of the rehabilitation process adapted to each patient [11]. Thus, this paper proposes a fuzzy system for the recommendation of rehabilitation exercises for stroke patients. This sys-tem integrates an expert knowledge base defined by means of fuzzy rules and variables that reflects aspects such as the performance of a patient when performing rehabilitation exercises. The system is capable of adapting the rehabilitation plan initially assigned by the therapist. This adaptation takes the form of recommendations for new exercises, or exercises already performed by the patient, depending on the variation in the patient's level of progress as the rehabilitation process progresses.
The remainder of this article is structured as follows. Section 2 positions our work in the context of recommender systems, and particularly, those that operate automatically in remote rehabilitation systems. Subsequently, Section 3 presents our contribution, discussing the fundamental aspects and addressing the integration in a remote rehabilitation system. Section 4 presents the results obtained after conducting an experiment that illustrates with examples of how the fuzzy recommender system adapts a patient's rehabilitation routine. These results are discussed in Section 5, and the article ends with a series of conclusions in Section 6.

Related Work
When designing remote rehabilitation systems, it is essential to take into account the personalization of the patient's rehabilitation process. A symbiosis must be sought between the patient, the system, and the clinician, which seeks to adapt to the patient's progress according to the state of their injury. Achieving this involves the design of recommendation systems that are adaptive to the patient.
The design of a recommender system depends to a large extent on the used information and the available knowledge. Recommender systems can be classified into different groups [12]: (i) user profile recommendation systems; (ii) content recommendation systems; (iii) hybrid recommendation systems; (iv) filter-based recommendation systems; and (v) feature-based recommendation systems.
In the field of remote rehabilitation, recommendation systems based on the user's profile are commonly used. These systems analyze the patient's profile, considering their condition and evolution, and based on this, recommend a rehabilitation routine from the established plan for the recovery of their injury.
One of the main problems to be faced when studying a patient's profile is the uncertainty and vagueness with which the patient's condition is usually assessed. Furthermore, determining how well they are performing a certain exercise or even establishing how they are progressing represent similar challenges. In this sense, fuzzy logic and linguistic variables [13,14] are well-validated tools to be taken into account when dealing with uncertainty and vagueness.
In the context of remote rehabilitation systems, González-González et al. [15] presented a proposal in which the general objective is the design of an intelligent rehabilitation system based on exergames, consisting of an exercise player and a tool for designing them. The system includes a recommendation module that analyses the user's interactions, physical history, and preferences to assign the exergames to be performed. In turn, this module handles the concepts of difficulty levels and user skills. The recommendation algorithm revolves around three simple assumptions based on the patient's most recent performance (last exergame performed): (i) if the performance was low, the algorithm chooses an easier exergame; (ii) if the performance was good, the algorithm assigns a more difficult exercise; (iii) otherwise, the algorithm chooses an exercise of medium difficulty. The system was evaluated with domain experts, users and therapists, with positive results in terms of gesture-based interaction and medical applications.
Esfahlani et al. [16] discussed a serious game designed for the user to perform a series of tasks based on a dynamic of reaching virtual goals with a therapeutic objective. The difficulty levels of these tasks are adjusted based on a fuzzy controller, which has the user's skeleton tracking data (position and orientation of joints in 3D space) as input and the difficulty level of the game that the patient will perform later as output. In this sense, the proposed system allows to guide, in an automatic way, the patient's rehabilitation routine through continuous and personalized learning. The fuzzy rules are derived from consultancy and collaboration with physiotherapists, along with the various tests carried out. On the other hand, the authors of [17] describe related work in which a grammar is used to enable therapists to specify rehabilitation exercises. The system includes a fuzzy logic-based component that evaluates, in real time, whether the patient performs the exercises according to the exercise definition. In a related context, the prototype of the patient rehabilitation station that integrates video games for rehabilitation based on computational intelligence techniques is presented in [18], both for the online monitoring of the execution of movements during the games and for the adaptation of the game to the patient's condition. The prototype integrates a fuzzy system to monitor the execution of the exercises, in real time, according to the clinical constraints defined by the therapist at the time of configuration, and to provide direct feedback to the patients. At the same time, the system adapts to modify the game according to the patient's current performance and progress and to the exercise plan specified by the therapist. This latter work represents one of the pillars of the methodology for the design of safe, therapeutic exergames introduced by these same authors [19].
In a line of research more linked to the management of expert knowledge, a telerehabilitation system for the remote selection, evaluation and management of physical therapies is proposed in [20]. The main contribution of this work is the creation of an integral system for tele-rehabilitation, although the authors place special emphasis on the extraction and use of knowledge through the definition of an ontology composed of 2300 classes and 100 properties, to appropriately select the exercises assigned to each patient. To do this, a knowledge base is used that contains information about the patient's medical history and the previously assigned treatment.
On the other hand, Karime et al. [21] proposed a web-based framework for wrist rehabilitation that makes use of fuzzy logic to offer adaptive tasks to the patient, in parallel with the supervision performed by the therapist. In this work, an evaluation of the effectiveness of the framework is carried out, considering the adjustment of various parameters used in the rehabilitation process in a framework that combines the level of personalization of the rehabilitation based on the patient's performance and the feedback offered by the therapist. The use of fuzzy logic is also present in articles focusing on patient rehabilitation using robots or exoskeletons, such as the work discussed in [22], where a system based on deterministic adaptive robust control is introduced whose control parameters are optimized thanks to a novel approach based upon cooperative game theory. External disturbances (possibly time-varying) are managed through fuzzy logic and its ability to work with uncertainty.
Our proposal, which is described in detail in Section 3, which falls within the scope of several lines of research that are currently considered popular research topics. Particularly noteworthy is the line that contemplates the definition of artificial intelligence models and the use of expert knowledge to guide or orientate the patient's evolution, based on their clinical data and the context of their illness. This line is closely related to the impact that precision medicine has had on the medical domain, and whose ideas can be borrowed with the ultimate aim of adapting or personalizing the rehabilitation process to each patient. Furthermore, this work is also framed in the field of telemedicine tools in the context of physical rehabilitation, thus trying to respond to an unresolved clinical challenge as a consequence of the lack of specialized clinical staff to supervise patients affected by stroke or, from a more general point of view, by neurological diseases requiring physical rehabilitation.
Thus, the main contributions of this research article are as follows: • Firstly, a recommendation module which can automatically modify rehabilitation plans previously devised by physicians is proposed. Conditional knowledge is defined to select the most suitable exercise for the patients, depending on their current condition and how they progress in terms of rehabilitation; • Secondly, the gap between the rehabilitation system in which the recommendation module is integrated and the patients/physicians is reduced, thanks to the use of fuzzy logic to both represent and infer knowledge. This approach facilitates the understanding of the artificial system, and particularly, how the recommendation module operates. We think that this contribution is especially relevant when it comes to explain how artificial systems make decisions. Furthermore, the feedback provided to the patients can be used to guide the rehabilitation process in a dynamic way; • Thirdly, the proposal sets the foundations for providing physicians with a tool that reduces the time spent supervising stroke patients. Currently, there is a lack of specialized personnel to supervise, face-to-face and on a regular basis, patients affected by neurological diseases that require physical rehabilitation. Our work may eventually help improve the quality and effectiveness of remote rehabilitation by addressing the automatic adaptation of rehabilitation routines.

Remote Rehabilitation System Overview
In this section, a fuzzy system for automatically recommending rehabilitation exercises for stroke patients is proposed. Particularly, the exercises recommended by this system are therapeutic exergames, which involve physical effort guided by gamification techniques. Fundamentally, this system was mainly designed to enable patients to perform home rehabilitation exercises, according to their condition and situation at a given moment of their therapy. The proposed approach employs the therapist's knowledge to evaluate the patient mobility and recommend, in consequence, a rehabilitation exercise according to such information. However, it should be pointed out that the recommendation of an exercise when patients perform rehabilitation at home is exacerbated, since the adjustment of the therapy turns into a more complex process by having a fuzzy idea of their current situation. This system bears this in mind, and is able to automatically generate personalized modifications of existent exercises by considering the particularities of the patients. Despite this, it should be noted that the system does not pretend to remove the therapist's role. On the contrary, it aims to complement it in order to reduce their workload by delegating tasks to the proposed intelligent system.
The system introduced herein consists of several components that interact between them. Figure 1 depicts the overall architecture, whose interrelated components are the domain knowledge module (i); the interface module (ii); the tracking module (iii); the evaluation module (iv); and the recommender module (v). Each component is briefly described below. The domain knowledge module integrates the knowledge necessary for the system to correctly work. This module considers the following aspects: knowledge about the physical rehabilitation of stroke patients, knowledge about the performance of rehabilitation exercises, knowledge about managing their rehabilitation plan, knowledge about the patient's body, their injury, their condition, and the evolution in their rehabilitation. This module is referred to as the knowledge of domain experts from a higher perspective. Specifically, this is structured and organized in three specific classes of knowledge, which are clearly differentiated: declarative knowledge, procedural knowledge, and conditional knowledge: • Declarative knowledge. It refers to the facts or static knowledge. In this regard, it defines the set of existent body joints that can be exercised during the rehabilitation, which will be recognized by the system (i.e., J = {j 1 , j 2 , . . . , j 31 } https://docs.microsoft.com/ bs-latn-ba/azure/kinect-dk/body-joints, accessed on 11 June 2021), the constraints associated with them (i.e., C(J) = {C(j 1 ), C(j 2 ), . . . , C(j 31 )}), the associated variables to monitor the rehabilitation exercise of patients (i.e., Procedural knowledge. This knowledge defines the rehabilitation exercises and the game dynamics associated with them (i.e., E = {e 1 , e 2 , . . . , e n }. In each e i ∈ E, the patient works out a concrete joint (i.e., j x ∈ J) with a different degree of complexity, trying to rehabilitate a body member with low mobility. The procedural knowledge also includes the knowledge required to check how well the patient performs an exercise and to determine how the patient is progressing in the rehabilitation process; • Conditional knowledge. This knowledge will be used to recommend the next exercise to be performed in the patients' rehabilitation plan (i.e., e i ∈ E), based on their degree of injury and their progress towards recovery. Fundamentally, it makes use of a set of fuzzy (if-then) rules (i.e., R = {r 1 , r 2 , . . . , r m }) to achieve the aforementioned goal. This will be deepened in the following section.
The interface module enables the communication between the patient/therapist and the system. On the one hand, it includes the adequate interaction mechanisms so that patients perform rehabilitation exercises as if they played games. On the other hand, it provides the software components to the therapists in order to define rehabilitation exercises and game dynamics associated with them.
The tracking module is responsible for recognizing in real time the users' movements to perform rehabilitation exercises. In essence, it captures the body tracking results from a sensor device, in this case Microsoft Azure Kinect DK https://azure.microsoft.com/eses/services/kinect-dk/, accessed on 11 June 2021. These results represent the 3D spatial coordinates of the human body joints, i.e., positions (x, y and z) ∈ R 3 , and rotations (w, a, b and c) ∈ R 4 . The latter is expressed as a normalized quaternion.
The evaluation module assesses the performance of a rehabilitation exercise according to the level of complexity that it entails for the patient. This information is necessary to know the patient's status within the context of the rehabilitation plan and to recommend new rehabilitation exercises.
The recommendation module is responsible for modifying the patient's rehabilitation plan according to the patient's current condition. This module will make use of conditional knowledge to determine the most appropriate exercise for the patient based on their injury and their current level of progress within their rehabilitation plan. This module, which is the core of the paper, is fully detailed in the next section.
As described above, procedural knowledge contains the exercises used in this system. These are physical activities to be executed by patients within the rehabilitation plan with a motivational approach that is based on play, i.e., exergames. The exergame constitutes the core of the system and it is defined as a 8-tuple, consisting of the following elements: where each element represents the following: • D i is a description of the exercise e i ; • J I i is the set associated with the joints involved in the rehabilitation exercise e i , i.e., SET_i is the setup of the exercise which is defined as a 4-tuple (sc, rp, t, c). sc indicates the degree of success by achieving a step in the rehabilitation exercise e i (sc ∈ N); rp are the repetitions required to perform the exercise e i (rp ∈ N); t is the time needed to finish the exercise e i (t ∈ R); and c is the degree of complexity of the exercise (c ∈ N); • VE i represents the virtual objects positioned in a playable scene in the 3D space. Examples of this objects may be rings, spheres and hoops, among others; • T i refers to the trajectories associated with the movements that a patient will make when performing the exergame e i . T i is defined as a set of virtual points that establish the movements the patient must perform; • RG i is a set of rules that contains the game mechanics of the exercise e i , which are based on the interaction between J I i and T i in the 3D space to achieve an objective. Formally, RG i = (rg i1 , rg i2 , . . . , rg in ), where each particular rule of the game rg ij is used to define the function -J I i establishes the joints that interact with the game rule; -VE i establishes the virtual nodes that interact with the game rule; -O is a set of objectives defined to satisfy the game rules GM is a set of game mechanics to be triggered when a joint involved J I i interacts with a virtual node VE i meeting a certain objective o j . Example of game mechanics may be visual feedback provided to the patient to correct a bad movement.
is a set of constraints that are associated with joints that the patient should not ideally move to compensate for the lack of mobility or strength in the exercise e i (i.e., KPI i is a set of key performance indicators that are used to monitor the patient's evolution according to the performance of the exercise e i .

Proposed Recommendation Module
This module aims to help therapists recommend new exercises to patients who perform home rehabilitation. Generally, therapists ask patients to carry out a series of exercises at home, when the therapy has not yet been completed in the rehabilitation center. Once the patients return to the clinic, therapists interview them about how they have performed the exercises and evaluate their progress in order to be able to recommend new exercises. Without the use of technology, the therapists' knowledge may be inaccurate regarding the patients' progress as they do not know their commitment at home.
The developed system will collect data on how the patients have performed exercises at home within their rehabilitation plan. In addition, the system, using an intelligent recommender, is able to adapt the rehabilitation plan to the patients' needs. This section presents the architecture devised for the intelligent rehabilitation module which will be used by the general system to autonomously modify the patients' rehabilitation plan according to their evolution.
However, entering before fully into detail of the formal model, the next subsection shows the fundamental ideas of the proposed system.

Fundamental Ideas
This system allows therapists to define a rehabilitation therapy based on the patients' injury and the their initial assessment regarding the patients' condition (their injury state, their physical condition, and their age).
Particularly, the overall rehabilitation system makes use of the gym metaphor to define a rehabilitation therapy. This means that our approach is based on the global concept of patient's rehabilitation plan, which can be considered as a succession of exercises taken from E and ordered by their complexity, which must be carried out by the patient in a sequential way. However, the plan should be able to be altered according to the patient's progress. Thus, provided that the system detects that the patient is finding difficulties to perform an exercise in the plan, the system should be capable of recommending an exercise with lower complexity. It even may modify an existent exercise, reducing the number of repetitions or increasing the time to be spent on it. On the other hand, the system should behave in a similar way when in a situation in which complex exercises are easily performed.
Thus, a rehabilitation plan for a patient p i , denoted as P(p i ), is defined as follows: P(p i ) = {e x , e y , . . . , e k } where each e j ∈ P(p i ) is also an element of E (i.e., e j ∈ E) and it is satisfied that Complexity(e x ) ≤ Complexity(e y ) ≤ . . . ≤ Complexity(e k ) with Complexity(e j ) being a function that returns the complexity of the exergame e j (taken from c ∈ SET_j).
As mentioned above, the exercises that form part of a patient's plan are initially selected and organized by the therapists according to the patient's injury and condition. The recommendation module will automatically adjust the plan according to the patient's performance, acting on the set of exercises included, their order or even their configuration (values of parameters rp (number of repetitions) and t (time needed to finish the exercise) taken from SET x ).

Recommender Module Definition
The recommendation system presented herein has been proposed as a function that will determine an action on the patient's rehabilitation plan to be adjusted, as much as possible, to the patient's state of recovery. Therefore, this function models the existing relationship between the domain, i.e., the patient's condition in the recovery of the injured limb, and the codomain, i.e., an action to be performed in the rehabilitation plan.
The challenge to be faced is the domain of definition of such a function. This should provide information on how the patients are progressing in their recovery. It will be determined by how they have performed the last exercise of the plan as well as the state in which they are found regarding their recovery.
The variables, which can be recorded by the system, and can provide information on how the patient performed the last exercise of the plan, are defined below: • difference_number_steps (V 1 ) is the difference between the number of steps that the patients and the therapists performed to carry out the last rehabilitation exercise last_exg (i.e., the patient fails to pass through all the virtual points that establish the exercise trajectory); • accumulated_deviation (V 2 ) is the cumulative spatial deviation between the patient's exercise and that gold standard or the therapist's exercise (i.e., this calculation is based on the distance accumulated when traversing the trajectory associated to the last exercise last_exg); • difference_time (V 3 ) is the temporal difference regarding the execution of the last exercise last_exg between the patient and the therapist.
These variables collect information about the patients' status, i.e., how they have performed the last exercise of the allocated plan. However, they do not take into account their evolution, that is, how they have progressed. Significantly, it becomes essential to add this information to the domain to know the actual state of the patient in detail. Thus, the variable progress_level (PPL) was included in order to track the state in which a patient is found before performing the last exercise. Its value belongs to the range [0, 10], and the initial one is determined by the therapists when they assess the patient for the first time. It should be noted that the value of the previous variable is considered to choose the exercises for the patient's rehabilitation plan. Furthermore, this variable is modified depending on the patient's evolution towards the last recovery session.
On the other hand, the codomain should reflect the next exercise to be performed by the patients according to their condition. In this research work, the initial rehabilitation plan established by the therapist is modified by proposing a new exercise based on a desirable difficulty recommended to the patient. Thus, the output will consist of a new exercise, which will be established depending on the difficulty given by one of the following functions: • propose_exercise. It chooses an exercise from E whose lesion and joint J I i are similar to the last exercise last_exg. This function takes into account an exercise that has not yet been performed, since the system internally stores information about the patients and the exercises they performed, i.e., their level of success regarding the exercise, their points, as well as the time spent by the patient to complete it. To do this, this function takes two parameters: (1) a label indicating the complexity of the exercise to be searched for (MC, more complexity; SC, same complexity; LC, less complexity) based on the (2) last performed exercise (last_exg); • repeat_last_exg. It recommends the repetition of the last exercise performed by the patient last_exg based on modifying its configuration. This function takes as parameters rp (number of repetitions) and t (time needed to finish the exercise) from SET last_exg .
It is important to highlight that the execution of the last exercise influences the patient's progress level, i.e., the results from the execution of the last_exg affects the value of the variable progress_level (PPL). This is why any action on this variable will also be included as an output of the recommender system. This variable, denoted as EPPL, is named Effect_on_PPL.
When modeling the function that relates the domain or inputs to the codomain or outputs, a mechanism is used to understand why the recommendation was made. At the same time, this mechanism also deals with the imprecision and uncertainty that exists when evaluating the performance of the last exercise performed by the patient. Even when evaluating the level of progress of the patient within the context of their rehabilitation plan. For this reason, a set of IF-THEN fuzzy rules (R), which model the function The linguistic variable V (i.e., V = {V 1 , V 2 , V 3 }) considers the following domain of definition: DDV x = { very low (VL), low (L), medium (M), high (H), very high (V H)} being x defined from 1 to 3. Each linguistic value in DDV x is defined by means of a trapezoidal function (Π), enclosed by a lower limit a, an upper limit d, a lower support limit b, and an upper support limit c, where a < b < c < d (see Equation (2)). If the values of b and c are equal, a triangular function is obtained: The choice of the trapezoidal function to construct the membership function, for each of the values that the variables used in the system can take, is justified because it is the only one that gives us the necessary freedom to represent any type of value (i.e., ordered-discrete or ordinal, unordered-discrete or nominal, boolean, numerical, ranking or the most frequent continuous) [23].
The  On the other hand, the linguistic input variable PPL may take the following values: "excellent achievement" (EA, equivalent to 9 or 10); "outstanding achievement" (OA, equivalent to 7 or 8); "satisfactory achievement" (SA, equivalent to 5 or 6); and "not achieved" (N A, smaller than 5). Each linguistic value that this variable can take is defined by means of a trapezoidal function-as can be seen Figure 3. The linguistic output variable EPPL takes the following values: "substantial decrease" (SD, equivalent to decrease 1 point); "moderate decrease" (MD, equivalent to decrease 0.5 point); "no change" (NC); "moderate increase" (MI, equivalent to increase 0.5 point); and "substantial increase" (SI, equivalent to increase 1 point). Each one of these linguistic values will also be defined by means of a trapezoidal function-as can be seen in Figure 4. It is purely used to modify the patient's level of progress as the patient recovery level potentially suffers a change after a physical activity. The operations to be considered are three: increasing the patient's progress, decreasing it or maintaining it.
Knowledge engineering techniques have been used during the design of the system, mainly based on interviews with physicians, using designs and executions which have been fine-tuned in different stages as a basis. Thanks to this process, the rules and the variables and values they take have been determined, seeking a compromise between understandability and efficiency. As for the other output of the system, it will be a recommended exercise for the patient by invoking the function propose_exercise, as mentioned above. This function will recommend an exercise from the set P(p i ) with higher, lower or same complexity as the last exercise performed by the patient. Otherwise, if the exercise to be recommended is not found, E will be used. The function is shown in Algorithm 1. It should be pointed out that we assume an exercise will certainly be taken from E.
Invoking the function repeat_last_exg(rp, t) involves recommending to the patient the repetition of the last performed exercise e y , however, altering some of its configuration parameters from SET y , namely rp by setting a different number of repetitions, or t by giving a different time to finish the exercise e y . The modification of the values may be an increase (+) or reduction (-) in the parameters rp and t. Each rule r i ∈ R has the following form: IF V 1 is DDV 1 (i) AND V 2 is DDV 2 (i) AND V 3 is DDV 3 (i) AND PPL is DDV PPL (i) THEN e y and EPPL is DDV EPPL (i). On the one hand, e y represents the exercise to be recommended. On the other hand, DDV x (i) represents the values that the variable V x takes in the rule i, that is, DDV x (i) ⊆ DDV x . Similarly, DDV PPL (i) and DDV EPPL (i) represent the values that the variables PPL and EPPL take in the rule i, respectively, where DDV PPL (i) ⊆ DDV PPL and DDV EPPL (i) ⊆ DDV EPPL . The set DDV x is a global set that represents the values that must take the variable V. Furthermore, the set DDV PPL and DDV EPPL are the global sets that represent the values that must take the variables PPL and EPPL.
Lastly, some of the rules defined in this system to model the behavior of the recommender system, which will constitute the conditional knowledge of the remote rehabilitation system, are shown below: As can be seen, the rules are highly explainable, which will help understand why the system makes a new recommendation.

Functions Of The Proposed Recommender System
In this section, we present how the proposed system uses the fuzzy rules presented above to recommend a new rehabilitation exercise and to alter a patient's progress level.
Given that the output of the rules consists of two elements, that is, the recommended exercise and an alteration in the value of the patient's progress level, two outputs need to be obtained for each occurrence of the inputs (V 1 × V 2 × V 3 × PPL). Therefore, the system infers two situations for each input, which are enumerated below: 1.
The next rehabilitation exercise that the patient should perform; 2.
How to alter the value of the patient's progress level.
For this purpose, we will consider that the rules inform of the following two relations, since the consequent is related to a logical AND: To infer within the first relationship, we will check the activation degree of each rule. This will be done by evaluating the antecedent of each one. This evaluation is performed as discussed subsequently.
A function ϕ ji will be associated with each variable V i in the rule j, whose definition depends on the values taken by the variable V i in it. Therefore, if the variable takes a single linguistic label L x (i.e., L x ∈ DDV i ), the definition of the function ϕ ji will be the same as the one defining the linguistic value (i.e., ϕ ji = Π L x ). However, when the variable takes more than one linguistic value, this function will be built based on whether or not the values are close to the domain of definition of the variable V i , i.e., DDV i . For consecutive linguistic values, we will refer to this set as C. The function ϕ ji will be defined as a trapezoidal one with the following parameters: If the variable V i in a rule takes non-consecutive values, or there are two non-consecutive groups of values, the function ϕ ji will be defined with as many trapezoidal functions as there are non-consecutive values or non-consecutive groups ( Figure 5). The activation degree of a rule r j for an input (x 1 , x 2 , x 3 , x 4 ), where x i is the input value (crisp value) taken by the variable V i , will be calculated by determining the membership value of each input x i to the function that defines the input variable V i , i.e., ϕ ji (x i ). Given that the antecedent of our rules has more than one part related with a logical AND operator, the t-norm [24] of the minimum has been applied to obtain a single membership value. The definition of this calculus is as follows: To obtain the output of this first inference process, the t-conorm [24] of the maximum will be used (i.e., the t-conorm corresponding to the minimum t-norm). As a result, the system will recommend the exercise that proposes the rule with the highest activation degree: output_exercise(r j ) = max j=1,...,n {activation degree(r j )} (8) On the other hand, the inference of the second relationship has been carried out by using the Mamdani's fuzzy inference method [25], whose output is a fuzzy set. This fuzzy inference process is composed of the following steps:

1.
Evaluate the antecedent for each rule r j ∈ R to obtain a single membership value, i.e., activation degree (r j ). We will do this as in the previous case; 2.
Obtain the conclusion of each rule in EPPL. To do this, we truncate the fuzzy value taken by the consequent of the rule in the variable EEPL using the minimum with the activation degree(r j ) on its membership function. The output will be a new fuzzy set defined by means of a membership function µ j where: and it is defined as with L x being the value that the variable EPPL takes in the rule r j (L x ∈ DDV EPPL ).

3.
Aggregate rule's conclusions into a single fuzzy set defined by means of the function µ, using a fuzzy aggregation operator. The t-conorm of the maximum has been used to aggregate the truncated output functions returned by the previous step:

4.
Defuzzification. Since we want to obtain a crisp value that affects to the PPL value, which we recall is confined to the range [0, 10], so we need to transform the fuzzy set obtained in step 3 into a single numerical value. To do this, we used the defuzzification method of the centroid, which returns the center of the area under the fuzzy set obtained in step 3. It should be pointed out that the total area of the membership function distribution used to represent the combined control action is divided into a number of sub-areas. We denote the centroid as EPPL co and it is calculated as where N indicates the number of sub-areas, µ(x i ) and x i represent the area and the centroid of the area, respectively, of the i th sub-area.
The value EPPL co (EPPL co ∈ [−1, 1]) is used to modify the patient's progress level (PPL) with the aim of updating their progress: We would like to conclude by stressing that Zadeh's conventional t-operators of Min and Max, which have been used in this system, perform significantly well within the context of our problem [26].

Proposed System In Operation
This section describes an experimental case study conducted to show the benefits of the proposal discussed in this research work. Then, an example that describes how the fuzzy system that underpins our proposal would work in a real-world situation is presented.
However, before fully entering the description of the experimental case study, let us take a look at the holistic view of the whole recommender system presented in Figure 6 in order to understand how it works with all the modules involved.

1.
The system proposes an exercises (e x ∈ E) to the patient through the interface module; 2.
The patient performs an exercise whose movements are captured by the tracking module; 3.
The system evaluates, through the evaluation module, the performance of the patient. Particularly, it obtains the value of the variables (V 1 , V 2 , V 3 ); 4.
The system, based upon the values of the variables (V 1 , V 2 , V 3 , and PPL), triggers the rules following the next criteria: (a) It computes the activation degree of the rules belonging to the knowledge base (i.e., conditional knowledge); It selects, employing the first inference system, the rule whose activation degree is greater among the set of rules. Its consequent contains the exercise to be recommended, which may be a new one or a modification of the last exercise performed; (c) It modifies, employing the second inference system, the patient's progress level (EEPL). It should be noted that this modification takes into account the last exercise performed.  Consider a stroke patient whose mobility on the left side of the body has been substantially reduced. Fortunately, the patient's progress has relatively improved over the past few sessions. Imagine that the last exercises performed consisted in, from an upright bipedal posture, raising the left arm from the hip to the shoulder, passing the hand in red color through the spheres placed in the 3D world that draw a trajectory. Fundamentally, the hand must pass first through the sphere close to the hip and with the largest size, ending the repetition when the colored joint reaches the sphere close to the shoulder and with the smallest size. This exercise comprises three repetitions and it must be completed under two minutes. Figure 7 graphically shows the left shoulder abduction by means of a virtual system in which the patient simulates the movement, so that their left hand touches the colored spheres.

Example 2.
Assume that the value of the variable PPL is assigned to 4.5 based on the last session. After performing the last exercise, the values of the variables V 1 , V 2 and V 3 were obtained. They are 0.75, 0.80 and 0.55, respectively. The process to obtain the EPPL value is described below.
The previous description means that the patient took more steps than the therapist. The trajectory between them differed considerable. However, the patient did not spend much more time on completing the exercise than the therapist. It should be reminded that the values of these variables are the result of the mean after the patient performing all repetitions.
It should be highlighted that the previous values of the input scores are computed taking into account the configuration SET i and the performance of the therapist. However, the underlying details of this process are not provided as it is beyond the scope of this paper.
Considering this situation as an starting point, the inference process that this system carries out is discussed subsequently. At this point, it is important to point out that the system infers two situations for each input, i.e., The first inference process consists of proposing a physical rehabilitation exercise that is best suited according to the patient's situation. Initially, the values associated with each input v i are applied to each rule r j to obtain its activation degree. We show below only the rules from R whose activation degree is greater than 0 (i.e., {r i | r i ∈ R ∧ activation degree(r i ) > 0}): Therefore, the best compelling exercise to be recommended is obtained from the rule whose activation degree is greater among the set from the previous step. In other words: max{activation degree(r 3 ), activation degree(r 8 ), activation degree(r 12 )} As a result, the recommended exercise is the one related to the rule r 3 which proposes the repetition of the last performed exercise, but reducing the repetitions and increasing the time. Given that the system infers that the exercise was not well performed because of time, the algorithm responsible for this update proposes two repetitions in 3 min. That is, the system subtracts one repetition and adds one minute. The underlying details of this algorithm are not provided as it is beyond the scope of this paper. This new configuration for the proposed exercise will be used later so as to see the reliability level of the system in terms of decisions making.
On the other hand, the inference of the second relationship was also performed in order to update the patient's progress level. Clearly, the completion of the last rehabilitation exercise must have had some effect on their progress. Let us see how that effect is computed.
As from the activation degrees previously obtained, the output fuzzy set is truncated with the aforementioned values by using the minimum method. That is, the output fuzzy set is reshaped for each rule r j , whose output is represented by the following new sets defined as membership functions: From the outputs calculated in the previous step, an aggregation process is employed to unify these values in a single fuzzy set. The outputs of each rule (i.e., activation degree) are combined into a single fuzzy set as follows: Figure 8, all three rules, which are activated, are displayed to show how their outputs are aggregated into a single fuzzy set (µ(x)). The membership function of this fuzzy set assigns a weight for every output EPPL value.
Finally, a representative value is obtained after performing the defuzzification step that uses the EPPL co defined in Equation (11). In the aggregated fuzzy set, as shown in Figure 8, the total area is divided into five sub-areas. This value and with the centroid of each sub-area are calculated in Table 1. The defuzzified value EPPL co is: ∑ Area * x i / ∑ Area; −0.36572/0.9825 −0.38. Therefore, the new PPL value is updated through Equation (12), that is, 4.5 − 0.38 = 4.12. This result indicates that the patient's progress level should be reduced.
The system now proposes performing the last exercise with reduced repetitions but increased time (output of the rule r 3 ). The repetitions to be taken are 2 and the time is 3 min.

Example 3.
After performing the last proposed exercise, the values of the variables V 1 , V 2 and V 3 are 0.2, 0.45 and 0.15, respectively. The PPL value is 4.12, whose result was obtained in the previous example. The process to obtain the new EPPL value is described below, omitting unnecessary steps.
It is remarkable that the patient correctly performed the exercise. They took almost the same number of steps as the therapist. The trajectory was relatively low. Furthermore, the time spent completing the exercise was also similar to that of the therapist.
As in the previous example, we show below only the rules from R whose activation degrees are greater than 0: activation degree(r 2 ) = 0.20 activation degree(r 7 ) = 0.60 activation degree(r 13 ) = 0.80 As a result of applying the output exercise function 8, the rule r 13 is triggered as its activation degrees is greater among the others. Therefore, the best compelling exercise to be proposed by the system is one whose complexity is the same as the last exercise performed. This exercise consists of a left arm abduction, that is, a movement which implies raising the left arm around the shoulder, moving it laterally away from the body. This exercise comprises two repetitions and it must be completed under three minutes. Figure 9 graphically shows the left shoulder abduction by means of a virtual system in which the patient simulates the movement, so that their left hand touches the colored spheres.  Then, the new membership functions are computed as a consequence of truncating the output fuzzy sets with the values previously obtained. In other words: After that, a single fuzzy set is obtained by combining the previous outputs using the function 10. The result is as follows: µ(x) = max{µ 2 (x), µ 7 (x), µ 13 (x)} Finally, the output, i.e., EPPL co , is computed using the centroid function defined in (11). Similar to the previous example, the total area is divided into six sub-areas. Table 2 shows the area and centroid of each sub-area. Furthermore, Figure 10 depicts the new aggregated fuzzy set. The defuzzified value EPPL co is: ∑ Area * x i / ∑ Area; 0.21148425/0.775 0.27. Therefore, the new PPL value is updated through Equation (12), that is, 4.12 + 0.27 = 4.39. This result indicates that the patient's progress level has relatively improved.

Discussion
A preliminary evaluation was carried out and the results obtained appear to be quite interesting. The discussed case study showed that the system proposed in this research work is capable of inferring the next rehabilitation exercise and appropriately updating the patient's progress level. Both tasks are based on the performance of the last exercise made by the patient.
The main goal of the experiment conducted was oriented towards demonstrating the utility of the proposed system. This is the first step before using the system for a clinical trial with patients, who have a suffered moderate or severe stroke, according to the levels measured by the National Institutes of Health Stroke Scale (NIHSS) scoring system. These clinical trials will test the efficacy of the system in the recovery of stroke patients.
Interestingly, the results of the evaluation are in accordance with the values of the input variables v i . The patient's progress level was relatively low (PPL = 4.5). The time invested was not too bad with respect to the time spent by the therapist (V 1 = 0.55), but the number of steps between the patient and the therapist was significantly different (V 2 = 0.75). In addition, the trajectory greatly differed from the one charted by therapist (V 3 = 0.8). In other words, the exercise was not accurately performed by the patient. This means that the patient preferred to sacrifice accuracy over time. In this regard, the system automatically concluded that the patient needs to keep working out to positively upgrade their progress. Additionally, the system suggested that the patient repeats the last performed exergame, considering that the number of repetitions should be reduced but the time spent in performing the exercise should be increased. Remarkably, the result of this system's suggestion is coherent taking into account the progress level of the patient (PPL = 4.12) and also the performance of the last exercise proposed (V 1 = 0.2, V 2 = 0.45, V 3 = 015). As a result, the patient's progress level was moderately upgraded, highlighting that this increase is reasonable based on two previous performances. In view of these facts, the reliability of the system is noteworthy. The system adequately performs recommendations and updates the progress of the patient accordingly.
However, one limitation of our research work is the difficulty to test the proposed system with a representative sample of stroke patients due to the current COVID-19 pandemic. To date, we focused our work on evaluating the system from an internal point of view, that is, according to case studies such as the one described in Section 4. Therefore, the results presented in this paper need to be interpreted with caution.
Despite the limitations of this evaluation, our findings suggest that the use of Fuzzy Logic for physical rehabilitation seems to make sense as it enables making decisions in an automatic and understandable way. What this approach offers is to dynamically monitor and guide the home rehabilitation process, whose supervision is difficult to be made by a therapist because of their lack of time and the need for a face-to-face supervision. However, the developed system does not aim at replacing the therapist. On the contrary, it is intended to relieve the therapists' workload and help them interpret, through an inference process similar to the human one, how the patient progresses as the rehabilitation plan is being completed.
This research aims to be complemented, in a second phase, with a clinical trial to evaluate the impact of using our system on the recovery process of real stroke patients. In a third phase, another clinical trial will be conducted to analyze the efficacy of the system for its intended use, which is to improve physical rehabilitation at home.

Conclusions
In order for a remote rehabilitation system to be used continuously and effectively by stroke patients, three essential characteristics must be provided: (i) usability, to remove the barrier that the use of technology may represent, and adequately guide the user in the process of autonomous rehabilitation; (ii) motivation, to encourage the continued use of the system and reduce the possibility of abandonment by the patient; and (iii) autonomy, to be able to automatically recognize and evaluate the rehabilitation exercises performed by the patient without the need for continuous supervision and presence of the therapist. A significant part of the existing research work focuses on one or more of these features, with the therapist being responsible for adjusting the rehabilitation routine according to the level of progress of their patients. Ideally, a remote rehabilitation system that offers an integral solution should be able to offer suggestions or recommendations that enable the ability to customize the rehabilitation routine automatically or semi-automatically.
In this paper, we proposed a new recommender system to determine the next action that should be performed by the patient in their rehabilitation plan. The system is based on a set of fuzzy rules and a double inference process on them. The use of fuzzy logic is justified because it provides patients and physicians with guidance that they can understand. In this sense, the use of linguistic variables makes it easier for them to interpret this information. On the other hand, the recommender system provides the patients with detailed feedback on the work they have done, with an explanation about the areas in which they have performed well, and others which may still need improvement. In addition, on a broader level, patients will be informed whether they have truly performed the rehabilitation routine well.
The approach presented herein shows the potential of automating the work of monitoring and guiding the steps in a patient's rehabilitation. The idea of this method is not to replace the role of the physician, but to support them with tools that enable them to conduct an efficient rehabilitation process, dedicating their time to higher level tasks. The proposed system is intended to speed up the assignment of exercises to patients and to obtain data that can be provided to physicians. All these data allow them to evaluate and determine the patient's state of evolution in their injury.
The discussed case study shows the potential of our approach in terms of adapting the rehabilitation process to the patient's progress level. Particularly, the adoption of fuzzy logic to guide the processes of knowledge representation and inference of recommendations greatly facilitates the automatic customization of rehabilitation routines, since the way such processes are described is inherently close to the way therapists adjust rehabilitation routines. Thus, this research work contributes to increase the level of autonomy for remote rehabilitation systems thanks to the capacity of dynamically adjusting the rehabilitation process.
As future lines of research, we can stress the need to work on a main objective: evaluating the degree of improvement on stroke patients using the proposed system in a real treatment. For doing so, once the system has been validated by the research community, two clinical trials will be conducted. The first will study the impact of using the recommender system on real stroke patients over a significant period of time. The second will study the efficacy of the system on patient recovery. The data collected in these clinical trials will be used for improving the system and exploring other solutions that may be of interest to be included in it. Funding: This research was funded by Instituto de Salud Carlos III grant number DTS18/00122, co-funded by the European Regional Development Fund, European Social Fund "Investing in your future".
Informed Consent Statement: Informed consent was obtained from all subjects involved in the study.

Conflicts of Interest:
The authors declare no conflict of interest.