Group Abstract Group Abstract

Message Boards Message Boards

0
|
3.6K Views
|
8 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Improving accuracy of neural network for determining qubit rotation angle

Posted 1 year ago

The physics example problem (to illustrate the use of a basic neural network using Mathematica) I am looking at is a qubit rotated about the y-axis, where the rotation angle is discretized as $\theta_j \in (0, \pi)$. The setup involves the y-rotated qubit measured in the z-basis (hence spin-up and spin-down projector measurements). This scenario involves first analytically determining the measurement outcome probabilities in as a function of the rotation angle $\theta$, then generating measurement outcomes for training, for specific fixed rotation angles $\theta_j$. Then generating another set of test measurement data for some fixed rotation angle $\theta$, we use the neural network to infer the most probable rotation angle. My training data involves generating m = 1000 total measurements for each discrete rotation angle $\theta_j \in [0, \pi]$, then saving the measurement outcomes as tuples of spin-up and spin-down outcomes for each discrete angle. These outcomes are associated with each of the discrete $\theta_j$ values which are one-hot vectors (hence training data of the form {1000,0} -> {1,0,0,0,0...} if for the first rotation angle we get all spin-up outcomes).

The idea is that after training, setting some true rotation angle $\theta$, and generating a new set of test measurement outcomes, the trained neural network should be able to output a probability distribution that shows the most likely discrete rotation angle is the true angle. The code below works but I am having difficulty improving the accuracy without simply increasing the layers and MaxTrainingRounds (this seems to have it's limits in improving accuracy). Can anyone advise on how to improve the accuracy of the code in determining the correct discrete rotation angle (I would like to maintain the general framework of the code)? I am very new to using Mathematica for machine learning applications hence the query. Thanks for any assistance, this is the code in question:

POSTED BY: Byron Alexander
8 Replies
Posted 1 year ago

Please see the attachment. I provided 3 examples.

You are predicting the numerical values, e.g., {{9997, 3} -> 1 but the SoftmaxLayer[] is to classify categorical values. In other words, your output data is numerical (e.g., 1) but your network uses the error function for categorical output. The SoftmaxLayer automatically invoke the CrossEntropyLossLayer as a default which is to compute the measurements for the purpose of classification (e.g., accuracy, confusion matrix), rather than prediction (e.g., r-square or mean square)

"For nets that contain CrossEntropyLossLayer, the following built-in measurements are available"

What I learned are:

  • pay attention to the type of the output, whether for prediction (numerical values) or classification (categorical value). This will determine the type of loss layer (MeanSquaredLossLayer, CrossEntropyLossLayer)
  • pay attention to the type of the output value (real value, vector, or a list}, this determines the last layer and the second last layer (SoftmaxLayer[] or, LinearLayer[], SoftmaxLayer[]) as well as the number of neurons (e.g., LinearLayer[1] or LinearLayer[50]).
  • Use the "TrainingNet" option to check the type of loss layer (not "TrainedNet")

    trainedNet3["TrainingNet"]

    finalNet3 = trainedNet3["TrainedNet"]

  • Use the "All" option in the NetTrain[net3, trainingData3, All] to check all properties

I noticed you applied PINN and it would be nice if you can share it (I am also learning PINN).

Attachments:
POSTED BY: Sangdon Lee
Posted 1 year ago
POSTED BY: Sangdon Lee
Attachments:
POSTED BY: Byron Alexander
Posted 1 year ago
POSTED BY: Sangdon Lee
Posted 1 year ago

@SangdonLee Many thanks for your response, just one query, when I try to evaluate NetMeasurements using the following code:

validationData = trainingData2b;
accuracy = NetMeasurements[trainedNet, validationData, "Accuracy"]
precision = NetMeasurements[trainedNet, validationData, "Precision"]

I obtain the following strange results: 
1.
<|1 -> 1., 2 -> 1., 3 -> 1., 4 -> 1., 5 -> 1., 6 -> 1., 7 -> 1., 
 8 -> 1., 9 -> 1., 10 -> 1., 11 -> 1., 12 -> 1., 13 -> 1., 14 -> 1., 
 15 -> 1., 16 -> 1., 17 -> 1., 18 -> 1., 19 -> 1., 20 -> 1., 21 -> 1.,
  22 -> 1., 23 -> 1., 24 -> 1., 25 -> 1., 26 -> 1., 27 -> 1., 
 28 -> 1., 29 -> 1., 30 -> 1., 31 -> 1., 32 -> 1., 33 -> 1., 34 -> 1.,
  35 -> 1., 36 -> 1., 37 -> 1., 38 -> 1., 39 -> 1., 40 -> 1., 
 41 -> 1., 42 -> 1., 43 -> 1., 44 -> 1., 45 -> 1., 46 -> 1., 47 -> 1.,
  48 -> 1., 49 -> 1., 50 -> 1.|>

Firstly, I don't think the accuracy could be 1. Secondly, I would have expected some real number between 0 and 1 for the precision (instead I get this strange output). Do you have any idea what is going on here?

POSTED BY: Updating Name
Posted 1 year ago
POSTED BY: Sangdon Lee
POSTED BY: Byron Alexander
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard