Problème de mémoire dans R ?

Postez ici vos questions, réponses, commentaires ou suggestions - Les sujets seront ultérieurement répartis dans les archives par les modérateurs

Modérateur : Groupe des modérateurs

Thomas Galtier
Messages : 93
Enregistré le : 14 Mai 2007, 12:08

Problème de mémoire dans R ?

Messagepar Thomas Galtier » 31 Mai 2007, 08:42

Bonjour,

Voici le message d'erreur que j'ai :

Code : Tout sélectionner

 KO<-krige(TEMP~1,~LONG+LAT,data=forva,newdata=va,model=fvg)
[using ordinary kriging]

"memory.c", line 57: can't allocate memory in function m_get()
Erreur dans predict.gstat(g, newdata = newdata, block = block, nsim = nsim,  :
        m_get


Je précise que TEMP, LONG, LAT, font 12278 de longueur, et ma data.frame "va" ne fait qu'un de longeur.


Voici (en partie) le code la fonction predict.gstat (j'ai mis en rouge la ligne ou il y a errer):

Code : Tout sélectionner

for (i in 1:length(object$data)) {
        name = names(object$data)[i]
        d = object$data[[i]]
        if (!is.null(d$data)) {
            if (!identical(proj4string(d$data), proj4string(newdata)))
                stop(paste(name, ": data item in gstat object and newdata have different coordinate reference systems"))
        }
        if (d$nmax == Inf)
            nmax = as.integer(-1)
        else nmax = as.integer(d$nmax)
        nmin = as.integer(max(0, d$nmin))
        if (d$maxdist == Inf)
            maxdist = as.numeric(-1)
        else maxdist = d$maxdist
        if (d$dummy) {
            if (is.null(d$beta) || length(d$beta) == 0)
                stop("dummy data should have beta defined")
            if (d$degree != 0)
                stop("dummy data cannot have non-zero degree arg; use formula")
            loc.dim = dim(coordinates(newdata))[[2]]
            .Call("gstat_new_dummy_data", as.integer(loc.dim),
                as.integer(d$has.intercept), as.double(d$beta),
                nmax, nmin, maxdist, as.integer(d$vfn), as.integer(is.projected(newdata)))
        }
        else {
            if (is.null(d$weights))
                w = numeric(0)
            else w = d$weights
            raw = gstat.formula(d$formula, d$data)
            .Call("gstat_new_data", as.double(raw$y), as.double(raw$locations),
                as.double(raw$X), as.integer(raw$has.intercept),
                as.double(d$beta), nmax, nmin, maxdist, as.integer(d$vfn),
                as.numeric(w), double(0), as.integer(d$degree),
                as.integer(is.projected(d$data)))
        }
      [color=red]  if (!is.null(object$model[[name]]))[/color]
            load.variogram.model(object$model[[name]], c(i -
                1, i - 1))
        raw = gstat.formula.predict(d$formula, newdata, na.action = na.action)
        if (is.null(new.X))
            new.X = raw$X
        else new.X = cbind(new.X, raw$X)
        if (i > 1) {
            for (j in 1:(i - 1)) {
                cross = cross.name(names(object$data)[j], name)
                if (!is.null(object$model[[cross]]))
                  load.variogram.model(object$model[[cross]],
                    c(i - 1, j - 1))
            }
        }
    }
    if (!is.null(object$set))
        gstat.load.set(object$set)
    if (!is.null(object$merge))
        gstat.load.merge(object)
    if (is(newdata, "SpatialPolygons")) {
        pol = getSpPpolygonsSlot(newdata)
        if (length(pol) != nrow(raw$locations))
            stop("polygons and center points length mismatch")
        block = matrix(NA, 0, 2)
        nd = as(newdata, "SpatialPolygons")
        block.cols = rep(as.numeric(NA), length(pol))
        for (i in seq(along = pol)) {
            sps.args$x = nd[i]
            cc = coordinates(do.call("spsample", sps.args))
            cc[, 1] = cc[, 1] - raw$locations[i, 1]
            cc[, 2] = cc[, 2] - raw$locations[i, 2]
            block.cols[i] = nrow(block) + 1
            block = rbind(block, cc)
        }
        if (length(pol) == 1)
            block.cols = 2
    }
    else if (is(newdata, "SpatialLines")) {
        lin = getSLlinesSlot(newdata)
        if (length(lin) != nrow(raw$locations))
            stop("lines and line midpoints length mismatch")
        block = matrix(NA, 0, 2)
        nd = as(newdata, "SpatialLines")
        block.cols = rep(as.numeric(NA), length(lin))
        for (i in seq(along = lin)) {
            sps.args$x = nd[i]
            cc = coordinates(do.call("spsample", sps.args))
            cc[, 1] = cc[, 1] - raw$locations[i, 1]
            cc[, 2] = cc[, 2] - raw$locations[i, 2]
            block.cols[i] = nrow(block) + 1
            block = rbind(block, cc)
        }
        if (length(lin) == 1)
            block.cols = 2
    }
    else if (!is.null(dim(block))) {
        block = data.matrix(block)
        block.cols = ncol(block)
    }
    else {
        block = as.numeric(block)
        block.cols = numeric(0)
    }
    valid.pattern = NULL
    if (any(is.na(raw$locations)) || any(is.na(new.X))) {
        valid.pattern = !(apply(cbind(raw$locations, new.X),
            1, function(x) any(is.na(x))))
        raw$locations.all = raw$locations
        raw$locations = as.matrix(raw$locations[valid.pattern,
            ])
        new.X = as.matrix(new.X[valid.pattern, ])
    }
    if (nsim) {
        if (indicators == TRUE)
            nsim = -abs(nsim)
        perm = sample(seq(along = new.X[, 1]))
        ret = .Call("gstat_predict", as.integer(nrow(as.matrix(new.X))),
            as.double(as.vector(raw$locations[perm, ])), as.double(as.vector(new.X[perm,
                ])), as.integer(block.cols), as.vector(block),
            as.integer(nsim), as.integer(BLUE))[[1]]
        if (nsim == 1)
            colsel = seq(1, by = 2, length.out = nvars)
        else colsel = TRUE
        ret = data.frame(cbind(raw$locations, matrix(ret[order(perm),
            colsel], nrow(as.matrix(new.X)), abs(nsim) * nvars)))
    }
    else {
        ret = .Call("gstat_predict", as.integer(nrow(as.matrix(new.X))),
            as.double(as.vector(raw$locations)), as.vector(new.X),
            as.integer(block.cols), as.vector(block), as.integer(nsim),
            as.integer(BLUE))[[1]]
        ret = data.frame(cbind(raw$locations, ret))
    }
    .Call("gstat_exit", NULL)
    if (!is.null(valid.pattern) && any(valid.pattern)) {
        ret.all = data.frame(matrix(NA, length(valid.pattern),
            ncol(ret)))
        ret.all[, 1:ncol(raw$locations.all)] = raw$locations.all
        ret.all[valid.pattern, ] = ret
        ret = ret.all
    }
    if (abs(nsim) > 0) {
        names.vars = names(object$data)
        if (length(names.vars) > 1)
            names.vars = paste(rep(names.vars, each = abs(nsim)),
                paste("sim", 1:abs(nsim), sep = ""), sep = ".")
        else names.vars = paste("sim", 1:abs(nsim), sep = "")
    }
    else names.vars = create.gstat.names(names(object$data))
    names(ret) = c(dimnames(raw$locations)[[2]], names.vars)
    if (return.sp) {
        if (is(newdata, "SpatialPolygons")) {
            row.names(ret) = sapply(newdata@polygons, function(x) slot(x,
                "ID"))
            ret = SpatialPolygonsDataFrame(as(newdata, "SpatialPolygons"),
                ret, match.ID = TRUE)
        }
        else if (is(newdata, "SpatialLines")) {
            row.names(ret) = sapply(newdata@lines, function(x) slot(x,
                "ID"))
            ret = SpatialLinesDataFrame(as(newdata, "SpatialLines"),
                ret, match.ID = TRUE)
        }
        else {
            coordinates(ret) = dimnames(raw$locations)[[2]]
            gridded(ret) = gridded(newdata)
        }
        proj4string(ret) = CRS(proj4string(newdata))
    }
    return(ret)
}


Pour ma part je pense qu'il ya saturation de la memoire pour l'utilisation de la fonction krige ... j'avais testé le même code avec moins de données et ça marchait au poil ...

Si vous avez des suggestions je suis preneur car ça m'aiderait pas mal si j'pouvais voir si ça venait vraiment de là !

Merci par avance pour tout renseignements,

Thomas

Retourner vers « Questions en cours »

Qui est en ligne

Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 1 invité