Esempio n. 1
0
 def __init__(self,
              dataset,
              name,
              is_observed=True,
              batch_size=(),
              indices=()):
     self._type = "Empirical"
     ranges = {
         "dataset": geometric_ranges.UnboundedRange(),
         "batch_size": geometric_ranges.UnboundedRange(),
         "indices": geometric_ranges.UnboundedRange()
     }
     super().__init__(name,
                      dataset=dataset,
                      indices=indices,
                      learnable=False,
                      ranges=ranges,
                      is_observed=is_observed)
     self.distribution = distributions.EmpiricalDistribution()
     if batch_size:
         self.distribution.batch_size = batch_size
         self.batch_size = batch_size
     elif indices:
         self.distribution.batch_size = len(indices)
         self.batch_size = batch_size  #TODO: Clean up here
     else:
         raise ValueError(
             "Either the indices or the batch size has to be given as input"
         )
Esempio n. 2
0
    def __init__(self,
                 dataset,
                 name,
                 learnable=False,
                 has_bias=False,
                 is_observed=False,
                 batch_size=None,
                 indices=None,
                 weights=None):  #TODO: Ugly logic
        self._type = "Empirical"
        input_parameters = {
            "dataset": dataset,
            "batch_size": batch_size,
            "indices": indices,
            "weights": weights
        }
        ranges = {
            par_name: geometric_ranges.UnboundedRange()
            for par_name, par_value in input_parameters.items()
            if par_value is not None
        }
        kwargs = {
            par_name: par_value
            for par_name, par_value in input_parameters.items()
            if par_value is not None
        }
        super().__init__(name,
                         **kwargs,
                         learnable=learnable,
                         has_bias=has_bias,
                         ranges=ranges,
                         is_observed=is_observed)

        if not batch_size:
            if indices:
                batch_size = len(indices)
            else:
                raise ValueError(
                    "Either the indices or the batch size has to be given as input"
                )

        self.batch_size = batch_size
        self.distribution = distributions.EmpiricalDistribution(
            batch_size=batch_size, is_observed=is_observed)