Real-time control systems: feedback, scheduling and robustness

ABSTRACT The efficient control of real-time distributed systems, where continuous components are governed through digital devices and communication networks, needs a careful examination of the constraints arising from the different involved domains inside co-design approaches. Thanks to the robustness of feedback control, both new control methodologies and slackened real-time scheduling schemes are proposed beyond the frontiers between these traditionally separated fields. A methodology to design robust aperiodic controllers is provided, where the sampling interval is considered as a control variable of the system. Promising experimental results are provided to show the feasibility and robustness of the approach.

Introduction
The design and implementation of real-time control systems distributed over networks need to combine methodologies and technologies from the domains of control, computing and networking. Effective control methodologies, based on the feedback paradigm, must be further designed and implemented to cope with the fast evolution of the underlying technologies (Murray, Aström, Boyd, Brockett, & Stein, 2003).
Feedback control systems are deployed, often silently, over various fields of industry and services. For example, they are used in the control of automotive systems, for the coordination of swarms of mobile robots and in the redundant and distributed flight controllers embedded in modern aircraft. Networks for the production, transport and distribution of energy, water and gas are monitored by such automatic systems, just as the regulation of railway and aerial services. Sensors networks based on wireless links can be enhanced by adding some actuation and control functions to their sensing capabilities, for example in smart automated buildings (Baillieul & Antsaklis, 2007). Internet of Things now integrate various objects in large Cyber Physical Systems for which some kind of distributed control is needed, e.g. see Lee (2008), Rajkumar, Lee, Sha, and Stankovic (2010) and Khaitan and McCalley (2015) for founding references and further surveys.
For a control scientist point of view, the problem to be solved is the achievement of a control objective mixing stability, performance and reliability requirements. On the other hand, the computing and communication resources used to implement the control actions are numerical systems with limited capabilities such as computing speed and networking bandwidth (Hespanha, Naghshtabrizi, & Xu, 2007), whose consumption must be jointly studied and eventually optimised (Cao, Cheng, Chen, & Sun, 2013).
Moreover, especially in the case of embedded, mobile and autonomous systems, the energy storage and consumption are also subject to tight constraints. Jointly taking into account these CONTACT Daniel Simon daniel.simon@inria.fr various constraint may lead to a Quality of Service formulation of the control problem, able to specify an acceptable trade-off between the control performance and the resources availability. Various control approaches have been already investigated to solve this control problem. For instance, it is relevant of Model Predictive Control, whose application for embedded cyber-physical systems has been already actively explored, as reviewed in Lucia, Kögel, Zometa, Quevedo, and Findeisen (2016). Another research direction considers fuzzy models of the distributed control system to further solve control problems related to packets dropping, time delays and signal quantisation. See Qiu, Gao, and Ding (2016) for a recent survey, in which it is observed that most existing works only consider partial networked-induced phenomena to reduce the complexity of investigation.

Varying sampling approaches
The idea of using varying control intervals naturally arises when the available computing power devoted to feedback control is limited, e.g. in embedded systems. It is obvious that decreasing the control frequency directly decreases the amount of calculation cycles needed for control. In that case, a feedback scheduler is assumed to compute on-line new control intervals according to the Central Processing Unit (CPU) load and system's state. Different control approaches have been considered to design varying sampling controllers, e.g. see Cloosterman et al. (2010) for a survey. Among others, in Hu and Michel (2000), a stability analysis of the effect of varying sampling is provided for nonlinear systems, and in Olm, Ramos, and Costa-Castelló (2011) an H Ý approach is used to conclude on the allowed sampling intervals that keep stability of a digital repetitive control scheme. In Cuenca, Garcia Gil, Arzén, and Albertos (2009), stability analysis of a controlled system under non-uniform sampling is realised with a predictor/observer structure. A Takagi-Sugeno fuzzy modelling approach is considered in Yoneyama (2010) to design state feedback controllers with varying sampling interval. A gridding approach is used in Sala (2005) to design a discrete-time controller and observer with variable sampling. More recently, in Fiter, Hetel, Perruquetti, and Richard (2015), a robust stability framework for Linear Time Invariant (LTI) systems with varying sampling is provided, thanks to a Lyapunov-Razumikhin stability conditions approach, and can be extended to event-triggered control, self-triggered control and statedependent sampling. Finally, Hetel et al. (2017) review recent results about the stability of systems under aperiodic sampling.

Slacken scheduling approaches
Control systems are typical real-time applications. The execution of a control task (including data communication) must be achieved under time constraints (often given as deadline constraints) to guarantee its stability and the desired control performance. Control systems are often cited in the real-time literature as cases of 'hard real-time systems' where deadline violations are considered as fatal faults, e.g. Buttazzo (2011). To deal with, the real-time community usually considers simplified assumptions, control tasks with fixed periods, hard deadlines and known worst-case execution times (WCET). These 'hard' assumptions lead to the separation of concerns between control and scheduling. However, as they do not take into account the robustness properties of feedback control systems, they also lead to over-constrained specifications and to under use the execution resources.
Robustness in control traditionally only considers the plant's parameter uncertainties. For simple SingleInput/SingleOutput (SISO) continuous systems, it leads to design the system with phase, gain and delay margins, and the control algorithm computation time is often neglected at design time. Indeed, the computation-induced delay does not compromise the closedloop stability as far as it is smaller than the delay margin of the controller. Hence, the closed-loop system is not only robust with respect to the plant parameters uncertainties, it is also robust with respect to unmodelled loop delays. A jitter margin also exists, as revealed in Cervin, Lincoln, Eker,Årzén, and Buttazzo (2004), and robustness considering timing deviations from the ideal delay-less and perfectly periodic case can be also observed for more general multi-variable systems as in, e.g. Andrianiaina, Seuret, and Simon, 2011.

Joint control and scheduling
Therefore, the traditional assumption considering control systems as 'hard real-time' does not hold longer for feedback control systems. Conversely, they must be considered as weakly hard real-time system, as defined in Bernat, Burns, and Llamosí (2001). It means that they are able to tolerate specified deviations from the ideal scheduling scheme while keeping their stability and specified performance level. Therefore, new degrees of freedom in the overall control system design can be used by jointly considering robust control and execution resources.
First, the execution platform (CPUs, tasks and fieldbus) can be designed using slackened scheduling parameters (i.e. with specified clock variations and sample loss rates), allowing for using off-the-shelf hardware and software components for a cheaper implementation of the system. Second, the robustness and adaptiveness properties of feedback control can be exploited to design new control algorithms freed from perfect equidistant sampling. Therefore, varying sampling or event-based control represents new tools to control the execution resources consumption. Finally, computing devices such as real-time schedulers are also likely to be controlled by feedback laws, as used in the founding paper (Eker, Hagander, & Arzen, 2000) where a feedback scheduler computes on-the-fly the control intervals of concurrent Linear Quadratic (LQ) controllers. However, approaches gathering real-time scheduling and feedback control considerations are still quite rare. Let us, for example, cite Blind and Allgöwer (2015) for the analysis of closed-loop stability under weakly hard scheduling constraints.

Problem formulation
Among other approaches, this paper aims at consistently collecting and extending some results of the authors, in particular those previously presented in Robert, Sename, and Simon (2006), Robert, Sename, and Simon (2010), Andrianiaina, Simon, Seuret, Crayssac, and Laperche (2011), Roche, Sename, and Simon (2012). Indeed, the approach focuses on the robustness of feedback loops with respect to variations of the sampling rate. It is assumed that the values of the control intervals are managed by a real-time scheduler which jointly runs with the controllers to share and manage the execution resources.
The design of effective real-time controllers for distributed and/or embedded systems can be stated as 'control design under execution resources constraints' , for which co-design methodologies gathering, at design time, the constraints arising from control, computing and networking, are needed.
A controlled process is classically a physical device whose dynamics changes along a continuous time scale. Its dynamics is usually described by some kind of differential equation, for example using a state space model: where x, y and u are vectors of continuous variables representing the state, the output and the control inputs of the plant, respectively. The functions f and g are non-linear functions, usually assumed to satisfy locally Lipschitz conditions. The objective is to design a control law u which guarantees the performances of the closed-loop system shown in Figure 1. The control algorithms can be designed in continuous time, then the controller is discretised assuming that the sampling rate is fast enough considering the desired closed-loop dynamics. It can be also directly synthesised in discrete time, using a model of the plant sampled by a zero-order holder and a periodic clock. A control theory for linear systems sampled at fixed rates was established a long time ago, e.g.Åström and Wittenmark (1997), Chen and Francis (1995). However, in the context of distributed control systems, more complex assumptions are needed to consider that the control loop is implemented using a digital system where data are exchanged over networks. To ensure the performances of the control system, it is necessary to handle these phenomena from both the automatic control and the computer science viewpoints.

. Outline
The paper is organised as follows: the next section formalises the problem of control under execution resources constraints, and recalls the basic timing schemes used in real-time control. Section 2.2 proposes some slackened real-time scheduling scenarii compliant with the robustness of feedback control. Then, Section 3 provides a methodology to design varying sampling controllers using the sampling interval as a control parameter. A preliminary analysis of the robustness of such controllers is attempted in Section 3.4, and a study case of varying sampling control of an inverted pendulum is given in Section 4.

Scheduling for control
Beyond the usual separation of concern between control and computing, the design of control-aware real-time systems needs to examine scheduling schemes with both control requirements and implementation feasibility in mind, as done for some scheduling scenarii in the next sections.

Timing parameters assignment
For computer-controlled systems, the control objective is achieved by a feedback control law u which cyclically computes the control inputs u(t k ) at some instants t k where 0 = t 0 < t 1 < t 2 .... and such that t k tends to infinity as k tends to infinity. The control input depends on the tracking error signal e(t k ) = y d (t k ) − y(t k ) between the desired reference and the plant output ( Figure 1).
Samplings and delays introduce distortions with respect to the original continuous time framework, especially when limited computing resources induce long calculations and variations in the sampling intervals. Anyway the control objectives, i.e. stability and specified performance, must be achieved despite the imperfections of the execution resources such as limited bandwidth and varying computation times (note that quantisation-related problems are out of scope for the presented approach).
In large control systems, concurrent controllers are more and more executed as concurrent tasks under control of a realtime operating system (RTOS). Besides static scheduling used in highly critical system such as aircraft control, many off-theshelf RTOS make use of fixed-priority and allow preemption between concurrent tasks. The performance of a given control law highly rely on the value of the sampling interval and of the loop latency, i.e. the delay between a measurement instant on a sensor and the instant at which the related control signal is applied to the actuator (Åström & Wittenmark, 1997). Hence, the control law behaviour depends on the scheduling parameters of the real-time system, which must be designed so that the resulting actual sampling rates and latencies are compliant with the control design assumptions.
Even choosing a right value for the sampling rate of a control law is not so simple, while being decisive for the control performance. There are some rules to be applied for linear systems. Shannon's theorem gives a lower limit for the sampling rate and rules of thumb may give a first approach to select an effective control interval. For example, Åström and Wittenmark (1997) recommends that ω c h 0.15 …0.5, where ω c is the desired closed-loop pulsation and h is the sampling period. This is only a preliminary setting and the sampling rate selection needs further simulations and tests, especially for non-linear systems. Anyway, for centralised systems without communication links, it is often observed that higher the sampling rate and lower the latency, better is the control performance.
However, the execution resources used to implement a control system are limited and cannot accommodate arbitrarily high sampling rates. Hence, the scheduling parameters are the result of a trade-off between the control performance and the execution resource capabilities. This is especially true for control systems distributed over networks where the communication links are subject to saturation in case of fast sampling. The chart in Figure 2(a) -taken from Moyne and Tilbury (2007) -shows the importance of selecting a right sampling rate to provide a satisfactory trade-off between the control performance and both the computing and networking loads.

Control aware scheduling
Implementation features such as multi-rate sampling, preemption, synchronisation and various sources of delays make the run-time behaviour of the controller very difficult to accurately predict. Even for the case of control tasks running in isolation inside static slots, a source of indeterminacy comes from the task's execution time which randomly varies between a best and a worst case as in Figure 2(b) taken from Hansen, Hissam, and Moreno (2009).
Assuming static scheduling, where fixed size slots are allocated to tasks on a shared CPU, several scheduling schemes are analysed with control constraints in mind.

... Clock driven periodic, hard real-time
This first scheduling scheme of a control task fits with the common assumption of perfectly periodic execution and known WCET, as depicted by Figure 3(a).
A periodic time slot T slot = WCET is reserved for the task execution. It is triggered with a period s k − s k − 1 = h, ∀k ∈ N and s 0 = 0, by an equidistant clock providing measurements x(s k ) at time s k . The controller computation takes duration T ex which is by definition smaller than the WCET. The control signal is applied and holds to the actuators at the end of the slot to avoid jitter, i.e. at time s k + WCET: Therefore, it is a periodic control system, with constant period h, subject to a constant delay T slot = WCET.
This setting complies with the hard real-time assumption, and should be applied when the controller is not robust against sampling disturbances or if it is not allowed to deviate from the perfect periodic scheme by regulations. As deadline miss is considered as fatal failures, the WCET must be very carefully evaluated and, in practice, safety margins are given using overestimates.
Anyway, as the time slots are assigned based on the WCET of the control tasks, their computation always terminates before the end of the slot and a fraction of the slot is unused. The wasted computing power is even more large when the WCET is by far larger than the average value of the observed execution time T ex . Indeed, it is the case for modern CPUs using hardware acceleration such as caches and pipelines, leading to very large ratio WCET/BCET (Best Case Execution Time).

... Weakly hard real-time schemes
To improve the average utilisation ratio of the execution resources in embedded controllers, it is proposed to slacken the usual hard real-time constraints. The number of wasted computing cycles can be decreased by allocating computing slots smaller than the WCET at the cost of occasional data loss. It is argued that a robust feedback controller is able to keep its stability despite timing disturbances, and that the scheduling and control parameters can be jointly tuned to reach an acceptable trade-off between the control performance and the computing average efficiency. Indeed, most control tasks computation are likely to finish on time, and sporadic data loss must be processed by various overrun handlers, e.g. as in Cervin (2005), with related consequences both for control performance and for implementation feasibility.
In the following cases, a time slot T slot < WCET is allocated to the control task. The initial clock h of incoming sensory data keeps its original constant value, and the control signal is sent to the actuators at the end of the slots to nullify the calculation induced jitter.
In case of deadline misses referring to Figure 3(b), the execution of the running control task is Aborted, the current control signal is hold and a new computation is started with the freshly available sensory data at the next allocated slot. The control signal u(x(s k )) is hold for one extra period so that the deadline miss occur at time s k + T slot : and for N consecutive deadline misses and data loss: Consequently, the control input becomes asynchronous since the difference between two control signal updates is timevarying (but bounded by h and Nh). From the implementation side, it is needed to abort the control task at arbitrary points and restart it with the right values of its internal registers : this can be difficult in particular if dynamic controllers or recursive filters are involved in the computation.
Besides this basic resource allocation scheme, others scheduling strategies can be associated with various overrun handlers . For example, it is possible to Skip the next clock tick and allow the task to terminate during the next slot. With Asap, the control signal is sent to the actuators as soon as possible , i.e. when the computation ends, to minimise the average input/output latency at the cost of output jitter. In this case, it is expected -e.g. Buttazzo and Cervin (2007) -that the disturbance due to the output jitter is compensated by the average lowered value of the loop latency to finally increase the control performance. Some Spare slots can be reserved for handling overruns. Also, rather than keeping the original value of the input interval, the triggering interval can be Stripped, so that the control performance is expected to improve from both the latency and sampling interval diminution.
The main features of these scheduling schemes and overrun handlers are summarised in Table 1. They can be combined according to the features of various case studies, coming from both the plant dynamics, parameters uncertainties and implementation feasibility considerations.
Obviously, the stability of a feedback controller subject to weakly hard real-time constraints must be proven. For example, based on recent advances in control -using Lyapunov-Krasovskii functionals and Linear Matrix Inequalities (LMIs) systems solvers -it has been proven that even an aircraft flight control system can keep its stability despite a quite large amount of samples loss in the feedback control loops, allowing for a substantial lightening of the computing equipment .

LPV robust control and varying sampling
Conversely with the previous section, where fixed scheduling parameters were set to execute a given controller with a computing resource, it is now examined how these timing parameters can be adapted on-the-fly to cope with varying conditions. Linear Parameter Varying (LPV) representations are increasingly used to deal with robust control of non-linear systems. In particular, this allows to represent some non-linearities as varying parameters, and also to schedule a controller according to some performance criteria, e.g. Shirazi, Mohammadpour Velni, and Grigoriadis (2011). The authors have proposed (among others, e.g. Hetel, Daafouz, & Iung, 2006) LPV models of digital control systems with varying sampling, under the assumption that the system representation is affine with respect to the sampling interval (Robert et al., 2006).

Discrete-time model with varying sampling interval
This subsection briefly describes the considered model, following the methodology in Robert et al. (2010). A state space representation of a continuous time plant is considered as The exact discretisation of this system with a zero-order hold at the sampling period h can be computed (Åström & Wittenmark, 1997), leading to the discrete-time LPV system (3) Then we write: The previous equation gives the exact sampling-dependent model of a continuous-time state space representation. In the framework of the H Ý approach, a discrete-time, sampling interval dependent, augmented plant is obtained from the continuous time plant and from weighting functions.
In previous works of the authors, two different methodologies have been provided for sampling interval dependent control design, the first one based on Polytopic models (Robert et al., 2010) and the second one using the Linear Fractional Representation approach (Roche et al., 2012). Only the first approach is briefly described below.

The polytopic approach
As seen before, A δ and B δ involve exponential matrices of the original A and B matrices that are not affine on δ. To get a polytopic model, a Taylor series of order T is used to approximate the matrix exponential in Equation (5), and allows to get: This leads to Let us define H = [δ, δ 2 , . . . , δ T ] the vector of parameters, that belongs to a polytope H with 2 T vertices.
Combined with weighting functions, the polytopic model is recast into a polytopic generalised plant, further used to design self-scheduled controllers. This self-scheduled controller is given by the convex combination of 2 T 'vertex' controllers, where T (i.e. the order of the Taylor expansion) tunes a trade-off between the approximation precision and the controller complexity.
Another way to reduce the controller complexity considers the case where the sampling interval is the only varying parameter in the model. In this case, thanks to the dependency between the successive powers of the sampling interval h, h 2 , ..., h T , the number of elementary vertex controllers to be combined can be reduced from 2 T down to T + 1. Moreover, solving the control synthesis with a smaller set of polytopic parameters drastically decreases the conservatism of the method and makes the solution easier to implement (see Robert et al., 2010 for details).

LPV sampling-dependent control design ... Performance specification
Using the H Ý framework, the general control scheme of Figure 4 is considered, where W i and W o are weighting functions specifying the closed-loop performance (Skogestad & Postlethwaite, 2005). The objective is to synthesise a controller K that ensures internal stability and z 2 < γ w 2 , where γ is the H Ý level performance (actually the L 2 induced gain). It is well known that the achievable performance of a feedback control systems depends on the sampling frequency. Conversely with classical robust controllers where the closed-loop objectives are statically defined by LTI weighting functions, the closed-loop performance objectives are here adapted to account for the sampling interval variations. This is done using 'sampling-dependent' weighting functions. It is enough to use only a single weighting function, W e , acting on the tracking error, to allow for the performance adaptation with respect to the current sampling interval, as explained in Robert et al. (2010).

... LPV/H Ý polytopic control design
When the reduced polytope is considered, (T + 1) controllers are synthesised at the vertex of the parameter polytope (corresponding with the extreme values of the parameters). The gainscheduled controller K(H) is then the convex combination of these controllers where A K i , B K i , C K i and D K i have the dimensions of the the original system (2). It can be seen as a dynamic state feedback controller: for which the on-line scheduling needs to compute α i (h) knowing h. Considering a Taylor's expansion at order T around h 0 with δ min = h min − h 0 and δ max = h max − h 0 and the case of the reduced polytope, explicit solutions are easily recursively computed as

Robustness of LPV based varying sampling
In this section, the aim is to check the robustness of the previous control law with respect to modelling and sampling uncertainties. A preliminary analysis is given here for controller (13) to take into account the computation durations. Recall that the controlled plant is governed by the following differential equation: and that the dynamic output feedback controller is given by Equation (13). Note that, conversely with the original controller (13) where the production of the control signal u k was considered as instantaneous and synchronous with the inputs y k , the new version of the controller accounts for a variable computation duration and assumes that the control signal is sent to the actuators as soon as it is computed (as in the Asap scheduling scenario of Section 2.2.2). It is worth noting that this system evolves in continuoustime while the dynamic output feedback controller is computed in discrete time. This particular interaction between the continuous-and discrete-time systems needs a particular attention when analysing stability and more particularly robustness. In particular, it is well known that the stability analysis of this class of systems is difficult to extend in the case of model uncertainties. The difficulty lies in finding a model of the discretised systems (3) when the continuous-time model is not perfectly known.
However, it is possible to analyse this class of system using an alternative approach which consists of first rewriting the closedloop systems as an impulsive systems, e.g. Bainov and Simeonov (2001) and Briat and Seuret (2012).
To guarantee stability, the theorem taken from Briat and Seuret (2012) has been tested. The main motivation for choosing this stability conditions are expressed in terms of Sum of Squares which allows to take into account the particular structure of the scheduled control law.
However, preliminary tests of the method show that the computation time is prohibitive, even with a very small size toy example. As the number of LMIs to be solved increases very fast with the size of the system, it is not usable even for the moderate size system studied in the next section. It is expected that effective solutions can be provided by other approaches, e.g. based on weakly hard real-time considerations as suggested by Blind and Allgöwer (2015) for the case of switched systems. Other modelling paradigms may be also investigated, e.g. as in Qiu, Wei, and Karimi (2015) where time delays are handled inside hybrid systems modelled by Markov jump systems.

Test case
The polytopic approach of Section 3.3.2 was implemented and tested using an under-actuated 'T' inverted pendulum (Educational Control Products model 505), as detailed in Robert et al. (2010). The objective here is to show the stability of the closed-loop system subject to specified sampling variations, and to show the feasibility of the approach using off-the-shelf realtime systems and tools.

Real-time set-up and experiments
The controller is synthesised for sampling rates varying in the interval [10 −3 , 3.10 −3 ] s. The 1-3 sampling rate ratio is chosen as it fits with the frequency scaling capabilities of the chips used in many current laptops, thus enabling the controller to fully use the hardware capabilities. Note that, even if it seems to be very fast with respect to the desired bandwidth, previous experiments show that this particular open-loop unstable and underactuated system needs fast sampling to be stabilised, whatever the control algorithm.
The controller is synthesised using a reduced polytope model and a Taylor's expansion truncated at the order 2. Hence, three vertex controllers only are combined for every new value of the control interval. The controller is implemented using the Realtime Workshop and xPC Target, using the output of the robust synthesis toolbox provided by Matlab/Simulink.
In Figure 5, the pendulum angle tracks a step reference while the sampling rate is subject to step changes, as seen at the bottom of Figure 5.
As expected from the sampling-dependent performance objectives defined in Section 3.3.1, the settling time is small when the control interval is large, and conversely. Note that, even if the sampling interval is subject to abrupt changes, the control signal keeps values smaller than the actuator saturation ( Figure 5 middle, where the spikes in the control signal are due to friction and elasticity in the actuator's drive). According to Equation (14), the computation of the polytopic coordinates reduces here to the simple explicit solutions (with δ min = 0): The controller reconstruction given by Equation (11) involves 3 vertex controllers whose size is the one of the state vector of the plant, i.e. it involves a linear combination of 4 × 4 matrices. Moreover, the controller updates only occur when the value of the control interval changes. Hence, in the case of sporadic step changes, the on-line overhead of the method is negligible compared with the cost of a classical H Ý controller. Even in the case of continuously varying sampling, the computation of the new gains only involves the simple algebraic computations given by Equation (14) at each sample. Finally, note that this kind of varying sampling controller can be easily implemented using the basic features shared by almost all RTOS, i.e. programmable clocks and real-time tasks.

Further testings in simulation
The only assumption made about the sampling rate during control synthesis is that the control interval lies inside predefined bounds [h min ; h max ]. The interval can be changed at any speed, between any admissible values at any instant, ensuring both the system stability and the specified performance ( Figure 6(i)). Conversely, a naive solution uses a bank of periodic LTI controllers, each of them synthesised for a given sampling interval.
In that case, it is necessary to store the internal state and matrices of all the controllers of the bank and to carefully initialise them to avoid stability problems at switching time. However, as seen in Figure 6(ii), the performances are in that case not satisfactory compared with the LPV controller. Even if some comparison with other control methods could also make sense, the results in Figure 6 emphasises that the LPV approach is an interesting tool for dealing with real-time control using varying sampling rates, while being simple enough to be implemented using off-the-shelf real-time tools. The capabilities of the polytopic controller, in particular its robustness against unmodelled delays, are now explored using simulations.

... Control under a data dropping (m,k)-firm policy
Varying sampling may origin from several sources, it can be either a control variable used to manage the execution resources, or it can be considered as a disturbance imposed by the execution environment.
r In the first case, the control interval is a control variable used to jointly manage both the control performance and the execution resources (CPU and/or fieldbus) utilisation. Besides off-line management techniques, resource sharing can be done dynamically by a feedback scheduler whose outputs are the scheduling parameters of the real-time system, in particular the control intervals of the real-time tasks and the flow of messages. The case when the control interval can take any value in the predefined interval is well suited to finely manage the CPU load in a preemptive RTOS; r In the second case, the control interval is an uncontrolled but measured parameter. However, it is assumed to lie inside predefined bounds, and can be estimated in realtime. It can be also predefined, as in the case of statically scheduled systems. For example, predefined Time Division Multiple Access scheduling of ultrasonic sensors is used in underwater applications (Roche, Sename, Simon, & Varrier, 2011). Selective data dropping under control of a (m,k)-firm scheduler allows for network overload management as in Felicioni, Jia, Simonot-Lion, and Song (2010). Note that such (m,k)-firm data dropping policy, leading to control intervals which are multiple of a base clock, is well suited for the management of the control data flow over networks because preemption cannot be used over communication links.
In the simulation plotted by Figure 7, the control interval is randomly selected with values in the set {1, 2, 3} ms. It is for example the case of sensors and control task sampled at 1 KHz, followed by a (m,k)-firm scheduler using a (1,3) dropping policy to cancel some messages sent towards the actuator. The dropping selection can be made according to some trade-off between the control quality and the network load. Here the control quality is managed through the sampling-dependent weighting functions used for the robust synthesis.
Note that it is a particular switched system (or gain scheduled system) for which the design process, using a robust H ∞ synthesis and a Lyapunov function approach, ensures the system stability for all values of the sampling interval inside the predefined bounds (and not only for a subset of discrete values between the bounds).

... Robustness with respect to unmodelled delays
Until now, it is assumed that the control signal sent by the LPV controller is not subject to delays or jitter. Indeed, delays and jitter are induced by the control tasks computation itself -due to varying calculation times -and to the preemption between the control tasks competing to gain access to the CPU. Also, in case of a distributed execution, delays are added by the fieldbus used to connect the controller and the actuator. Obviously, these added delays are uncertain and cannot be accurately known when computing the polytopic gains and vertex controllers combination.
Assuming that the output delay is bounded, a possible solution, given in Sala, Cuenca, and Salt (2009), consists in computing, at each control execution, a set of control signals corresponding to the expected delay range with some gridding step, sending all the set to the actuator and apply the particular control signal which matches the measured latency. However, this approach is paid by overloading both the CPU and fieldbus with useless computations and communications, which may themselves increase the execution-induced delays.
Indeed, as any feedback control loop, the polytopic controller is robust, to some extend, against modelling errors and unmeasured delays. Note that nothing was done in the experiments previously depicted in Figure 5 to account for the execution latencies induced by the execution and scheduling of the control law.
Additional simulations were performed to explore the robustness of the polytopic controller against unmodelled latencies. In the simulation depicted in Figure 8, the control interval was set to a constant value (2 ms) and a delay with increasing values (upto 12 ms) is inserted in the control path between the control task and the actuator. It can be observed that the control system is still stable for large values of the unmeasured delay, as unstability only appears for delays larger than 15 ms (a value surprisingly larger than the control interval). The response of the system degrades with an oscillatory behaviour while the latency increases, and the degradation seems to be monotonically increasing with the added delay in this particular case study.
Hence, the variable sampling control synthesis using the polytopic method appears to be effective to robustly stabilise the study case plant, with respect to predefined performance objective over the range of desired control intervals. Therefore, this process controller can be easily used as a building block in a Quality of Service control loop, where the higher level feedback   scheduler can be designed only with the execution resources management in mind, without worrying about the stability of the low-level control loops subject to varying sampling rates.

Summary and perspectives
The efficient design of controllers for distributed systems needs to carefully examine the constraints arising from the domain of control, real-time computing and networking, and to early integrate these constraints in the design process. Usual control systems using a hard real-time assumption lead to overconstrain the system specification and to under-use the execution resources. Understanding how feedback controllers are robust with respect to sampling deviations and data loss allows for the design of control systems where the real-time assumptions are slackened, and where the execution resources can be efficiently used while preserving the system's stability and specified performance.
The association of robust control and slackened real-time provides new degrees of freedom in the design of real-time control systems. Many industrial applications are concerned with similar requirements of real-time control such as robotics, automotive and aerospace industries. Several such applications for aircraft control , mechanical devices (Robert et al., 2010) and underwater robotics (Roche et al., 2011) are referenced in the paper.
Anyway research efforts are still needed to efficiently integrate the constraints arising from the control and computing domains in a system wide Quality of Service viewpoint. In particular, beyond the simulation case study, the robustness of control loops using the variable sampling rate as a control parameter of the system deserves to be further investigated. It has been already noticed, in Section 2.2.2 and citations herein, that the robustness of a feedback loop is concurrently shared between robustness with respect to uncertainties of the plant parameters and robustness considering unmodelled loop delays. Handling both the plant parameters and the sampling interval as uncertain parameters of an LPV model has been already done for specific case studies, e.g. in Roche et al. (2012) using Linear Fractional Transforms, the approach deserves to be generalised.
Adding unknown bounded time delays in such models, as sketched in Section 3.4, remains to be done. Possible research directions include extended models of the hybrid control system as, e.g. Markov jump systems (Qiu et al., 2015). Another promising way is the translation of the weakly hard scheduling constraints (gathering aperiodic sampling and time delays) into stability conditions as done in Blind and Allgöwer (2015) to model the data loss process in a control loop.
Finally, the real-time scheduler itself may induce other sporadic events that could disturb the control application. Such problems may also lead to research studies integrating stochastic models of the real-time environment.

Disclosure statement
No potential conflict of interest was reported by the authors.


extfieldsofstudy:
Mathematics
Computer Science

text:
Novel similarity measure for interval-valued data based on overlapping ratio

In computing the similarity of intervals, current similarity measures such as the commonly used Jaccard and Dice measures are at times not sensitive to changes in the width of intervals, producing equal similarities for substantially different pairs of intervals. To address this, we propose a new similarity measure that uses a bi-directional approach to determine interval similarity. For each direction, the overlapping ratio of the given interval in a pair with the other interval is used as a measure of uni-directional similarity. We show that the proposed measure satisfies all common properties of a similarity measure, while also being invariant in respect to multiplication of the interval endpoints and exhibiting linear growth in respect to linearly increasing overlap. Further, we compare the behavior of the proposed measure with the highly popular Jaccard and Dice similarity measures, highlighting that the proposed approach is more sensitive to changes in interval widths. Finally, we show that the proposed similarity is bounded by the Jaccard and the Dice similarity, thus providing a reliable alternative.

I. INTRODUCTION
Similarity measures are widely utilized in a range of applications including decision making, data aggregation, approximate reasoning, and machine learning. Measuring the similarity between two objects captures the degree to which they are alike. Similarities are commonly expressed as nonnegative real numbers, often between 0 (completely dissimilar) and 1 (identical) for simplicity. Similarity is typically assumed to be symmetrical; however, for certain stimuli, similarity may be better modeled by uni-directional or asymmetric functions [1]. Various similarity measures have been introduced in the literature to assess the likeness of data structures including numerals, intervals, and crisp and fuzzy sets. As individual similarity measures have their respective strengths and weaknesses, the selection of the most appropriate measure is widely considered to be application dependent.
Recently, interval-valued data and associated intervalsimilarity have gained much interest as they enable the efficient representation of imprecise and uncertain information [2]. Thus, intervals have been used in many applications, including the modeling of survey data [3], the clustering of symbolic data [4], and the capturing of natural language expressions [2].
For comparing intervals in terms of their similarity, the Jaccard [5] and Dice [6] similarity measures are the most commonly used. Both of these measures provide a symmetrical Pairs of intervals similarity which increases gradually from minimum similarity (0) to maximum similarity (1) in respect to increasing intersection between the intervals. Nevertheless, they are often subject to aliasing, i.e., they yield the same similarity for very different interval pairs. Fig. 1 shows an example of two interval pairs for which the Jaccard and the Dice similarity measures give the same similarity of 0.33 and 0.50 respectively-though intuitively, this is unexpected. Another way of viewing the example is that the measures, in effect, are sometimes not sensitive to (changes in) the relative width of the intervals, being instead driven by the size of their intersection and union. It is reasonable to consider that as the width of an interval varies, the similarity varies as well. Therefore, we propose a new similarity measure for pairs of intervals that focuses on the following similarity features: • sensitivity to changes in the width of the intervals; • sensitivity to the size of the intersection when one interval is a subset of another.
The proposed similarity measure uses the reciprocal overlapping ratios of the intervals to compute their asymmetric similarities which in turn are used to establish an overall symmetrical similarity, bounded by [0,1]. We compare the behavior of the new measure with the Jaccard and the Dice similarity measures using synthetic interval datasets. Along with the standard properties of similarity measures, we explore the properties of invariance and linearity for all three similarity measures. The paper is structured as follows. Section II briefly reviews the Jaccard and the Dice similarity measures. Section III introduces the proposed similarity measure based on the overlapping ratio of intervals and discusses its properties. We demonstrate the behavior of the proposed similarity measure in comparison to both Jaccard and Dice in Section IV. Lastly, Section V concludes the paper and provides suggestions for future work.

II. BACKGROUND
We now briefly review the concept of similarity measures as well as the specific similarity measures of Dice and Jaccard, the two commonly applied measures in the literature.

A. Similarity Measures
A similarity measure S(A, B) → [0, 1] is a real-valued function that determines the similarity between two objects A and B. Generally, the similarity between two objects is bounded by 0 and 1, where 0 means that both objects are completely different and 1 means that they are identical. The four common properties of a similarity measure for sets A, B and C are as follows [7]:

B. Jaccard Similarity Measure
The Jaccard similarity measure [5] is one of the most widely used similarity measures. It satisfies all of the above properties of a similarity measure [7]. Generally, the Jaccard similarity of two sets is defined as the ratio of the cardinality of their intersection and the cardinality of their union, Using the crisp set difference operation [8], (1) can be written as where A\B is the set of items that are in A but not in B and B\A is the set of items that are in B but not in A. Note that this alternative form of the Jaccard similarity measure at (2) is relevant for showing its relationship with the Dice and our proposed similarity measures, detailed in Section III. Beyond crisp sets, the Jaccard similarity measure is used to estimate the similarity for intervals or sets of intervals [9], [10]. A closed intervalĪ i is a set of real numbers characterized by two endpoints For comparing the intervals I i andĪ j , the Jaccard similarity measure is expressed as where |Ī i ∩Ī j | is the size of the intersection betweenĪ i and I j and |Ī i ∪Ī j | is the size of the entire interval segment(s) covering bothĪ i andĪ j . Hence, S J (Ī i ,Ī j ) = 1 whenĪ i andĪ j are completely overlapping and 0 when they are not overlapping at all. Similar to (2), we can rewrite (3) as where |Ī i \Ī j | is the size of the interval segment ofĪ i that is not overlapping withĪ j and |Ī j \Ī i | is the size of the interval segment ofĪ j that is not overlapping withĪ i . Along with crisp sets and intervals, many use the Jaccard similarity measure for assessing the similarity between type-1 sets [11]. A fuzzy set [12] is defined as a set where the set's elements have membership ranging between 0 and 1. Formally, a type-1 fuzzy set F in the universe of discourse X is written as [13] F is the membership grade of the element x in F . For two type-1 fuzzy sets F 1 and F 2 , the Jaccard similarity can be written as [14] S where µ F1 (x i ) and µ F2 (x i ) are the membership grades of x i in F 1 and F 2 respectively. Equation (6) yields a value of 1 when the fuzzy sets are identical and 0 when they are completely disjoint. Note that the Jaccard similarity measure has been extended for interval type-2 [15], [16] and general type-2 fuzzy sets [17]; though, this is not discussed here.

C. Dice Similarity Measure
The Dice similarity measure [6] is closely related to Jaccard and is also a popular similarity measure. It considers the ratio of the size of the intersection of two sets and the average of their cardinality/size. Like the Jaccard similarity, it produces outputs in [0, 1]. Specifically, for two crisp sets A and B, the Dice similarity is expressed as where |A| is the size of the set A. We can rewrite (7) by applying the crisp set difference operation [8] Note that the alternative expressions of Jaccard (2) and Dice (8) show clearly that the averaging operation in the denominator of (8) results in the Dice similarity always being equal (when sets are identical) to or larger than the Jaccard similarity. We expand on this in Section III.
In [9], [10], the Dice similarity is used along with the Jaccard similarity for interval-valued evidence. By following (4), the Dice similarity for two intervalsĪ i andĪ j can be expressed as While less frequently used for fuzzy sets than Jaccard, the Dice similarity measure was used in [18], [19] for trapezoidal fuzzy numbers in the context of solving multicriteria decisionmaking problems.
III. OVERLAPPING RATIO BASED SIMILARITY MEASURE In this section, we introduce a new similarity measure for intervals based on their overlapping ratio. The proposed measure estimates the overall similarity of a pair of intervals by considering the reciprocal similarity of each of the intervals within the pair. We first define the concept of the overlapping ratio for a pair of intervals and, later, present the new proposed similarity measure and discuss its essential properties.
A. Overlapping Ratio of Intervals Definition 1. The overlapping ratio (OR) of a given interval I i within an interval pair {Ī i ,Ī j } captures the ratio of the size of the intersection of the pair and the size of the given interval. The OR is defined as where |Ī i ∩Ī j | is the size of the intersection betweenĪ i and I j and |Ī i | is the size ofĪ i . Note that for any intervalĪ i with a size of 0, i.e., |Ī i | = 0, OR(Ī i ,Ī j ) is set to 0.
From (10), it is clear that the overlapping ratio for an interval in a pair will fall under one of the following cases:

B. Similarity Measure Based on the Overlapping Ratio
As noted, the motivation behind proposing a new similarity measure is to capture the potentially (very) different width of both intervals in the similarity calculation. Thus, the proposed overlapping ratio based similarity measure S OR , defined next, takes into consideration the reciprocal similarity of both intervals within a pair in order to estimate their overall similarity. Definition 2. The overlapping ratio based similarity measure S OR for a pair of intervals,Ī i andĪ j , is the t-norm of their reciprocal overlapping ratios, defined as where is a t-norm.
In this paper, we use the minimum t-norm for throughout. We will discuss the product t-norm in future work.
Similar to (4) and (9), we can rewrite (11) as where |Ī i \Ī j | is the size of the non-overlapping segment of the intervalĪ i with respect to the intervalĪ j and vice-versa for |Ī j \Ī i |.
Note that a distance measure D OR (Ī i ,Ī j ) can easily be derived from the S OR similarity measure (11) by taking its complement-i.e., 1 − S OR (Ī i ,Ī j ) -thus capturing the dissimilarity between both intervals. We discuss this distance measure in more detail, including proving that it is a metric, in future work.

C. Properties of the Proposed Similarity Measure
This section explores the properties of the proposed overlapping ratio similarity measure S OR (Ī i ,Ī j ).
AsĪ j ⊆Ī k , it follows that |Ī j | ≤ |Ī k |. Therefore, |Īi| |Īj | ≥ |Īi| Theorem 5. S OR (Ī i ,Ī j ) is bounded by the Jaccard and the Dice similarity measures when is the minimum t-norm. That is, Proof: For the interval pair {Ī i ,Ī j }, consider the formulations of the similarity measures at (4), (9), and (12). To prove this theorem, we consider four cases: Case 1: IfĪ i =Ī j , then all three measures yield a similarity of 1. That is, Case 3: IfĪ i ⊂Ī j (complete subset), then |Ī i ∩Ī j | = |Ī i |. With respect toĪ i , there is no non-overlap segment ofĪ j ; hence, |Ī i \Ī j | = 0. Inversely, there is a non-overlap segment ofĪ j in Ī i ; thus, |Ī j \Ī i | = 0. In this case, the three similarity measures can be simplified to which implies that Case 4: Considering the case w i ≤ w j , the three similarity measures can be rewritten as It is true that Note that for the case w j ≤ w i , the same procedure can be used to prove the above relation.

IV. DEMONSTRATION AND ANALYSIS
In this section, we demonstrate and analyze the behavior of the proposed S OR similarity measure by comparing its output to those of both Jaccard and Dice for a set of key synthetic examples. We specifically focus on exploring the following key aspects: • Aliasing, i.e., similarity measures producing the same output for different input intervals. • Behavior when one interval is a complete subset of another. Pairs of intervals  • Behavior for intervals of equal size and equal overlapping ratios. • Invariance to scaling/multiplication of interval endpoints. • Linearity in measure output in respect to linearly increasing interval overlap.
1) Experiment on aliasing: In Fig. 2, four different pairs of intervals {Ī i ,Ī j } are considered, where all pairs have an intersection of equal size. The similarity results for the pairs using the three similarity measures are shown in Table I. The S J and the S D measures give a similarity of 0.15 and 0.26 respectively for all pairs. Indeed, both measures provide identical similarities for pairs of intervals when the size of the union of their non-overlapping segments remains constant. On the contrary, the proposed S OR measure yields different similarity for all cases. Note, that as shown in Theorem 5 the results of the S OR measure are bounded by the similarity produced by the S J and S D measures. The reason that the S OR measure produces different results for each case is that it captures changes in the width of both input intervals which affects their reciprocal similarity and the overall similarity.
2) Experiment with interval pairs when one interval is a complete subset of the other: Five interval pairs are shown in Fig. 3, whereĪ j is a complete subset ofĪ i in all pairs and overlapping by 10%, 20%, 30%, 40%, and 50%, respectively ofĪ i . Table II presents the similarity for all pairs with all three measures. Note that for all pairs, the overlapping ratio ofĪ j is 1 while the overlapping ratio ofĪ i depends on the size ofĪ i andĪ j , i.e., |Īi∩Īj | |Īi| . Therefore, intuitively their mutual similarity can be at most |Īi∩Īj | |Īi| for each pair. The S J and the S OR measures perform accordingly while the S D measure exceeds this limit. Pairs of intervals  3) Experiment with interval pairs of equal size and equal overlapping ratio: In Fig. 4, five interval pairs are shown, where the intervals are of equal size and their intersection is varied to be 10%, 20%, 30%, 40%, and 50% of their size. Table III provides the results for all pairs using the three similarity measures. In all pairs, the overlapping ratio is equal, and it is intuitive to expect the similarity to be the extent of this overlapping ratio. In this case, the S D and the S OR measures satisfy the expectation whereas the S J measure yields lower similarity.
4) Experiment on invariance: Five pairs of intervals are shown in Fig. 5 where both endpoints of I i1 and I j1 are gradually multiplied by a factor, n = {2, 3, 4, 5} to produce new interval pairs. Yet, the overlapping ratio is maintained for individual intervals in all the pairs. Adapting the definition from [21], a similarity measure is invariant if its similarity output remains constant regardless of multiplying the endpoints of interval pairs by a factor. Table IV shows the similarity for all pairs using the three measures where n refers to the factor applied to the interval endpoints. The results shows that all three measures satisfy the invariance property for the given pairs of intervals.

5) Experiment on linearity:
Adapting the definition from [21], a similarity measure on intervals is linear if its similarity output varies linearly in respect to a linear change in the size of the intersection of the intervals. In Fig. 6(a), the intersection between two intervals of equal size is gradually increased in 10% steps. The corresponding similarity outputs for the pairs and all three measures are shown graphically in Fig. 6 Pairs of intervals  Pairs of intervals  while the S J measure exhibits convexity (differences rise with the increase of intersection).

V. CONCLUSION AND FUTURE WORK
In this paper, we have introduced a new similarity measure that considers the reciprocal similarity of a pair of intervals in computing their overall similarity. We have used the overlapping ratio of the intervals within the pair for capturing the asymmetric similarity. We have also demonstrated that the new measure satisfies essential properties of a similarity measure. Lastly, we have compared the behavior of the proposed measure with the two popular Jaccard and Dice similarity measures using synthetic datasets. The results have shown that the proposed similarity measure is more sensitive to the changes in the width of intervals, and further it is invariant and linear. We have also proved that the proposed similarity is bounded by the Jaccard and the Dice similarity.
In future, we will use the proposed similarity measure for capturing the mutual agreement of interval-valued evidence for aggregation. As each α-cut of a normal and convex fuzzy set is a closed interval [22], we aim to extend the proposed similarity measure for comparing fuzzy sets.

ACKNOWLEDGMENT
Shaily Kabir acknowledges the financial support of the Commonwealth Scholarship Commission in the UK.


Depression and Self-Harm Risk Assessment in Online Forums

Users suffering from mental health conditions often turn to online resources for support, including specialized online support communities or general communities such as Twitter and Reddit. In this work, we present a framework for supporting and studying users in both types of communities. We propose methods for identifying posts in support communities that may indicate a risk of self-harm, and demonstrate that our approach outperforms strong previously proposed methods for identifying such posts. Self-harm is closely related to depression, which makes identifying depressed users on general forums a crucial related task. We introduce a large-scale general forum dataset consisting of users with self-reported depression diagnoses matched with control users. We show how our method can be applied to effectively identify depressed users from their use of language alone. We demonstrate that our method outperforms strong baselines on this general forum dataset.

Introduction
Mental health remains a major challenge in public health care. Depression is one of the most common mental disorders and 350 million people are estimated to suffer from depression worldwide (WHO, 2010). In 2014 an estimated 7% of all U.S. adults had experienced at least one major depressive disorder (2015). Suicide and selfharm are major related concerns in public mental health. Suicide is one of the leading causes of death (CDC, 2015), and each suicide case has major consequences on the physical and emotional * The first two authors contributed equally to this work. well-being of families and on societies in general. Therefore identifying individuals at risk of selfharm and providing support to prevent it remains an important problem (Ferrari et al., 2014).
Social media is often used by people with mental health problems to express their mental issues and seek support. This makes social media a significant resource for studying language related to depression, suicide, and self-harm, as well as understanding the authors' reasons for making such posts, and identifying individuals at risk of harm (Coppersmith et al., 2014a). Depression and suicide are closely related given that depression is the psychiatric diagnosis most commonly associated with suicide. Research has demonstrated that forums are powerful platforms for selfdisclosure and social support seeking around mental health concerns (De Choudhury and De, 2014;Manikonda and De Choudhury, 2017). Such support forums are often staffed by moderators who are mental health experts, trained volunteers, or more experienced users whose role is to identify forum posts suggesting that a user is at risk of selfharm and to provide support.
Studies have shown that self expression and social support are beneficial in improving the individual's state of the mind (Turner et al., 1983;Choudhury and Kiciman, 2017) and thus such communities and interventions are important in suicide prevention. However, there are often thousands of user posts published in such support forums daily, making it difficult to manually identify individuals at risk of self-harm. Additionally, users in acute distress need prompt attention, and any delay in responding to these users could have adverse consequences. Therefore, identifying individuals at risk of self-harm in such support forums is an important challenge. Identifying signs of depression in general social media, on the other hand, is also a difficult task that has appli-cations for both better understanding the relationship between mental health and language use and for monitoring a specific user's state (e.g., in the context of monitoring a user's response to clinical care). In this work we propose and evaluate a framework for performing self-harm risk assessment and for identifying depression in online forums.
We present a general neural network architecture for combining posts into a representation of a user's activity that is used to classify the user. To address the challenge of depression risk assessment over the general forums, we introduce a large-scale novel Reddit dataset that is substantially larger than the existing data and has a much more realistic number of control users. The dataset contains over 9,000 users with selfreported depression diagnoses matched with over 107,000 control users. We apply our approach to (1) identify the users with depression on a general forum like Reddit, and to (2) estimate the risk of self-harm indicated by posts in a more specific mental-health support forum. Our methods perform significantly better on both datasets than strong existing methods, demonstrating that our approach can be used both to identify depressed users and to estimate the risk of self-harm posed by individual posts.

Related Work
There is a growing body of related work analyzing mental health-related discourse and language usage in social media to better discover and understand mental health related concerns (Resnik et al., 2013;De Choudhury et al., 2013;Coppersmith et al., 2014b,a;Tsugawa et al., 2015;Coppersmith et al., 2015a;Althoff et al., 2016;Mowery et al., 2016;Benton et al., 2017b). To investigate NLP methods for identifying depression and PTSD users on Twitter, a shared task (Coppersmith et al., 2015b) at the 2nd Computational Linguistics and Clinical Psychology Workshop (CLPsych 2015) was introduced where the participants evaluated their methods on a dataset of about 1800 Twitter users. Other work has used data from approximately 900 Reddit.com users to support self-reported diagnosis detection (Losada and Crestani, 2016). Previous work identifying depression and other mental health problems, including the methods participating in CLPsych 2015 (e.g. (Resnik et al., 2015;Preoţiuc-Pietro et al., 2015)) heavily rely on utilizing features such as LIWC (Pennebaker et al., 2015), topic modeling, manual lexicons, or other domain-dependent application-specific features. Aside from the effort required to design effective features, these approaches usually model the problem with respect to the selected features and ignore other indicators and signals that can improve prediction. In contrast, our model only relies on text and is not dependent on any external or domain-specific features. Previous selfreported diagnosis detection datasets contained a limited number of both control users and diagnosed users. In contrast to this, we construct a new dataset with over 9,000 depressed users matched with a realistic number of control users.
In addition to general studies addressing mental health, related work has also specifically studied suicide and self-harm through social media (Jashinsky et al., 2014;Thompson et al., 2014;Gunn and Lester, 2015;De Choudhury et al., 2016;. Recently, CLPsych 2016 (Hollingshead and Ungar, 2016) investigated approaches for detecting the self-harm risk of mental health forum posts (Milne et al., 2016). Most related work in this area uses variations of linear classifiers with some sort of feature engineering; successful methods have employed: a combination of sparse (bag-of-words) and dense (doc2vec) representation of the target forum posts , a stack of featurerich Random Forest and linear Support Vector Machine (SVM) (Malmasi et al., 2016), an RBF SVM classifier utilizing similar sets of features (Brew, 2016), and various contextual and psycholinguistic features (Cohan et al., 2016(Cohan et al., , 2017. In contrast to the above works, our model does not use any general or domain specific feature engineering; it learns appropriate representations of documents by considering only their textual content. Our proposed models consist of a shared architecture based on a CNN, a merge layer, modelspecific loss functions, and an output layer (as we will describe in §4). While our model shares similarities with CNN-based models in prior work (Kalchbrenner et al., 2014;Kim, 2014;Xiao and Cho, 2016), it focuses on learning representations of user's posts and combining the post representations into an overall representation of the user's activity. In the case of self-harm risk assessment, we experiment with several loss functions to de-termine whether considering the ordinal nature of self-harm risk labels (i.e., green, amber, red, and crisis) can improve performance. Evaluation results suggest that the model variant using this loss function is more robust than our other variants.

Depression dataset construction.
We created a new dataset to support the task of identifying forum users with self-reported depression diagnoses. The Reddit Self-reported Depression Diagnosis (RSDD) dataset was created by annotating users from a publicly-available Reddit dataset 1 . Users to annotate were selected by identifying all users who made a post between January 2006 and October 2016 matching a highprecision diagnosis pattern. 2 Users with fewer than 100 posts made before their diagnosis post were discarded. Each of the remaining diagnosis posts was then viewed by three layperson annotators to decide whether the user was claiming to have been diagnosed with depression; the most common false positives included hypotheticals (e.g., "if I was diagnosed with depression"), negations (e.g., "it's not like I've been diagnosed with depression"), and quotes (e.g., "my brother announced 'I was just diagnosed with depression' "). Only users with at least two positive annotations were included in the final group of diagnosed users.
A pool of potential control users was identified by selecting only those users who had (1) never posted in a subreddit related to mental health, and (2) never used a term related to depression or mental health. These restrictions minimize the likelihood that users with depression are included in the control group. In order to prevent the diagnosed users from being easily identified by the usage of specific keywords that are never used by the control users, we removed all posts by diagnosed users that met either one of the aforementioned conditions (i.e., that was posted in a mental health subreddit or included a depression term).
For each diagnosed user and potential control user, we calculated the probability that the user would post in each subreddit (while ignoring diagnosed users' posts made to mental health subreddits). Each diagnosed user was then greedily matched with the 12 control users who had the smallest Hellinger distance between the diagnosed user's and the control user's subreddit post probability distributions, excluding control users with 10% more or fewer posts than the diagnosed user. This matching approach ensures that diagnosed users are matched with control users who are interested in similar subreddits and have similar activity levels, preventing biases based on the subreddits users are involved in or based on how active the users are on Reddit. This yielded a dataset containing 9,210 diagnosed users and 107,274 control users. On average each user in the dataset has 969 posts (median 646). The mean post length is 148 tokens (median 74).
The Reddit Self-reported Depression Diagnosis (RSDD) dataset differs from prior work creating self-reported diagnoses datasets in several ways: it is an order of magnitude larger, posts were annotated to confirm that they contained claims of a diagnosis, and a realistic number of control users were matched with each diagnosed user. The lists of terms related to mental health, subreddits related to mental health, high-precision depression diagnosis patterns, and further information are available 3 . We note that this dataset has some (inevitable) caveats: (i) the method only captures a subpopulation of depressed people (i.e. those with self-reported diagnosis), (ii) Reddit users may not be a representative sample of the population as a whole, and (iii) there is no way to verify whether the users with self-reported diagnoses are truthful.

Self-harm assessment.
For self-harm risk assessment we use data from mental health forum posts from ReachOut.com, which is a successful Australian support forum for young people. In addition to providing peersupport, ReachOut moderators and trained volunteers monitor and participate in the forum discussions. The NAACL 2016 Computational Linguistics and Clinical Psychology Workshop (Hollingshead and Ungar, 2016) released a Triage dataset containing 65,024 forum posts from ReachOut, with annotations for 1,227 posts indicating the author's risk of self-harm (Milne et al., 2016). The annotations consist of one of four labels: green (indicating no action is required from ReachOut's moderators), amber (non-urgent attention is required), red (urgent attention is required), and crisis (a risk that requires immediate attention).  Figure 1: The general neural network architecture shared among our user and post classification models. Each input (e.g., each of a user's posts) is processed by a convolutional network and merged to create a vector representation of the user's activity. This vector representation is passed through one or more dense layers followed by an output layer that performs classification. The type of input received, merge operation, and output layer vary with the specific model.

Ethical concerns.
Social media data are often sensitive, and even more so when the data are related to mental health. Privacy concerns and the risk to the individuals in the data should always be considered (Hovy and Spruit, 2016;Šuster et al., 2017;Benton et al., 2017a). We note that the risks associated with the data used in this work are minimal. This assessment is supported by previous work on the ReachOut dataset (Milne et al., 2016), on Twitter data (Coppersmith et al., 2015b), and on other Reddit data (Losada and Crestani, 2016). The RSDD dataset contains only publicly available Reddit posts. Annotators were shown only anonymized posts and agreed to make no attempts to deanonymize or contact them. The RSDD dataset will only be made available to researchers who agree to follow ethical guidelines, which include requirements not to contact or attempt to deanonymize any of the users. Additionally, for the ReachOut forum data that was explicitly related to mental health, the forum's rules require the users to stay anonymous; moderators actively redact any user identifying information.

Methodology
We describe a general neural network architecture for performing text classification over multiple input texts. We propose models based on this architecture for performing two tasks in the social media and mental health domains that we call selfharm risk classification and detecting depression.
The task of self-harm risk classification is estimating a user's current self-harm risk given the user's A convolutional layer takes a series of terms as input (a) and applies l filters to a k-term sliding window to derive feature values for each window or region (b); k = 2 and l = 3 shown here. A max pooling layer considers nonoverlapping region sequences of length n (b) and keeps the highest feature value for the sequence (c); n = 3 shown here.
post on a mental health support forum and the previous posts in the thread. The task of detecting depressions in users is identifying Reddit users with self-reported depression diagnoses given the users' post histories (excluding posts containing mental health keywords or posted in subreddits related to mental health).
While both tasks are focused on predicting a user's mental health status, they differ in both the type of classification performed (i.e., estimating severity on a four point scale vs. boolean classification) and in the amount of data available. Our general architecture is based on a two step process: (1) identifying relevant features in each input text, and (2) combining the features observed in the model's inputs to classify the user.

Shared Architecture
Our proposed models share a common architecture that takes one or more posts as input, processes the posts using a convolutional layer to identify features present in sliding windows of text, merges the features identified into a vector representation of the user's activity, and uses a series of dense layers to perform classification on the merged vector representation. The type of merging performed and the output layers are properties of the model variant, which we describe in detail in the following section. Convolutional networks have commonly been applied to the task of text classification, such as by Kim (2014). We use categorical cross-entropy as a loss function with both methods, but also experiment with other loss functions when performing severity classification. First, the model takes one or more posts as input and processes each post with a convolutional network containing a convolutional layer and a pooling layer. This process is illustrated with a max pooling layer in Figure 2. The convolutional layer applies filters to a sliding window of k terms (a) and outputs a feature value for each sliding window region and each filter (b). The same filters are applied to each window; each filter can be viewed as a feature detector and the overall process can be conceptualized as looking for windows of terms that contain specific features. The features are not specified a priori through feature engineering, but instead are learned automatically when the model is trained. After identifying the features present in each region (i.e., sliding window), a max pooling layer considers non-overlapping regions of length n and keeps the highest feature value for each region (c). This step eliminates the regions (i.e., sliding windows) that do not contain useful features, which reduces the size of the convolutional network's output. The same convolutional network is applied to each input post, meaning that the model learns to look for the same set of features in each.
After each input post has been processed by a convolutional network, the output of each convolutional network is merged to create a representation of the user's activity across all input posts. This representation is processed by one or more dense layers (i.e., fully connected layers) with dropout (Srivastava et al., 2014) before being processed by a final output layer to perform classification. The type of output layer is dependent on the model variant. Our shared model architecture is illustrated in Figure 1. The architecture's hyperparameters (e.g., the sliding window size k, the number of convolutional filters used, and type of pooling) also vary among models and are described in the supplemental material. Both the convolutional and dense layers use ReLU activations (Nair and Hinton, 2010) in all model variants.

Depression detection
Our model for depression detection takes a user's posts as input and processes each post with a convolutional network. Each convolutional network performs average pooling to produce its output. That is, the model considers non-overlapping se-quences of n posts and keeps the average feature value across all sequences. These post representations are then merged with a second convolutional layer to create a user representation; we found this approach led to more stable performance than using a second average pooling or max pooling layer. The user representation created by the merge step is then passed to one or more dense layers before being passed to a dense output layer with a softmax activation function to perform classification. The number of dense layers used is a hyperparameter described in §5. Categorical cross-entropy is used as the model's loss function.

Self-harm risk assessment
Our model for self-harm risk classification takes two inputs: the target post being classified and the prior posts (if any) in the target post's thread. The prior posts provide context and are thus useful for estimating the risk of self-harm present in the target post. The two inputs are both processed by a convolutional network as in user-level classification, but in this case the convolutional network's outputs correspond to a representation of the target post and to a representation of the target post's context (i.e., the prior posts in the thread). Given that these two outputs represent different aspects, they are merged by concatenating them together. This merged representation is then passed to one or more dense layers and to an output layer; the type of output layer depends on the loss function used. There are four self-harm risk assessment model variants in total: Categorical Cross Ent. uses an output layer with a softmax activation function, and categorical cross-entropy as its loss function. This mirrors the output layer and loss function used in the user level classification model.
MSE uses an output layer with a linear activation function, and mean squared error as its loss function. The model's output is thus a single value; to perform classification, this output value is rounded to the nearest integer in the interval [0, t − 1], where t is the number of target classes.
The final two loss functions perform metric learning rather than performing classification directly. They learn representations of a user's activity and of the four self-harm risk severity labels; classification is performed by comparing the euclidean distance between a representation of a user's activity (produced by the final layer) and each of the four severity label representations. Class Metric: Let d be the size of the output layer and X be the layer's d-dimensional output. Class Metric learns a d-dimensional representation of each class C i such that ||X − C i || 2 is minimized for the correct class i; this is accomplished with the loss function: L i,p,n = max(0, ||X i − C p || 2 − ||X i − C n || 2 + α) where C p is the correct (i.e., positive) class for X i , C n is a randomly chosen incorrect (i.e., negative) class, and α is a constant to enforce a minimum margin between classes. Classification is performed by computing the similarity between X i and each class C j .
Class Metric (Ordinal) extends Class Metric to enforce a margin between ordinal classes as a function of the distance between classes. Given a ranked list of classes such that more similar classes have closer rankings, that is ∀i sim(C i , C i±1 ) > sim(C i , C i±2 ), we incorporate the class distance into the margin such that more distant incorrect class labels must be further away from the correct class label in the metric space. The loss function becomes L i,p,n = max(0, ||X i − C p || 2 − ||X i − C n || 2 + α|p − n|) where |p − n| causes the margin to scale with the distance between classes p and n.

Experiments
In this section we describe the model hyperparameters used and present our results on the depression detection and self-harm risk assessment tasks. To facilitate reproducibility we provide our code and will provide the Reddit depression dataset to researchers who sign a data usage agreement 4 .

Experimental setup.
The hyperparameters used with our models are shown in Table 1. The severity risk assessment models' hyperparameters were chosen using 10fold cross validation on the 947 ReachOut training posts, with 15% of each fold used as validation 4 http://ir.cs.georgetown.edu/data/reddit depression/ data. The depression identification model's hyperparameters were chosen using the Reddit validation set. The depression identification model's second convolutional layer (i.e., the layer used to merge post representations) used filters of length 15, a stride of length 15, and the same number of filters as the first convolutional layer. All models were trained using stochastic gradient descent with the Adam optimizer (Kingma and Ba, 2014). The hyperparameters that varied across models are shown in Table 1. The convolution size, number of convolutional filters, pooling type, pooling length, and number of dense layers was similar across all post models. Class balancing was performed with Categorical Cross Ent. by weighting classes inversely proportional to their frequencies, whereas sampling an equal number of instances for each class worked best with the other methods.
Addressing limited data. The post classification models' input consists of skip-thought vectors (Kiros et al., 2015); each vector used is a 7200dimensional representation of a sentence. Thus, the convolutional windows used for post classification are over sentences rather than over terms. This input representation was chosen to mitigate the effects of the ReachOut dataset's relatively small size. The skip-thought vectors were generated from the the ReachOut forum dataset by sequentially splitting the posts in the training set into sentences, tokenizing them, and training skipthoughts using Kiros et al.'s implementation with the default parameters. Sentence boundary detection was performed using the Punkt sentence tokenizer (Kiss and Strunk, 2006) available in NLTK (Bird et al., 2009). These 2400-dimensional forum post skip-thought vectors were concatenated with the 4800-dimensional book corpus skip-thought vectors available from Kiros et al.. Experiments on the training set indicated that using only the ReachOut skip-thought vectors slightly decreased performance, while using only the book corpus skip-thought vectors substantially decreased performance. As input the post models received the last 20 sentences in each target post and the last 20 sentences in the thread prior to the target post; any prior sentences are ignored.

Depression detection.
The data used for depression detection was described in §3. We compare our model against several baselines using MNB and SVM classifiers (Wang and Manning, 2012). Specifically, we consider two sets of features for the classifiers. The first set of features is the post content itself represented as sparse bag of words features (BoW baselines). The second set of features (feature-rich baselines) comprises a large set of features including bag of words features encoded as sparse weighted vectors, external psycholinguistic features captured by LIWC 5 (2015), and emotion lexicon features (Staiano and Guerini, 2014). Since our problem is identifying depression among users, psycholinguistic signals and emotional attributes in the text are potentially important features for the task. These features (as described in §2) have been also previously used by successful methods in the Twitter self-reported diagnosis detection task (Coppersmith et al., 2015b). Thus, we argue that these are strong baselines for our self-reported diagnosis detection task. We apply count based and tf-idf based feature weighting for bag of words features. We perform standard preprocessing by removing stopwords and lowercasing the input text. 6 The data is split into training, validation, and testing datasets each containing approximately 3,000 diagnosed users and their matched control users. The validation set is used for tuning development and hyperparameter tuning of our models and the baselines. The reported results are on the test set. The depression detection models' input consisted of raw terms encoded as one-hot vectors. We used an input layer to learn 50-dimensional representation of the terms. For each target user, the CNN received up to 400 posts containing up to 100 terms; experiments on the validation data indicated that increasing the maximum number of  posts did not significantly improve performance.
Results. The results of identifying depressed users for our model and baselines are shown in Table 2. Our proposed model outperforms the baselines by a large margin in terms of recall and F1 on the diagnosed users (increases of 41% and 16%, respectively), but performs worse in terms of precision. As described later in the analysis section, the CNN identifies language associated with negative sentiment across a user's posts.

Self-harm risk classification.
We train our methods to label the ReachOut posts and compare them against the top methods from CLPsych '16. We use the same experimental protocol as was used in CLPsych '16; our methods were trained on the 947 training posts and evaluated on the remaining 280 testing posts. We used 15% of the 947 training posts as validation data.
We report results using the same metrics used in CLPsych, which were: the macro-averaged F1 for the amber, red, and crisis labels (nongreen posts); the macro-averaged F1 of green posts vs. amber ∪ red ∪ crisis (flagged posts); and the macro-averaged F1 of green ∪ amber vs. red∪crisis (urgent posts). The non-green F1 was used as the official CLPsych metric with the intention of placing emphasis on classification performance for the non-green categories (i.e., those that required some response). The binary flagged meta-class was chosen to measure models' abilities to differentiate between posts that require attention and posts that do not, and the binary urgent meta-class was chosen to measure their abilities to differentiate between posts that require quick responses and posts that do not. In addition to macro-averaged F1, CLPsych also reported the accuracy for each category. We additionally report F1 macro-averaged over all classes.

Method
Non-green Flagged Urgent All F1 F1 Acc. F1 Acc. F1 Acc. Baseline (Milne et al., 2016) 0   Results. The results on the self-harm risk assessment task for our models and for the current best-performing methods (briefly explained in §2) are shown in Table 3. We also report a baseline result which is based on a SVM classifier with bigram features. When measured by non-green F1, the official metric of the CLPsych '16 Triage Task, our proposed models perform up to 19% better than the best existing methods. Similarly, our models perform up to 11% better when measured with an F1 macro-averaged across all categories (i.e., all column) and up to 5% better with measured accuracy across all categories. Categorical Cross Ent. performs best in all of these cases, though the difference between the performance of Categorical Cross Ent. and Class Metric with an ordinal margin is not statistically significant.
We also evaluate the performance of our methods on the training set using 10-fold cross valida-tion to better observe the performance differences between our model variants (Table 4). All models' perform substantially better on the training set than on the test set. This is partially explained by the fact that the models were tuned on the training set, but the large difference in some cases (e.g., the increase in the highest non-green F1 from 0.50 to 0.87) suggest there may be qualitative differences between the training and testing sets. The best-performing method on the test set, Categorical Cross Ent., performs the worst on the training set. Similarly, the worst-performing method on the test set, MSE, performs the best on the training set. Class Metric (Ordinal) performs well on both the testing and training sets, however, suggesting that it is more robust than the other methods. Furthermore, there is no statistically significant difference between Class Metric (Ordinal) and the best-performing method on either dataset.  Table 5: Example phrases that strongly contributed to a user's depression classification on the RSDD dataset.

Analysis
In this section we analyze the language that strongly contributed to the identification of depressed users on the Reddit dataset. Note that it is impossible to show entire Reddit posts without compromising users' anonymity; we found that even when a post is paraphrased, enough information remains that it can easily be identified using a Web search engine. For example, one Reddit post that strongly contributed to the author's classification as a depressed user contained the mention of a specific type of abuse and several comments vaguely related to this type of abuse. We attempted to paraphrase this post, but found that any paraphrase containing general language related to both the type of abuse and to the user's comments was enough to identify the user. Thus, to protect the anonymity of the users in our dataset, we do not publish posts in any form.
Rather than publishing posts, we identify key phrases in posts from users who were correctly identified as being depressed. Phrases from eight self-reported depressed users are shown in Table 5; to prevent these phrases from being used to identify users, we retain only the top phrase from each user. These phrases were identified by using the model's convolutional filter weights to identify posts in the validation dataset that are strongly contributing to the model's classification decision, and then using the convolutional filter weights to identify the phrase within each post that most strongly contributed to the post's classification (i.e., had the highest feature values).
In keeping with the design of our dataset, terms related to depression or diagnoses are not present. Instead, the model identifies phrases that often could be associated with a negative sentiment or outlook. For example, "my whole" could be part of a negative comment referring to the poster's whole life. It should be noted that the model makes classification decisions based on the occur-rence of phrases across many posts by the same user. Though one can imagine how the phrases shown here could be used to convey negative sentiment, the presence of a single such phrase is not sufficient to cause the model to classify a user as depressed.

Conclusion
In this work we argued for the close connection between social media and mental health, and described a neural network architecture for performing self-harm risk classification and depression detection on social media posts. We described the construction of the Reddit Self-reported Depression Diagnosis (RSDD) dataset, containing over 9,000 users with self-reported depression diagnoses matched with over 107,000 similar control users; the dataset is available under a data usage agreement. We applied our classification approach to the task of identifying depressed users on this dataset and found that it substantially outperformed strong existing methods in terms of Recall and F1. While these depression detection results are encouraging, the absolute values of the metrics illustrate that this is a challenging task and worthy of further exploration. We also applied our classification approach to the task of estimating the self-harm risk posed by posts on the ReachOut.com mental health support forum, and found that it substantially outperformed strong previously-proposed methods.
Our approach and results are significant from several perspectives: they provide a strong approach to identifying posts indicating a risk of self-harm in social media; they demonstrate a means for large scale public mental health studies surrounding the state of depression; and they demonstrate the possibility of sensitive applications in the context of clinical care, where clinicians could be notified if the activities of their patients suggest they are at risk of self-harm. Furthermore, large-scale datasets such as the one presented in this paper can provide complementary information to existing data on mental health which are generally relatively smaller collections.