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:
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:
[...] which returns the following incorrect expression:
No, the expression computed by Mathematica is correct.
Below that is verified.
"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]];
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]]) *)
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])]) *)
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]))] *)
Compare the results:
FullSimplify[res1 == res2]
(* True *)
Correct answer by Anton Antonov on August 12, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP