def main(): try: params = UserInput.getUserInput('test') ExampleLoader.loadExamples(params) w = CacheObj.loadObject(params.modelFile) Performance.writePerformance(params, w, params.resultFile) Performance.printStrongAndWeakTrainError(params, w) utils.dumpCurrentLatentVariables(params, params.latentVariableFile) except Exception, e : import traceback traceback.print_exc(file=sys.stdout)
def optimize(w, globalSPLVars, params): bestObj = numpy.inf wBest= CommonApp.PsiObject(params,False) initLatentVariables(w, params) utils.dumpCurrentLatentVariables(params, "%s.%s"%(params.latentVariableFile, 'init')) iter = 0 while True: logging.debug("SSVM iteration %d" % (iter)) w,optState = SPLInnerLoop.optimize(w, globalSPLVars, params, iter) (converged, bestObj, wBest,newObj) = checkConvergence(w, globalSPLVars, params, bestObj, w,iter) logging.debug("Objective after optimizing w: %f" % newObj) lastedLongEnough= (iter > params.minOuterIters) and ((params.splParams.splMode=='CCCP' ) or (params.splParams.splMode!='CCCP' and iter > params.splParams.splInitIters and globalSPLVars.fraction >= 1.0)) logging.debug("Breaking because of convergence") if (converged and lastedLongEnough): logging.debug("Breaking because of convergence") break elif iter>params.maxOuterIters: logging.debug("Breaking because its been 10 iterations") break elif params.supervised: logging.debug("Only one run because we are in supervised mode") break HImputation.impute(optState, params) (converged, bestObj, wBest,newObj) = checkConvergence(w, globalSPLVars, params, bestObj, w,iter) logging.debug("Objective after updating latents: %f" % newObj) logging.debug("Objective (best so far) %f" % bestObj) CacheObj.cacheObject(params.modelFile + "."+str(iter), w) utils.dumpCurrentLatentVariables(params, "%s.%d"%(params.latentVariableFile, iter)) iter += 1 utils.dumpCurrentLatentVariables(params, params.latentVariableFile) logging.debug("Best objective attained is %f" % bestObj) return wBest
def main(): try: params = UserInput.getUserInput('train') ExampleLoader.loadExamples(params) CommonApp.setExampleCosts(params) w = None if params.initialModelFile: w = CacheObj.loadObject(params.initialModelFile) else: w = CommonApp.PsiObject(params,False) globalSPLVars = SPLSelector.SPLVar() if params.splParams.splMode != 'CCCP': SPLSelector.setupSPL(params) w = LSSVM.optimize(w, globalSPLVars, params) CacheObj.cacheObject(params.modelFile,w) Performance.printStrongAndWeakTrainError(params, w) except Exception, e : import traceback traceback.print_exc(file=sys.stdout)