Index: mttroot/mtt/lib/control/PPP/ppp_RT_sim_compute.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_RT_sim_compute.m +++ mttroot/mtt/lib/control/PPP/ppp_RT_sim_compute.m @@ -17,10 +17,10 @@ u_star = ppp_ustar(A_u_sim,1,t,0,0,n_u-n_U); ## Simulate par(i_ppp_sim(:,3)) = U; # Update the simulation ppp weights [y_sim,x] = eval(sprintf("%s_sim(x_0_sim, par, simpar_sim, u_star);", \ - system_name_sim)); - x_0_sim = x(n_t,:)'; # Extract state for next time + system_name_sim)); + x_0_sim = x(n_t,:)'; # Extract state for next time u_sim = (u_star*U); endfunction Index: mttroot/mtt/lib/control/PPP/ppp_nlin_run.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_nlin_run.m +++ mttroot/mtt/lib/control/PPP/ppp_nlin_run.m @@ -37,14 +37,15 @@ extras.emulate_timing = 0; extras.max_iterations = 10; extras.simulate = 1; extras.v = 1e-5; extras.verbose = 0; + extras.visual = 0; endif ##Estimate if we have some adjustable parameters - estimating_parameters = (length(i_par)>0) + estimating_parameters = (length(i_par)>0); ## Names s_system_name = sprintf("s%s", system_name); ## System details -- defines simulation within ol interval @@ -141,11 +142,11 @@ u_star_t = ppp_ustar(A_u,1,t_ol',0,0,n_u-n_U); ## Tune parameters/states if (estimating_parameters==1) ## Save up the estimated parameters - par_est = pars(i_par(:,1)) + par_est = pars(i_par(:,1)); p = [p; par_est']; ## Set up according to interval length if (T_ol>T_ol_0) ## Truncate data simpar_est.last = T_ol_0; @@ -160,11 +161,17 @@ ## Optimise tick = time; [pars,Par,Error,Y,its] = \ ppp_optimise(s_system_name,x_0_models,pars,simpar_est,u_star_t,y_est,i_par,extras); -II = [1:length(y_est)]; plot(II,y_est,"*", II,Y) + + if extras.visual + figure(2); + title("Parameter optimisation"); + II = [1:length(y_est)]; plot(II,y_est,"*", II,Y); + endif + est_time = time-tick; t_est = [t_est;est_time]; its_est = [its_est; its-1]; endif @@ -178,10 +185,11 @@ simpar_model.last = T_ol; [y_model,x_model] = eval(sprintf("%s_sim(x_0_model, par, simpar_model, \ u_star_t);",system_name)); x_0 = x_model(n_ol+1,:)'; # Initial state of next interval +## x_0 = x_model(n_ol-1,:)'; # Initial state of next interval x_0_model = x_0; x_0_models(1:2:(2*n_x)-1) = x_0_model; ## Compute U by optimisation tick = time; @@ -196,11 +204,16 @@ ## Optimize for next interval U_old = U; # Save previous value U = expm(A_u*T_ol)*U; # Initialise from continuation trajectory pars(i_ppp(:,1)) = U; # Put initial value of U into the parameter vector [U, U_all, Error, Y, its] = ppp_nlin(system_name,x_nexts,pars,simpars,u_star_tau,w_s,i_ppp,extras); - + if extras.visual + figure(3); + title("PPP optimisation"); + II = [1:length(w_s)]; plot(II,w_s,"*", II,Y); + figure(1); + endif ppp_time = time-tick; t_ppp = [t_ppp;ppp_time]; its_ppp = [its_ppp; its-1]; Index: mttroot/mtt/lib/control/PPP/ppp_optimise.m ================================================================== --- mttroot/mtt/lib/control/PPP/ppp_optimise.m +++ mttroot/mtt/lib/control/PPP/ppp_optimise.m @@ -26,10 +26,13 @@ ############################################################### ## Version control history ############################################################### ## $Id$ ## $Log$ + ## Revision 1.8 2002/04/23 17:50:39 gawthrop + ## error --> err to avoid name clash with built in function + ## ## Revision 1.7 2001/08/10 16:19:06 gawthrop ## Tidied up the optimisation stuff ## ## Revision 1.6 2001/07/03 22:59:10 gawthrop ## Fixed problems with argument passing for CRs @@ -52,11 +55,10 @@ ## ############################################################### ## Copyright (C) 1999,2000 by Peter J. Gawthrop - sim_command = sprintf("%s_ssim(x_0,par,simpar,u,i_s)", system_name); ## Extract indices i_t = free(:,1); # Parameters i_s = free(:,2)'; # Sensitivities @@ -116,18 +118,13 @@ mess = sprintf("n_y (%i) in data not same as n_y (%i) in model", n_y,N_y); error(mess); endif ## Use the last part of the simulation to compare with data - y = y(1+N_data-n_data:N_data,:); - y_par = y_par(1+N_data-n_data:N_data,:); - - if extras.verbose # Diagnostics -## printf("y and y_0\n"); -## [y,y_0] - endif - + y = y(N_data-n_data:N_data-1,:); + y_par = y_par(N_data-n_data:N_data-1,:); + ##Evaluate error, cost derivative J and cost second derivative JJ err = 0; J = zeros(n_th,1); JJ = zeros(n_th,n_th);