Sowiks commented on code in PR #96:
URL: https://github.com/apache/otava/pull/96#discussion_r2532270975


##########
otava/change_point_divisive/base.py:
##########
@@ -0,0 +1,109 @@
+# 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.
+
+from dataclasses import dataclass, fields
+from typing import Generic, List, Optional, TypeVar
+
+from numpy.typing import NDArray
+
+
+@dataclass
+class CandidateChangePoint:
+    '''Candidate for a change point. The point that maximizes Q-hat function 
on [start:end+1] slice'''
+    index: int
+    qhat: float
+
+
+@dataclass
+class BaseStats:
+    '''Abstract statistics class for change point. Implementation depends on 
the statistical test.'''
+    pvalue: float
+
+
+GenericStats = TypeVar("GenericStats", bound=BaseStats)
+
+
+@dataclass
+class ChangePoint(CandidateChangePoint, Generic[GenericStats]):
+    '''Change point class, defined by index and signigicance test statistic.'''
+    stats: GenericStats
+
+    def __eq__(self, other):
+        '''Helpful to identify new Change Points during divisive algorithm'''
+        return isinstance(other, self.__class__) and self.index == other.index
+
+    @classmethod
+    def from_candidate(cls, candidate: CandidateChangePoint, stats: 
GenericStats) -> 'ChangePoint[GenericStats]':
+        return cls(
+            index=candidate.index,
+            qhat=candidate.qhat,
+            stats=stats,
+        )
+
+    def to_candidate(self) -> CandidateChangePoint:
+        '''Downgrades Change Point to a Candidate Change Point. Used to 
recompute stats for Weak Change Points.'''
+        data = {f.name: getattr(self, f.name) for f in 
fields(CandidateChangePoint)}
+        return CandidateChangePoint(**data)
+
+
+class SignificanceTester(Generic[GenericStats]):
+    '''Abstract class for significance tester'''
+
+    def __init__(self, alpha: float):
+        self.alpha = alpha

Review Comment:
   Will do



-- 
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]

Reply via email to