|
| 1 | +/* Conection painting. */ |
| 2 | +/* |
| 3 | + Copyright (C) 2004 University of Texas at Austin |
| 4 | + |
| 5 | + This program is free software; you can redistribute it and/or modify |
| 6 | + it under the terms of the GNU General Public License as published by |
| 7 | + the Free Software Foundation; either version 2 of the License, or |
| 8 | + (at your option) any later version. |
| 9 | + |
| 10 | + This program is distributed in the hope that it will be useful, |
| 11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + GNU General Public License for more details. |
| 14 | + |
| 15 | + You should have received a copy of the GNU General Public License |
| 16 | + along with this program; if not, write to the Free Software |
| 17 | + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | +*/ |
| 19 | +#include <math.h> |
| 20 | + |
| 21 | +#include <rsf.h> |
| 22 | +#include "predict.h" |
| 23 | + |
| 24 | +int main (int argc, char* argv[]) |
| 25 | +{ |
| 26 | + int order, n1, n2, n12, i1, i2, i0, nw; |
| 27 | + char *label, *unit; |
| 28 | + float **u, ***conv, *trace; |
| 29 | + float o1, d1, o2, d2, eps, *time; |
| 30 | + sf_file cnv, out, seed; |
| 31 | + |
| 32 | + sf_init(argc, argv); |
| 33 | + cnv = sf_input("in"); |
| 34 | + out = sf_output("out"); |
| 35 | + |
| 36 | + if (SF_FLOAT != sf_gettype(cnv)) sf_error("Need float input"); |
| 37 | + if (!sf_histint(cnv,"n1",&n1)) sf_error("Need n1= in input"); |
| 38 | + |
| 39 | + if (!sf_histint(cnv,"n3",&n2)) sf_error("Need n3= in input"); |
| 40 | + if (!sf_histfloat(cnv,"o3",&o2)) o2=0.; |
| 41 | + if (!sf_histfloat(cnv,"d3",&d2)) d2=1.; |
| 42 | + |
| 43 | + n12 = n1*n2; |
| 44 | + |
| 45 | + if (!sf_histint(cnv,"n2",&nw)) sf_error("Need n2= in input"); |
| 46 | + |
| 47 | + sf_putint(out,"n2",n2); |
| 48 | + sf_putfloat(out,"d2",d2); |
| 49 | + sf_putfloat(out,"o2",o2); |
| 50 | + if (NULL != (label= sf_histstring(cnv,"label3"))) sf_putstring(out,"label2",label); |
| 51 | + if (NULL != (unit= sf_histstring(cnv,"unit3"))) sf_putstring(out,"unit2",unit); |
| 52 | + |
| 53 | + sf_putint(out,"n3",1); |
| 54 | + |
| 55 | + order = nw/2; |
| 56 | + |
| 57 | + if (NULL != sf_getstring("seed")) { |
| 58 | + seed = sf_input("seed"); |
| 59 | + time = NULL; |
| 60 | + } else { |
| 61 | + seed = NULL; |
| 62 | + time = sf_floatalloc(n1); |
| 63 | + if (!sf_histfloat(cnv,"o1",&o1)) o1=0.; |
| 64 | + if (!sf_histfloat(cnv,"d1",&d1)) d1=1.; |
| 65 | + for (i1=0; i1 < n1; i1++) { |
| 66 | + time[i1] = o1+i1*d1; |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + if (!sf_getfloat("eps",&eps)) eps=0.01; |
| 71 | + /* regularization */ |
| 72 | + |
| 73 | + if (!sf_getint("i0",&i0)) i0=0; |
| 74 | + /* reference trace */ |
| 75 | + |
| 76 | + predict_init (n1, n2, eps*eps, order, 1, false); |
| 77 | + |
| 78 | + u = sf_floatalloc2(n1,n2); |
| 79 | + conv = sf_floatalloc3(n1,nw,n2); |
| 80 | + trace = sf_floatalloc(n1); |
| 81 | + |
| 82 | + sf_floatread(conv[0][0],n12*nw,cnv); |
| 83 | + |
| 84 | + if (NULL != seed) { |
| 85 | + sf_floatread(trace,n1,seed); |
| 86 | + } else { |
| 87 | + for (i1=0; i1 < n1; i1++) { |
| 88 | + trace[i1] = time[i1]; |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + for (i1=0; i1 < n1; i1++) { |
| 93 | + u[i0][i1] = trace[i1]; |
| 94 | + } |
| 95 | + for (i2=i0-1; i2 >= 0; i2--) { |
| 96 | + predict_step(false,false,trace,conv[i2]); |
| 97 | + for (i1=0; i1 < n1; i1++) { |
| 98 | + u[i2][i1] = trace[i1]; |
| 99 | + } |
| 100 | + } |
| 101 | + for (i1=0; i1 < n1; i1++) { |
| 102 | + trace[i1] = u[i0][i1]; |
| 103 | + } |
| 104 | + for (i2=i0+1; i2 < n2; i2++) { |
| 105 | + predict_step(false,true,trace,conv[i2-1]); |
| 106 | + for (i1=0; i1 < n1; i1++) { |
| 107 | + u[i2][i1] = trace[i1]; |
| 108 | + } |
| 109 | + } |
| 110 | + sf_floatwrite(u[0],n1*n2,out); |
| 111 | + |
| 112 | + exit(0); |
| 113 | +} |
| 114 | + |
| 115 | + |
| 116 | + |
0 commit comments