def OnOpenInput(self, event): ie = InputEditor(self, self.realTimeVars) ie.editor.loadInput() ie.Show()
def OnOpenCommand(self, event): ie = InputEditor(self, self.realTimeVars, filename='command1') ie.editor.loadInput() ie.Show()
histories['soln'] = [] histories['vars'] = varDict.keys() while not sampler.converged and total_runs < 20: total_runs += 1 print 'run:', total_runs runDict = sampler.giveSample() histories['nRun'].append(total_runs) for key in runDict.keys(): try: histories[key].append(runDict[key]) except IndexError: histories[key] = [runDict[key]] histories['varVals'].append(runDict['varVals']) #get input file name, write input file inp_file = ie.writeInput(templateFile, runDict['varVals'], total_runs) #run file os.system('./TwoDProblem -i ' + inp_file + ' > /dev/null') os.system('rm ' + inp_file) histories['soln'].append(ie.storeOutput()) #build backend backendTypes = input_file('Backend/active', '').split(' ') for beType in backendTypes: if beType in ['plot2D']: backend = be.Plotter2D() cprvarsX = input_file('Output/Plot2D/xvars', '').split(' ') cprvarsY = input_file('Output/Plot2D/yvars', '').split(' ') for i in range(len(xvars)): backend.compareVars(cprvarsX[i], cprvarsY[i], histories)
def createROMs(self): print '' print 'Beginning HDMR term calculations...' self.ROMs = {} ie = InputEditor.HDMR_IO() #reference run chlist, ident = self.makeCase({}) runfile = ie.writeInput(self.unc_inp_file, chlist, ident) inp_file = GetPot(Filename=runfile) ex = Executor.ExecutorFactory('SC', {}, inp_file) ex.run(verbose=False) os.system('rm ' + runfile) self.ROMs[ident] = ex.ROM # rest of runs numruns = {} for i in range(1, self.hdmr_level + 1): nr = 0 print '\n====================================' print ' STARTING %i-INPUT INTERACTIONS' % i print '====================================\n' new = self.createROMLevel(i, ie) for key, value in new.iteritems(): nr += 1 self.ROMs[key] = value print '\nnumber of order %i runs: %i' % (i, nr) numruns[i] = nr xs = {} for key, value in self.varDict.iteritems(): xs[key] = 1 #for key,value in self.ROMs.iteritems(): # print 'mean',key,':',value.moment(1) print '\nROMs per level:' for key, value in numruns.iteritems(): print ' ', key, value #for rom in self.ROMs.values(): # pk.dump(rom.serializable(),file('hdmr_'+rom.case()+'.pk','w')) self.HDMR_ROM = ROM.HDMR_ROM(self.ROMs, self.varDict) print 'Total Det. Runs:', self.HDMR_ROM.numRunsToCreate() print 'HDMR sampled', self.HDMR_ROM.sample(xs, self.hdmr_level)[1] #store output case = 'hdmr' case += '_' + self.input_file('Sampler/SC/indexSet', '') case += '_N' + str(len(self.varDict)) case += '_H' + str(self.hdmr_level) #case+= '_L'+self.input_file('Sampler/SC/expOrd','') mean = self.HDMR_ROM.moment(self.hdmr_level, r=1, verbose=False) if self.input_file('HDMR/anova', 0) > 0: secm, contribs = self.HDMR_ROM.moment(self.hdmr_level, r=2, anova=True) anovaFileName = case + '.anova' anovaFile = file(anovaFileName, 'w') anovaFile.writelines('Variables,Contribution,Percent\n') for i, j in contribs.iteritems(): name = '-'.join(i.split('_')[1:]) value = str(j**2 / secm) anovaFile.writelines(name + ',' + str(j**2) + ',' + value + '\n') anovaFile.close() print 'ANOVA analysis written to', anovaFileName else: secm = self.HDMR_ROM.moment(self.hdmr_level, r=2, verbose=False) outFile = file(case + '.out', 'a') outFile.writelines('\nRuns,SC Level,Mean\n') outFile.writelines(str(self.HDMR_ROM.numRunsToCreate()) + ',') outFile.writelines(self.input_file('Sampler/SC/expOrd', '') + ',') outFile.writelines('%1.15e,%1.15e \n' % (mean, secm - mean * mean)) outFile.close()
def OnOpenInput(self, event): ie = InputEditor(self) ie.editor.loadInput() ie.Show()
for a, arg in enumerate(args): args[a] = float(arg) varDict[var] = Variable(var, path) varDict[var].setDist(dist, args) converged = False runDict = {} datapts = [] totruns = 0 curTime = time.time() x = [] y = [] print 'Running', totalSamples, 'histories...' #sample extremum first runFileName, cx, cy, kx, ky = ie.writeInput(templateFile, runDict, totruns) runDict[varDict[varDict.keys()[1]].path] = varDict[varDict.keys() [0]].sampleLow() runDict[varDict[varDict.keys()[0]].path] = varDict[varDict.keys() [0]].sampleLow() while not converged: # build sample values #if totruns < 4: #do an extreme case # if totruns == 0: #low,low # runDict[varDict[varDict.keys()[0]].path]=varDict[varDict.keys()[0]].sampleLow() # runDict[varDict[varDict.keys()[1]].path]=varDict[varDict.keys()[1]].sampleLow() # elif totruns == 1: # runDict[varDict[varDict.keys()[0]].path]=varDict[varDict.keys()[0]].sampleHi() # runDict[varDict[varDict.keys()[1]].path]=varDict[varDict.keys()[1]].sampleLow()
for a,arg in enumerate(args): args[a]=float(arg) varDict[var]=Variable(var,path) varDict[var].setDist(dist,args) converged = False runDict={} datapts=[] totruns=0 curTime=time.time() x=[] y=[] print 'Running',totalSamples,'histories...' #sample extremum first runFileName,cx,cy,kx,ky = ie.writeInput(templateFile,runDict,totruns) runDict[varDict[varDict.keys()[1]].path]=varDict[varDict.keys()[0]].sampleLow() runDict[varDict[varDict.keys()[0]].path]=varDict[varDict.keys()[0]].sampleLow() while not converged: # build sample values #if totruns < 4: #do an extreme case # if totruns == 0: #low,low # runDict[varDict[varDict.keys()[0]].path]=varDict[varDict.keys()[0]].sampleLow() # runDict[varDict[varDict.keys()[1]].path]=varDict[varDict.keys()[1]].sampleLow() # elif totruns == 1: # runDict[varDict[varDict.keys()[0]].path]=varDict[varDict.keys()[0]].sampleHi() # runDict[varDict[varDict.keys()[1]].path]=varDict[varDict.keys()[1]].sampleLow() # elif totruns == 2: # runDict[varDict[varDict.keys()[0]].path]=varDict[varDict.keys()[0]].sampleLow()