def __init__(self, params: ExpertParams, creator: TensorCreator = torch): """Initialises the flock. Args: params: parameters of the flock, see ExpertParams form default values. creator: """ super_params = params.clone() super_params.spatial.buffer_size = 1 # these are just internal buffers local to each expert, # they do not learn from them. super().__init__(super_params, creator) super()._validate_universal_params(params) self._validate_conv_learning_params(params) float_dtype = get_float(self._device) # Common buffer where each flock stores data and from which they learn. self.common_buffer = SPFlockBuffer( creator=creator, flock_size=1, buffer_size=params.spatial.buffer_size, input_size=self.input_size, n_cluster_centers=self.n_cluster_centers) # The initial clusters are randomised self.common_cluster_centers = creator.randn( (1, self.n_cluster_centers, self.input_size), device=self._device, dtype=float_dtype) # Virtual replications of the common cluster centers, mainly for observation purposes. self.cluster_centers = self.common_cluster_centers.expand( self.flock_size, self.n_cluster_centers, self.input_size) # For keeping track of which clusters are being boosted and for how long self.cluster_boosting_durations = creator.full( (1, self.n_cluster_centers), fill_value=self.cluster_boost_threshold, device=self._device, dtype=creator.int64) self.prev_boosted_clusters = creator.zeros((1, self.n_cluster_centers), device=self._device, dtype=creator.uint8) # For holding the targets and deltas of the cluster centers self.cluster_center_targets = creator.zeros( (1, self.n_cluster_centers, self.input_size), device=self._device, dtype=float_dtype) self.cluster_center_deltas = creator.zeros( (1, self.n_cluster_centers, self.input_size), device=self._device, dtype=float_dtype) self.boosting_targets = creator.zeros((1, self.n_cluster_centers), device=self._device, dtype=creator.int64) self.tmp_boosting_targets = creator.zeros((1, self.n_cluster_centers), device=self._device, dtype=creator.int64) # There only needs to be one learning counter as only one expert learns in the convolutional case, # but we need the expanded version for cluster observer. self.common_execution_counter_learning = creator.zeros( (1, 1), device=self._device, dtype=creator.int64) self.execution_counter_learning = self.common_execution_counter_learning.expand( self.flock_size, 1)
def __init__(self, creator: TensorCreator): super().__init__('cpu') self.output = creator.randn((1, ))