コード例 #1
0
    def testChicagoSampling(self):
        # load original graph
        params_original = {
            "dataset_type": "chicago",
            "days": 10,
            "sparsity": 1
        }
        gen = Generator("testChicago", params_original)
        gen.generate()
        graph_orig, idle_driver_locations, real_orders, onoff_driver_locations, _, _ = gen.load_complete_set(
        )

        params = {"dataset_type": "chicago", "days": 10, "sparsity": 3}

        gen = Generator("testChicago", params)
        gen.generate()
        graph, idle_driver_locations, real_orders, onoff_driver_locations, _, _ = gen.load_complete_set(
        )
        real_orders = np.array(real_orders)
        exp_size = len(graph_orig) // params['sparsity']
        self.assertEqual(idle_driver_locations.shape,
                         (24 * 60 // 15, exp_size))
        self.assertEqual(len(graph), exp_size)
        self.assertGreater(np.sum(np.array(real_orders)[:1, :]), 0)
        self.assertGreater(np.sum(idle_driver_locations), 0)
コード例 #2
0
def main():
    if len(argv) != 3:
        print("Usage: python3 clProgram.py outputFileName schemaInQuotes")
        if len(argv) < 3:
            print("Too few arguments provided.")
        else:
            print(
                "Too many arguments provided. Hint: Did you forget to put the schema in quotes?"
            )
        return -1

    gen = Generator()
    wr = Writer()
    output_file_name = argv[1]
    [reqs, variable] = split_req(argv[2])
    #print(reqs)
    wr.open_file(output_file_name)
    for req in reqs:
        if req == ';':
            print()
            wr.write_new_line()
            continue
        arg = gen.parse_request(req)
        #print(arg)
        data = gen.generate(**arg)
        wr.write(data)
        print(data, end='', sep=' ')
        if arg.get('var_name', False) is not False:
            gen.variables[arg['var_name']] = data
コード例 #3
0
ファイル: GUI.py プロジェクト: jucarhev/MetaGenerador
    def preview_info(self, event):  #error 2
        if self.cbo_list.GetValue() == 'Date':
            if self.txt_config.GetValue() == 'r':
                wx.MessageBox(
                    "Date, no puede tener solo r, debe ser asi 1990,2000,r",
                    "Warning", wx.OK | wx.ICON_INFORMATION)

        gen = Generator()

        n = len(self.array_data_preview_generate)
        if self.cbo_list.GetValue() != 'Ninguna' or self.cbo_columns.GetValue(
        ) != 'Ninguna':
            print("aqui")
            columna = str(self.cbo_columns.GetValue()).split(' ')
            lista = self.cbo_list.GetValue()
            example = gen.examples(lista, self.txt_config.GetValue())
            array_preview = [
                n, columna[0], columna[1],
                lista + ' ' + self.txt_config.GetValue(), example
            ]
            self.array_data_preview_generate.append(array_preview)

            self.list_preview.DeleteAllItems()

            for ar in self.array_data_preview_generate:
                index = self.list_preview.InsertStringItem(
                    sys.maxsize, str(ar[0]))
                self.list_preview.SetStringItem(index, 1, str(ar[1]))
                self.list_preview.SetStringItem(index, 2, str(ar[2]))
                self.list_preview.SetStringItem(index, 3, str(ar[3]))
                self.list_preview.SetStringItem(index, 4, str(ar[4]))
コード例 #4
0
ファイル: GUI.py プロジェクト: jucarhev/MetaGenerador
    def __init__(self, parent, database, table):
        wx.Dialog.__init__(self,
                           parent=None,
                           title='Describe Table',
                           pos=wx.DefaultPosition,
                           size=wx.Size(600, 200))

        self.list = wx.ListCtrl(self,
                                -1,
                                pos=(10, 170),
                                size=(600, 250),
                                style=wx.LC_REPORT)
        self.list.InsertColumn(0, 'Field', width=100)
        self.list.InsertColumn(1, 'Type', width=100)
        self.list.InsertColumn(2, 'Null', wx.LIST_FORMAT_RIGHT, 70)
        self.list.InsertColumn(3, 'Key', wx.LIST_FORMAT_RIGHT, 70)
        self.list.InsertColumn(4, 'Default', wx.LIST_FORMAT_RIGHT, 70)
        self.list.InsertColumn(5, 'Extra', wx.LIST_FORMAT_RIGHT, 100)

        self.gen = Generator()
        self.gen.check_connect()
        rows = self.gen.query_model("SHOW COLUMNS FROM " + table, database)

        for ar in rows:
            index = self.list.InsertStringItem(sys.maxsize, str(ar[0]))
            self.list.SetStringItem(index, 1, str(ar[1]))
            self.list.SetStringItem(index, 2, str(ar[2]))
            self.list.SetStringItem(index, 3, str(ar[3]))
            self.list.SetStringItem(index, 4, str(ar[4]))
            self.list.SetStringItem(index, 5, str(ar[5]))
コード例 #5
0
ファイル: GUI.py プロジェクト: jucarhev/MetaGenerador
    def __init__(self, parent):
        wx.Dialog.__init__(self,
                           parent,
                           id=wx.ID_ANY,
                           title=u"Preferences",
                           pos=wx.DefaultPosition,
                           size=wx.Size(285, 189),
                           style=wx.DEFAULT_DIALOG_STYLE)

        self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)

        bSizer5 = wx.BoxSizer(wx.VERTICAL)

        self.m_staticText10 = wx.StaticText(self, wx.ID_ANY,
                                            u"Exclude databases:",
                                            wx.DefaultPosition, wx.DefaultSize,
                                            0)
        self.m_staticText10.Wrap(-1)
        bSizer5.Add(self.m_staticText10, 0, wx.ALL, 5)

        self.txt_exclude_databases = wx.TextCtrl(self, wx.ID_ANY,
                                                 wx.EmptyString,
                                                 wx.DefaultPosition,
                                                 wx.Size(300, -1), 0)
        bSizer5.Add(self.txt_exclude_databases, 0, wx.ALL, 5)

        self.m_staticText11 = wx.StaticText(self, wx.ID_ANY,
                                            u"Exclude columns:",
                                            wx.DefaultPosition, wx.DefaultSize,
                                            0)
        self.m_staticText11.Wrap(-1)
        bSizer5.Add(self.m_staticText11, 0, wx.ALL, 5)

        self.txt_exclude_columns = wx.TextCtrl(self, wx.ID_ANY, wx.EmptyString,
                                               wx.DefaultPosition,
                                               wx.Size(300, -1), 0)
        bSizer5.Add(self.txt_exclude_columns, 0, wx.ALL, 5)

        bSizer7 = wx.BoxSizer(wx.HORIZONTAL)

        self.btn_save_preferences = wx.Button(self, wx.ID_ANY, u"Guardar",
                                              wx.DefaultPosition,
                                              wx.DefaultSize, 0)
        bSizer7.Add(self.btn_save_preferences, 0, wx.ALL, 5)

        bSizer5.Add(bSizer7, 0, wx.EXPAND, 5)

        self.SetSizer(bSizer5)
        self.Layout()

        self.Centre(wx.BOTH)

        self.gen = Generator()
        file_check = self.gen.file_open('preferences.txt', 'src/config/')
        array_preferences = file_check.split('\n')
        self.txt_exclude_databases.SetValue(array_preferences[0])
        self.txt_exclude_columns.SetValue(array_preferences[1])

        self.btn_save_preferences.Bind(wx.EVT_BUTTON, self.save_config)
コード例 #6
0
ファイル: GUI.py プロジェクト: jucarhev/MetaGenerador
 def combo_change_databases(self, evt):
     gen = Generator()
     self.cbo_tables.Clear()
     self.cbo_tables.SetValue('Ninguna')
     self.cbo_columns.SetValue('Ninguna')
     gen.check_connect()
     self.cbo_tables.AppendItems(
         gen.list_table_database(self.cbo_databases.GetValue()))
コード例 #7
0
ファイル: GUI.py プロジェクト: jucarhev/MetaGenerador
 def start_file_list(self):
     gen = Generator()
     self.cbo_list.Clear()
     array1 = [
         'Ninguna', 'Email', 'Password', 'Date', 'Random', 'Feature',
         'Telephone', 'Direction', 'Code', 'Secuencia'
     ]
     array2 = gen.list_files_diccionary()
     self.cbo_list.AppendItems(array1 + array2)
コード例 #8
0
ファイル: GUI.py プロジェクト: jucarhev/MetaGenerador
 def menu_file_export(self, event):
     items = self.spin_number_items.GetValue()
     gen = Generator()
     if len(self.array_data_preview_generate) != 0:
         n = len(self.array_data_preview_generate)
         r = gen.create_mysql(self.array_data_preview_generate, items,
                              self.cbo_tables.GetValue())
         conecta = export_dialog(None, r)
         conecta.ShowModal()
         conecta.Destroy()
コード例 #9
0
ファイル: GUI.py プロジェクト: jucarhev/MetaGenerador
 def combo_change_tables(self, evt):
     try:
         gen = Generator()
         gen.check_connect()
         self.cbo_columns.Clear()
         self.cbo_columns.SetValue('Ninguna')
         self.cbo_columns.AppendItems(
             gen.columns_list(self.cbo_databases.GetValue(),
                              self.cbo_tables.GetValue()))
     except Exception as e:
         print(e)
コード例 #10
0
ファイル: GUI.py プロジェクト: jucarhev/MetaGenerador
 def save_config(self, evt):
     self.gen = Generator()
     try:
         dlg = wx.TextEntryDialog(self, 'Enter Name file', 'Name')
         if dlg.ShowModal() == wx.ID_OK:
             content = self.txt_newdocument.GetValue()
             self.gen.write_file(str(dlg.GetValue()) + '.txt', content)
             wx.MessageBox("Ok, Change", 'Ok', wx.OK | wx.ICON_INFORMATION)
         dlg.Destroy()
     except Exception as e:
         wx.MessageBox(str(e), 'Error', wx.OK | wx.ICON_ERROR)
コード例 #11
0
ファイル: GUI.py プロジェクト: jucarhev/MetaGenerador
 def check_start(self):
     gen = Generator()
     if (gen.check_connect() != True):
         wx.MessageBox(str(gen.check_connect()), 'Error',
                       wx.OK | wx.ICON_ERROR)
         self.cbo_databases.Clear()
         array1 = ['Ninguna']
         self.cbo_databases.AppendItems(array1)
     else:
         self.cbo_databases.Clear()
         array1 = ['Ninguna']
         array2 = gen.databases()
         self.cbo_databases.AppendItems(array1 + array2)
コード例 #12
0
 def test_hexagon(self):
     params = {
         "dataset_type": "hexagon",
         "days": 10,
         "n": 3,
         "time_periods": 4,
         "order_distr": "uniform",
         "orders_density": 1,
         "number_of_cars": 10
     }
     gen = Generator("testGenerator", params)
     gen.generate()
     g, _, _, _, _, _ = gen.load_complete_set()
     assert g.has_edge(0, 1)
     assert g.has_edge(0, 4)
     assert g.has_edge(1, 3)
     assert g.has_edge(1, 5)
     assert g.number_of_edges() == 20
コード例 #13
0
def create_gan_instances(config):
    n_gpu = int(config['CONFIGS']['ngpu'])
    latent_vector_size = int(config['CONFIGS']['latent_vector_size'])
    ngf = int(config['CONFIGS']['ngf'])
    ndf = int(config['CONFIGS']['ndf'])
    num_channels = int(config['CONFIGS']['num_channels'])

    device = torch.device('cuda:0' if (
        torch.cuda.is_available() and n_gpu > 0) else 'cpu')

    # Create the generator and discriminator
    generator = Generator.Generator(n_gpu, latent_vector_size, ngf,
                                    num_channels).to(device)
    discriminator = Discriminator.Discriminator(n_gpu, latent_vector_size, ndf,
                                                num_channels).to(device)

    generator = _handle_multiple_gpus(generator, n_gpu, device)
    discriminator = _handle_multiple_gpus(discriminator, n_gpu, device)
    return generator, discriminator, device
コード例 #14
0
    if task_name == 'SkipNet_CIFAR100_2' or task_name == 'BlockDrop_CIFAR10_2':
        continue

    model_name, data_set = task_name.split('_')[0], task_name.split('_')[1]

    log_file = os.path.join('IlfoLog', log_file)
    with open(log_file, 'r') as f:
        data = f.readlines()
    data = data[11:]
    data = [time2int(d.split(' ')[1]) for d in data]
    ilfo_cost = []
    for i in range(len(data) - 1):
        ilfo_cost.append(data[i + 1] - data[i])
    gan_model = 'AbuseGanModel/' + task_name + '_hyper0.0001/netG_epoch_90.pth'
    gan_model = torch.load(gan_model)
    model = Generator(3, 3)
    print(task_name, 'load successful')
    model.load_state_dict(gan_model)
    gan_model = model.to(device).eval()

    model, trainSet, testSet = load_model_data(model_name, data_set)
    model = model.to(device).eval()
    test_loader = DataLoader(testSet, batch_size=256, shuffle=False)

    gan_cost = []
    for (x, y) in tqdm(test_loader):
        x = x.to(device)
        t1 = time.time()
        x = gan_model(x) + x
        pred = model(x, device)
        t2 = time.time()
コード例 #15
0
ファイル: start.py プロジェクト: Egomania/SOME-IP_Generator
from src import Generator 


if __name__ == '__main__':
    Generator.start()
    
コード例 #16
0
import torch
import torch.optim as optim
import src.Generator as G
import src.Discriminator as D
import pickle
import torchvision.transforms as trans
import gc

"""
File used to train the gan 
"""


# Create/ load networks
G = G.Generator().cuda()
D = D.Discriminator().cuda()

# with open(r'D:\GAN_Gallery\src\D_linear.cnn', 'rb') as file:
#     D = pickle.load(file)

# with open(r'D:\GAN_Gallery\src\G_linear.cnn', 'rb') as file:
#     G = pickle.load(file)

trans = trans.ToPILImage()

### Set up hyperparameters
epochs = 5
lr = 5e-5
counter = 0

### Training Loop
コード例 #17
0
ファイル: GUI.py プロジェクト: jucarhev/MetaGenerador
    def __init__(self, parent):
        wx.Dialog.__init__(self,
                           parent,
                           id=wx.ID_ANY,
                           title=u"Database connection",
                           pos=wx.DefaultPosition,
                           size=wx.Size(323, 179),
                           style=wx.DEFAULT_DIALOG_STYLE)

        self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize)

        bSizer1 = wx.BoxSizer(wx.VERTICAL)

        fgSizer1 = wx.FlexGridSizer(0, 2, 0, 0)
        fgSizer1.SetFlexibleDirection(wx.BOTH)
        fgSizer1.SetNonFlexibleGrowMode(wx.FLEX_GROWMODE_SPECIFIED)

        self.m_staticText4 = wx.StaticText(self, wx.ID_ANY, u"HostName:",
                                           wx.DefaultPosition, wx.DefaultSize,
                                           0)
        self.m_staticText4.Wrap(-1)
        fgSizer1.Add(self.m_staticText4, 0, wx.ALL, 5)

        self.txt_hostname = wx.TextCtrl(self, wx.ID_ANY,
                                        wx.EmptyString, wx.DefaultPosition,
                                        wx.Size(200, -1), 0)
        fgSizer1.Add(self.txt_hostname, 0, wx.ALL | wx.EXPAND, 5)

        self.m_staticText5 = wx.StaticText(self, wx.ID_ANY, u"UserName:"******"Password:"******"Guardar",
                                             wx.DefaultPosition,
                                             wx.DefaultSize, 0)
        fgSizer1.Add(self.btn_save_connection, 0, wx.ALL, 5)

        self.btn_test_connection = wx.Button(self, wx.ID_ANY, u"Test",
                                             wx.DefaultPosition,
                                             wx.DefaultSize, 0)
        fgSizer1.Add(self.btn_test_connection, 0, wx.ALL, 5)

        bSizer1.Add(fgSizer1, 0, wx.ALL | wx.EXPAND, 5)

        self.SetSizer(bSizer1)
        self.Layout()

        self.Centre(wx.BOTH)

        self.gen = Generator()
        with open('src/config/config.json') as file:
            data = json.load(file)

        self.txt_hostname.SetValue(data["conn"][0])
        self.txt_username.SetValue(data["conn"][1])
        self.txt_password.SetValue(data["conn"][2])

        self.btn_save_connection.Bind(wx.EVT_BUTTON, self.save_config)
        self.btn_test_connection.Bind(wx.EVT_BUTTON, self.test_config)
コード例 #18
0
ファイル: train_dcgan.py プロジェクト: doiken23/sat_gan
    transforms.Normalize([0.5] * 4, [0.5] * 5)
    ])
train_dataset = SATDataset(args.data, phase='train', transform=trans)
train_loader = data_utils.DataLoader(train_dataset,
        args.batchsize, shuffle=True, num_workers=2, drop_last=True)
test_dataset = SATDataset(args.data, phase='val', transform=trans)
test_loader = data_utils.DataLoader(test_dataset,
        args.batchsize, num_workers=2, drop_last=True)

# random generator
def generate_z(batchsize):
    return torch.randn((args.batchsize, 50))

# prepare network
D = Discriminator(ndf=args.ndf).to(device)
G = Generator(50, ngf=args.ngf).to(device)
## initialization the network parameters
def weights_init(m):
    classname = m.__class__.__name__
    if classname.find('Conv' or 'Linear') != -1:
        init.normal(m.weight, mean=args.mu, std=args.sigma)
D.apply(weights_init)
G.apply(weights_init)

# criterion
criterion = nn.Softplus()

# prepare optimizer
d_optimizer = optim.Adam(D.parameters(), lr=args.lr)
g_optimizer = optim.Adam(G.parameters(), lr=args.lr)
コード例 #19
0
from src import Generator, split as split_req, Writer
# from src.parsers import split as split_req
# from src.writer import Writer

if __name__ == "__main__":
    gen = Generator()
    wr = Writer()
    base_file_name = input("Enter File Name: ")
    while True:
        try:
            inputCount = int(input("Enter Count: "))
        except ValueError:
            print("Please enter positive integers only")
            continue
        if inputCount <= 0:
            print("Please enter positive integers only")
            continue
        break

    for i in range(0, inputCount):
        output_file_name = f"{base_file_name}{i+1}"
        [reqs, variable] = split_req(input())
        #print(reqs)
        wr.open_file(output_file_name)
        for req in reqs:
            if req == ';':
                print()
                wr.write_new_line()
                continue
            arg = gen.parse_request(req)
            #print(arg)
コード例 #20
0
ファイル: tests.py プロジェクト: navyakanu/TestCaseGenerator
class TestCases(unittest.TestCase):
    generator = Generator()
    valid_chars = set('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')

    # test Generate a Random Integer
    def test_generate_number(self):
        generated_number = self.generator.generate_number(type='integer', )
        self.assertEqual(type(generated_number), int)

    # test Generate a Random Integer less than a given number
    def test_generate_number_higher_range(self):
        higher_range = 1000
        generated_number = self.generator.generate_number(type='integer',
                                                          range=True,
                                                          range_end=higher_range)
        self.assertEqual(type(generated_number), int)
        self.assertLessEqual(generated_number, higher_range)

    # test Generate a Random Integer more than a given number
    def test_generate_number_lower_range(self):
        lower_range = 1000
        generated_number = self.generator.generate_number(type='integer',
                                                          range=True,
                                                          range_start=lower_range)
        self.assertEqual(type(generated_number), int)
        self.assertGreaterEqual(generated_number, lower_range)

    # test Generate a Random Integer between 2 given numbers
    def test_generate_number_full_range(self):
        lower_range = 10
        higher_range = 100
        generated_number = self.generator.generate_number(type='integer',
                                                          range=True,
                                                          range_start=lower_range,
                                                          range_end=higher_range)
        self.assertEqual(type(generated_number), int)
        self.assertGreaterEqual(generated_number, lower_range)
        self.assertLessEqual(generated_number, higher_range)

    # test Generate a Random Character (alphanumeric)
    def test_generate_character(self):
        generated_character = self.generator.generate_string(type='string',
                                                             length=1)
        self.assertEqual(type(generated_character), str)
        self.assertIn(generated_character, self.valid_chars)

    # test Generate a Random Character from a given set of characters
    def test_generate_character_from_given_set(self):
        valid_set = (1, 2, 3, 4, 5, 'a', 'b', 'c', 'd', 'e')
        generated_character = self.generator.generate_string(type='string',
                                                             length=1,
                                                             choices=valid_set,
                                                             choice_invert=False)
        self.assertEqual(type(generated_character), str)
        self.assertIn(generated_character, valid_set)

    # test Generate 10 Random Characters
    def test_generate_10_random_characters(self):
        generated_set = self.generator.generate_string(type='string',
                                                             length=10)
        self.assertEqual(type(generated_set), str)
        for letter in generated_set:
            self.assertIn(letter, self.valid_chars)
コード例 #21
0
from src import Generator

if __name__ == '__main__':
    Generator.start()