Skip to content

Commit

Permalink
Merge pull request #132 from ou3llnl/master
Browse files Browse the repository at this point in the history
Add ability to adjust UQ envelope
  • Loading branch information
ou3llnl authored Mar 8, 2018
2 parents 31a1ff0 + 394dd57 commit bf1ea34
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
8 changes: 4 additions & 4 deletions foqus_lib/framework/uq/RSAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def checkMARS(data, rsOptions):

@staticmethod
def validateRS(fname, y, rsMethodName, rsOptions=None,
genCodeFile=False, nCV=None, userRegressionFile=None, testfile=None):
genCodeFile=False, nCV=None, userRegressionFile=None, testfile=None, error_tol_percent=10):

# read data
data = LocalExecutionModule.readSampleFromPsuadeFile(fname) # does not assume rstype/order written to data
Expand Down Expand Up @@ -512,12 +512,12 @@ def validateRS(fname, y, rsMethodName, rsOptions=None,
Common.showError(error, out)
return None

RSAnalyzer.plotValidate(data, y, rsMethodName, userMethod, mfile)
RSAnalyzer.plotValidate(data, y, rsMethodName, userMethod, mfile, error_tol_percent)

return (mfile, trainErrors, cvErrors, testErrors)

@staticmethod
def plotValidate(data, y, rsMethodName, userMethod, mfile):
def plotValidate(data, y, rsMethodName, userMethod, mfile, error_tol_percent=10):
outVarNames = data.getOutputNames()
outVarName = outVarNames[y-1]
if userMethod: # ... user regression ...
Expand All @@ -532,7 +532,7 @@ def plotValidate(data, y, rsMethodName, userMethod, mfile):
ptitle = ['Model Error Histogram', 'Actual vs. Predicted Data']
xlabel = ['Model Errors', 'Actual Data for %s' % outVarName]
ylabel = ['Probabilities', 'Predicted Data for %s' % outVarName]
Plotter.plotRSvalidate(dat, ftitle, ptitle, xlabel, ylabel)
Plotter.plotRSvalidate(dat, ftitle, ptitle, xlabel, ylabel, error_tol_percent=error_tol_percent)

return None

Expand Down
10 changes: 6 additions & 4 deletions foqus_lib/framework/uq/RSValidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
class RSValidation(UQRSAnalysis):

def __init__(self, ensemble, output, responseSurface, rsOptions = None,
genCodeFile = False, nCV = 10, userRegressionFile = None, testFile = None):
genCodeFile = False, nCV = 10, userRegressionFile = None, testFile = None,
error_tol_percent=10):
super(RSValidation, self).__init__(ensemble, output, UQAnalysis.RS_VALIDATION,
responseSurface, None, rsOptions,
userRegressionFile, None)
Expand All @@ -18,7 +19,8 @@ def __init__(self, ensemble, output, responseSurface, rsOptions = None,
nCV = 10
self.nCV = nCV
self.testFile = testFile

self.error_tol_percent = error_tol_percent

def saveDict(self):
sd = super(RSValidation, self).saveDict()
sd['genCodeFile'] = self.genCodeFile
Expand All @@ -45,7 +47,7 @@ def analyze(self):

mfile = RSAnalyzer.validateRS(fname, self.outputs[0], self.responseSurface,
self.rsOptions, self.genCodeFile, self.nCV,
self.userRegressionFile, self.testFile)
self.userRegressionFile, self.testFile, self.error_tol_percent)

if mfile is None:
return None
Expand All @@ -63,7 +65,7 @@ def showResults(self):
mfile = 'RSFA_CV_err.m'
self.restoreFromArchive(mfile)

RSAnalyzer.plotValidate(self.ensemble, self.outputs[0], self.responseSurface, userMethod, mfile)
RSAnalyzer.plotValidate(self.ensemble, self.outputs[0], self.responseSurface, userMethod, mfile, error_tol_percent=self.error_tol_percent)

def getAdditionalInfo(self):
info = super(RSValidation, self).getAdditionalInfo()
Expand Down
18 changes: 11 additions & 7 deletions foqus_lib/gui/uq/AnalysisDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ def populateUserRegressionFile(self, regressionFile_edit):

## RS Validate
def rsValidate(self, y, rs, rsOptions, genRSCode, nCV = None, userRegressionFile = None,
testFile = None):
testFile = None, error_tol_percent = 10):
self.freeze()

data = self.data
Expand All @@ -476,7 +476,7 @@ def rsValidate(self, y, rs, rsOptions, genRSCode, nCV = None, userRegressionFile
# validate RS
self.setModal(False)
rsv = RSValidation(data, y, rs, rsOptions=rsOptions, genCodeFile = genRSCode,
nCV = nCV, userRegressionFile = userRegressionFile, testFile = testFile)
nCV = nCV, userRegressionFile = userRegressionFile, testFile = testFile, error_tol_percent=error_tol_percent)
mfile = rsv.analyze()
if mfile is not None:
self.data.addAnalysis(rsv)
Expand Down Expand Up @@ -690,7 +690,7 @@ def handleRSAnalyzeCombo2(self, combo1, combo2, samplePDFChosen = False):
combo2.setEnabled(False)
combo2.show()

def RSAnalyze(self, output_combo, RSAnalyze_combo1, RSAnalyze_combo2, legendre_spin,
def RSAnalyze(self, output_combo, RSAnalyze_combo1, RSAnalyze_combo2, legendre_spin, wizardErrorEnvelope_edit,
userRegressionFile_edit, rs, xprior = None, evars = None,
marsBasis_spin = None, marsDegree_spin = None):

Expand All @@ -705,6 +705,7 @@ def RSAnalyze(self, output_combo, RSAnalyze_combo1, RSAnalyze_combo2, legendre_s
method = RSAnalyze_combo1.currentText()
self.setModal(False)

error_tol_percent = wizardErrorEnvelope_edit.value()
rsOptions = None
if rs == ResponseSurfaces.getPsuadeName(ResponseSurfaces.LEGENDRE):
rsOptions = legendre_spin.value()
Expand Down Expand Up @@ -1057,8 +1058,8 @@ def wizardRSValidate(self):
rsOptions = None
if rs == ResponseSurfaces.getPsuadeName(ResponseSurfaces.LEGENDRE):
rsOptions = self.wizardRSLegendre_spin.value()

result = self.rsValidate(y, rs, rsOptions, False, userRegressionFile = self.wizardUserRegressionFile_edit.text())
result = self.rsValidate(y, rs, rsOptions, False, userRegressionFile = self.wizardUserRegressionFile_edit.text(), error_tol_percent = self.wizardErrorEnvelope_edit.value())
self.unfreeze()
self.activateWizardRSAnalysis()

Expand All @@ -1067,6 +1068,7 @@ def wizardRSValidate(self):
self.RS_combo1.setCurrentIndex(self.wizardRS_combo1.currentIndex())
self.RS_combo2.setCurrentIndex(self.wizardRS_combo2.currentIndex())
self.RSLegendre_spin.setValue(self.wizardRSLegendre_spin.value())
self.doubleSpinBox.setValue(self.wizardErrorEnvelope_edit.value())
self.expertUserRegressionFile_edit.setText(self.wizardUserRegressionFile_edit.text())
self.activateExpertRSAnalysis()

Expand Down Expand Up @@ -1111,7 +1113,7 @@ def wizardAnalyze(self):

self.RSAnalyze(self.wizardAnalysisOutput_combo, self.wizardAnalyze_combo1,
self.wizardAnalyze_combo2, self.wizardRSLegendre_spin,
self.wizardUserRegressionFile_edit, rs)
self.wizardUserRegressionFile_edit, rs, self.wizardErrorEnvelope_edit)

# Show plot help text
analysisType = self.wizardAnalyze_combo1.currentText()
Expand Down Expand Up @@ -1560,6 +1562,7 @@ def expertRSValidate(self):
# get RS
rs = self.getExpertRS()
rsOptions = None
error_tol_percent = self.doubleSpinBox.value()
if rs == ResponseSurfaces.getPsuadeName(ResponseSurfaces.LEGENDRE):
rsOptions = self.RSLegendre_spin.value()
elif rs.startswith('MARS'):
Expand All @@ -1573,7 +1576,7 @@ def expertRSValidate(self):
testFile = self.testSet_edit.text()

genRSCode = True
self.rsValidate(y, rs, rsOptions, genRSCode, nCV, self.expertUserRegressionFile_edit.text(), testFile)
self.rsValidate(y, rs, rsOptions, genRSCode, nCV, self.expertUserRegressionFile_edit.text(), testFile, error_tol_percent)

rs = self.RS_combo2.currentText()
if rs != ResponseSurfaces.getFullName(ResponseSurfaces.MARSBAG):
Expand All @@ -1592,6 +1595,7 @@ def expertRSValidate(self):
self.wizardRS_combo2.setCurrentIndex(self.RS_combo2.currentIndex())
self.wizardRSLegendre_spin.setValue(self.RSLegendre_spin.value())
self.wizardUserRegressionFile_edit.setText(self.expertUserRegressionFile_edit.text())
self.wizardErrorEnvelope_edit.setValue(self.doubleSpinBox.value())
self.activateWizardRSAnalysis()

self.unfreeze()
Expand Down
2 changes: 1 addition & 1 deletion foqus_lib/gui/uq/SimSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from PyQt5 import uic
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QFileDialog, QListWidgetItem, \
QAbstractItemView, QDialogButtonBox, QStackedLayout, QComboBox, QApplication
QAbstractItemView, QDialogButtonBox, QStackedLayout, QComboBox, QApplication, QMessageBox
from PyQt5.QtGui import QCursor
mypath = os.path.dirname(__file__)
_SimSetupUI, _SimSetup = \
Expand Down

0 comments on commit bf1ea34

Please sign in to comment.