def testVectorEncoderOPFInstance(self): """calling VectorEncoder from OPF""" opfVect = VectorEncoderOPF(3, 1, 3, n=211, w=21, dataType="int") data=[1,2,3] enc=opfVect.encode(data) dec=opfVect.decode(enc) data2=opfVect.getData(dec) self.assertEqual(data, data2, "VectorEncoderOPF did not encode/decode correctly.")
def testVectorEncoderOPFTypeCast(self): """for calling from OPF, use this to cast data type""" opfVect = VectorEncoderOPF(3, 1, 3, n=300, w=21, dataType="str") data=[1,2,3] enc=opfVect.encode(data) dec=opfVect.decode(enc) data2=opfVect.getData(dec) self.assertIsInstance(data2[0], str, "VectorEncoderOPF did not cast output to str(ing)") opfVect = VectorEncoderOPF(3, 1, 3, n=300, w=21, dataType="int") data=[1,2,3] enc=opfVect.encode(data) dec=opfVect.decode(enc) data2=opfVect.getData(dec) self.assertIsInstance(data2[0], int, "VectorEncoderOPF did not cast output to int")
def __init__(self, pathToFevalFnFile, length=5, feedbackDelay=0, minval=-5, maxval=5, resolution=1, scoreMin=0, scoreMax=100, scoreResolution=1, forced=False): """ @param pathToFevalFnFile path to a file that contains python \"def feval(self, other, params)\" function to be loaded; used as feval """ # TODO: cleanup the params dataV = VectorEncoderOPF(length, minval, maxval, resolution=resolution, name='data') scoreS = ScalarEncoder(21, scoreMin, scoreMax, resolution=scoreResolution, name='utility') myDef = imp.load_source('module.name', pathToFevalFnFile) if not isinstance(myDef.feval, FunctionType): raise Exception("failed to load feval() function from %s" % pathToFevalFile) super(UtilityEncoderOPF, self).__init__(dataV, scoreS, feval=myDef.feval, feedbackDelay=feedbackDelay, name='UtilityOPF', forced=forced)
def testVectorEncoderOPFInstance(self): # for calling from OPF, use this: opfVect = VectorEncoderOPF(3, 1, 1, 3, n=3)