Пример #1
0
def plot_graph(dim,
               r=1,
               displace_value=1,
               sphere=False,
               d=1,
               k=2,
               nodes=False,
               method='CG',
               percentile=0,
               opt=None,
               tol=1.e-03,
               x0=None,
               tg=True,
               seed=None):
    if seed is None:
        seed = rn.random()
    ls = hl.create_lattice(dim, d)
    l = ls[0]
    l = hl.manipulate_lattice_absolute_value(l,
                                             ls[1],
                                             displace_value=displace_value)
    if sphere:
        ls = hl.create_lattice_sphere(dim, r**2, displace_value, d)
        l = ls[0]
    matrices = hl.dilute_lattice_point(hl.adjacency_matrix(l), percentile, l,
                                       seed)
    A = np.add(matrices[0], matrices[1])

    draw_initial_graph(A,
                       22,
                       generate_manipulated_plot_positions(
                           dim,
                           l,
                           r=r,
                           displace_value=displace_value,
                           sphere=sphere,
                           d=d,
                           k=k,
                           method=method,
                           percentile=percentile,
                           opt=opt,
                           tol=tol,
                           x0=x0,
                           tg=tg,
                           seed=seed),
                       l,
                       nodes=nodes,
                       dv=displace_value,
                       rad=r,
                       draw_sphere=sphere,
                       d=d)
Пример #2
0
def contour_coords(dim, displace_value, path, tol=.1):
    lattice = hl.create_lattice(dim, 1)
    l = hl.manipulate_lattice_absolute_value(lattice[0],
                                             lattice[1],
                                             displace_value=displace_value)
    res = import_pickle(path)
    values = hl.assemble_result(res.x,
                                hl.list_of_coordinates(l)[0],
                                plot=False)
    x = []
    z = []

    for i in range(len(values[0])):
        if abs(values[1][i]) <= tol:
            x.append(values[0][i])
            z.append(values[2][i])

    return x, z, res.fun
Пример #3
0
def calculate_distance(path, d=1, rad=None):
    v = hf.value_from_path(path)
    dim = int(v[0])
    dv = float(v[1])
    perc = float(v[2])
    seed = int(v[3])
    lattice = hl.create_lattice(dim, d)
    lattice = hl.manipulate_lattice_absolute_value(lattice[0], lattice[1], dv)
    if rad:
        lattice = hl.create_lattice_sphere(dim, rad**2, dv, d)[0]
    pic = pickle.load(open(path, 'rb'))
    distance = []
    x = pic.x
    adj = hl.dilute_lattice_point(hl.adjacency_matrix(lattice), perc, lattice,
                                  seed)
    mrows, mcols, imrows, imcols, e = hl.energy_func_prep(
        np.triu(adj[0]), np.triu(adj[1]), d)
    xs, no_use, xsdict, xdict = hl.list_of_coordinates(lattice)

    for i in range(len(mrows)):
        rpos = xdict[mrows[i]]
        cpos = xdict[mcols[i]]
        distance.append(((x[rpos] - x[cpos])**2 +
                         (x[rpos + 1] - x[cpos + 1])**2 +
                         (x[rpos + 2] - x[cpos + 2])**2)**.5 - e)

    for i in range(len(imrows)):
        if (lattice[imrows[i]].return_mobility() is
                True) and (lattice[imcols[i]].return_mobility() is False):
            rpos = xdict[imrows[i]]
            cpos = xsdict[imcols[i]]
            distance.append(((x[rpos] - xs[cpos])**2 +
                             (x[rpos + 1] - xs[cpos + 1])**2 +
                             (x[rpos + 2] - xs[cpos + 2])**2)**.5 - e)

        elif (lattice[imrows[i]].return_mobility() is
              False) and (lattice[imcols[i]].return_mobility() is True):
            rpos = xsdict[imrows[i]]
            cpos = xdict[imcols[i]]
            distance.append(((xs[rpos] - x[cpos])**2 +
                             (xs[rpos + 1] - x[cpos + 1])**2 +
                             (xs[rpos + 2] - x[cpos + 2])**2)**.5 - e)

    return distance
Пример #4
0
def single_plot_from_pickle(dim,
                            dv,
                            path,
                            perc=0,
                            seed=None,
                            d=1,
                            max_dist=None,
                            sphere=False,
                            rad=0):
    ls = hl.create_lattice(dim, d)
    l = ls[0]
    l = hl.manipulate_lattice_absolute_value(l, ls[1], displace_value=dv)
    if sphere:
        l = hl.create_lattice_sphere(dim, rad**2, dv, d)[0]
    matrices = hl.dilute_lattice_point(hl.adjacency_matrix(l), perc, l, seed)
    A = np.add(matrices[0], matrices[1])
    pos = {}
    pic = pickle.load(open(path, 'rb'))
    list_mobile_coords = pic.x
    print('Energy: ', pic.fun)

    for i in range(0, len(l)):
        if l[i].return_mobility():
            pos[i] = (list_mobile_coords[0], list_mobile_coords[1],
                      list_mobile_coords[2])

            list_mobile_coords = list_mobile_coords[3:]
        elif not l[i].return_mobility():
            vector = l[i].return_coordinates()
            pos[i] = (vector[0], vector[1], vector[2])

    plot.draw_initial_graph(A,
                            22,
                            pos,
                            l,
                            dv=dv,
                            rad=rad,
                            draw_sphere=sphere,
                            d=d,
                            max_dist=max_dist)
Пример #5
0
def energy_func_speedtest(dim, num, dv, d=1, k=2):
    lattice = hl.create_lattice(dim)
    l = hl.manipulate_lattice_absolute_value(lattice[0], lattice[1], 0.3)
    t1 = 0
    t2 = 0
    for i in range(num):
        start_time = time.time()
        energy1 = hl.run_absolute_displacement(dim,
                                               dv,
                                               jac_func=hl.energy_func_jac).fun
        end_time = time.time()
        dt = end_time - start_time
        print(dt)
        t1 += dt

        start_time = time.time()
        energy2 = hl.run_absolute_displacement(
            dim, dv, jac_func=hl.energy_func_jac_opt).fun
        end_time = time.time()
        dt = end_time - start_time
        print(dt)
        t2 += end_time - start_time

    return energy1, energy2, t1, t2