def __init__( self, domain, logger, initial_representation, discretization=20, maxBatchDicovery=1, batchThreshold=0, bagSize=100000, sparsify=False, ): self.selectedFeatures = [] self.iFDD_ONLINETHRESHOLD = 1 # This is dummy since omptd will not use ifdd in the online fashion self.maxBatchDicovery = maxBatchDicovery self.batchThreshold = batchThreshold self.initial_representation = initial_representation self.iFDD = iFDD( domain, logger, self.iFDD_ONLINETHRESHOLD, initial_representation, sparsify=0, discretization=discretization, useCache=1, ) self.bagSize = bagSize self.features_num = self.initial_representation.features_num self.isDynamic = True super(OMPTD, self).__init__(domain, logger, discretization) self.fillBag() self.totalFeatureSize = self.bagSize self.selectedFeatures = range( self.initial_representation.features_num ) # Add initial features to the selected list self.remainingFeatures = arange( self.features_num, self.bagSize ) # Array of indicies of features that have not been selected self.show() if self.logger: self.logger.log("Initial Representation:\t%s" % className(self.initial_representation)) self.logger.log("Bag Size:\t\t%d" % self.bagSize) self.logger.log("Batch Threshold:\t\t%0.3f" % self.batchThreshold) self.logger.log("Max Batch Discovery:\t%d" % self.maxBatchDicovery)
def featureType(self): return self.initial_representation.featureType() if __name__ == "__main__": STDOUT_FILE = "out.txt" JOB_ID = 1 OUT_PATH = "Results/Temp" # logger = Logger('%s/%d-%s'%(OUT_PATH,JOB_ID,STDOUT_FILE)) logger = Logger() discovery_threshold = 1 # domain = MountainCar() domain = SystemAdministrator("/../Domains/SystemAdministratorMaps/20MachTutorial.txt") initialRep = IndependentDiscretizationCompactBinary(domain, logger) rep = iFDD(domain, logger, discovery_threshold, initialRep, debug=0, useCache=1) rep.theta = arange(rep.features_num * domain.actions_num) * 10 print "Initial [0,1,20] => ", print rep.findFinalActiveFeatures([0, 1, 20]) print "Initial [0,20] => ", print rep.findFinalActiveFeatures([0, 20]) rep.showCache() print "discover 0,20" phi_s = zeros(rep.features_num) phi_s[0] = 1 phi_s[20] = 1 rep.discover(phi_s, discovery_threshold + 1) rep.showFeatures() rep.showCache() print "Initial [0,20] => ", print rep.findFinalActiveFeatures([0, 20])