Overview
Comment: | New identification DIY reps |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | origin/master | trunk |
Files: | files | file ages | folders |
SHA3-256: |
bca1a038ac1a16121e07948623d16ae3 |
User & Date: | gawthrop@users.sourceforge.net on 2002-08-20 15:39:47 |
Other Links: | branch diff | manifest | tags |
Context
2002-08-20
| ||
15:43:45 | Works with ident DIY rep check-in: b135670b5f user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
15:39:47 | New identification DIY reps check-in: bca1a038ac user: gawthrop@users.sourceforge.net tags: origin/master, trunk | |
2002-08-19
| ||
14:37:05 | Fixed eta, beta, theta, Theta and zeta. check-in: 4fe11382f5 user: geraint@users.sourceforge.net tags: origin/master, trunk | |
Changes
Modified mttroot/mtt/lib/rep/ident_rep.make from [042982e678] to [0ce701c93b].
1 2 3 4 5 6 7 8 9 | # -*-makefile-*- # Makefile for representation ident # File ident_rep.make #Copyright (C) 2000,2001,2002 by Peter J. Gawthrop ## Model targets model_reps = ${SYS}_sympar.m ${SYS}_simpar.m ${SYS}_state.m model_reps += ${SYS}_numpar.m ${SYS}_input.m ${SYS}_ode2odes.m | | > > > > > > > > | | > > > > > | | > > | > | | > > > > > > > > > > > > > > > > | < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | # -*-makefile-*- # Makefile for representation ident # File ident_rep.make #Copyright (C) 2000,2001,2002 by Peter J. Gawthrop ## Model targets model_reps = ${SYS}_sympar.m ${SYS}_simpar.m ${SYS}_state.m model_reps += ${SYS}_numpar.m ${SYS}_input.m ${SYS}_ode2odes.m model_reps += ${SYS}_def.m ## Prepend s to get the sensitivity targets sensitivity_reps = ${model_reps:%=s%} ## Model prerequisites model_pre = ${SYS}_abg.fig ${SYS}_lbl.txt model_pre += ${SYS}_rdae.r ${SYS}_numpar.txt ## Prepend s to get the sensitivity targets sensitivity_pre = ${model_pre:%=s%} ## Simulation targets sims = ${SYS}_sim.m s${SYS}_ssim.m ## m-files needed for ident ident_m = ${SYS}_ident.m ${SYS}_ident_numpar.m ## Targets for the ident simulation ident_reps = ${ident_m} ${sims} ${model_reps} ${sensitivity_reps} ## ps output files etc psfiles = ${SYS}_ident.ps ${SYS}_ident.comparison.ps figfiles = ${psfiles:%.ps=%.fig} gdatfiles = ${psfiles:%.ps=%.gdat} datfiles = ${psfiles:%.ps=%.dat2} ## LaTeX files etc latexfiles = ${SYS}_ident_par.tex all: ${SYS}_ident.${LANG} echo: echo "sims: ${sims}" echo "model_reps: ${model_reps}" echo "sensitivity_reps: ${sensitivity_reps}" echo "ident_reps: ${ident_reps}" ${SYS}_ident.view: ${psfiles} ident_rep.sh ${SYS} view ${psfiles}: ${figfiles} ident_rep.sh ${SYS} ps ${figfiles}: ${gdatfiles} ident_rep.sh ${SYS} fig ${gdatfiles}: ${datfiles} ident_rep.sh ${SYS} gdat ${datfiles} ${latexfiles}: ${ident_reps} ident_rep.sh ${SYS} dat2 ${SYS}_ident.m: ident_rep.sh ${SYS} m ${SYS}_ident_numpar.m: ident_rep.sh ${SYS} numpar.m ## System model reps ## Generic txt files ${SYS}_%.txt: mtt ${OPTS} -q -stdin ${SYS} $* txt ## Specific m files ${SYS}_ode2odes.m: ${model_pre} mtt -q -stdin ${OPTS} ${SYS} ode2odes m ${SYS}_sim.m: ${SYS}_ode2odes.m mtt ${OPTS} -q -stdin ${SYS} sim m ## Numpar files ${SYS}_numpar.m: mtt ${SYS} numpar m ## Sympar files ${SYS}_sympar.m: mtt ${SYS} sympar m ## Generic txt to m ${SYS}_%.m: ${SYS}_%.txt mtt ${OPTS} -q -stdin ${SYS} $* m ## r files ${SYS}_def.r: ${SYS}_abg.fig mtt ${OPTS} -q -stdin ${SYS} def r ${SYS}_rdae.r: mtt ${OPTS} -q -stdin ${SYS} rdae r ## Sensitivity model reps ## Generic txt files s${SYS}_%.txt: mtt ${OPTS} -q -stdin -s s${SYS} $* txt ## Specific m files ## Numpar files s${SYS}_numpar.m: mtt -s s${SYS} numpar m ## Sympar files s${SYS}_sympar.m: mtt -s s${SYS} sympar m s${SYS}_ode2odes.m: ${sensitivity_pre} mtt -q -stdin ${OPTS} -s s${SYS} ode2odes m s${SYS}_ssim.m: mtt -q -stdin ${OPTS} -s s${SYS} ssim m s${SYS}_def.m: mtt -q -stdin ${OPTS} -s s${SYS} def m ## Generic txt to m s${SYS}_%.m: s${SYS}_%.txt mtt ${OPTS} -q -stdin s${SYS} $* m ## r files s${SYS}_rdae.r: mtt ${OPTS} -q -stdin -s s${SYS} rdae r |
Modified mttroot/mtt/lib/rep/ident_rep.sh from [509586cb1e] to [8c10f339dc].
1 2 3 4 5 6 7 8 9 10 11 12 | #! /bin/sh ## ident_rep.sh ## DIY representation "ident" for mtt # Copyright (C) 2002 by Peter J. Gawthrop sys=$1 rep=ident lang=$2 mtt_parameters=$3 rep_parameters=$4 | > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #! /bin/sh ## ident_rep.sh ## DIY representation "ident" for mtt # Copyright (C) 2002 by Peter J. Gawthrop ps=ps sys=$1 rep=ident lang=$2 mtt_parameters=$3 rep_parameters=$4 |
︙ | ︙ | |||
38 39 40 41 42 43 44 45 46 47 | echo ${mtt_options} > ${option_file} fi } ## Make the _ident.m file make_ident() { filename=${sys}_${rep}.m echo Creating ${filename} cat > ${filename} <<EOF | > | | > > | > > > | | | | | | | < | | < > | | < < < < < | < > | < < < < | < | | | < | < < < | < | < < < | < < | | < < | | < < | < < | | < < > | < | | < < | > | | | | < < < | < < < < | | < < | < | < < < < < < < < < | < < < < < < < < < < < < < < < < | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | | | > > > > | | | > > > | > > > > | > > > > > > > > | > > > > | > > > > > > > > | | > | > | > | | | < < | < | | < < < | | | | | | | | | > > | > > > > > | < > > > | < > > > > > | 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | echo ${mtt_options} > ${option_file} fi } ## Make the _ident.m file make_ident() { filename=${sys}_${rep}.m date=`date` echo Creating ${filename} cat > ${filename} <<EOF function [epar,Y] = ${sys}_ident (y,u,t,par_names,Q,extras) ## usage: [epar,Y] = ${sys}_ident (y,u,t,par_names,Q,extras) ## ## last last time in run ## ppp_names Column vector of names of ppp params ## par_names Column vector of names of estimated params ## extras Structure containing additional info ## ## Created by MTT on ${date} ## Sensitivity system name system_name = "s${sys}" ##Sanity check if nargin<3 printf("Usage: [y,u,t] = ${sys}_ident(y,u,t,par_names,Q,extras);"); return endif if nargin<6 ## Set up optional parameters extras.criterion = 1e-3; extras.emulate_timing = 0; extras.max_iterations = 10; extras.simulate = 2; extras.v = 1e-2; extras.verbose = 1; extras.visual = 1; endif ## System info [n_x,n_y,n_u,n_z,n_yz] = ${sys}_def; sympar = ${sys}_sympar; simpar = ${sys}_simpar; sympars = s${sys}_sympar; simpars = s${sys}_simpar; ## Parameter indices i_par = ppp_indices (par_names,sympar,sympars); ## Initial model state x_0 = zeros(2*n_x,1); ## Initial model parameters par_0 = s${sys}_numpar; ## Reset simulation parameters [n_data,m_data] = size(y); dt = t(2)-t(1); simpars.last = (n_data-1)*dt; simpars.dt = dt; ## Identification [epar,Par,Error,Y,iterations,x] = ppp_optimise(system_name,x_0,par_0,simpars,u,y,i_par,Q,extras); ## Do some plots figure(1); title("Comparison of data"); xlabel("t"); ylabel("y"); [N,M] = size(Y); plot(t,Y(:,M),"1;Estimated;", t,y,"3;Actual;"); figfig("${sys}_ident_comparison"); ## Create a table of the parameters [n_par,m_par] = size(i_par); fid = fopen("${sys}_ident_par.tex", "w"); fprintf(fid,"\\\\begin{table}[htbp]\\n"); fprintf(fid," \\\\centering\\n"); fprintf(fid," \\\\begin{tabular}{|l|l|}\\n"); fprintf(fid," \\\\hline\\n"); fprintf(fid," Name & Value \\\\\\\\ \\n"); fprintf(fid," \\\\hline\\n"); for i = 1:n_par fprintf(fid,"$%s$ & %4.2f \\\\\\\\ \\n", par_names(i,:), epar(i_par(i,1))); endfor fprintf(fid," \\\\hline\\n"); fprintf(fid,"\\\\end{tabular}\\n"); fprintf(fid,"\\\\caption{Estimated Parameters}\\n"); fprintf(fid,"\\\\end{table}\\n"); fclose(fid); endfunction EOF } make_ident_numpar() { echo Creating ${ident_numpar_file} cat > ${sys}_ident_numpar.m <<EOF function [y,u,t,par_names,Q,extras] = ${sys}_ident_numpar; ## usage: [y,u,t,par_names,Q,extras] = ${sys}_ident_numpar; ## Edit for your own requirements ## Created by MTT on ${date} ## This section sets up the data source ## simulate = 0 Real data (you supply ${sys}_ident_data.dat) ## simulate = 1 Real data input, simulated output ## simulate = 2 Unit step input, simulated output simulate = 2; ## System info [n_x,n_y,n_u,n_z,n_yz] = ${sys}_def; simpars = s${sys}_simpar; ## Access or create data if (simulate<2) # Get the real data if (exist("${sys}_ident_data.dat")==2) printf("Loading ${sys}_ident_data.dat\n"); load ${sys}_ident_data.dat else printf("Please create a loadable file ${sys}_ident_data.dat containing y,u and t\n"); return endif else switch simulate case 2 # Step simulation t = [0:simpars.dt:simpars.last]'; u = ones(size(t)); otherwise error(sprintf("simulate = %i not implemented", simulate)); endswitch endif if (simulate>0) par = ${sys}_numpar(); x_0 = ${sys}_state(par); dt = t(2)-t(1); simpars.dt = dt; simpars.last = t(length(t)); y = ${sys}_sim(zeros(n_x,1), par, simpars, u); endif ## Default parameter names - Put in your own here sympar = ${sys}_sympar; # Symbolic params as structure par_names = struct_elements (sympar); # Symbolic params as strings [n,m] = size(par_names); # Size the string list ## Sort by index for [i,name] = sympar par_names(i,:) = sprintf("%s%s",name, blanks(m-length(name))); endfor ## Output weighting vector Q = ones(n_y,1); ## Extra parameters extras.criterion = 1e-5; extras.emulate_timing = 0; extras.max_iterations = 10; extras.simulate = simulate; extras.v = 1e-2; extras.verbose = 1; extras.visual = 1; endfunction EOF } make_dat2() { ## Inform user echo Creating ${dat2_file} ## Use octave to generate the data octave -q <<EOF [y,u,t,par_names,Q,extras] = ${sys}_ident_numpar; [epar,Y] = ${sys}_ident (y,u,t,par_names,Q,extras); [N,M] = size(Y); y_est = Y(:,M); data = [t,y_est,u]; save -ascii ${dat2_file} data EOF ## Tidy up the latex stuff - convert foo_123 to foo_{123} cat ${sys}_ident_par.tex > mtt_junk sed -e "s/_\([a-z0-9,]*\)/_{\1}/g" < mtt_junk >${sys}_ident_par.tex rm mtt_junk } case ${lang} in numpar.m) ## Make the numpar stuff make_ident_numpar; ;; m) ## Make the code make_ident; ;; dat2) ## The dat2 language (output data) & fig file make_dat2; ;; gdat) cp ${dat2_file} ${dat2s_file} dat22dat ${sys} ${rep} dat2gdat ${sys} ${rep} ;; fig) gdat2fig ${sys}_${rep} ;; ps) figs=`ls ${sys}_ident*.fig | sed -e 's/\.fig//'` for fig in ${figs}; do fig2dev -Leps ${fig}.fig > ${fig}.ps done texs=`ls ${sys}_ident*.tex | sed -e 's/\.tex//'` for tex in ${texs}; do makedoc "" "${sys}" "ident_par" "tex" "" "" "$ps" doc2$ps ${sys}_ident_par "$documenttype" done ;; view) pss=`ls ${sys}_ident*.ps` echo Viewing ${pss} for ps in ${pss}; do gv ${ps}& done |
︙ | ︙ |