lfd.tpsopt package¶
Class inheritance diagram¶
Submodules¶
lfd.tpsopt.batchtps module¶
-
class
lfd.tpsopt.batchtps.
GPUContext
(bend_coefs=None)[source]¶ Bases:
object
Class to contain GPU arrays
-
add_cld
(name, proj_mats, offset_mats, cloud_xyz, kernel, scale_params, update_ptrs=False)[source]¶ adds a new cloud to our context for batch processing
-
bidir_tps_cost
(other, bend_coef=1, outlierprior=0.1, outlierfrac=0.01, outliercutoff=0.01, T=0.005, norm_iters=10, sigma=1, return_components=False)[source]¶
-
get_target_points
(other, outlierprior=0.1, outlierfrac=0.01, outliercutoff=0.01, T=0.005, norm_iters=10)[source]¶ computes the target points for self and other using the current warped points for both
-
mapping_cost
(other, bend_coef=0.001, outlierprior=0.1, outlierfrac=0.01, outliercutoff=0.01, T=0.005, norm_iters=10)[source]¶ computes the error in the current mapping assumes that the target points have already been filled
-
setup_tgt_ctx
(cloud_xyz)[source]¶ returns a GPUContext where all the clouds are cloud_xyz and matched in length with this contex
assumes cloud_xyz is already downsampled and scaled
-
test_bending_cost
(other, bend_coef=0.001, outlierprior=0.1, outlierfrac=0.01, outliercutoff=0.01, T=0.005, norm_iters=10)[source]¶
-
test_get_targ
(other, T=0.005, outlierprior=0.1, outlierfrac=0.01, outliercutoff=0.01, norm_iters=10)[source]¶
-
test_mapping_cost
(other, bend_coef=0.001, outlierprior=0.1, outlierfrac=0.01, outliercutoff=0.01, T=0.005, norm_iters=10)[source]¶
-
test_norm_corr
(other, T=0.005, outlierprior=0.1, outlierfrac=0.01, outliercutoff=0.01, norm_iters=10)[source]¶
-
w_nd_ptrs
= None¶ TPS PARAM FORMAT [ np.zeros(DATA_DIM) ] [ trans_d ] [1 x d] [ np.eye(DATA_DIM) ] = [ lin_dd ] = [d x d] [np.zeros((np.zeros, DATA_DIM))] [ w_nd ] [n x d]
-
-
class
lfd.tpsopt.batchtps.
Globals
[source]¶ -
i
= 9¶
-
streams
= [<Mock name='mock()' id='140724508621392'>, <Mock name='mock()' id='140724508621648'>, <Mock name='mock()' id='140724507127440'>, <Mock name='mock()' id='140724508621776'>, <Mock name='mock()' id='140724508621904'>, <Mock name='mock()' id='140724508622032'>, <Mock name='mock()' id='140724508622160'>, <Mock name='mock()' id='140724508622288'>, <Mock name='mock()' id='140724508622416'>, <Mock name='mock()' id='140724508622544'>]¶
-
sync
= False¶
-
-
class
lfd.tpsopt.batchtps.
SrcContext
(bend_coefs=None)[source]¶ Bases:
lfd.tpsopt.batchtps.GPUContext
specialized class to handle source clouds includes support for warped trajectories as well
-
add_cld
(name, proj_mats, offset_mats, cloud_xyz, kernel, scale_params, r_traj, r_traj_K, l_traj, l_traj_K, update_ptrs=False)[source]¶ does the normal add, but also adds the trajectories
-
-
class
lfd.tpsopt.batchtps.
TgtContext
(src_ctx)[source]¶ Bases:
lfd.tpsopt.batchtps.GPUContext
specialized class to handle the case where we are mapping to a single target cloud –> only allocate GPU Memory once
lfd.tpsopt.clouds module¶
lfd.tpsopt.culinalg_exts module¶
-
lfd.tpsopt.culinalg_exts.
batch_sum
(a_arr_gpu, a_ptr_gpu)[source]¶ computes a sum of all of the arrays pointed to by a_arr_gpu and a_ptr_gpu
-
lfd.tpsopt.culinalg_exts.
dot_batch
(a_arr_gpu, b_arr_gpu, a_ptr_gpu, b_ptr_gpu, transa='N', transb='N')[source]¶
-
lfd.tpsopt.culinalg_exts.
dot_batch_nocheck
(a_arr_gpu, b_arr_gpu, c_arr_gpu, a_ptr_gpu, b_ptr_gpu, c_ptr_gpu, transa='N', transb='N', a=1, b=1, handle=None)[source]¶ Implementation of batched dot products using cuda.
- a_arr_gpu : list of pycuda.gpuarray.GPUArray
- Input array.
- b_arr_gpu : list of pycuda.gpuarray.GPUArray
- Input array.
- c_arr_gpu : list of pycuda.gpuarray.GPUArray
- Input/Output array.
- a_ptr_gpu : pycuda.gpuarray.GPUArray
- Array of pointers to arrays in a_arr_gpu
- b_ptr_gpu : pycuda.gpuarray.GPUArray
- Array of pointers to arrays in b_arr_gpu
- c_ptr_gpu : pycuda.gpuarray.GPUArray
- Array of pointers to arrays in c_arr_gpu
- transa : char
- If ‘T’, compute the product of the transpose of a_arr_gpu[i]. If ‘C’, compute the product of the Hermitian of a_arr_gpu[i].
- transb : char
- If ‘T’, compute the product of the transpose of b_arr_gpu[i]. If ‘C’, compute the product of the Hermitian of b_arr_gpu[i].
- handle : int
- CUBLAS context. If no context is specified, the default handle from scikits.cuda.misc._global_cublas_handle is used.
None. Output is stored into the arrays in c_arr_gpu
The input matrices must all contain elements of the same data type. All matrics in a list must have same size.
>>> import pycuda.driver >>> import pycuda.autoinit >>> from pycuda import gpuarray >>> import numpy as np >>> from scikits.cuda import linalg >>> linalg.init() >>> a_arr = [np.asarray(np.random.rand(4, 2), np.float32) for i in range(10)] >>> b_arr = [np.asarray(np.random.rand(2, 2), np.float32) for i in range(10)] >>> c_arr = [np.asarray(np.random.rand(4, 2), np.float32) for i in range(10)] >>> a_arr_gpu = [gpuarray.to_gpu(a_gpu) for a_gpu in a_arr] >>> b_arr_gpu = [gpuarray.to_gpu(b_gpu) for b_gpu in b_arr] >>> c_arr_gpu = [gpuarray.to_gpu(c_gpu) for c_gpu in c_arr] >>> a_ptr_gpu = gpuarray.to_gpu(np.asarray([int(a_gpu.gpudata) for a_gpu in a_arr_gpu])) >>> b_ptr_gpu = gpuarray.to_gpu(np.asarray([int(b_gpu.gpudata) for b_gpu in b_arr_gpu])) >>> c_ptr_gpu = gpuarray.to_gpu(np.asarray([int(c_gpu.gpudata) for c_gpu in c_arr_gpu])) >>> linalg.dot_batch_nocheck(a_arr_gpu, b_arr_gpu, c_arr_gpu, a_ptr_gpu, b_ptr_gpu, c_ptr_gpu) >>> for i in range(10): ... print np.allclose(np.dot(a_arr[i], b_arr[i]) + c_arr[i], c_arr_gpu[i].get()) ... True True True True True True True True True True >>>
-
lfd.tpsopt.culinalg_exts.
geam
(a_gpu, b_gpu, c_gpu, transa='N', transb='N', alpha=1, beta=1, handle=None)[source]¶
lfd.tpsopt.precompute module¶
-
lfd.tpsopt.precompute.
get_exact_solver
(x_na, K_nn, bend_coefs, rot_coef)[source]¶ precomputes several of the matrix products needed to fit a TPS w/o the approximations for the batch computation
a TPS is fit by solving the system N’(Q’WQ +O_b)N z = -N’(Q’W’y - N’R) x = Nz
This function returns a tuple N, QN, N’O_bN, N’R where N’O_bN is a dict mapping the desired bending coefs to the appropriate product
-
lfd.tpsopt.precompute.
get_sol_params
(x_na, K_nn, bend_coef, rot_coef)[source]¶ precomputes the linear operators to solve this linear system. only dependence on data is through the specified targets
all thats needed is to compute the righthand side and do a forward solve
-
lfd.tpsopt.precompute.
gripper_joint2gripper_l_finger_joint_values
(gripper_joint_vals)[source]¶ Only the %s_gripper_l_finger_joint%lr can be controlled (this is the joint returned by robot.GetManipulator({“l”:”leftarm”, “r”:”rightarm”}[lr]).GetGripperIndices()) The rest of the gripper joints (like %s_gripper_joint%lr) are mimiced and cannot be controlled directly
lfd.tpsopt.registration module¶
Register point clouds to each other
arrays are named like name_abc abc are subscripts and indicate the what that tensor index refers to
- index name conventions:
- m: test point index n: training point index a: input coordinate g: output coordinate d: gripper coordinate
-
lfd.tpsopt.registration.
loglinspace
(a, b, n)[source]¶ n numbers between a to b (inclusive) with constant ratio between consecutive numbers
-
lfd.tpsopt.registration.
registration_cost
(xyz0, xyz1, f_p_mats=None, f_o_mats=None, b_p_mats=None, b_o_mats=None)[source]¶
-
lfd.tpsopt.registration.
tps_rpm_bij
(x_nd, y_md, fsolve, gsolve, n_iter=20, reg_init=0.1, reg_final=0.001, rad_init=0.1, rad_final=0.005, rot_reg=0.001, outlierprior=0.1, outlierfrac=0.2, vis_cost_xy=None, return_corr=False, check_solver=False)[source]¶ tps-rpm algorithm mostly as described by chui and rangaran reg_init/reg_final: regularization on curvature rad_init/rad_final: radius for correspondence calculation (meters) plotting: 0 means don’t plot. integer n means plot every n iterations
lfd.tpsopt.settings module¶
lfd.tpsopt.tps module¶
Functions for fitting and applying thin plate spline transformations
-
lfd.tpsopt.tps.
solve_eqp1
(H, f, A)[source]¶ solve equality-constrained qp min tr(x’Hx) + sum(f’x) s.t. Ax = 0
-
lfd.tpsopt.tps.
tps_apply_kernel
(distmat, dim)[source]¶ - if d=2:
- k(r) = 4 * r^2 log(r)
- d=3:
- k(r) = -r
import numpy as np, scipy.spatial.distance as ssd x = np.random.rand(100,2) d=ssd.squareform(ssd.pdist(x)) print np.clip(np.linalg.eigvalsh( 4 * d**2 * log(d+1e-9) ),0,inf).mean() print np.clip(np.linalg.eigvalsh(-d),0,inf).mean()
Note the actual coefficients (from http://www.geometrictools.com/Documentation/ThinPlateSplines.pdf) d=2: 1/(8*sqrt(pi)) = 0.070523697943469535 d=3: gamma(-.5)/(16*pi**1.5) = -0.039284682964880184
-
lfd.tpsopt.tps.
tps_cost
(lin_ag, trans_g, w_ng, x_na, y_ng, bend_coef, K_nn=None, return_tuple=False, wt_n=None)[source]¶ XXX doesn’t include rotation cost
-
lfd.tpsopt.tps.
tps_cost_regrot
(lin_ag, trans_g, w_ng, x_na, y_ng, bend_coef, rfunc, K_nn=None, wt_n=None)[source]¶ (Y-KA-XB-1C)’ W (Y-KA-XB-1C) + tr(A’KA) + r(B) subject to A’(X 1) = 0
-
lfd.tpsopt.tps.
tps_fit_fixedrot
(x_na, y_ng, bend_coef, lin_ag, K_nn=None, wt_n=None)[source]¶ minimize (Y-KA-XB-1C)’W(Y-KA-XB-1C) + tr(A’KA) + r(B)
-
lfd.tpsopt.tps.
tps_fit_regrot
(x_na, y_ng, bend_coef, rfunc, wt_n=None, max_iter=1, inner_max_iter=100, rgrad=None, l_init=None)[source]¶ minimize (Y-KA-XB-1C)’ W (Y-KA-XB-1C) + tr(A’KA) + r(B) subject to A’(X 1) = 0
-
lfd.tpsopt.tps.
tps_nr_cost_eval
(lin_ag, trans_g, w_ng, x_na, y_ng, xnr_ma, bend_coef, nr_coef, K_nn=None, return_tuple=False)[source]¶
lfd.tpsopt.transformations module¶
-
class
lfd.tpsopt.transformations.
EmptySolver
(max_N, bend_coefs)[source]¶ Bases:
object
pre-allocates the GPU space needed to get a new solver efficiently computes solution params and returns a TPSSolver
-
class
lfd.tpsopt.transformations.
NoGPUEmptySolver
(max_N, bend_coefs)[source]¶ Bases:
object
computes solution params and returns a NoGPUTPSSolver
-
class
lfd.tpsopt.transformations.
NoGPUTPSSolver
(bend_coefs, N, QN, NON, NR, x_nd, K_nn, rot_coef)[source]¶ Bases:
object
class to fit a thin plate spline to data using precomputed matrix products
-
class
lfd.tpsopt.transformations.
TPSSolver
(bend_coefs, N, QN, NON, NR, x_nd, K_nn, rot_coef, QN_gpu=None, WQN_gpu=None, NON_gpu=None, NHN_gpu=None)[source]¶ Bases:
object
class to fit a thin plate spline to data using precomputed matrix products
-
class
lfd.tpsopt.transformations.
ThinPlateSpline
(d=3)[source]¶ Bases:
lfd.tpsopt.transformations.Transformation
- members:
- x_na: centers of basis functions w_ng: lin_ag: transpose of linear part, so you take x_na.dot(lin_ag) trans_g: translation part
-
class
lfd.tpsopt.transformations.
Transformation
[source]¶ Bases:
object
Object oriented interface for transformations R^d -> R^d