def barycenter_weights(X, Z, reg=0.001):
 X = check_array(X, dtype=FLOAT_DTYPES)
 Z = check_array(Z, dtype=FLOAT_DTYPES, allow_nd=True)
 (n_samples, n_neighbors) = (X.shape[0], Z.shape[1])
 B = np.empty((n_samples, n_neighbors), dtype=X.dtype)
 v = np.ones(n_neighbors, dtype=X.dtype)
 for (i, A) in enumerate(Z.transpose(0, 2, 1)):
  C = (A.T - X[i])
  G = np.dot(C, C.T)
  trace = np.trace(G)
  if (trace > 0):
   R = (reg * trace)
  else:
   R = reg
  G.flat[::(Z.shape[1] + 1)] += R
  w = solve(G, v, sym_pos=True)
  B[i, :] = (w / np.sum(w))
 return B

def barycenter_weights ( X , Z , reg = 0.001 ) : X = check_array ( X , dtype = FLOAT_DTYPES ) Z = check_array ( Z , dtype = FLOAT_DTYPES , allow_nd = True ) ( n_samples , n_neighbors ) = ( X . shape [ 0 ] , Z . shape [ 1 ] ) B = np . empty ( ( n_samples , n_neighbors ) , dtype = X . dtype ) v = np . ones ( n_neighbors , dtype = X . dtype ) for ( i , A ) in enumerate ( Z . transpose ( 0 , 2 , 1 ) ) : C = ( A . T - X [ i ] ) G = np . dot ( C , C . T ) trace = np . trace ( G ) if ( trace > 0 ) : R = ( reg * trace ) else : R = reg G . flat [ : : ( Z . shape [ 1 ] + 1 ) ] += R w = solve ( G , v , sym_pos = True ) B [ i , : ] = ( w / np . sum ( w ) ) return B
compute barycenter weights of x from y along the first axis we estimate the weights to assign to each point in y[i] to recover the point x[i] .