gemseo / post / core

# hessians module¶

Hessian matrix approximations from gradient pairs.

Classes:

 BFGSApprox(history) Builds a BFGS approximation from optimization history. HessianApproximation(history) Abstract class for hessian approximations from optimization history. LSTSQApprox(history) Builds a Least squares approximation from optimization history. SR1Approx(history) Builds a Symmetric Rank One approximation from optimization history.
class gemseo.post.core.hessians.BFGSApprox(history)[source]

Builds a BFGS approximation from optimization history.

Constructor.

Parameters

history – the optimization history

Methods:

 build_approximation(funcname[, save_diag, …]) Builds the hessian approximation B. build_inverse_approximation(funcname[, …]) Builds the inversed hessian approximation H. compute_corrections(x_hist, x_grad_hist) Computes the corrections from the history. compute_scaling(hessk, hessk_dsk, …) Compute scaling. get_s_k_y_k(x_hist, x_grad_hist, iteration) Generate the s_k and y_k terms, respectively design variable difference and gradients difference between iterates. get_x_grad_history(funcname[, first_iter, …]) Get gradient history and design variables history of gradient evaluations. iterate_approximation(hessk, dsk, dyk[, scaling]) BFGS iteration from step k to step k+1. iterate_inverse_approximation(h_mat, s_k, y_k) Inverse BFGS iteration. iterate_s_k_y_k(x_hist, x_grad_hist) Generate the s_k and y_k terms, respectively design variable difference and gradients difference between iterates. rebuild_history(x_corr, x_0, grad_corr, g_0) Computes the history from the corrections.
build_approximation(funcname, save_diag=False, first_iter=0, last_iter=- 1, b_mat0=None, at_most_niter=- 1, return_x_grad=False, func_index=None, save_matrix=False, scaling=False, normalize_design_space=False, design_space=None)

Builds the hessian approximation B.

Parameters
• funcname – function name

• save_diag – if True, returns the list of diagonal approximations (Default value = False)

• first_iter – first iteration after which the history is extracted (Default value = 0)

• last_iter – last iteration before which the history is extracted (Default value = -1)

• b_mat0 – initial approximation matrix (Default value = None)

• at_most_niter – maximum number of iterations to take (Default value = -1)

• return_x_grad – if True, also returns the last gradient and x (Default value = False)

• func_index – Default value = None) (Default value = False)

• scaling – do scaling step

• normalize_design_space – if True, scale the values to work in a normalized design space (x between 0 and 1)

• design_space – the design space used to scale all values mandatory if normalize_design_space==True

Returns

the B matrix, its diagonal, and eventually the x and grad history pairs used to build B, if return_x_grad=True, otherwise, None and None are returned for args consistency

build_inverse_approximation(funcname, save_diag=False, first_iter=0, last_iter=- 1, h_mat0=None, at_most_niter=- 1, return_x_grad=False, func_index=None, save_matrix=False, factorize=False, scaling=False, angle_tol=1e-05, step_tol=10000000000.0, normalize_design_space=False, design_space=None)

Builds the inversed hessian approximation H.

Parameters
• funcname – function name

• save_diag – if True, returns the list of diagonal approximations (Default value = False)

• first_iter – first iteration after which the history is extracted (Default value = 0)

• last_iter – last iteration before which the history is extracted (Default value = -1)

• h_mat0 – initial inverse approximation matrix (Default value = None)

• at_most_niter – maximum number of iterations to take (Default value = -1)

• return_x_grad – if True, also returns the last gradient and x (Default value = False)

• func_index – Default value = None)

• normalize_design_space – if True, scale the values to work in a normalized design space (x between 0 and 1)

• design_space – the design space used to scale all values mandatory if normalize_design_space==True

Returns

the H matrix, its diagonal, and eventually the x and grad history pairs used to build H, if return_x_grad=True, otherwise, None and None are returned for args consistency

Computes the corrections from the history.

static compute_scaling(hessk, hessk_dsk, dskt_hessk_dsk, dyk, dyt_dsk)

Compute scaling.

Parameters
• hessk – previous approximation

• hessk_dsk – product between hessk and dsk

• dskt_hessk_dsk – product between dsk^t, hessk and dsk

• dyk – gradients difference between iterates

• dyt_dsk – product between dyk^t and dsk^t

Generate the s_k and y_k terms, respectively design variable difference and gradients difference between iterates.

Parameters
• x_hist – design variables history array

• iteration – iteration number for which the pair must be generated

get_x_grad_history(funcname, first_iter=0, last_iter=0, at_most_niter=- 1, func_index=None, normalize_design_space=False, design_space=None)

Parameters
• funcname – function name

• first_iter – first iteration after which the history is extracted (Default value = 0)

• last_iter – last iteration before which the history is extracted (Default value = 0)

• at_most_niter – maximum number of iterations to take (Default value = -1)

• func_index – Default value = None)

• normalize_design_space – if True, scale the values to work in a normalized design space (x between 0 and 1)

• design_space – the design space used to scale all values mandatory if normalize_design_space==True

static iterate_approximation(hessk, dsk, dyk, scaling=False)

BFGS iteration from step k to step k+1.

Parameters
• hessk – previous approximation

• dsk – design variable difference between iterates

• dyk – gradients difference between iterates

• scaling – do scaling step

Returns

updated approximation

static iterate_inverse_approximation(h_mat, s_k, y_k, h_factor=None, b_mat=None, b_factor=None, factorize=False, scaling=False)

Inverse BFGS iteration.

Parameters
• h_mat – previous approximation

• s_k – design variable difference between iterates

• y_k – gradients difference between iterates

Returns

updated inverse approximation

Generate the s_k and y_k terms, respectively design variable difference and gradients difference between iterates.

Parameters
• x_hist – design variables history array

Computes the history from the corrections.

class gemseo.post.core.hessians.HessianApproximation(history)[source]

Bases: object

Abstract class for hessian approximations from optimization history.

Constructor.

Parameters

history – the optimization history

Methods:

 build_approximation(funcname[, save_diag, …]) Builds the hessian approximation B. build_inverse_approximation(funcname[, …]) Builds the inversed hessian approximation H. compute_corrections(x_hist, x_grad_hist) Computes the corrections from the history. compute_scaling(hessk, hessk_dsk, …) Compute scaling. get_s_k_y_k(x_hist, x_grad_hist, iteration) Generate the s_k and y_k terms, respectively design variable difference and gradients difference between iterates. get_x_grad_history(funcname[, first_iter, …]) Get gradient history and design variables history of gradient evaluations. iterate_approximation(hessk, dsk, dyk[, scaling]) BFGS iteration from step k to step k+1. iterate_inverse_approximation(h_mat, s_k, y_k) Inverse BFGS iteration. iterate_s_k_y_k(x_hist, x_grad_hist) Generate the s_k and y_k terms, respectively design variable difference and gradients difference between iterates. rebuild_history(x_corr, x_0, grad_corr, g_0) Computes the history from the corrections.
build_approximation(funcname, save_diag=False, first_iter=0, last_iter=- 1, b_mat0=None, at_most_niter=- 1, return_x_grad=False, func_index=None, save_matrix=False, scaling=False, normalize_design_space=False, design_space=None)[source]

Builds the hessian approximation B.

Parameters
• funcname – function name

• save_diag – if True, returns the list of diagonal approximations (Default value = False)

• first_iter – first iteration after which the history is extracted (Default value = 0)

• last_iter – last iteration before which the history is extracted (Default value = -1)

• b_mat0 – initial approximation matrix (Default value = None)

• at_most_niter – maximum number of iterations to take (Default value = -1)

• return_x_grad – if True, also returns the last gradient and x (Default value = False)

• func_index – Default value = None) (Default value = False)

• scaling – do scaling step

• normalize_design_space – if True, scale the values to work in a normalized design space (x between 0 and 1)

• design_space – the design space used to scale all values mandatory if normalize_design_space==True

Returns

the B matrix, its diagonal, and eventually the x and grad history pairs used to build B, if return_x_grad=True, otherwise, None and None are returned for args consistency

build_inverse_approximation(funcname, save_diag=False, first_iter=0, last_iter=- 1, h_mat0=None, at_most_niter=- 1, return_x_grad=False, func_index=None, save_matrix=False, factorize=False, scaling=False, angle_tol=1e-05, step_tol=10000000000.0, normalize_design_space=False, design_space=None)[source]

Builds the inversed hessian approximation H.

Parameters
• funcname – function name

• save_diag – if True, returns the list of diagonal approximations (Default value = False)

• first_iter – first iteration after which the history is extracted (Default value = 0)

• last_iter – last iteration before which the history is extracted (Default value = -1)

• h_mat0 – initial inverse approximation matrix (Default value = None)

• at_most_niter – maximum number of iterations to take (Default value = -1)

• return_x_grad – if True, also returns the last gradient and x (Default value = False)

• func_index – Default value = None)

• normalize_design_space – if True, scale the values to work in a normalized design space (x between 0 and 1)

• design_space – the design space used to scale all values mandatory if normalize_design_space==True

Returns

the H matrix, its diagonal, and eventually the x and grad history pairs used to build H, if return_x_grad=True, otherwise, None and None are returned for args consistency

Computes the corrections from the history.

static compute_scaling(hessk, hessk_dsk, dskt_hessk_dsk, dyk, dyt_dsk)[source]

Compute scaling.

Parameters
• hessk – previous approximation

• hessk_dsk – product between hessk and dsk

• dskt_hessk_dsk – product between dsk^t, hessk and dsk

• dyk – gradients difference between iterates

• dyt_dsk – product between dyk^t and dsk^t

Generate the s_k and y_k terms, respectively design variable difference and gradients difference between iterates.

Parameters
• x_hist – design variables history array

• iteration – iteration number for which the pair must be generated

get_x_grad_history(funcname, first_iter=0, last_iter=0, at_most_niter=- 1, func_index=None, normalize_design_space=False, design_space=None)[source]

Parameters
• funcname – function name

• first_iter – first iteration after which the history is extracted (Default value = 0)

• last_iter – last iteration before which the history is extracted (Default value = 0)

• at_most_niter – maximum number of iterations to take (Default value = -1)

• func_index – Default value = None)

• normalize_design_space – if True, scale the values to work in a normalized design space (x between 0 and 1)

• design_space – the design space used to scale all values mandatory if normalize_design_space==True

static iterate_approximation(hessk, dsk, dyk, scaling=False)[source]

BFGS iteration from step k to step k+1.

Parameters
• hessk – previous approximation

• dsk – design variable difference between iterates

• dyk – gradients difference between iterates

• scaling – do scaling step

Returns

updated approximation

static iterate_inverse_approximation(h_mat, s_k, y_k, h_factor=None, b_mat=None, b_factor=None, factorize=False, scaling=False)[source]

Inverse BFGS iteration.

Parameters
• h_mat – previous approximation

• s_k – design variable difference between iterates

• y_k – gradients difference between iterates

Returns

updated inverse approximation

Generate the s_k and y_k terms, respectively design variable difference and gradients difference between iterates.

Parameters
• x_hist – design variables history array

Computes the history from the corrections.

class gemseo.post.core.hessians.LSTSQApprox(history)[source]

Builds a Least squares approximation from optimization history.

Constructor.

Parameters

history – the optimization history

Methods:

 build_approximation(funcname[, save_diag, …]) Builds the hessian approximation. build_inverse_approximation(funcname[, …]) Builds the inversed hessian approximation H. compute_corrections(x_hist, x_grad_hist) Computes the corrections from the history. compute_scaling(hessk, hessk_dsk, …) Compute scaling. get_s_k_y_k(x_hist, x_grad_hist, iteration) Generate the s_k and y_k terms, respectively design variable difference and gradients difference between iterates. get_x_grad_history(funcname[, first_iter, …]) Get gradient history and design variables history of gradient evaluations. iterate_approximation(hessk, dsk, dyk[, scaling]) BFGS iteration from step k to step k+1. iterate_inverse_approximation(h_mat, s_k, y_k) Inverse BFGS iteration. iterate_s_k_y_k(x_hist, x_grad_hist) Generate the s_k and y_k terms, respectively design variable difference and gradients difference between iterates. rebuild_history(x_corr, x_0, grad_corr, g_0) Computes the history from the corrections.
build_approximation(funcname, save_diag=False, first_iter=0, last_iter=- 1, b_mat0=None, at_most_niter=- 1, return_x_grad=False, scaling=False, func_index=- 1, normalize_design_space=False, design_space=None)[source]

Builds the hessian approximation.

Parameters
• funcname – function name

• save_diag – if True, returns the list of diagonal approximations (Default value = False)

• first_iter – first iteration after which the history is extracted (Default value = 0)

• last_iter – last iteration before which the history is extracted (Default value = -1)

• b_mat0 – initial approximation matrix (Default value = None)

• at_most_niter – Default value = -1)

• return_x_grad – Default value = False)

• func_index – Default value = -1)

• normalize_design_space – if True, scale the values to work in a normalized design space (x between 0 and 1)

• design_space – the design space used to scale all values mandatory if normalize_design_space==True

Returns

the B matrix, its diagonal, and eventually the x and grad history pairs used to build B, if return_x_grad=True, otherwise, None and None are returned for args consistency

build_inverse_approximation(funcname, save_diag=False, first_iter=0, last_iter=- 1, h_mat0=None, at_most_niter=- 1, return_x_grad=False, func_index=None, save_matrix=False, factorize=False, scaling=False, angle_tol=1e-05, step_tol=10000000000.0, normalize_design_space=False, design_space=None)

Builds the inversed hessian approximation H.

Parameters
• funcname – function name

• save_diag – if True, returns the list of diagonal approximations (Default value = False)

• first_iter – first iteration after which the history is extracted (Default value = 0)

• last_iter – last iteration before which the history is extracted (Default value = -1)

• h_mat0 – initial inverse approximation matrix (Default value = None)

• at_most_niter – maximum number of iterations to take (Default value = -1)

• return_x_grad – if True, also returns the last gradient and x (Default value = False)

• func_index – Default value = None)

• normalize_design_space – if True, scale the values to work in a normalized design space (x between 0 and 1)

• design_space – the design space used to scale all values mandatory if normalize_design_space==True

Returns

the H matrix, its diagonal, and eventually the x and grad history pairs used to build H, if return_x_grad=True, otherwise, None and None are returned for args consistency

Computes the corrections from the history.

static compute_scaling(hessk, hessk_dsk, dskt_hessk_dsk, dyk, dyt_dsk)

Compute scaling.

Parameters
• hessk – previous approximation

• hessk_dsk – product between hessk and dsk

• dskt_hessk_dsk – product between dsk^t, hessk and dsk

• dyk – gradients difference between iterates

• dyt_dsk – product between dyk^t and dsk^t

Generate the s_k and y_k terms, respectively design variable difference and gradients difference between iterates.

Parameters
• x_hist – design variables history array

• iteration – iteration number for which the pair must be generated

get_x_grad_history(funcname, first_iter=0, last_iter=0, at_most_niter=- 1, func_index=None, normalize_design_space=False, design_space=None)

Parameters
• funcname – function name

• first_iter – first iteration after which the history is extracted (Default value = 0)

• last_iter – last iteration before which the history is extracted (Default value = 0)

• at_most_niter – maximum number of iterations to take (Default value = -1)

• func_index – Default value = None)

• normalize_design_space – if True, scale the values to work in a normalized design space (x between 0 and 1)

• design_space – the design space used to scale all values mandatory if normalize_design_space==True

static iterate_approximation(hessk, dsk, dyk, scaling=False)

BFGS iteration from step k to step k+1.

Parameters
• hessk – previous approximation

• dsk – design variable difference between iterates

• dyk – gradients difference between iterates

• scaling – do scaling step

Returns

updated approximation

static iterate_inverse_approximation(h_mat, s_k, y_k, h_factor=None, b_mat=None, b_factor=None, factorize=False, scaling=False)

Inverse BFGS iteration.

Parameters
• h_mat – previous approximation

• s_k – design variable difference between iterates

• y_k – gradients difference between iterates

Returns

updated inverse approximation

Generate the s_k and y_k terms, respectively design variable difference and gradients difference between iterates.

Parameters
• x_hist – design variables history array

Computes the history from the corrections.

class gemseo.post.core.hessians.SR1Approx(history)[source]

Builds a Symmetric Rank One approximation from optimization history.

Constructor.

Parameters

history – the optimization history

Attributes:

Methods:

 build_approximation(funcname[, save_diag, …]) Builds the hessian approximation B. build_inverse_approximation(funcname[, …]) Builds the inversed hessian approximation H. compute_corrections(x_hist, x_grad_hist) Computes the corrections from the history. compute_scaling(hessk, hessk_dsk, …) Compute scaling. get_s_k_y_k(x_hist, x_grad_hist, iteration) Generate the s_k and y_k terms, respectively design variable difference and gradients difference between iterates. get_x_grad_history(funcname[, first_iter, …]) Get gradient history and design variables history of gradient evaluations. iterate_approximation(b_mat, s_k, y_k[, scaling]) SR1 iteration. iterate_inverse_approximation(h_mat, s_k, y_k) Inverse BFGS iteration. iterate_s_k_y_k(x_hist, x_grad_hist) Generate the s_k and y_k terms, respectively design variable difference and gradients difference between iterates. rebuild_history(x_corr, x_0, grad_corr, g_0) Computes the history from the corrections.
EPSILON = 1e-08
build_approximation(funcname, save_diag=False, first_iter=0, last_iter=- 1, b_mat0=None, at_most_niter=- 1, return_x_grad=False, func_index=None, save_matrix=False, scaling=False, normalize_design_space=False, design_space=None)

Builds the hessian approximation B.

Parameters
• funcname – function name

• save_diag – if True, returns the list of diagonal approximations (Default value = False)

• first_iter – first iteration after which the history is extracted (Default value = 0)

• last_iter – last iteration before which the history is extracted (Default value = -1)

• b_mat0 – initial approximation matrix (Default value = None)

• at_most_niter – maximum number of iterations to take (Default value = -1)

• return_x_grad – if True, also returns the last gradient and x (Default value = False)

• func_index – Default value = None) (Default value = False)

• scaling – do scaling step

• normalize_design_space – if True, scale the values to work in a normalized design space (x between 0 and 1)

• design_space – the design space used to scale all values mandatory if normalize_design_space==True

Returns

the B matrix, its diagonal, and eventually the x and grad history pairs used to build B, if return_x_grad=True, otherwise, None and None are returned for args consistency

build_inverse_approximation(funcname, save_diag=False, first_iter=0, last_iter=- 1, h_mat0=None, at_most_niter=- 1, return_x_grad=False, func_index=None, save_matrix=False, factorize=False, scaling=False, angle_tol=1e-05, step_tol=10000000000.0, normalize_design_space=False, design_space=None)

Builds the inversed hessian approximation H.

Parameters
• funcname – function name

• save_diag – if True, returns the list of diagonal approximations (Default value = False)

• first_iter – first iteration after which the history is extracted (Default value = 0)

• last_iter – last iteration before which the history is extracted (Default value = -1)

• h_mat0 – initial inverse approximation matrix (Default value = None)

• at_most_niter – maximum number of iterations to take (Default value = -1)

• return_x_grad – if True, also returns the last gradient and x (Default value = False)

• func_index – Default value = None)

• normalize_design_space – if True, scale the values to work in a normalized design space (x between 0 and 1)

• design_space – the design space used to scale all values mandatory if normalize_design_space==True

Returns

the H matrix, its diagonal, and eventually the x and grad history pairs used to build H, if return_x_grad=True, otherwise, None and None are returned for args consistency

Computes the corrections from the history.

static compute_scaling(hessk, hessk_dsk, dskt_hessk_dsk, dyk, dyt_dsk)

Compute scaling.

Parameters
• hessk – previous approximation

• hessk_dsk – product between hessk and dsk

• dskt_hessk_dsk – product between dsk^t, hessk and dsk

• dyk – gradients difference between iterates

• dyt_dsk – product between dyk^t and dsk^t

Generate the s_k and y_k terms, respectively design variable difference and gradients difference between iterates.

Parameters
• x_hist – design variables history array

• iteration – iteration number for which the pair must be generated

get_x_grad_history(funcname, first_iter=0, last_iter=0, at_most_niter=- 1, func_index=None, normalize_design_space=False, design_space=None)

Parameters
• funcname – function name

• first_iter – first iteration after which the history is extracted (Default value = 0)

• last_iter – last iteration before which the history is extracted (Default value = 0)

• at_most_niter – maximum number of iterations to take (Default value = -1)

• func_index – Default value = None)

• normalize_design_space – if True, scale the values to work in a normalized design space (x between 0 and 1)

• design_space – the design space used to scale all values mandatory if normalize_design_space==True

static iterate_approximation(b_mat, s_k, y_k, scaling=False)[source]

SR1 iteration.

Parameters
• b_mat – previous approximation

• s_k – design variable difference between iterates

• y_k – gradients difference between iterates

• scaling – do scaling step

Returns

updated approximation

static iterate_inverse_approximation(h_mat, s_k, y_k, h_factor=None, b_mat=None, b_factor=None, factorize=False, scaling=False)

Inverse BFGS iteration.

Parameters
• h_mat – previous approximation

• s_k – design variable difference between iterates

• y_k – gradients difference between iterates

Returns

updated inverse approximation