当前位置: 首页>>代码示例>>Python>>正文


Python LinearAlgebra.shifts_to_curve方法代码示例

本文整理汇总了Python中LinearAlgebra.shifts_to_curve方法的典型用法代码示例。如果您正苦于以下问题:Python LinearAlgebra.shifts_to_curve方法的具体用法?Python LinearAlgebra.shifts_to_curve怎么用?Python LinearAlgebra.shifts_to_curve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LinearAlgebra的用法示例。


在下文中一共展示了LinearAlgebra.shifts_to_curve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: find_geodesic_midpoint

# 需要导入模块: import LinearAlgebra [as 别名]
# 或者: from LinearAlgebra import shifts_to_curve [as 别名]
def find_geodesic_midpoint(start_point, end_point, number_of_inner_points, basis_rotation_matrix,
                           tangent_direction, codimension, metric_server_addresses, mass_matrix, authkey,
                           gtol=1e-5):
    """ This function computes the local geodesic curve joining start_point to end_point using a modified BFGS method.
    The modification arises from taking the implementation of BFGS and re-writing it to minimise the number
    of times the metric function is called.

    Args:
      start_point (numpy.array) :
          The first end point of the curve.
      end_point (numpy.array) :
          The last end point of the curve.
      number_of_inner_points (int) :
          The number of nodes along the curve, less the end points.
      basis_rotation_matrix (numpy.array) :
          The matrix computed as a result of the orthogonal_tangent_basis function.
      tangent_direction (numpy.array) :
          The tangent direction as computed by the SimulationClient.
      codimension (int) :
          The dimension of the problem minus 1. Computed from the atomistic simulation environment.
      metric_server_addresses :
          A list of tuples of the form (str, int) containing the hostnames and port numbers of the SimulationPotential
          instances.
      mass_matrix (numpy.array) :
          A diagonal NumPy array containing the masses of the molecular system as computed in the SimulationClient
          object.
      authkey (str) :
          The password used in order to communicate with the SimulationPotential instances.
      gtol (optional float) :
          The tolerance threshold for the BGFS method.

    Returns:
      numpy.array: The midpoint along the local geodesic curve.

    """

    # Determine the number of variable the BFGS method will be applied to
    number_of_variables = number_of_inner_points * codimension

    # Produce an initial guess for the minimum, in this case it will be that the straight line segment joining
    # start_point to end_point is the initial guess
    x0 = np.zeros(number_of_variables)

    # Allocate memory for the kth iterate
    xk = x0

    # Convert the description of the curve as shifts in the orthonormal hyperspace along the initial line to points in
    # the full space. See LinearAlgebra.shifts_to_curve for more details.
    curve = la.shifts_to_curve(start_point, end_point, xk, number_of_inner_points,
                            basis_rotation_matrix, tangent_direction, codimension)

    # Get the initial metric values along the starting curve.
    metric = get_metric(curve, number_of_inner_points, metric_server_addresses, authkey)

    # If the SimulationPotential couldn't be contacted then return None to close the SimulationClient
    if metric is None:
        return None

    # Obtain the initial gradient of the length functional along the curve
    gfk = GradLength(curve, metric, number_of_inner_points, mass_matrix, basis_rotation_matrix)

    # Create an identity matrix object
    I = np.eye(number_of_variables, dtype=int)

    # Initialise the memory to store the approximate Hessian matrix
    Hk = I

    # Compute the norm of the gradient in the L^{\infty} norm
    gnorm = np.amax(np.abs(gfk))

    # The main body of the BFGS calculation:
    # Repeat the method until the norm of the gradient of the length is sufficiently small.
    while gnorm > gtol:

        alpha1 = 1.0
        pk = -np.dot(Hk, gfk)

        phi0 = Length(curve, metric, number_of_inner_points, mass_matrix)
        phi1 = phi0
        derphi0 = np.dot(gfk, pk)
        derphi1 = derphi0

        isave = np.zeros((2,), np.intc)
        dsave = np.zeros((13,), float)
        task = b'START'

        # Perform the linesearch
        for i in xrange(30):
            stp, phi1, derphi1, task = minpack2.dcsrch(alpha1, phi1, derphi1, 1e-4, 0.9, 1e-14, task, 1e-8, 50,
                                                       isave, dsave)
            if task[:2] == b'FG':
                alpha1 = stp
                # Convert the description of the curve as shifts in the orthonormal hyperspace along the initial line
                # to points in the full space. See LinearAlgebra.shifts_to_curve for more details.
                curve = la.shifts_to_curve(start_point, end_point, xk + stp*pk, number_of_inner_points,
                                        basis_rotation_matrix, tangent_direction, codimension)

                # Get the initial metric values along the current trial.
                metric = get_metric(curve, number_of_inner_points, metric_server_addresses, authkey)

#.........这里部分代码省略.........
开发者ID:suttond,项目名称:MODOI,代码行数:103,代码来源:CustomBFGS.py


注:本文中的LinearAlgebra.shifts_to_curve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。