def __init__(self, **kwargs): """ As minimal year 1970 is assumed, as maximal year the current year. """ DistanceFunction.__init__(self, **kwargs) self._min, self._now = 1970, date.today().year self._max_diff = (self._now - self._min) or 1
def __init__(self, no_rating=0, min_rating=1, max_rating=5, **kwargs): """ :param no_rating: The rating that unrated songs will have, e.g. 0 stars. :param min_rating: The minimal rating you will have e.g. 1 stars. :param max_rating: The maximal rating you will have e.g. 5 stars. """ DistanceFunction.__init__(self, **kwargs) self._min_rating = min_rating self._max_rating = max_rating self._no_rating = no_rating
def __init__(self, name, mask, config=DEFAULT_CONFIG): """Create a new session: :param name: The name of the session. Used to load it again from disk. :param mask: The mask. See :term:`Mask` :param config: A dictionary with config values. See :class:`DefaultConfig` for available keys. """ self._config = config self._name = name # Publicly readable attribute. self.mapping = {} # Make access to the mask more efficient self._mask = copy(mask) self._attribute_list = sorted(mask) self._listidx_to_key = {k: i for i, k in enumerate(self._attribute_list)} # Lookup tables for those attributes (fast access is crucial here) def make_index(idx, default_func): index = {} for key, descr in self._mask.items(): if descr[idx] is not None: index[key] = descr[idx] else: index[key] = default_func(key) return index # Import this locally, since we might get circular import otherway: from munin.distance import DistanceFunction from munin.provider import Provider # Build indices and set default values: self._key_to_providers = make_index(0, lambda key: Provider() ) self._key_to_distfuncs = make_index(1, lambda key: DistanceFunction(self._key_to_providers[key]) ) self._key_to_weighting = make_index(2, lambda key: 1.0 ) # Sum of the individual weights, pre-calculated once. self._weight_sum = sum((descr[2] for descr in mask.values())) # Create the associated database. self._database = Database(self) # Filtering related: self._filtering_enabled = config['recom_history_sieving'] self._recom_history = RecommendationHistory( penalty_map=config['recom_history_penalty'] ) # Publicly readable attribute. self.mapping = bidict()