User Tools

Site Tools


inputs

Table of Contents

Inputs

Usage

In N2S3, inputs work like a pipelined stream : data are successively transformed to ultimately be sent to the neural network.

The input stream need to begin with a StreamEntry[T](shape : Shape) class. This last allow to set a type of the incoming data, the template parameter T, but also their dimensionality with the parameter Shape. It is then possible to pipe some stream converter to the stream.

An example of a piped input stream:

StreamEntry[SampleInput](Shape(28, 28)) >> // stream entry in sample format, in this case images (T = SampleInput, Shape = 28*28)
  StreamOversampling(2, 2) >> // multiply each dimension size by 2 (T = SampleInput, Shape = 56*56)
  SampleToSpikeTrainConverter(0, 22, 150 MilliSecond, 350 MilliSecond) >> // convert to spike trains (T = InputSeq[N2S3Input], Shape = 56*56)
  InputNoiseGenerator(5 hertz) >> // add noise to each spike trains (T = InputSeq[N2S3Input], Shape = 56*56)

To provide data to the network, the end of the stream need to be of type InputSeq[N2S3Input]. In the last example, this is achieved with the SampleToSpikeTrainConverter class.

Create New Inputs

All the inputs need to extends the class N2S3InputStream[T]. Several methods need to be implemented :

  • shape: Shape, which indicate the data dimensionality
  • next() : T, which need return the next data
  • reset() : Unit, which set the class state at the beginning of the data
  • atEnd() : Boolean, which indicate if it remain some input data

Let's create an input example. We will create a reader for the Iris dataset. This last is compound of 150 instances. Each of them had one label and four attributes. In the data file each instance is described by a line in the following format:

<attribute1 : Float>,<attribute2 : Float>,<attribute3 : Float>,<attribute2 : Float>,<label : String>

So, the input shape will be only Shape(4). We need us a file reader first, and then, provide each data sample with it label:

class IrisEntry(filename : String) extends N2S3InputStream[SampleInput] {
  val data = Source.fromFile(filename).getLines().map(_.split(",")).filter(_.length == 5).toSeq
 
  var cursor = 0
 
  def shape : Shape = Shape(4)
 
  def next() : SampleInput = {
 
    val entry = data(cursor)
 
    val d = for((f, i) <- entry.take(4).zipWithIndex) yield {
      SampleUnitInput(f.toFloat, i)
    }
 
    cursor += 1
    SampleInput(d, entry(4))
  }
 
  def reset() = {
    cursor = 0
  }
 
  def atEnd() = cursor >= data.size
}
inputs.txt ยท Last modified: 2016/11/10 11:33 by Pierre.Falez@univ-lille1.fr