Commit 881e0504 authored by Argyris Kalogeratos's avatar Argyris Kalogeratos

init

parents
%epidemicControl - This is the main script that initializes the environment,
%performs simulations, and reports comparative results.
%---
% This is part of the DRA Simulator package for Dynamic Resource Allocation
% strategies aiming to suppress SIS epidemics. See README.md for more
% details. If you make use of this package, or part of it, please consider
% citing the paper:
%
% "A Greedy Approach for Dynamic Control of Diffusion Processes in
% Networks", K. Scaman, A. Kalogeratos, N Vayatis, IEEE International
% Conference on Tools with Artificial Intelligence (ICTAI), 2015.
%
% DRA Simulator is free software: redistribute them and/or modify them
% under the terms of the GNU General Public License as published by the
% Free Software Foundation, either version 3 of the License, or (at your
% option) any later version.
%
% DRA Simulator package is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
% Public License for more details. You should have received a copy of the
% GNU General Public License along with DRA Simulator. If not, see
% <http://www.gnu.org/licenses/>.
%
% Copyright (c) by Argyris Kalogeratos and Kevin Scaman, 2015.
%---
% INITIALIZATION (run only once - to force initialization, clear the environment first)
if (~exist('MATLAB_WORKERS', 'var')) % avoid re-initializations
prepareWorkspace();
end
% Initialize the random number generator (RNG) for reproducibility of the results
if (rng_seed >= 0), rng(rng_seed); end
rngInfo = rng;
%% PARAMETER SETUP
% Graph parameters
graphPars = struct;
% a. Generate graph
graphPars.N = 100; % the size of graph to generate
graphPars.graphType = 'erdosRenyi'; % available: 'erdosRenyi', 'preferentialAttachment', 'smallWorld', 'adjacencyMatrix'
if (strcmp(graphPars.graphType, 'erdosRenyi') == 1)
graphPars.prob_arete_graph = 0.1; % only for erdosRenyiGraph() generation
end
% b. Use an input graph
% - enter 'adjacencyMatrix' in graphPars.graphType
% - include the following:
% - load or create your graph G
% G = erdosRenyiGraph(graphPars.N, graphPars.prob_arete_graph); % this is just an example
% graphPars.adjacencyMatrix = G;
% graphPars.N = size(G,1);
% Infection seeds parameters
infectionSeedPars = struct;
infectionSeedPars.size = 0.9; % the percentage of initial seeds distributed uniformly at random
% Epidemic parameters
epidemicPars = struct;
epidemicPars.beta = 3; % independent infection rate for each edge
epidemicPars.delta = 1; % recovery rate for each infected node
epidemicPars.rho = 120; % increase in recovery rate for each treated node
% Control strategy parameters
btot = 5; % number of available treatment resources
strategies = createStrategies(btot, 'LRIE');%'RAND', 'LRSR', 'LRIE'); % which strategies to test (baseline, static, dynamic): for more info see the documentation of this function
% Simulation and experimentation parameters
simulationPars = struct;
simulationPars.T = 2; % simulation time
simulationPars.noSlopeT = Inf; % characteristic time for the non stationarity test
simulationPars.timeStep = 0.01; % time step for results
simulationPars.stateSnapshots = false; % record the infection state and the resource distribution for every change that happens
numTests = 10;
% automatically defined
simulationPars.runInParallel = (MATLAB_WORKERS > 0); % use multiple Matlab workers
simulationPars.consistentRNG = (rngInfo.Seed == rng_seed); % preserve the consistency of random number generator if the seed is the one given by the user
if (simulationPars.runInParallel == simulationPars.consistentRNG)
simulationPars.runInParallel = 0;
warning('Warning: RNG cannot be consistent when multiple workers are used (simulationPars.runInParallel turned to false)');
end
%% EPIDEMIC SIMULATION
results = cell(numTests, 1);
tic;
for iTest=1:numTests,
fprintf('\n=== iTest: %g ==================================================\n', iTest);
results{iTest} = simulateEpidemic(graphPars, infectionSeedPars, epidemicPars, simulationPars, strategies, 'verbosityLevel', 2);
end
toc;
%% COMPUTE AND SHOW METRICS
fResults = invertCellStruct(results); % make a strcture with proper format for exploring the results
fResults = applyMetric(fResults, @(s) 100 * double(s.numInfected) / graphPars.N, 'percentageInfected');
fResults = applyMetric(fResults, @(s) 100 * double(s.numInfected(end)) / graphPars.N, 'finalPercentageInfected');
fResults = applyMetric(fResults, @(s) sum(s.numInfected) * simulationPars.timeStep, 'AUC');
fResults = applyMetric(fResults, @(s) timeOfExtinction(s), 'timeExtinction');
fResults = applyMetric(fResults, @(s) double(s.numInfected(end)), 'finalNumInfected');
%% SHOW OUTPUT RESULTS & PLOTS
showMeasures(fResults, 'AUC', 'timeExtinction', 'finalPercentageInfected');
plotCurves(fResults, 'percentageInfected', 'title', 'Comparison of resource allocation strategies', 'xlabel', 'time', 'ylabel', 'percentage of infected nodes');
%simulationResult - This function applies a function that computes an
%evaluation metric on the simulation result and store it as a field in the
%results' structure.
%
% function sResult = applyMetric (simulationResult, ...
% metricFunction, metricName)
%
% Input:
% - sResult: a structure with the simulation results.
% - metricFunction: a function handler that computes an evaluation metric
% on the recorded simulation results. This is defined through the call.
% - metricName: the name of computed evaluation metric.
%
% Output:
% - sResult: the udated structure with the simulation results.
%---
% This is part of the DRA Simulator package for Dynamic Resource Allocation
% strategies aiming to suppress SIS epidemics. See the comments header
% of the main script DRAsimulator.m and the README.md for more details.
% This package is distributed under GNU GPL v.3 or later.
%
% Copyright (c) by Argyris Kalogeratos and Kevin Scaman, 2015.
%---
function sResult = applyMetric (sResult, metricFunction, metricName)
sResult = structfun(@(strategy) addMetricToStrategy(strategy), sResult, 'UniformOutput', false);
function strategy = addMetricToStrategy(strategy)
if (iscell(strategy))
strategy = cellfun(@(test) addMetricValue(test, metricFunction(test), metricName), strategy, 'UniformOutput', false);
else
strategy = addMetricValue(strategy, metricFunction(strategy), metricName);
end
end
function strategy = addMetricValue(strategy, value, name)
strategy.(name) = value;
end
end
\ No newline at end of file
%computeMeanAndStd - This is a helper function which is called by the
%showMeasures(). It computes mean and std values for given fields of the
%structure with the simulation results.
%
% function meanAndStd = computeMeanAndStd (fRresults, fieldName)
%
% Input:
% - fRresults: a structure with the simulation results.
% - fieldName: the field to compute the values (should be a name of an
% evaluation metric existing in the structure).
%
% Output:
% - meanAndStd: the resulting values in a structure.
%---
% This is part of the DRA Simulator package for Dynamic Resource Allocation
% strategies aiming to suppress SIS epidemics. See the comments header
% of the main script DRAsimulator.m and the README.md for more details.
% This package is distributed under GNU GPL v.3 or later.
%
% Copyright (c) by Argyris Kalogeratos and Kevin Scaman, 2015.
%---
function meanAndStd = computeMeanAndStd (fRresults, fieldName)
valuesStruct = structfun(@(s) cellfun(@(t) t.(fieldName)(end), s), fRresults, 'UniformOutput', false);
meanAndStd = structfun(@(v) createStruct(v), valuesStruct, 'UniformOutput', false);
function meanAndStd = createStruct(values)
meanAndStd = struct;
meanAndStd.mean = mean(values(values ~= Inf));
meanAndStd.std = std(values(values ~= Inf));
end
end
%smallWorldGraph - Shows a selection of evaluation metrics stored in the
%simulation results structure.
%
% function showMeasures (fRresults, varargin)
%
% Input:
% - fRresults: a structure with the simulation results.
% - varargin : a list of names of the evaluation metrics to show.
%---
% This is part of the DRA Simulator package for Dynamic Resource Allocation
% strategies aiming to suppress SIS epidemics. See the comments header
% of the main script DRAsimulator.m and the README.md for more details.
% This package is distributed under GNU GPL v.3 or later.
%
% Copyright (c) by Argyris Kalogeratos and Kevin Scaman, 2015.
%---
function showMeasures (fRresults, varargin)
methodNames = fieldnames(fRresults);
numMeasures = length(varargin);
numMethods = length(methodNames);
measures = cell(numMeasures, 1);
for j=1:numMeasures
measure = computeMeanAndStd(fRresults, varargin{j});
measures{j} = structfun(@(strategy) strategy.mean, measure);
end
fprintf('-----------------------\n Comparing strategies\n-----------------------\n');
for i=1:numMethods
for j=1:numMeasures
measure = measures{j};
fprintf('%s: %10.2f (%2.2f), ', varargin{j}, measure(i), measure(i) / min(measure));
end
fprintf('-- [%20s]\n', methodNames{i});
end
end
\ No newline at end of file
%timeOfExtinction - Computes and returns the extinction time of an epidemic.
%
% function textinct = timeOfExtinction (strategyResults)
%
% Input:
% - strategyResults: a structure with the simulation results of a strategy.
%
% Output:
% - textinct: the time of extinction of the epidemic, or an Inf value if
% the epidemic is not completely removed.
%---
% This is part of the DRA Simulator package for Dynamic Resource Allocation
% strategies aiming to suppress SIS epidemics. See the comments header
% of the main script DRAsimulator.m and the README.md for more details.
% This package is distributed under GNU GPL v.3 or later.
%
% Copyright (c) by Argyris Kalogeratos and Kevin Scaman, 2015.
%---
function textinct = timeOfExtinction (strategyResults)
idx = find(strategyResults.numInfected == 0, 1);
if (isempty(idx))
textinct = Inf;
else textinct = strategyResults.time(idx);
end
end
%erdosRenyiGraph - A generator for Erdos Renyi graphs.
%
% function G = erdosRenyiGraph (N, p)
%
% Input:
% - N: the size of the graph to generate.
% - p: the probability of creating each edge (i,j).
%
% Output:
% - G: the generated graph.
%---
% This is part of the DRA Simulator package for Dynamic Resource Allocation
% strategies aiming to suppress SIS epidemics. See the comments header
% of the main script DRAsimulator.m and the README.md for more details.
% This package is distributed under GNU GPL v.3 or later.
%
% Copyright (c) by Argyris Kalogeratos and Kevin Scaman, 2015.
%---
function G = erdosRenyiGraph (N, p)
G = rand(N);
G = G + G';
if (p <= 0.5)
G = G < sqrt(2 * p);
else
G = G >= sqrt(2 * (1 - p));
end
G = G - diag(diag(G));
G = sparse(G);
end
\ No newline at end of file
%preferentialAttachmentGraph - A generator for Preferential Attachment graphs.
%
% function G = preferentialAttachmentGraph (N, M, delta)
%
% Input:
% - N: the size of the graph to generate.
% - M: is the number of esges to generate.
% - delta: is an extra additive weight that increases the probability of
% creating an edge, for each node.
%
% Output:
% - G: the generated graph.
%---
% This is part of the DRA Simulator package for Dynamic Resource Allocation
% strategies aiming to suppress SIS epidemics. See the comments header
% of the main script DRAsimulator.m and the README.md for more details.
% This package is distributed under GNU GPL v.3 or later.
%
% Copyright (c) by Argyris Kalogeratos and Kevin Scaman, 2015.
%---
function G = preferentialAttachmentGraph (N, M, delta)
if (nargin < 3)
delta = 0;
end
G = spalloc(N, N, N*M);
G(1, 2) = 1;
G(2, 1) = 1;
for i = 3:N
numNeighbors = full(sum(G,1));
newNeighbors = randp(max(0, numNeighbors + delta), [M 1]);
G(i, newNeighbors) = 1;
G(newNeighbors, i) = 1;
end
end
%smallWorldGraph - A generator for Small World graphs.
%
% function G = smallWorldGraph (N, k, p)
%
% Input:
% - N: the size of the graph to generate.
% - k: the size of the neighbors to connect each node (it assumes that
% each node is located on the periphery of a ring, then k is the number
% of nearest neighbors to connect with each node)
% - p: the probability of creating each edge (i,j) of the Erdos Renyi model.
% the generator makes an OR between the graph generated with the ring
% layout and an Erdos Renyi graph.
%
% Output:
% - G: the generated graph.
%---
% This is part of the DRA Simulator package for Dynamic Resource Allocation
% strategies aiming to suppress SIS epidemics. See the comments header
% of the main script DRAsimulator.m and the README.md for more details.
% This package is distributed under GNU GPL v.3 or later.
%
% Copyright (c) by Argyris Kalogeratos and Kevin Scaman, 2015.
%---
function G = smallWorldGraph (N, k, p)
G = zeros(N,N);
for i = 1:k
G = G + diag(ones(N - i, 1), i);
end
G = G + G';
G = max(G, erdosRenyiGraph(N, p));
p = randperm(N);
G = G(p,:);
G = G(:,p);
G = sparse(G);
end
%smallWorldGraph - A generator for Small World graphs.
%%RANDOMSEED Creates an infection state with exactly infection_seed_sz
%infected nodes among N distributed at random.
% function [infected, seed_sz] = randomSeed (N, infection_seed_sz)
%
% Input:
% - N: the size of the available network.
% - infection_seed_sz: the size of the random initial infection to generate.
% This can be either an integer [1,N] or a percentage in [0,1].
%
% Output:
% - infected: a vector with ones for the infected nodes of the network.
%---
% This is part of the DRA Simulator package for Dynamic Resource Allocation
% strategies aiming to suppress SIS epidemics. See the comments header
% of the main script DRAsimulator.m and the README.md for more details.
% This package is distributed under GNU GPL v.3 or later.
%
% Copyright (c) by Argyris Kalogeratos and Kevin Scaman, 2015.
%---
function infected = randomSeed (N, infection_seed_sz)
if (infection_seed_sz < 0)
error('Error: negative number of seed nodes.\n');
end
infected = false(N,1);
% Let a fixed number of infected nodes
if (infection_seed_sz < 1) % a fraction of nodes, otherwise an explicit num of nodes
infection_seed_sz = floor(infection_seed_sz * N);
end
infection_seed_sz = min(N, infection_seed_sz);
infected(randperm(N, infection_seed_sz)) = true;
end
This diff is collapsed.
%LINcriterion - It implements the LIN strategy.
%
% function strategyInternalState = LINcriterion (idxVariation, ...
% strategyInternalState)
%
% Input:
% - idxVariation: the index [1,N] of the node that changed state
% (i.e. it got infected or recovered).
% - strategyInternalState: a structure with all the internal information
% of the strategy state.
%
% Output:
% - strategyInternalState: returns the updated strategy's internal state.
%---
% This is part of the DRA Simulator package for Dynamic Resource Allocation
% strategies aiming to suppress SIS epidemics. See the comments header
% of the main script DRAsimulator.m and the README.md for more details.
% This package is distributed under GNU GPL v.3 or later.
%
% Copyright (c) by Argyris Kalogeratos and Kevin Scaman, 2015.
%---
function strategyInternalState = LINcriterion (idxVariation, strategyInternalState)
N = strategyInternalState.N;
G = strategyInternalState.graph;
idxRanked = strategyInternalState.idxRanked;
infections = strategyInternalState.infections;
% Compute the criterion for all the infected neighbors of the node that changed state,
% and that node itself only if it changed healthy --> infected.
if (idxVariation ~= -1)
strategyInternalState.idxVariation_s = find(idxRanked == idxVariation, 1); % the id of the node that changed state wrt the vector of sorted nodes
idxUpdatedNodeScores = strategyInternalState.nghbs(G, idxVariation) & infections;
idxUpdatedNodeScores(idxVariation) = infections(idxVariation); % add the altered node (there are no self-edges in G,
% thus the previous line doesn't cover this case
numNodesToUpdate = nnz(idxUpdatedNodeScores);
if (numNodesToUpdate ~= 0)
idxNodeIDs = find(idxUpdatedNodeScores ~= 0, numNodesToUpdate);
strategyInternalState.nodeScores(idxNodeIDs) = - sum(G(infections, idxNodeIDs), 1)';
end
else % this branch runs only in the first iteration of the simulation where all node scores need to be computed
strategyInternalState.idxVariation_s = [];
idxUpdatedNodeScores = infections;
strategyInternalState.nodeScores = zeros(N, 1);
strategyInternalState.nodeScores(infections) = - sum(G(infections, infections), 1)'; % the number of infected nodes pointing to an infected node has negative effect
end
strategyInternalState.idxUpdatedNodeScores = idxUpdatedNodeScores;
end
\ No newline at end of file
%LRIEcriterion - It implements the LRIE strategy.
%
% function strategyInternalState = LRIEcriterion (idxVariation, ...
% strategyInternalState)
%
% Input:
% - idxVariation: the index [1,N] of the node that changed state
% (i.e. it got infected or recovered).
% - strategyInternalState: a structure with all the internal information
% of the strategy state.
%
% Output:
% - strategyInternalState: returns the updated strategy's internal state.
%---
% This is part of the DRA Simulator package for Dynamic Resource Allocation
% strategies aiming to suppress SIS epidemics. See the comments header
% of the main script DRAsimulator.m and the README.md for more details.
% This package is distributed under GNU GPL v.3 or later.
%
% Copyright (c) by Argyris Kalogeratos and Kevin Scaman, 2015.
%---
function strategyInternalState = LRIEcriterion (idxVariation, strategyInternalState)
N = strategyInternalState.N;
G = strategyInternalState.graph;
idxRanked = strategyInternalState.idxRanked;
infections = strategyInternalState.infections;
% Compute the criterion for all the infected neighbors of the node that changed state,
% and that node itself only if it changed healthy --> infected.
if (idxVariation ~= -1)
strategyInternalState.idxVariation_s = find(idxRanked == idxVariation, 1); % the id of the node that changed state wrt the vector of sorted nodes
idxUpdatedNodeScores = strategyInternalState.nghbs(G, idxVariation) & infections;
idxUpdatedNodeScores(idxVariation) = infections(idxVariation); % add the altered node (there are no self-edges in G,
% thus the previous line doesn't cover this case
numNodesToUpdate = nnz(idxUpdatedNodeScores);
if (numNodesToUpdate ~= 0)
idxNodeIDs = find(idxUpdatedNodeScores ~= 0, numNodesToUpdate);
strategyInternalState.nodeScores(idxNodeIDs) = sum(G(idxNodeIDs, ~infections), 2) - sum(G(infections, idxNodeIDs), 1)';
end
else % this branch runs only in the first iteration of the simulation where all node scores need to be computed
strategyInternalState.idxVariation_s = [];
idxUpdatedNodeScores = infections;
strategyInternalState.nodeScores = zeros(N, 1);
strategyInternalState.nodeScores(infections) = sum(G(infections, ~infections), 2) - sum(G(infections, infections), 1)';
end
strategyInternalState.idxUpdatedNodeScores = idxUpdatedNodeScores;
end
\ No newline at end of file
%MSNcriterion - It implements the MSN strategy.
%
% function strategyInternalState = MSNcriterion (idxVariation, ...
% strategyInternalState)
%
% Input:
% - idxVariation: the index [1,N] of the node that changed state
% (i.e. it got infected or recovered).
% - strategyInternalState: a structure with all the internal information
% of the strategy state.
%
% Output:
% - strategyInternalState: returns the updated strategy's internal state.
%---
% This is part of the DRA Simulator package for Dynamic Resource Allocation
% strategies aiming to suppress SIS epidemics. See the comments header
% of the main script DRAsimulator.m and the README.md for more details.
% This package is distributed under GNU GPL v.3 or later.
%
% Copyright (c) by Argyris Kalogeratos and Kevin Scaman, 2015.
%---
function strategyInternalState = MSNcriterion (idxVariation, strategyInternalState)
N = strategyInternalState.N;
G = strategyInternalState.graph;
idxRanked = strategyInternalState.idxRanked;
infections = strategyInternalState.infections;
% Compute the criterion for all the infected neighbors of the node that changed state,
% and that node itself only if it changed healthy --> infected.
if (idxVariation ~= -1)
strategyInternalState.idxVariation_s = find(idxRanked == idxVariation, 1); % the id of the node that changed state wrt the vector of sorted nodes
idxUpdatedNodeScores = strategyInternalState.nghbs(G, idxVariation) & infections;
idxUpdatedNodeScores(idxVariation) = infections(idxVariation); % add the altered node (there are no self-edges in G,
% thus the previous line doesn't cover this case
numNodesToUpdate = nnz(idxUpdatedNodeScores);
if (numNodesToUpdate ~= 0)
idxNodeIDs = find(idxUpdatedNodeScores ~= 0, numNodesToUpdate);
strategyInternalState.nodeScores(idxNodeIDs) = sum(G(idxNodeIDs, ~infections), 2);
end
else % this branch runs only in the first iteration of the simulation where all node scores need to be computed
strategyInternalState.idxVariation_s = [];
idxUpdatedNodeScores = infections;
strategyInternalState.nodeScores = zeros(N, 1);
strategyInternalState.nodeScores(infections) = sum(G(infections, ~infections), 2);
end
strategyInternalState.idxUpdatedNodeScores = idxUpdatedNodeScores;
end
\ No newline at end of file
%createStrategies - This function creates one structure storing all the
%settings for the comtrol strategies that wil be simulated.
%
% function strategies = createStrategies (btot, varargin)
%
% Input:
% - btot: the number of treatment resources.
% - varargin: some names of the following available control strategies.
% There are three groups of strategies but an important property is
% whether there is dynamic response to the diffusion or not.
% --<Baseline strategies>--
% > 'NONE': it does not distribute any resources.
% > 'ALL' : distributes a treatment resource to every network node.
% Note that it does not respect the btot parameter.
% > 'RAND': each time a change in the distributes the btot resourses to
% randomly chosen nodes. Note that this is a naive dynamic strategy
% which decides at random each time an event happens (infection/recovery).
% --<Static strategies>--
% > 'RANDFIXED': it fixes the btot treatments to randomly selected
% nodes and keep it this way throughout all the simulation.
% > 'MN': favors the treatment of the nodes with most neighbors (high degree nodes).
% > 'LN': favors the treatment of the nodes with least neighbors (low degree nodes).
% > 'SRAI' or 'LRSR': the Largest Reduction of Spectral Radius strategy.
% --<Dynamic strategies>--
% > 'MSN' : the treatment resources are given to the btot nodes that
% have the most susceptible neighbors (i.e. to the most viral nodes)
% > 'LIN' : the treatment resources are given to the btot nodes that
% have the least infected neighbors (i.e. to the most safe nodes)
% > 'LRIE': it roughly combines MSN and LIN. This is the optimal greedy
% control strategy.
%
% For more information about the LRIE and the other strategies please
% refer to the paper:
%
% "A Greedy Approach for Dynamic Control of Diffusion Processes in
% Networks", K. Scaman, A. Kalogeratos, N Vayatis, IEEE International
% Conference on Tools with Artificial Intelligence (ICTAI), 2015.
%
% Output:
% - strategies: the structure with all the settings for all the control
% the will be simulated.
%---
% This is part of the DRA Simulator package for Dynamic Resource Allocation
% strategies aiming to suppress SIS epidemics. See the comments header
% of the main script DRAsimulator.m and the README.md for more details.
% This package is distributed under GNU GPL v.3 or later.
%
% Copyright (c) by Argyris Kalogeratos and Kevin Scaman, 2015.
%---
function strategies = createStrategies (btot, varargin)
strategies = struct;
for strategyName=varargin
%-------------------------
% Baseline strategies
%-------------------------
if(strcmp(strategyName, 'NONE'))
strategies.NONE = @(idx, state) nullStrategy(idx, state);
end
if(strcmp(strategyName, 'RAND'))
strategies.RAND = @(idx, state) randomStrategy(idx, state, btot, true);
end
if(strcmp(strategyName, 'ALL'))
strategies.ALL = @(idx, state) [ones(size(state.graph, 1), 1), state];
end
%-------------------------
% Static strategies
%-------------------------
if(strcmp(strategyName, 'RANDFIXED'))
strategies.RANDFIXED = @(idx, state) staticStrategy(idx, state, @(G, infected) randperm(size(G,1))', btot, 'RANDMIXED', true);
end
if(strcmp(strategyName, 'MN'))
strategies.MN = @(idx, state) staticStrategy(idx, state, @(G, infected) full(sum(G, 2)), btot, 'MN', true);
end
if(strcmp(strategyName, 'LN'))
strategies.LN = @(idx, state) staticStrategy(idx, state, @(G, infected) -full(sum(G, 1))', btot, 'LN', true);
end
if(strcmp(strategyName, 'SRAI') || strcmp(strategyName, 'LRSR'))
strategies.LRSR = @(idx, state) staticStrategy(idx, state, @(G, infected) dropInMaxEigenValueApprox(G), btot, 'LRSR', true); % approximated version
end
%-------------------------
% Dynamic strategies
%-------------------------
if(strcmp(strategyName, 'MSN'))
strategies.MSN = @(idx, state) preferentialStrategy(idx, state, @(idx, state) MSNcriterion(idx, state), btot);
end
if(strcmp(strategyName, 'LIN'))
strategies.LIN = @(idx, state) preferentialStrategy(idx, state, @(idx, state) LINcriterion(idx, state), btot);
end
if(strcmp(strategyName, 'LRIE'))
strategies.LRIE = @(idx, state) preferentialStrategy(idx, state, @(idx, state) LRIEcriterion(idx, state), btot);
end
end
end
%dropInMaxEigenValueApprox - An appriximation algorithm for the computation
%of a score for each node that represents the drop of in the max eigenvalue
%observed after removing that node from the graph.
%
% function scoreDropInEig = dropInMaxEigenValueApprox (G)
%
% Input:
% - G: the input graph.
%
% Output:
% - scoreDropInEig: a score value for each node.
%---
% This is part of the DRA Simulator package for Dynamic Resource Allocation
% strategies aiming to suppress SIS epidemics. See the comments header
% of the main script DRAsimulator.m and the README.md for more details.
% This package is distributed under GNU GPL v.3 or later.
%
% Copyright (c) by Argyris Kalogeratos and Kevin Scaman, 2015.
%---
function scoreDropInEig = dropInMaxEigenValueApprox (G)
N = size(G, 1);
scoreDropInEig = zeros(N, 1);
[U, ~, V] = svds(G, 1);
Up = U';
for i=1:N
v = sparse(i, i, 1, N, N, 1);
E = G * v;
E = E + E';
scoreDropInEig(i) = Up * E * V;
end
end
%nullStrategy - It creates a strategy object for the NULL strategy.
%
% function [treatments, strategyInternalState] = ...
% nullStrategy (~, strategyInternalState)
%
% Input:
% - <void par>: this is a dummy parameter for