def plotSTi(self, width=0.5, addval=True, sortit=True, *args, **kwargs): ''' Plot a barchart of the given STi Parameters ----------- width : float (0-1) width of the bars in the barchart addval : bool if True, the morris mu values are added to the graph sortit : bool if True, larger values (in absolute value) are plotted closest to the y-axis *args, **kwargs : args passed to the matplotlib.bar ''' if self.repl > 1: print 'Table generates only output of first line!' fig = plt.figure() ax1 = fig.add_subplot(111) ax1 = plotbar(ax1, self.STi[0], self._namelist, width=width, addval=addval, sortit=True, *args, **kwargs) ax1.set_ylabel(r'$S_Ti$', fontsize=20) ax1.yaxis.label.set_rotation('horizontal') ax1.yaxis.set_label_coords(-0.02, 1.) plt.draw() return fig, ax1
def plotSTi(self, width = 0.5, addval = True, sortit = True, *args, **kwargs): ''' Plot a barchart of the given STi Parameters ----------- width : float (0-1) width of the bars in the barchart addval : bool if True, the morris mu values are added to the graph sortit : bool if True, larger values (in absolute value) are plotted closest to the y-axis *args, **kwargs : args passed to the matplotlib.bar ''' if self.repl > 1: print 'Table generates only output of first line!' fig = plt.figure() ax1 = fig.add_subplot(111) ax1 = plotbar(ax1, self.STi[0], self._namelist, width = width, addval = addval, sortit = True, *args, **kwargs) ax1.set_ylabel(r'$S_Ti$',fontsize=20) ax1.yaxis.label.set_rotation('horizontal') ax1.yaxis.set_label_coords(-0.02, 1.) plt.draw() return fig, ax1
def plotsens(self, indice='PE', width = 0.5, addval = True, sortit = True, outputid = 0, *args, **kwargs): ''' Plot a barchart of either CAS, CTRS or PE based Senstivitity Parameters ----------- indice: PE, CAS or CTRS choose which indice you want to show width : float (0-1) width of the bars in the barchart addval : bool if True, the sensitivity values are added to the graph sortit : bool if True, larger values (in absolute value) are plotted closest to the y-axis outputid : int the output to use whe multiple are compared; starts with 0 *args, **kwargs : args passed to the matplotlib.bar Returns ---------- fig : matplotlib.figure.Figure object figure containing the output ax1 : axes.AxesSubplot object the subplot ''' if indice == 'PE': indtoplot = self.PE_SENS[:,outputid] elif indice == 'CAS': indtoplot = self.CAS_SENS[:,outputid] elif indice == 'CTRS': indtoplot = self.CTRS_SENS[:,outputid] else: raise Exception('Choose either PE, CAS or CTRS') fig = plt.figure() ax1 = fig.add_subplot(111) ax1 = plotbar(ax1, indtoplot, self._namelist, width = width, addval = addval, sortit = True, *args, **kwargs) ax1.set_ylabel(indice,fontsize=20) ax1.yaxis.label.set_rotation('horizontal') ax1.yaxis.set_label_coords(-0.02, 1.) plt.draw() return fig, ax1
def plotmustar(self, width = 0.5, addval = True, sortit = True, outputid = 0, *args, **kwargs): ''' Plot a barchart of the given mustar mu* is a measure for the first-order effect on the model output. By taking the average of the absolute values of the parameter distribution, the absolute effect on the output can be calculated. This is very useful when you are working with non-monotonic functions. The drawback is that you lose information about the direction of influence (is this factor influencing the output in a positive or negative way?). For the direction of influence use plotmustar! Parameters ----------- width : float (0-1) width of the bars in the barchart addval : bool if True, the morris values are added to the graph sortit : bool if True, larger values (in absolute value) are plotted closest to the y-axis outputid : int the output to use whe multiple are compared; starts with 0 *args, **kwargs : args passed to the matplotlib.bar; width is already used Returns ---------- fig: matplotlib.figure.Figure object figure containing the output ax1: axes.AxesSubplot object the subplot ''' fig = plt.figure() ax1 = fig.add_subplot(111) ax1 = plotbar(ax1, self.mustar[outputid*self._ndim:(outputid+1)*self._ndim], self._namelist, width = width, addval = addval, sortit = True, *args, **kwargs) ax1.set_ylabel(r'$\mu*$',fontsize=20) ax1.yaxis.label.set_rotation('horizontal') ax1.yaxis.set_label_coords(-0.02, 1.) plt.draw() return fig, ax1
def plotmu(self, width = 0.5, addval = True, sortit = True, outputid = 0, *args, **kwargs): ''' Plot a barchart of the given mu mu is a measure for the first-order effect on the model output. However the use of mu can be tricky because if the model is non-monotonic negative elements can be in the parameter distribution and by taking the mean of the variance (= mu!) the netto effect is cancelled out! Should always be used together with plotsigma in order to see whether higher order effects are occuring, high sigma values with low mu values can be caused by non-monotonicity of functions. In order to check this use plotmustar and/or plotmustarsigma Parameters ----------- width : float (0-1) width of the bars in the barchart addval : bool if True, the morris mu values are added to the graph sortit : bool if True, larger values (in absolute value) are plotted closest to the y-axis outputid : int the output to use whe multiple are compared; starts with 0 *args, **kwargs : args passed to the matplotlib.bar Returns ---------- fig : matplotlib.figure.Figure object figure containing the output ax1 : axes.AxesSubplot object the subplot ''' fig = plt.figure() ax1 = fig.add_subplot(111) ax1 = plotbar(ax1, self.mu[outputid*self._ndim:(outputid+1)*self._ndim], self._namelist, width = width, addval = addval, sortit = True, *args, **kwargs) ax1.set_ylabel(r'$\mu$',fontsize=20) ax1.yaxis.label.set_rotation('horizontal') ax1.yaxis.set_label_coords(-0.02, 1.) plt.draw() return fig, ax1
def plotsens(self, indice="PE", width=0.5, addval=True, sortit=True, outputid=0, *args, **kwargs): """ Plot a barchart of either CAS, CTRS or PE based Senstivitity Parameters ----------- indice: PE, CAS or CTRS choose which indice you want to show width : float (0-1) width of the bars in the barchart addval : bool if True, the sensitivity values are added to the graph sortit : bool if True, larger values (in absolute value) are plotted closest to the y-axis outputid : int the output to use whe multiple are compared; starts with 0 *args, **kwargs : args passed to the matplotlib.bar Returns ---------- fig : matplotlib.figure.Figure object figure containing the output ax1 : axes.AxesSubplot object the subplot """ if indice == "PE": indtoplot = self.PE_SENS[:, outputid] elif indice == "CAS": indtoplot = self.CAS_SENS[:, outputid] elif indice == "CTRS": indtoplot = self.CTRS_SENS[:, outputid] else: raise Exception("Choose either PE, CAS or CTRS") fig = plt.figure() ax1 = fig.add_subplot(111) ax1 = plotbar(ax1, indtoplot, self._namelist, width=width, addval=addval, sortit=True, *args, **kwargs) ax1.set_ylabel(indice, fontsize=20) ax1.yaxis.label.set_rotation("horizontal") ax1.yaxis.set_label_coords(-0.02, 1.0) plt.draw() return fig, ax1
def plotsigma(self, width = 0.5, addval = True, sortit = True, outputid = 0, *args, **kwargs): ''' Plot a barchart of the given sigma sigma is a measure for the higher order effects (e.g. curvatures and interactions). High sigma values typically occurs when for example parameters are correlated, the model is non linear,... The sum of all these effects is sigma. For linear models without any correlation sigma should be approximately zero. Parameters ----------- width : float (0-1) width of the bars in the barchart addval : bool if True, the morris values are added to the graph sortit : bool if True, larger values (in absolute value) are plotted closest to the y-axis outputid : int the output to use whe multiple are compared; starts with 0 *args, **kwargs : args passed to the matplotlib.bar Returns ---------- fig : matplotlib.figure.Figure object figure containing the output ax1 : axes.AxesSubplot object the subplot ''' fig = plt.figure() ax1 = fig.add_subplot(111) ax1 = plotbar(ax1, self.sigma[outputid*self._ndim:(outputid+1)*self._ndim], self._namelist, width = width, addval = addval, sortit = True, *args, **kwargs) ax1.set_ylabel(r'$\sigma$',fontsize=20) ax1.yaxis.label.set_rotation('horizontal') ax1.yaxis.set_label_coords(-0.02, 1.) plt.draw() return fig, ax1
def runTestModel(self, ai): ''' Run a testmodel Use a testmodel to get familiar with the method and try things out. The implemented model is the G Sobol function: testfunction with analytical solution, moire information, see [M3]_ Parameters ----------- ai : list list with the input factors (equal size as number of factors) Examples --------- >>> ai=[78, 12, 0.5, 2, 97, 33] >>> Xi = [(0.0,1.0,r'$X_1$'),(0.0,1.0,r'$X_2$'),(0.0,1.0,r'$X_3$'), (0.0,1.0,r'$X_4$'),(0.0,1.0,r'$X_5$'),(0.0,1.0,r'$X_6$')] >>> #set up the morris screening class >>> sm = MorrisScreening(Xi,ModelType = 'testmodel') >>> #Get an optimized set of trajectories >>> OptMatrix, OptOutVec = sm.Optimized_Groups(nbaseruns=100, intervals = 4, noptimized=4, Delta = 0.4) >>> #compare the selected trajects with the general >>> sm.Optimized_diagnostic(width=0.15) >>> #run a testmodel and get the outputs >>> sm.runTestModel(ai) ''' output = np.zeros((sm.OptOutMatrix.shape[0],1)) for i in range(sm.OptOutMatrix.shape[0]): output[i,:] = analgfunc(ai,sm.OptOutMatrix[i,:]) SAmeas_out, OutMatrix = self.Morris_Measure_Groups(output) print 'Higher values of ai correspond to lower importance of Xi \n' #Analytical to compare -> G Vi = np.zeros(len(ai)) for i in range(len(ai)): Vi[i] = (1./3.)/(1.+ai[i])**2 VTi = np.zeros(len(ai)) for i in range(len(ai)): Vj = np.prod(np.delete(Vi,i)+1.) VTi[i] = Vi[i] * Vj Vtot = 1. for i in range(len(ai)): Vtot = Vtot * (1+Vi[i]) Vtot = Vtot -1. print 'Morris gives only qualitive measures of importance, \n' print 'a correspondance between STi and mustar is expected \n' print 'and compared here \n' print ' \n' print 'Analytical Solution for STi: \n' print VTi/Vtot print 'The Morris mu* results: \n' print self.mustar print 'A barplot is generated...' fig, ax1 = self.plotmustar(width=0.15, ec='grey',fc='grey') ax1.set_title('Morris screening result') fig2 = plt.figure() ax2 = fig2.add_subplot(111) ax2 = plotbar(ax2, VTi/Vtot, self._namelist, width = 0.15, addval = True, sortit = True, ec='grey',fc='grey') ax2.set_title('Analytical result')
def plot_SRC(self, width = 0.2, addval = True, sortit = True, outputid = 'all', ncols = 3, outputnames=[], *args, **kwargs): ''' Plot a barchart of the SRC values; actually a Tornadoplot in the horizontal direction. More in the style of the other methods. TODO: make for subset of outputs, also in other methods; currently all or 1 Parameters ----------- width : float (0-1) width of the bars in the barchart addval : bool if True, the sensitivity values are added to the graph sortit : bool if True, larger values (in absolute value) are plotted closest to the y-axis outputid : int or all the output to use whe multiple are compared; starts with 0 if all, the different outputs are plotted in subplots ncols : int number of columns to put the subplots in outputnames : list of strings [] to plot no outputnames, otherwise list of strings equal to the number of outputs *args, **kwargs : args passed to the matplotlib.bar Returns ---------- fig : matplotlib.figure.Figure object figure containing the output ax1 : axes.AxesSubplot object the subplot Examples --------- >>> #plot single SRC >>> reg.plot_SRC(outputid=0, width=0.3, sortit = True, ec='grey',fc='grey') >>> #plot single SRC (assume 4 outputs) >>> reg.plot_SRC(outputid = 'all' , ncols = 2, outputnames=['o1','o2','o3','o4'], ec='grey', fc='grey') ''' if outputid == 'all': #define number of rows numsrc = self.SRC.shape[1] nrows = np.divide(numsrc,ncols) if np.remainder(numsrc,ncols)>0: nrows+=1 #prepare plots fig, axes = plt.subplots(nrows = nrows, ncols = ncols, figsize=(40,40), facecolor = 'white') fig.subplots_adjust(hspace=0.25, wspace=0.2) i=0 for ax in axes.flat: if i<numsrc: ax = plotbar(ax, self.SRC[:,i], self._namelist, width = width, addval = addval, sortit = True, *args, **kwargs) ax.set_ylabel('SRC',fontsize=15) ax.yaxis.label.set_rotation('horizontal') ax.yaxis.set_label_coords(-0.02, 1.) if outputnames: ax.set_title(outputnames[i]) else: ax.set_axis_off() i+=1 else: print 'SRC values of output ',outputid,' is shown in graph' fig = plt.figure() ax1 = fig.add_subplot(111) ax1 = plotbar(ax1, self.SRC[:,outputid], self._namelist, width = width, addval = addval, sortit = True, *args, **kwargs) ax1.set_ylabel('SRC',fontsize=20) ax1.yaxis.label.set_rotation('horizontal') ax1.yaxis.set_label_coords(-0.02, 1.) plt.draw() return fig, ax1
def plot_SRC(self, width=0.2, addval=True, sortit=True, outputid='all', ncols=3, outputnames=[], *args, **kwargs): ''' Plot a barchart of the SRC values; actually a Tornadoplot in the horizontal direction. More in the style of the other methods. TODO: make for subset of outputs, also in other methods; currently all or 1 Parameters ----------- width : float (0-1) width of the bars in the barchart addval : bool if True, the sensitivity values are added to the graph sortit : bool if True, larger values (in absolute value) are plotted closest to the y-axis outputid : int or all the output to use whe multiple are compared; starts with 0 if all, the different outputs are plotted in subplots ncols : int number of columns to put the subplots in outputnames : list of strings [] to plot no outputnames, otherwise list of strings equal to the number of outputs *args, **kwargs : args passed to the matplotlib.bar Returns ---------- fig : matplotlib.figure.Figure object figure containing the output ax1 : axes.AxesSubplot object the subplot Examples --------- >>> #plot single SRC >>> reg.plot_SRC(outputid=0, width=0.3, sortit = True, ec='grey',fc='grey') >>> #plot single SRC (assume 4 outputs) >>> reg.plot_SRC(outputid = 'all' , ncols = 2, outputnames=['o1','o2','o3','o4'], ec='grey', fc='grey') ''' if outputid == 'all': #define number of rows numsrc = self.SRC.shape[1] nrows = np.divide(numsrc, ncols) if np.remainder(numsrc, ncols) > 0: nrows += 1 #prepare plots fig, axes = plt.subplots(nrows=nrows, ncols=ncols, figsize=(40, 40), facecolor='white') fig.subplots_adjust(hspace=0.25, wspace=0.2) i = 0 for ax in axes.flat: if i < numsrc: ax = plotbar(ax, self.SRC[:, i], self._namelist, width=width, addval=addval, sortit=True, *args, **kwargs) ax.set_ylabel('SRC', fontsize=15) ax.yaxis.label.set_rotation('horizontal') ax.yaxis.set_label_coords(-0.02, 1.) if outputnames: ax.set_title(outputnames[i]) else: ax.set_axis_off() i += 1 else: print 'SRC values of output ', outputid, ' is shown in graph' fig = plt.figure() ax1 = fig.add_subplot(111) ax1 = plotbar(ax1, self.SRC[:, outputid], self._namelist, width=width, addval=addval, sortit=True, *args, **kwargs) ax1.set_ylabel('SRC', fontsize=20) ax1.yaxis.label.set_rotation('horizontal') ax1.yaxis.set_label_coords(-0.02, 1.) plt.draw() return fig, ax1