<HTML><HEAD>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.18702"></HEAD>
<BODY style="MARGIN: 4px 4px 1px; FONT: 10pt Tahoma">
<DIV>Jonathan,</DIV>
<DIV>Thanks for your quick reply. I just tried your Tahoe example using x and y in the call rather than a formula and it worked fine, so I was barking up the wrong tree. Sorry. I'll try to delve deeper and put together a subset example for you to check out if I can't get anywhere. </DIV>
<DIV> </DIV>
<DIV>Thanks,</DIV>
<DIV>Tim<BR><BR>>>> Jonathan Greenberg <jgrn@illinois.edu> 3/26/2014 10:23 AM >>><BR>Hi Tim:<BR><BR>Re: stack, yep, it should work. In general, you get a decreased<BR>performance from stacks since you are having to read from multiple<BR>files rather than a single one, but it will still benefit from<BR>parallel processing.<BR><BR>Re: formula -- the best way for me to test this is to crop out a piece<BR>of your image and send me the random forest model (use ?save), and the<BR>call you were using. In theory you should be able to use anything you<BR>would normally use on a data frame, but I'd have to play with it to<BR>confirm! If you can set up those on e.g. google drive I can test it<BR>out. Cheers!<BR><BR>--j<BR><BR>On Wed, Mar 26, 2014 at 6:49 AM, Tim Howard <tghoward@gw.dec.state.ny.us> wrote:<BR>> Jonathan,<BR>> Thank you for putting this together and for the example. I'm doing two<BR>> things differently with randomForest ... I think perhaps one of them the<BR>> function isn't handling.<BR>><BR>> First, based on recommendations from Andy Liaw (and ?randomForest), I don't<BR>> use the formula interface but use x=<many columns>, y=<a column> in the<BR>> call. Does predict_rasterEngine handle the absence of a formula in the<BR>> object?<BR>><BR>> Second, I have many large rasters I want to run the predict on, so making a<BR>> brick would be difficult. I use a rasterStack instead. Does your example<BR>> work with a rasterStack?<BR>><BR>> I can dive deeper if any of this isn't clear or if these two tweaks work<BR>> just fine for you. I was just trying to swap out this version of predict<BR>> with another parallel version to evaluate speed and, while the alternate<BR>> version works fine, predict_rasterEngine bailed on me.<BR>><BR>> Thanks in advance.<BR>> Tim Howard<BR>><BR>><BR>><BR>>>>>>>><BR>> Date: Tue, 18 Mar 2014 22:14:23 -0500<BR>> From: Jonathan Greenberg <jgrn@illinois.edu><BR>> To: "r-sig-geo@r-project.org" <R-sig-Geo@r-project.org><BR>> Subject: [R-sig-Geo] Parallel predict now in spatial.tools<BR>> Message-ID:<BR>> <CABG0rfseg+p0h4HdYOK+_Za=OLMeTKHAT+TQn7g_FkEdYiunFQ@mail.gmail.com><BR>> Content-Type: text/plain; charset=ISO-8859-1<BR>><BR>> R-sig-geo'ers:<BR>><BR>> I finally got around to building a parallel predict statement that<BR>> I've included in version 1.3.7 (or later) of spatial.tools (check<BR>> <A href="http://r-forge.r-project.org/R/?group_id=1492">http://r-forge.r-project.org/R/?group_id=1492</A> for the status of the<BR>> build), "predict_rasterEngine". It should, in theory, be a direct<BR>> swap-in for the standard generic predict() statement. Currently, it<BR>> will work on any predict.* statement that has the following features:<BR>> 1) The data is passed to the predict as a data frame via a newdata<BR>> parameter, and<BR>> 2) The data is returned from the predict statement as a vector/matrix.<BR>><BR>> When using predict_rasterEngine, the object= parameter is your model,<BR>> and the newdata= parameter is the raster/brick/stack to apply the<BR>> model to on a pixel-by-pixel basis (note that the names of the layers<BR>> must match the names of the predictor variables, in most cases).<BR>><BR>> I was hoping to get some stress-testing on this, since it is a fairly<BR>> oft-requested function. If a predict.* function you'd like to use<BR>> doesn't work, let me know which function it is (with some test data)<BR>> and I'll see if I can tweak it to work.<BR>><BR>> Right now, I have confirmed this works with randomForest. Here's an<BR>> example:<BR>><BR>> ######################<BR>><BR>> packages_required <- c("spatial.tools","doParallel","randomForest")<BR>> lapply(packages_required, require, character.only=T)<BR>><BR>> # Load up a 3-band image:<BR>> tahoe_highrez <- setMinMax(<BR>> brick(system.file("external/tahoe_highrez.tif", package="spatial.tools")))<BR>> tahoe_highrez<BR>> plotRGB(tahoe_highrez)<BR>><BR>> # Load up some training points:<BR>> tahoe_highrez_training_points <- readOGR(<BR>> dsn=system.file("external", package="spatial.tools"),<BR>> layer="tahoe_highrez_training_points")<BR>><BR>> # Extract data to train the randomForest model:<BR>> tahoe_highrez_training_extract <- extract(<BR>> tahoe_highrez,<BR>> tahoe_highrez_training_points,<BR>> df=TRUE)<BR>><BR>> # Fuse it back with the SPECIES info:<BR>> tahoe_highrez_training_extract$SPECIES <-<BR>> tahoe_highrez_training_points$SPECIES<BR>><BR>> # Note the names of the bands:<BR>> names(tahoe_highrez_training_extract) # the extracted data<BR>> names(tahoe_highrez) # the brick<BR>><BR>> # Generate a randomForest model:<BR>> tahoe_rf <-<BR>> randomForest(SPECIES~tahoe_highrez.1+tahoe_highrez.2+tahoe_highrez.3,<BR>> data=tahoe_highrez_training_extract)<BR>><BR>> tahoe_rf<BR>><BR>> # This will run the predict in parallel:<BR>> sfQuickInit()<BR>> prediction_rf_class <-<BR>> predict_rasterEngine(object=tahoe_rf,newdata=tahoe_highrez,type="response")<BR>> prediction_rf_prob <-<BR>> predict_rasterEngine(object=tahoe_rf,newdata=tahoe_highrez,type="prob")<BR>> sfQuickStop()<BR>><BR>> ###############<BR>><BR>> --j<BR><BR><BR><BR>-- <BR>Jonathan A. Greenberg, PhD<BR>Assistant Professor<BR>Global Environmental Analysis and Remote Sensing (GEARS) Laboratory<BR>Department of Geography and Geographic Information Science<BR>University of Illinois at Urbana-Champaign<BR>259 Computing Applications Building, MC-150<BR>605 East Springfield Avenue<BR>Champaign, IL 61820-6371<BR>Phone: 217-300-1924<BR><A href="http://www.geog.illinois.edu/~jgrn/">http://www.geog.illinois.edu/~jgrn/</A><BR>AIM: jgrn307, MSN: jgrn307@hotmail.com, Gchat: jgrn307, Skype: jgrn3007<BR></DIV></BODY></HTML>