翻译代码: class AutocorrelationTest(Test):def init(self, seq_length: int ,shift: int = 1): # Generate base Test class self._shift = shift super(AutocorrelationTest, self).init(“Autocorrelation”, 0.01, seq_length) def _execute(self, bits: numpy.ndarray): """ Overridden method of Test class: check its docstring for further information. """ original_vector : numpy.ndarray = bits[:bits.size - self._shift] shifted_vector: numpy.ndarray = numpy.roll(bits, -self._shift)[:bits.size - self._shift] result_vector: numpy.ndarray = numpy.bitwise_xor(original_vector, shifted_vector) # Compute ones int result vector ones: int = numpy.count_nonzero(result_vector) tmp: float = 2 * (ones - (bits.size - self._shift) / 2.0) / math.sqrt(bits.size - self._shift) # Compute score score: float = math.erfc(abs(tmp) / (math.sqrt(2.0))) # Compute q_value q_value: float = math.erfc(tmp / (math.sqrt(2.0))) / 2.0 # Return result if score >= self.significance_value: return Result(self.name, True, numpy.array([score]), numpy.array([q_value])) return Result(self.name, False, numpy.array([score]), numpy.array([q_value])) def repr(self) -> str: return f’{self.name} (k={self._shift})
时间: 2023-06-03 18:02:19 浏览: 115
这段代码定义了一个类AutocorrelationTest,继承自Test类。它有两个参数:seq_length表示序列的长度,shift表示计算自相关系数时的偏移值,默认为1。在类的构造函数__init__中进行初始化。
阅读全文