<jupyter_start><jupyter_text><jupyter_code>opt = qml.optimize.RotosolveOptimizer()
# set the number of steps
steps = 50
# set the initial parameter values

for i in range(steps):
    # update the circuit parameters
    gen_weights = opt.step(gen_cost, gen_weights)
    #print(params, type(params))
    #gen_weights = params

    if (i + 1) % 5 == 0:
        print("Cost after step {:5d}: {: .7f}".format(i + 1, gen_cost(gen_weights)))

print("Optimized rotation angles: {}".format(gen_weights))<jupyter_output>Cost after step     5: -0.9394419
Cost after step    10: -0.9344345
Cost after step    15: -0.9572276
Cost after step    20: -0.9450917
Cost after step    25: -0.9573423
Cost after step    30: -0.9234007
Cost after step    35: -0.9451738
Cost after step    40: -0.9425347
Cost after step    45: -0.9290797
Cost after step    50: -0.9680209
Optimized rotation angles: [[[-0.27159776  2.03933555 -1.6541293 ]
  [ 0.36354742  2.31376844 -2.39035047]
  [ 1.19344581 -1.97049972  2.14433902]]

 [[ 2.40456466 -1.46444568  2.13785844]
  [-2.52917735 -2.61070361  0.20345007]
  [-2.54508104  0.2305002  -2.06627153]]

 [[-2.1559029  -2.28266751  2.03261127]
  [-2.70613521 -2.20103475  1.41482838]
  [ 2.23249214 -2.31357872  2.84899847]]]<jupyter_text>At the joint optimum, both of real and fake data should be classified as real.<jupyter_code>print("Probability of real data classified as real: ", real_true(disc_weights))

print("Probability of fake data classified as real: ", fake_true(gen_weights, disc_weights))<jupyter_output>Probability of fake data classified as real:  0.9693305101245642<jupyter_text>We define the discriminator's cost as difference between how it classifies fake and real data. At the join optimum, we see that it is much closer to zero, i.e. it classifies both of them as real.<jupyter_code>disc_cost(disc_weights)
gen_cost(gen_weights)
opt = qml.AdagradOptimizer(stepsize=0.1, eps=1e-08)
# set the number of steps
steps = 100
# set the initial parameter values

for i in range(steps):
    # update the circuit parameters
    disc_weights = opt.step(disc_cost, disc_weights)

    if (i + 1) % 5 == 0:
        print("Cost after step {:5d}: {: .7f}".format(i + 1, disc_cost(disc_weights)))

print("Optimized rotation angles: {}".format(disc_weights))
opt = qml.optimize.RotosolveOptimizer()
# set the number of steps
steps = 50
# set the initial parameter values

for i in range(steps):
    # update the circuit parameters
    gen_weights = opt.step(gen_cost, gen_weights)
    #print(params, type(params))
    #gen_weights = params

    if (i + 1) % 5 == 0:
        print("Cost after step {:5d}: {: .7f}".format(i + 1, gen_cost(gen_weights)))

print("Optimized rotation angles: {}".format(gen_weights))
print("Probability of real data classified as real: ", real_true(disc_weights))
print("Probability of fake data classified as real: ", fake_true(gen_weights, disc_weights))
print("Discriminator's cost", disc_cost(disc_weights))
print("Generator's cost", gen_cost(gen_weights))
opt = qml.AdagradOptimizer(stepsize=0.1, eps=1e-08)
# set the number of steps
steps = 100
# set the initial parameter values

for i in range(steps):
    # update the circuit parameters
    disc_weights = opt.step(disc_cost, disc_weights)

    if (i + 1) % 5 == 0:
        print("Cost after step {:5d}: {: .7f}".format(i + 1, disc_cost(disc_weights)))

print("Optimized rotation angles: {}".format(disc_weights))
opt = qml.optimize.RotosolveOptimizer()
# set the number of steps
steps = 50
# set the initial parameter values

for i in range(steps):
    # update the circuit parameters
    gen_weights = opt.step(gen_cost, gen_weights)
    #print(params, type(params))
    #gen_weights = params

    if (i + 1) % 5 == 0:
        print("Cost after step {:5d}: {: .7f}".format(i + 1, gen_cost(gen_weights)))

print("Optimized rotation angles: {}".format(gen_weights))
print("Probability of real data classified as real: ", real_true(disc_weights))
print("Probability of fake data classified as real: ", fake_true(gen_weights, disc_weights))
print("Discriminator's cost", disc_cost(disc_weights))
print("Generator's cost", gen_cost(gen_weights))<jupyter_output>Probability of real data classified as real:  0.995952125871554
Probability of fake data classified as real:  0.9689365578815341
Discriminator's cost -0.024314356269314885
Generator's cost -0.9696989897638559<jupyter_text>We can continue to train discriminator and generator alternatively until both of them no longer converge, i.e. an optimal point is reached.<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11701662292213473, 'fraction_numerical': 0.10433070866141732, 'mean_word_length': 4.4635603345280765, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '188495', 'license': 'MIT', 'n_tokens_mistral': 1872, 'n_tokens_neox': 1565, 'n_words': 459, 'path': 'PauliOps/QuGAN.ipynb', 'repo_name': 'Q-Alpha/Hackathon2020', 'size': '4572'}