def __init__(
        self,
        debug=False,
        n_inputs=None,
    ):
        """
        Configure the featurizer.

        Parameters
        ---------
        debug: boolean
        n_inputs : int
            The number of inputs (cables) that each Ziptie will be
            equipped to handle.
        """
        self.debug = debug

        # name: string
        #     A label for this object.
        self.name = 'featurizer'

        # epsilon: float
        #     A constant small theshold used to test for significant
        #     non-zero-ness.
        self.epsilon = 1e-8

        # n_inputs: int
        #     The maximum numbers of inputs and bundles
        #     that this level can accept.
        self.n_inputs = n_inputs

        # TODO:
        # Move input filter and ziptie creation into step,
        # along with clustering.

        # filter: InputFilter
        #     Reduce the possibly large number of inputs to the number
        #     of cables that the Ziptie can handle. Each Ziptie will
        #     have its own InputFilter.
        self.filter = InputFilter(
            n_inputs=self.n_inputs,
            name='ziptie_0',
            debug=self.debug,
        )
        # ziptie: Ziptie
        #     The ziptie is an instance of the Ziptie algorithm class,
        #     an incremental method for bundling inputs. Check out
        #     ziptie.py for a complete description. Zipties note which
        #     inputs tend to be co-active and creates bundles of them.
        #     This feature creation mechanism results in l0-sparse
        #     features, which sparsity helps keep Becca fast.
        self.ziptie = Ziptie(n_cables=self.n_inputs, debug=self.debug)

        # n_features: int
        #     The total number of features that have been colllected so far.
        #     This includes the cable candidate pools from each ziptie.
        self.n_features_by_level = [0, 0]

        # mapping: 2D array of ints
        #     The transformation from candidates (List or arrays of values)
        #     to the feature pool.
        #     If there is a one at [row_i, col_j] then
        #     candidate row_i maps to feature index col_j .
        #         feature_pool = np.matmul(candidates, self.mapping)
        self.mapping = np.zeros((0, 0), dtype=np.int)
Ejemplo n.º 2
0
    def __init__(
            self,
            n_inputs,
            # max_n_features=None,
            threshold=None,
            verbose=False,
            ):
        """
        Configure the featurizer.

        Parameters
        ---------
        n_inputs : int
            The number of inputs (cables) that each Ziptie will be
            equipped to handle.
        threshold : float
            See Ziptie.nucleation_threshold
        """
        # verbose : boolean
        #     Print out extra information about the featurizer's operation.
        self.verbose = verbose

        # name : string
        #     A label for this object.
        self.name = 'featurizer'

        # epsilon : float
        #     A constant small theshold used to test for significant
        #     non-zero-ness.
        self.epsilon = 1e-8

        # n_inputs : int
        # n_bundles : int
        # max_n_features : int
        #     The maximum numbers of inputs, bundles and features
        #     that this level can accept.
        #     max_n_features = n_inputs + n_bundles
        self.n_inputs = n_inputs
        # self.max_n_features = self.n_inputs
        self.n_bundles = 4 * self.n_inputs
        # if max_n_features is None:
        #     # Choose the total number of bundles (created features) allowed,
        #     # in terms of the number of inputs allowed.
        #     self.n_bundles = 3 * self.n_inputs
        #     self.max_n_features = self.n_inputs + self.n_bundles
        # else:
        #     self.max_n_features = max_n_features
        #     self.n_bundles = self.max_n_features - self.n_inputs

        # Normalization constants.
        # input_max : array of floats
        #     The maximum of each input's activity.
        #     Start with the assumption that each input has a
        #     maximum value of zero. Then adapt up from there
        #     based on the incoming observations.
        # input_max_decay_time, input_max_grow_time : float
        #     The time constant over which maximum estimates are
        #     decreased/increased. Growing time being lower allows the
        #     estimate to be weighted toward the maximum value.
        #self.input_max = np.zeros(self.n_inputs)
        #self.input_max_grow_time = 1e2
        #self.input_max_decay_time = self.input_max_grow_time * 1e2

        # input_activities,
        # bundle_activities,
        # feature_activities : array of floats
        #     inputs, bundles and features are characterized by their
        #     activity--their level of activation at each time step.
        #     Activity for each input or bundle or feature
        #     can vary between zero and one.
        #self.input_activities = np.zeros(self.n_inputs)
        #self.bundle_activities = np.zeros(self.n_bundles)
        #self.feature_activities = np.zeros(self.max_n_features)

        # live_features : array of floats
        #     A binary array tracking which of the features have ever
        #     been active.
        # self.live_features = np.zeros(self.max_n_features)

        # TODO:
        # Move input filter and ziptie creation into step,
        # along with clustering.

        # filter: InputFilter
        #     Reduce the possibly large number of inputs to the number
        #     of cables that the Ziptie can handle. Each Ziptie will
        #     have its own InputFilter.
        self.filter = InputFilter(
            n_inputs_final = self.n_inputs,
            verbose=self.verbose,
        )
        # ziptie: Ziptie
        #     The ziptie is an instance of the Ziptie algorithm class,
        #     an incremental method for bundling inputs. Check out
        #     ziptie.py for a complete description. Zipties note which
        #     inputs tend to be co-active and creates bundles of them.
        #     This feature creation mechanism results in l0-sparse
        #     features, which sparsity helps keep Becca fast.
        self.ziptie = Ziptie(
            n_cables=self.n_inputs,
            n_bundles=self.n_bundles,
            threshold=threshold,
            verbose=self.verbose)
Ejemplo n.º 3
0
    def __init__(self, brain, max_num_inputs, max_num_features=None):
        """
        Configure the featurizer.

        Parameters
        ---------
        max_num_inputs : int
            See Featurizer.max_num_inputs.
        max_num_features : int
            See Featurizer.max_num_features.
        """
        # debug : boolean
        #     Print out extra information about the featurizer's operation.
        self.debug = False

        # name : string
        #     A label for this object.
        self.name = 'featurizer'

        # epsilon : float
        #     A constant small theshold used to test for significant
        #     non-zero-ness.
        self.epsilon = 1e-8

        # max_num_inputs : int
        # max_num_bundles : int
        # max_num_features : int
        #     The maximum numbers of inputs, bundles and features
        #     that this level can accept.
        #     max_num_features = max_num_inputs + max_num_bundles
        self.max_num_inputs = max_num_inputs
        if max_num_features is None:
            # Choose the total number of bundles (created features) allowed,
            # in terms of the number of inputs allowed.
            self.max_num_bundles = 3 * self.max_num_inputs
            self.max_num_features = self.max_num_inputs + self.max_num_bundles
        else:
            self.max_num_features = max_num_features
            self.max_num_bundles = self.max_num_features - self.max_num_inputs

        # Normalization constants.
        # input_max : array of floats
        #     The maximum of each input's activity.
        #     Start with the assumption that each input has a
        #     maximum value of zero. Then adapt up from there
        #     based on the incoming observations.
        # input_max_decay_time, input_max_grow_time : float
        #     The time constant over which maximum estimates are
        #     decreased/increased. Growing time being lower allows the
        #     estimate to be weighted toward the maximum value.
        self.input_max = np.zeros(self.max_num_inputs)
        self.input_max_grow_time = 1e2
        self.input_max_decay_time = self.input_max_grow_time * 1e2

        # input_activities,
        # bundle_activities,
        # feature_activities : array of floats
        #     inputs, bundles and features are characterized by their
        #     activity--their level of activation at each time step.
        #     Activity for each input or bundle or feature
        #     can vary between zero and one.
        self.input_activities = np.zeros(self.max_num_inputs)
        self.bundle_activities = np.zeros(self.max_num_bundles)
        self.feature_activities = np.zeros(self.max_num_features)

        # live_features : array of floats
        #     A binary array tracking which of the features have ever
        #     been active.
        self.live_features = np.zeros(self.max_num_features)

        # TODO:
        #     Move ziptie creation into step, along with clustering.

        # ziptie : Ziptie
        #     The ziptie is an instance of the Ziptie algorithm class,
        #     an incremental method for bundling inputs. Check out
        #     ziptie.py for a complete description. Zipties note which
        #     inputs tend to be co-active and creates bundles of them.
        #     This feature creation mechanism results in l0-sparse
        #     features, which sparsity helps keep Becca fast.
        self.ziptie = Ziptie(self.max_num_inputs,
                             num_bundles=self.max_num_bundles,
                             debug=self.debug)
Ejemplo n.º 4
0
    def __init__(
        self,
        debug=False,
        n_inputs=None,
        threshold=None,
    ):
        """
        Configure the featurizer.

        Parameters
        ---------
        debug: boolean
        n_inputs : int
            The number of inputs (cables) that each Ziptie will be
            equipped to handle.
        threshold : float
            See Ziptie.nucleation_threshold
        """
        self.debug = debug

        # name: string
        #     A label for this object.
        self.name = 'featurizer'

        # epsilon: float
        #     A constant small theshold used to test for significant
        #     non-zero-ness.
        self.epsilon = 1e-8

        # n_inputs: int
        #     The maximum numbers of inputs and bundles
        #     that this level can accept.
        self.n_inputs = n_inputs

        # TODO:
        # Move input filter and ziptie creation into step,
        # along with clustering.

        # filter: InputFilter
        #     Reduce the possibly large number of inputs to the number
        #     of cables that the Ziptie can handle. Each Ziptie will
        #     have its own InputFilter.
        self.filter = InputFilter(
            n_inputs = self.n_inputs,
            name='ziptie_0',
            debug=self.debug,
        )
        # ziptie: Ziptie
        #     The ziptie is an instance of the Ziptie algorithm class,
        #     an incremental method for bundling inputs. Check out
        #     ziptie.py for a complete description. Zipties note which
        #     inputs tend to be co-active and creates bundles of them.
        #     This feature creation mechanism results in l0-sparse
        #     features, which sparsity helps keep Becca fast.
        self.ziptie = Ziptie(
            n_cables=self.n_inputs,
            threshold=threshold,
            debug=self.debug)

        # mapping_to_features: list of lists
        #     Tracks which feature candidate index corresponds to each
        #     ziptie input. The first level list corresponds to
        #         0: inputs to ziptie level 0
        #         1: inputs to ziptie level 1
        #               (also bundles from ziptie level 0)
        #         2: inputs to ziptie level 2
        #               (also bundles from ziptie level 1)
        #         ...
        #     The second level list index of the feature candidate that
        #     each input maps to.
        self.mapping_to_features = [[]]
        # mapping_from_features: list of 2-tuples,
        #     The inverse of mapping_to_features. Tracks which input
        #    corresponds which each feature candidate.
        #     Each item is of the format
        #         (level, input index)
        self.mapping_from_features = []