Пример #1
0
def simpleCurveWithAvoidPoint(start_range, goal_range, attractor_range, plot=False):
    # fig, ax = plt.subplots()
    start = unif(start_range[0], start_range[1])
    goal = unif(goal_range[0], goal_range[1])

    attractor_point = unif(attractor_range[0], attractor_range[1])
    avoid_point = attractor_point + np.random.rand(2) * 0.05

    distractor_1 = unif([0.1, 0.1], [0.9, 0.9])
    distractor_2 = unif([0.1, 0.1], [0.9, 0.9])

    ts = np.array([0.0, 0.5, 1.0])

    relevant_keypoints = np.array([start, attractor_point, goal])
    all_features = np.array([start, avoid_point, attractor_point, distractor_1, distractor_2, goal])
    spline = CubicSpline(ts, relevant_keypoints)

    true_xys = spline(np.linspace(0, 1, 100))
    unif_xys = equally_space_curve(true_xys, 100)

    if plot:
        # noisy_xys =  true_xys + np.random.randn(100, 2) * 0.02
        #ax.scatter(true_xys[:, 0], true_xys[:, 1], alpha=0.4, label='squashed')
        # ax.scatter(noisy_xys[:, 0], noisy_xys[:, 1], alpha=0.25)

        plt.scatter(unif_xys[:, 0], unif_xys[:, 1], label='uniform', alpha=0.5)
        plt.scatter(all_features[0:2, 0], all_features[0:2, 1], marker='x', c='r', s=40*2)
        # ax.scatter(avoid_point[0], avoid_point[1], s=30**2, alpha=0.3, c='r')
        # plt.add_artist(plt.Circle(avoid_point, radius=0.1, alpha=0.2, color='r'))
        plt.xlabel("x")
        plt.ylabel("y")
        plt.tight_layout()


    return all_features, unif_xys 
Пример #2
0
def movingSinWave(start_range, goal_range, attractor_range, plot=False):
    start = unif(start_range[0], start_range[1])
    goal = unif(goal_range[0], goal_range[1])

    attractor = unif(attractor_range[0], attractor_range[1])
    distractor_1 = unif([0.1, 0.1], [0.9, 0.9])
    distractor_2 = unif([0.1, 0.1], [0.9, 0.9])

    ts = np.array([0.0, 0.5, 1.0])
    relevant_keypoints = np.array([start, attractor, goal])
    spline = CubicSpline(ts, relevant_keypoints)


    true_xys = spline(np.linspace(0, 1, 100))
    unif_xys = equally_space_curve(true_xys, 100)

    sin_noise = np.sin(2 * np.linspace(0, np.pi * 2, len(unif_xys))) * 0.2
    unif_xys[:, 1] += sin_noise

    unif_xys = equally_space_curve(unif_xys, 100)

    all_features = np.array([start, attractor, distractor_1, distractor_2, goal])

    if plot:
        plt.scatter(unif_xys[:, 0], unif_xys[:, 1], label='uniform', alpha=0.5)
        plt.scatter(all_features[0:2, 0], all_features[0:2, 1], marker='x', c='r', s=40*2)
        plt.scatter(all_features[-1, 0], all_features[-1, 1], marker='x', c='r', s=40*2)
        plt.xlabel("x")
        plt.ylabel("y")
        plt.ylim(bottom=0, top=1)
        plt.tight_layout()


    return all_features, unif_xys
Пример #3
0
def simpleCurveWithTwoPatrols(start_range, goal_range, ar_1, ar_2, plot=False):
    start = unif(start_range[0], start_range[1])
    goal = unif(goal_range[0], goal_range[1])

    attractor_1 = unif(ar_1[0], ar_1[1])
    attractor_2 = unif(ar_2[0], ar_2[1])

    distractor_1 = unif([0.1, 0.1], [0.9, 0.9])
    distractor_2 = unif([0.1, 0.1], [0.9, 0.9])

    ts = np.array([0.0, 0.25, 0.75, 1.0])
    relevant_keypoints = np.array([start, attractor_1, attractor_2, goal])
    spline = CubicSpline(ts, relevant_keypoints)

    true_xys = spline(np.linspace(0, 1, 100))
    unif_xys = equally_space_curve(true_xys, 100)

    patrol_1 = unif_xys[25] + unif([-0.05, 0.05], [-0.1, 0.1])
    patrol_2 = unif_xys[75] + unif([0.05, -0.05], [0.1, -0.1])

    all_features = np.array([start, patrol_1, patrol_2,
                             attractor_1, attractor_2, distractor_1, distractor_2, goal])

    if plot:
        plt.scatter(unif_xys[:, 0], unif_xys[:, 1], label='uniform', alpha=0.5)
        plt.scatter(all_features[0:3, 0], all_features[0:3, 1], marker='x', c='r', s=40*2)
        plt.xlabel("x")
        plt.ylabel("y")
        plt.tight_layout()


    return all_features, unif_xys
Пример #4
0
 def agents_setup(self):
     '''
     Create N agents, with random positions and starting headings.
     '''
     N = int(self.density * self.height * self.width)
     for i in range(1, N + 1):
         x = self.width * self.random.random()
         if self.random.random() < 1 / 2:
             y = unif(0, self.height / 2)
             direction = False  # ->
         else:
             y = unif(self.height / 2, self.height)
             direction = True  # <-
         pos = np.array([x, y])
         agent = Pedestrian(i, self, (x, y), direction)
         self.space.place_agent(agent, pos)
         self.schedule.add(agent)
Пример #5
0
def vuelos(numero):
    muestra = []
    for _ in range(numero):
        Y = np.array([g + unif(-e, e) for e, g in zip(perturbacion, goal)])
        vuelo, acciones = simulador(Y, Ze, 30, 800, jac=jac_f)
        for estado, accion in zip(vuelo, acciones):
            nuevo_estado = funcion(estado)
            muestra.append(np.concatenate((accion, nuevo_estado), axis=None))
    matriz = np.reshape(muestra, (799 * numero, 22))
    with open('tablaaaaaaa.csv', 'w', newline='', encoding='utf-8') as csvfile:
        writer = csv.writer(csvfile)
        writer.writerows(muestra)
Пример #6
0
def unevenSpeeds(start_range, goal_range, attractor_range, plot=False):
    start = unif(start_range[0], start_range[1])
    goal = unif(goal_range[0], goal_range[1])

    attractor = unif(attractor_range[0], attractor_range[1])
    distractor_1 = unif([0.1, 0.1], [0.9, 0.9])
    distractor_2 = unif([0.1, 0.1], [0.9, 0.9])

    ts = np.array([0.0, 0.5, 1.0])
    relevant_keypoints = np.array([start, attractor, goal])
    spline = CubicSpline(ts, relevant_keypoints)

    true_xys = spline(np.linspace(0, 1, 100))
    unif_xys = equally_space_curve(true_xys, 100)

    uneven_xys = np.concatenate((
        equally_space_curve(unif_xys[0:30], 40),
        equally_space_curve(unif_xys[30:70], 20),
        equally_space_curve(unif_xys[70:], 40)
    ))

    # print("Diffs: ", np.linalg.norm(uneven_xys[:-1] - uneven_xys[1:],  axis=1))
    # unif_xys = equally_space_curve(unif_xys, 100)

    all_features = np.array([start, attractor, distractor_1, distractor_2, goal])

    if plot:
        # plt.scatter(unif_xys[:, 0], unif_xys[:, 1], label='uniform', alpha=0.5)
        plt.scatter(uneven_xys[:, 0], uneven_xys[:, 1], label='uniform', alpha=0.5)
        plt.scatter(all_features[0:2, 0], all_features[0:2, 1], marker='x', c='r', s=40*2)
        plt.scatter(all_features[-1, 0], all_features[-1, 1], marker='x', c='r', s=40*2)
        plt.xlabel("x")
        plt.ylabel("y")
        plt.ylim(bottom=0, top=1)
        plt.tight_layout()


    return all_features, uneven_xys
Пример #7
0
        def randomize(xyz, missingness, extraness, random_extraness, stddev):
            to_return = []
            xyz = np.array(xyz)
            to_return.append(np.random.normal(xyz, stddev))

            # Extraness
            if np.random.binomial(1, 1 - extraness) == 0:
                for x in range(np.random.poisson(1)):
                    to_return.append(np.random.normal(xyz, stddev))

            # Random Extraness
            if np.random.binomial(1, 1 - random_extraness) == 0:
                for x in range(np.random.poisson(1)):
                    to_return.append(
                        np.array([
                            unif(low=x_range[0], high=x_range[1]),
                            unif(low=y_range[0], high=y_range[1]),
                            unif(low=z_range[0], high=z_range[1])
                        ]))

            # Missingness
            to_return = [] if (np.random.binomial(1, 1 - missingness)
                               == 0) else to_return
            return np.array(to_return)
Пример #8
0
    def data(self):
        """[summary]
        
        Raises:
            ValueError -- [if number of variable is less than 3, insuffieint to test MMI]
        
        Returns:
            [np array] -- [n_sample by n_variables matrix]
        """

        if self.n_variables < 2 or self.n_samples < 1:
            raise ValueError
        else:
            x = unif(self.low, self.high,
                     self.n_samples * (self.n_variables - 1)).reshape(
                         self.n_samples, self.n_variables - 1)
            x = np.append(x,
                          np.remainder(np.sum(x, axis=1), 1)[:, None],
                          axis=1)
            return x
Пример #9
0


demo_dir = "demos/splines2D-{}".format(t_stamp())

os.mkdir(demo_dir)
os.mkdir(demo_dir + "/train")
os.mkdir(demo_dir + "/val")

ts = np.array([0.0, 0.25, 0.75, 1.0])

fig, ax = plt.subplots()

# Training Data
for i in range(70):
    start = unif([0.0, 0.0], [0.1, 0.1])
    goal = unif([0.9, 0.9], [1.0, 1.0])
    c1 = unif([0.5, 0.05], [0.65, 0.25])
    c2 = unif([0.05, 0.5], [0.25, 0.65])
    distractor_1 = unif([0.3, 0.3], [0.7, 0.7])

    relevant_keypoints = np.array([start, c1, c2, goal])
    all_keypoints = np.array([start, c1, c2, distractor_1, goal])
    spline = CubicSpline(ts, relevant_keypoints)

    true_xys = spline(np.linspace(0, 1, 100))
    unif_xys = equally_space_curve(spline, 100)

    # noisy_xys =  true_xys + np.random.randn(100, 2) * 0.02
    #ax.scatter(true_xys[:, 0], true_xys[:, 1], alpha=0.4, label='squashed')
    # ax.scatter(noisy_xys[:, 0], noisy_xys[:, 1], alpha=0.25)
Пример #10
0
 def reset(self):
     x = self.width / 2 + unif(-2.5, 2.5)
     y = self.height / 2 + unif(-2.5, 2.5)
     phi = unif(0, 2 * pi)
     return np.array([x, y, phi])
 def reset(self):
     self.i = 0
     self.state = np.array(
         [max(0, g + unif(-e, e)) for e, g in zip(self.p, self.goal)])
     return self.state