An Energy-Efficient Spectrum-Aware Reinforcement Learning-Based Clustering Algorithm for Cognitive Radio Sensor Networks

It is well-known that clustering partitions network into logical groups of nodes in order to achieve energy efficiency and to enhance dynamic channel access in cognitive radio through cooperative sensing. While the topic of energy efficiency has been well investigated in conventional wireless sensor networks, the latter has not been extensively explored. In this paper, we propose a reinforcement learning-based spectrum-aware clustering algorithm that allows a member node to learn the energy and cooperative sensing costs for neighboring clusters to achieve an optimal solution. Each member node selects an optimal cluster that satisfies pairwise constraints, minimizes network energy consumption and enhances channel sensing performance through an exploration technique. We first model the network energy consumption and then determine the optimal number of clusters for the network. The problem of selecting an optimal cluster is formulated as a Markov Decision Process (MDP) in the algorithm and the obtained simulation results show convergence, learning and adaptability of the algorithm to dynamic environment towards achieving an optimal solution. Performance comparisons of our algorithm with the Groupwise Spectrum Aware (GWSA)-based algorithm in terms of Sum of Square Error (SSE), complexity, network energy consumption and probability of detection indicate improved performance from the proposed approach. The results further reveal that an energy savings of 9% and a significant Primary User (PU) detection improvement can be achieved with the proposed approach.


Introduction
Technological advances in microelectronics have led to the widespread applications of wireless sensor networks (WSNs) in a variety of application areas. In general, wireless sensor nodes and many other wireless devices based on Wi-Fi, Zigbee and Bluetooth standards operate in unlicensed spectrum bands such as the Industrial Scientific and Medical (ISM) band which lack tight regulations. This leads to severe congestion in the useable unlicensed spectrum bands and causes harmful interference between the various wireless devices. On the other hand, licensed spectrum bands which are assigned to licensed users known as Primary Users (PUs) tend to become underutilized due to their fixed spectrum band allocation, as reported in the Federal Communications Commission (FCC) report [1]. This necessitates the need for a paradigm shift from the conventional inefficient spectrum allocation policy to a dynamic and more flexible spectrum access management.
Cognitive Radio (CR) is a new paradigm that has the potential to efficiently utilize the unused licensed spectrum bands, also known as spectrum holes, by dynamically allocating the spectrum holes to unlicensed users referred to as Secondary Users (SUs) without any harmful interference with PUs' transmissions. Therefore, the main motivation for CR is dynamic access to temporal and spatial spectrum holes [2]. Spectrum sensing is the main fundamental function of CR for spectrum band exploration to identify spectrum holes and to protect PUs from harmful interference. Two performance metrics namely, probability of detection Pd and probability of false alarm Pf are used to measure the reliability of spectrum sensing techniques for discovering the availability or otherwise of spectrum holes. However, wireless propagation impairments such as multi-path fading, receiver uncertainty, shadowing and interference in wireless channels degrade the performance of PU detection techniques [3].
Cooperative spectrum sensing is a promising approach to overcome these problems [4]. The approach involves coordinating multiple CRs to share their local sensing results and make a collective decision about spectrum hole availability. It also improves the probability of PU detection through exploration of multi-users' sensing diversity. A Fusion Centre (FC) performs decision fusion on the sensing results obtained and makes a global decision on the spectrum holes' status. Although cooperative spectrum sensing yields better sensing performance, it also increases communications overhead, incurs in high energy consumption as well as extra sensing and reporting delays, particularly in large-scale networks such as CR-WSN. These problems can be minimized by logical grouping of multiple SUs to form a cluster.
clustering requires additional conditions for grouping of nodes based on common vacant channels detected in a temporal and spatial neighborhood [14]. In such a network, sensor nodes within a cluster are require to have at least one common vacant channel between the transmitter and the receiver for communication. The dynamic nature of the environment which is influenced by the PU activities necessitates the need for spectrum aware clustering schemes.
Spectrum-aware clustering schemes in cognitive radio networks has received considerable attention in recent times. Network scalability and heterogeneity challenges have been well investigated and addressed such as in [15]. The scheme is based on distributed coordination approach where SUs construct groups in accordance with common vacant channels locally detected. A spectrum-aware routing solution for cognitive radio described in [16] selects routes that offer the highest spectrum availability and computes its long-term routing metrics to balance between short-term route performance and long term route satiability. The scheme mainly addresses channelization and dynamic variation issues in cognitive radio routing protocol to effectively utilize unused licensed channels. The spectrum aware clustering scheme in [14] is mainly driven by an event which requires a temporal cluster. The scheme uses nodes' local position in respect to the event and sinks to select eligible nodes for clustering. It then elects a clusterhead among the eligible nodes based on channel availability, node degree and distance to sinks in the neighborhood. The authors in [17] proposed a centralized Groupwise Spectrum-Aware (GWSA) clustering algorithm; it first creates a proximity matrix for all nodes, determines from the matrix the global minimum distance between pairs and then merges the nearest clusters that satisfy the Groupwise constraints in each iteration until an optimal number of clusters that minimizes network-wide energy consumption is achieved.
However, this approach suffers from network instability because PU arrival may cause re-clustering of the whole network and also its high computational complexity which increases proportionately along with the size of the proximity matrix limits its practical implementation in a large-scale network. The algorithm described in [18] minimizes the network instability problem such that re-clustering involves only nodes that detect the PU arrival while network topology of other nodes remains intact. Furthermore, it determines local minimum distance between neighboring cluster pair and merges multiple nearest cluster pair at a single time to increase the convergence rate. Although the algorithm achieves relatively much less computation complexity, its performance is relatively inferior to the GWSA. Unlike [17,18] our proposed algorithm not only tends to minimize network energy consumption, but also improves spectrum hole detection, by way of exploring multi-user sensing diversity through cooperative spectrum sensing which is essential for dynamic spectrum access in cognitive radio.
The reinforcement learning (RL) technique has been applied to many existing works related to cognitive radio, but they were mainly applied to spectrum sensing [2], cooperative sensing [3,19], spectrum sharing [20], channel sensing [21,22] and dynamic channel access [23][24][25]. For example, the authors in [3,19] applied RL to enhance cooperative gain and mitigate cooperative overhead in cognitive radio. The approach eliminates correlated and unreliable cooperative neighboring SUs from cooperation and determines optimal set of cooperative SUs that minimize spectrum sensing delays and control channel traffic. In a bid to improve channel sensing performance, the authors in [26] used channel achievable and channel availability as the basis for determining optimal channel sensing order by applying a low complexity RL algorithm. The approach in [2] achieved energy efficient spectrum sensing by exploration of sensing assignment and exploitation of high throughput frequency bands. Even though the existing RL approaches in the literature made valuable contributions to CR-WSN, none of them considered RL for network clustering In this paper, we propose an Energy Efficient Spectrum Aware clustering algorithm based on Reinforcement Learning (EESA-RLC) to enhance spectrum hole detection and minimize network energy consumption in CR-WSNs. Reinforcement learning is a machine learning technique that allows an agent to interact with its operating environment and learn an optimal policy that maximizes cumulative rewards [27]. The operating environment can be formulated as a Markov Decision Process (MDP) comprising actions, state of the system, transition rewards, transition probability, performance metric and policy [28]. The agent, which in this case is the SU, detects vacant licensed channels through channel sensing, imposes pairwise constraints to select a clusterhead among the neighboring clusterheads, cooperates with other member nodes in the cluster to determine channel availability, and then chooses an optimal policy that enhances spectrum hole detection and minimizes network energy consumption. The agent employs a Temporal Differences (TD) learning technique [29] to learn from the neighboring clusterheads, evaluates its local decision accuracy, distance to the clusterheads which translates into energy consumption and selects an optimal action policy that optimizes its performance in determining an optimal clusterhead. Although RL is a well-known machine learning technique and has been extensively applied to many fields such as cooperative sensing [3,30], channel sensing sequence [26,22], energy efficient communication [2,31], its application in clustering algorithm is still at the infancy stage. Therefore, our contributions in this paper can be summarized as follows: i. We propose a novel energy-efficient clustering algorithm that is aware of the dynamic radio environment and allows member nodes to learn an optimal policy for choosing optimal clusters based on local decision accuracy and energy consumption for cooperative sensing and data communication. ii. The proposed algorithm implements pairwise constraints in spectrum-aware clustering such that only SUs with at least one common vacant channel with a clusterhead and within the clusterhead's one hop radio range can form a cluster. iii. We model network energy consumption, cooperative channel sensing, inter-cluster and intra-cluster data communication energy consumptions and determine an optimal number of network clusters that minimizes network energy consumption. iv. We show the performance improvements of the proposed clustering algorithm over Groupwise constraint-based algorithms [17,18] in terms of energy efficiency, channel sensing performance and computational complexity, which make it more attractive for resource constrained devices such as CR-WSNs. In addition, the algorithm eliminates network instability due to re-clustering when the SUs detect PUs' arrival.

System Model
This section describes the system model and parameters adopted for this research. The network is assumed to be static, consisting of non-mobile homogenous fully functional cognitive radio sensor nodes capable of performing complex tasks. The number of SUs in the network exert a significant impact on energy consumption and on sensing performance. For instance, in a fixed size cluster, the cooperative probability of detection increases along with the increase in the number of cooperative SUs. The network area is partitioned into clusters, each cluster can be seen as a small cell network comprising a clusterhead and a few member nodes, as shown in Figure 1. Partitioning the network area into clusters has a significant effect on the network energy consumption. If the number of clusters in the network is too small, spectrum sensing, reporting and data communication consume a large amount of energy owing to large number of member nodes per cluster. On the other hand, if the number of clusters is too many, the number of member nodes would be too small and hence the energy consumption per cluster would be low but a large amount of energy would be consumed for inter-cluster communication. Therefore, the optimal number of clusters is extremely important. The nodes are uniformly distributed in a two-dimensional square area N of L × L square meters and each node is battery powered. This means sensor nodes' energy cannot be recharged, therefore, nodes' energy consumption need to be minimized to extend the lifetime of the network. Each node can operate either as a clusterhead or member node. The member nodes MNs sense a set of licensed channels to detect vacant channels, report local sensing decisions to clusterheads for cooperative decision-making and also sense the environment to detect events. The clusterheads perform additional tasks which include decision fusion on the sensing results, controlling access to free channels for data communication and coordinating channel sensing. These additional tasks drain more energy from the battery of the clusterhead, therefore the role of clusterhead will be reassigned to other member nodes within a cluster when the energy depletes below a threshold. It is further assumed that all member nodes lie within the radio range of their respective clusterheads ( < ) and communicate directly with the clusterheads in a single-hop manner. This means that member nodes require only low transmissions power and at least one common vacant channel to communicate their data to clusterheads since the distance between them is short.
The operation of the SUs are divided into time slots of durations, is the time allocated for sensing channels, is the time duration for reporting the results, and is duration over which the SU can access the free channel for data transmission. There are heterogeneous licensed channels in which each channel may exhibit different bandwidth and channel conditions. Larger bandwidth requires longer sensing time which translates into higher energy consumption and poor channel conditions resulting in inaccurate local decisions. An energy detection technique is employed to detect the presence of PUs on the licensed channels, since the PUs' signals are assumed to be unknown, coupled with the unique resource constraint features of the CR-WSN which requires less complex spectrum sensing techniques.

The Proposed Energy Efficient Spectrum Aware Reinforcement Learning Based Clustering (EESA-RLC) Algorithm
This section presents modelling and algorithms for our energy-efficient reinforcement learning-based clustering scheme. The algorithms basically comprise of initialization, set-up and coordination phases.
The initialization phase precedes the reinforcement learning process; it involves election of clusterheads. Each SU senses a predefined set of channels to detect the presence or absence of PUs in the channels, computes its clusterhead probability based on the number of vacant channels detected and residual energy E , as well as the required percentage of clusterheads (e.g., 5%) for the network. The clusterhead probability is the probability of a sensor node to become a clusterhead. The main goal is to ensure that all SUs in the network are covered by a set of clusterheads at the initial stage, so that member nodes can directly communicate with clusterheads within their radio range via a single-hop while the clusterheads communicate with the BS through a single-hop or multi-hop fashion. The clusterhead probability for secondary user can be expressed as: where E denotes the reference maximum energy of the SU when fully charged. This clusterhead probability is similar to the HEED protocol described in [32]. The clustering initialization process begins at time . Each SU determines its clusterhead probability and compares it with a given threshold < 1. If its clusterhead probability is greater or equal to the given threshold ≥ , then the SU emerges as a tentative clusterhead and then broadcasts an advertisement packet comprising its ID and clusterhead probability. This means that SUs with the highest probability are more likely to emerge as the tentative clusterheads. SUs with clusterhead probability less than the threshold ( < ) hearing the clusterheads announcement withdraw from competing and wait for the final clusterheads announcement by the BS. These SUs are more likely to remain as member nodes while the other in the set perform = 1  ⁄ maximum number of iterations and compete for the role of clusterhead after expiration of announcement waiting period . Where  denotes percentage of the threshold which can be set to a value less than one  < 1.
In each iteration , ≤ , each of the SUs increases its clusterhead probability by  ( e.g.,  = 10% of ) and compares the updated clusterhead probability with the given threshold. If the clusterhead probability is greater than or equal to the threshold, then it terminates the iteration and broadcasts an advertisement packet. Otherwise, it proceeds to the next iteration. The set of SUs with least number of iterations would emerge as the tentative clusterheads, then after expiration of announcement waiting period the other sets that follow them would be elected. This process continues until all nodes are covered by the clusterheads. This means that after the emergence of the first set of clusterheads, each subsequent emergence of sets of clusterheads would be delayed by some duration depending on the number of iterations. The BS selects an optimal number of clusterheads among the tentative clusterheads and broadcasts the list.
The set-up phase mainly deals with cluster formation, based on the advertisement packet received from multiple neighboring clusterheads | = 1, 2, 3, … , which also denotes clusters | = 1, 2, 3, … , , hence clusterhead and cluster will be used interchangeably in this paper. The SU learns the energy consumed and local decision accuracy for each of the clusters by executing model-free reinforcement learning and then selects an optimal cluster * that minimizes energy consumption and enhances spectrum holes detection. During the learning process, the SU senses set of licensed channels = { ℎ | = 1, 2, 3, … , } at every episode , sends its local decision = { | = 1, 2, 3, … , } to the clusterhead for the final cooperative decision = { | = 1, 2, 3, … , } and then compares its local decision with the cooperative decision to determine the local decision accuracy in respect to cluster . It also determines the energy consumption for communicating data , and cooperative sensing , . In addition, during the process, favourable clusters which offer minimum energy consumption and better spectrum hole detection would be selected, while excluding the less favorable clusters.
The maintenance phase involves coordination of cluster members. In this phase, the clusterheads specify the set of channels to be sensed based on their availabilities and control access to the free licensed channels for data communication. Upon energy depletion of any clusterhead, the clusterhead initiates re-clustering process and a new clusterhead would emerge among the member nodes.
The main objective of the algorithm is to achieve an optimal policy for selecting optimal cluster or clusterhead that satisfies the pairwise constraint conditions, minimizes cooperative channel sensing energy consumption and data communication energy consumption while enhancing spectrum hole detection. denote sets of vacant channels detected by the member node and the selected clusterhead , respectively, then the problem of finding optimal clusterhead * can be formulated as a Markov Decision Process while the energy minimization problem can be formulated as pairwise constraint Sum of Square Error (SSE) minimization problem subject to one hop transmission constraint. This is given as: Subject to: To achieve this, Q-learning would be adopted due to its model-free capability and the pairwise constraint would be applied on the member nodes and the clusterheads during the clustering.

Pairwise Constraint Clustering
The concept of pairwise constraints has been widely implemented in many clustering algorithms such as k-means [33] and complete link [34] clustering to impose must-link and cannot-link constraints on pairs of nodes during the clustering as illustrated in Figure 2. The must-link constraint forces pair nodes and to be placed in the same cluster, while the cannot-link constraint disallows pair nodes and to be placed in the same cluster [17]. This significantly influences the outcome of the clustering, since pair nodes with common links usually belong to the same cluster, while those without common links belong to different clusters. Therefore, the pairwise constraint concept can also be implemented in a spectrum-aware clustering algorithm, which can be explained by comparing it with the groupwise constraint method employed in [17,18] for spectrum-aware clustering. Unlike conventional WSN clustering schemes, spectrum-aware clustering schemes require each node to sense the spectrum band and detect spectrum holes that can be used for data communication. In addition, each clusterhead must have at least one common available channel with its member nodes since each member node transmits its data directly to the clusterhead without intermediary nodes. To highlight the difference between pairwise and groupwise constraints, we consider a clusterhead and three member nodes , , that operate on a set of licensed channels = { ℎ | = 1, 2, 3, … , } as shown in Figure 3. The numbers beside them represent the vacant licensed channels detected by the respective member node; a dotted line between them indicates a cannot-link constraint, while a solid line indicates a must link constraint as illustrated in Figure 2. The figure shows that member node shares channel ℎ with and , member node shares channel ℎ and channel ℎ with in addition to member node , while member node shares only channel ℎ with . Based on this scenario, the pairwise constraint imposes a must-link constraint on member nodes and to form a cluster with clusterhead because they all share a vacant channel ( ℎ ). It also imposes a cannot-link constraint on and so that the member nodes cannot form a cluster since member node has no common vacant channel with even though it shares a vacant channel with member node . On the other hand, the groupwise constraint imposes cannot-links on all the four nodes, including , disallowing them from forming a cluster, because the nodes share no common vacant channel. While a pairwise constraint requires at least one common vacant channel for pair nodes of clusterhead and member node to form a cluster, a groupwise constraint requires at least one common vacant channel for all nodes in a group to a form cluster.

Cooperative Channels Sensing
Spectrum sensing is a key function of cognitive radio for determining licensed channel occupancy; this is done by detecting the existence of PUs in the channels. Energy detection technique has been commonly employed to detect the existence of PUs' signals in the spectrum bands by measuring energy of the received signal waveform over a specified observation time. The received signal is first filtered by a Band Pass Filter (BPF) to limit the noise bandwidth. The filtered output signal of bandwidth is converted to discrete samples by an Analogue-to-Digital Converter (ADC) and then passed through an integrator for an observation interval . The final average energy of the observed samples from the output of the integrator = ∑ | ( )| is compared with a threshold λ to determine the existence or otherwise of a PU signal [4]. If < λ, then a PU's signal is absent and the channel is considered available, otherwise, a PU's signal is considered to be present and the channel is being occupied. Thus, the received signal at the SU can be expressed as [4]: where ( ) denotes zero-mean Additive White Gaussian Noise (AWGN), ( ) denotes the received signal waveform. denotes the null hypothesis which indicates the absence of a PU's signal, while denotes a hypothesis which indicates the presence of a PU's signal. Thus, the test statistics from the output of the integrator follow a chi-square distribution and can be approximated to a Gaussian distribution using central limit theorem, which when the number of samples is large given as [29]: where denotes received the noise signal's variance and denotes the received signal's variance ( ). Optimal PU detection can be achieved through a Maximum A Posteriori (MAP) scheme which models the PU behaviors into On and Off states using a two-state Markov chain that has been widely adopted [35][36][37]. Therefore, the probability of detection which suggests the presence of a PU in the considered channel can be expressed as: Similarly, the probability of false alarm which falsely indicates the presence of a PU's signal in the considered channel can be expressed as: where ℚ(. ) is the generalized Marcum Q-function, and are probabilities that the channel is in busy or idle states respectively. Cooperative spectrum sensing enhances the PU detection through exploitation of SUs' observed signals spatial diversity.  [38]. This implies that when the number of cooperative member nodes that report presence of PU's signal in the considered channel is greater than or equal to half of the total number of cooperative member node ( ≥ 2 ⁄ ), then the final cooperative decision indicates the presence of a PU in the observed channels [39]. Otherwise it indicates the absence of a PU and hence the availability of the observed channels. Thus, the cooperative probability of detection , is given as [30]:

Cognitive Radio Wireless Sensor Network Energy Consumption Model
Network energy consumption for CR-WSNs mainly comprises of energy consumptions for vacant channels detection, event sensing, data processing, and communication. The energy consumption for detecting vacant channels is the energy consumed for cooperative channels sensing. The event sensing energy consumption is attributed to energy consumed for the sensing event while the data processing energy is attributed to energy consumed for data logging. The energy consumption for data transmission is attributed to energy consumed for intra-cluster and inter-cluster data communications.
Several attempts have been made to model wireless sensor network energy consumptions. The most widely adopted models [40][41][42] have combined the impact of the external radio environment and the sensor node's communication hardware together. According to these models, energy consumption for transmitting a unit bit of data depends largely on the distance between the transmitting and the receiving nodes. However, the outcome of experimental measurements conducted in [43] is inconsistent with the widely adopted simplified models. In addition, it is revealed that separating energy consumption of each hardware component from the external radio environment may lead to a more realistic energy consumption model [44]. The authors in [45] proposed a comprehensive node power consumption model which considered other energy consumption sources that were ignored in the previous models such as sensor sensing and sensor logging. However, these approaches are specifically developed for conventional sensor nodes without due consideration of the cognitive radio aspect. Therefore, accurate estimation of CR-WSN life expectancy requires a realistic network energy consumption model that incorporates channel sensing energy consumption as well.
The main components of a cognitive radio sensor node are event sensing, data processing, communication and cognitive radio units as shown in Figure 4. The event sensing unit monitors the environment and generates signal traffic whenever an event is occurred. The processing unit processes the data while the communication unit transmits the data to desire sink over a free licensed channel and also receives data. The cognitive radio module detects set of unused licensed channels and then accesses the most suitable channel to communicate the data.

Event Sensing Unit Energy Consumption
The event sensing unit interacts with the physical environment to detect an event and then convert the physical signals to digital signals. Signal sampling, physical signal conversion to electrical signals and analogue signal to digital signal conversion are the main sources of energy consumption in the event sensing unit [45]. Let denotes the event sensing duration, denotes power required for the event sensing activity which includes event detection and signal conversion and denotes the bits packet. The energy dissipation for event sensing activity for bits packet is given as:

Processing Unit Energy Consumption
The processing unit executes functions such as sensor data logging, data aggregation and processing. Energy consumption for sensor data logging is due to amount of energy consumed for reading and writing a packet of data into the memory. Let denote the power consumption for reading a packet from the memory, denotes power consumption for writing a packet into the memory then, the energy consumption for data logging can be expressed as [45]: Energy consumption for data aggregation and processing are mainly derived from microcontroller energy losses which occur as a result of switching and leakage currents. The total energy consumption for processing or aggregating bits of data packet can be expressed as [46]: where denotes the number of clock cycles per task, denotes the leakage current, denotes average number of capacitance switches per cycle, denotes the frequency of the sensor, denotes a constant parameter defined by the processor, and denote the source and terminal voltage, respectively [45].

Cognitive Radio Unit Energy Consumption
The CR unit senses the licensed channels and detects vacant channels that can be used for data communications. Energy consumption for vacant channels detection comprises energy consumption for sensing sets of channels and reporting local decisions as well as receiving final cooperative decisions [47]. Energy consumption for sensing sets of channels E comprises of energy consumed for listening over the channels and receiving observation samples, as well as energy required to process the signal samples (modulation, signal shaping etc.) and make local decisions. If denotes the energy detector's circuit power consumption and denotes the energy consumption for processing the received signal samples, then energy dissipation for sensing sets of channels can be expressed as: This suggests that the energy consumption for channel sensing is a function of channel sensing duration and it increases along with an increase in the number of channels . Minimum energy consumption can be achieved with minimum channel sensing time but accurate results may not be obtained. The Nyquist sampling theorem suggests that the sample frequency of the received signal samples ( = 2 ) must be at least twice the bandwidth ( ≥ 2 ) [29]. Let denote the target probability of detection, denotes target probability of false alarms, and denotes the average of the PU's SNR received on the channel. The channel sensing time can be expressed as [37]: In cooperative sensing, each member node senses sets of channels to detect vacant channels, makes local decisions on the existence of PU and then reports its result to the FC which is the clusterhead for the final cooperative decision. Let , denote the Euclidian distance between and , denotes the energy consumption for running the radio electronics of and denotes the energy consumption for amplifying the signal to be transmitted to so as to maintain an acceptable SNR level. Then the energy cost for reporting -bits packet of local decisions to the can be expressed as: The energy cost for receiving the bits packet of final cooperative decision broadcast by the after performing a decision is mainly determined by the number of bits in the packet and energy consumed for running the radio electronics circuitry. Therefore, the energy consumption for receiving -bits of broadcasted packet can be expressed as: Therefore, the energy consumed by member node is the energy consumption for cooperative channel sensing which comprises the energy consumption for sensing the set of channels, energy consumption for reporting local decisions and energy consumption for receiving the final cooperative decision which is given as: Each performs data fusion upon receiving MNs' local decisions and then broadcasts the final cooperative decision. Energy consumption E for receiving -bits of each local decision is given as: Let denote the maximum radio range of clusterhead , then the consumed energy E for broadcasting the final cooperative decision can be expressed as: Let E denote energy consumption for processing a bits packet received from each member node for decision fusion. Energy cost for clusterhead cooperative channel sensing is the energy consumed for sensing a set of channels, energy consumed for receiving member nodes' local decisions, energy consumption for processing the decisions and energy consumption for broadcasting the final cooperative decisions which is given as: Therefore, total energy cost for cooperative channel sensing can be expressed as:

Transceiver Unit Energy Consumption
The transceiver unit enables communication between the member nodes MNs and the clusterheads CHs as well as between the CHs and the BS. Each transmits its reading data to any of the selected clusterheads through the available licensed channels. Since all MNs are within the radio range of their neighboring clusterheads, adjacent MNs can send their data to the without intermediary nodes. Energy consumption E for transmitting -bits packet to over a distance , can be expressed as: The aggregates the data received from the MNs and then forwards the aggregated data either through some intermediate neighbouring clusterhead or directly to the BS. Energy consumption E for receiving -bits packet from member node can be expressed as: Let denote the immediate neighbouring clusterhead through which the aggregated data packets will be routed to the BS, denotes the energy consumption for amplifying the signal and , denotes the distance between clusterhead and the immediate neighbouring clusterhead or the BS. The energy consumption E for transmitting the aggregated data packets to the immediate neighboring clusterhead or the BS over a distance , can be expressed as: Energy consumption for receiving the aggregated data packets from neighbouring clusterhead for onward transmission is given as: The source of power consumption in the RF-front end is mainly dominated by power amplifier which boosts the transmission power to a certain level depending on the type of the amplifier and the application. The power amplifier's power consumption which is a function of transmission distance largely depends on many factors which include operating frequency, DC supply voltage, output power, hardware technology and load characteristic. The total power consumption for running the power amplifier is equal to the DC input power ( = ) [44]. The ability of the power amplifier to convert the DC input power into RF signal power is referred to as drain efficiency. This efficiency can be expressed as the ratio of signal power to DC power given as: Communication over the wireless medium is susceptible to propagation impairments such as multi-path, fading and attenuation. If denotes the RF signal power from the transmitter's power amplifier delivered to the receiver node's antenna, and is a parameter that defines the characteristic of the transmitting and receiving antenna, then the RF signal power received at the receiving sensor node can be expressed as: Therefore, from Equations (24) and (25), the minimum power consumption of RF power amplifier to amplify transmission signals is given by = / , where = is a constant given by the received RF signal power P and the antenna characteristic G [44]. The parameter value μ is a function of radio environment and can be set to a single-hop maximum transmission power value i.e., 6.3 mW instead of absolute value as in [44]. The energy consumption for data transmission comprises of energy cost for intra-cluster and inter-cluster data communication.
In intra-cluster data communication, distance between the MNs and their prospective CHs is presumably short and therefore, the channel between them follows the Friis free space path loss model with signal power attenuation of β = 2 power loss [30]. Thus, energy consumption for intra-cluster communication comprises of total energy consumption of all MNs for transmitting bits of data packet over a distance , to their respective clusterheads and total energy consumption for receiving the data by the clusterhead . This is given as: In inter-cluster data communications, the distance between CHs and BS is presumably long and therefore, the channel between them follows the Friis free space path loss model with signal power attenuation of β = 4 power loss [30]. Each clusterhead forwards its aggregated data packets to the BS either through intermediate clusterhead ( , > , ) or direct to the BS without any intermediate clusterhead ( , ≤ , ). The total energy consumption for inter-cluster data communications is the energy consumption for aggregating the received data and energy consumption for forwarding the data packet to the BS which is given as: Thus, the total energy consumption for data communications can be expressed as: If , denotes the number of member nodes in cluster and is the number of clusters in the network which is also equal to the number of clusterheads in the network, then the number of cognitive radio sensor nodes in the network = ∑ ( , + 1) . Therefore, total energy consumed by member node in cluster is given as: Similarly, total energy consumption of clusterhead in cluster is given as: Thus, total energy consumption for the entire network is given as:

Optimal Number of Clusters
Network clustering is a promising technique that can be employed to achieve network scalability, reliable and energy efficient communication. A near-centre member node in a cluster consumes less energy for intra-cluster communication than a near-border member node but both consume maximum power for inter-cluster communication when they are selected as clusterheads [17]. This means a shorter average distance between member nodes and clusterhead requires less energy for intra-cluster communication. Therefore, the number of clusters which influences member nodes distribution in each cluster and average intra-cluster distance are key elements to be considered in minimizing network energy consumption. The optimal number of clusters * need to be carefully determined so that network-wide energy consumption can be minimized. The network is partitioned into number of clusters with each cluster comprises of one clusterhead and 1 − number of member nodes ≈ uniformly distributed within the radio range of the clusterhead . Let denotes average spans for -axis and -axis of each cluster , denotes average cluster area and ( , ) denotes nodes distribution density within a cluster. The Euclidian square distance , between the member node and the clusterhead can be expressed as: If area , of cluster is assumed to be a two dimensional area, then the average span = ⁄ and the node distribution density = / . Thus, Equation (32) can be expressed as: After further simplification, the equation reduces to: Therefore, optimal number of cluster * can be derived analytically from the network wide energy consumption equation which is given as: where = ( + + E )/ denotes the energy costs per bit for sensing events, logging the readings data and sensing set of channels for detecting vacant channels, respectively.

Modelling of RL-Based Clustering
The problem of selecting optimal clusterhead is formulated as a Markov Decision Process (MDP) where a SU learns the energy consumption and local decision accuracy for neighboring clusterheads and then selects an optimal cluster that minimizes energy consumption and improves sensing performance. A quadruple ( , , , ℛ) represents the Markov Decision Process (MDP) for selecting an optimal cluster in the network, denotes set of states in the model of the operating environment s = { , , , … , }, s ∈ , denotes state transition function, denotes a set of actions to be executed = { , , … , }, ∈ , while ℛ denotes the state reward function ( , ) ∈ ℛ [19]. Each of the SUs or the agent selects an action in every state of the model as shown in Figure 5. The selected action leads to sensing a set of channels, reporting local decisions to a clusterhead, computing the energy consumption and evaluating the local decision accuracy for the chosen cluster. Reward obtained from the computed energy consumption and local decision accuracy for state determines the next state and the next action , denotes the stage index of the process. The agent adopts an optimal policy that maximizes the cumulative reward obtained from a known state experience and from exploitation of unknown states to select the optimal clusterhead. States: The state of the MDP stands for the stage at which the agent selects a cluster among the neighboring clusterheads and determines the reward for taking an action in the state. The set | | comprises of states equal to the number of neighbouring clusterheads plus an initialization state which initiates the state transition for selecting the clusterhead. Initialization of the clusterhead selection process begins at = 0, = 0 for = , where = {0, 1, 2, . . . , T} denotes the decision episode, denotes the stage index and ∈ denotes the current state number which indicates the selected clusterhead, if ≠ 0 . Therefore, at every stage index ≠ 0 of the learning process, the state = ∈ for selecting an action ∈ can be expressed as: where ( ) is an indicator function in that: For each episode of the learning process, the agent employs a softmax action selection strategy to select an action , computes the state-action reward ∈ ℛ for the current state = , and then determines the subsequent state = ℎ ∈ . Actions: an action in this context implies a strategic choice made by an agent for selecting a clusterhead among the neighbouring clusterheads | = 1, 2, 3, … , . The selected action = ∈ in every state = ∈ is expected to maximize the current reward for updating Q-value ( , ) . If = ( , , , , … , , , , ) denotes the sequence of state-actions executed from to in episodes = {0, 1, 2, . . . , T} and denotes the corresponding set of selected clusterheads for the state-actions then the action taken can be formulated based on a stochastic process as = ( ) ∈ ( ), where = \{{ } ∪ , denotes a set of selected actions, denotes decision rule that maps the sequence of state-action into a probability distribution ∆ ( ) [3].
To achieve a policy that maximizes long-term rewards, a Boltzmann distribution-based action selection strategy known as softmax is adopted to balance between exploration of random actions and exploitation of state-actions. The strategy selects an action that returns the highest estimated reward for the state-action values based on a probability determined by a positive parameter called temperature. The probability can be expressed as [27]: Transition Probability: The transition probability : × × … . → [0,1] maps the state-action transit to a probability of moving from current state to next state whenever an action is executed in the state . Therefore, the transition probability ( , ⁄ ) from current state = to the next state = ℎ is a function of the action = executed in the current state. However, the adopted learning algorithm which is Q-learning does not require transition probabilities.
Reward function: Reward ℛ ∶ × × … . → is a key component of the MDP model that can be used to evaluate the state-action value for each episode and update the Q-table. It maps the state transition from state to subsequent state for the action taken to an actual value reward [3]. In each episode, the agent selects an action = j to select clusterhead in state = , computes its reward before moving to the next state = ℎ, and then restarts the state = 0 upon reaching the last state. The expected cumulative reward can be computed based on agent's reward for energy consumption , and reward for local decision accuracy , subject to the pairwise constraint condition , . Thus: where = 0, 1, 2, … , − 1 denotes the stage index at episode , the indicator function { } can either be zero or one, depending on . The pairwise constraint condition , can be expressed as: This means that the cumulative reward will be zero if the member node and the chosen clusterhead share no common vacant channel , ∩ , = ∅. The reward for energy consumption , can be obtained from the member node's consumed energy E for transmitting bits of data packet to a neighboring clusterhead and for performing cooperative channel sensing .
Thus, consumed energy is given as: Therefore, a reward of one will be obtained for minimum energy consumption, a reward of half will be awarded for energy consumption less than the maximum consumed energy, while the reward for maximum energy consumed is zero. Thus, the reward for energy consumption is given as: State-action that leads to selection of a clusterhead that leads to low energy consumption receives a higher reward which translates into an increase in the corresponding Q-value and also its chances for likely selection in subsequent states. This means that less favorable clusters that lead to high energy consumptions are more likely to be excluded during the learning process.
Local decision on PU existence in a channel is usually prone to errors due to the channel's propagation impairment which degrades the channel sensing performance. Therefore, the local decision accuracy determines the divergence of an individual member node's sensing outcome compared to the cooperative sensing outcome. The reward for local decision accuracy can be obtained by comparing the local decision ∈ made by member node on PU existence on the channels with the cooperative decisions ∈ which involves other member nodes MNs in the cluster . Therefore, when a set of local decisions matches with a corresponding set of cooperative decisions , then a reward of one will be received, while local decisions that agree with the majority of the corresponding cooperative decisions receive half rewards, local decisions that match the corresponding cooperative decisions with less than half the number of the channels attract a reward of zero (i.e., do not earn a reward). Thus, the reward for local decision accuracy can be expressed as:

The EESA-RLC Algorithm
The algorithm begins with the clustering initialization phase which deals with clusterhead emergence as outlined in Table 1. All SUs (line 1 to line 20) sense a set of predefined channels (line 2), compute their clusterhead probabilities based on the number of vacant channels detected, percentage of clusterheads and their residual energy (line 3). If the clusterhead probability is greater or equal to the threshold, then a clusterhead announcement is broadcast (line 5) and the SU becomes a tentative clusterhead (line 6), otherwise, if the clusterhead probability is less than the threshold and it has heard the clusterhead announcement (line 7), then it waits for the final announcement (line 8) and the SU is a member node (line 9). Another set of SUs (line 10) perform iteration (line 11 to line 18). In each iteration, we increment the probability by a factor (line 12) and compare the result with the threshold (line 13). If it is clusterhead (line 15), it broadcasts an announcement (line 14). The Base Station selects an optimal number of clusterheads among the potential clusterheads (line 21) and broadcasts the list (line 24). The selected clusterheads broadcast advertisement packets to their neighboring SUs (line 24 to line 25). The RL process shown in Table 2 begins immediately after the emergence of clusterheads by setting all state-action values (| |, | |) array and action to zero (line 2) and then carrying out a number of iterations (line 3 to line 30) up to maximum episodes specified in the inputs (line 1). The state transition follows a sequential order (line 4) and is re-started upon reaching the number of clusters (line 28) i.e., number of elements in (line 1). The softmax action selection strategy is employed (line 5) in each episode to select a clusterhead among the prospective clusterheads (line 7). This leads to sensing a set of channels | | (line 8) and computing the energy consumptions (line 9) and then obtaining the associated rewards (line 11 to line 25). The state-action Q-values (line 26) are updated by the cumulative reward (line 10) and the final Q-matrix is determined after the last episode. The state-action that returns the maximum total cumulative reward value (line 31) denotes the optimal policy of selecting a clusterhead and the optimal cluster * is the index of the optimal policy which indicates the cluster (line 32).

Performance Analysis and Evaluation
In this section, we analyze optimality of the EESA-RLC algorithm and evaluate its performance in terms of convergence, complexity and adaptability to model a free dynamic environment in achieving an optimal policy * that minimizes energy consumption while enhancing vacant channel detection. The optimal policy * maximizes the cumulative reward to achieve the optimal cluster * by choosing an optimal clusterhead * for the agent.
In the simulation, we assume a moderate scale network consisting of 250 SUs uniformly distributed in a 90 m × 90 m square area and five PUs randomly deployed in the network. Each PU can operate on one channel such that SUs can only access unused licensed channels for data transmission. Each channel might be free or occupied at any time depending on PU activity. We also consider low power wireless sensor nodes in computing the energy dissipation for spectrum sensing, reporting to clusterheads and data transmission. All SUs are homogenous and uniformly distributed in the network area, therefore in our simulation and mathematical modeling, all radio parameter and energy dissipation values for processing the received signal samples, tuning the detector's circuit to channel's bandwidth and running the electronics circuit are the same. The parameter values used for both analysis and simulation as indicated in Table 3 are either computed based on parameter values obtained from the indicated references or originated from the sources indicated in situ.
The Q-learning and SARSA algorithms were implemented in MATLAB to evaluate the performance of the EESA-RLC algorithm for = 5000 episodes [19]. We set the step size for the exploration of state-action pairs and for learning rate update to  = ( + ) ⁄ , while the discount factor is set to γ = 0.9. The discount factor determines the level priority given to future rewards. A factor of zero makes an agent consider only immediate rewards [48].
After extensive state-actions exploration and clusters exploitation during the learning phase, the EESA-RLC algorithm partitions the network into seven clusters { , , , , , , } which translate into seven different clusterheads { , , , , , , } as shown in Figure 6.
The network consists of 250 uniformly distributed SUs and five PUs randomly deployed in the network. The SUs form seven clusterheads and 243 member nodes. During the learning phase, each member node considers only clusterheads that are within its radio range instead of all seven clusters and chooses the optimal cluster among its neighborhood clusters. The seven clusters which are the optimal number for the network as determined through simulation as shown in Figure 6, are indicated by dashed circles with the corresponding common available channels inscribed in the circle.
To examine the effect of cluster size on the network energy consumption, we determined the energy consumed by both member nodes and their respective clusterheads for different cluster sizes through simulation, as shown in Figure 7. For a fixed number of nodes, when the number of clusters is too small (e.g., 3), each cluster would have a large number of member nodes that communicate with high transmission power. This increases the network energy consumption due to long intra-cluster distance communication between the member nodes and their clusterheads.   On the other hand, for large number of clusters (e.g., 15), the network energy consumption is relatively small, but inter-cluster communication consumes relatively high energy because of the excessive number of clusterheads which in reality consume much more energy than member nodes. Therefore, network energy consumption can be minimized by determining the optimal number of clusters that balances energy consumption for inter-cluster and intra-cluster communications. The result shows that at the minimum network energy consumption, the optimal number of clusters is seven.

Optimality of EESA-RLC Algorithm
The EESA-RLC algorithm allows SUs to learn and adapt to the dynamic environment to achieve an optimal solution through an optimal policy. The optimal solution means the optimal clusterhead * ∈ selected by the cluster member node through the optimal policy * that maximizes cumulative reward . The necessary conditions required to achieve the optimal solution is presented in the following proposition and proof. Proof. In every state , a member node selects a clusterhead ∈ among the set of clusterheads to determine a set of common vacant channels , ∩ , and energy consumption , ( , ) ∈ ( , ) for transmitting data to the clusterhead over distance through the vacant channels. The selected clusterhead with minimum distance ∈ must minimize energy consumption , ∈ ( , ), maximize vacant channels detection , , , and satisfy the pairwise constraint condition , such that , ∩ , ≠ ∅ and obtain the highest reward value for the energy consumption reward , and highest reward value for the local decision accuracy reward , to achieve the maximum cumulative reward value = ∈ , ∈ ∑ ( , ) . If denotes the index of the selected clusterhead ∈ in states that maximizes the cumulative reward , then for each state , j = ∈ ( , ) which denotes the optimal action selection policy * = * and the optimal clusterhead * ∈ .

Convergence and Computational Complexity of the EESA-RLC Algorithm
The algorithm converges to an optimal solution after adequate exploration and exploitation of state-actions pairs. The algorithm's convergence period is a function of some parameter values which include action selection strategy, discount factor and learning rate. We simulate the Q-learning and SARSA RL algorithms to examine the convergence of the algorithms over = 5000 episodes and evaluate their performance as shown in Figure 8. The result indicates that both the learning algorithms converged to the optimal solution but after different numbers of episodes. The SARSA learning algorithm converged to the optimal value after = 3020 episodes and achieved a maximum average expected cumulative reward value of = 0.52 which is much higher than that of the Q-learning algorithm. On the other hand, the Q-learning algorithm converged to an optimal solution at = 2020 which is much lower than SARSA and achieved a maximum expected cumulative reward value of = 0.44. This suggests that the Q-learning algorithm converges to optimal solution in a relatively short learning period because of its reliance on an action selection strategy rather than cluster exploration to update its estimated optimal policy. In contrast, cluster explorations while updating the Q-value slows the convergence of the SARSA algorithm due to the extension of its learning period, but this of course yields a better expected accumulative reward. It can be concluded that learning period has a significant effect on the convergence of the algorithms, increasing as the number of episodes increases which in turn decreases the learning rate and therefore, the algorithm converges slower. Optimal clustering can be achieved through many techniques. While some techniques employ computationally infeasible approaches such as exhaustive search techniques which try all possible options for efficient clustering and select the best option among them, while others employ less computationally complex approaches based on heuristic techniques such as hierarchical, k-means, c-means and fuzzy clustering, etc. For example, the GWSA approach performs a high number of iterations to merge the nearest clusters in the nodes' proximity matrix till an optimal solution is achieved [17]. However, its overall computational complexity ( ) is extremely high and increases proportionally with increase in size of the number of cognitive radio sensor nodes which make it impractical to implement in a large scale network. Distributed Group Wise Spectrum Aware (DGWSA) offers relatively low complexity as shown in Figure 9 [18]. This approach merges multiple neighboring cluster pairs at every iteration instead of using a proximity matrix and its complexity largely depends on the size of neighboring clusters instead of network size. Therefore, we compare the computational complexity of our algorithm with that of the GWSA and DGWSA algorithms by increasing the size of the cognitive radio sensor nodes as shown in Figure 9. The result shows that the GWSA algorithm offers high computational complexity, which increases with size of the network, while our algorithm and the DGWSA one achieve much lower complexities that are largely influenced by the number of neighboring clusters.
We employed Q-learning to evaluate the performance of our algorithm in terms of learning and adaptability to a dynamic environment in achieving an optimal solution. Our choice for Q-learning is due to its faster convergece which requires a shorter learning period. We examined the performance of a single MN that learns and determines cumulative average rewards for each selected clusterhead in a total number episodes of = 5000, as shown in Figure 10. We also examined the influence of the two metric functions, viz energy consumption and local decision accuracy, on the optimal cluster selection as shown in Figure 11.   The cumulative average reward represents the average reward obtained for energy consumption and local decision accuracy during the learning process. Figure 10 shows cumulative average for the three clusterheads , , that are within the radio range of the MN without the remaining four clusterheads , , , that have no direct link with the MN. The result indicates that clusterhead attracts the highest cumulative average reward of = 0.65, followed by clusterhead which attracts cumulative average reward of = 0.4, while clusterhead receives the lowest cumulative average reward of = 0.12 . This indicates that the agent learns and adapts to the environment through exploration of the neighbouring clusterheads and exploitation of actions that attract favourable rewards to return clusterhead as the optimal clusterhead. Figure 11 shows the effect of energy dissipation and local decision accuracy on selecting a clusterhead during the learning phase and choosing the optimal clusterhead. The agent learns the energy and cooperative sensing costs for each of the neighboring clusterhead and then selects the most favorable clusterhead that satisfies the pairwise constraints and minimum energy dissipation requirements as the optimal clusterhead. The local decision accuracy indicates the success of individual MN's local decision about channels occupancy in respect to cooperative decision. In this context, local decisions are considered to be accurate when local decisions about a set of channels agree with the cooperative decisions irrespective whether the channels are available or not. Therefore, it can be deduced from the result, all the three clusterheads , and have satisfied the pairwise constraint which requires at least one common available channel between the MN and the clusterhead but only clusterhead satisfied the minimum energy consumption requirement with the highest reward value = 0.98. This suggests that significant amount of energy can be saved when the MN selects as the optimal cluster as compared to which attracts zero reward = 0 for energy consumption. Therefore, it is extremely important to consider not only cooperative sensing success, but also energy consumption when choosing the optimal clusters. To evaluate the performance of our algorithm, we used GWSA [17] clustering as the benchmark for comparison, since it also considers spectrum-aware constraints in the network clustering and converges to optimal clusters. We first implemented the algorithms and obtained the optimal clustering through simulation, and then compared the performance of GWSA with our algorithm in terms of network energy minimization and spectrum sensing enhancement. Based on member nodes' distances to their respective clusterheads in each cluster and clusterheads' distances to the BS obtained from each of the clustering scheme, we determined Sum of Square Error (SSE) for the network, and computed network energy consumption and determined probability of detection for the two schemes as shown in Figures 12-14 respectively. Figure 12 compares the average SSE for different numbers of member nodes for the two clustering schemes. The SSE is a key component for determining the performance of clustering schemes in terms of network energy efficiency. Less SSE translates into minimum network energy consumption, which means more energy efficiency can be achieved with the clustering schemes that has less SSE. The result shows that SSE increases along with increase in number of member nodes. It is observed that our clustering scheme achieves much lower SSE than the GWSA. For example SSE for 200 member nodes is approximately 100 which is 50% less than that of GWSA for the same size of member nodes. This suggests that our approach is more energy efficient.    Figure 13 further reveals the performance improvement of our approach over the GWSA in terms energy efficiency. The result indicates that average energy dissipation decreases with increase in size of clusters. It is evident from the result that our approach achieved the least average energy dissipation compared with the GWSA approach. For example, the average energy dissipation for a five-cluster size of our approach is about 60 J, which is 8.4% lower than that of GWSA approach for the same cluster size. Furthermore, the total network energy dissipation based on our clustering scheme is 417.3 J, while that of GWSA is 458.8 J. This implies that an energy savings of 9% can be achieved with our approach. This shows that the RL-based approach learns energy dissipation for each neighboring cluster through exploration of the clusters and chooses the most favorable cluster that attracts low dissipation through exploitation. Figure 14 compares the average probability of detection Qd for the two clustering schemes with different numbers of cognitive radio sensor nodes. The result indicates that our approach performs much better than the GWSA clustering scheme in terms PU detection. This is because the GWSA approach does not incorporate cooperative spectrum sensing which is vital for improving PU detection. It is observed that the average cooperative probability of detection Qd of our approach rapidly reaches a relatively high value that satisfies the required detection accuracy of ≥ . at the initial stage and then increases slowly with increasing number of cognitive radio sensor nodes. This suggests that multi-user sensing diversity exploration is crucial for enhancing PU detection and discovering of more spectrum opportunity.

Conclusions
In this paper, we propose a novel spectrum-aware clustering algorithm based on reinforcement learning to minimize network energy consumption and enhance channel sensing in cognitive radio sensor networks. We first modelled the network energy consumptions in terms of cooperative channel sensing, and inter-cluster and intra-cluster data communication energy consumptions, and then show that network energy consumptions can be minimized by determining an optimal number of clusters that balances energy consumption for inter-cluster and intra-cluster communications. The problem of nodes to choose their respective optimal clusters is formulated as a Markov decision problem and the results obtained show that the algorithm is capable of adapting to a dynamic environment and converging to an optimal solution.
We also showed that pairwise constraints can be implemented in spectrum-aware clustering to improve primary user detection. Also the energy cost and local decision accuracy have a significant influence on determining the optimal cluster. We further showed through simulations the performance improvement of our approach over groupwise constraint-based algorithms in terms of energy efficiency, channels sensing performance and computational complexity, which are vital to resource constrained devices such as CR-WSN.