Changeset ea3d3da in tol for tol_pkg/MulVarFunAprox
- Timestamp:
- Nov 30, 2009, 10:58:14 AM (17 years ago)
- Branches:
- 1941-docker-image-to-test, devel, master
- Children:
- eddd23a
- Parents:
- e1355dd
- File:
-
- 1 edited
-
tol_pkg/MulVarFunAprox/test/test_0001/test.tol (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tol_pkg/MulVarFunAprox/test/test_0001/test.tol
re1355dd rea3d3da 14 14 15 15 //Random seed setting 16 Real PutRandomSeed( 234234);16 Real PutRandomSeed(0); 17 17 Real rndSeed = GetRandomSeed(0); 18 18 WriteLn("Current Random Seed = "<<rndSeed); … … 26 26 Real maxDeg = 4; 27 27 28 29 MulVarFunAprox::@BaseC2FunRn2R.Monomial base = 30 MulVarFunAprox::@BaseC2FunRn2R.Monomial::New(n,maxDeg); 28 FunRn2R::@BaseC2.Monomial base = 29 FunRn2R::@BaseC2.Monomial::New(n,maxDeg); 31 30 32 31 Real K = base::_.K; 33 Real J = K*1000; 34 35 VMatrix X = Group("ConcatColumns",For(1,n,VMatrix(Real i) 36 { 37 Real min = Rand(0,0); 38 Real len = Rand(5,10)*(i^(1/n)); 39 Rand(J,1,min,min+len) 40 })); 41 42 43 VMatrix fun.eval.intra.base(VMatrix X) 44 { 45 Set x = For(1,n,VMatrix(Real i) { SubCol(X,[[i]]) }); 46 (x[1]*0+1)*Rand(-10,10)+ 47 x[1]*Rand(-10,10)+ 48 x[2]*Rand(-10,10)+ 49 x[1]^2*Rand(-10,10)+ 50 x[2]^2*Rand(-10,10)+ 51 x[1]$*x[2]*Rand(-10,10) 32 Real J = K*20; 33 34 ////////////////////////////////////////////////////////////////////////////// 35 VMatrix generate.nodal.points(Real J, Real n) 36 ////////////////////////////////////////////////////////////////////////////// 37 { 38 Group("ConcatColumns",For(1,n,VMatrix(Real i) 39 { 40 Real min = Rand(0,0); 41 Real len = Rand(5,10)*(i^(1/n)); 42 Rand(J,1,min,min+len) 43 })) 52 44 }; 53 45 46 ////////////////////////////////////////////////////////////////////////////// 47 NameBlock base.random.fun = 48 ////////////////////////////////////////////////////////////////////////////// 49 [[ 50 Matrix coef = Rand(base::_.K, 1, -10, 10); 51 VMatrix eval(VMatrix X) 52 { 53 SetSum(For(1,base::_.K, VMatrix(Real k) 54 { 55 base::function.v(k,X)*MatDat(coef,k,1) 56 })) 57 } 58 ]]; 59 60 ////////////////////////////////////////////////////////////////////////////// 54 61 VMatrix fun.eval.extra.base(VMatrix X) 62 ////////////////////////////////////////////////////////////////////////////// 55 63 { 56 64 Set x = For(1,n,VMatrix(Real i) { SubCol(X,[[i]]) }); … … 58 66 }; 59 67 60 VMatrix Fx = fun.eval.extra.base(X); 61 62 Real lengthRatio = 0.5*(J/(K*n))^(1/n); 68 Code fun.eval = fun.eval.extra.base; 69 //Code fun.eval = base.random.fun::eval; 70 71 72 VMatrix X = generate.nodal.points(J,n); 73 VMatrix Fx = fun.eval(X); 74 75 Real lengthRatio = 0.7*(J/(K*n))^(1/n); 63 76 64 77 Set X.col.info = For(1,n,Set(Real i) … … 109 122 ( X << (Y*0)); 110 123 124 ////////////////////////////////////////////////////////////////////////////// 111 125 VMatrix closest.Y.index(VMatrix A) 126 ////////////////////////////////////////////////////////////////////////////// 112 127 { 113 128 Real m = VRows(A); … … 156 171 Real X.maxNeighbour = 1+2*n; 157 172 158 VMatrix X.closest.Y.index = closest.Y.index(X); 159 VMatrix X.closest.Y = SubRow(Y,VCol2Set(X.closest.Y.index)); 160 161 VMatrix X.j=DifEq(1/(1-B),Rand(J,1,1,1)); 162 163 VMatrix X.h=SubRow(Y.neighbourhood, VCol2Set(X.closest.Y.index)); 164 165 Set X.dif = For(1,X.maxNeighbour,VMatrix(Real i) 166 { 167 X - SubRow(Y,VCol2Set(SubCol(X.h,[[i]]))) 168 }); 169 170 Set X.tao = For(1,X.maxNeighbour,VMatrix(Real i) 171 { 172 VMatrix X.norm2 = RPow(X.dif[i],2)*Rand(n,1,1,1); 173 RPow(X.norm2,0.5)/radius 174 }); 175 176 Set X.tao2 = For(1,X.maxNeighbour,VMatrix(Real i) 177 { 178 RPow(X.tao[i],2) 179 }); 180 181 Set X.match = For(1,X.maxNeighbour,VMatrix(Real i) 182 { 183 LE(X.tao[i],Rand(J,1,1,1)) 184 }); 185 186 Set X.lambda = For(1,X.maxNeighbour,VMatrix(Real i) 187 { 188 RPow(X.match[i] $* (Rand(J,1,1,1)-X.tao2[i]),4) 189 }); 190 191 VMatrix X.lambda.sum = SetSum(X.lambda); 192 193 Set X.weight = For(1,X.maxNeighbour,VMatrix(Real i) 194 { 195 X.lambda[i] $/ X.lambda.sum 196 }); 197 198 Matrix QX.triplet = Group("ConcatRows", For(1,X.maxNeighbour,Matrix(Real i) 199 { 200 VMatrix w.i = X.weight[i]; 201 Set sel.rows = MatQuery::SelectMatch(NE(Drop(Abs(w.i),1.E-15),w.i*0)); 202 VMatrix wi = SubRow(w.i,sel.rows); 203 VMatrix X.hiK = SubRow((SubCol(X.h,[[i]])-1)*K,sel.rows); 204 VMatrix Xdif.i = SubRow(X.dif[i],sel.rows); 205 VMatrix X.j.i = SubRow(X.j,sel.rows); 206 Group("ConcatRows", For(1,K,Matrix(Real k) 207 { 208 VMatrix pk = base::function.v(k,Xdif.i); 209 VMatrix qk = wi$*pk; 210 VMat2Mat(X.j.i | (X.hiK+k) | qk) 211 })) 212 })); 213 214 VMatrix QX = Pack(Convert(Triplet(QX.triplet, J, N),"Cholmod.R.Sparse")); 173 ////////////////////////////////////////////////////////////////////////////// 174 VMatrix builds.obs.input(VMatrix X) 175 ////////////////////////////////////////////////////////////////////////////// 176 { 177 Real J = VRows(X); 178 179 VMatrix X.closest.Y.index = closest.Y.index(X); 180 VMatrix X.closest.Y = SubRow(Y,VCol2Set(X.closest.Y.index)); 181 182 VMatrix X.j=DifEq(1/(1-B),Rand(J,1,1,1)); 183 184 VMatrix X.h=SubRow(Y.neighbourhood, VCol2Set(X.closest.Y.index)); 185 186 Set X.dif = For(1,X.maxNeighbour,VMatrix(Real i) 187 { 188 X - SubRow(Y,VCol2Set(SubCol(X.h,[[i]]))) 189 }); 190 191 Set X.tao = For(1,X.maxNeighbour,VMatrix(Real i) 192 { 193 VMatrix X.norm2 = RPow(X.dif[i],2)*Rand(n,1,1,1); 194 RPow(X.norm2,0.5)/radius 195 }); 196 197 Set X.tao2 = For(1,X.maxNeighbour,VMatrix(Real i) 198 { 199 RPow(X.tao[i],2) 200 }); 201 202 Set X.match = For(1,X.maxNeighbour,VMatrix(Real i) 203 { 204 LE(X.tao[i],Rand(J,1,1,1)) 205 }); 206 207 Set X.lambda = For(1,X.maxNeighbour,VMatrix(Real i) 208 { 209 RPow(X.match[i] $* (Rand(J,1,1,1)-X.tao2[i]),4) 210 }); 211 212 VMatrix X.lambda.sum = SetSum(X.lambda); 213 214 Set X.weight = For(1,X.maxNeighbour,VMatrix(Real i) 215 { 216 X.lambda[i] $/ X.lambda.sum 217 }); 218 219 Matrix QX.triplet = Group("ConcatRows", For(1,X.maxNeighbour,Matrix(Real i) 220 { 221 VMatrix w.i = X.weight[i]; 222 Set sel.rows = MatQuery::SelectMatch(NE(Drop(Abs(w.i),1.E-15),w.i*0)); 223 VMatrix wi = SubRow(w.i,sel.rows); 224 VMatrix X.hiK = SubRow((SubCol(X.h,[[i]])-1)*K,sel.rows); 225 VMatrix Xdif.i = SubRow(X.dif[i],sel.rows); 226 VMatrix X.j.i = SubRow(X.j,sel.rows); 227 Group("ConcatRows", For(1,K,Matrix(Real k) 228 { 229 VMatrix pk = base::function.v(k,Xdif.i); 230 VMatrix qk = wi$*pk; 231 VMat2Mat(X.j.i | (X.hiK+k) | qk) 232 })) 233 })); 234 Pack(Convert(Triplet(QX.triplet, J, N),"Cholmod.R.Sparse")) 235 }; 236 237 VMatrix QX = builds.obs.input(X); 215 238 216 239 … … 334 357 Real E.ste = VMatStDs(E); 335 358 359 360 VMatrix X2 = generate.nodal.points(J,n); 361 VMatrix Fx2 = fun.eval(X2); 362 VMatrix QX2 = builds.obs.input(X2); 363 VMatrix F2.frc = QX2*alpha; 364 VMatrix E2 = Fx2 - F2.frc; 365 Real E2.avr = VMatAvr(E2); 366 Real E2.ste = VMatStDs(E2); 367 336 368 Set View([[ 337 Real n, K, J, H, 338 X.maxNeighbour, Z.maxNeighbour, 339 T, N, Mz,M, E.avr, E.ste, "\n"]],""); 369 Real n, K, J, H, 370 X.maxNeighbour, Z.maxNeighbour, 371 T, N, Mz,M, 372 E.avr, E.ste, 373 E2.avr, E2.ste, 374 "\n"]],""); 340 375 341 376 /* … … 367 402 /* */ 368 403 369 /*370 VMatrix Z.min = Group("ConcatColumns", For(1,n,VMatrix(Real i)371 {372 Real aux = range[i][1];373 Rand(2*H,1,aux,aux)374 }));375 376 VMatrix Z.max = Group("ConcatColumns", For(1,n,VMatrix(Real i)377 {378 Real aux = range[i][Card(range[i])];379 Rand(2*H,1,aux,aux)380 }));381 382 VMatrix Z.interior = EQ(383 And(GE(Z.all,Z.min), LE(Z.all,Z.max))*Rand(n,1,1,1),384 Rand(2*H,1,n,n));385 386 VMatrix Z = SubRow(Z.all,MatQuery::SelectMatch(Z.interior));387 VMatrix Z.Y.1 = SubRow(Z.Y.1.all,MatQuery::SelectMatch(Z.interior));388 VMatrix Z.Y.2 = SubRow(Z.Y.2.all,MatQuery::SelectMatch(Z.interior));389 VMatrix Z.h.1 = closest.Y.index(Z.Y.1);390 VMatrix Z.h.2 = closest.Y.index(Z.Y.2);391 */392 393 /*394 Real deg = 3;395 396 Real dim = 2;397 Real maxDeg = 3;398 VMatrix candidates = Mat2VMat(SetMat(Range(0,maxDeg,1)^dim));399 VMatrix match = LE(candidates*Rand(dim,1,1,1),Rand(VRows(candidates),1,maxDeg,maxDeg));400 VMatrix degrees = SubRow(candidates, MatQuery::SelectMatch(match));401 Real K = VRows(degrees);402 Class @PolynBasic403 {404 Real k;405 VMatrix fun (VMatrix x)406 {407 SetProd(For(1,dim,VMatrix(Real i)408 {409 410 })411 };412 413 };414 Set base = For(1,K,NameBlock(Real k)415 {416 });417 /* */418
Note: See TracChangeset
for help on using the changeset viewer.
