1 | function w=sidp_transformace(sidp_parameters, rsss_parameters,system,apriori)
|
---|
2 | %transformace
|
---|
3 | q=0;
|
---|
4 | mode=0;
|
---|
5 | N=sidp_parameters.horizont-2;
|
---|
6 | poc=zeros(N,2);
|
---|
7 | kon=zeros(N,2);
|
---|
8 |
|
---|
9 | eps=10^-2;
|
---|
10 | system.dim=2;
|
---|
11 |
|
---|
12 | if abs(apriori.y0)-2*apriori.y0_range<0
|
---|
13 | apriori.eta0=(abs(apriori.y0)+2*apriori.y0_range)/2/system.sigma;
|
---|
14 | apriori.eta0_range=apriori.eta0;
|
---|
15 | else
|
---|
16 | apriori.eta0=abs(apriori.y0)/system.sigma;
|
---|
17 | apriori.eta0_range=2*apriori.y0_range/system.sigma;
|
---|
18 | end
|
---|
19 | etar=system.yr/system.sigma;
|
---|
20 |
|
---|
21 | apriori.beta0=abs(apriori.b0)/sqrt(apriori.P0);
|
---|
22 | apriori.beta0_range=2*apriori.P0/sqrt(apriori.P0);
|
---|
23 | if apriori.beta0-apriori.beta0_range<eps
|
---|
24 | apriori.beta0=(abs(apriori.b0)+2*apriori.P0)/2/sqrt(apriori.P0);
|
---|
25 | apriori.beta0_range=apriori.beta0-eps;
|
---|
26 | end
|
---|
27 |
|
---|
28 | %pomocne promenne a konstanty
|
---|
29 | step=[1; sidp_parameters.n_grid];
|
---|
30 |
|
---|
31 | [H ny]=init_hyperstate(N,sidp_parameters.n_grid,apriori,mode); %vytvori H a mi, nastavi H0 a mi*
|
---|
32 |
|
---|
33 | for i=1:sidp_parameters.n_pass
|
---|
34 |
|
---|
35 | for j=1:sidp_parameters.n_iter
|
---|
36 | [i j]
|
---|
37 | search_region=sidp_parameters.gama^(j-1)*sidp_parameters.lambda^(i-1)*sidp_parameters.search_region_init;
|
---|
38 | [H ny zero range eigvec]=update_hyperstate(H, ny); %vygeneruje trajektorie, v zasazenem regionu rovnomerne rozmisti body a prekopiruje nalezena mi*
|
---|
39 | %>1
|
---|
40 |
|
---|
41 | %los=mc_study2(system,apriori,1000);
|
---|
42 | %porovnej(los)
|
---|
43 |
|
---|
44 | poc(:,:)=H(:,1,:);
|
---|
45 | kon(:,:)=H(:,end,:);
|
---|
46 |
|
---|
47 | for k=N:-1:1 %pozor na meze
|
---|
48 | level=N-k+1;
|
---|
49 | k
|
---|
50 |
|
---|
51 | for l=1:size(H,2)
|
---|
52 | candidates=generate_candidates(ny(k,l), search_region, sidp_parameters.num_of_candidates,sidp_parameters.generate_candidates_mode);
|
---|
53 |
|
---|
54 | %compare candidates
|
---|
55 | realization1=zeros(size(candidates,1),rsss_parameters.n0);
|
---|
56 |
|
---|
57 | for m=1:sidp_parameters.num_of_candidates
|
---|
58 | best_control=-candidates(m);
|
---|
59 | for n=1:rsss_parameters.n0
|
---|
60 | eta=H(k,l,1);
|
---|
61 | beta=H(k,l,2);
|
---|
62 | %generate realization
|
---|
63 | for o=1:level
|
---|
64 | s=randn;
|
---|
65 | pom=sqrt(1+best_control^2);
|
---|
66 | eta=abs(eta+beta*best_control+pom*s);
|
---|
67 | beta=abs(pom*beta+best_control*s);
|
---|
68 |
|
---|
69 | realization1(m,n)=realization1(m,n)+(eta-etar(k+o))^2;
|
---|
70 |
|
---|
71 | if o<level
|
---|
72 | %find in H
|
---|
73 | stav=[eta beta]-zero(k+o,:);
|
---|
74 | stav1(1)=(stav(1)*eigvec(k+o,1,1)+stav(2)*eigvec(k+o,2,1))*range(k+o,1)*(sidp_parameters.n_grid-1)+1;
|
---|
75 | stav1(2)=(stav(1)*eigvec(k+o,1,2)+stav(2)*eigvec(k+o,2,2))*range(k+o,2)*(sidp_parameters.n_grid-1)+1;
|
---|
76 | index=min(max(round(stav1),1),sidp_parameters.n_grid)-[0 1];
|
---|
77 | index=index*step;
|
---|
78 |
|
---|
79 | best_control=-ny(k+o,index);
|
---|
80 | %if index==find_in_hyperstate5([eta beta], H(k+o,:,:))
|
---|
81 | %else
|
---|
82 | % 1 ;
|
---|
83 | %end
|
---|
84 | % plot(H(k+o,:,1),H(k+o,:,2), 'r.' ); hold on; plot(eta,beta, 'b+' ); plot(H(k+o,index,1),H(k+o,index,2), 'g+' ); hold off
|
---|
85 | end
|
---|
86 | end
|
---|
87 | best_control=-(eta-etar(end))*beta/(1+beta^2);
|
---|
88 | s=randn;
|
---|
89 | pom=sqrt(1+best_control^2);
|
---|
90 | eta=abs(eta+beta*best_control+pom*s);
|
---|
91 |
|
---|
92 | realization1(m,n)=realization1(m,n)+(eta-etar(end))^2;
|
---|
93 | end
|
---|
94 | end
|
---|
95 | mean_values=mean(realization1,2);
|
---|
96 | [min_val min_index]=min(mean_values);
|
---|
97 | best_control=candidates(min_index);
|
---|
98 | ny(k,l)=best_control;
|
---|
99 | end
|
---|
100 | end
|
---|
101 |
|
---|
102 | vypis(:,:)=H(:,:,1);
|
---|
103 | save 'eta.txt' vypis -ASCII;
|
---|
104 | vypis(:,:)=H(:,:,2);
|
---|
105 | save 'Beta.txt' vypis -ASCII;
|
---|
106 | save 'ny.txt' ny -ASCII;
|
---|
107 |
|
---|
108 | los=mc_study(sidp_parameters,system,apriori,1000,[0 0 0]);
|
---|
109 | q=q+1;
|
---|
110 | w(q)=los(3)/los(4);
|
---|
111 | end
|
---|
112 | end
|
---|
113 | %w
|
---|
114 | end
|
---|