Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/0xdata/h2o
Browse files Browse the repository at this point in the history
  • Loading branch information
anqi committed Apr 3, 2014
2 parents 2c0e8b0 + 0eb62fe commit fcc23d7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 32 deletions.
24 changes: 21 additions & 3 deletions h2o-scala/src/main/scala/water/api/dsl/DslLegos.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import water.MRTask2
import water.fvec.Chunk
import water.Iced
import water.fvec.NFSFileVec
import java.io.File
import java.io.{FileNotFoundException, File}
import water.fvec.ParseDataset2
import water.Job
import hex.drf.DRF
Expand Down Expand Up @@ -248,13 +248,29 @@ trait T_H2O_Env[K<:HexKey, VT <: DFrame] { // Operating with only given represen
def parse(file:File):DFrame = parse(file, file.getName+".hex")
def parse(s:String, destKey:String):DFrame = parse(new File(s), destKey)
def parse(file:File, destKey:String):DFrame = {
if (!file.exists()) throw new FileNotFoundException(file.getName)
val dest: Key = Key.make(destKey)
val fkey:Key = NFSFileVec.make(file)
val f = ParseDataset2.parse(dest, Array(fkey))
UKV.remove(fkey)
// Wrap the frame
new DFrame(f)
}
// Find a given filename
def ffind(fname: String):File = {
var file = new File(fname)
if (!file.exists())
file = new File("../" + fname)
if (!file.exists())
file = new File("../../" + fname)
if (!file.exists())
file = new File("../smalldata/" + fname)
if (!file.exists())
file = new File("../../smalldata/" + fname)
if (!file.exists())
throw new FileNotFoundException(fname)
file
}
def keys:Unit = keys(false)
// Simply print a list of keys in KV store
def keys(verbose:Boolean = false) = {
Expand Down Expand Up @@ -285,7 +301,8 @@ trait T_H2O_Env[K<:HexKey, VT <: DFrame] { // Operating with only given represen
val drf:DRF = new DRF()
drf.source = ftrain(x++Seq(y)).frame()
drf.response = ftrain.frame().vec(y)
params(drf).invoke()
if (params!=null) params(drf)
drf.invoke()
return UKV.get(drf.dest())
}

Expand All @@ -303,7 +320,8 @@ trait T_H2O_Env[K<:HexKey, VT <: DFrame] { // Operating with only given represen
dl.response = ftrain.frame().vec(y)
dl.validation = if (ftest != null) ftest.frame() else null
// Fill parameters and invoke computation
params(dl).invoke()
if (params!=null) params(dl)
dl.invoke()
return UKV.get(dl.dest())
}
}
Expand Down
10 changes: 1 addition & 9 deletions h2o-scala/src/main/scala/water/api/dsl/H2ODsl.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
package water.api.dsl

import water.fvec.Frame
import scala.collection.immutable.Range
import water.fvec.Frame
import water.UKV
import water.Key
import water.H2O
import water.TestUtil
import java.io.File
import water.fvec.NFSFileVec
import water.fvec.ParseDataset2
import java.util.UUID

/** The object carry global environment and provides basic global methods such as head, tail, nrows, ... */
object H2ODsl extends H2ODslImplicitConv with T_R_Env[DFrame] with T_H2O_Env[HexKey, DFrame] with DefaultEnv[HexKey, DFrame] {
Expand All @@ -34,7 +26,7 @@ object H2ODsl extends H2ODslImplicitConv with T_R_Env[DFrame] with T_H2O_Env[Hex
def save(k:HexKey, d:DFrame) = put(k,d)

def example():DFrame = example(System.getProperty("user.dir") + "/../../")

def example(topdir:String):DFrame = {
println("topdir is: " + topdir)
val tdir = if (topdir==null) "" else if (!topdir.endsWith("/")) topdir+"/" else topdir
Expand Down
2 changes: 2 additions & 0 deletions h2o-scala/src/main/scala/water/api/dsl/ShalalaRepl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ object ShalalaRepl {
intp.addImports("water.api.dsl.H2ODsl._")
intp.addImports("water.api.dsl._")
intp.addImports("water.api.Request.API")
intp.addImports("hex.deeplearning.DeepLearning")
intp.addImports("hex.deeplearning.DeepLearning.ClassSamplingMethod")
})

override def printWelcome() {
Expand Down
27 changes: 7 additions & 20 deletions h2o-scala/src/main/scala/water/api/dsl/examples/Examples.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package water.api.dsl.examples

import water.{Boot, H2O, Iced}
import water.api.dsl.{Row, T_T_Collect, DFrame}
import hex.deeplearning.DeepLearning
import java.io.File
import java.util.Random
import hex.deeplearning.DeepLearning.ClassSamplingMethod
import hex.drf.DRF

/**
Expand Down Expand Up @@ -94,7 +91,11 @@ makes a prediction over train data and compute MSE of prediction."""")
/** Simple example of deep learning model builder. */
def example4() = {
banner(4, "Call deep learning model builder and validate it on test data.")
// Import favorite classes
import water.api.dsl.H2ODsl._
import hex.deeplearning.DeepLearning
import hex.deeplearning.DeepLearning.ClassSamplingMethod

// Parse train dataset
val ftrain = parse(ffind("smalldata/logreg/prostate.csv"))
// Create parameters for deep learning
Expand Down Expand Up @@ -129,10 +130,10 @@ makes a prediction over train data and compute MSE of prediction."""")
def userMain(args: Array[String]):Unit = {
H2O.main(args)
try {
//example1()
example1()
example2()
//example3()
//example4()
example3()
example4()
} catch {
case t:Throwable => t.printStackTrace() // Simple debug
} finally {
Expand All @@ -145,20 +146,6 @@ makes a prediction over train data and compute MSE of prediction."""")
println("\n==== Example #"+id+" ====\n "+desc )
println( "====================\n")
}

// Find a given filename
private def ffind(fname: String):File = {
var file = new File(fname)
if (!file.exists())
file = new File("../" + fname)
if (!file.exists())
file = new File("../../" + fname)
if (!file.exists())
file = null
file
}


}

// Companion class
Expand Down

0 comments on commit fcc23d7

Please sign in to comment.