Skip to content

Commit

Permalink
Merge pull request #181 from AdityaSavara/graphs_subdirectory_export
Browse files Browse the repository at this point in the history
Graphs subdirectory export
  • Loading branch information
AdityaSavara authored Apr 18, 2021
2 parents 4d37d88 + 8495c1d commit 12814b7
Show file tree
Hide file tree
Showing 191 changed files with 511 additions and 409 deletions.
89 changes: 55 additions & 34 deletions CheKiPEUQ/InverseProblem.py

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion CheKiPEUQ/UserInput.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import numpy as np

#####Directory Settings####
directories = {}
directories['graphs'] = "./Graphs/"
#directories['text_and_csv_outputs'] = "/text_and_csv_outputs/" This feature is not implemented yet. In the future, this is where log files, csv files, and the Citations Log will be saved. A complication in implementing this feature is that some features (like continueSampling and parallel processing runs) need to access files in the main directory, so those reading statements will need to be changed to point towards this subdirectory.


#####Experimental Data Input Files#####
responses = {}
responses['responses_abscissa'] = [] #Make 1 or more list or array within a list.
Expand All @@ -25,8 +31,9 @@
model['InputParametersPriorValuesUncertainties'] = []# Should be like: [200, 200, 13, 13, 0.1, 0.1] #If user wants to use a prior with covariance, then this must be a 2D array/ list. To assume no covariance, a 1D
#A value of -1 in the Uncertainties indicates the parameter in question is described a univorm distribution In this case, the InputParameterPriorValues_upperBounds and InputParameterPriorValues_lowerBounds must be defined for each parmeter (can be defined as None for the non-uniform parameters).
model['InputParameterInitialGuess'] = [] #This is optional. An initial guess changes where the search is centered without changing the prior. If no initial guess is proided, the InputParameterPriorValues are taken as an initial guess.
model['parameterNamesAndMathTypeExpressionsDict'] = {} #This must be provided. It can be as simple as {"Param1":"1"} etc. but it must be a dictionary with strings as keys and as values. The next line is a comment with a more complicated example.
model['parameterNamesAndMathTypeExpressionsDict'] = {} #This should be a dictionary with strings as keys and as values, or it can just be a list. If it is not provided, the parmeters will get names like ParInd_0, ParInd_1, etc. The next line is a comment with a more complicated example.
#Example: model['parameterNamesAndMathTypeExpressionsDict'] = {'Ea_1':r'$E_{a1}$','Ea_2':r'$E_{a2}$','log_A1':r'$log(A_{1})$','log_A2':r'$log(A_{2})$','gamma1':r'$\gamma_{1}$','gamma2':r'$\gamma_{2}$'}
#A simpler list example would be ['Ea1', 'Ea2', 'logA1', 'logA2', 'gamma1', 'gamma2'], but then the graphs would have no subscripts.
model['populateIndependentVariablesFunction'] = None #Not normally used. Mainly for design of experiments.
model['simulateByInputParametersOnlyFunction'] = None #A function must be provided! This cannot be left as None. The function should normally return an array the same size and shape as responses_observed, or should return a None object when the simulation fails or the result is considered non-physical. Alternatively, the function can written an object that needs to be processed further by SimulationOutputProcessingFunction.
model['simulationOutputProcessingFunction'] = None #An optional function may be provided which takes the outputs from simulateByInputParametersOnlyFunction and then processes them to match the size, shape, and scale of responses_observed. A None object can be returned when the simulation fails or the result is considered non-physical.
Expand Down
9 changes: 8 additions & 1 deletion CheKiPEUQ/nestedObjectsFunctionsLocal.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,11 @@ def checkIfStaggered_2dNested(arr):
onesArray = np.matmul(arr.transpose(), onesArray) #This is the key line and catches staggered arrays.
return False
except:
return True
return True

#Takes an arrayLike object like [1,2,3,4] and returns a nested version like [[1],[2],[3],[4]]
def convertToNested(inputList):
nestedList = []
for individualItem in inputList:
nestedList.append([individualItem])
return nestedList
20 changes: 10 additions & 10 deletions CheKiPEUQ/plotting_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def seaborn_scatterplot_matrix(self):
def rate_tot_plot(self):
return

def sampledParameterHistogramMaker(parameterSamples, parameterName,parameterNamesAndMathTypeExpressionsDict, sampledParameterFiguresDictionary, sampledParameterAxesDictionary):
def sampledParameterHistogramMaker(parameterSamples, parameterName,parameterNamesAndMathTypeExpressionsDict, sampledParameterFiguresDictionary, sampledParameterAxesDictionary, directory=''):
parameterIndex = list(parameterNamesAndMathTypeExpressionsDict).index(parameterName)
sampledParameterFiguresDictionary[parameterName], sampledParameterAxesDictionary[parameterName] = plt.subplots() #making plt objects
sampledParameterAxesDictionary[parameterName].hist(parameterSamples[:,parameterIndex]) #filling the object with data
Expand All @@ -119,7 +119,7 @@ def sampledParameterHistogramMaker(parameterSamples, parameterName,parameterName
sampledParameterAxesDictionary[parameterName].tick_params(axis='x', labelsize=16) #TODO: make these labels sizes a setting that can be changed.
sampledParameterAxesDictionary[parameterName].tick_params(axis='y', labelsize=16)
sampledParameterFiguresDictionary[parameterName].tight_layout()
sampledParameterFiguresDictionary[parameterName].savefig('Histogram_sampling_'+str(parameterIndex)+'_'+parameterName+'.png', dpi=220)
sampledParameterFiguresDictionary[parameterName].savefig(directory+'Histogram_sampling_'+str(parameterIndex)+'_'+parameterName+'.png', dpi=220)



Expand All @@ -132,14 +132,14 @@ def sampledParameterHistogramMaker(parameterSamples, parameterName,parameterName
# fig2.savefig('Ea2.png', dpi=220)

#Make histograms for each parameter. Need to make some dictionaries where relevant objects will be stored.
def makeHistogramsForEachParameter(parameterSamples,parameterNamesAndMathTypeExpressionsDict):
def makeHistogramsForEachParameter(parameterSamples,parameterNamesAndMathTypeExpressionsDict, directory=''):
sampledParameterFiguresDictionary = copy.deepcopy(parameterNamesAndMathTypeExpressionsDict) #This must be a deep copy to perserve original.
sampledParameterAxesDictionary = copy.deepcopy(parameterNamesAndMathTypeExpressionsDict) #This must be a deep copy to preserve original.
for key in parameterNamesAndMathTypeExpressionsDict:
parameterName = key
sampledParameterHistogramMaker(parameterSamples, parameterName,parameterNamesAndMathTypeExpressionsDict, sampledParameterFiguresDictionary, sampledParameterAxesDictionary)
sampledParameterHistogramMaker(parameterSamples, parameterName,parameterNamesAndMathTypeExpressionsDict, sampledParameterFiguresDictionary, sampledParameterAxesDictionary, directory=directory)

def createSimulatedResponsesPlot(x_values, listOfYArrays, plot_settings={}, listOfYUncertaintiesArrays=[], showFigure=True):
def createSimulatedResponsesPlot(x_values, listOfYArrays, plot_settings={}, listOfYUncertaintiesArrays=[], showFigure=True, directory=''):
exportFigure = True #This variable should be moved to an argument or something in plot_settings.
#First put some defaults in if not already defined.
x_values = np.array(x_values)
Expand Down Expand Up @@ -235,23 +235,23 @@ def createSimulatedResponsesPlot(x_values, listOfYArrays, plot_settings={}, list
ax0.legend(plot_settings['legendLabels']) #legends must be after plots are made.
fig0.tight_layout()
if exportFigure==True:
fig0.savefig(plot_settings['figure_name'] + '.png', dpi=plot_settings['dpi'])
fig0.savefig(directory + plot_settings['figure_name'] + '.png', dpi=plot_settings['dpi'])
if showFigure==False:
plt.close(fig0)
return fig0

def makeTrisurfacePlot(xValues, yValues, zValues, exportFigure = True, figure_name="TrisurfacePlot", showFigure=True):
def makeTrisurfacePlot(xValues, yValues, zValues, exportFigure = True, figure_name="TrisurfacePlot", showFigure=True, directory=''):
from mpl_toolkits.mplot3d import Axes3D #Although it does not look like this is called here, the InfoGain plots will fail without this line.
fig1, ax1 = plt.subplots(1)
ax1 = plt.axes(projection ='3d')
image = ax1.plot_trisurf(xValues,yValues, zValues)
if exportFigure == True:
fig1.savefig(figure_name + '.png')
fig1.savefig(directory + figure_name + '.png')
if showFigure==False:
plt.close(fig1)
return fig1, ax1, image

def makeMeshGridSurfacePlot(XX, YY, ZZ, plot_settings = {}, exportFigure = True, figure_name="MeshGridSurfacePlot", showFigure=True):
def makeMeshGridSurfacePlot(XX, YY, ZZ, plot_settings = {}, exportFigure = True, figure_name="MeshGridSurfacePlot", showFigure=True, directory=''):
#TODO: plot_settings should be used for axis labels etc, like above.
#TODO: create a UserInput variable named info_gain_plot_settings (like what the other cases have).
from mpl_toolkits.mplot3d import Axes3D #I am not sure if this line is needed here, it might b.
Expand All @@ -266,7 +266,7 @@ def makeMeshGridSurfacePlot(XX, YY, ZZ, plot_settings = {}, exportFigure = True
ax1.set_title('Information Gain Surface')
fig1.colorbar(surf, shrink=0.5, aspect=5)
if exportFigure==True:
fig1.savefig(figure_name + '.png')
fig1.savefig(directory + figure_name + '.png')
if showFigure==False:
plt.close(fig1)
return fig1, ax1#, image
Expand Down
Binary file removed Examples/Example00/Histogram_sampling_a.png
Binary file not shown.
Binary file removed Examples/Example00/Histogram_sampling_b.png
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()

CKPQ.save_PE_object(PE_object, "SavingProjectExample")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
2 changes: 1 addition & 1 deletion Examples/Example00/runfile_Example_00b_CPE.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()

#The below lines are written with the intent that this file be run in spyder (one could also convert this file into a jupyter notebook). This file will then create a series of plots with different mcmc threshold filters.
UserInput.parameter_estimation_settings['mcmc_threshold_filter_samples'] = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
# PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
PE_object.createAllPlots() #This function calls each of the below functions so that the user does not have to.
# PE_object.makeHistogramsForEachParameter()
# PE_object.makeSamplingScatterMatrixPlot()
# PE_object.createSimulatedResponsesPlot()
# PE_object.createSimulatedResponsesPlots()
Loading

0 comments on commit 12814b7

Please sign in to comment.