Beispiel #1
0
    def evolve(self, pop):
        if len(pop) == 0:
            return pop
        sigma = 0.001
        alpha = 0.003  # learningrate

        # for each iteration, jitter around starting points, and move in the
        # best direction (weighted average jitter coordinates according to
        # fitness score)
        for i in range(self.iter):

            # get the population
            wl = pop.get_x()

            # do the jittering and selection
            j = 0
            for w in wl:
                #                 print(f"mutating {str(w)}")
                noise = np.random.randn(10, 3)
                wp = [[x, y, z]
                      for [x, y, z] in np.expand_dims(w, 0) + sigma * noise]
                #                 print(np.expand_dims(w, 0) + sigma * noise)

                R = np.array([-run_sim(wi, max_iter=1e7)[0] for wi in wp])
                R -= R.mean()
                R /= R.std()
                g = np.dot(R, noise)
                #                 print(f"R = {R}, g = {g}")
                u = alpha * g
                print(f"new individual = {str(u)}")
                w += u  # mutate the population/take the step

                pop.set_x(j, w)  # make the move previously selected
                j += 1
        return pop
Beispiel #2
0
def run_with_scaled_score(psi):
    score, success, _ = run_sim(psi, duration=200, max_iter=1e7)
    if not success:
        score += 1
        score *= 10
    score += psi[2]
    score = log(score)
    return score, success
            exit()
        x = self.xs[i]
        y = self.ys[i]
        print(x, y, self.Xs_moon[i]**2 + self.Ys_moon[i]**2)
        self.xdata.append(x)
        self.ydata.append(y)
        self.line.set_data(self.xdata, self.ydata)

        self.lunxdata.append(self.Xs_moon[i])
        self.lunydata.append(self.Ys_moon[i])
        self.moonline.set_data(self.lunxdata, self.lunydata)
        return self.line, self.moonline


score, success, path = run_sim(
    [3.794182930145708, 0.023901745288554, 3.090702702702703],
    duration=50,
    max_iter=1e7)
fig, ax = plt.subplots()
interval = 32
orbit = Orbit(path, ax, interval=interval)

# pass a generator in "emitter" to produce data for the update func
ani = animation.FuncAnimation(fig,
                              orbit.update,
                              range(int(len(path) / interval)),
                              interval=5,
                              blit=True)

plt.show()
Beispiel #4
0
        archi.evolve()
        #         print(archi) # prints description of islands contained in archipelago
        #         archi.wait()
        sols = archi.get_champions_f()
        idx = sols.index(min(sols))
        sols_x = archi.get_champions_x()
        sol = sols[idx], sols_x[idx]
    else:
        pop = pg.population(prob=prob, size=4)
        pop.set_x(0,
                  [-2.277654673852600, 0.047996554429844, 3.810000000000000])
        pop.set_x(1,
                  [-0.138042744751570, -0.144259374836607, 3.127288444444444])
        pop.set_x(2,
                  [-2.086814820119193, -0.000122173047640, 3.111181716545691])
        uda.evolve(pop)
        sol = (pop.champion_f, pop.champion_x)

    print("Done! best solution is:")
    print(sol)
    return sol


# In[ ]:

if __name__ == "__main__":
    Dv, psi = pygmo_es()
    path = run_sim(psi)
    orbitplot2d(path, psi)
    orbitplot_non_inertial(path, psi)
Beispiel #5
0
 def fitness(self, psi):
     res, _ = run_sim(psi, duration=50 / UNIT_TIME, max_iter=1e7)
     return [-res]
Beispiel #6
0
    idxs = []
    tally = 0
    for i in range(
            len(hs)
    ):  # each time step h, check whether the little tally has reached our threshold.
        h = hs[i]  # if it has, take that index as a time step
        tally += h
        if tally >= 3.5e-3:
            idxs.append(i)
            tally = 0
    return idxs


if __name__ == "__main__":
    fig = plt.figure()
    ax = fig.gca()
    cpath = run_sim([3.794183030145708, 0.023901845288554, 3.090703702702703],
                    duration=200)
    trajp = TrajPlot(cpath, ax)
    ani = animation.FuncAnimation(fig,
                                  trajp.update,
                                  range(len(trajp.idxs)),
                                  interval=0.1,
                                  blit=True)
    # plt.rcParams[
    #     "animation.convert_path"
    # ] = "C:\Program Files\ImageMagick-7.0.8-Q16\magick.exe"  # "/usr/local/bin/magick"
    # writer = ImageMagickFileWriter()
    # ani.save(f"{str(Path.home())}/animation.mp4", writer="ffmpeg", fps=90)
    plt.show()
Beispiel #7
0
def fitness(psi):
    score, success, _ = run_sim(psi, duration=200, max_iter=1e7)
    return [score, success]
Beispiel #8
0
    paths = args.p
    in_psi = args.psi
    # for x in range(10):
    #     psi = [rand() *2*pi, rand() * 2* pi, rand() * 4 / unit_velocity]
    #     path = launch_sim(psi)
    #     orbitplot2d(path, psi)
    # starttime=time.time()
    # psi = [-2.282942228154665, 0.0000, -31.49483130653266 / unit_velocity]
    # launch_sim(psi,max_iter=1000000)
    # print(round(time.time() - starttime, 3))

    starttime = time.time()
    if in_psi is not None and len(in_psi) == 3:
        # user defined
        psi = in_psi
        path = run_sim(psi, duration=100)
        orbitplot2d(path, psi, title="userdef")
        orbitplot_non_inertial(path, psi, title="userdef")
    if paths is not None:
        if "leo" in paths:
            # leo
            psi = [0.0, 0.0, 0.0]
            path = run_sim(psi, duration=0.0625)
            leo_plot(path, psi, title="leo")

        if "h" in paths:
            # hohmann
            psi = [-2.086814820119193, -0.000122173047640, 3.111181716545691]
            path = run_sim(psi, duration=5)
            orbitplot2d(path, psi, title="hohmann")
            orbitplot_non_inertial(path, psi, title="hohmann")
Beispiel #9
0
examples = [
    # ["hohmann", [-2.086814820119193, -0.000122173047640, 3.111181716545691], 5],
    [
        "long_leto", [3.794182930145708, 0.023901745288554, 3.090702702702703],
        200
    ],
    # ["short_leto", [-0.138042744751570, -0.144259374836607, 3.127288444444444], 41],
    # ["3-day_hohmann", [-2.272183066647597, -0.075821466029764, 3.135519748743719], 3],
    # ["1-day_hohmann", [-2.277654673852600, 0.047996554429844, 3.810000000000000], 1],
]  # [title, psi, duration]
for title, psi, duration in examples:
    psis = []
    paths = []
    for i in range(N):
        permute_psi = np.array(psi) + np.array([i * 1e-6, i * 1e-6, i * 1e-6])
        path = run_sim(permute_psi, max_iter=1e7, duration=duration)
        psis.append(permute_psi)
        paths.append(path)

    # In[26]:

    for i in range(len(paths)):
        orbitplot2d(
            paths[i],
            psis[i],
            filepath="./lyapunov_figs/trajectories",
            title=f"{title}_{i}",
        )
        orbitplot_non_inertial(
            paths[i],
            psis[i],
Beispiel #10
0
    array(
        [
            [0.00550597, 1.99977048, 3.08277011],
            [0.91305461, 0.99549021, 3.60492682],
            [-0.0872857, -2.00216414, 3.09651504],
            [0.07863384, 2.39300289, 3.20663878],
        ]
    ),
    array(
        [
            [0.00694828, 2.01226472, 3.07251364],
            [0.93132053, 0.98330834, 3.60007157],
            [-0.06441153, -1.96546595, 3.1115717],
            [0.09824729, 2.38089277, 3.18372714],
        ]
    ),
    array(
        [
            [-4.41284420e-05, 2.00728842e+00, 3.11817667e+00],
            [9.17913852e-01, 1.02732551e+00, 3.60458666e+00],
            [-6.13165263e-02, -1.97697217e+00, 3.12125154e+00],
            [1.06943150e-01, 2.41348942e+00, 3.21571327e+00],
        ]
    ),
]

for psi in x1:
    res = run_sim(psi, max_iter=1e7)
    orbitplot2d(res, psi)