def randomize(self, data_matrix, amount=.5): random.seed(self.random_state) inclusion_threshold = random.uniform(amount, 1) selectors = [] if random.random() > inclusion_threshold: selectors.append( SparseSelector(random_state=random.randint(1, 1e9))) if random.random() > inclusion_threshold: selectors.append( MaxVolSelector(random_state=random.randint(1, 1e9))) if random.random() > inclusion_threshold: selectors.append( QuickShiftSelector(random_state=random.randint(1, 1e9))) if random.random() > inclusion_threshold: selectors.append( DensitySelector(random_state=random.randint(1, 1e9))) if random.random() > inclusion_threshold: selectors.append( OnionSelector(random_state=random.randint(1, 1e9))) if not selectors: selectors.append( DensitySelector(random_state=random.randint(1, 1e9))) selectors.append( SparseSelector(random_state=random.randint(1, 1e9))) selector = CompositeSelector(selectors=selectors) selector.randomize(data_matrix, amount=amount) self.selectors = deepcopy(selector.selectors) self.metric = 'rbf' self.kwds = {'gamma': random.choice([10**x for x in range(-3, 3)])} if random.random() > inclusion_threshold: self.n_nearest_neighbors = random.randint(3, 20) else: self.n_nearest_neighbors = None self.n_links = random.randint(1, 5) self.random_state = self.random_state ^ random.randint(1, 1e9)
def make_selectors(opts): # compose selector list selectors = [] if 'QuickShiftSelector' in opts and opts['QuickShiftSelector'] is not None: from eden.selector import QuickShiftSelector selectors.append( QuickShiftSelector(n_instances=opts['QuickShiftSelector'])) if 'MaxVolSelector' in opts and opts['MaxVolSelector'] is not None: from eden.selector import MaxVolSelector selectors.append(MaxVolSelector(n_instances=opts['MaxVolSelector'])) if 'DensitySelector' in opts and opts['DensitySelector'] is not None: from eden.selector import DensitySelector selectors.append(DensitySelector(n_instances=opts['DensitySelector'])) if 'SparseSelector' in opts and opts['SparseSelector'] is not None: from eden.selector import SparseSelector selectors.append(SparseSelector(n_instances=opts['SparseSelector'])) if 'EqualizingSelector' in opts and opts['EqualizingSelector'] is not None: from sklearn.cluster import MiniBatchKMeans from eden.selector import EqualizingSelector n_clusters = opts['EqualizingSelector'] / 10 selectors.append( EqualizingSelector(n_instances=opts['EqualizingSelector'], clustering_algo=MiniBatchKMeans(n_clusters))) return selectors