TransWikia.com

Evaluating expected improvement in Mathematica

Mathematica Asked on August 12, 2021

There is a concept in optimization called expected improvement where you sequentially search for the value of x that optimizes the problem. Here is a screen shot of the general idea of the derivation:

enter image description here

Now, what I am trying to figure out is how to evaluate the expected value of the improvement function in Mathematica?

Here is code that I have tried, but for some reason it is not returning the answer I would have expected. Can anyone please point out why what I am doing is wrong, or give Mathematica code that does the correct evaluation?

Here is my code:

Expectation[Max[f-Y,0], Y [Distributed] NormalDistribution[mu,sigma]]

which returns the following incorrect expression:

enter image description here

One Answer

[...] which returns the following incorrect expression:

OPimg

No, the expression computed by Mathematica is correct.

Below that is verified.

1

"where ?, ? are the PDF and CDF of standard normal distribution, respectively."

Definitions as in OP's question:

[Phi][x_] := Evaluate[PDF[NormalDistribution[0, 1], x]];
[CapitalPhi][x_] := Evaluate[CDF[NormalDistribution[0, 1], x]];

2

Code from OP's question:

res1 = Expectation[
  Max[f - ([Mu] + [Sigma] [Epsilon]), 0], [Epsilon] [Distributed] 
   NormalDistribution[0, 1], Assumptions -> [Sigma] > 0]

(* (E^(-((f - [Mu])^2/(
  2 [Sigma]^2))) (E^((f - [Mu])^2/(2 [Sigma]^2)) f Sqrt[[Pi]] - 
   E^((f - [Mu])^2/(2 [Sigma]^2)) Sqrt[[Pi]] [Mu] + Sqrt[2] [Sigma] + 
   E^((f - [Mu])^2/(2 [Sigma]^2)) f Sqrt[[Pi]]
     Erf[(f - [Mu])/(Sqrt[2] [Sigma])] - 
   E^((f - [Mu])^2/(2 [Sigma]^2))
     Sqrt[[Pi]] [Mu] Erf[(f - [Mu])/(Sqrt[2] [Sigma])]))/(2 Sqrt[[Pi]]) *)

3

Simplified result:

res1 = FullSimplify[res1]

(* (E^(-((f - [Mu])^2/(2 [Sigma]^2))) [Sigma])/Sqrt[2 [Pi]] + 
 1/2 (f - [Mu]) (1 + Erf[(f - [Mu])/(Sqrt[2] [Sigma])]) *)

4

The right hand side of the last EI(x) formula in OP's question:

res2 = (f - [Mu])*[CapitalPhi][(f - [Mu])/[Sigma]] + [Sigma]*[Phi][(
    f - [Mu])/[Sigma]]

(* (E^(-((f - [Mu])^2/(2 [Sigma]^2))) [Sigma])/Sqrt[2 [Pi]] + 
 1/2 (f - [Mu]) Erfc[-((f - [Mu])/(Sqrt[2] [Sigma]))] *)

5

Compare the results:

FullSimplify[res1 == res2]

(* True *)

enter image description here

Correct answer by Anton Antonov on August 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP