Stats

Popular Posts

Followers

Mathematica 教學:Value function iterations for deterministic cake eating problem

戴忠淵 於 Friday, February 3, 2023 10:01 PM 發表

Value function iterations方法是通過計算出最佳化問題的每一步所實現的最佳結果,並將這些結果用於計算下一步的最佳結果。此過程在一定數量的迭代後會得到一個最佳策略,並且這個策略也是最終的最佳解。因此它對於解決複雜的最佳化問題非常有用。它可以被用於解決各種經濟學、工程學和其他領域的最佳化問題。
ClearAll["Global`*"]
\[Alpha]=0.3;
\[Beta]=0.95;
\[Delta]=0.1;
\[Sigma]=1.5;
size=99;
K=Range[0.1,5,4.9/(size)];
V=Table[0,{size}];

ast=With[{n=size},
obj=
ParallelTable[
If[i^\[Alpha]+(1-\[Delta])*i-j<0,-10^9,
((i^\[Alpha]+(1-\[Delta])*i-j)^(1-\[Sigma])-1)/(1-\[Sigma])],
{i,0.1,5,4.9/n},{j,0.1,5,4.9/n}];
loops=0;
\[Epsilon]=99999;

Print[
Grid[{{"loop number ",Dynamic[loops]," with distance ",
Dynamic[NumberForm[\[Epsilon],
ExponentFunction->(If[-10<#<10,Null,#]&)]]}}]];

NestWhile[
Transpose[SortBy[#,First][[-1]]&/@Table[{obj[[i,j]]+\[Beta]*#[[1,j]],
Range[0.1,5,4.9/n][[j]]},{i,n+1},{j,n+1}]//Parallelize]&,
{Table[0,n+1],Table[0,n+1]},(loops++;\[Epsilon]=Norm[#1[[1]]-#2[[1]]];
Norm[#1[[1]]-#2[[1]]]>10^-6)&,2]
];
Tags: , , , ,

讀者回應 ( 0 意見 )

Post a Comment

Please leave your name and tell me what you thought about this site. Comments, suggestions and views are welcomed.

如果這篇文章對你有幫助,那請留個訊息給我~