From 05656c85d6d68eaa4982ccf157a547fbfa8ca2ed Mon Sep 17 00:00:00 2001 From: ralf Date: Mon, 5 Aug 2024 13:19:34 +0300 Subject: [PATCH] prelimenary exploration for fitter --- Multi_fitter_test_file.py | 39 ++++++++++++++++++++++++++++++ __pycache__/Model.cpython-311.pyc | Bin 15278 -> 15278 bytes 2 files changed, 39 insertions(+) create mode 100644 Multi_fitter_test_file.py diff --git a/Multi_fitter_test_file.py b/Multi_fitter_test_file.py new file mode 100644 index 0000000..5fb5a73 --- /dev/null +++ b/Multi_fitter_test_file.py @@ -0,0 +1,39 @@ +import numpy as np +from scipy.optimize import minimize + + +# example model +def model(params, x): + return params[0] * x + params[1] + + +# Cost function +def cost_function(params, x_data, y_data): + return np.sum((model(params, x_data) - y_data) ** 2) + + +# Global cost function +def global_cost_function(params, experiments): + total_cost = 0 + for x_data, y_data in experiments: + total_cost += cost_function(params, x_data, y_data) + return total_cost + + +# Example data for two experiments +x_data_1 = np.array([0, 1, 2, 3]) +y_data_1 = np.array([1, 3, 5, 7]) + +x_data_2 = np.array([0, 1, 2, 3]) +y_data_2 = np.array([2, 4, 6, 8]) + +experiments = [(x_data_1, y_data_1), (x_data_2, y_data_2)] + +# Initial guess/parameters +initial_params = [1, 0] + +# Run the optimization +result = minimize(global_cost_function, initial_params, args=(experiments,)) + +# Optimized parameters +print("Optimized parameters:", result.x) diff --git a/__pycache__/Model.cpython-311.pyc b/__pycache__/Model.cpython-311.pyc index 7f5f490a4f9f47697b496bb8e48d88dc7c9a27ac..a9b49526f10b0eb184bf563919ccdc8aeafdcdc8 100644 GIT binary patch delta 20 acmZ2izOI~mIWI340}w=SU$K#Uu{8iiX$Exw delta 20 acmZ2izOI~mIWI340}#ybUA~cfu{8ijL