[Python] Fixed Point Iteration Optimisation Problem

Discussão em 'Python' iniciado por Stack, Junho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I have to solve this problem using fixed-point iteration. I have tried but I am having different solutions depending on the initial condition of y12.

    Definition of the problem

    Can someone help me? Also, the initial idea was to solve the problem using FPI and Casadi but I can't manage to find a way to do it so if anyone knows if it possible to use the FPI method and Casadi it is also helpful (I am trying Scicpy as I couldn't find a solution).

    This is my code:

    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}")

    Continue reading...

Compartilhe esta Página