Exemple #1
0
 def __init__(self, para=Parameters.gtnc(), debug_mode=False, device='cpu'):
     # Initialize Parameters
     Programclass.Program.__init__(self, device=device, dtype=para['dtype'])
     MLclass.MachineLearning.__init__(self, para, debug_mode)
     self.debug_mode = debug_mode
     self.initialize_parameters_gtnc()
     self.name_md5_generate()
     self.inner_product = dict()
     self.data_mapped = dict()
     self.right_label = dict()
     self.accuracy = dict()
     self.test_info = dict()
     self.is_all_gtn_trained = False
     if not self.debug_mode:
         self.load_accuracy()
# -*- encoding: utf-8 -*-
from library import MPSMLclass
from library import Parameters
import matplotlib.pyplot as plt
import numpy as np
import json
import copy

para = Parameters.gtnc()
# get the relation between cutting dimention and testing accuracy
batch_bond = []
batch_acc = []
saved_para = dict()
for i in range(1, 9):
    bond = 2**i  # get the cutting bond
    para['virtual_bond_limitation'] = bond
    print('The current cutting bond is %d' % bond)
    A = MPSMLclass.GTNC(para=para,
                        device='cpu')  # change device='cuda' to use GPU
    A.training_gtn()  # if the GTN are not trained
    acc = A.calculate_accuracy('test')
    print('Bond {0} acc is {1}'.format(bond, acc))
    batch_bond.append(bond)
    # para[''] = acc
    batch_acc.append(acc)
    counterpart_para = copy.deepcopy(para)
    for item in counterpart_para.keys():
        counterpart_para[item] = str(counterpart_para[item])
    counterpart_para['Accuracy'] = acc
    saved_para["bond" + str(bond)] = counterpart_para