-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathGPTransfer.m
More file actions
68 lines (45 loc) · 3.51 KB
/
Copy pathGPTransfer.m
File metadata and controls
68 lines (45 loc) · 3.51 KB
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
(* ::Package:: *)
(* ::Input::Initialization:: *)
TestFunc[x_]=10x;
TestFunc2[x_]=3x;
(* ::Input::Initialization:: *)
KSE[x1_,x2_,l_]:=Exp[-((x1-x2)^2/(2l^2))];
KSEMat[x_,l_]:=Module[{nGps=Dimensions[x][[1]],nSmpls=Dimensions[x][[2]]},
Table[KSE[x[[gp,smpl1]],x[[gp,smpl2]],l[[gp]]],{gp,1,nGps},{smpl1,1,nSmpls},{smpl2,1,nSmpls}]]
KSEMat[x_,l_]:=Module[{nGps=Dimensions[x][[1]],nSmpls=Dimensions[x][[2]]},
Table[KSE[x[[gp,smpl1]],x[[gp,smpl2]],l[[gp]]],{gp,1,nGps},{smpl1,1,nSmpls},{smpl2,1,nSmpls}]]
(* ::Input::Initialization:: *)
dKSEdX1:=Derivative[1,0,0][KSE];
dKSEdX2:=Derivative[0,1,0][KSE];
dKSEdL:=Derivative[0,0,1][KSE];
dKSEMatdX[x_,l_,dLdKSE_]:=Module[{nGps=Dimensions[x][[1]],nSmpls=Dimensions[x][[2]],nOut=Dimensions[dLdKSE][[1]]},
Table[Sum[dLdKSE[[out,h,c,b]] dKSEdX1[x[[h,c]],x[[h,b]],l[[h]]],{b,1,nSmpls}]+
Sum[dLdKSE[[out,h,a,c]] dKSEdX2[x[[h,a]],x[[h,c]],l[[h]]],{a,1,nSmpls}],
{out,1,nOut},{h,1,nGps},{c,1,nSmpls}]];
dKSEMatdL[x_,l_,dLdKSE_]:=Module[{nGps=Dimensions[x][[1]],nSmpls=Dimensions[x][[2]],nOut=Dimensions[dLdKSE][[1]]},
Table[Sum[dLdKSE[[out,j,a,b]] dKSEdL[x[[j,a]],x[[j,b]],l[[j]]],{a,1,nSmpls},{b,1,nSmpls}],{out,1,nOut},{j,1,nGps}]];
(* ::Input:: *)
(**)
(* ::Input:: *)
(*dKSEdX1[1.,2.,3.]*)
(* ::Input:: *)
(*trnSmpls={{1.0,2.0,3.3},{5.0,6.0,6.5}};*)
(*ls={2.0,4.0};*)
(*KSEMat[trnSmpls,ls][[2]]//MatrixForm*)
(* ::Input:: *)
(*dlDKSEval={*)
(*{*)
(*{{1.,2.,3.},{4.,5.,6.}, {7.,8.,9}},*)
(*{{1.,2.,3.},{4.,5.,6.}, {7.,8.,9}}*)
(*}};*)
(*Dimensions[dlDKSEval]*)
(* ::Input:: *)
(*dKSEMatdX[trnSmpls,ls,dlDKSEval]*)
(* ::Input:: *)
(*D[KSE[x1,x2,l],x1]*)
(* ::Input:: *)
(*dKSEdX1[1.0,2.0,3.0]*)
(* ::Input:: *)
(*KSE*)
(* ::Input:: *)
(*Derivative[1,0,0][KSE][1,2,3]*)