/ proof-of-concept / benchcompress
Sign in
proof-of-concept / benchcompress
benchcompress / benchcompress / src / benchcompress / algorithms / ans / markov_predict.py
26 lines · 1.2 KBBlameHistoryRaw
1import numpy as np
2from .markov_predict_cpp_ext import markov_predict_int16, markov_predict_int32
5def markov_predict(x: np.ndarray, M: int, num_training_samples: int = 10000) -> tuple:
6 """Predict signal using Markov model and return coefficients, initial values and residuals using C++ implementation.
8 Args:
9 x: Input signal (must be int16 or int32)
10 M: Number of previous samples to use for prediction
11 num_training_samples: Maximum number of samples to use for fitting the model coefficients (default: 10000).
12 Using fewer samples speeds up model fitting on large inputs while maintaining accuracy.
14 Returns:
15 tuple: (coefficients (float32), initial_values (same dtype as input), residuals (same dtype as input))
17 Raises:
18 ValueError: If input array is not int16 or int32
19 """
20 # Check input dtype and call appropriate implementation
21 if x.dtype == np.int16:
22 return markov_predict_int16(x, M, num_training_samples)
23 elif x.dtype == np.int32:
24 return markov_predict_int32(x, M, num_training_samples)
25 else:
26 raise ValueError(f"Input array must be int16 or int32, got {x.dtype}")
↑↓ move↵openescclose