Exemplo n.º 1
0
    def optVOIParal(self,i,nStart,numProcesses=None):
	"""
	Runs in parallel the multi-start gradient ascent method
	to optimize the VOI.
	It restarts the gradient ascent method nStart times.
	
        Args:
	    i: Iteration of the algorithm.
	    nStart: Number of restarts of the gradient ascent method.
        """
        try:
            n1=self._n1
            n2=self._dimW
	    tempN=self.numberTraining+i
            Xst=self.Obj.sampleFromX(nStart)
            wSt=self.Obj.simulatorW(nStart)
	    args3=self.getParametersOptVoi(i)
	    jobs = []
            pool = mp.Pool(processes=numProcesses)
            for j in range(nStart):
		args2=args3.copy()
                x1=Xst[j:j+1,:]
                w1=wSt[j:j+1,:]
                st=np.concatenate((x1,w1),1)
                args2['start']=st
                job = pool.apply_async(misc.VOIOptWrapper, args=(self,), kwds=args2)
                jobs.append(job)
            pool.close()  # signal that no more data coming in
            pool.join()  # wait for all the tasks to complete
        except KeyboardInterrupt:
            print "Ctrl+c received, terminating and joining pool."
            pool.terminate()
            pool.join()
        for j in range(nStart):
            try:
                self.optRuns.append(jobs[j].get())
            except Exception as e:
                print "Error optimizing VOI"
                
        if len(self.optRuns):
            j = np.argmax([o.fOpt for o in self.optRuns])
	    fl.writeNewPointSBO(self,self.optRuns[j])
        self.optRuns=[]
        self.optPointsArray=[]
Exemplo n.º 2
0
    def optVOInoParal(self,i):
	"""
	Runs the single-start gradient ascent method to optimize the VOI.
	
        Args:
	    i: Iteration of the algorithm.
        """
	n1=self._n1
	n2=self._dimW
	Xst=self.Obj.sampleFromX(1)
	wSt=self.Obj.simulatorW(1)
	x1=Xst[0:0+1,:]
	w1=wSt[0:0+1,:]
	tempN=self.numberTraining+i
	st=np.concatenate((x1,w1),1)
	args2=self.getParametersOptVoi(i)
	args2['start']=st
	self.optRuns.append(misc.VOIOptWrapper(self,**args2))
	fl.writeNewPointSBO(self,self.optRuns[0])