hpe-cct / cct-core

CCT compiler, runtime, graphical debugger, and standard library
Apache License 2.0
15 stars 4 forks source link

How to print the field value of the compute graph using actuators? #7

Closed shrutiramesh88 closed 8 years ago

shrutiramesh88 commented 8 years ago

val cg = new ComputeGraph(optimize=false){ ... var correct = CorrectCount(d4.forward, label.forward, batchSize, 0.01f) / batchSize var avgCorrect = NormalizedLowPass(correct, 0.001f) ... } I want to print the correct and avgCorrect values

tobingonzalez commented 8 years ago

You could use an actuator that prints values to the console. E.g.:

// imports needed for our actuator definition
import libcog.{ScalarFieldReader, Actuator}

val cg = new ComputeGraph {
  ...
  var correct = CorrectCount(d4.forward, label.forward, batchSize, 0.01f) / batchSize
  var avgCorrect = NormalizedLowPass(correct, 0.001f)

  def printToConsole(prefix: String)(data: ScalarFieldReader): Unit = {
    // assumes there is exactly one scalar value in 'data'
    println(prefix+data.read())
  }
  val correctPrinter = Actuator(correct, printToConsole("correct: ")(_))
  val avgCorrectPrinter = Actuator(avgCorrect, printToConsole("avgCorrect: ")(_))
  ...
}

This will print the values of the 'correct' and 'avgCorrect' fields on every model tick.