julia>* GI*
4x8x3 Array{Float64,3}:
[:, :, 1] =
 0.25    0.25    0.25    0.25    0.125   0.125   0.125   0.25
 0.25    0.125   0.0625  0.0625  0.125   0.125   0.0625  0.125
 0.0625  0.25    0.125   0.25    0.0625  0.0625  0.25    0.125
 0.125   0.0625  0.25    0.125   0.125   0.125   0.125   0.25

[:, :, 2] =
 0.25   0.25   0.25   0.25   0.125  0.125  0.125  0.25
 0.25   0.125  0.0    0.0    0.125  0.125  0.125  0.125
 0.125  0.25   0.125  0.25   0.125  0.0    0.25   0.125
 0.125  0.0    0.25   0.125  0.125  0.125  0.125  0.25

[:, :, 3] =
 0.5   0.5  0.5  0.5  0.0   0.0  0.0   0.5
 0.5   0.0  0.0  0.0  0.0   0.0  0.25  0.0
 0.25  0.5  0.0  0.5  0.25  0.0  0.5   0.0
 0.0   0.0  0.5  0.0  0.0   0.0  0.0   0.5

julia>* Tr*
3x3 Array{Float64,2}:
 0.998003     0.00199601  9.98002e-7
 0.000998003  0.998004    0.000998003
 9.98002e-7   0.00199601  0.998003

julia> *Pr*
1x3 Array{Float64,2}:
 0.25  0.5  0.25

*Julia code:*
 
* function forward(GI::Array,Tr::Array,Pr::Array)*
*    nsamp = size(GI,1)*
*    nmark = size(GI,2)*
*    F = GI*
*    F[:,1,:] = broadcast(*,Pr,GI[:,1,:])*
*    for i=2:nmark*
*      F[:,i,:] = GI[:,i,:].*(F[:,i-1,:]*Tr)*
*  S = F[:,i,1] + F[:,i,2] + F[:,i,3]  *
*  F[:,i,:] = broadcast(/,S',F[:,i,:])  *
* end*
*    return F[:,:,:]*
*  end*

*R code:*

*forward <- function(G.I,Tr,Pr)*
*{*
*    n.samp <- dim(G.I)[1]*
*    n.mark <- dim(G.I)[2]*
*    F <- G.I*
*    F[,1,] <- sweep(G.I[,1,],2,Pr,"*")*
*    for (i in 2:n.mark)*
*    {*
*        F[,i,] <- G.I[,i,]*(F[,i-1,]%*%Tr)*
*        S <- F[,i,1] + F[,i,2] + F[,i,3]*
*        F[,i,] <- sweep(F[,i,],1,S,"/")*
*    }*
*    return(F)*
*}*

when it run, the error:

julia>* F[:,1,:] = broadcast(*,Pr,GI[:,1,:])*
ERROR: DimensionMismatch("tried to assign 4x3x3 array to 4x1x3 destination")
 in throw_setindex_mismatch at operators.jl:233 (repeats 2 times)

 
when i=2, error:
julia>* F[:,2,:] = GI[:,2,:].*(F[:,2-1,:]*Tr)*
ERROR: `*` has no method matching *(::Array{Float64,3}, ::Array{Float64,2})


julia>* F[:,2,:] = GI[:,2,:].*(F[:,2-1,:].*Tr)*
ERROR: arrays could not be broadcast to a common size
 in broadcast_shape at broadcast.jl:40
 in .* at broadcast.jl:278

How can I change the R code to Julia code? Thank you!

Reply via email to