什么是“输入的意外结束"?错误是什么意思? [英] What does the "Unexpected end of input" error mean?

查看:100
本文介绍了什么是“输入的意外结束"?错误是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在R中构建一个应用程序,以计算QR矩阵分解,QR非负矩阵分解和计算ICA.目前,我正在完成第一个任务.我收到以下错误:

I am currently building an application in R to calculate the QR matrix decomposition, the QR non negative matrix decomposition and computing ICA. At the moment I am working on the first task. I am getting the following error:

source("trial.R")

Error in source("trial.R") : trial.R:153:0: unexpected end of input
151: 
152: 
    ^

代码:

library(rworldmap)


install.packages("plotrix")
library(plotrix)


install.packages("fastICA")
library(fastICA)
install.packages("Matrix")
source("utils.R")
library("corpcor")

twophase.cx <- function(A, k, fudge=5) {

    SVD=svd(normalised)
    V=SVD$v

    vk<-array(0,dim=c(nrow(V),k))
    cols_v=ncol(V)
    for(cl in 1:k){
     for(r in 1:nrow(V)){
      vk[r,cl]<-V[r,cl+k]
      }}

   probs=rep(0,k)

   prod=A%*%vk%*%t(vk)
    for(j in 1:k){

    subA=A[nrow(A)-j,ncol(A)-j]

    subV=vk[nrow(subV)-j,ncol(vk)-j]

    subprod=prod[nrow(prod)-j,ncol(prod)-j]

    normv<-norm(subV,"2")
    normA<-norm(subA,"2")
    normProd<-norm(subprod,"2")
    add1<-(normv*normv)/(2*k)
    add2<-((normA*normA)-(normProd*normProd))/(2*((normA*normA)-           (normProd*normProd)))                                          
    probs[j]<-add1+add2
  }

   const<-(k*log(k))

   keep<-sample(c(1:k),size=const,prob=probs,replace=FALSE)

   S1<-matrix(0,ncol(A),const)
   for(i in 1:ncol(A)){
    for(j in 1:const){
     if(is.element(j,keep)){
      S1[i,j]<-1}}}

  D1<-matrix(0,const,const)
 for(i in 1:const){
   if(is.element(i,keep)){
    prd<-const*probs[i]
   if(prd<1){D[i,i]<-prd}
   if(prd>=1){D[i,i]<-1}
  }

 toSample<-t(vk)%*%S1%*%D1
 S2<-qr(toSample)$pivot[1:k]
 C<-A %*% S1 %*% S2
cols<-C
X<-pseudoinverse(C)%*%A
err<-norm(A-C %*% X, 'F')
list(cols=C,X=X,  err=err)    

} 


cx <- function(A, k, nreps=20, ...) {
best.res = list(cols=NA, X=NA, err=Inf)
for (rep in 1:nreps) {
    res <- twophase.cx(A, k, ...)
    if (res$err < best.res$err) {
        best.res <- res
    }
}
best.res
}


data <- as.matrix( read.csv("worldclim.csv") )
coord <- read.csv("coordinates.csv")



data.normal <-scale(data,center=TRUE,scale=TRUE)
k<-10


cx.res <- cx(t(data.normal), 5)


xLim <- c(min(coord["lon"]), max(coord["lon"]))
yLim <- c(min(coord["lat"]), max(coord["lat"]))
map <- getMap(resolution="low")
plot(map, xlim=xLim, ylim=yLim, asp=1)



points(coord[cx.res$cols,1], coord[cx.res$cols,2], col=2, pch=19, cex=1.5)
points(coord[cx.res$cols,1], coord[cx.res$cols,2], col=4, pch=65:127,    cex=.6)

x <- cx.res$X[1,]
plot(map, xlim=xLim, ylim=yLim, asp=1)
points(coord[,1], coord[,2], col=color.scale(x, c(0,1), 0.8, 1,     color.spec="hsv"), cex=.6, pch=19)
color.legend(xLim[1]+1, yLim[1]-5, xLim[2]-1, yLim[1]-3, c(round(min(x),    4), round(mean(x), 4), round(max(x), 4)), color.scale(sort(x), c(0,1), 0.8, 1,    color.spec="hsv"), gradient="x")


convex.cone <- function(A, k) {

}


house.price <- read.csv("us_housing_prices.csv", row.names=1)


rownames(house.price)

colnames(house.price)[1:18]
colnames(house.price)[seq(1, by=12, to=ncol(house.price))]


plot.time.series(house.price[1:5,])
plot.time.series(house.price[6:10,])
plot.time.series(house.price[11:15,])
plot.time.series(house.price[16:20,])

hp <- house.price
hp[is.na(house.price)] <- 0


hp <- scale(t(hp))

hp.ica <- fastICA(hp, 20, fun="logcosh", verbose=TRUE)




rownames(hp.ica$S) <- colnames(house.price)
with(hp.ica, plot.time.series(t(S[,1:5])) )

with(hp.ica, plot(S[,1:2], asp=1) )

with(hp.ica, identify(S[,1:2], labels=rownames(S)) )

我对R很陌生.请提出可能是问题所在.

I am quite new to R. Please suggest which might be the issue.

推荐答案

您可能缺少 twophase.cx 函数的} ,我怀疑在第72行.

You're missing a } for the twophase.cx function, I suspect at line 72.

这篇关于什么是“输入的意外结束"?错误是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆