Commit 2300042b authored by Philippe SWARTVAGHER's avatar Philippe SWARTVAGHER
Browse files

Add __repr__ functions to [Multi]CurveFit

parent 707910b9
import abc
from enum import Enum
import functools
import inspect
import math
import matplotlib.pyplot as plt
import numpy as np
......@@ -794,6 +795,14 @@ class CurveFit:
def predict(self, x):
return self.f(x, *self.coefs)
def __repr__(self):
param_names = inspect.getfullargspec(self.f)[0]
s = "CurveFit: "
for i in range(1, len(param_names)):
s += f"{param_names[i]}={self.coefs[i-1]:.3f} "
return s + f"r²={self.r_square:.3f}"
class MultiCurveFit:
def __init__(self, f, x, y, x_slices, y_std=None, bounds=(-np.inf, np.inf)):
......@@ -862,3 +871,9 @@ class MultiCurveFit:
def predict(self, x):
return self._find_curve_for_x(x).predict(x)
def __repr__(self):
s = "MultiCurveFit:\n"
for c in self.curves:
s += f"\tx=[{c.x[0]}..{c.x[-1]}], y=[{c.y[0]}..{c.y[-1]}], " + str(c) + "\n"
return s
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment