Expose numeric trend segment formulas from native reconstruction models

This commit is contained in:
2026-09-27 03:13:39 +03:00
parent de4609ea00
commit f3937eaf14
7 changed files with 203 additions and 4 deletions

View File

@@ -14,6 +14,7 @@ class Reconstruction:
input_count: int
unique_count: int
rmse: float
pieces: tuple = ()
@lru_cache(maxsize=1)
def library():
@@ -29,7 +30,7 @@ def library():
except (AttributeError, OSError, RuntimeError) as error:
raise ValueError("Пересоберите SETProtocol с set_signal.c и set_wavegen.c") from error
def reconstruct(points, method="pchip", output_count=1000, degree=2, *, endpoint=True):
def reconstruct(points, method="pchip", output_count=1000, degree=2, *, endpoint=True, with_model=False):
if method not in METHODS or type(output_count) is not int or not 2 <= output_count <= 10000:
raise ValueError("Неизвестный метод или число выходных точек вне 2…10000")
count = len(points)
@@ -44,7 +45,14 @@ def reconstruct(points, method="pchip", output_count=1000, degree=2, *, endpoint
raise ValueError({1: "Недостаточно точек для выбранной степени или неверные параметры",
2: "Нужны конечные значения и минимум две различные временные точки",
3: "Неустойчивая аппроксимация: уменьшите степень"}.get(code, "Ошибка расчёта"))
return Reconstruction(list(zip(ox, oy)), int(meta[0]), int(meta[1]), meta[2])
pieces = ()
if with_model:
from .plot_formula import reconstruction_pieces
if method == 'polynomial' and output_count <= degree:
pieces = reconstruct(points, method, degree + 1, degree, with_model=True).pieces
else:
pieces = reconstruction_pieces(work, count, int(meta[1]), method, degree, oy, endpoint)
return Reconstruction(list(zip(ox, oy)), int(meta[0]), int(meta[1]), meta[2], pieces)
def dac12(volts, vref=3.3):
data = (C.c_double * len(volts))(*volts)