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
POSTED BY: Byron Alexander
8 Replies
Posted 1 year ago
Attachments:
POSTED BY: Sangdon Lee
Posted 1 year ago

Per your interest on predicting probabilities, you can compute the probabilities for classification, by using the "net3" and the "trainedNet3" which use the SoftmaxLayer and the output as a string (e.g., "1", not 1.0.

{finalNet3[{9987, 13}, "Probabilities"] 
 finalNet3[{5062, 4938}, "Probabilities"] 
 finalNet3[{0, 10000}, "Probabilities"] }

Note that the following three samples are classified correctly. For example, using the 1st, 25th, and 50th samples, the 3 samples are correctly classified with the highest probabilities.

  • {9987,13} -> "1": {9987,13} show the highest probability to be classified as "1"
  • {5062,4938}->"25": {5062,4938} show the highest probability to be classified as "25"
  • {0,10000}-> "50": {0,10000} show the highest probability to be classified as "50"

I am not sure what you mean by: "the output in training has inverted commas " ", that is {{9988, 12} -> "1"} instead of {{9988, 12} -> 1}." I think you mean string not a number.

You can compute the probabilities for each class by using the SoftmaxLayer but the SoftmaxLayer requires the output to be a string, not a number, which I called classification.

By the way, you can check and plot the sensitivities of each input by changing the 1st input while holding the 2nd input constant and vice versa.

Table[{x1, finalNet3[{x1, 5000}]}, {x1, 4000, 6000, 100}]

Hope this helps.

POSTED BY: Sangdon Lee

@SangdonLee Thanks, all the discussions are very helpful. The physics problem that I am considering, for learning purposes at this stage, is the problem of a rotating qubit. I consider that a qubit rotates about it's y-axis by an angle of \theta in [0, pi]. For training we consider the z measurements of spin-up and spin-down for discretized angles of [0, pi]. Hence the training result {9989, 11} -> "1" indicates that I obtain 9989 spin up results and 11 spin down when measuring the qubit during the first discretized rotation angle. Since I discretize the range [0, pi] in 50 intervals, I obtain 50 such training data results. Have a look at my final code, let me know what you think of my attempt to model this example (not sure how familiar you are with quantum mechanics?). You can advise if anything is unclear in the code or example.

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

The followings are mere suggestions.

  • The inputs are a 100 x 2 matrix (i.e., only 2 input parameters), but the outputs are a 100 x 100 matrix (a vector of 100 values due to one-hot vectors) which is huge compared to the 2 predictors. It might be helpful to change the one-hot coding as a number or string. e.g., {1,0,0,0,0.......} to 1, {0,1,0,0,0.......} to 2, etc.

    trainingData2 = Thread[trainingData[[All, 1]] -> Range[100]]
    net = NetChain[{LinearLayer[50], ElementwiseLayer["ReLU"], 
        LinearLayer[50], ElementwiseLayer["ReLU"], LinearLayer[1]}];  
    
  • The "net" has only very few hidden layers and it might be helpful to increase the number of hidden layers. Adding more layers does not necessarily increase the accuracy thus apply other layers such as batch normalization layer (adding which layer may not be straightforward)

  • The last 4 samples of the "trainingData" have the same input values but the output values are different, which does not make sense.
POSTED BY: Sangdon Lee

@SangdonLee Thanks for your response. Having implemented your suggestions I do note an improvement. One query, do you maybe know how to incorporate the ValidationSet[] built-in function into the type of neural network to increase the accuracy and prevent overfitting? I left highlighted in purple my attempt at including the ValidationSet[]. It does run but I don't think it is set in an optimal way. I attach the revised Notebook.

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