Код: Выделить всё
def get_angles(x):
beta0 = 2 * np.arcsin(np.sqrt(x[1] ** 2) / np.sqrt(x[0] ** 2 + x[1] ** 2 + 1e-12))
beta1 = 2 * np.arcsin(np.sqrt(x[2] ** 2) / np.sqrt(x[2] ** 2 + x[2] ** 2 + 1e-12))
beta2 = 2 * np.arcsin(np.linalg.norm(x[2:]) / np.linalg.norm(x))
return np.array([beta2, -beta1 / 2, beta1 / 2, -beta0 / 2, beta0 / 2])
Код: Выделить всё
input_features = [10, 20, 30, 40, 50]`
# Transform the features
features = np.array(get_angles(input_features))
Заранее спасибо.
Ожидаем получения input_features после запуска окончательных функций с помощью функции get_reverse_angles я попробовал несколько вариантов функции get_reverse_angles, таких как приведенный ниже, но безрезультатно.
Код: Выделить всё
def get_reverse_angles(angles):
# Extract the angles
beta2, neg_beta1, pos_beta1, neg_beta0, pos_beta0 = angles
# Solve for x using trigonometric equations
x0 = np.sqrt(2)
x1 = np.sin(beta2 / 2) * np.sqrt(2)
x2 = np.sin(pos_beta1 / 2) * np.sqrt(2)
x3 = np.sin(pos_beta0 / 2) * np.sqrt(2)
x4 = np.sin(neg_beta0 / 2) * np.sqrt(2)
# Compute x0 using the first equation
x0 = np.sqrt(x1 ** 2 + x2 ** 2 + x3 ** 2 + x4 ** 2)
# Return the values of the reversed operation
return np.array([x0, x1 * x0, x2 * x0, x3 * x0, x4 * x0])
Подробнее здесь: https://stackoverflow.com/questions/781 ... put-values