Skip to content

Commit

Permalink
Debugging sampler
Browse files Browse the repository at this point in the history
  • Loading branch information
MargaretDuff committed Aug 15, 2023
1 parent ebdf329 commit ba35fb8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
4 changes: 2 additions & 2 deletions Wrappers/Python/cil/framework/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ def randomWithReplacement(num_subsets, prob=None, seed=None):
prob=prob
if len(prob)!=num_subsets:
raise ValueError("Length of the list of probabilities should equal the number of subsets")
if sum(prob)!=1.:
raise ValueError("Probabilites should sum to 1.")
if sum(prob)-1.>=1e-5:
raise ValueError("Probabilities should sum to 1. Your probabilities sum to {}".format(sum(prob)))
sampler=Sampler(num_subsets, sampling_type='random_with_replacement', prob=prob, seed=seed)
return sampler

Expand Down
25 changes: 10 additions & 15 deletions Wrappers/Python/cil/optimisation/algorithms/SPDHG.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class SPDHG(Algorithm):
List of probabilities. If None each subset will have probability = 1/number of subsets
gamma : float
parameter controlling the trade-off between the primal and dual step sizes
sampler: instnace of the Sampler class
sampler: instance of the Sampler class
Method of selecting the next mini-batch. If None, random sampling and each subset will have probability = 1/number of subsets
**kwargs:
norms : list of floats
Expand All @@ -77,11 +77,7 @@ class SPDHG(Algorithm):
Notation for primal and dual step-sizes are reversed with comparison
to PDHG.py
Note
----
this code implements serial sampling only, as presented in [2]
(to be extended to more general case of [1] as future work)
References
----------
Expand Down Expand Up @@ -126,11 +122,11 @@ def set_up(self, f, g, operator, tau=None, sigma=None, \
List of Step size parameters for Dual problem
initial : DataContainer, optional, default=None
Initial point for the SPDHG algorithm
prob : list of floats, optional, default=None
List of probabilities. If None each subset will have probability = 1/number of subsets
gamma : float
parameter controlling the trade-off between the primal and dual step sizes
sampler: instance of the Sampler class
Method of selecting the next mini-batch. If None, random sampling and each subset will have probability = 1/number of subsets.
**kwargs:
norms : list of floats
precalculated list of norms of the operators
Expand All @@ -154,13 +150,12 @@ def set_up(self, f, g, operator, tau=None, sigma=None, \
self.prob = [1/self.ndual_subsets] * self.ndual_subsets
self.sampler=Sampler.randomWithReplacement(self.ndual_subsets, prob=self.prob)
else:
if self.prob==None:
if self.sampler.prob!=None:
self.prob=self.sampler.prob
else:
self.prob = [1/self.ndual_subsets] * self.ndual_subsets
if self.sampler.prob!=None:
self.prob=self.sampler.prob
else:
warnings.warn('You supplied both probabilites and a sampler. The sampler will be used for sampling and the probabilites for calculationg step sizes, if not explicitly set.')
self.prob = [1/self.ndual_subsets] * self.ndual_subsets
if self.prob!=None:
warnings.warn('You supplied both probabilities and a sampler. The given probabilities will be ignored.')



Expand Down

0 comments on commit ba35fb8

Please sign in to comment.