WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

Matlab Optimierungsproblem

 

Lisa89
Forum-Anfänger

Forum-Anfänger


Beiträge: 33
Anmeldedatum: 13.12.18
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 24.11.2019, 16:37     Titel: Matlab Optimierungsproblem
  Antworten mit Zitat      
Hallo,

ich suche jemanden, der mir bei der Programmierung eines Models aus der Volkswirtschaft helfen kann. Es handelt sich dabei, um ein Optimierierungsproblem.
Ich habe das Model schon programmiert nur es gibt einen Teil, den ich leider nicht verstehe. Ich habe auch einen Code, der für so einen ähnlichen Fall geschrieben worden ist aber leider kann ich den Code nicht nachvollziehen. Kann mir jemand dabei helfen?


LG
Lisa
Private Nachricht senden Benutzer-Profile anzeigen


Harald
Forum-Meister

Forum-Meister


Beiträge: 24.495
Anmeldedatum: 26.03.09
Wohnort: Nähe München
Version: ab 2017b
     Beitrag Verfasst am: 24.11.2019, 16:47     Titel:
  Antworten mit Zitat      
Hallo,

poste am besten den Code und die konkrete Frage dazu, dann kann man sehen, ob man dir weiterhelfen kann.

Grüße,
Harald
_________________

1.) Ask MATLAB Documentation
2.) Search gomatlab.de, google.de or MATLAB Answers
3.) Ask Technical Support of MathWorks
4.) Go mad, your problem is unsolvable ;)
Private Nachricht senden Benutzer-Profile anzeigen
 
Lisa89
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 33
Anmeldedatum: 13.12.18
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 26.11.2019, 12:34     Titel:
  Antworten mit Zitat      
Hallo Harald,

der Code sieht wie folgt aus: Das ist das eigentliche Model.
Code:
% Version 1: Taylor-Rule depends on E[x(+1)] and E[pi(+1)]

% Q             Number of quarters in data output
% seed          Initializer for the pseudo random number generator
% varargin      Additional input arguments that can be used to change standard parameterization
%               e.g.: GenerateDynamics(100, 1, 'h',0.5)
%               del_d_s can be used to analyze UNconventional monetary policy
%
% data          Structure array containing all return data


%% Initialization
randn('seed',seed);         % ... of pseudo random number generator
exploded = 0;               % ... of control variable to check whether dynamics did explode

%% Taylor Rule
del_x = 0.5;       % Taylor Parameter Outputgap
del_pi = 1.5;      % Taylor Parameter Inflation
eta = 0;           % Persistence    ... + eta*i(q-1)
del_d_s = 0;

%% Financial Markets Tax
tau = 0;           % Financial transaction tax
tax_type = 'FTT';  % FTT or FAT, FAT_progressive (bei letzterer muss unten der 'normale' Steuersatz gesetzt werden)

%% Shock    0, 1, 2:    0 --> No shock    
%                       1 --> Cost shock in q = 10
%                       3 --> Interest Rate Shock
%                       4 --> tau shock
Shock = 0;

%% interaction parameter
k = 0;
kap = 0;
c_1 = 0;
c_3 = 0.5;
c_4 = 1;
h = 0;

%% NKM Parameters
sig = 1;
%gam = 0.17166;  % wird unten aus den deep parameters berechnet
bet = 0.99;
alp_x = 0.2;
alp_pi = 0.2;
alp_s = 0.2;
zeta = 0.5;
phi = 10;

sig_eps = 0.15;

alp=0.0; eps=6; thet=0.67; varphi=1;


%% ABC Parameter
a = 1;
b = 0.04;
c = 0.04;
d = 0.975;
e = 300;
f_bar = 0;
var_s = 0.01;
var_C = 0.05;
var_F = 0.01;

%% Special parameters
Turn_Noise_Off_in_q = -1;
ParTabPath = '';  % to which path should the parameterization table be saved ('' meens none)

% Weights that are used to bring the daily stock prices to a quartertly level
st_sq_weights = (ones(64,1)/64);                    %  <-- equally weighted
%st_sq_weights = (1-0.5) * (0.5).^[63:-1:0]';       %  <-- geometrically decaying weighted
%st_sq_weights = st_sq_weights./sum(st_sq_weights);

silent = false;  % Bei explosivem Pfad keine Warnung anzeigen

%% Change parameterization depending on "nargin"
for i = 1:length(varargin)
    if strcmpi(varargin{i},'h')
        h = varargin{i+1};
    end
    if strcmpi(varargin{i},'kap')
        kap = varargin{i+1};
    end
    if strcmpi(varargin{i},'c_1')
        c_1 = varargin{i+1};
    end
    if strcmpi(varargin{i},'k')
        k = varargin{i+1};
    end
    if strcmpi(varargin{i},'1_minus_thet')
        thet = 1 - varargin{i+1};
    end
    if strcmpi(varargin{i},'alp_x')
        alp_x = varargin{i+1};
    end
    if strcmpi(varargin{i},'phi')
        phi = varargin{i+1};
    end
    if strcmpi(varargin{i},'zeta')
        zeta = varargin{i+1};
    end
    if strcmpi(varargin{i},'alp_pi')
        alp_pi = varargin{i+1};
    end
    if strcmpi(varargin{i},'del_d_s')
        del_d_s = varargin{i+1};
    end
    if strcmpi(varargin{i},'a')
        a = varargin{i+1};
    end
    if strcmpi(varargin{i},'b')
        b = varargin{i+1};
    end
    if strcmpi(varargin{i},'Turn_Noise_Off_in_q')
        Turn_Noise_Off_in_q = varargin{i+1};
    end    
    if strcmpi(varargin{i},'ParTabPath')
        ParTabPath = varargin{i+1};
    end
    if strcmpi(varargin{i},'del_x')
        del_x = varargin{i+1};
    end
    if strcmpi(varargin{i},'del_pi')
        del_pi = varargin{i+1};
    end
    if strcmpi(varargin{i},'eta')
        eta = varargin{i+1};
    end
    if strcmpi(varargin{i},'silent')
        silent = true;
    end
   
end

gam = (1-thet)*(1-bet*thet)/thet * (1-alp)/(1-alp+alp*eps) * (sig + (varphi+alp)/(1-alp));   %0.17166;  %0.35;


%% create data vectors
burnin = 20;        % quarters to remove at beginning
T = (Q+burnin)*64;  % Total number of day (including burnin)

% Data Vectors for NKM
x_vec  = zeros(1,Q+burnin);
pi_vec = zeros(1,Q+burnin);
sq_vec = zeros(1,Q+burnin);
i_vec  = zeros(1,Q+burnin);
r_vec  = zeros(1,Q+burnin);
dq_vec = zeros(1,Q+burnin);

Ex_vec = zeros(1,Q+burnin);     % Expectation: E_q[q+1] is located at position q in this vector
Ex_tar_vec = zeros(1,Q+burnin);
Ex_hab_vec = zeros(1,Q+burnin);
Ex_ext_vec = zeros(1,Q+burnin);
Epi_vec = zeros(1,Q+burnin);
Epi_tar_vec = zeros(1,Q+burnin);
Epi_rof_vec = zeros(1,Q+burnin);
Epi_ext_vec = zeros(1,Q+burnin);
Es_vec = zeros(1,Q+burnin);
Es_tar_vec = zeros(1,Q+burnin);
Es_sta_vec = zeros(1,Q+burnin);
Es_ext_vec = zeros(1,Q+burnin);

A_x_tar_vec = zeros(1,Q+burnin);     % Attractivity of optimist forcasting of x
A_x_hab_vec = zeros(1,Q+burnin);
A_x_ext_vec = zeros(1,Q+burnin);
A_pi_tar_vec = zeros(1,Q+burnin);     % Attractivity of extrapolators forcasting of pi
A_pi_rof_vec = zeros(1,Q+burnin);
A_pi_ext_vec = zeros(1,Q+burnin);
A_s_tar_vec = zeros(1,Q+burnin);     % Attractivity of extrapolators forcasting of pi
A_s_sta_vec = zeros(1,Q+burnin);
A_s_ext_vec = zeros(1,Q+burnin);

W_x_tar_vec = zeros(1,Q+burnin);
W_x_hab_vec = zeros(1,Q+burnin);
W_x_ext_vec = zeros(1,Q+burnin);
W_pi_tar_vec = zeros(1,Q+burnin);
W_pi_rof_vec = zeros(1,Q+burnin);
W_pi_ext_vec = zeros(1,Q+burnin);
W_s_tar_vec = zeros(1,Q+burnin);
W_s_sta_vec = zeros(1,Q+burnin);
W_s_ext_vec = zeros(1,Q+burnin);

% Data Vectors for ABC
st_vec  = ones(1,T+1)*f_bar;     %One longer for the last price adjust
f_vec  = ones(1,T)*f_bar;
DF_vec = zeros(1,T);
DC_vec = zeros(1,T);
AF_vec = zeros(1,T);
AC_vec = zeros(1,T);
WF_vec = zeros(1,T);
WC_vec = zeros(1,T);
ProfitTaxless_F_vec = zeros(1,T);
ProfitTaxless_C_vec = zeros(1,T);

TaxRevenue_quarterly = zeros(1,Q+burnin);
TaxRevenue = zeros(1,T);

%% Generate data
noise_nkm = randn(3,Q+burnin)*sig_eps;     % contains [epsilon_i; epsilon_x; epsilon_pi]
%noise_sm  = randn(3,(Q+burnin)*64) .* ([var_s;var_C;var_F]*ones(1,(Q+burnin)*64));     % contains [epsilon_s; epsilon_C; epsilon_F]

if Turn_Noise_Off_in_q>0 && Turn_Noise_Off_in_q<Q
    noise_nkm(:,burnin+Turn_Noise_Off_in_q:end) = 0;
    %noise_sm(:,(burnin+Turn_Noise_Off_in_q)*64:end)  = 0;
end
for q = 3:Q+burnin                  % Loop through quarters

    if q==5+burnin                  % Perform the shock: Make people more pessimistic (Caution, A is negative)
        if (Shock==4)
            tau = 0.01;
        end
    end
   
    if q==Turn_Noise_Off_in_q
        var_s = 0;
        var_C = 0;
        var_F = 0;
    end
   
    for t = ((q-1)*64+1):q*64           % Loop through days
   
        f_vec(t) = h*x_vec(q-1);

        ProfitTaxless_F_vec(t) = (exp(st_vec(t))-exp(st_vec(t-1)))*DF_vec(t-2);
        ProfitTaxless_C_vec(t) = (exp(st_vec(t))-exp(st_vec(t-1)))*DC_vec(t-2);
       
        % Attractivity
        if strcmp(tax_type,'FTT')
            AF_vec(t) = ProfitTaxless_F_vec(t) - tau*(exp(st_vec(t))+exp(st_vec(t-1)))*abs(DF_vec(t-2)) + d*AF_vec(t-1);
            AC_vec(t) = ProfitTaxless_C_vec(t) - tau*(exp(st_vec(t))+exp(st_vec(t-1)))*abs(DC_vec(t-2)) + d*AC_vec(t-1);
            TaxRevenue(t) = tau*(exp(st_vec(t))+exp(st_vec(t-1))) * (abs(DF_vec(t-2))*WF_vec(t-2)+abs(DC_vec(t-2))*WC_vec(t-2));
        elseif strcmp(tax_type,'FAT')
            AF_vec(t) = ProfitTaxless_F_vec(t)  - (ProfitTaxless_F_vec(t) > 0)*tau*ProfitTaxless_F_vec(t)    + d*AF_vec(t-1);
            AC_vec(t) = ProfitTaxless_C_vec(t)  - (ProfitTaxless_C_vec(t) > 0)*tau*ProfitTaxless_C_vec(t)    + d*AC_vec(t-1);
            TaxRevenue(t) = (ProfitTaxless_F_vec(t) > 0)*tau*ProfitTaxless_F_vec(t)*WF_vec(t-2)   +   (ProfitTaxless_C_vec(t) > 0)*tau*ProfitTaxless_C_vec(t)*WC_vec(t-2);
        elseif strcmp(tax_type,'FAT_progressive')
            FAT_rate_F = (ProfitTaxless_F_vec(t) > 0) * min(1, tau * ProfitTaxless_F_vec(t)^2 / 0.0015^2 * (ProfitTaxless_F_vec(t) > 0) );
            FAT_rate_C = (ProfitTaxless_C_vec(t) > 0) * min(1, tau * ProfitTaxless_C_vec(t)^2 / 0.0015^2 * (ProfitTaxless_C_vec(t) > 0) );
            AF_vec(t) = ProfitTaxless_F_vec(t) - FAT_rate_F*ProfitTaxless_F_vec(t)    + d*AF_vec(t-1);
            AC_vec(t) = ProfitTaxless_C_vec(t) - FAT_rate_C*ProfitTaxless_C_vec(t)    + d*AC_vec(t-1);
            TaxRevenue(t) = (ProfitTaxless_F_vec(t) > 0)*FAT_rate_F*ProfitTaxless_F_vec(t)*WF_vec(t-2)   +   (ProfitTaxless_C_vec(t) > 0)*FAT_rate_C*ProfitTaxless_C_vec(t)*WC_vec(t-2);
        end
           
        % Weights
        WF_vec(t) = exp(e*AF_vec(t)) / (exp(e*AF_vec(t))+exp(e*AC_vec(t))+1);
        WC_vec(t) = exp(e*AC_vec(t)) / (exp(e*AF_vec(t))+exp(e*AC_vec(t))+1);
       
        % Demands
        DF_vec(t) = c*(f_vec(t)-st_vec(t))  +  randn*var_F;
        DC_vec(t) = b*(st_vec(t)-st_vec(t-1))  +  randn*var_C;

        % Stock price
        st_vec(t+1) = st_vec(t) + a*(WF_vec(t)*DF_vec(t)+WC_vec(t)*DC_vec(t)+k/64*(dq_vec(q-1)-dq_vec(q-2)+del_d_s*st_vec(t))) + randn*var_s;

    end
   
    TaxRevenue_quarterly(q) = sum(TaxRevenue(((q-1)*64+1):q*64));
    sq_vec(q) =  st_vec((q-1)*64+1:q*64) * st_sq_weights;          % Calculate relevant mean stock price for NKM model
%TaxRevenue_quarterly(q) = 0;
%sq_vec(q) = 0;

    % Attractivity
    A_x_tar_vec(q)  = -(x_vec(q-1) -Ex_tar_vec(q-2))^2  + zeta*A_x_tar_vec(q-1);
    A_x_hab_vec(q)  = -(x_vec(q-1) -Ex_hab_vec(q-2))^2  + zeta*A_x_hab_vec(q-1);
    A_x_ext_vec(q)  = -(x_vec(q-1) -Ex_ext_vec(q-2))^2  + zeta*A_x_ext_vec(q-1);
    A_pi_tar_vec(q) = -(pi_vec(q-1)-Epi_tar_vec(q-2))^2 + zeta*A_pi_tar_vec(q-1);
    A_pi_rof_vec(q) = -(pi_vec(q-1)-Epi_rof_vec(q-2))^2 + zeta*A_pi_rof_vec(q-1);
    A_pi_ext_vec(q) = -(pi_vec(q-1)-Epi_ext_vec(q-2))^2 + zeta*A_pi_ext_vec(q-1);
    A_s_tar_vec(q)  = -(sq_vec(q-1)-Es_tar_vec(q-2))^2 + zeta*A_s_tar_vec(q-1);
    A_s_sta_vec(q)  = -(sq_vec(q-1)-Es_sta_vec(q-2))^2 + zeta*A_s_sta_vec(q-1);
    A_s_ext_vec(q)  = -(sq_vec(q-1)-Es_ext_vec(q-2))^2 + zeta*A_s_ext_vec(q-1);
   
     
    % Weights
    W_x_tar_vec(q)  = exp(phi*A_x_tar_vec(q))  /  (exp(phi*A_x_tar_vec(q)) +exp(phi*A_x_hab_vec(q)) +exp(phi*A_x_ext_vec(q)));
    W_x_hab_vec(q)  = exp(phi*A_x_hab_vec(q))  /  (exp(phi*A_x_tar_vec(q)) +exp(phi*A_x_hab_vec(q)) +exp(phi*A_x_ext_vec(q)));
    W_x_ext_vec(q)  = exp(phi*A_x_ext_vec(q))  /  (exp(phi*A_x_tar_vec(q)) +exp(phi*A_x_hab_vec(q)) +exp(phi*A_x_ext_vec(q)));
    if sum(isnan([W_x_tar_vec(q) W_x_hab_vec(q) W_x_ext_vec(q)])) > 0   % if all weights are very small, a division by zero would be created below
        W_x_tar_vec(q) = 0;
        W_x_hab_vec(q) = 0;
        W_x_ext_vec(q) = 0;
        if A_x_tar_vec(q) > A_x_hab_vec(q) && A_x_tar_vec(q) > A_x_ext_vec(q)
            W_x_tar_vec(q) = 1;
        elseif A_x_hab_vec(q) > A_x_tar_vec(q) && A_x_hab_vec(q) > A_x_ext_vec(q)
            W_x_hab_vec(q) = 1;
        else
            W_x_ext_vec(q) = 1;
        end
    end
    W_pi_tar_vec(q) = exp(phi*A_pi_tar_vec(q)) /  (exp(phi*A_pi_tar_vec(q))+exp(phi*A_pi_rof_vec(q))+exp(phi*A_pi_ext_vec(q)));
    W_pi_rof_vec(q) = exp(phi*A_pi_rof_vec(q)) /  (exp(phi*A_pi_tar_vec(q))+exp(phi*A_pi_rof_vec(q))+exp(phi*A_pi_ext_vec(q)));
    W_pi_ext_vec(q) = exp(phi*A_pi_ext_vec(q)) /  (exp(phi*A_pi_tar_vec(q))+exp(phi*A_pi_rof_vec(q))+exp(phi*A_pi_ext_vec(q)));
    if sum(isnan([W_pi_tar_vec(q) W_pi_rof_vec(q) W_pi_ext_vec(q)])) > 0   % if all weights are very small, a division by zero would be created below
        W_pi_tar_vec(q) = 0;
        W_pi_rof_vec(q) = 0;
        W_pi_ext_vec(q) = 0;
        if A_pi_tar_vec(q) > A_pi_rof_vec(q) && A_pi_tar_vec(q) > A_pi_ext_vec(q)
            W_pi_tar_vec(q) = 1;
        elseif A_pi_rof_vec(q) > A_pi_tar_vec(q) && A_pi_rof_vec(q) > A_pi_ext_vec(q)
            W_pi_rof_vec(q) = 1;
        else
            W_pi_ext_vec(q) = 1;
        end
    end
    W_s_tar_vec(q) = exp(phi*A_s_tar_vec(q)) /  (exp(phi*A_s_tar_vec(q))+exp(phi*A_s_sta_vec(q))+exp(phi*A_s_ext_vec(q)));
    W_s_sta_vec(q) = exp(phi*A_s_sta_vec(q)) /  (exp(phi*A_s_tar_vec(q))+exp(phi*A_s_sta_vec(q))+exp(phi*A_s_ext_vec(q)));
    W_s_ext_vec(q) = exp(phi*A_s_ext_vec(q)) /  (exp(phi*A_s_tar_vec(q))+exp(phi*A_s_sta_vec(q))+exp(phi*A_s_ext_vec(q)));
   
   
    % time dependend system variables
    A_q = [sig-(sig-(1-eta)*del_x)*W_x_ext_vec(q)*(1+alp_x)-sig*c_1*W_s_tar_vec(q)*h  -(1-(1-eta)*del_pi-sig*c_1)*W_pi_ext_vec(q)*(1+alp_pi) ;
           -gam  1-bet*W_pi_ext_vec(q)*(1+alp_pi)];
    C_q = [(sig-(1-eta)*del_x)*(W_x_hab_vec(q)-W_x_ext_vec(q)*alp_x)  (1-(1-eta)*del_pi-sig*c_1)*(W_pi_rof_vec(q)-W_pi_ext_vec(q)*alp_pi) ;
           0  bet*(W_pi_rof_vec(q)-W_pi_ext_vec(q)*alp_pi)];
    D_q = [c_1*sig*(W_s_ext_vec(q)*(1+alp_s)-1) ; -kap];
    E_q = [c_1*sig*(W_s_sta_vec(q)-alp_s*W_s_ext_vec(q)) ; 0];
   
    res = inv(A_q)*C_q*[x_vec(q-1); pi_vec(q-1)]  +  inv(A_q)*D_q*sq_vec(q)  +  inv(A_q)*E_q*sq_vec(q-1)  +  inv(A_q)*[-eta;0]*i_vec(q-1)  +  inv(A_q)*[ sig*noise_nkm(2,q)-noise_nkm(1,q) ; noise_nkm(3,q) ];
   
    if q==5+burnin          % Perform the shock
        if (Shock==1)           % cost shock
            res = res + inv(A_q)*[ 0-0/sig ; 1 ];
        elseif (Shock==3)       % interest rate shock
            res = res + inv(A_q)*[ 0-1/sig ; 0 ];
        end
    end
       
    % Save results in other vector
    x_vec(q) = res(1);
    pi_vec(q) = res(2);
   
    % Expectations for q+1
    Ex_tar_vec(q)  = 0;
    Ex_hab_vec(q)  = x_vec(q-1);
    Ex_ext_vec(q)  = x_vec(q) + alp_x*(x_vec(q)-x_vec(q-1));
    Ex_vec(q) = W_x_tar_vec(q)*Ex_tar_vec(q) + W_x_hab_vec(q)*Ex_hab_vec(q) + W_x_ext_vec(q)*Ex_ext_vec(q);  % market expectation of output gap
    Epi_tar_vec(q) = 0;
    Epi_rof_vec(q) = pi_vec(q-1);
    Epi_ext_vec(q) = pi_vec(q) + alp_pi*(pi_vec(q)-pi_vec(q-1));
    Epi_vec(q) = W_pi_tar_vec(q)*Epi_tar_vec(q) + W_pi_rof_vec(q)*Epi_rof_vec(q) + W_pi_ext_vec(q)*Epi_ext_vec(q);  % market expectation of output gap
    Es_tar_vec(q) = 0;
    Es_sta_vec(q) = sq_vec(q-1);
    Es_ext_vec(q) = sq_vec(q) + alp_s*(sq_vec(q)-sq_vec(q-1));
    Es_vec(q) = W_s_tar_vec(q)*Es_tar_vec(q) + W_s_sta_vec(q)*Es_sta_vec(q) + W_s_ext_vec(q)*Es_ext_vec(q);  % market expectation of output gap
   
    % interest rate
    i_vec(q) = del_pi*Epi_vec(q) + del_x*Ex_vec(q) + noise_nkm(1,q);
    r_vec(q) = i_vec(q) - Epi_vec(q);
   
    % stock demand of households
    dq_vec(q) = x_vec(q)  -c_3*(sq_vec(q)-sum(pi_vec(1:q))) - c_4*i_vec(q);
   
end

%% Check if s exploded
if isnan(st_vec(length(st_vec))) || st_vec(end) > 10000
    if silent == false
        disp('Exploded!    :-(     ');
    end
    exploded = 1;
end


%% Put all results into "result" variable
result.x  = x_vec(burnin+1:(Q+burnin));
result.pi = pi_vec(burnin+1:(Q+burnin));
result.sq = sq_vec(burnin+1:(Q+burnin));
result.i  = i_vec(burnin+1:(Q+burnin));
result.r  = r_vec(burnin+1:(Q+burnin));
result.dq  = dq_vec(burnin+1:(Q+burnin));
result.Ex = Ex_vec(burnin+1:(Q+burnin));
result.Ex_tar = Ex_tar_vec(burnin+1:(Q+burnin));
result.Ex_hab = Ex_hab_vec(burnin+1:(Q+burnin));
result.Ex_ext = Ex_ext_vec(burnin+1:(Q+burnin));
result.W_x_tar = W_x_tar_vec(burnin+1:(Q+burnin));
result.W_x_hab = W_x_hab_vec(burnin+1:(Q+burnin));
result.W_x_ext = W_x_ext_vec(burnin+1:(Q+burnin));
result.Epi = Epi_vec(burnin+1:(Q+burnin));
result.Epi_tar = Epi_tar_vec(burnin+1:(Q+burnin));
result.Epi_rof = Epi_rof_vec(burnin+1:(Q+burnin));
result.Epi_ext = Epi_ext_vec(burnin+1:(Q+burnin));
result.W_pi_tar = W_pi_tar_vec(burnin+1:(Q+burnin));
result.W_pi_rof = W_pi_rof_vec(burnin+1:(Q+burnin));
result.W_pi_ext = W_pi_ext_vec(burnin+1:(Q+burnin));

result.st = st_vec(burnin*64+1:(Q+burnin)*64);
result.f = f_vec(burnin*64+1:(Q+burnin)*64);
result.WF = WF_vec(burnin*64+1:(Q+burnin)*64);
result.WC = WC_vec(burnin*64+1:(Q+burnin)*64);
result.ProfitTaxless_F = ProfitTaxless_F_vec(burnin*64+1:(Q+burnin)*64);
result.ProfitTaxless_C = ProfitTaxless_C_vec(burnin*64+1:(Q+burnin)*64);

result.TaxRevenue_quarterly = TaxRevenue_quarterly(burnin+1:(Q+burnin));
result.TaxRevenue = TaxRevenue(burnin*64+1:(Q+burnin)*64);

result.exploded = exploded;


Das Problem liegt hier: Ich kann diesen Code nicht nachvollziehen. Es handelt sich um ein Optimierungsporblem:
Code:

function [ LossVal, vol_pi, vol_x,vol_s ] = Loss_Fun( data, w_pi, w_x )

vol_pi = (mean(data.pi.^2));
vol_x = (mean(data.x.^2));
vol_s = (mean(data.st.^2));

LossVal =   w_pi * vol_pi ...
          + w_x  * vol_x  ...
          + w_s  * vol_s;

         w_pi = 0.5 ;   %1;
         w_x = 0.25;   %0.5;
       
end
 

Code:
function [ LossVal, vol_pi, vol_x, vol_s ] = Eval_Loss_Fun( optim_par, fix_par )

    % Set the data generating process
    global DGP

    % Check if results already exist
    file_name_BerechnungsSpeicher = [num2str(optim_par,20) ' ' num2str(fix_par,20)];
    for i = 1:5
        file_name_BerechnungsSpeicher = strrep(file_name_BerechnungsSpeicher,'               ',' ');
        file_name_BerechnungsSpeicher = strrep(file_name_BerechnungsSpeicher,'   ',' ');
        file_name_BerechnungsSpeicher = strrep(file_name_BerechnungsSpeicher,'  ',' ');
    end
    warning off;  mkdir(['Berechnungsspeicher/' DGP]);  warning on;
    file_name_BerechnungsSpeicher = ['Berechnungsspeicher/' DGP '/' strrep(file_name_BerechnungsSpeicher,' ','_') '.mat'];
    %delete(file_name_BerechnungsSpeicher);
   
    if exist(file_name_BerechnungsSpeicher, 'file') == 0    
   
        del_pi = optim_par(1);
        del_x  = optim_par(2);
       
        if length(optim_par) >= 3
            del_d_s = optim_par(3);
        else
            del_d_s = NaN;
        end

        % interaction parameter
        k = fix_par(1);   %0.2;
        kap = fix_par(2);   %0.1;
        c_1 = fix_par(3);   %0.2;
        h = fix_par(4);   %0.5;

        % Weights for Loss Function
        w_pi = fix_par(5);   %1;
        w_x = fix_par(6);   %0.5;
        w_s = fix_par(7);   %0;

        if length(fix_par) >= 8
            eta = fix_par(8);   %0;
        else
            eta = 0;
        end

        no_of_seeds = 100;

        seeds = 100:100:100*no_of_seeds;
        LossVal_vec = zeros(size(seeds));
        vol_pi_vec  = zeros(size(seeds));
        vol_x_vec   = zeros(size(seeds));
        vol_s_vec   = zeros(size(seeds));
        for seed_pos = 1:no_of_seeds
            if isnan(del_d_s)
                eval(['data = ' DGP '(500, ' num2str(seeds(seed_pos)) ', ''del_pi'',' num2str(del_pi) ', ''del_x'',' num2str(del_x) ', ''k'',' num2str(k) ', ''kap'',' num2str(kap) ', ''c_1'',' num2str(c_1) ', ''h'',' num2str(h) ', ''eta'',' num2str(eta) ', ''silent'');']);
                %data = GenerateDynamics_Erw2(500, seeds(seed_pos), 'del_pi',del_pi, 'del_x',del_x, 'k',k, 'kap',kap, 'c_1',c_1, 'h',h, 'silent');
            else
                eval(['data = ' DGP '(500, ' num2str(seeds(seed_pos)) ', ''del_pi'',' num2str(del_pi) ', ''del_x'',' num2str(del_x) ', ''del_d_s'', ' num2str(del_d_s) ', ''k'',' num2str(k) ', ''kap'',' num2str(kap) ', ''c_1'',' num2str(c_1) ', ''h'',' num2str(h) ', ''eta'',' num2str(eta) ', ''silent'');']);
            end
            [ LossVal_vec(seed_pos), vol_pi_vec(seed_pos), vol_x_vec(seed_pos), vol_s_vec(seed_pos) ] = Loss_Fun( data, w_pi, w_x, w_s );
            %pause(0.01)
        end

        LossVal = mean(LossVal_vec);
        vol_pi  = mean(vol_pi_vec);
        vol_x   = mean(vol_x_vec);
        vol_s   = mean(vol_s_vec);

        if isnan(LossVal)
            LossVal = inf;
        end

        % Save Loss_Value to hard disk
        save(file_name_BerechnungsSpeicher, 'LossVal', 'vol_pi', 'vol_x', 'vol_s');
   
    else
   
        % Lode previously saved result from hard disk
        load(file_name_BerechnungsSpeicher);
        pause(0.01);
   
    end
   
end


Ich stehe komplett auf dem Schlauch hier. Zuerst wird die Lossfunktion definiert, das erkenne ich nicht. Aber was dann danach passiert, verstehe ich nicht. Wie man an dem unteren Teil des Codes erkennen kann, sollen optimale parameter gefunden werden, um die Lossfunktion so klein wie möglich zu halten.
Private Nachricht senden Benutzer-Profile anzeigen
 
Lisa89
Themenstarter

Forum-Anfänger

Forum-Anfänger


Beiträge: 33
Anmeldedatum: 13.12.18
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 27.11.2019, 15:42     Titel:
  Antworten mit Zitat      
Ich habe einen Ansatz gefunden, um das Optimierungsproblem zu lösen und zwar mit dem Nelder Mead Algorithmus. Aber dafür bräuchte ich Hilfe. Ich hab diese Beschreibung im Internet gefunden und das ist genau das, was ich machen muss:

The loss_search_ files start the Nelder-Mead algorithm that optimizes the coefficients of the Taylor rule according to the welfare loss obained by the functions loss_.

Taylor Rule ist in meinem Fall:

i= delta_pi*pi +delta_x*x + ut

und meine Lossfunktion ist:
lim L= 1/2 (Var pi + lambda Var xt)

die koeffizienten sind delta_pi and delta_x
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2024 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.