Ejemplo n.º 1
0
  def testDecoding(self):
    s = ScalarEncoder(1,1,3,n=3, name='idx', forced=True)
    v = VectorEncoder(3, s, typeCastFn=float)
    data=[1,2,3]
    enc = v.encode(data)

    #decode
    dec = v.decode(enc)
    print "decoded=", dec
    res= v.getData(dec)
    self.assertEqual(data, res, "Decoded data not equal to original")
Ejemplo n.º 2
0
  def testEncoding(self):
    s = ScalarEncoder(1,1,3,n=3, name='idx', forced=True)
    v = VectorEncoder(3, s, typeCastFn=float)

    data=[1,2,3]
    print "data=", data
    # encode
    enc = v.encode(data)
    print "encoded=", enc
    correct = [1,0,0,0,1,0,0,0,1]
    self.assertTrue((enc==correct).all(), "Did not encode correctly")
Ejemplo n.º 3
0
    def testDecoding(self):
        s = ScalarEncoder(1, 1, 3, n=3, name='idx')
        v = VectorEncoder(3, s, typeCastFn=float)

        data = [1, 2, 3]
        print "data=", data
        # encode
        enc = v.encode(data)
        print "encoded=", enc
        correct = [1, 0, 0, 0, 1, 0, 0, 0, 1]
        assert (enc == correct).all()

        #decode
        dec = v.decode(enc)
        print "decoded=", dec
        res = v.getData(dec)
        assert data == res
Ejemplo n.º 4
0
  def testDecoding(self):
    s = ScalarEncoder(1,1,3,n=3, name='idx')
    v = VectorEncoder(3, s, typeCastFn=float)

    data=[1,2,3]
    print "data=", data
    # encode
    enc = v.encode(data)
    print "encoded=", enc
    correct = [1,0,0,0,1,0,0,0,1]
    assert (enc==correct).all()

    #decode
    dec = v.decode(enc)
    print "decoded=", dec
    res= v.getData(dec)
    assert data==res
Ejemplo n.º 5
0
 def __init__(self, length=5, feedbackDelay=0, minval=-5, maxval=5, resolution=1, scoreMin=0, scoreMax=100, scoreResolution=1, forced=False):
   """
   initialize UtilityEncoder with default settings. 
   @param length  size of the input vector 
   @param feedbackDelay integer >=0; used if you want to apply a score from the current state (T) to state in time T-1; default(0) means state(T) pairs with score(T)
   @param minval  minimal value of input data (from ScalarEncoder)
   @param maxval  max value input data can reach; eg for set of vectors {[0,0,1], [0,-1,0],[1,2,0]} it's -1 and 2
   @param resolution  resolution of the underliing scalar encoder
   @param scoreMin
   @param scoreMax  same as minval, maxval but for the score
   @param scoreResolution
   @forced
   """
   dataS = ScalarEncoder(21, minval, maxval, resolution=resolution, name='idx')
   dataV = VectorEncoder(length, dataS, name='data')
   scoreS = ScalarEncoder(21, scoreMin, scoreMax, resolution=scoreResolution, name='utility')
   super(SimpleUtilityEncoder, self).__init__(dataV, scoreS, feedbackDelay=feedbackDelay, name='simpleUtility', forced=forced)
   print "WARNING: feval not set! do not forget to def(ine) the function and set it with setEvaluationFn() "
Ejemplo n.º 6
0
    def setUp(self):
        self.data = [-1, 0, 10]

        # encoder for score: 0..100, fine-grained to 0.5
        self.scoreEnc = ScalarEncoder(3, 0, 100, resolution=0.5, name='score')

        # encoder for the input (data) part
        elem = ScalarEncoder(5, -5, 50, resolution=1)
        self.dataEnc = VectorEncoder(len(self.data),
                                     elem,
                                     typeCastFn=float,
                                     name='data')

        # utility encoder
        def sumAll(list):
            return sum(list)

        self.fn = sumAll

        self.utilityEnc = UtilityEncoder(self.dataEnc,
                                         self.scoreEnc,
                                         feval=self.fn,
                                         name='sum-er')
Ejemplo n.º 7
0
 def testInitialization(self):
   e = VectorEncoder(3, ScalarEncoder(21, 0, 10, n=200), name="vec")
   self.assertIsInstance(e, VectorEncoder)