Problem mit fester Punkt -Iteration OptimierungsproblemPython

Python-Programme
Anonymous
 Problem mit fester Punkt -Iteration Optimierungsproblem

Post by Anonymous »

Ich muss dieses Problem mithilfe der Festpoint-Iteration lösen. Ich habe es versucht, aber ich habe unterschiedliche Lösungen, abhängig von der Anfangsbedingung von Y12. Die anfängliche Idee war auch, das Problem mit FPI und Casadi zu lösen, aber ich kann es nicht schaffen, einen Weg zu finden. Wenn jemand weiß, ob es möglich ist, die FPI-Methode zu verwenden, und Casadi ist auch hilfreich (ich versuche Scicpy, da ich keine Lösung finden kann).

Code: Select all

import numpy as np
from scipy.optimize import minimize

# Constants
b = 3
d = 3.5
tolerance = 1e-6
max_iterations = 10000

# Define the nonlinear functions a(x1) and c(x2)
def a_func(x1):
return 0.25/(1 + np.exp(x1)) + 0.5

def c_func(x2):
return -(1/(1 + np.exp(x2)) + 0.5)

# Fixed-point iteration to solve for y12 and y21 given x
def fixed_point_iteration(x):
x1, x2 = x
a = a_func(x1)
c = c_func(x2)

y12_old = -1.44
for _ in range(max_iterations):
y21_new = a*(y12_old - b)**2
y12_new = c*y21_new + d

if abs(y12_new - y12_old) < tolerance:
return y12_new, y21_new
y12_old, y21_old = y12_new, y21_new

raise RuntimeError("Fixed-point iteration did not converge")

# Objective function to minimize
def objective(x):
try:
y12, y21 = fixed_point_iteration(x)
print(y12,y21)
return y12**2 - 100*y21 + 0.1*(x[0]**2 + x[1]**2)
except RuntimeError:
return np.inf  # Penalize non-converging points

# Initial guess for x

x0 = np.array([5.82409222, 7.73955672])
y12,y21 = fixed_point_iteration(x0)
print(y12,y21)
print(y21-(0.25/(1+np.exp(x[0]))+0.5)*(y12-b)**2)
print(y12-(-(1/(1+np.exp(x[1]))+0.5)*y21 + d))
# Perform optimization
#result = minimize(objective, x0, method="BFGS", tol = 1e-8)

# Extract optimal values
#x_opt = result.x
#y12_opt, y21_opt = fixed_point_iteration(x_opt)
#f_opt = objective(x_opt)

# Print results
print(f"Optimal x: {x_opt}")
print(f"Optimal y12: {y12_opt}")
print(f"Optimal y21: {y21_opt}")
print(f"Optimal objective value: {f_opt}")

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post