def learnData(self, *args, **kws): # learn data for dtype, values in self.dataContainer.items(): knowledge = {} print KnowledgeTypes.toString(dtype) # do the learning for t, dataContainer in values.items(): print "t = %g, " % t, if dataContainer is not None: learner = self._learners[t] # learn data, if there is any available learner.grid = self.getGrid() learner.dataContainer = dataContainer alpha = learner.learnData() # prepare the answer knowledge[t] = copyGrid(learner.grid), DataVector(alpha) print # update results if len(knowledge) > 0: self.updateResults(knowledge, dtype)
def getAlphasByQoI(self, qoi='_', dtype=KnowledgeTypes.SIMPLE, iteration=None): """ Get all coefficient vectors for the given quantity of interest @param qoi: string quantity of interest @param iteration: int, iteration number """ if iteration is None: iteration = self.__iteration if qoi in self.__alphas[iteration] and \ dtype in self.__alphas[iteration][qoi]: return self.__alphas[iteration][qoi][dtype] else: raise AttributeError('no knowledge for (i=%i, qoi=%s, \ dtype=%i)' % (iteration, qoi, KnowledgeTypes.toString(dtype)))
def getAlphasByQoI(self, qoi='_', dtype=KnowledgeTypes.SIMPLE, iteration=None): """ Get all coefficient vectors for the given quantity of interest @param qoi: string quantity of interest @param iteration: int, iteration number """ if iteration is None: iteration = self.__iteration if qoi in self.__alphas[iteration] and \ dtype in self.__alphas[iteration][qoi]: return self.__alphas[iteration][qoi][dtype] else: raise AttributeError( 'no knowledge for (i=%i, qoi=%s, dtype=%i)' % (iteration, qoi, KnowledgeTypes.toString(dtype)))
def runASGCAnalysis(self, analysis, label, alabel, blabel): # ---------------------------------------------- # write stats # ---------------------------------------------- pathResults = os.path.join(self.pathResults, alabel, blabel) analysisMC = None if 'ref' in self.uqSettings: res = self.uqSettings['ref'].getResults() analysisMC = MCAnalysis(self.params, res) # print "sobol indices" # analysis.writeSensitivityValues(os.path.join(pathResults, label)) print("surpluses") analysis.writeSurplusesLevelWise(os.path.join(pathResults, label)) print("stats") analysis.writeStats(os.path.join(pathResults, label)) print("moments") analysis.writeMoments(os.path.join(pathResults, label)) print("sampling") analysis.sampleGrids(os.path.join(pathResults, "samples", label)) print("checkpoints") analysis.writeCheckpoints( os.path.join(pathResults, "checkpoints", label)) print("density") kde = analysis.estimateDensity(dtype="kde") sgde = analysis.estimateDensity(dtype="sgde") kdeMC = None if analysisMC is not None: kdeMC = analysisMC.estimateDensity(dtype="kde") fig = plt.figure() plotDensity1d(kde, label="kde") plotDensity1d(sgde, label="sgde") if kdeMC is not None: plotDensity1d(kdeMC, label="kde (ref)") plt.legend() plt.savefig(os.path.join(pathResults, "scc.pdf.png")) plt.close(fig) fig = plt.figure() plotCDF1d(kde, label="kde") plotCDF1d(sgde, label="sgde") if kdeMC is not None: plotCDF1d(kdeMC, label="kde (ref)") plt.legend() plt.savefig(os.path.join(pathResults, "scc.cdf.png")) plt.close(fig) # ---------------------------------------------- # do some plotting # ---------------------------------------------- uqManager = analysis.getUQManager() # scatter plot of surpluses level wise for t in uqManager.getTimeStepsOfInterest(): for dtype in uqManager.getKnowledgeTypes(): surpluses = analysis.computeSurplusesLevelWise(t, dtype) maxLevel = uqManager.getKnowledge().getGrid(uqManager.getQoI())\ .getStorage().getMaxLevel() fig = plotSurplusLevelWise(surpluses, maxLevel) fig.savefig( os.path.join( pathResults, "surpluses.%s.t%g.png" % (KnowledgeTypes.toString(dtype), t)))