Patrizio Frederic
2008-Jul-29 16:00 UTC
[R] tensor product of equi-spaced B-splines in the unit square
Dear all, I need to compute tensor product of B-spline defined over equi-spaced break-points. I wrote my own program (it works in a 2-dimensional setting) library(splines) # set the break-points Knots = seq(-1,1,length=10) # number of splines M = (length(Knots)-4)^2 # short cut to splineDesign function bspline = function(x) splineDesign(Knots,x,outer.ok = T) # bivariate tensor product of bspline btens = function(x) t(bspline(x[1]))%*%bspline(x[2]) # numebr of points to plot ng = 51 # create vectors for plotting xgr = seq(-1,1,length=ng) xgr2 = expand.grid(xgr,xgr) # generate random coef. of linear combination bet = rnorm(M) # create matrix for contour-type plot Bx = apply(xgr2,1,btens) Bmat = matrix(t(Bx)%*%bet,ng) # plot the result contour(xgr,xgr,Bmat) persp(xgr,xgr,Bmat,theta=15) any of you have a better idea (ie more efficient)? Thanks in advance, Patrizio Frederic +------------------------------------------------- | Patrizio Frederic | Research associate in Statistics, | Department of Economics, | University of Modena and Reggio Emilia, | Via Berengario 51, | 41100 Modena, Italy | | tel: +39 059 205 6727 | fax: +39 059 205 6947 | mail: patrizio.frederic at unimore.it +-------------------------------------------------
Patrizio Frederic
2008-Jul-31 15:18 UTC
[R] tensor product of equi-spaced B-splines in the unit square
dear all,
I apologize for a second post on the same subject. I still have the
problem. I'm going to describe the problem in a different setting:
I have 3 matrix A,B,W such that
dim(A) = c(n,M)
dim(B) = c(n,M)
dim(W) = c(M,M)
what I'm searching for is an efficient computation of vector R,
length(R)=n, where
R[i] = \sum_{j=1}^M \sum_{k=1}^M A[i,j]*B[i,k]*W[j,k] # I apologize
for a bit of LaTex code.
I understand this is about tensor products but I can't figure how to
use neither package tensor nor tensorA (I was not trained in tensor
algebra and right now it's too hot in Italy to me for studing a new
topic).
Any suggestion is welcome.
Regards,
Patrizio Frederic
+-------------------------------------------------
| Patrizio Frederic
| Research associate in Statistics,
| Department of Economics,
| University of Modena and Reggio Emilia,
| Via Berengario 51,
| 41100 Modena, Italy
|
| tel: +39 059 205 6727
| fax: +39 059 205 6947
| mail: patrizio.frederic at unimore.it
+-------------------------------------------------
2008/7/29 Patrizio Frederic <frederic.patrizio at
gmail.com>:> Dear all,
> I need to compute tensor product of B-spline defined over equi-spaced
> break-points.
> I wrote my own program (it works in a 2-dimensional setting)
>
> library(splines)
> # set the break-points
> Knots = seq(-1,1,length=10)
> # number of splines
> M = (length(Knots)-4)^2
> # short cut to splineDesign function
> bspline = function(x) splineDesign(Knots,x,outer.ok = T)
> # bivariate tensor product of bspline
> btens = function(x) t(bspline(x[1]))%*%bspline(x[2])
> # numebr of points to plot
> ng = 51
> # create vectors for plotting
> xgr = seq(-1,1,length=ng)
> xgr2 = expand.grid(xgr,xgr)
> # generate random coef. of linear combination
> bet = rnorm(M)
> # create matrix for contour-type plot
> Bx = apply(xgr2,1,btens)
> Bmat = matrix(t(Bx)%*%bet,ng)
> # plot the result
> contour(xgr,xgr,Bmat)
> persp(xgr,xgr,Bmat,theta=15)
>
> any of you have a better idea (ie more efficient)?
> Thanks in advance,
>
> Patrizio Frederic
>
> +-------------------------------------------------
> | Patrizio Frederic
> | Research associate in Statistics,
> | Department of Economics,
> | University of Modena and Reggio Emilia,
> | Via Berengario 51,
> | 41100 Modena, Italy
> |
> | tel: +39 059 205 6727
> | fax: +39 059 205 6947
> | mail: patrizio.frederic at unimore.it
> +-------------------------------------------------
>