def optimize(w, globalSPLVars, params, iter): if params.splParams.splMode == 'CCCP' or iter <= params.splParams.splInitIters: wOptstateBundle= SSVM.cuttingPlaneOptimize(w, params, iter) else: assert(0) # I don't understand globalSPLVars.fraction = 1 SPLSelector.select(globalSPLVars, w, params) wOptstateBundle = SSVM.cuttingPlaneOptimize(w, params, iter) return wOptstateBundle
def optimize(w, params, spl_params): if spl_params.spl_mode == 0: w = SSVM.cuttingPlaneOptimize(w, params, spl_params) elif spl_params.spl_mode == 1: assert(0) #TODO: actually do stuff elif spl_params.spl_mode == 2: assert(0) #TODO: actually do stuff else: assert(0) #TODO: actually do stuff return w
def checkConvergence(w, globalSPLVars, params, curBestObj, wBest,iter): if (params.splParams.splMode!='CCCP') and globalSPLVars.fraction < .9999: #NOT INCLUDING EVERYTHING, IGNORE RESULTS return ( False, numpy.inf, w) obj,margin,constraint,mostViolatedLatents= SSVM.computeObjective(w, params) if obj < curBestObj: wBest = w return (obj >= (curBestObj - params.maxDualityGap), min([obj, curBestObj]), wBest,obj)
def run( self ): try: while 1: (blob, mapper, reducer) = self.input_queue.get() if mapper == HImputation.imputeSingle: env,task = SSVM.initializeMosek(self.examples[0].params) blob.env = env blob.task = task mapped = [mapper(blob,example) for example in self.examples] if reducer is not None: A = reduce(reducer,mapped) self.output_queue.put(A) else: self.output_queue.put(mapped) except Exception, e: logging.debug('worker died') import traceback traceback.print_exc(file=sys.stderr) sys.stderr.flush()
def reoptimizeW(optState,example): assert(example.params.splParams.splMode == 'CCCP') marginsNew = [] margins = optState.margins FNewtranspose = numpy.asmatrix(numpy.zeros(optState.F.T.shape)) Ftranspose = optState.F.T latents = optState.latents for iteration in range(len(margins)): ybar, hbar = latents[iteration][example.id] contributedMargin = CommonApp.delta(ybar, example.trueY) contributedConstraintGiven = CommonApp.padCanonicalPsi(example.psis()[example.h,:].T, example.trueY, example.params) contributedConstraintHBar = CommonApp.padCanonicalPsi(example.psis()[hbar,:].T, ybar, example.params) FNewtranspose[iteration,:] = (Ftranspose[iteration,:] - (contributedConstraintGiven - contributedConstraintHBar).T) marginsNew.append(margins[iteration]-contributedMargin) FNew = FNewtranspose.T FTF = FNew.T*FNew wNew, objective, gap = SSVM.solveDualQPV2(FTF, FNew,marginsNew,example.params, optState.env,optState.task) return wNew