Class Salsa

Inheritance Relationships

Base Type

Class Documentation

class Salsa : public SubmodularOptimizer

The Salsa optimizer for submodular functions. This algorithms runs multiple copies of different thresholding strategies in parallel. Some of these strategies require additional information about the datastream such as its length and thus this algorithm might not be applicable in a “real” streaming scenario.

  • Stream: (Yes)

  • Solution: \(1/2 - \varepsilon\)

  • Runtime: \(O(1)\)

  • Memory: \(O(K \cdot log(K) / \varepsilon)\)

  • Function Queries per Element: \(O(log(K) / \varepsilon)\)

  • Function Types: nonnegative, monotone submodular functions

Example usage in C++:

//read some data 
std::vector<std::vector<data_t>> = read_some_data(); 
auto K = 50;
// Define the function to be maximized and select the summary
FastIVM fastIVM(K, RBFKernel( std::sqrt(data[0].size()), 1.0) , 1.0);
Salsa opt(K, fastIVM, 1.0, 0.01);
opt.fit(data);
std::cout << "fval:" << opt.get_fval() << "num_elements: " << opt.get_num_elements_stored() << "num_candidates: " << opt.get_num_candidate_solutions() << std::endl;
// Process summary
auto summary = opt.get_solution();

Example usage in Python:

X = read_some_data(); 
K = 50
# Create function to be maximized
kernel = RBFKernel(sigma=sigma,scale=scale)
fastLogDet = FastIVM(K, kernel, 1.0)
opt = Salsa(K, fastLogDet, 1.0, 0.01)
opt.fit(X, K)
print("fval: {} num_elements: {} num_candidates: {}".format(opt.get_fval(), opt.get_num_elements_stored(), opt.get_num_candidate_solutions()))
# process summary
summary = opt.get_solution()

References

  • Norouzi-Fard, A., Tarnawski, J., Mitrovic, S., Zandieh, A., Mousavifar, A. & Svensson, O.. (2018). Beyond 1/2-Approximation for Submodular Maximization on Massive Data Streams. Proceedings of the 35th International Conference on Machine Learning, in PMLR 80:3829-3838

  • Norouzi-Fard, A., Tarnawski, J., Mitrovic, S., Zandieh, A., Mousavifar, A. & Svensson, O.. (2018). Beyond 1/2-Approximation for Submodular Maximization on Massive Data Streams. https://arxiv.org/abs/1808.01842

Public Functions

inline Salsa(unsigned int K, SubmodularFunction &f, data_t m, data_t epsilon, data_t hilow_epsilon = 0.05, data_t hilow_beta = 0.1, data_t hilow_delta = 0.025, data_t dense_beta = 0.8, data_t dense_C1 = 10, data_t dense_C2 = 0.2, data_t fixed_epsilon = 1.0 / 6.0)

Construct a new Salsa object.

Parameters
  • K – The cardinality constraint you of the optimization problem, that is the number of items selected.

  • f – The function which should be maximized. Note, that the clone function is used to construct a new SubmodularFunction which is owned by this object. If you implement a custom SubmodularFunction make sure that everything you need is actually cloned / copied.

  • m – The maximum singleton function value \( m = \max f({m}) \) .

  • epsilon – The \(\varepsilon\) parameter used to sample different thresholds via the “SieveStreaming” rule \(O = \{(1+\varepsilon)^i \mid i \in \mathbb{Z}, m \le (1+\varepsilon)^i \le K \cdot m\}\) where \(m = \max f({m})\) is the maximum singleton function value.

  • hilow_epsilon – The \(\epsilon\) parameter of the High-Low thresholding algorithm

  • hilow_beta – The \(\beta\) parameter of the High-Low thresholding algorithm

  • hilow_delta – The \(\delta\) parameter of the High-Low thresholding algorithm

  • dense_beta – The \(\beta\) parameter of the Dense thresholding algorithm

  • dense_C1 – The \(C_1\) parameter of the Dense thresholding algorithm

  • dense_C2 – The \(C_2\) parameter of the Dense thresholding algorithm

  • fixed_epsilon – The \(\epsilon\) parameter of the Fixed thresholding algorithm

inline Salsa(unsigned int K, std::function<data_t(std::vector<std::vector<data_t>> const&)> f, data_t m, data_t epsilon, data_t hilow_epsilon = 0.05, data_t hilow_beta = 0.1, data_t hilow_delta = 0.025, data_t dense_beta = 0.8, data_t dense_C1 = 10, data_t dense_C2 = 0.2, data_t fixed_epsilon = 1.0 / 6.0)

Construct a new Salsa object.

Parameters
  • K – The cardinality constraint you of the optimization problem, that is the number of items selected.

  • f – The function which should be maximized. Note, that this parameter is likely moved and not copied. Thus, if you construct multiple optimizers with the same function they all reference the same function. This can be very efficient for state-less functions, but may lead to weird side effects if f keeps track of a state.

  • m – The maximum singleton function value \( m = \max f({m}) \).

  • epsilon – The \(\varepsilon\) parameter used to sample different thresholds via the “SieveStreaming” rule \(O = \{(1+\varepsilon)^i \mid i \in \mathbb{Z}, m \le (1+\varepsilon)^i \le K \cdot m\}\) where \(m = \max f({m})\) is the maximum singleton function value.

  • hilow_epsilon – The \(\epsilon\) parameter of the High-Low thresholding algorithm

  • hilow_beta – The \(\beta\) parameter of the High-Low thresholding algorithm

  • hilow_delta – The \(\delta\) parameter of the High-Low thresholding algorithm

  • dense_beta – The \(\beta\) parameter of the Dense thresholding algorithm

  • dense_C1 – The \(C_1\) parameter of the Dense thresholding algorithm

  • dense_C2 – The \(C_2\) parameter of the Dense thresholding algorithm

  • fixed_epsilon – The \(\epsilon\) parameter of the Fixed thresholding algorithm

inline virtual unsigned int get_num_candidate_solutions() const

Returns the number of thresholding algorithms used in parallel. Each algorithm stores at most one full summary.

inline virtual unsigned long get_num_elements_stored() const

Returns the total number of items stored across all algorithms.

inline virtual void fit(std::vector<std::vector<data_t>> const &X, std::vector<idx_t> const &ids, unsigned int iterations = 1)

Executes all different thresholding algorithm in parallel and picks that one with the best summary.

Parameters
  • X – A constant reference to the entire data set

  • ids – A list of identifier for each object. This can be used to uniquely identify the objects in the summary. If ids.size() < X.size(), then only partial ids are stored. No ids are stored if ids is empty. Make sure, that either all or no object receives an id to keep track which id belongs to which object. This algorithm simply stores the objects and the ids in two separate lists and performs no safety checks.

  • iterations – Has no effect. Greedy iterates K times over the entire dataset in any case.

inline virtual void fit(std::vector<std::vector<data_t>> const &X, unsigned int iterations = 1)

Executes all different thresholding algorithm in parallel and picks that one with the best summary.

Note

This internally calls fit with an empty id set.

Parameters
  • X – A constant reference to the entire data set

  • iterations – Has no effect. Greedy iterates K times over the entire dataset in any case.

inline virtual void next(std::vector<data_t> const &x, std::optional<idx_t> const id = std::nullopt)

Throws an exception when called. Salsa does not support streaming!

Parameters

x – A constant reference to the next object on the stream.

Protected Attributes

std::vector<std::unique_ptr<SubmodularOptimizer>> algos
data_t m
data_t epsilon
data_t hilow_epsilon
data_t hilow_beta
data_t hilow_delta
data_t dense_beta
data_t dense_C1
data_t dense_C2
data_t fixed_epsilon
class Dense : public SubmodularOptimizer

Dense thresholding strategy (Algorithm 1 in the ICML paper). This basically simulates the SimpleGreedy / PreemptionStreaming algalgorithm with a slightly different sampling strategy for the thresholds. In the original version OPT is known and different epsilon are used to “sample” different thresholds. As detailed in the longer version arxiv version of the paper, we can estimate OPT via \(O = \{(1+\varepsilon)^i \mid i \in \mathbb{Z}, m \le (1+\varepsilon)^i \le K \cdot m\}\) where \( m = \max f({m}) \) is the maximum singleton function value.

Public Functions

inline Dense(unsigned int K, SubmodularFunction &f, data_t threshold, data_t beta, data_t C1, data_t C2, unsigned int N)

Construct a new Dense object.

Parameters
  • K – The cardinality constraint you of the optimization problem, that is the number of items selected.

  • f – The function which should be maximized. Note, that the clone function is used to construct a new SubmodularFunction which is owned by this object. If you implement a custom SubmodularFunction make sure that everything you need is actually cloned / copied.

  • threshold – The (sampled) OPT threshold

  • beta – The \(\beta\) parameter

  • C1 – The \(\C_1\) parameter

  • C2 – The \(C_2\) parameter

  • N – The number of items in the datastream

inline Dense(unsigned int K, std::function<data_t(std::vector<std::vector<data_t>> const&)> f, data_t threshold, data_t beta, data_t C1, data_t C2, unsigned int N)

Construct a new Dense object.

Parameters
  • K – The cardinality constraint you of the optimization problem, that is the number of items selected.

  • f – The function which should be maximized. Note, that this parameter is likely moved and not copied. Thus, if you construct multiple optimizers with the same function they all reference the same function. This can be very efficient for state-less functions, but may lead to weird side effects if f keeps track of a state.

  • threshold – The (sampled) OPT threshold

  • beta – The \(\beta\) parameter

  • C1 – The \(\C_1\) parameter

  • C2 – The \(C_2\) parameter

  • N – The number of items in the datastream

inline virtual void fit(std::vector<std::vector<data_t>> const &X, unsigned int iterations = 1)

Throws an exception when called. FixedThreshold should not be used outside Salsa.

Parameters
  • X – A constant reference to the entire data set

  • iterations – Number of iterations over the entire dataset

inline virtual void next(std::vector<data_t> const &x, std::optional<idx_t> const id = std::nullopt)

Consume the next object in the data stream. Add the current item to the summary if there are fewer than K element in it and if the items gain exceeds the current thresholding rule. Performs one function query.

Parameters
  • &x – A constant reference to the next object on the stream.

  • id – The id of the given object. If this is a std::nullopt this parameter is ignored. Otherwise the id is inserted into the solution. Make sure, that either all or no object receives an id to keep track which id belongs to which object. This algorithm simply stores the objects and the ids in two separate lists and performs no safety checks.

class FixedThreshold : public SubmodularOptimizer

Fixed thresholding strategy (Algorithm 2 in the ICML paper). This basically simulates the thresholding strategy of SieveStreaming with a slightly different sampling strategy for the thresholds. In the original version OPT is known and different epsilon are used to “sample” different thresholds. As detailed in the longer version arxiv of the paper, we can estimate OPT via \(O = \{(1+\varepsilon)^i \mid i \in \mathbb{Z}, m \le (1+\varepsilon)^i \le K \cdot m\}\) where \( m = \max f({m}) \) is the maximum singleton function value.

Note

This class is basically also implemented in SieveStreaming and SieveStreamingPP. I decided against a unified class for these Sieves, since the thresholding rules are often slightly different from paper to paper. I tried to stick as close as possible to the pseudocode in the papers.

Public Functions

inline FixedThreshold(unsigned int K, SubmodularFunction &f, data_t epsilon, data_t threshold)

Construct a new FixedThreshold object.

Parameters
  • K – The cardinality constraint you of the optimization problem, that is the number of items selected.

  • f – The function which should be maximized. Note, that the clone function is used to construct a new SubmodularFunction which is owned by this object. If you implement a custom SubmodularFunction make sure that everything you need is actually cloned / copied.

  • epsilon – The epsilon parameter for this algorithm

  • threshold – The (sampled) OPT threshold

inline FixedThreshold(unsigned int K, std::function<data_t(std::vector<std::vector<data_t>> const&)> f, data_t epsilon, data_t threshold)

Construct a new FixedThreshold object.

Parameters
  • K – The cardinality constraint you of the optimization problem, that is the number of items selected.

  • f – The function which should be maximized. Note, that this parameter is likely moved and not copied. Thus, if you construct multiple optimizers with the same function they all reference the same function. This can be very efficient for state-less functions, but may lead to weird side effects if f keeps track of a state.

  • epsilon – The epsilon parameter for this algorithm

  • threshold – The (sampled) OPT threshold

inline virtual void fit(std::vector<std::vector<data_t>> const &X, unsigned int iterations = 1)

Throws an exception when called. FixedThreshold should not be used outside Salsa.

Parameters
  • X – A constant reference to the entire data set

  • iterations – Number of iterations over the entire dataset

inline virtual void next(std::vector<data_t> const &x, std::optional<idx_t> const id = std::nullopt)

Consume the next object in the data stream. Add the current item to the summary if there are fewer than K element in it and if the items gain exceeds the current thresholding rule. Performs one function query.

Parameters
  • &x – A constant reference to the next object on the stream.

  • id – The id of the given object. If this is a std::nullopt this parameter is ignored. Otherwise the id is inserted into the solution. Make sure, that either all or no object receives an id to keep track which id belongs to which object. This algorithm simply stores the objects and the ids in two separate lists and performs no safety checks.

class HighLowThreshold : public SubmodularOptimizer

High-Low thresholding strategy (Algorithm 3 in in the ICML paper]). This basically combines Dense and FixedThresholding. In the original version OPT is known and different epsilon are used to “sample” different thresholds. As detailed in the longer arxiv version of the paper, we can estimate OPT via \(O = \{(1+\varepsilon)^i \mid i \in \mathbb{Z}, m \le (1+\varepsilon)^i \le K \cdot m\}\) where \( m = \max f({m}) \) is the maximum singleton function value.

Public Functions

inline HighLowThreshold(unsigned int K, SubmodularFunction &f, data_t epsilon, data_t threshold, data_t beta, data_t delta, unsigned int N)

Construct a new HighLowThreshold object.

Parameters
  • K – The cardinality constraint you of the optimization problem, that is the number of items selected.

  • f – The function which should be maximized. Note, that the clone function is used to construct a new SubmodularFunction which is owned by this object. If you implement a custom SubmodularFunction make sure that everything you need is actually cloned / copied.

  • epsilon – The \(\epsilon\) parameter

  • threshold – The (sampled) OPT threshold

  • beta – The \(\beta\) parameter

  • delta – The \(\delta\) parameter

  • N – The number of items in the datastream

inline HighLowThreshold(unsigned int K, std::function<data_t(std::vector<std::vector<data_t>> const&)> f, data_t epsilon, data_t threshold, data_t beta, data_t delta, unsigned int N)

Construct a new HighLowThreshold object.

Parameters
  • K – The cardinality constraint you of the optimization problem, that is the number of items selected.

  • f – The function which should be maximized. Note, that this parameter is likely moved and not copied. Thus, if you construct multiple optimizers with the same function they all reference the same function. This can be very efficient for state-less functions, but may lead to weird side effects if f keeps track of a state.

  • epsilon – The \(\epsilon\) parameter

  • threshold – The (sampled) OPT threshold

  • beta – The \(\beta\) parameter

  • delta – The \(\delta\) parameter

  • N – The number of items in the datastream

inline virtual void fit(std::vector<std::vector<data_t>> const &X, unsigned int iterations = 1)

Throws an exception when called. FixedThreshold should not be used outside Salsa.

Parameters
  • X – A constant reference to the entire data set

  • iterations – Number of iterations over the entire dataset

inline virtual void next(std::vector<data_t> const &x, std::optional<idx_t> const id = std::nullopt)

Consume the next object in the data stream. Add the current item to the summary if there are fewer than K element in it and if the items gain exceeds the current thresholding rule. Performs one function query.

Parameters
  • &x – A constant reference to the next object on the stream.

  • id – The id of the given object. If this is a std::nullopt this parameter is ignored. Otherwise the id is inserted into the solution. Make sure, that either all or no object receives an id to keep track which id belongs to which object. This algorithm simply stores the objects and the ids in two separate lists and performs no safety checks.