An adaptive algorithm for anomaly and novelty detection in evolving data streams

In the era of big data, considerable research focus is being put on designing efficient algorithms capable of learning and extracting high-level knowledge from ubiquitous data streams in an online fashion. While, most existing algorithms assume that data samples are drawn from a stationary distribution, several complex environments deal with data streams that are subject to change over time. Taking this aspect into consideration is an important step towards building truly aware and intelligent systems. In this paper, we propose GNG-A, an adaptive method for incremental unsupervised learning from evolving data streams experiencing various types of change. The proposed method maintains a continuously updated network (graph) of neurons by extending the Growing Neural Gas algorithm with three complementary mechanisms, allowing it to closely track both gradual and sudden changes in the data distribution. First, an adaptation mechanism handles local changes where the distribution is only non-stationary in some regions of the feature space. Second, an adaptive forgetting mechanism identifies and removes neurons that become irrelevant due to the evolving nature of the stream. Finally, a probabilistic evolution mechanism creates new neurons when there is a need to represent data in new regions of the feature space. The proposed method is demonstrated for anomaly and novelty detection in non-stationary environments. Results show that the method handles different data distributions and efficiently reacts to various types of change.


Introduction
Usual machine learning and data mining methods learn a model by performing several passes over a static dataset.Such methods are not suitable when the data is massive and continuously arriving as a stream.With the big data phenomenon, designing efficient algorithms for incremental learning from data streams is attracting more and more research attention.Several domains require an online processing where each data point is visited only once and processed as soon as it is available, e.g., due to realtime or limited memory constraints.Applications in dynamic environments experience the so-called concept drift (Gama et al. 2014) where the target concepts or the data characteristics change over time.Such change in streaming data can happen at different speed, being sudden (Nishida et al. 2008;Gama et al. 2004) or progressive (Ditzler and Polikar 2013;GonçAlves and Barros 2013).Change in streaming data also includes the so called concept evolution (Masud et al. 2010) where new concepts (e.g., classes or clusters) can emerge and disappear at any point in time.Most existing methods, such as those reviewed in Gama et al. (2014) and Žliobaitė et al. (2016), address the problem of concept drift and evolution with a focus on supervised learning tasks.In this paper, we focus on online unsupervised learning from an evolving data stream.Specifically, we address the question of how to incrementally adapt to changes in a non-stationary distribution without requiring sensitive hyper-parameters to be manually tuned.
The problem is both interesting and important as evolving data streams are present in a large number of dynamic processes (Žliobaitė et al. 2016).For example, on-board vehicle signals (e.g., air pressure or engine temperature), often used to detect anomalies and deviations (Byttner et al. 2011;Fan et al. 2015b, a), are subject to changes due to external factors such as seasons.Other examples include decision support systems in the healthcare domain (Middleton et al. 2016) where advances in medicine lead to gradual changes in diagnoses and treatments, modeling of the human behavior which naturally change over time (Webb et al. 2001;Pentland and Liu 1999), or the tracking of moving objects on a video (Santosh et al. 2013;Patel and Thakore 2013), to mention but a few.
A naive approach to address the problem of evolving data streams would be to periodically retrain the machine learning model of interest.However, such retraining being triggered without detecting whether it is currently needed or not, often leads to wasted computations.The most widely used approach to deal with changes in data steams consists of training the model based on a sliding window (Zhang et al. 2017;Hong and Vatsavai 2016;Ahmed et al. 2008;Bifet and Gavalda 2007;Jiang et al. 2011).However, choosing a correct window size is not straightforward, since it depends on the speed and type of changes, which are usually unknown.Moreover, existing approaches are specialized for a particular type of change (e.g., sudden, progressive, cyclic).There exist few methods which can handle different types of concept drift, such as (Losing et al. 2016;Dongre and Malik 2014;Webb et al. 2016;Brzezinski and Stefanowski 2014), however, most of those methods are dedicated for supervised learning problems, where the change is primarily detected by estimating a degradation in the classification performance.Other approaches such as (Kifer et al. 2004;Bifet 2010) are designed to explicitly detect, in an unsupervised way, when a change happens.Unfortunately, such approaches require hyper-parameters which are hard to set manually when no prior knowledge is available.
Unsupervised neural learning methods such as Fritzke (1995), Prudent and Ennaji (2005) and Shen et al. (2013) are good candidates for modeling dynamic environments as they are trained incrementally and take into account relations of neighborhood between neurons (data representatives).Specifically, the Growing Neural Gas (GNG) algorithm (Fritzke 1995) creates neurons and edges between them during learning by continuously updating a graph of neurons using a competitive Hebbian learning strategy (Martinetz et al. 1993), allowing it to represent any data topology.This provides an important feature in the context of unsupervised learning from data streams where no prior knowledge about the data is available.However, GNG does not explicitly handle changes in the data distribution.
Some adaptations of GNG such as Frezza-Buet (2014), Shen et al. (2013), Marsland et al. (2002) and Fritzke (1997) try to address some of the problems related to either concept evolution (Shen et al. 2013;Marsland et al. 2002) or drift (Frezza-Buet 2014;Fritzke 1997).However, these methods require an expert to specify some sensitive parameters that directly affect the evolution or the forgetting rate of the neural network.Setting such global parameters prior to the learning does not address the more general case where the speed of changes can vary over time, or when the distribution becomes non-stationary only in some specific regions of the feature space.
We propose in this paper an extension of the GNG algorithm named GNG-A (for Adaptive) and we show how it is used for novelty and anomaly detection in evolving data streams.The contributions of this paper are summarized as follows.First, an adaptive learning rate which depends on local characteristics of each neuron is proposed.Such learning rate allows for a better adaptation of the neurons in stationary and non-stationary distributions.Second, a criterion characterizing the relevance of neurons is proposed and used to remove neurons that become irrelevant due to a change in the data distribution.An adaptive threshold for removing irrelevant neurons while ensuring consistency when no change occurs is also proposed.Third, a probabilistic criterion is defined to create new neurons in the network when there is a need to represent new regions of the feature space.The probabilistic criterion depends on the competitiveness between neurons and ensures stabilization of the network's size if the distribution is stationary.The proposed method is adaptive, highly dynamic, and does not depend on critical parameters.It is fully online as it visits each data point only once, and can adapt to various types of change in the data distribution.
This paper is organized as follows.In Sect. 2 we give a background related to the growing neural gas based methods.In Sect. 3 we propose a mechanism that allows to continuously adapt neurons in order to closely follow a shift in the data distribution.In Sect. 4 we present an adaptive forgetting mechanism that allows to detect and remove neurons that become irrelevant as a consequence of a change in the data distribution.In Sect. 5 we present an evolution mechanism that allows to create new neurons when necessary.In Sect.6 we summarize the proposed algorithm and we show how it is used for novelty and anomaly detection.In Sect.7 we justify the contribution using experimental evaluation.Finally, we conclude and present future work in Sect.8.

Preliminaries and related work
In this section, we describe the self-organizing unsupervised learning methods that are at the origin of the algorithm proposed in this paper.
The neural gas (NG) (Martinetz et al. 1993) is a simple algorithm based on the self-organizing maps (Kohonen 1998), which seeks an optimal representation of an input data by a set of representatives called neurons, where each neuron is represented as a feature vector.In this algorithm, the number of neurons is finite and set manually.This constitutes a major drawback, because the number of representatives needed to approximate any given distribution, is usually unknown.
The growing neural gas algorithm (GNG) (Fritzke 1995) solves the previous problem by allowing the number of neurons to increase.It maintains a graph G which takes into account the neighborhood relations between neurons (vertices of the graph).As shown in Algorithm 1, a minimum number of neurons is initially created (line 3), then, new neurons and new neighborhood connections (edges) are added between them during learning, according to the input instances.For each new instance x from the stream (line 4), the two nearest neurons n * x and n * * x are found (line 6) as follows where a−b is the Euclidean distance between vectors a and b.A local representation error err n * x is increased for the wining neuron n * x (line 7) and the age of the edges connected to this neuron is updated (line 8).The wining neuron (i.e., n * x ) is adapted to get closer to x, according to a learning rate 1 ∈ [0, 1].The neighboring neurons (linked to n * x by an edge) are also adapted according to a learning rate 2 < 1 (line 9).Furthermore, the two neurons n * x and n * * x are linked by a new edge (of age 0).The edges that reached a maximum age a max without being reset, are deleted.If, as a consequence, any neuron becomes isolated, it is also deleted (lines 10-13).The creation of a new neuron is done periodically (i.e., after each λ iterations) between the two neighboring neurons that have accumulated the largest representation error (lines 14-20).Finally, the representation error of all neurons is subject to an exponential decay (line 21) in order to emphasize the importance of the most recently measured errors.
The preservation of neighborhood relations in GNG allows it to represent data of any shape (as shown on Fig. 1), which makes it particularly interesting for a wide range of applications.However, in a non-stationary environment, the GNG algorithm suffers from several drawbacks.
First, it organizes neurons to represent the input distribution by continuously adapting the feature vectors of neurons based on two learning rates 1 , 2 (see Algorithm 1, Algorithm 1 Growing Neural Gas (GNG) 1: Input: 1 , 2 , a max , λ 2: t ← 0 3: Initialize graph G with at least 2 neurons 4: for each new instance x from the stream do 5: t ← t + 1 6: Let n * x , n * * x be the two neurons closest to x 7: Increment the age of n * x 's edges 9: Adapt n * x and its neighbors (linked to n * x ) Remove neurons that become isolated 14: if t is multiple of λ then 15: Let n q = argmax n∈G err n 16: Let n f = argmax n∈Neighbours(n q ) err n 17: Create a new neuron n new between n q and n f 18: n new = 0.5 × (n q + n f ) 19: err n new = 0.5 × err n q 20: end if 21: Exponentially decrease the representation error of all neurons: ∀n ∈ G : err n ← 0.9 × err n 22: end for Fig. 1 GNG is able to learn the topology of data in a stationary environment line 9), whose values are set manually.If those values are not chosen appropriately, the neural network will not be able to closely follow changes in the data distribution.Second, when the distribution changes fast, many neurons will not be updated anymore, and will consequently not be able to follow the change.As such neurons do not become isolated, they will never be removed by GNG. Figure 2 shows a data distribution which initially forms one cluster and then splits into two clusters.The first cluster, in the bottom left region of Fig. 2(1), is stationary.The other cluster is Fig. 2 In GNG, with a non-stationary distribution, some irrelevant neurons are not updated anymore and are never removed moving and getting farther from the first cluster, as shown by the sequence of Fig. 2ad.Neurons that are not able to follow the moving cluster are kept as part of the graph even if they not relevant anymore.
Third, the GNG algorithm suffers from the need to choose the parameter λ (see Algorithm 1, line 14), used to periodically create a new neuron.The periodic evolution of the neural network is clearly not convenient for handling sudden changes where new neurons need to be created immediately.Some adaptations of GNG, like those proposed in Prudent and Ennaji (2005), Shen et al. (2013) and Marsland et al. (2002), try to overcome the problem of periodic evolution by replacing the parameter λ by a distance threshold which can be defined globally or according to local characteristics of each neuron.For each new instance x, if x − n * x is higher than some threshold, then a new neuron is created at the position of x.However, although this overcomes the problem of periodic evolution, setting an appropriate value for the threshold is not straightforward as it highly depends on the unknown distribution of the input data.Moreover, such methods are more prone to representing noise because they create a new neuron directly at the position of x instead of regions where the accumulated representation error is highest (as in the original GNG).
There exist several variants of GNG for non-stationary environments such as Frezza-Buet (2014), Fritzke (1997) andFrezza-Buet (2008).Perhaps the most known variant is GNG-U (Fritzke 1997) which is proposed by the original authors of GNG.It defines a utility measure that removes neurons located in low density regions and inserts them in regions of high density.The utility measure is defined as follows.Let n r be the neuron with the lowest estimated density u n r .Let n q be the neuron which accumulated the highest representation error err n q (as in line 15 of Algorithm 1).If the ratio err nq u nr is higher than some threshold θ , then the neuron n r is removed from its current location and inserted close to n q .However, the threshold θ is yet another user defined parameter which is hard to set because the ratio err nq u nr is unbounded and highly depend on the input data.Moreover, removing n r and immediately inserting it close to n q assumes that the distribution is shifting (i.e., the removal and insertion operations are synchronized).Yet, in many cases, we may need to create new neurons without necessarily removing others (e.g., the appearance of a new cluster).Moreover, the evolution of the neural network is still periodic, as in GNG.The only way to limit the network's size is to set a user-specified limit on the number of neurons, which otherwise leads to a permanent increase in the size of the network.
A state of the art method called GNG-T (Frezza-Buet 2014), which is an improved version of the method proposed in Frezza-Buet (2008), allows to follow non-stationary distributions by controlling the representation error of the neural network.During an epoch of N successive iterations (i.e., successive inputs to the algorithm), let {x i j } 1≤ j≤l i denote the set of l i input data for which n i is the winning neuron.Then the representation error of the neuron n i is defined as The method determines the σ -shortest confidence interval (Guenther 1969) (E min , E max ) based on the errors of all neurons {E n i } n i ∈G .Let T be a target representation error specified by the user.GNG-T seeks to keep the representation error of the neural network close to T by maintaining T ∈ [E min , E max ].More specifically, after each period, if E max becomes less than T , then a neuron is removed.Similarly, if E min becomes higher than T , then a new neuron is inserted.After each epoch, the neurons that have not won are simply considered as irrelevant, and are removed.GNG-T is the closest work to what we propose in this paper.Unfortunately, it depends on critical parameters (mainly, the epoch N , the target error T and the confidence σ ) which directly guide the insertion and removal of neurons.Moreover, splitting the stream into epochs of N successive input data means that GNG-T is only partially online.
In order to relax the constraints related to GNG and its derivatives in non-stationary environments we propose, in the following sections, new mechanisms for: (1) a better adaptation of the neurons in stationary and non-stationary distributions (Sect.3); (2) an adaptive removal of irrelevant neurons, while ensuring consistency when no change occurs (Sect.4); (3) creating new neurons when necessary, while ensuring stabilization of the network's size if the distribution is stationary (Sect.5).

Adaptation of existing neurons
GNG, and the self-organizing neural gas based methods in general, can intrinsically adapt to the slowly changing distributions by continuously updating the feature vector of neurons.As shown in Algorithm 1 (line 9), this adaptation depends on two constant learning rates 1 (for adapting the closest neuron n * x to the input) and 2 (for adapting the topological neighbors of n * x ) such that 0 < 2 < 1 1.If the learning rates 1 and 2 are too small, then neurons learn very little from their assigned data points.This causes the neural network to adapt very slowly to the data distribution.In contrast, too high learning rates can cause the neural network to oscillate too much.
Many existing methods try to address this problem by decreasing the learning rate over time (also referred to as "annealing" the learning rate), so that the network converges, the same way as it is done for the stochastic gradient descent (Zeiler 2012).However, in a streaming setting, as time goes, this may cause neurons to adapt very slowly to changes in data distribution that happen far in the future (as the learning rate will be very small).Moreover, such a global learning rate is not convenient for handling local changes where the distribution is only stationary in some regions of feature space.Some methods like (Shen et al. 2013) define the learning rate for the winning neuron n * x as being inversely proportional to the number of instances associated with that neuron (i.e., the more it learns, the more it becomes stable).However, such learning rate is constantly decreasing over time, thus still causes neurons to adapt slowly to changes in data distribution as time goes.
In order to closely follow the changing distribution and properly handle local changes, we propose to use an adaptive local learning rate n for each neuron n.Intuitively, a local change is likely to increase the local error of nearby neurons without affecting the ones far away.Therefore, we define the learning rate of a neuron n as being related to its local error err n .By doing so, at each point in time, the learning rate of each neuron can increase or decrease, depending on the locally accumulated error.
Let E be the set of local errors for all neurons in the graph G, sorted in the descending order (i.e., from high error to low error).The learning rate for each neuron n ∈ G is then defined as follows where Index(err n , E) is the index (or rank) of err n in E. Therefore, we define the learning rate used for adapting the winning neuron as 1 = n * x , and the learning rate for adapting each neighboring neuron n v ∈ Neighbors(n * x ) as 2 = min( 1 , n v ).By adapting the wining neurons with a learning rate which depends on the ordering of their local errors, the algorithm manages to better adapt to local changes.However, it should be noted that when the number of neurons is static and the concepts are stationary, the learning rates will still be different for different neurons in the network.An alternative solution consists in adapting the learning rates by magnitude instead of ordering.However, this solution is prone to outliers and the local errors are constantly subject to an exponential decay, making their values significantly different from each other.Therefore, we prefer to use the solution which is based on ordering.

Forgetting by removing irrelevant neurons
Dealing with concept drifting data implies not only adapting to the new data but also forgetting the information that is no longer relevant.GNG is able to remove neurons that become isolated after removing old edges (lines 12-13 of Algorithm 1).However, as shown previously on Fig. 2, when the data distribution changes sufficiently fast, some neurons will not be adapted anymore and they will still be kept, representing old data points that are no longer relevant.The forgetting mechanism proposed in this section allows us to eliminate such irrelevant neurons in an adaptive way.

Estimating the relevance of a neuron
In order to estimate the "relevance" of neurons, we introduce a local variable C n for each neuron n.This local variable allows to ensure that removing neurons will not negatively affect the currently represented data when no change occurs.For this purpose, C n captures the cost of removing the neuron n.This cost represents how much the total error of the neighboring neurons of n would increase, if n is removed.In order to define C n , let us consider x i } as the set of instances (data points) associated with a given neuron n (instances closest to n, i.e., for which n was winner).
If n is removed, instances in X n would be associated to their nearest neurons in the neighborhood of n.Associating an instance x i ∈ X n to its (newly) nearest neuron n * * x i would increase the local error of that neuron by x − n * * x i .Therefore, we define C n for a neuron n according to the distance from its associated instances to their second nearest neurons, as follows where t is the current time step (i.e., t'th instance from the stream), and 1(Cond) is the 0-1 indicator function of condition Cond, defined as In order to compute an approximation of C n for each neuron n in an online fashion, each time a new instance x is received from the stream, the local variable C n * x of its closest neuron n * x (i.e., the winning neuron) is increased by x − n * * x (i.e., by the distance to the second closest neuron) (2) The local variable C n is then an estimation for the cost of removing the neuron n.At each iteration, this local variable is exponentially decreased for all the existing neurons (the same way as it is done for the local representation error in line 21 of Algorithm 1): ∀n ∈ G, C n ← 0.9 × C n . (3) It follows that a very small value C n for a neuron n, may indicate two things.First, when the distribution is stationary, it indicates that n is competing with other neurons in its neighborhood (i.e., the cost of removing n is low), which suggests that the data points associated with n can be safely represented by its neighboring neurons instead.
Second, when the distribution is not stationary, a low value of C n indicates that n is no longer often selected as the closest neuron to the input data point, which suggests that it is no longer relevant.In both of those cases, n can be safely removed for a sufficiently small value of C n .Note that if n is the closest neuron to some input data points but is far away from these points (i.e.all the neurons are far from these data points, since n is the closest), then C n is high because n needs to be adapted to represent these data points instead of being removed.
Let us denote by n the neuron which is most likely to be removed (i.e. with the smallest C n ): Naturally, the forgetting can be triggered by removing n if the value of its local variable C n falls below a given threshold.However, such value may quickly become small (approaching 0) as it is constantly subject to an exponential decay, which makes it hard to directly set a threshold on this value.Instead of removing n when C n is sufficiently small, a more convenient strategy is to remove it when − log C n is sufficiently high, that is, when where τ is an upper survival threshold.The smaller τ , the faster the forgetting.Larger values of τ would imply a longer term memory (i.e.forgetting less quickly).The exact value of the threshold τ depends, among other factors, on the data distribution and how fast it is changing.This is clearly an unknown information.Therefore, a problem that still remains is: when do we trigger the forgetting mechanism?In other words, how do we decide that C n is sufficiently small, without requiring the user to directly specify such a sensitive threshold?To define a convenient value for τ , we propose in the following subsection an adaptive threshold.
In order to analyze the proposed removal process for a given neuron n, remember that C n is exponentially decreased at each iteration according to Eq. 3 and only increased when n is a winning neuron according to Eq. 2. Since x − n * * x can be assumed to be bounded and to simplify the analysis, let us assume that when n wins, C n is simply increased by a constant value, e.g. 1.If the input data follow a stationary uniform distribution and the number of neurons at some iteration is g, then n is expected to win once after g iterations.Therefore, C n decreases g times according Eq. 3 before it is increased by 1.In this case, C n at time t can be expressed as: n = (((1 × 0.9 g 1 + 1) × 0.9 g 2 + 1) × 0.9 g 3 + • • • + 1) * 0.9 g v , (4) where v is the winning count1 of n, and g i is the number of neurons at the i'th time where n was winner.If the number of neurons is fixed, i.e., g 1 = g 2 = • • • = g, then v = t g and C n becomes the sum of a geometric series: n = 0.9 g + 0.9 2g + 0.9 3g + • • • + 0.9 vg = 0.9 g 1 − 0.9 g (1 − 0.9 t ).
In this case, C n represents a stationary process because lim t→∞ C (t) n = 0.9 g 1−0.9 g and neurons will not be removed (i.e. the network stays stable).However, if the distribution changes and n is not winning anymore, then it is obvious that C n will keep decreasing and n get's removed as soon as C n falls below τ .In this case, if c 0 is the last value of C n when n was winner, then n is removed when c 0 × 0.9 α ≤ τ .In order words, n is removed after α = 1 log 0.9 log τ c 0 iterations.

Adaptive removal of neurons
In order to motivate the adaptive threshold we propose, let us consider Fig. 3, which shows the value of − log C n for a stationary (blue curve) and a non-stationary (red curve) distributions.On the one hand, if the neuron n has not been selected as winner during some short period of time, then − log C n may temporarily be high, but would decrease again as soon as n is updated (see the blue curve on Fig. 3).In this case, if the threshold τ is chosen too low, then it wrongly causes n to be immediately removed.On the other hand, if n is not anymore selected as winner (in the case of a non-stationary distribution), then − log C n keeps increasing (see the red curve on Fig. 3).In this case, if the threshold τ is chosen too high, then it causes long delay in removing neurons that are not relevant anymore (leading to results similar to those previously shown on Fig. 2), which is not in favor of a real-time tracking of the non-stationary distribution.
In order to automatically adapt the threshold τ , we consider the two following cases: 1. Increasing τ : If − log C n > τ (i.e., n should be removed) but n would still be winning in the future, then the threshold τ should be increased (to remove less neurons in the future).The reason for increasing τ in this case is that a neuron which should be removed is expected to not be winner anymore (or very rarely) in the future.2. Decreasing τ : If − log C n ≤ τ (i.e., n is not removed) but n is not winning anymore, then the threshold τ should be decreased (to remove more neurons in the future).The reason for decreasing τ in this case is that a neuron which is not removed is expected to be a winner sufficiently frequently.To address the first case, when a neuron n is removed from G because − log C n > τ, we do not discard it completely; instead, we keep it temporarily, in order to use it for a possible adaptation of the threshold τ .Let R be a buffer (a Queue with FIFO order) where the removed neurons are temporarily kept2 .Let x be a new instance from the stream, and n * x be the nearest neuron to , then r * x would have been the winner instead of n * x .In this case, we increase τ as follows: where ∈ [0, 1] is a small learning rate (discussed thereafter in this section).Finally, we need to design a strategy to maintain the R buffer.Let W n be the number of times where a neuron n has been winner during the W last time steps (iterations).Let R = {r ∈ R|W r = 0} be the subset of neurons from R that has never been a winner during the W last time steps.If |R | > k (i.e., a sufficient number of neurons are not updated anymore), then we definitively remove the oldest neuron from R.
For the second case, let |{n ∈ G|W n = 0}| be the number of neurons from G that has never been a winner during the W last time steps.If this number is higher than k and − log C n ≤ τ , then we decrease τ as follows: The learning rate ∈ [0, 1] used in Eqs. 5 and 6 for updating τ can be decreased over time, as shown in Eq. 7, so that τ converges more quickly.
where N τ is the number of times where τ has been updated (increased or decreased).Alternatively, can be kept constant if the speed of the changing distribution is expected to change over time (i.e., acceleration is not constant), depending on the application domain.
In order to give a chance for each neuron in G to be selected as winner at least once, W needs to be at least equal to the number of neurons.Therefore, instead of having a manually fixed value for W , this latter is simply increased if the number of neurons reaches W (i.e. if |G| ≥ W ). Note that in all our experiments W is simply increased by 10 each time |G| ≥ W .
Besides, the parameter k plays a role in the adaptation of the threshold τ used to remove neurons.If more than k neurons are not updated anymore (i.e.their W n = 0), then τ is adapted to increase the chance of removing such neurons in future.Consequently, higher values of k lead to a less frequent adaptation of τ (i.e.promoting more stability).Note that setting k to a too high value can introduce some delay in removing irrelevant neurons.On the opposite side, by setting k too low (e.g.k = 1), it is possible (even when the distribution is stationary) that any neuron n would occasionally have W n = 0 and causes the adaptation of τ .

Dynamic creation of new neurons
As explained in Sect.2, GNG creates a new neuron periodically.If there is a sudden change in the distribution and data points starts to come in new regions of the feature space, the algorithm cannot immediately adapt to represent those regions.This is mainly due to the fact that a new neuron is created only every λ iterations.In many real-time applications, new neurons need to be created immediately without affecting the existing ones (i.e., concept evolution).In order to handle such changes faster, we propose a dynamic strategy that allows creation of new neurons when necessary.The proposed strategy ensures that less neurons are created when the distribution is stationary, while being able to create more neurons if necessary, i.e. when there is a change in the data distribution.
Remember that W n is the number of times where a neuron n has been winner during the W last time steps (iterations).Let us define the ratio W n W ∈ [0, 1] as the winning frequency of a neuron n.When the number of neurons in G is low, their winning frequency is high.This is essentially due to a low competition between neurons, which gives a higher chance for each neuron to be selected as winner.An extreme case example is when G contains only one neuron which is always winning (i.e. its winning frequency is 1).In contrast, as the number of neurons in G increases, their winning frequency decreases due to a higher competitiveness between neurons.We propose a strategy for creating new neurons in a probabilistic way, based on the current winning frequency of neurons in G.
Let f q ∈ [0, 1] be the overall winning frequency in the graph G defined as Fig. 4 The value of f q with synthetic data, in two cases: a stationary distribution (blue) and a non-stationary distribution (red) (Color figure online) where S is a set of k neurons with the highest winning frequencies3 among all neurons in G.The higher the overall winning frequency f q , the higher the probability of creating a new neuron, and vice-versa.
Let S be a set of k neurons with the highest winning frequencies.It is easy to prove that for any k > k (i.e. S ⊂ S ), we have Therefore, higher values of k lead to creating neurons less frequently (i.e.promoting more stability).
If the data distribution is stationary, then creating new neurons is likely to decrease f q , which implies a smaller probability to create more neurons in the future.However, if there is a change in the data distribution so that new neurons actually need to be created, then f q will automatically increase (which leads to a higher probability of creating more neurons).Indeed, let us assume that data points from a new cluster start to appear.Some existing neurons that are the closest to those points will be selected as winner, making their winning frequencies high, which consequently increases rm f q .As f q increases, there is more chance for creating new neurons to represent the new cluster.This is illustrated in Fig. 4 which shows f q for a stationary distribution (blue curve) and for a non-stationary distribution (red curve) where a new cluster is suddenly introduced after time step 1000 .
The insertion of a new neuron is done with a probability proportional to f q .However, in order to lower the chance of performing insertions too close in time and give time for the newly inserted neuron to adapt, we introduce a retarder term r t defined as follows: where t is the current time step and t < t is the previous time when the last insertion of a neuron occurred.Hence, a new neuron is created with a probability max(0, f q − r t ).
In other words, a new neuron is created if rand < f q − r t , where rand ∈ [0, 1] is randomly generated according to a uniform distribution.
For the purpose of analysis, let us assume that the input data follow a stationary uniform distribution.If |G| = g is the number of neurons at some iteration t, then all neurons are equally likely to win and the winning frequency of each neuron is g .Since the insertion of a new neuron happens with a probability which is essentially f q , then when |G| = 2, f q = 1 2 and a new neuron is added after 2 iterations; when |G| = 3, f q = 1 3 and one more neuron is added after 3 more iterations, etc.Thus, the expected number of neurons at time t (when no removal occurs) can be expressed as: e.g. at t = 10 iterations, g = 4 neurons Therefore, if no removal occurs, the number of neurons increases continuously (but slowly) over time.However, as the number of neurons increases, each neuron will win less frequently.It follows that some neurons would have their C n decreasing and would eventually be removed, keeping the number of neurons stable.In order to show that C n decreases, let us consider again Eq. 4. If the initial number of neurons is g 1 = 1, then as explained previously, after two more iterations g 2 = 2, and after three more iterations g 3 = 3, etc.Therefore Eq. 4 becomes: The sum above has no closed-form expression.However, it can be re-written recursively as C (t) n = 0.9 t (C (t−1) n + 1), and it is easy to show that ∀t > t > 5, we have n .Therefore, n would eventually be removed as C n is monotonically decreasing.

Algorithm
GNG-A is summarized in Algorithm 2, which makes a call to Algorithm 3 to check for the removal of neurons (see Sect. 4) and Algorithm 4 to check for the creation of neurons (see Sect. 5).
First, Algorithm 2 initializes the graph G with two neurons (line 3).For each new data point x, the two nearest neurons n * x and n * * x are found (line 7).The local error err n * x is updated for the wining neuron n * x and the age of the edges emanating from this neuron is incremented (lines 8-9).The local relevance variable C n * x is increased in order to record the cost of removing this neuron (line 10), as described in Sect.4.1.

Algorithm 2 Proposed method (GNG-A)
1: Input: k (used in Algorithms 3 and 4), a max 2: Let t ← 0, t ← 0, N τ ← 1 // global variables 3: Initialize graph G with at least 2 neurons 4: Initialize τ > 0 randomly 5: for each new instance x from the stream do 6: t ← t + 1 7: Let n * x , n * * x be the two neurons closest to x 8: Increment the age of n * x 's edges 10: x 2 11: Update the local learning rates according to Eq. 1 12: Adapt n * x and its neighbors (linked to n * x ) for each n ∈ G do 20: err n ← 0.9 × err n 21: C n ← 0.9 × C n 22: end for 23: end for The neuron n * x and its neighbors (linked to n * x by an edge) are adapted to get closer to x (lines 11-12), using the local learning rates that are computed according to Eq. 1 as described in Sect.3. As in GNG, n * x and n * * x are linked by an edge, old edges are deleted, and neurons that becomes isolated are also deleted.Algorithm 3 is called (line 17) to adapt the forgetting threshold τ and to check if there is any irrelevant neuron that needs to be removed, as described in Sect. 4.Then, Algorithm 4 is called (line 18) in order to insert a new neuron according to a probabilistic criterion described in Sect. 5. Finally, the local errors and relevance variables of all neurons are subject to an exponential decay (line 19).
Note that the parameter k used in Algorithms 3 and 4 serves different but related purposes.Indeed, as higher values of k promote stability in both the removal and the creation cases, it is reasonable and more practical to collapse the value of the parameter k for both cases into one.
Let f be the size of x (i.e. the number of features), g be the number of neurons (i.e. the size of the graph |G|), and r be the number of neurons in R, with r g.The most time consuming operation in Algorithm 2 is finding the neurons in G that are closest from the input x (line 7 of Algorithm 2).For each input x, this operation takes O( f × g).Additionally, the adaptation of the local variables of neurons (e.g.lines 19-22 of Algorithm 2) has O(g) time complexity.Algorithm 3 has a time complexity of O( f × r ) as it needs to find r * x , and Algorithm 4 has a time complexity of O(g).Therefore, the overall complexity of the proposed method (GNG-A) for learning from each instance x is O( f ×(g +r )), which is very similar to the original GNG algorithm.
Remove (dequeue) the oldest neuron in R 10: end if 11: 12: // check if τ need to be decreased 13: Let n q = argmax n∈G err n 6: Let n f = argmax n∈Neighbours(n q ) err n 7: Create a new neuron n new between n q and n f 8: n new = 0.5 × (n q + n f ) 9: err n new = 0.5 × err n q 10: end if Anomaly and novelty detection methods (Liu et al. 2008;Krawczyk and Woźniak 2015;Li et al. 2003;Schölkopf et al. 2000) learn a model from a reference set of regular (or normal) data, and classify a new test data point as irregular (or abnormal) if it deviates from that model.If the reference data comes as a stream and its distribution is subject to change over time, such methods are typically trained over a sliding window as described in Ding and Fei (2013) and Krawczyk and Woźniak (2015).
The method we proposed is able to adapt to various types of change without keeping data points in a sliding window, and therefore it is straightforward to use it for the task of anomaly and novelty detection where the distribution of the reference data is non-stationary.More specifically, each neuron in G can be considered as the center of a hyper-sphere of a given radius d (a distance threshold).Therefore, at any time t, the graph G (i.e., all hyper-spheres) covers the area of space that represents regular data.It follows that a test data point x whose distance to the nearest neuron is larger than d, is not part of the area covered by G.More formally, x is considered as abnormal (or novel) if Manually choosing a convenient value for the decision parameter d is hard because it not only depends on the dataset but also on the number of neurons in G, which varies over time.Indeed, a higher number of neurons requires a smaller d.However, it is also natural to expect that a higher number of neurons in G would cause the distance between neighboring neurons to be smaller (and vise versa).Therefore, we heuristically set d equal to the expected distance between neighboring neurons in G.In order words, d at any time is defined as the average length of edges at that time: where E is the current set of edges in the graph, and (n i , n j ) is an edge linking two neurons n i and n j .

Experiments
In this section, we evaluate the proposed method.First, we present the datasets used for evaluation in Sect.7.1.Then, we evaluate the general properties of the proposed method in terms of the ability to follow a non-stationary distribution, in Sect.7.2.Finally, we present and discuss the results of the anomaly and novelty detection using the proposed method, in comparison to other benchmarking methods in Sect.7.3.

Datasets
We consider in our experimental evaluation several real-world and artificial datasets covering a wide range of non-stationary distributions.The other datasets are provided in Souza et al. (2015) and publicity available for download. 5These datasets experience various levels of change over time, thus, are ideal to showcase the performance of algorithms in non-stationary environments.All these artificial non-stationary datasets are illustrated in Fig. 5.The last four artificial datasets in Table 1 are stationary datasets with distributions corresponding to various shapes, as illustrated in Fig. 5.

General properties of GNG-A
The first set of experiments shows the general properties of the proposed method in terms of the adaptability, the ability to represent stationary distributions, and to follow non-stationary distributions.
As an initial step, Fig. 6 illustrates a simple proof of concept of the proposed method for a simulated one-dimensional non-stationary data distribution, which is initially shown by the grey box on the left.The location, over time, of the created neurons is shown with red points.The size of the graph G is limited to 10 neurons for better visualization purposes.At time 1000, the distribution is moderately shifted, which makes half of the neurons to be reused, and others to be created.At time 3000 the distribution suddenly changes, which makes only few neurons change their location, and leads to the creation of many new neurons and the removal of existing ones.After time 5000, the distribution splits into two parts (clusters), and the proposed method follows the change.
Figure 7 shows an experiment performed on the 1CDT dataset (non-stationary) with the goal to showcase the adaptive removal of neurons described in Sect.4.2.Remember that, for a given dataset, the forgetting rate depends on the value to which the threshold τ is set.As τ is adaptive, we show in this experiment that it is not very sensitive to the initial value to which it is set.Figure 7a shows the final values of τ (i.e., after adaptation) according to the initial values of τ .Figure 7b shows the current value of τ over time, based on different initial values.Despite the fact that there is some influence from the initial value of τ , we can see from Fig. 7a, b that any initial value of τ , leads to values of τ that are close to each other.
Moreover, a learning rate is used during the adaptation of τ (see Eqs. 6, 5).In the experiment of Fig. 7a, b, this learning rate was set according to Eq. 7 as described in Sect.4.2.In order to illustrate the effect of on τ , Fig. 7c shows the value of τ over time, based on different values of .It is natural that when is low (e.g.0.005), τ changes slowly at each adaptation step.For τ to eventually stabilize, needs only to be sufficiently small.Nonetheless, for the reminder of this paper, is adapted according to Eq. 7. In order to illustrate the influence of the parameter k on the creation of neurons and how fast the network grows, Fig. 8 shows (for the non stationary dataset 1CDT ) the evolution of the overall winning frequency f q (A) and the number of neurons (B) over time, for a fixed threshold τ , according to different values of the parameter k.We can see from Fig. 8 that higher values of k lead to a smaller overall winning frequency f q , which consequently lead to a less frequent creation of neurons.Figure 9 shows the same experiment with the adaptive threshold τ , in order to illustrate the influence of the parameter k on both the adaptive creation and removal of neurons.We can see from Fig. 9 that smaller values of k lead to a more frequent adaptation of τ .If more than k neurons are not updated anymore, then τ is decreased in order to remove more neurons in future.Specifically, by setting k to the lowest value k = 1, τ is decreased  10 The winning frequency f q over time for data generated by one cluster (a Gaussian).At time t = 3000 an additional number of clusters are introduced frequently causing the removal of many neurons and the insertion of others, which leads to an unstable network.Besides the fact that higher values of k lead to less frequent removals and insertions (and vice versa), Figs. 8 and 9 also show that for a reasonable choice of k (e.g.k = 10), the number of neurons stabilizes over time.
The overall winning frequency f q defines the probability of creating new neurons.This probability is especially important in the case of a sudden appearance of new concepts.Figure 10 shows the values of f q over time where a variable number of new clusters are introduced at time t = 3000.We can see that f q increases at time t = 3000 allowing for the creation of new neurons to represent the new clusters.Moreover, Fig. 10 shows that the probability of inserting new neurons is higher and lasts longer when the number of newly introduced clusters is higher, which is a desired behavior.
Fig. 11 The period λ = 100 in GNG, GNG-U and GNG-T.The removal threshold θ = 10 9 , 10 5 and 10 7 for the three respective datasets in GNG-U.The epoch N = 500, the confidence σ = 0.8, and target error T = 0.3, 0.01 and 0.4, for the three respective datasets in GNG-T.k = 10 for the proposed method.Note that in the first column the plot of GNG-T (blue) is thicker (appears to be black) because points in the graph are very close.Also, the plot of GNG (thin black) in the first line is hidden behind the plot of GNG-U (green) (Color figure online) Figure 11 illustrates the behavior of proposed method in comparison to GNG (Fritzke 1995) and two other variants for non-stationary distributions described in Sect.2, namely GNG-U (Fritzke 1997) and GNG-T (Frezza-Buet 2014).For each method, we show the evolution of the number of neurons over time in first column of figures, the overall representation error (i.e., average over all neurons) in the second column of figures, and the percentage of irrelevant neurons (i.e., that have never been updated during the last 100 steps) in the third column of figures.We show the results in three situations: a stationary distribution using dataset 2D-1 (the three top figures), a non-stationary distribution with a progressive change using dataset 1CDT (the three middle figures), and a stationary distribution with a sudden change happening after time 2500, using dataset 2D-4 (the three bottom figures).We can observe from Fig. 11 that the proposed method manages to create more neurons at early stages, which leads to a lower representation error.The number of neurons automatically stabilizes over time for the proposed method (unlike GNG and GNG-U).It also stabilizes for GNG-T depending on the user specified target parameter T .Moreover, all three methods (unlike GNG) efficiently remove irrelevant neurons.Nonetheless, it should be noted that the proposed method is adaptive, and unlike GNG-U and GNG-T, there is no need to adapt any parameter across the three datasets.6

Anomaly and novelty detection
In the following, the proposed method (GNG-A) is compared against: One Class SVM (OCSVM) (Schölkopf et al. 2000), Isolation Forest (Liu et al. 2008), and KNNPaw (Bifet et al. 2013), in addition to GNG, GNG-U and GNG-T.The KNNPaw method consists in a kNN with dynamic sliding window size able to handle drift.The anomaly detection with the KNNPaw method is done by checking whether the mean sample distance to the k Neighbors is higher than the mean distance between samples in the sliding window.The two anomaly detection methods OCSVM and Isolation Forest are trained over a sliding window, allowing them to handle non-stationary distributions.The Python implementations available on the scikit-learn machine learning library (Pedregosa et al. 2011) have been used.A sliding window of 500 instances is chosen for OCSVM and Isolation Forest, as it provides the best overall results across all datasets.
For each dataset, instances from a subset of classes (roughly half of the number of classes) are considered as normal (or regular) instances, and the instances from the other half are considered as abnormal (or novel).The considered methods are trained based on the stream of regular instances.As advocated by Gama et al. (2009), a prequential accuracy is used for evaluating the performance of the methods in correctly distinguishing the regular vs. novel instances.This measure corresponds to the average accuracy computed online, by predicting for every instance whether it is regular or novel, prior to its learning.The average accuracy is estimated using a sliding window of 500 instances.
Note that during predication, the anomaly detector classifies unlabeled examples as normal or abnormal without having access to true labels.However, to asses and evaluate its performance, true labels are needed.Labels information is not used during prediction, it is only used to "evaluate" the performance of the system(s).Moreover, the prequential evaluation is preconized for streaming algorithms.Our novelty detection algorithm is a streaming algorithm in non-stationary environments, therefore, it makes sense to use a prequential evaluation (over a sliding window) to report a performance which reflect the current time (i.e.forget about previous predictions that happened long in the past).
A search of some parameters of each algorithm is performed and the best results are reported.Details about the parameters for each algorithm are provided in "Appendix B".
Tables 2 and 3 show the overall results by presenting the average accuracy over time, as well as the p-value obtained based on the Student's t-test.This p-value indicates how much significantly the results of the proposed method differ from the results of the best performing method.For each dataset, the result of the best performing method is highlighted with bold text in Tables 2 and 3.If the result of the best performing It can be seen from Tables 2 and 3 that the proposed method achieves a better overall performance than the other methods.Moreover, as indicated by the p-values, in the vast majority of cases, the results achieved by the proposed method are significantly different from the results achieved by the other methods.This is especially true for real datasets with a variable or unknown rate of drift.These results confirm that the adaptive proposed method is generally more convenient for various types of nonstationary environments, due to its dynamic adaptation over time.

Conclusion and future work
In this paper we have introduced a new method (GNG-A) for online learning from evolving data streams for the task of anomaly and novelty detection.The method extends GNG for a better adaptation, removal and creation of neurons.The usefulness of the proposed method was demonstrated on various real-world and artificial datasets covering a wide range of non-stationary distributions.The empirical and statistical evaluation that we performed show that the proposed method achieved the best overall performance compared to three other methods (two methods designed for stationary data and one state of the art method in non-stationary data), while being much less sensitive to initialization parameters.Results show that the proposed adaptive forgetting and evolution mechanisms allow the method to deal with various stationary and non-stationary distributions without the need to manually fine-tune different sensitive hyper-parameters.Hence, the proposed method is suitable for a wide range of application domains varying from static environments to highly dynamic ones.
For future work, we plan to design a parallel version of the proposed method and take advantage of data intensive computing platforms, such as Apache Spark, for the implementation.In order to do this, one way is to parallelize independent parts of the data and process them in parallel while sharing the same graph of neurons.Another alternative is to design algorithms to adequately split and distribute the graph of neurons on multiple machines running in parallel.The Elec2 dataset, described in Harries and Wales (1999), holds information of the Australian New South Wales Electricity Market, whose prices are affected by supply and demand.Each sample is described by attributes such as day of week, time-stamp, market demand etc., and the relative change of the price (higher or lower) is identified based on a moving average of the last 24 h.
The Covtype dataset is introduced in Blackard and Dean (1999) and often used as a benchmark for drift algorithms.It assigns cartographic variables such as elevation, slope, soil type, etc. to different forest cover types.Only forests with minimal humancaused disturbances were used, so that resulting forest cover types are more a result of ecological processes.
The Outdoor dataset (Losing et al. 2015) is obtained from images recorded by a mobile in a garden environment.Images contain 40 different objects, each approached ten times under varying lighting conditions affecting the color based representation.Each approach consists of 10 images and is represented in temporal order within the dataset.
The Rialto dataset (Losing et al. 2016) consists of images of colorful buildings next to the famous Rialto bridge in Venice, encoded in a normalized 27-dimensional RGB histogram.Images are obtained from time-lapse videos captured by a webcam with fixed position.The recordings cover 20 consecutive days.Continuously changing weather and lighting conditions affect the representation.
The Spamdata dataset is introduced in Katakis et al. ( 2010) and consists of email messages from the Apache Spam Assassin Collection http://spamassassin.apache.org.A bag-of-words approach was used for representing emails, resulting in 9324 instances and 500 attributes.There are two classes, legitimate and spam.As observed in Katakis et al. (2010), the characteristics of spam messages in this dataset gradually change as time passes.
The Sea Concepts dataset is an artificial adapted for novelty detection and originally proposed by Street and Kim (2001).It consists of 60,000 instances with three attributes of which only two are relevant.The two class decision boundary is given by f 1 + f 2 = b, where f 1 , f 2 are the two relevant features and b is a predefined threshold.Abrupt drift is simulated with four different concepts by changing the value of b.The dataset contains 10% of noise.
The Keystroke dataset (described in Souza et al. (2015)) is from a real-world application related to keystroke dynamics for recognizing users by their typing rhythm, where user profiles evolve incrementally over time.
The Usenet dataset is a text dataset inspired by Katakis et al. (2010) and processed for novelty detection.It consists of a simulation of news filtering with concept drift related to the change of interest of a user over time.A user can decide to unsubscribe from news groups that he is not interested in and subscribe for new ones that he becomes interested in, and the previously interesting topics become out of his main interest.
The Optdigits dataset is a real-word stationary dataset of handwritten digits, described in the UCI machine learning repository (Frank and Asuncion 2010).It is introduced to test the performance of the proposed method in a stationary environment, where the data is split across multiple clusters.

B Details about parameters
Table 4 lists, for each dataset, the parameters selected for each method, which lead to the best results.The parameter values which are not variable across the different datasets are reported here (not in the table).For Isolation Forest, the ensemble size is fixed to e = 50.The training set size used to train each isolation tree is fixed to a default value of s = 256 provided by the scikit-learn library.The parameter ø of Isolation Forest refers to the amount of contamination of the dataset (i.e., the proportion of outliers in the dataset).The respective parameters γ and ν of OCSVM refer to the kernel coefficient for the radial basis function (RBF) and to the upper bound on the fraction of training errors.The parameter w of KNNPaw represents the expected window size as described in Bifet et al. (2013) (not the exact size, as it is probabilistic), and k is the usual parameter of kNN.The parameters of GNG, GNG-U and GNG-T in Table 4 are explained in Sect. 2. The parameters 1 and 2 for GNG, GNG-U and GNG-T are set to 0.1 and 0.005 respectively.The parameter a max is set to 10 for all the GNG-based algorithms (including the proposed one) on all datasets.Finally, the parameter k of the proposed method is set to 10.

Fig. 3
Fig. 3 The value − log C n for the neuron n (which is most likely to be removed at each iteration) in two cases: a stationary distribution (blue) and a non-stationary distribution (red) (Color figure online)

Fig. 5
Fig. 5 Snapshots from the artificial non-stationary datasets

Fig. 6
Fig. 6 The location of neurons for a one-dimensional non-stationary distribution over time.|G| ≤ 10, k = 10

Fig. 7 aFig. 8
Fig. 7 a, b The value of the adaptive threshold τ according to different initial values.c The effect of on the adaptation of the threshold τ .Parameter k = 10

Fig. 9
Fig. 9 The evolution of the adaptive threshold τ and the number of neurons over time, according to different values of the parameter k. a The values of τ and b the number of neurons.The non stationary dataset 1CDT is used

Table 1
Summary of the datasets characteristics variable or significantly different intervals between consecutive changes.The column Regular reports the percentage of regular instances in each dataset.The first group consists in various real world datasets: Covtype, Elec2, Outdoor, Rialto, Weather, Spamdata, Keystroke and Opendigits; in addition to two commonly

Table 2
Average accuracy for distinguishing normal and abnormal (or novel) data is not significantly different from the other methods (i.e.p value > 0.05) then the result of those methods is also highlighted with bold text. method