def test_scalar_product_structured(): def kernel(x, y): return 1 structured_field0 = np.array([[0, 0], [0, 0], [1, 1], [0, 0]]) structured_field1 = np.array([[0, 0], [0, 0], [0, 0], [1, 1]]) assert pytest.approx( structured_vector_fields.scalar_product_structured( structured_field0, structured_field1, kernel)) == 0 assert pytest.approx( structured_vector_fields.scalar_product_structured( structured_field0, structured_field1, kernel) == 4)
def product(vect0, vect1): return struct.scalar_product_structured(vect0, vect1, kernel)
#%%% Visualize results def kernel_np(x, y): #si = tf.shape(x)[0] return np.exp(-sum([(x[i] - y[i])**2 for i in range(dim)]) / (sigma**2)) get_unstructured_op = struct.get_from_structured_to_unstructured( space, kernel_np) structured_computed = [] unstructured_computed = [] fac = [] for i in range(nbdatamax): structured_temp = struct.create_structured(points_list[i], np.dot(vectors_list[i], alpha)) prod = struct.scalar_product_structured(structured_temp, structured_list[i], kernel_np) squared_norm = struct.scalar_product_structured(structured_temp, structured_temp, kernel_np) fac.append(prod / squared_norm) structured_computed.append(structured_temp.copy()) unstructured_computed.append(get_unstructured_op(structured_temp).copy()) # for i in range(nbdatamax): get_unstructured_op(structured_list[i]).show( 'unstructured data {}'.format(i)) (fac[i] * unstructured_computed[i]).show( 'unstructured computed {}'.format(i)) # for i in range(nbdatamax):
def product(f, g): return struct.scalar_product_structured(f, g, kernel)