Abstract
Flow state assessment is essential to understand the involvement of an individual in a particular task assigned. If there is no involvement in the task assigned then the individual in due course of time gets affected either by psychological or physiological illnesses. The National Crime Records Bureau (NCRB) statistics show that non-involvement in the task drive the individual to a depression state and subsequently attempt for suicide. Therefore, it is essential to determine the decrease in flow level at an earlier stage and take remedial steps to recover them. There are many invasive methods to determine the flow state, which is not preferred and the commonly used non-invasive method is the questionnaire and interview method, which is the subjective and retroactive method, and hence chance to fake the result is more. Hence, the main objective of our work is to design an efficient flow level measurement system that measures flow in an objective method and also determines real-time flow classification. The accuracy of classification is achieved by designing an Expert Active k-Nearest Neighbour (EAkNN) which can classify the individual flow state towards the task assigned into nine states using non-invasive physiological Electrocardiogram (ECG) signals. The ECG parameters are obtained during the performance of FSCWT. Thus this work is a combination of psychological theory, physiological signals and machine learning concepts. The classifier is designed with a modified voting rule instead of the default majority voting rule, in which the contribution probability of nearest points to new data is considered. The dataset is divided into two sets, training dataset 75%and testing dataset 25%. The classifier is trained and tested with the dataset and the classification efficiency is 95%.
Keywords
Introduction
In recent developments of computing technology, there has been a growing interest to recognize people’s affective states. Flow is an awareness state where an individual is entirely involved in an activity and enjoys the activity to its fullest. A study by Csikszentmihalyi [1] defines flow [12] as a peak involvement that occurs in any circumstances where there is an activity and comprises of three components, absorption, that is, total immersion in an activity, enjoyment and intrinsic motivation [1]. In academics, the three components for flow is defined as absorption which refers to the absolute concentration state [2]. Students who take delight in their studies feel happy [3] and this feel is the outcome of cognitive and effective evaluations of the flow experience [4, 5]. Intrinsic motivation refers to performing a certain work-related activity to experience the passion with inherent pleasure and fulfilment in the activity [6]. Intrinsically motivated students are self-motivated and they show continuous interest in their studies [7]. Involvement of an individual in any activity primarily will have a high absorption level due to curiosity but as days go by, this attention level decreases due to the shortcomings in concentration level and lack of motivation and as a result, they lack interest in the activity and thus the individual extricates from the activity and also develop a harmful emotion. According to the Yerkes-Dodson law, performance on a task is determined by the inverse interaction between competition and difficulty, and we hypothesised that flow would follow a similar pattern.
Psychology categorizes the mental state of a person towards completion of an assigned task into three types as cognitive flow, anxiety and boredom. Cognitive flow [8] defines the state of the person, who involves and completes the task with full enthusiasm, concentration and association. The three mental states, flow, anxiety and boredom depend on two factors, skill level and challenge level. Skill is defined as the ability of the individual and challenge is defined as the difficulty level of the work assigned to the individual. The challenge is also defined as opportunities for action and skill is defined as the ability to handle the situation. The flow is modelled based on the balance between challenge and skill. Thus, when the skill level is proportional to the challenge, then the person is said to be in the flow state and the person is involved with fullest interest and concentration. If the skill level is less compared to the challenge level, then the person enters into an anxiety state, which is an unpleasant state of mind. If the skill level is high compared to the challenge level, then the person is moved into a state of boredom [2], in which the individual does not concentrate and has no involvement in the work assigned, as there is a lack of interest [17]. The mental state of an individual causes a major influence on the involvement of an individual’s activity in the work assigned. The Stroop Color and Word Test (SCWT) is a widely used neuropsychological test for assessing the capacity to block cognitive interference, which happens when processing of one stimulus attribute interrupts processing of another, a phenomenon known as the Stroop Effect.
In our work, flow is modelled based on two parameters skill and challenge, where both are classified into three levels, low, medium and high, hence the combination leads to nine states. Stroop colour test is an important tool in psychology for determining cognitive states, which is modelled to determine the flow state with three challenge levels of low, medium and high. Based on the performance of the subject, that is, the number of correct responses and reaction time, the skill level of the subjects are classified into low, medium and high levels. Thus the combination of skill and challenge is used to design Flow Stroop Colour Word Test (FSCWT) [52]. Our research work aims to determine the mental state of an individual when a task is assigned to a person. The focus on continuous monitoring of the mental state can be analyzed to determine if an individual is not in the flow state, then the person can be counselled and alternatives could be suggested.
Literature survey
Literature studies show that flow state can be measured by analyzing brain activities using invasive methods like Functional Magnetic Resonance Imaging (FMRI), Functional Near Infra-Red (FNIR) [9–11] which is not preferred. There are different non-invasive methods to measure flow state, that is, questionnaires, interview sessions which are subjective measures. Initially, interview methods were adopted as suggested by Csikszentmihalyi [18] to measure flow in real life and also for academics. Jackson formulated an interview model to determine the flow for athletes [19]. The interview model is structured into a Questionnaire method, in which questions were based on the individual’s experience [18]. In Mayer’s work, the flow scale is used to determine the flow experience [20, 21]. Flow scales were used to measure the flow in sports by Jackson and Marsh [22]. The Experience Sampling Method (ESM), which focused not only on data of activities but also on emotional and motivational states and a systematic phenomenology is developed [23]. The ESM is a sum of levels of self-report on concentration, involvement and enjoyment which is measured on a 10-point scale. The challenge versus skill identifies three regions of experience, first is the flow region, where challenge and skill match. Secondly, the boredom region, in which challenges with respect to skill is less and the third region is the anxiety in which challenges exceed the skill [24].
The flow is redefined because when there is a balance between challenges and skill, flow occurs when they have more opportunities and enough skills to use the opportunity [24]. This remapping allowed for the fourth state that is apathy state, which is exactly in contradiction with the flow state. Thus the phenomenological map is redrawn with eight states considering the experience [21] (Fig. 1).

Original model of the flow state: Challenges Vs Skills [24].
The various experimental variables are enjoyment, concentration, wish to do the activity, self-esteem and perceived importance to the future. An individual in an anxiety state will feel high stakes, less enjoyment and less motivation towards the work. A person in a flow state will have a higher rate in all the experimental variables and an apathy or boredom state will lead to the least rate in the experimental variables. In the relaxed state, the individual enjoys and wishes to do the activity and it is a higher state compared to flow. In terms of educational perspective, it is important to study the flow state of mind to understand the involvement in the study process. Jackson and Marsh defined eight dimensions of flow given as balance between challenge and skill, mergence of action and awareness, goal clarity, feedback, concentration, control, loss of self-consciousness, the transformation of time, autotelic experience [13]. The previous studies proved that flow is an independent predictor of learning task outcome in the areas of computer-game playing [14], mathematics [15], foreign languages [15], and computer-based statistics [16].
Therefore understanding the flow in relation to learning is an important predictor for direct relation among academic work and mental health and it is an indirect predictor for physical health. If flow should occur properly, then the task should have a clear goal that enables the individual to focus on the fundamentals of activity and a fast unambiguous feedback mechanism, which decides the individual’s progress in achieving the goal (Fig. 2). The flow model used in our work is defined by two parameters, one is the skill with three levels, low, medium and high, and the other one is the challenge with three levels, low, medium and high. Therefore using the combination of three skill levels and three challenge levels, the mental states modelled into nine states as shown in Fig. 3.

Experience Fluctuation Model diagram [25].

Mental states modelled into nine states.
In this paper, the design of FSCWT is explained in chapter 3 and the design of EAkNN is explained in chapter 4. The experimental setup for data acquisition is described in chapter 5. The performance of the FSCWT test, identification of skill stages and classification of physiological signals using EAkNN is discussed under the heading of Results and Discussion in chapter 6. The findings of this work are concluded in chapter 7.
The skill of a person is measured in terms of individual’s involvement towards assigned work, which is directly proportional to their attention level, concentration level and cognitive status [28] in the assigned work. In medical applications it is proved that the Stroop colour test [27] is an authentic tool in the field of cognitive neuroscience [26], to determine the cognitive and attention level of a person. In this work, FSCWT is developed, which is computer-based, used to measure the flow states of an individual when involved in a task. Two parameters are used to measure the flow states, that is, Reaction Time and Correct Response. Reaction time is defined as the time required to press the response word after viewing the stimulus word [30]. As the complexity of the interference effect increases compared to the basic level, the reaction time also increases. Correct Response is determined as the number of appropriate responses selected from the response word [47].
FSCWT is developed for nine flow states, a modified model of the flow state proposed by Csikszentmihalyi [31], that incorporates the medium skill and medium challenge state. The Stroop colour test is designed with three primary colours, RED, BLUE and GREEN and three secondary colours, YELLOW, MAGENTA and CYAN, thus a total of six colours. The test is designed with two types of interference levels, one type of interference is the colour in which stimulus word and response word is displayed, thus forming six types of segments, whereas the other type of interference is the order in which the segments are displayed which forms six types of phases (Table 1).
Combination of stimulus word colour and response word colour
Combination of stimulus word colour and response word colour
The computer-based design FSCWT consists of a screen that is divided into two halves. The left half displays one of the six colour words, which is referred to as the stimulus word and the other half displays all six response words, the order in which the names of colours listed, is shuffled during each display. In both stimulus word and response word, the name of the colour and colour of the word is identical or non-identical. For example, if the stimulus word RED is displayed in RED colour, then in the response list the subject should select the word with RED colour. If the stimulus word GREEN is displayed in BLUE colour, then from the response list, the colour word with BLUE should be selected.
Identical represents the name of the colour and the colour of the word are same, whereas non-identical represents the name of the colour and the colour of the word are different. White denotes that the colour of the word is displayed in white colour. For example, the Stimulus word BLUE is displayed in blue colour and the word BLUE in the Response list is displayed in white colour. This is called “Identical -White” (Fig. 4).

FSCWT –Segment 1 (SE1).
For example, if the Stimulus word is in BLUE the corresponding word BLUE in the Response list is also displayed in blue colour. This is called “Identical - Identical” (Fig. 5).

FSCWT –Segment 3 (SE3).
The order of segments forms six phases. The segments are combined in a sequence to produce three types of interference levels, that is, low, medium and high interference Stroop. The design sequence for low, medium and high interference Stroop is given in Table 2.
Design for Interference Level
For low interference, the segments are presented in the sequence of 1 to 6, for medium interference the segments are shuffled in proper sequence and for high interference the segments are shuffled in random order. The stimulus word is displayed for 1 second and the response list is displayed for 3 seconds and the subject should select the response word from the list. The time interval between the two tasks is 0.5 seconds. Therefore the total time to complete one Segment is 4.5 seconds. The segments are repeated to complete the low interference level in 5 minutes. Similarly, to complete the task of medium interference level and high interference level, 5 minutes is required for each test. ECG is recorded during the performance of FSCWT. The baseline measurement ECG is recorded for 5 minutes and a rest period of 10 minutes is given between low challenge and medium challenge and also between medium challenge and high challenge. Thus for one subject, to complete the experiment requires approximately 45 minutes. Lead II measurement is Negative for right arm, positive for left leg. The electrical difference between the electrodes on the left leg and the electrodes on the right arm is recorded. Lead II, which typically provides a clear picture of the P wave, is the most frequently utilised lead for recording the rhythm.
Though there are different methodologies available to classify the biomedical signals, earlier studies have proved that a simple k-Nearest Neighbour (kNN) [32] algorithm can efficiently classify biomedical signals. KNN is considered to be one of the dominant data mining algorithms [33] and many research works proved that the efficiency of classification can be improved by modifying the kNN algorithm [34]. The KNN classifier determines the relationship between the two input data by calculating the distance between them. The design of the classifier consists of two modules. In the first module, the classifier learns by acquiring knowledge from the input and output of the training dataset. In the second module, the acquired knowledge is used to predict the output class of the testing dataset. Each data in a dataset is defined by a feature vector <f1(x), f2(x), . . . .fn(x)>, where fi(x) signifies the value of the ith feature, and c(x) denotes the class to which the data belongs.
If x, y are the two input dataset, then the Euclidean distance d(x,y) between the two data is defined by:
Where, y1, y2, ⋯, yk are the k nearest neighbors of x,
K is the number of neighbours, and δ(c,c(yi)) = 1 if c = c(yi) and δ(c,c(yi)) = 0 otherwise.
In kNN classifier the default voting scheme is majority voting scheme in which the chance of biasing the results are more, thus misclassifying the input data. Therefore in our work attempt has been made to improve the classification efficiency by considering the probability value of the neighbouring data points which is considered f classification. The dataset is divided into two groups as training dataset Tr and Testing dataset Te. 75%of the dataset is used as training dataset and 25%of the dataset is used as testing dataset. With the training dataset, the centroid for nine classes is determined. The efficiency othe classifier is calculated by determining the class of each data in the testing dataset by considering five adjacent neighbours N = 5. The decision matrix (dm) is constructed for each new instance of testing dataset by using Euclidean distance [35].
Where
dm1 = decision matrix of data1 in testing dataset
dvij = decision value in the matrix with i neighbours and j class.
pt1 = data1 of testing dataset
ni = i neighbours, i = 1,2,3,4,5
Cj = j class, j = 1,2, . . . .9
To create the decision matrix three parameters, k value, distance metric and the voting rule is required. The number of neighbours, that is, k value is determined by assuming other parameters. Though there are many distance metrics like Euclidean, Manhattan, Mahalanobis and Diagonal Mahalanobis, based on literature the most commonly used distance metric is Euclidean distance [37, 38]. When classes are strongly correlated Mahalanobis distance performs better [39]. Considering our dataset, since the csses are less correlated with each other, Euclidean distance performs better compared to other distance metrics. There are many efficient voting schemes such as arithmetic average, maximum, minimum, median, weighted arithmetic average, weighted majority voting scheme. Amongst these combination schemes, unweight majority voting scheme is the simplest and commonly used combination scheme. The thumb rule states that the k value can be approximately determined as √n, where n is the number of data considered for classification, but this rule is not applicable for all problems, and in some cases, a low k value performs better compared to higher values [36]. Thus based on a trial basis, by varying the k value, from 1 to 16, performance is evaluated. Efficiency is calculated, and the results show that k = 5 gives the maximum efficiency. Therefore to construct decision matrix, k = 5, Euclidean distance and unweight majority voting scheme is considered.
The Nearest degree determines how close the determined value is to the threshold value using the formula [51]:
The probability that the given data belong to a particular class in the class is considered as 1 and the probability that it does not belong to a particular class is considered as 0. Thus the threshold value is chosen as 0.5.
The Nearest degree (ND) with the direction is calculated using the formula:
The Farthest degree (UD) is calculated by:
The Strength (S) is calculated by:
The Strength matrix is normalized and stored as SN mrix The Total Strength (TS) is calculated as:
The Total Strength sum (TS) can also be calculated using the equation.7
Substituting for UDsum from equation 6 and rearranging the equation
Therefore the final voting probability
Where i = 1,2 . . . 9, 9 classes
The steps for the design of EMkNN classifier is dcribed in Fig. 6. Thus the data is classified into the class which has the highest probability value based on equation 11. The classifier performance is evaluated based on the statistical measures [40]. Classification accuracy of the Classifier: It is the ratio of the number of correct assessments to the Total number of assessments.

Flow chart for the Design of EAkNN Classifier.
(i) Material and Methods
The experiments were conducted with 300 subjects in the age group of 17–22. The subjects with different skill levels of low, medium, high are included for this experimental analysis. The subjects under cardiovascular or psychiatric treatment or under medication that alters their heart rate were excluded from the test. The subjects affected by colour blindness or dyslexia were also excluded from the test.
(ii) Modules: The different modules in the identification of different states of the individual are:
(a) Data acquisition
(b) Feature extraction
(c) Classification
(iii) Data acquisition
The temperature and light of the room are maintained constant for all the subjects. The experimental procedure is explained in detail to the subject and a consent form that contains all the required information about the experiment is signed by the subject before the commencement of the experiment. The subjects were explained about the experimental procedure in detail. The ECG electrodes were connected for lead II, the subjects were asked to sit comfortably and relax by closing their eyes for 10 minutes and then Blood Pressure (BP) was measured. Biopac MP36 data acquisition system is used to record lead II ECG at the rate of 200 samples / second for 5 minutes, with a normal breadth rate of 12–18 / minute, which is the rest position. The subjects were asked to perform FSCWT. ECG lead II is recorded for 5 minutes during the performance of low, medium and high challenge levels with 10 minutes of rest in-between each level. The ECG signals that were not properly recorded were not considered for analysis. Thus a total of 250 subjects’ data were considered for further analysis.
(iv) Feature Extraction-ECG Parameters
The artefacts are removed and kubios software is used to select and analyze the RR series. The resampling frequency of the RR series is 4 Hz, and power spectrum between 0.15 Hz and 0.4 Hz is integrated to obtain High Frequency (HF) spectral powers and 0.04 Hz and 0.15 Hz is integrated to obtain Low Frequency (LF) spectral powers [41] The sum of LF and HF powers were also calculated.
(v) Classification
The HRV (Heart Rate Variability) time domain and frequency domain parameters obtained for the ECG signals acquired from the subjects during the performance of FSCWT, are the feature vectors and is input for the EAkNN classifier. The classifier classifies the input into one of the nine classes. HRV is a measure of the variation in time between each heartbeat.
Results and discussion (Performance of Flow Stroop Colour Word Test)
The FSCWT is designed based on two parameters, challenge and skill. Challenge is classified into three levels, low, medium and high and skill is also classified into three levels, low, medium and high. Therefore, the combination of challenge and skill levels forms nine states. Thus, ECG parameters for the nine states are tabulated in Table 3. From the tabulated values it can be observed that as challenge level increases from low to high level, the memory workload also increases, the time domain parameters, mean RR, RMSD, NN50, pNN50 decreases, but the mean HR value decreases as the challenge level increases from low to high challenge state, and for the other time-domain parameters the value increases form low challenge state to high challenge state. Similarly, SDNN, the time-domain parameter which is an estimate of overall HRV show a significant decrease from low challenge state to high challenge state.
HRV Features for Nine Mental States
HRV Features for Nine Mental States
In the frequency domain parameters, LF n.u, HF n.u and LF/HF ratio, the power spectral components are compared in the form of normalized units (n.u) because normalization reduces the effects of fluctuations in the total power of the values of LF and HF components to a minimum level by removing the less reliable VLF components from its estimations. In our experimental work, the LF n.u value increases as the challenge level increases from low to high state, whereas, HF n.u value decreases as the challenge increases from low state to high state. Thus the LF/HF ratio increases as the challenge increase from low to high state. All the values are tabulated in Table 3. Table 4 tabulates the comparison between different states based on p-value calculated using t-test. Earlier studies have proved that there is a change in various physiological parameter including HRV, when there is an increase in mental workload, hence both sympathetic and parasympathetic system influences LF component but parasympathetic variation stimulates only the HF component [42–44].
Comparison between different states based on p-value calculated using t-test
In our experimental work, the HF component decreases as the challenge level increases from low state to high state but the LF component significantly increases as the challenge level increases from the low state to the high state. This proves that sympathetic outflow increases and the time domain parameters, Mean RR, RMSSD, SDNN, NN50, pNN50 decreases, when the challenge level was increased from low to high state during the performance of FSCWT. HRV features are shown in Fig. 7.

HRV time domain and frequency domain parameters of kubios output.
Thus, in the process of adaptation of an individual to a challenging situation, the sympathovagal balance shifts towards the sympathetic limb. As the complexity level increases, the anxiety to complete the task also increases and therefore it increases the sympathetic discharge but decreases the parasympathetic tone, which is proved from the obtained results by comparing HRV parameters of different challenge levels. Thus, in this work, a combination of identical and non-identical segments was used to create a Flow Stroop Interference, therefore as the challenge level increases the demands on working memory also increase.
The FSCWT is designed with high, medium and low complication levels. The heart rate variability (HRV) parameters for different skill levels and challenge levels are analyzed. All the time domain and power spectral components followed the expected trend which every healthy people would follow when subjected to a challenge. Thus all the time domain and frequency domain parameters were considered as sensitive indicators of mental states [47]. Therefore, it can be concluded that the category of the task can be determined based on the frequency and time domain estimates. Thus, the designed FSCWT can be used as a flow inducer and HRV parameters obtained from ECG can efficiently distinguish between the nine different states.
The individual’s low, medium and high skill levels were identified based on the FSCWT performance which is evaluated based on the number of correct responses and the reaction time. The number of times the subject indicates the correct colour gives the number of the correct response. Reaction time is defined as the time between the stimulus onset and the subject’s correct response. The FSCWT is designed to impart low challenge, medium challenge and high challenge. The performance based on the number of correct responses and reaction time is determined for all the three categories low challenge, medium challenge and high challenge.
The performance graph shows that as challenge increases, the performance also increases until a certain optimal point is reached. After this optimal point the performance decreases, though challenge increases. Therefore the subjects’ performance is consistent with Yerkes-Dodson law. Mean reaction time and correct responses show a significant difference between the various categories. Thus, the correct response and reaction time can be used as a performance measure to distinguish between the various groups [45]. Table 5 shows the average value of the correct response for a different combination of skill and challenge levels. The average correct response is plotted with respect to different levels of skill and challenge and from Fig. 8 it can be inferred that the graph follows Yerkes-Dodson law.
Average correct response with respect to different levels of skill and challenge
Average correct response with respect to different levels of skill and challenge

Correct response with respect to different skill and challenge levels.
The ECG database is obtained from subjects with three different skill levels of low, medium and high, who performs three different challenge levels of low, medium and high. HRV time domain and frequency domain parameters are extracted using Kubios software and given as input to EAkNN. The performance of EAkNN classifier is analyzed for all the challenge levels and compared with the most commonly used combination schemes. The classification efficiency is calculated and compared with another commonly used voting scheme. It is observed that EAkNN efficiency is higher when compared to other combination schemes and has an efficiency of 95 %when the total database of low challenge, medium challenge and the high challenge is considered. Table 6 shows the classification efficiency of different combination techniques for different challenge levels. Figure 8 is plotted for classification efficiency for different challenge levels of low challenge, medium challenge and high challenge for the commonly used combination scheme along with the proposed EAkNN. In all the challenge states, the classification efficiency is higher for the proposed EAkNN. The classification efficiency is increased compared to the testing database for all the challenge levels. The classification efficiency of different combination techniques for different challenge levels are tabulated in Table 6 and the comparison is shown in Fig. 9.
Classification Efficiency of different combination techniques for different challenge levels
Classification Efficiency of different combination techniques for different challenge levels

Classification Efficiency compared between different combinations techniques.
The accuracy was 72.3%with random forest classifier with ECG as a physiological parameter and flow classification level was two levels high and low [49]. The SVM classifier, with EEG as a physiological parameter and three flow levels low, medium and high, had an accuracy of 87%[50]. Table 7 shows the efficiency of the proposed algorithm is high compared with the previous algorithm.
Comparison between proposed classifier algorithm and previous work
In our work, FSCWT is designed with three challenge states and also incorporates three skill states thus nine mental states can be analyzed, compared to the earlier work of Stroop colour test design with three mental states. In our work, the FSCWT is designed for three challenge levels and also considering the three skill levels, hence the performance of an individual is compared with respect to the combination of challenge and skill level, into nine mental states. The ECG signal is experimentally acquired, HRV parameters are extracted and given as input to the efficiently designed EAkNN classifier, which classifies the data with an average of 95%accuracy into nine mental states.
