def inverse_kinematic_optimization(chain, target_frame, starting_nodes_angles, regularization_parameter=None, max_iter=None):
<EOL>target = target_frame[:<NUM_LIT:3>, <NUM_LIT:3>]<EOL>if starting_nodes_angles is None:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>def optimize_target(x):<EOL><INDENT>y = chain.active_to_full(x, starting_nodes_angles)<EOL>squared_distance = np.linalg.norm(chain.forward_kinematics(y)[:<NUM_LIT:3>, -<NUM_LIT:1>] - target)<EOL>return squared_distance<EOL><DEDENT>if regularization_parameter is not None:<EOL><INDENT>def optimize_total(x):<EOL><INDENT>regularization = np.linalg.norm(x - starting_nodes_angles[chain.first_active_joint:])<EOL>return optimize_target(x) + regularization_parameter * regularization<EOL><DEDENT><DEDENT>else:<EOL><INDENT>def optimize_total(x):<EOL><INDENT>return optimize_target(x)<EOL><DEDENT><DEDENT>real_bounds = [link.bounds for link in chain.links]<EOL>real_bounds = chain.active_from_full(real_bounds)<EOL>options = {}<EOL>if max_iter is not None:<EOL><INDENT>options["<STR_LIT>"] = max_iter<EOL><DEDENT>res = scipy.optimize.minimize(optimize_total, chain.active_from_full(starting_nodes_angles), method='<STR_LIT>', bounds=real_bounds, options=options)<EOL>logs.manager.info("<STR_LIT>".format(res.nit))<EOL>return chain.active_to_full(res.x, starting_nodes_angles)<EOL>
Computes the inverse kinematic on the specified target with an optimization method

Parameters
----------
chain: ikpy.chain.Chain
    The chain used for the Inverse kinematics.
target_frame: numpy.array
    The desired target.
starting_nodes_angles: numpy.array
    The initial pose of your chain.
regularization_parameter: float
    The coefficient of the regularization.
max_iter: int
    Maximum number of iterations for the optimisation algorithm.