Beispiel #1
0
  def _pour(self, a, shape, p):
    """

    Parameters
    ----------
    a: 1D np.ndarray or int
      The allowed values for to randomly select from
    shape: list of ints
      The shape of the outputted array of random values.
    p: 1D np.ndarray of numbers 0 <= 0 <=1 that sum to one or None
      The probability with which to select each value from 'a'

    Returns
    -------
    dict(
      target: np.ndarray
        The randomly selected values
      a: 1D np.ndarray or int
        The allowed values for to randomly select from
      p: 1D np.ndarray of numbers 0 <= 0 <=1 that sum to one or None
        The probability with which to select each value from 'a'
    )

    """
    target = np.random_choice(a, shape=shape, p=p)

    return {'target': target, 'a': ut.maybe_coppy(a), 'p': ut.maybe_coppy(p)}
def main():
    samplerate = 30000
    duration_sec = 10  # number of timepoints
    true_firing_rates_hz = [1, 2, 3, 4, 5]
    approx_false_negative_rates = [0, 0.1, 0.2, 0.3, 0.4]
    approx_false_positive_rates = [0, 0.2, 0.1, 0.4, 0.3]
    extra_unit_firing_rates_hz = [0.5, 1, 1.5]

    num_timepoints = samplerate * duration_sec

    sorting_true = se.NumpySortingExtractor()
    sorting = se.NumpySortingExtractor()
    for ii in range(len(true_firing_rates_hz)):
        num_events = int(duration_sec * true_firing_rates_hz[ii])
        times0 = np.random.choice(np.arange(num_timepoints),
                                  size=num_events,
                                  replace=False).astype(float)
        num_hits = int((1 - approx_false_negative_rates[ii]) * num_events)
        hits = np.random.choice(times0, size=num_hits, replace=False)
        num_extra = int(approx_false_positive_rates[ii] * num_events)
        extra = np.random_choice(np.arange(num_timepoints),
                                 size=num_extra,
                                 replace=False).astype(float)
        times1 = np.sort(hits + extra)

        sorting_true.add_unit(ii + 1, times0)
        sorting.add_unit(ii + 1, times1)

    for ii in range(len(extra_unit_firing_rates_hz)):
        num_events = int(duration_sec * extra_unit_firing_rates_hz[ii])
        times0 = np.random.choice(np.arange(num_timepoints),
                                  size=num_events,
                                  replace=False).astype(float)
        sorting.add_unit(len(true_firing_rates_hz) + ii + 1, times0)
Beispiel #3
0
    def _pour(self, a, shape, p):
        """

    Parameters
    ----------
    a: 1D np.ndarray or int
      The allowed values for to randomly select from
    shape: list of ints
      The shape of the outputted array of random values.

    Returns
    -------
    dict(
      target: np.ndarray
        The randomly selected values
      a: 1D np.ndarray or int
        The allowed values for to randomly select from
    )

    """
        target = np.random_choice(a, shape=shape, p=p)

        return {
            'target': target,
            'a': ut.maybe_coppy(a),
            'p': ut.maybe_coppy(p)
        }
Beispiel #4
0
def sample_a(policy_f, theta, s):
    num_actions = theta.shape[1]

    action_probs = []
    for a in range(num_actions):
        action_probs.append(policy_f(theta, s, a))
    action = numpy.random_choice(num_actions, p=action_probs)
    return a
    def sample(self, mini_batchsize):
        current_size = min(self.mem_count, self.mem_size)
        idx = np.random_choice(current_size, mini_batchsize, replace=False)

        states = self.state_memory[idx]
        actions = self.action_memory[idx]
        rewards = self.reward_memory[idx]
        new_states = self.new_state_memory[idx]
        dones = self.done_memory[idx]

        return states, actions, rewards, new_states, dones
Beispiel #6
0
    def get_hash_generator(self, hash_kwargs):
        assert self.hash_type in ['tabulation', 'poly', 'random'] #implemented only. 

        if self.hash_type == 'tabulation':
            raise NotImplementedError()

        elif self.hash_type == 'poly':
            return lambda x: poly_hash(hash_kwargs['k'])(x)

        elif self.hash_type == 'random':
            return lambda x: np.random_choice([1,-1])
 def _retrieve(self, lower_bound, parent_idx = 0):
     left_child_idx = 2 * parent_idx + 1
     right_child_idx = left_child_idx + 1
     
     if left_child_idx >= len(self.tree):
         return parent_idx
     
     if self.tree(left_child_idx) == self.tree(right_child_idx):
         return self._retrieve(lower_bound, np.random_choice([left_child_idx, right_child_idx]))
     if lower_bound <= self.tree[left_child_idx]:
         return self._retrieve(lower_bound, left_child_idx)
     else:
         return self._retrieve(lower_bound - self.tree[left_child_idx], right_child_idx]
Beispiel #8
0
def create_wrong(file_path):
    folder = np.random.choice(glob.glob(file_path + "*"))
    while floder == "fatalab":
        folder = np.random.choice(glob.glob(file_path + "*"))
    mat = np.zeros((480, 640), dtype='float32')
    i = 0
    j = 0
    depth_file = np.random_choice(glob.glob(folder + "/*.dat"))
    with open(depth_file) as file:
        for line in file:
            vals = line.split('\t')
            for val in vals:
                if val == "\n": continue
                if int(val) > 1200 or int(val) == -1: val = 1200
                mat[i][j] = float(int(val))
                j += 1
                j = j % 640

            i += 1
        mat = np.asarry(mat)
    mat_small = mat[140:340, 220:420]
    mat_small = (mat_small - np.mean(mat_small)) / np.max(mat_small)

    plt.imshow(mat_small)
    plt.show()

    folder2 = np.random.choice(glob.glob(file_path + "*"))
    while folder == folder2 or folder2 == "datalab":  #it activates if it chose the same folder
        folder2 = np.random.choice(glob.glob(file_path + "*"))
    mat2 = np.zeros((480, 640), dtype='float32')
    i = 0
    j = 0
    depth_file = np.random.choice(glob.glob(folder2 + "/*.dat"))
    with open(depth_file) as file:
        for line in file:
            vals = line.split('\t')
            for val in vals:
                if val == "\n": continue
                if int(val) > 1200 or int(val) == -1: val = 1200
                mat2[i][j] = float(int(val))
                j += 1
                j = j % 640

            i += 1
        mat2 = np.asarray(mat2)
    mat2_small = mat2[140:340, 220:420]
    mat2_small = (mat2_small - np.mean(mat2_small)) / np.max(mat2_small)
    plt.imshow(mat2_small)
    plt.show()

    return np.array([mat_small, mat2_small])
Beispiel #9
0
 def allocate_group(self, genotype):
     na = 0
     self.agents = []
     while na < n_agents:
         allocate = True
         ax = np.random.randint(200, self.worldx - 200)
         ay = np.random.randint(200, self.worldy - 200)
         ae = 50
         ao = ag_o + np.random_choice([0, 90, 180, 270])
         new_agent = ag.Agent(genotype, ax, ay, ao, ae, self.dt,
                              self.worldx, self.worldy)
         for agent in self.agents:
             if new_agent.area.intersects(agent.area):
                 allocate = False
         if allocate:
             self.agents.append(new_agent)
             na += 1