Page MenuHomec4science

optimizer.py
No OneTemporary

File Metadata

Created
Wed, Jul 24, 17:27

optimizer.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 10 10:19:11 2019
Authors: Omid Ashtari and Armand Sieber
Description: Scripts intended to minimize a quadratic function using scipy.optimize built-in function.
The function to minimize is defined as S(X)= X'AX - X'B, with X = [x, y], X' the transform of X
A is a 2x2 matrix and B 2X1 vector
"""
import numpy as np
from scipy.optimize import minimize
def objective(x, *args): #objective function to be minimized
A = args[0]
B = args[1].T
S = np.dot(x.T, np.dot(A, x)) - np.dot(x.T, B)
return S
# Parameters of the unction to minimize
A = np.array([[4, 0], [1, 3]])
B = np.array([0, 1])
# Initial guess
X0 = np.array([3, 2])
print(objective(X0, A, B))
solution = minimize(objective, X0, args = (A, B), method = 'BFGS', options = {'xtol': 1e-12, 'maxiter':100})
print(solution)

Event Timeline