Ich bin erste Ausgabe der "falsche Anzahl von Indizes in der matrix"?

Bin ich immer problem der "falsche Anzahl von Indizes in der matrix" für lange, Bitte helfen Sie mir. Ich bin auf der Suche nach dem Fehler aber nicht zu finden, meine Datenmenge ist riesig, aber ich bin mit kleinere anfängliche Daten für das Programm ausführen. Ich habe mein bestes versucht, aber alles vergebens. Die Fehlermeldung kommt in den letzten Zeilen von code. Ich bin neu zu codieren also bitte entschuldigt meine Fehler in der Einrückung.

########### inputs
#Y <- as.matrix(read.table("data2.dat"));
#X <- as.matrix(read.table("data1.dat"));
###########
# smaller X and Y for initial code run.
X <- matrix(c(71,22,53,14,75,68,74,93,72),9,1)
Y <- matrix(c(7,1,4,1,7,6,6,8,5),9,1)



########### Constant
Xlen <- length(X[,1])  #### rows of X
Yhat <- as.matrix(mat.or.vec(Xlen,1))
error <- as.matrix(mat.or.vec(Xlen,1))
Rmax <- 30
Z <- as.matrix(cbind(X,Y)) 
Zlen <- length(Z[1,]) #### columns of Z
P <- as.matrix(mat.or.vec(1,Rmax))
U <- as.matrix(mat.or.vec(1,Rmax)) # mu calculation
lambda <- as.matrix(mat.or.vec(1,Rmax)) # lambda calculation
C <- as.matrix(mat.or.vec(Zlen,Rmax))
R <- 0
sigma <- 0
beta <- as.matrix(mat.or.vec(1,Zlen))
Zp <- mat.or.vec(1,Zlen)
V1 <- 0
V2 <- 0
V3 <- 0
Pz <- 0
Dmin <-0
Dind <-0
Pmax <-0
Pind <-0
r <- 0.4
alpha <- 4/(r^2)
P_mat <- 10^4 * diag(2)
gamma <- as.matrix(mat.or.vec(2,Rmax))
w <- as.matrix(mat.or.vec(2,Rmax))
Xe <- as.matrix(cbind(1,X))
##### 


for (i in 1:Xlen)
{   
if (i==1) 
{R <- R+1 ; C[,R] <- Z[i,] ; P[R] <- 1; Yhat <- Y[i,]}
else 

{V1 <- sum(Z[i,]^2)
sigma <- sigma + sum(Z[i-1,]^2)
beta <- beta + Z[i-1,]
V2 <- sum(Z[i,]*t(beta))
Pz <- (i-1)/((i-1)*(V1+1)+(sigma-(2*V2)))
for (j in 1:R)
{V3 <- sum((Z[i,]-Z[i-1,])^2);P[j] <- ((i-1)*P[j])/((i-2)+(P[j])+(P[j]*V3))}
dist <- as.matrix(mat.or.vec(1,R))

for (k in 1:R)
{dist[k] <- abs(sqrt(sum((Z[i,]-C[,k])^2)))}


Dmin <- min(dist)
Dind <- which.min(dist)


Pmax <- max(P)
Pind <- which.max(P)


if (r > Dmin/(1-(Pz/Pmax)) && Pz > Pmax)
{C[,Dind] <- Z[i,]; P[Dind] <- Pz}

if (r < (Dmin/(1-(Pz/Pmax))) && Pz > Pmax && R< Rmax)
{R <- R+1; C[,R] <- Z[i,]; P[R] <- Pz}

for(n in 1:R)
{U[,n] <- exp(-alpha*(X[i]-C[1,n])^2)}

for(n in 1:R)
{lambda[,n] <- U[,n]/sum(U)}


A1 <- as.matrix(P_mat%*%Xe[i,]%*%lambda)
B1 <- as.matrix(t(lambda)%*%Xe[i,])
C1 <- as.matrix(diag(Rmax))
D1 <- as.matrix(P_mat)
E1 <- as.matrix(B1%*%D1%*%t(B1))
F1 <- C1+E1
gamma <- A1%*%solve(F1)
P_mat <- (diag(2)%*%gamma%*%t(lambda)%*%Xe[i,])%*%P_mat
G1 <- as.matrix(lambda%*%t(Xe[i,]%*%w))
H1 <- as.matrix(Y[i,])
I1 <- as.vector(H1-G1)
J1 <- I1*gamma
w <- w + J1; #as.matrix(I1%*%gamma)
K1 <- Xe[i,]%*%w
L1 <- lambda%*%t(K1)

hier kommt der Fehler bei Yhat

Yhat[i,] <- L1  
#error[i,] <- Y[i,]-Yhat[i,]
#b <- b+1
}
}
#Yhat <- as.vector(Yhat)
#plot(Y,type="l",col="red")
#lines(Yhat,col="green")
#plot(Yhat)
#plot(error)
Herauszufinden auf welcher Zeile der Fehler passiert, das wäre ein guter Anfang...
Oh boy, der Einzug Formatvorlage, die Sie verwenden, ist mir weh zu tun...

InformationsquelleAutor ALI KHAN | 2014-09-06

Schreibe einen Kommentar