shunping commented on code in PR #33994: URL: https://github.com/apache/beam/pull/33994#discussion_r1960191745
########## sdks/python/apache_beam/ml/anomaly/univariate/base.py: ########## @@ -0,0 +1,88 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +import abc +from collections import deque +from enum import Enum + + +class BaseTracker(abc.ABC): + """Abstract base class for all univariate trackers.""" + @abc.abstractmethod + def push(self, x): + """Push a new value to the tracker. + + Args: + x: The value to be pushed. + """ + raise NotImplementedError() + + @abc.abstractmethod + def get(self): + """Get the current tracking value. + + Returns: + The current tracked value, the type of which depends on the specific + tracker implementation. + """ + raise NotImplementedError() + + +class WindowMode(Enum): + """Enum representing the window mode for windowed trackers.""" + #: operating on all data points from the beginning. Review Comment: It really depends on algorithms and what statistics we talk about here. For example, we don't need to store all data points to compute the mean in a landmark window: an naive way is to only store the number of data points and their sum. However, for quantile, we will have to store all the data to compute the exact answer. There are some approximate algorithms for quantile that does not need to store all data points, but they are outside the scope of this current implementation. That's why in `WindowTracer`, we don't explicitly declare a list to store all data points, because it may or may not need all the data points. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
