forked from esiwgnahz/DGSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1046469
commit 8779fe8
Showing
69 changed files
with
85,492 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
|
||
% | ||
% Distance-based generalized sensitivity analysis (dGSA) | ||
% Evaluation of sensitivity of the conditioanl effects | ||
|
||
% Author: Celine Scheidt | ||
% Date: August 2013 | ||
|
||
% Updated by Jihoon Park (jhpark3@stanford.edu) | ||
% Date: 14 May 2016 | ||
% - Use data structures | ||
% - Separate computations and visualizations | ||
% - Display the conditioning parameter computed | ||
|
||
function DGSA_ConditionalEffects = ... | ||
ComputeConditionalEffects(DGSA,alpha)%(Clustering,ParametersValues,ParametersNames,NbBins,alpha) | ||
|
||
|
||
%% Input Parameters | ||
|
||
% DGSA: (Stucture) Previous results of DGSA. | ||
% | ||
% .Clustering: (Structure) Results of clustering | ||
% .ParametersValues: (matrix, # of models x # of parameters) contains values of each parameter from Monte Carlo sampling. | ||
% .ConditionalEffects.NbBins: (vector, length=# of parameters) specifies each number of bins of parameters to compute conditional effects | ||
% .ParametersNames: (cell, 1 x # of parameters) contains the names of parameters | ||
% | ||
% alpha: (optional) alpha-percentile (by default, alpha = 0.95) for bootstrap percentile | ||
|
||
%% Output Parameters | ||
% | ||
% DGSA_ConditionalEffects: (Structure) Results of DGSA after computing conditional effects. | ||
% .ConditionalEffects.SensitivityByClusterandBins: | ||
% (4D array, (# of parameters) x (# of parameters-1) x (# of clusters) x (maximum value of bins)) | ||
% Element (i,j,c,l) corresponds to conditional effect of i-th parameter conditioned to l-th bin of j-th parameter from class c. | ||
% | ||
% .ConditionalEffects.StandardizedSensitivity: (vector, length=(# of parameters) x (# of parameters -1)) | ||
% Conditional effects averaged over bins and classes | ||
% | ||
% .ConditionalEffects.H0accConditional (logical vector, length=(# of parameters) x (# of parameters -1)) | ||
% Results of bootstrap hypothesis testing. If the value is 1, corresponding conditional effect is sensitive. | ||
% | ||
% .ConditionalEffects.Names_ConditionalEffects: (cell, length=(# of parameters) x (# of parameters -1)) | ||
% contains names of conditional effects | ||
|
||
%% Assign varaibles. | ||
DGSA_ConditionalEffects=DGSA; | ||
|
||
Clustering=DGSA.Clustering; | ||
ParametersValues=DGSA.ParametersValues; | ||
NbBins=DGSA.ConditionalEffects.NbBins; | ||
ParametersNames=DGSA.ParametersNames; | ||
|
||
|
||
%% Computations of conditional effects. | ||
|
||
NbParams = size(ParametersValues,2); | ||
NbClusters = size(Clustering.medoids,2); | ||
|
||
if nargin < 2; alpha = .95; end | ||
|
||
% Evaluate the normalized conditionnal interaction for each parameter, each | ||
% class and each bin | ||
L1Interactions = NaN(NbParams,NbParams-1,NbClusters,max(NbBins)); % array containing all the Interactions | ||
BootInteractions = NaN(NbParams,NbParams-1,NbClusters,max(NbBins)); | ||
|
||
for params = 1:NbParams | ||
fprintf('Computing sensitivity conditional to %s...\n',ParametersNames{params}); | ||
L1InteractionsParams = L1normInteractions(ParametersValues,params,Clustering,NbBins(params)); | ||
L1Interactions(params,:,:,1:NbBins(params)) = L1InteractionsParams(:,:,1:NbBins(params)); | ||
BootInteractionsParams = BootstrapInteractions(ParametersValues,params,Clustering,NbBins(params),2000,alpha); | ||
BootInteractions(params,:,:,1:NbBins(params)) = BootInteractionsParams(:,:,1:NbBins(params)); | ||
NormalizedInteractions = L1Interactions./BootInteractions; | ||
end | ||
|
||
|
||
% Measure of conditional interaction sensitivity per class | ||
SensitivityPerClass = nanmean(NormalizedInteractions,4); | ||
|
||
% Average measure of sensitivity over all classes | ||
SensitivityOverClass = nanmean(SensitivityPerClass,3); | ||
|
||
|
||
% Hypothesis test: Ho = 1 if at least one value > 1 (per cluster and per bin) | ||
SensitivityPerInteraction = reshape(permute(NormalizedInteractions,[2,1,4,3]),[],max(NbBins)*NbClusters); | ||
H0accInter = any(SensitivityPerInteraction >=1,2); | ||
|
||
StandardizedSensitivityInteractions = reshape(SensitivityOverClass',1,[]); | ||
%% Save variables to output data structure | ||
|
||
DGSA_ConditionalEffects.ConditionalEffects.SensitivityByClusterandBins=NormalizedInteractions; | ||
DGSA_ConditionalEffects.ConditionalEffects.StandardizedSensitivity=StandardizedSensitivityInteractions; | ||
DGSA_ConditionalEffects.ConditionalEffects.H0accConditional=H0accInter; | ||
DGSA_ConditionalEffects.ConditionalEffects.Names_ConditionalEffects=CreateNames_ConditionalEffect(ParametersNames); | ||
|
||
|
||
end | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
function DataStructMainEffects=ComputeMainEffects(DataStruct,alpha,ColorType) | ||
% This function computes/display main effects from DGSA. | ||
% Author: Jihoon Park (jhpark3@stanford.edu) and Celine | ||
% Scheidt(scheidtc@stanford.edu) | ||
|
||
% Input: | ||
|
||
% DataSturc : Data structure having inputs required for computing main effects. | ||
% .ParametersValues: (matrix, # of models x # of parameters) contains values of each parameter from Monte Carlo sampling. | ||
% .ParametersNames: (cell, 1 x # of parameters) contains the names of parameters | ||
% .D: (matrix, # of models x # of models or vector, length =# of models x (# of models -1)) | ||
% Distance matrix or vector of distances between the model. | ||
% .Clustering: (structure) results of clustering | ||
% | ||
% | ||
% Inputs for Display:: | ||
% | ||
% .MainEffects.Display.StandardizedSensitivity: (string) specifies the method to visualize standardized main effect. | ||
% 'Pareto': Pareto plot | ||
% 'CI': Add a confidence interval to the Pareto plot | ||
% 'None': (default) do not display | ||
% .MainEffects.Display.ParetoPlotbyCluster: | ||
% | ||
% Optional:: | ||
% | ||
% alpha: (optional) % quantile of bootstrapped idstribution. If only Pareto plot is used to display standardized main effects, It should be scalar. The default value is 0.95 | ||
% If a confidence interval is displayed, it should be a vector of length 3. The value of sensitivity (length of Pareto bar) is based on the first element. | ||
% ColorType: (optional, string) specifies how the Pareto plot is colored when confidence interval is dispalyed. If 'RB', the bar is colord with Red/Blue scheme (default). | ||
% If 'jet', the bar is colored with 'jet' obejct from Matlab. | ||
|
||
|
||
|
||
% Output: | ||
|
||
% DataStructMainEffects.MainEffects: Results of Main effects are added to DataStruc | ||
% .SensitivitybyCluster : (matrix, # of parameters x # of clusters) contains main effects by parameters (rows) and clusters (columns) | ||
% .SensitivityStandardized : (vector, length=# of parameters) Main effects averaged over clusters. | ||
% .H0accMain: (logical, length=# of parameters) Result of bootstrap hypothesis test. If true, a parameter is sensitive. | ||
|
||
|
||
%% Create variables | ||
DataStructMainEffects=DataStruct; | ||
if nargin<2 | ||
alpha=.95; | ||
end | ||
|
||
|
||
%% 1. Check the visualization method. | ||
if ~DataStruct.MainEffects.Display.StandardizedSensitivity | ||
DataStruct.MainEffects.Display.StandardizedSensitivity='None'; % Default is not to visualize sensitivities | ||
end | ||
|
||
switch DataStruct.MainEffects.Display.StandardizedSensitivity | ||
|
||
case 'CI' | ||
if length(alpha)~=3 | ||
error('In order to disply confidence interval, alpha should be a vector of length 3') | ||
end | ||
|
||
[~,idx]=sort(alpha); | ||
|
||
if ~all(idx==[2,1,3]) | ||
error('In order to disply confidence interval, alpha(3)>alpha(1)>alpha(2)') | ||
end | ||
|
||
|
||
|
||
case 'Pareto' | ||
if ~isscalar(alpha) | ||
error('Significane level should be scalar for Parteo plot only') | ||
end | ||
case 'None' | ||
if ~isscalar(alpha) | ||
error('Significane level should be scalar when sensitivities not displayed') | ||
end | ||
otherwise | ||
error('Enter the right type of display method'); | ||
|
||
end | ||
|
||
|
||
%% 2. Create variables | ||
|
||
ParametersValues=DataStruct.ParametersValues; % Values of Parameters | ||
ParametersNames=DataStruct.ParametersNames; | ||
Clustering=DataStruct.Clustering; | ||
|
||
|
||
|
||
|
||
%% 3. Compute Main Effects | ||
|
||
L1MainFactors = L1normMainFactors(Clustering,ParametersValues); % evaluate L1-norm | ||
L1MainFactors=repmat(L1MainFactors,1,1,length(alpha)); | ||
|
||
BootMainFactors = BootstrapMainFactors(ParametersValues,Clustering,2000,alpha); % bootstrap procedure | ||
|
||
SensitivityMainFactors = L1MainFactors./BootMainFactors; % normalization | ||
SensitivitybyCluster=SensitivityMainFactors(:,:,1); | ||
StandardizedSensitivity = mean(SensitivityMainFactors,2); | ||
|
||
|
||
%% 4. Hypothetis test: H0=1(reject, so sensitive) if at least one value > 1 (per cluster) | ||
H0accMain = any(SensitivitybyCluster >=1,2); | ||
|
||
|
||
|
||
%% 5. Save Main effects to Data Structure | ||
SensitivityStandaridzed=StandardizedSensitivity(:,:,1); | ||
SensitivitybyCluster=SensitivityMainFactors(:,:,1); | ||
DataStructMainEffects.MainEffects.SensitivitybyCluster=SensitivitybyCluster; | ||
DataStructMainEffects.MainEffects.SensitivityStandardized=SensitivityStandaridzed; | ||
|
||
DataStructMainEffects.MainEffects.H0accMain=H0accMain; | ||
|
||
%% 6. Display main effects. | ||
|
||
% 6.1 Sensitivity by cluster. | ||
if DataStruct.MainEffects.Display.ParetoPlotbyCluster % display main effects by cluster | ||
ParetoMainFactors(SensitivitybyCluster,ParametersNames); | ||
end | ||
|
||
% 6.2 Display Standardized Sensitivity | ||
|
||
switch DataStruct.MainEffects.Display.StandardizedSensitivity | ||
case 'CI' | ||
if nargin<3 | ||
ColorType='RB'; | ||
end | ||
Pareto_GlobalSensitivity_CI(StandardizedSensitivity, H0accMain, ParametersNames,ColorType); | ||
|
||
case 'Pareto' | ||
|
||
Pareto_GlobalSensitivity(SensitivityStandaridzed,ParametersNames,H0accMain); | ||
|
||
|
||
end | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
function [NetConditionalEffects,Bin_MaxNetConditional]=ComputeNetConditionalEffects... | ||
(ParameterSpecified, DGSA,YTicktxt) | ||
% This functions compute net interactions and visualizae in bar graphs | ||
% Author: Jihoon Park (jhpark3@stanford.edu) | ||
% Date: 16 May 2016 | ||
% | ||
%Input: | ||
% ParameterSpecified: string, a name of parameter that wants to see net conditioanl effects | ||
% DGSA: Datastructure contains results of DGSA. | ||
% YTicktxt: Labels of y-axis of horizontal bar graph. | ||
|
||
%Output: | ||
|
||
% NetConditionalEffects:matrix (NbBins x (# of Parameters-1)): contains net conditional effects of the specified parameter. | ||
% Bin_MaxNetConditional: scalar, the index of bin that has the highest conditional effects. | ||
|
||
|
||
|
||
%% Assgin varaiables | ||
|
||
ParametersNames=DGSA.ParametersNames; | ||
IdxParametersSpecified=find(ismember(ParametersNames,ParameterSpecified)); | ||
NamesConditionalEffects=DGSA.ConditionalEffects.Names_ConditionalEffects; | ||
ParametersNames=DGSA.ParametersNames; | ||
ConditionalEffects_by_bins_clusters=DGSA.ConditionalEffects.SensitivityByClusterandBins; | ||
if isempty(IdxParametersSpecified) | ||
error('Enter Right name of the parameter') | ||
end | ||
|
||
|
||
%% | ||
NbParams=length(ParametersNames); | ||
|
||
SensitivityInteractionOverClass=nanmean(ConditionalEffects_by_bins_clusters, 3); % Average over cluster | ||
NetConditionalEffects_temp=SensitivityInteractionOverClass(IdxParametersSpecified,:,:,:); % Take according to varable specified. | ||
|
||
[~,NumConditionalPerParams,~,NbBins_Parameters]=size(NetConditionalEffects_temp); | ||
|
||
% Transform the form of variable NetConditionalEffects_temp | ||
|
||
NetConditionalEffects=zeros(NbBins_Parameters,NumConditionalPerParams); % Initialize | ||
|
||
for k=1:NbBins_Parameters | ||
NetConditionalEffects(k,:)=NetConditionalEffects_temp(:,:,:,k); | ||
end | ||
|
||
%% Visualization | ||
|
||
|
||
figure; | ||
barh(NetConditionalEffects,'stacked'); | ||
if nargin<3 | ||
if NbBins_Parameters==3 | ||
set(gca,'YTickLabel', {'Low','Med','High'}); | ||
end | ||
if NbBins_Parameters==2 | ||
set(gca,'YTickLabel', {'Low','High'}); | ||
end | ||
else | ||
set(gca,'YTickLabel', YTicktxt); | ||
|
||
end | ||
|
||
|
||
|
||
|
||
xlabel(ParametersNames(IdxParametersSpecified)); | ||
ylabel('Net conditional effects'); | ||
|
||
legend(NamesConditionalEffects((NbParams-1)*(IdxParametersSpecified-1)+1:(NbParams-1)*IdxParametersSpecified),'Location','EastOutside'); | ||
|
||
[~,Bin_MaxNetConditional]=max(sum(NetConditionalEffects,2)); | ||
|
||
|
||
end |
Oops, something went wrong.