当前位置: 首页>>代码示例>>Python>>正文


Python Manager.join方法代码示例

本文整理汇总了Python中multiprocessing.Manager.join方法的典型用法代码示例。如果您正苦于以下问题:Python Manager.join方法的具体用法?Python Manager.join怎么用?Python Manager.join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在multiprocessing.Manager的用法示例。


在下文中一共展示了Manager.join方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: predict

# 需要导入模块: from multiprocessing import Manager [as 别名]
# 或者: from multiprocessing.Manager import join [as 别名]
    def predict(self, x):
        """ Predict class for test set x.

        The predicted class of an input sample is computed as the majority
        prediction of the trees in the forest.

        Parameters
        ----------
        x : array-like of shape = [n_samples, n_features]
           The test input samples.

        Returns
        -------
        y_pred : array of shape = [n_samples]
                The predicted classes.

        probs : array of shape = [n_samples]
                Probabilities of each sample to belong to the predicted class.

        """
        if self.n_jobs == -1:
            n_workers = min(cpu_count(), self.n_trees)
        else:
            n_workers = min(self.n_jobs, self.n_trees)

        # Establish communication queues.
        tasks = Manager().JoinableQueue()
        results = Manager().Queue()

        # Start workers.
        workers = [Worker(tasks, results) for _ in xrange(n_workers)]

        for w in workers:
            w.start()

        # Populate task's queue.
        for i in xrange(self.n_trees):
            tasks.put(Task(_tree_predict, (x, self.forest[i]), i))

        # Add a poison pill for each worker.
        for i in xrange(n_workers):
            tasks.put(None)

        # Wait for all of the tasks to finish.
        tasks.join()

        # Retrieve results i.e. the votes of the trees from the queue i.e
        # an array of shape [n_trees, n_samples].
        votes = np.array(retrieve(results, self.n_trees), int)

        # Count up the votes of the trees.
        n_classes = len(np.unique(votes))
        counts = np.apply_along_axis(
            lambda z: np.bincount(z, minlength=n_classes), 0, votes)

        # Classify each sample according to the majority of the votes.
        y_pred = np.argmax(counts, axis=0)

        return y_pred, counts / self.n_trees
开发者ID:bluesurfer,项目名称:pyforest,代码行数:61,代码来源:forest.py

示例2: fit

# 需要导入模块: from multiprocessing import Manager [as 别名]
# 或者: from multiprocessing.Manager import join [as 别名]
    def fit(self, x, y):
        """ Build a random forest of trees from the training set (x, y).

        Parameters
        ----------
        x : array-like of shape = [n_samples, n_features]
           The training input samples.

        y : array-like of shape = [n_samples]
           The target values (integers that correspond to classes).

        Returns
        -------
        self : object
           Returns self.

        """
        if self.n_jobs == -1:
            n_workers = min(cpu_count(), self.n_trees)
        else:
            n_workers = min(self.n_jobs, self.n_trees)

        # Establish communication queues.
        tasks = Manager().JoinableQueue()
        results = Manager().Queue()

        # Start workers.
        workers = [Worker(tasks, results) for _ in xrange(n_workers)]

        for w in workers:
            w.start()

        # Populate task's queue.
        for i in xrange(self.n_trees):
            # Create a new random state for each tree.
            random_state = np.random.RandomState(i)
            tasks.put(Task(_build_tree, (x, y, self,random_state), i))

        # Add a poison pill for each worker.
        for i in xrange(n_workers):
            tasks.put(None)

        # Wait for all of the tasks to finish.
        tasks.join()

        # Retrieve results i.e. the trees from the queue.
        self.forest = retrieve(results, self.n_trees)

        return self
开发者ID:bluesurfer,项目名称:pyforest,代码行数:51,代码来源:forest.py

示例3: System

# 需要导入模块: from multiprocessing import Manager [as 别名]
# 或者: from multiprocessing.Manager import join [as 别名]
class System():
	fileName = 'settings.cfg'
	def __init__(self):
		try:
			self.currentSettings = Settings.loadSettings(System.fileName)
		except(IOError):
			print 'No settings file found, reverting to default settings...'
			self.currentSettings = Settings()
			self.currentSettings.saveSettings(self.fileName)
						
		self.manager = Manager()
		self.sharedData = self.manager.dict()
		self.sharedData.update({
			'pad' : 'on',
			'sensors' : self.manager.list([Sensor(4), Sensor(17)]),
			'temp' : 0,
			'hum' : 0,
			'alarms' : self.manager.dict(), #if map empty => all green
			'fan_in' : 0.5,
			'fan_out': 0.5
		})		
		
		self.sharedData.update(self.currentSettings.set_d)
		
		#self.sharedData.update({ 'biases' : self.manager.list(self.currentSettings.set_d['biases'])})
		
	def dumpSettings(self):
		while 1:
			self.currentSettings.updateSettings(self.sharedData)
			self.currentSettings.saveSettings(self.fileName)
			time.sleep(300)

	def start(self):
		self.processes = [SystemCommand(self.sharedData), Updater(self.sharedData), Process(target=self.dumpSettings)]
		for p in self.processes: 
			p.start()
		self.manager.join()
		
		
		
		
开发者ID:tibor0991,项目名称:OBM-BOB,代码行数:39,代码来源:system.py

示例4: len

# 需要导入模块: from multiprocessing import Manager [as 别名]
# 或者: from multiprocessing.Manager import join [as 别名]
        for word in list_of_words:
            if word in stopwords:
                sw.add(word)
                num_of_stops += 1
        try:
            frac_stops = len(sw) / stops_num
        except ZeroDivisionError:
            frac_stops = 0
        try:
            stops_percentage = num_of_stops / len(list_of_words)
        except ZeroDivisionError:
            stops_percentage = 0
        result_list = [features[0], str(frac_stops), str(stops_percentage), str(entropy)]
        log_info(" ".join(result_list) + "\n")


# consumer thread dependant
def log_info(info):
    with lock:
        out.write(info)

if __name__ == '__main__':
    start = time()
    print("Started at {0}".format(localtime(start)))
    out = open("quality_features.txt", "w")
    lock = Lock()
    m = Manager()
    m.start()
    m.join()
    out.close()
    print("Elapsed {0} seconds".format(time() - start))
开发者ID:vladimir-nazarenko,项目名称:Retrieval2,代码行数:33,代码来源:formatter.py


注:本文中的multiprocessing.Manager.join方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。