forked from dhvanipa/error_deep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
py_mutations_hub.py
803 lines (682 loc) · 21.4 KB
/
py_mutations_hub.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
# Copyright 2017 Dhvani Patel
import sqlite3
from check_pypy_syntax import checkPyPySyntax
from compile_error import CompileError
import tokenize
import token
import StringIO
import keyword
from Token import Token
import json
#from pprint import pprint
import numpy as np
from mutate_insert import insertMut
from mutate_deletion import deleteMut
from mutate_token_insert import insertTokMutS
from mutate_token_delete import deleteTokMutS
from mutate_token_sub import subTokMutS
import sys
import cPickle
from scipy import sparse
# NUM TOTAL: 462 563
# ACTUAl: 462 540
# ACTUAL: 925 080, BATCH = 60, GOOD = 30, BAD = 30 (I, D, S -> 10)
# Iterations: 15 418
# Unused samples = 23
# ONE HOT = 88
# OUT = 105 (2 + 2 + 3 + 10 + 88)
# 10 = WINDOW SIZE
WINDOW_SIZE = 10
BATCH_SIZE = 66
NUM_BITS_OUTPUT = 102
global all_tokens
new_tokens_ins = []
new_tokens_del = []
new_tokens_sub = []
global indexed_tokens
data = None
#Declaring Global Constants
YES_TOKEN = 0b10
NO_TOKEN = 0b01
INSERTION = 0b001
DELETION = 0b010
SUBSTITUTION = 0b100
YES_ERROR = 0b00
NO_ERROR = 0b01
START_TOKEN = '<s>'
END_TOKEN = '</s>'
def one_hot_a(indexed_tokens):
print indexed_tokens
print len(indexed_tokens)
one_hot = []
nb_classes = 88
one_hot_targets = np.eye(nb_classes)[indexed_tokens]
one_hot = one_hot_targets.tolist()
#print "fort"
#bruhTemp = one_hot[:]
for x in range(len(one_hot)):
#one_hot[x].astype(int)
[int(i) for i in one_hot[x]]
#one_hot.astype(int)
#print type(one_hot[0][0])
return one_hot
def one_hot(indexed_tokens):
return indexed_tokens
def set_from_json(all_tokens, flag):
#print "OMG"
with open('vocabulary.json') as data_file:
data = json.load(data_file)
#pprint(data)
#print len(data["indexes"])
#print "DHADHA"
tempT = all_tokens[:]
for token in tempT:
if len(token.value) > 0:
if token.value[0] == '#':
all_tokens.remove(token)
#print "no way"
for token in all_tokens:
if token.value == "\\r\\n":
token.value = "NEWLINE"
toCompare = token.value
#print token.type
#print "Broke..."
#print token.line
global indexed_tokens
if len(toCompare) > 0:
indexed_tokens.append(data["indexes"].index(toCompare))
for r in range(9):
indexed_tokens.insert(r, data["indexes"].index(START_TOKEN))
indexed_tokens.append(data["indexes"].index(END_TOKEN))
#print indexed_tokens
return one_hot(indexed_tokens)
def set_from_json_nonarr(token, flag):
#print "OMG"
with open('vocabulary.json') as data_file:
data = json.load(data_file)
#pprint(data)
#print len(data["indexes"])
#print "dhadha"
toCompare = token.value
#print token.type
#print "Broke..."
#print token.line
if len(toCompare) > 0:
ind_token_nonarr = data["indexes"].index(toCompare)
#print indexed_tokens
return ind_token_nonarr
def open_closed_tokens(token):
"""
'Flattens' Python into tokens based on whether the token is open or
closed.
"""
# List of token names that whose text should be used verbatim as the type.
VERBATIM_CLASSES = {
"AMPER", "AMPEREQUAL", "ASYNC", "AT", "ATEQUAL", "AWAIT", "CIRCUMFLEX",
"CIRCUMFLEXEQUAL", "COLON", "COMMA", "DOT", "DOUBLESLASH",
"DOUBLESLASHEQUAL", "DOUBLESTAR", "DOUBLESTAREQUAL", "ELLIPSIS",
"EQEQUAL", "EQUAL", "GREATER", "GREATEREQUAL", "LBRACE", "LEFTSHIFT",
"LEFTSHIFTEQUAL", "LESS", "LESSEQUAL", "LPAR", "LSQB", "MINEQUAL",
"MINUS", "NOTEQUAL", "OP", "PERCENT", "PERCENTEQUAL", "PLUS", "PLUSEQUAL",
"RARROW", "RBRACE", "RIGHTSHIFT", "RIGHTSHIFTEQUAL", "RPAR", "RSQB",
"SEMI", "SLASH", "SLASHEQUAL", "STAR", "STAREQUAL", "TILDE", "VBAR",
"VBAREQUAL"
}
OTHER = { "NEWLINE", "INDENT", "DEDENT"}
CHECK = {"None", "True", "False"}
if token.type == 'NAME':
# Special case for NAMES, because they can also be keywords.
if keyword.iskeyword(token.value):
return token.value
elif token.value in CHECK:
return token.value
else:
return '<IDENTIFIER>'
elif token.type in VERBATIM_CLASSES:
# These tokens should be mapped verbatim to their names.
assert ' ' not in token.value
return token.value
elif token.type in {'NUMBER', 'STRING'}:
# These tokens should be abstracted.
# Use the <ANGLE-BRACKET> notation to signify these classes.
return "<" + token.type.upper() + ">"
elif token.type in OTHER:
return token.type
else:
# Use these token's name verbatim.
# assert token.type in {
# 'NEWLINE', 'INDENT', 'DEDENT',
# 'ENDMARKER', 'ENCODING', 'COMMENT', 'NL', 'ERRORTOKEN'
#}
return token.value
def vocabularize_tokens(every_token, flag):
if flag == False:
EXTRANEOUS_TOKENS = {
# Always occurs as the first token: internally indicates the file
# ecoding, but is irrelelvant once the stream is already tokenized
'ENCODING',
# Always occurs as the last token.
'ENDMARKER',
# Insignificant newline; not to be confused with NEWLINE
'NL',
# Discard comments
'COMMENT',
# Represents a tokenization error. This should never appear for
# syntatically correct files.
'ERRORTOKEN',
}
elif flag == True:
EXTRANEOUS_TOKENS = {
# Always occurs as the first token: internally indicates the file
# ecoding, but is irrelelvant once the stream is already tokenized
'ENCODING',
# Always occurs as the last token.
'ENDMARKER',
# Discard comments
'COMMENT',
# Represents a tokenization error. This should never appear for
# syntatically correct files.
'ERRORTOKEN',
}
all_tokens_iter = every_token[:]
for Token in all_tokens_iter:
vocab_entry = open_closed_tokens(Token)
Token.value = vocab_entry
if Token.type in EXTRANEOUS_TOKENS:
every_token.remove(Token)
if flag == True:
if Token.value == "\\n":
every_token.remove(Token)
#if Token.type == "NL":
#print "Gotch u"
#for Token in every_token:
#print Token.value
return set_from_json(every_token, flag)
def getRid(every_token, flag):
if flag == False:
EXTRANEOUS_TOKENS = {
# Always occurs as the first token: internally indicates the file
# ecoding, but is irrelelvant once the stream is already tokenized
'ENCODING',
# Always occurs as the last token.
'ENDMARKER',
# Insignificant newline; not to be confused with NEWLINE
'NL',
# Discard comments
'COMMENT',
# Represents a tokenization error. This should never appear for
# syntatically correct files.
'ERRORTOKEN',
}
elif flag == True:
EXTRANEOUS_TOKENS = {
# Always occurs as the first token: internally indicates the file
# ecoding, but is irrelelvant once the stream is already tokenized
'ENCODING',
# Always occurs as the last token.
'ENDMARKER',
# Discard comments
'COMMENT',
# Represents a tokenization error. This should never appear for
# syntatically correct files.
'ERRORTOKEN',
}
all_tokens_iter = every_token[:]
for Token in all_tokens_iter:
#print tokenize.tok_name[Token[0]]
if tokenize.tok_name[Token[0]] in EXTRANEOUS_TOKENS:
every_token.remove(Token)
if flag == True:
if Token[1] == "\\n":
every_token.remove(Token)
#if Token.type == "NL":
#print "Gotch u"
return every_token
# Create list of tokens
def handle_token(type, token, (srow, scol), (erow, ecol), line):
if repr(token)[:2] == 'u\'':
val = repr(token)[2:len(repr(token))-1]
else:
val = repr(token)[1:len(repr(token))-1]
send = Token(tokenize.tok_name[type], val, srow, scol, erow, ecol, line)
global all_tokens
all_tokens.append(send)
#print "%d,%d-%d,%d:\t%s\t%s" % \
# (srow, scol, erow, ecol, tokenize.tok_name[type], repr(token))
def perform(curr):
sqlite_file = "/home/dhvani/python-sources.sqlite3"
conn = sqlite3.connect(sqlite_file)
c = conn.cursor()
#print "Success Connection to database..."
c.execute("SELECT source FROM source_file INNER JOIN eligible_source ON source_file.hash = eligible_source.hash")
#print "Executed SELECT..."
#print "Fetching all rows..."
all_rows = c.fetchmany(size=2600)
conn.close() # Close the connection to SQL
#for curr in range(2):
#print all_rows[curr][0]
if True:
#curr = 13
#print all_rows[curr][0]
#print "Got Em..."
#print "Running PyPy test..."
#print curr
toTest = checkPyPySyntax(all_rows[curr][0])
#print "DONE"
#print "CURRENT: "
# print curr
if toTest == None:
#print "here"
global all_tokens
all_tokens = []
global indexed_tokens
indexed_tokens = []
tokenStream = tokenize.tokenize(StringIO.StringIO(all_rows[curr][0]).readline, handle_token)
#print "RAW"
#print len(all_tokens)
allGood = []
global all_tokens
allGood = all_tokens[:]
print len(allGood)
#print "come on"
#print len(all_tokens)
#print len(allGood)
one_hot_good = vocabularize_tokens(all_tokens, False)
#one_hot_good_out = []
#for x in range(len(all_tokens)+(WINDOW_SIZE-1)+(WINDOW_SIZE-1)):
#toAdd = []
#toAdd = [0] * NUM_BITS_OUTPUT
#toAdd[0] = 0
#toAdd[1] = 1 # FIRST BIT (01) - INDICATE NO ERROR (1 because rest are 0 and so add up to 1)
#toAdd = [1]
#one_hot_good_out.append(1)
#print "DHVANI"
#print len(one_hot_good)
#print len(allGood)
#print len(all_tokens)
raw_tokens = tokenize.generate_tokens(StringIO.StringIO(all_rows[curr][0]).readline)
source_code = str(all_rows[curr][0])
#MUTATIONS PER TOKEN
# INSERT
#global all_tokens
#all_tokens = []
global indexed_tokens
indexed_tokens = []
#print "RAW"
#print len(all_tokens)
#passToks = all_tokens[:]
#print len(passToks)
#print "come
global all_tokens
print "dhadha"
#print len(all_tokens)
#print len(allGood)
passBall = allGood[:]
new_i_text, NO_TOKEN, INSERTION, out_tokens_loc, chosenTrueLineInds, insToks = insertTokMutS(raw_tokens, passBall, source_code)
while isinstance(new_i_text, int):
new_i_text, NO_TOKEN, INSERTION, out_tokens_loc, chosenTrueLineInds, insToks = insertTokMutS(NO_TOKEN, out_tokens_loc, INSERTION)
if isinstance(new_i_text, str):
break
print "here"
new_tokens_ins = allGood[:]
#print "BOL BOL BOL"
#print len(new_tokens_ins)
temp = insToks[:]
for insTok in temp:
if insTok.type == "NL":
insToks[insToks.index(insTok)].type = "NEWLINE"
temp2 = chosenTrueLineInds[:]
for chosenTrueLineInd in temp2:
vocab_entry = open_closed_tokens(chosenTrueLineInd)
chosenTrueLineInds[chosenTrueLineInds.index(chosenTrueLineInd)].value = vocab_entry
#print vocab_entry
#print "OK ------------------------------"
#print len(new_tokens_ins)
#print len(chosenTrueLineInds)
#print len(all_tokens)
bruhInd = 0
for wow in range(len(chosenTrueLineInds)):
bruhInd = -1
iterInd = 0
chosenTrueLineInd = chosenTrueLineInds[wow]
insTok = insToks[wow]
#print len(all_tokens)
for a in allGood:
if a == chosenTrueLineInd:
bruhInd = iterInd
iterInd = iterInd + 1
#print bruhInd + 1
#print bruhInd
#print "gotchu"
if bruhInd != -1:
#print bruhInd
#print "gotchu"
new_tokens_ins.insert(bruhInd+1, insTok)
#print "START DEBUG"
#print insTok.value
#print len(new_tokens_ins)
#print new_tokens_ins[bruhInd+1].value
one_hot_bad_ins = vocabularize_tokens(new_tokens_ins, True)
#print one_hot_bad_ins[bruhInd+1+WINDOW_SIZE-1]
#print "DONE DEBUG"
#print len(new_tokens_ins)
#print len(one_hot_bad_ins)
#if(bruhInd+1 < len(new_tokens_ins)):
#print "NEXT STEP...C"
#passInsErrorInd = (bruhInd+1)+(WINDOW_SIZE-1)
#one_hot_bad_ins_out = []
#trueErrorInd = (bruhInd+1)+(WINDOW_SIZE-1)
# INSERT OUT_PUT
#iterNum = len(new_tokens_ins)+(WINDOW_SIZE-1)+(WINDOW_SIZE-1)
#print "divide"
#print trueErrorInd
#print iterNum
'''
for x in range(iterNum):
#if x <= trueErrorInd <= (x+trueErrorInd):
#if x <= trueErrorInd <= x+(WINDOW_SIZE-1):
if True:
# DIFF - ACTUAL ERROR
#print x
#toAdd = []
#toAdd = [0] * NUM_BITS_OUTPUT
#toAdd[0] = 1 # FIRST BIT (10) - INDICATE ERROR
#toAdd[1] = 0
#if NO_TOKEN != None:
# toAdd[2] = 0
# toAdd[3] = 1
#if INSERTION != None:
# toAdd[4] = 0
# toAdd[5] = 0
# toAdd[6] = 1
#toAdd[7] = 1
toAdd = [0,3,6,7]
one_hot_bad_ins_out.append(toAdd)
else:
toAdd = []
toAdd = [0] * NUM_BITS_OUTPUT
toAdd[0] = 1
toAdd[1] = 0 # FIRST BIT (01) - INDICATE NO ERROR (1 because rest are 0 and so add up to 1)
one_hot_bad_ins_out.append(toAdd)
'''
#print "Morning"
#print len(new_tokens_ins)
#print len(one_hot_bad_ins_out)
#print one_hot_bad_ins_out[trueErrorInd]
# DELETE
raw_tokens = tokenize.generate_tokens(StringIO.StringIO(all_rows[curr][0]).readline)
#global all_tokens
#all_tokens = []
global indexed_tokens
indexed_tokens = []
#print type(raw_tokens)
#print type(source_code)
passBall = allGood[:]
new_d_text, YES_TOKEN, DELETION, chosens, fixToks = deleteTokMutS(raw_tokens,passBall, source_code)
while isinstance(new_d_text, int):
new_d_text, YES_TOKEN, DELETION, chosens, fixToks = deleteTokMutS(YES_TOKEN, DELETION)
if isinstance(new_d_text, str):
break
print "NEXT STEP..."
new_tokens_del = allGood[:]
tempFix = fixToks[:]
for send in tempFix:
vocab_entry = open_closed_tokens(send)
fixToks[fixToks.index(send)].value = vocab_entry
#print "len"
#print len(allGood)
#print len(fixToks)
#print len(new_tokens_del)
removeInds = []
for wow in range(len(chosens)):
bruhInd = -1
iterInd = 0
send = fixToks[wow]
#print send.value
for a in allGood:
if a == send:
bruhInd = iterInd
iterInd = iterInd + 1
#print bruhInd
#print "CHECK"
#print len(new_tokens_del)
removeInds.append(bruhInd)
#del new_tokens_del[bruhInd]
#print len(new_tokens_del)
#print "DEL ROR"
for r in reversed(removeInds):
del new_tokens_del[r]
#print len(new_tokens_del)
one_hot_bad_del = vocabularize_tokens(new_tokens_del, True)
#one_hot_bad_del_out = []
#trueErrorInd = (bruhInd)+(WINDOW_SIZE-1)
# DELETE OUT_PUT
#iterNum = len(new_tokens_del)+(WINDOW_SIZE-1)+(WINDOW_SIZE-1)
#print "divide"
#print len(send)
#print trueErrorInd
#print iterNum
#print "delete"
#print send.type
#print send.value
#oneH_ind_deleted = set_from_json_nonarr(send, True)
#print oneH_ind_deleted
#print "rad"
'''
for x in range(iterNum):
#if x <= trueErrorInd <= (x+trueErrorInd):
if True:
# DIFF - ACTUAL ERROR
#print x
#toAdd = []
#toAdd = [0] * NUM_BITS_OUTPUT
#toAdd[0] = 1 # FIRST BIT (10) - INDICATE ERROR
#toAdd[1] = 0
#if YES_TOKEN != None:
# toAdd[2] = 1
# toAdd[3] = 0
#if DELETION != None:
# toAdd[4] = 0
# toAdd[5] = 1
# toAdd[6] = 0
#toAdd[7] = 1
#toAdd[17] = 1
toAdd = [0,2,5,7,17]
one_hot_bad_del_out.append(toAdd)
else:
toAdd = []
toAdd = [0] * NUM_BITS_OUTPUT
toAdd[0] = 0
toAdd[1] = 1 # FIRST BIT (01) - INDICATE NO ERROR (1 because rest are 0 and so add up to 1)
one_hot_bad_del_out.append(toAdd)
'''
#print "Morning"
#print len(allGood)
#print len(one_hot_bad_del_out)
#print one_hot_bad_del_out[trueErrorInd]
# SUB
raw_tokens = tokenize.generate_tokens(StringIO.StringIO(all_rows[curr][0]).readline)
#global all_tokens
#all_tokens = []
global indexed_tokens
indexed_tokens = []
#print type(raw_tokens)
passBall = allGood[:]
new_s_text, YES_TOKEN, SUBSTITUTION, chosensS, fixToksS, insToksS = subTokMutS(raw_tokens, passBall, source_code)
while isinstance(new_s_text, int):
new_s_text, YES_TOKEN, SUBSTITUTION, chosensS, fixToksS, insToksS = subTokMutS(YES_TOKEN, SUBSTITUTION)
if isinstance(new_s_text, str):
break
#print "NEXT STEP..."
# SUB DELETE
new_tokens_sub = allGood[:]
temp = insToksS[:]
for insTok in temp:
if insTok.type == "NL":
insToks[insToksS.index(insTok)].type = "NEWLINE"
tempFix = fixToksS[:]
for send in tempFix:
vocab_entry = open_closed_tokens(send)
fixToksS[fixToksS.index(send)].value = vocab_entry
removeInds = []
for wow in range(len(chosensS)):
bruhInd = -1
iterInd = 0
send = fixToksS[wow]
#print send.value
for a in allGood:
if a == send:
bruhInd = iterInd
iterInd = iterInd + 1
#print bruhInd
#print "CHECK"
#print len(new_tokens_del)
removeInds.append(bruhInd)
#del new_tokens_del[bruhInd]
#print len(new_tokens_del)
#print "DEL ROR"
# SUB INSERT
#print len(removeInds)
#print len(insToksS)
comeIter = len(insToksS)-1
for r in reversed(removeInds):
del new_tokens_sub[r]
#print insToksS[comeIter].value
new_tokens_sub.insert(r, insToksS[comeIter])
comeIter -= 1
#for x in new_tokens_sub:
#print x.value
#print len(new_tokens_del)
#print insTokS.type
#print insTokS.value
#print "LUNCH"
one_hot_bad_sub = vocabularize_tokens(new_tokens_sub, True)
#one_hot_bad_sub_out = []
#trueErrorInd = (bruhInd)+(WINDOW_SIZE-1)
# SUB OUT_PUT
#iterNum = len(new_tokens_sub)+(WINDOW_SIZE-1)+(WINDOW_SIZE-1)
#print "divide"
#print len(send)
#print trueErrorInd
#print iterNum
#print "sub"
#print sendS.type
#print sendS.value
#oneH_sub_switch = set_from_json_nonarr(sendS, True)
#print oneH_sub_switch
#print "rad"
'''
for x in range(iterNum):
#if x <= trueErrorInd <= (x+trueErrorInd):
#if x <= trueErrorInd <= x+(WINDOW_SIZE-1):
if True:
# DIFF - ACTUAL ERROR
#print x
#toAdd = []
#toAdd = [0] * NUM_BITS_OUTPUT
#toAdd[0] = 1 # FIRST BIT (10) - INDICATE ERROR
#toAdd[1] = 0
#toAdd[2] = 1
#toAdd[3] = 0
#toAdd[4] = 1
#toAdd[5] = 0
#toAdd[6] = 0
#toAdd[7] = 1
#toAdd[17] = 1
toAdd = [0,2,4,7,17]
one_hot_bad_sub_out.append(toAdd)
else:
toAdd = []
toAdd = [0] * NUM_BITS_OUTPUT
toAdd[0] = 0
toAdd[1] = 1 # FIRST BIT (01) - INDICATE NO ERROR (1 because rest are 0 and so add up to 1)
one_hot_bad_sub_out.append(toAdd)
'''
#print "Morning"
#print len(allGood)
#print len(all_tokens)
#print len(one_hot_bad_sub_out)
#print one_hot_bad_sub_out[trueErrorInd]
# MUTATIONS PER CHARACTER
# insertMut(source_code)
#deleteMut(source_code])
#print "LEN"
#print one_hot_good[0]
#print one_hot_bad[0]
#print "----------INPUT-------------"
#print len(one_hot_good)
#print len(one_hot_bad_ins)
#print len(one_hot_bad_del)
#print len(one_hot_bad_sub)
#print "----------OUTPUT-------------"
#print len(one_hot_good_out)
#print len(one_hot_bad_ins_out)
#print len(one_hot_bad_del_out)
#print len(one_hot_bad_sub_out)
#print curr
#one_hot_all = np.concatenate((one_hot_good, one_hot_bad), axis=0)
#print "SUCCESS"
#sizes = [len(one_hot_good), len(one_hot_bad_ins),len(one_hot_bad_del),len(one_hot_bad_sub)]
#minSize = int(min(float(siz) for siz in sizes)) # min of a generator
#return minSize
#toPassGood = []
#print len(one_hot_good)
#for good in one_hot_good:
# ind = good.index(1.0)
# toPassGood.append(ind)
#print len(toPassGood)
#print one_hot_bad_sub_out
#print type(radha)
toPass = [one_hot_good, one_hot_bad_ins, one_hot_bad_del, one_hot_bad_sub]
#toPass = sparse.csr_matrix(toPassMatrix)
#print toPass
#print type(radha)
#cPickle.dump(one_hot_bad_ins, fileStore)
#cPickle.dump(one_hot_bad_del, fileStore)
#cPickle.dump(one_hot_bad_sub, fileStore)
#cPickle.dump(one_hot_good_out, fileStore)
#cPickle.dump(one_hot_bad_ins_out, fileStore)
#cPickle.dump(one_hot_bad_del_out, fileStore)
#cPickle.dump(one_hot_bad_sub_out, fileStore)
#cPickle.dump(passInsErrorInd, fileStore)
return toPass
#return one_hot_good, one_hot_bad_ins, one_hot_bad_del, one_hot_bad_sub, one_hot_good_out, one_hot_bad_ins_out, one_hot_bad_del_out, one_hot_bad_sub_out,passInsErrorInd
else:
print "Try again..."
print curr
#print all_rows[curr][0]
return -1
#return 1, None, None, None, 1, None, None, None, None
def giveItems():
allData = cPickle.load( open( "all_pre_data.txt", "rb" ) )
#print allData[3][8]
if __name__ == '__main__':
count = perform(1086)
print type(radha)
all_train_to_pass = []
for x in range(1000):
print x
if x != -1:
toP = perform(x)
all_train_to_pass.append(toP)
fileStore = open("train_pre_data.txt", 'w')
cPickle.dump(all_train_to_pass, fileStore)
fileStore.close()
all_val_to_pass = []
for x in range(1000):
print x
if x != -1:
toPV = perform(x+1001)
all_val_to_pass.append(toPV)
fileStoreV = open("val_pre_data.txt", 'w')
cPickle.dump(all_val_to_pass, fileStoreV)
fileStoreV.close()
print "FINISHED"
#giveItems()
sys.exit()
for x in range(10):
print "CURR"
print x
# 36, 80, 124, 126, 177
if x != 36 and x != 80 and x != 124 and x != 126 and x != 177:
perform(x)