Beispiel #1
0
 def createROMLevel(self, lvl, ie):
     ROMs = {}
     runs = self.getRunSet(lvl)
     for run, vrs in runs.iteritems():
         print '\nStarting run:', run
         chlist, ident = self.makeCase(run)
         runfile = ie.writeInput(self.unc_inp_file, chlist, ident)
         inp_file = GetPot(Filename=runfile)
         exdict = {}
         for i in range(len(run)):
             exdict[run[i]] = vrs[i]
         ex = Executor.ExecutorFactory('SC', exdict, inp_file)
         ex.run()
         os.system('rm ' + runfile)
         ROMs[ident] = ex.ROM
     return ROMs
Beispiel #2
0
 def createROMs(self):
     self.ROMs = {}
     ident = self.todo.keys()[0]
     print '\nStarting run:', ident
     inp_file = GetPot(Filename=self.unc_inp_file)
     ex_type = inp_file('Problem/executor', '')
     print 'ex type:', ex_type
     ex = Executor.ExecutorFactory(ex_type, self.varDict, inp_file)
     ex.run(verbose=self.verbose)
     try:
         self.ROMs[ident] = ex.ROM
         print 'sampled mean:', ex.ROM.moment(1)
     except AttributeError:
         pass  #MC doesn't store a rom at this point
     self.ex = ex
     #xs={}
     #for key,value in self.varDict.iteritems():
     #  xs[key]=1
     #print 'sampled:',ex.ROM.sample(xs,verbose=False)
     return ex
Beispiel #3
0
 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()