I have the following get_angles function that creates angles from input_features. The features returned by the function are being used to train a variational quantum circuit.
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])
As such:
input_features = [10, 20, 30, 40, 50]`
# Transform the features
features = np.array(get_angles(input_features))
Now, I would like to reverse this operation by taking the final features values and transforming them back into the input_features values used in the get_angles function. Is there a way to reverse the get_angles function defined above?
Thanks in advance.
Expecting to receive the input_features from running the final features through a get_reverse_angles function, I tried multiple variations of a get_reverse_angles function such as the one below to no avail.
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])
The get_reverse_angles function returned [ 1.79350156 2.41835701 0.97063605 1.33346136 -1.33346136] as opposed to the expected [10 20 30 40 50] input_features.
This answer is rewritten based on additional comments by @camaya :
input_features = [22393, 22962, 22689, 21849, 20979].So what do we have?!
Incoming data
input_features = [22393, 22962, 22689, 21849, 20979]- a list of unsorted integers.Three variables are declared in the
get_anglesfunction:(
input[:] == input_features ; def get_angles(x): return features[:])Step 1
Output to the console:
We are guaranteed to get the first two elements, but for this we used two nested for loops, the time complexity of this code is O(n^2) in the worst case.
Step 2
It is not possible to define the third element in the second step, you can only reduce the number of iterations for the third step.
Output to the console:
However, 43309 iterations of the first for loop is too expensive...
This is due to the fact that only one element input_features is used to calculate beta1 — this increases the inverse variability.
beta1 = 2 * np.arcsin(np.sqrt(x[2] ** 2) / np.sqrt(x[2] ** 2 + x[2] ** 2 + 1e-12))If it is acceptable to add one element to features for backward compatibility,
then the variability can be leveled.
Step 3
Output to the console:
Good. When you save the
input[2]you have the opportunity to get an acceptable result,but it is still not absolutely pure.
In addition, the duration of the recovery process is still very long.
Resume
We had to take these three steps to show that this approach is not effective enough.
When you process data that you will need in the future, keep the opportunity to access it.
At least this way...
You can go even further...
But that's a completely different story!