def _get_n_connections_from_pre_vertex_with_delay_maximum(
            self, delays, n_total_connections, n_connections, min_delay,
            max_delay, synapse_info):
        """ Get the expected number of delays that will fall within min_delay
            and max_delay given given a float, RandomDistribution or list of
            delays.

        :param delays:
        :type delays: ~numpy.ndarray or pyNN.random.NumpyRNG or int or float
            or list(int) or list(float)
        :param int n_total_connections:
        :param int n_connections:
        :param float min_delay:
        :param float max_delay:
        :rtype: float
        """
        if isinstance(delays, RandomDistribution):
            prob_in_range = utility_calls.get_probability_within_range(
                delays, min_delay, max_delay)
            return int(
                math.ceil(
                    utility_calls.get_probable_maximum_selected(
                        n_total_connections, n_connections, prob_in_range)))
        elif isinstance(delays, str):
            d = self._get_distances(delays, synapse_info)
            delays = _expr_context.eval(delays, d=d)
            n_delayed = sum([
                len([
                    delay for delay in delays
                    if min_delay <= delay <= max_delay
                ])
            ])
            if n_delayed == 0:
                return 0
            n_total = len(delays)
            prob_delayed = float(n_delayed) / float(n_total)
            return int(
                math.ceil(
                    utility_calls.get_probable_maximum_selected(
                        n_total_connections, n_connections, prob_delayed)))
        elif numpy.isscalar(delays):
            if min_delay <= delays <= max_delay:
                return int(math.ceil(n_connections))
            return 0
        elif hasattr(delays, "__getitem__"):
            n_delayed = sum([
                len([
                    delay for delay in delays
                    if min_delay <= delay <= max_delay
                ])
            ])
            if n_delayed == 0:
                return 0
            n_total = len(delays)
            prob_delayed = float(n_delayed) / float(n_total)
            return int(
                math.ceil(
                    utility_calls.get_probable_maximum_selected(
                        n_total_connections, n_connections, prob_delayed)))
        raise SpynnakerException("Unrecognised delay format")
Exemple #2
0
 def _get_n_connections_from_pre_vertex_with_delay_maximum(
         delays, n_total_connections, n_connections, connection_slices,
         min_delay, max_delay):
     """ Gets the expected number of delays that will fall within min_delay\
         and max_delay given given a float, RandomDistribution or list of\
         delays
     """
     if globals_variables.get_simulator().is_a_pynn_random(delays):
         prob_in_range = utility_calls.get_probability_within_range(
             delays, min_delay, max_delay)
         return int(
             math.ceil(
                 utility_calls.get_probable_maximum_selected(
                     n_total_connections, n_connections, prob_in_range)))
     elif numpy.isscalar(delays):
         if min_delay <= delays <= max_delay:
             return int(math.ceil(n_connections))
         return 0
     elif hasattr(delays, "__getitem__"):
         n_delayed = sum([
             len([
                 delay for delay in delays[connection_slice]
                 if min_delay <= delay <= max_delay
             ]) for connection_slice in connection_slices
         ])
         n_total = sum([
             len(delays[connection_slice])
             for connection_slice in connection_slices
         ])
         prob_delayed = float(n_delayed) / float(n_total)
         return int(
             math.ceil(
                 utility_calls.get_probable_maximum_selected(
                     n_total_connections, n_delayed, prob_delayed)))
     raise Exception("Unrecognised delay format")
 def _get_n_connections_from_pre_vertex_with_delay_maximum(
         self, delays, n_total_connections, n_connections, min_delay,
         max_delay):
     """ Get the expected number of delays that will fall within min_delay\
         and max_delay given given a float, RandomDistribution or list of\
         delays.
     """
     # pylint: disable=too-many-arguments
     if get_simulator().is_a_pynn_random(delays):
         prob_in_range = utility_calls.get_probability_within_range(
             delays, min_delay, max_delay)
         return int(
             math.ceil(
                 utility_calls.get_probable_maximum_selected(
                     n_total_connections, n_connections, prob_in_range)))
     elif numpy.isscalar(delays):
         if min_delay <= delays <= max_delay:
             return int(math.ceil(n_connections))
         return 0
     elif hasattr(delays, "__getitem__"):
         n_delayed = sum([
             len([
                 delay for delay in delays
                 if min_delay <= delay <= max_delay
             ])
         ])
         if n_delayed == 0:
             return 0
         n_total = len(delays)
         prob_delayed = float(n_delayed) / float(n_total)
         return int(
             math.ceil(
                 utility_calls.get_probable_maximum_selected(
                     n_total_connections, n_connections, prob_delayed)))
     raise Exception("Unrecognised delay format")
 def _get_n_connections_from_pre_vertex_with_delay_maximum(
         delays, n_total_connections, n_connections, connection_slices,
         min_delay, max_delay):
     """ Gets the expected number of delays that will fall within min_delay\
         and max_delay given given a float, RandomDistribution or list of\
         delays
     """
     if isinstance(delays, RandomDistribution):
         prob_in_range = utility_calls.get_probability_within_range(
             delays, min_delay, max_delay)
         return int(math.ceil(utility_calls.get_probable_maximum_selected(
             n_total_connections, n_connections, prob_in_range)))
     elif numpy.isscalar(delays):
         if min_delay <= delays <= max_delay:
             return int(math.ceil(n_connections))
         return 0
     elif hasattr(delays, "__getitem__"):
         n_delayed = sum([len([
             delay for delay in delays[connection_slice]
             if min_delay <= delay <= max_delay])
             for connection_slice in connection_slices])
         n_total = sum([
             len(delays[connection_slice])
             for connection_slice in connection_slices])
         prob_delayed = float(n_delayed) / float(n_total)
         return int(math.ceil(utility_calls.get_probable_maximum_selected(
             n_total_connections, n_delayed, prob_delayed)))
     raise Exception("Unrecognised delay format")
 def _get_n_connections_from_pre_vertex_with_delay_maximum(
         self, delays, n_total_connections, n_connections,
         min_delay, max_delay):
     """ Get the expected number of delays that will fall within min_delay\
         and max_delay given given a float, RandomDistribution or list of\
         delays.
     """
     # pylint: disable=too-many-arguments
     if get_simulator().is_a_pynn_random(delays):
         prob_in_range = utility_calls.get_probability_within_range(
             delays, min_delay, max_delay)
         return int(math.ceil(utility_calls.get_probable_maximum_selected(
             n_total_connections, n_connections, prob_in_range)))
     elif numpy.isscalar(delays):
         if min_delay <= delays <= max_delay:
             return int(math.ceil(n_connections))
         return 0
     elif hasattr(delays, "__getitem__"):
         n_delayed = sum([len([
             delay for delay in delays
             if min_delay <= delay <= max_delay])])
         if n_delayed == 0:
             return 0
         n_total = len(delays)
         prob_delayed = float(n_delayed) / float(n_total)
         return int(math.ceil(utility_calls.get_probable_maximum_selected(
             n_total_connections, n_connections, prob_delayed)))
     raise Exception("Unrecognised delay format")