From 79a460dea085f63bf2405282b43f0b6278f68d8c Mon Sep 17 00:00:00 2001 From: Yves Biener Date: Fri, 16 Jan 2026 19:50:46 +0100 Subject: [PATCH] add: print all model values after solving simple linear regression --- example.py | 3 +++ src/fitting.py | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/example.py b/example.py index 1a632c3..607c13e 100644 --- a/example.py +++ b/example.py @@ -9,6 +9,9 @@ from src import centrality from src import plot from src import fitting +# TODO: implement this AIC: +# https://www.statlect.com/fundamentals-of-statistics/linear-regression-model-selection-criteria + def merfish(): """ diff --git a/src/fitting.py b/src/fitting.py index 9010d00..a3daf74 100644 --- a/src/fitting.py +++ b/src/fitting.py @@ -21,7 +21,7 @@ def fit_piece_wise_linear(d, C, M=1000): """ n = len(d) - model = gp.Model() + model = gp.Model("Piece-wise Linear Model") m = model.addVar(vtype=GRB.CONTINUOUS, name="m") # Slope before breakpoint c0 = model.addVar(vtype=GRB.CONTINUOUS, name="c0") # y-intercept @@ -64,13 +64,17 @@ def fit_linear_regression(d, C): tuple: Optimized slope (beta) and intercept (alpha). """ n = len(d) - model = gp.Model() + model = gp.Model("Simple Linear Regression") alpha = model.addVar(vtype=GRB.CONTINUOUS, name="alpha") beta = model.addVar(vtype=GRB.CONTINUOUS, name="beta") model.setObjective(gp.quicksum((C[i] - alpha - beta * d[i])**2 for i in range(n)), GRB.MINIMIZE) model.optimize() + + for v in model.getVars(): + print(f"{v.VarName} {v.X:g}") + return beta.X, alpha.X