3

I need to normalize my data before training. In pybrain.rl.environments.task there is a function normalize(). But I did not try, does not work, only errors. Unable to call the function for the training data.

from pybrain.tools.shortcuts import buildNetwork
from pybrain.structure import TanhLayer
from pybrain.datasets import SupervisedDataSet
from pybrain.supervised.trainers import RPropMinusTrainer
from pybrain.supervised.trainers import BackpropTrainer
from pybrain.structure.networks import Network
from pybrain.rl.environments.task import Task
import numpy as np

ds = SupervisedDataSet(3, 1)

ds.addSample( (76.7, 13.8, 103.0), 770)
ds.addSample( (70.9, 13.0, 92.0), 650)
ds.addSample( (65.6, 15.9, 104.3), 713)
ds.addSample( (59.3, 14.8, 88.0), 593)
ds.addSample( (50.0, 13.0, 65.2), 443)
ds.addSample( (44.9, 17.6, 79.0), 547)
ds.addSample( (44.3, 18.4, 78.6), 553)
ds.addSample( (44.4, 18.4, 81.8), 576)

#create object for training data
test = Task(ds)

#set the normalization limits from 0 to 1
test.setScaling([(0, 1)], None)

#function call(problem here, I tried a lot of options for a function call, but none worked)
test.normalize((0, 1))

net = buildNetwork(ds.indim, 3, ds.outdim, bias = True, hiddenclass=TanhLayer)

trainer = BackpropTrainer(net, dataset=ds, verbose=False, learningrate = 0.01, momentum = 0.99)

trainer.trainOnDataset(ds,100)
trainer.testOnData(verbose=False)

I do not understand what and how I should pass in the normalization of the function so that it worked.

1 Answers1

0

I know this is way late but here is what I found, I guess. It seems like the setScaling receives the tuples of min-max in the dimension you want to normalize in the parameter sensor_limits:

def setScaling(self, sensor_limits, actor_limits):
    self.sensor_limits = sensor_limits
    self.actor_limits = actor_limits

On the other hand, normalize() receives the actual dimension in the parameter sensors and does the calculation with the tuples (min-max) specified in sensor_limits:

for l, s in zip(self.sensor_limits, sensors):
    if not l:
        result.append(s)
    else:
        result.append((s - l[0]) / (l[1] - l[0]) * 2 - 1.0)
gissemari
  • 11
  • 2