Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # b_pattern_recog_plus.py @481
- # written by Kirk Lawrence + https://pastebin.com/pqyNaFQi
- import math
- import random
- import os, sys
- import ast
- from itertools import combinations
- try:
- # Python2
- from Tkinter import *
- from urllib2 import urlopen
- except ImportError:
- # Python3
- from tkinter import *
- from urllib.request import urlopen
- okay = 1
- root = Tk()
- root.withdraw()
- def cpbd():
- try:
- # t = root.selection_get(selection="CLIPBOARD")
- t = root.clipboard_get()
- return t
- except:
- return []
- # root.clipboard_clear()
- # root.destroy()
- 0
- def gym(): # for that pseudo neural exercise
- if prediction != yn:
- if yn:
- for v in nodes:
- weightsY[v] += 1
- else:
- for v in nodes:
- weightsN[v] += 1
- 0
- def guess(): # guess before training for this data
- ttt = []
- for z in enumerate(data):
- s = '%d:%s'%z
- ttt.append(s)
- nodes.extend(list(combinations(ttt, 3))) ### length @ 5 = 792
- # print len(nodes)
- pY = 0
- pN = 0
- for v in nodes:
- if v not in weightsY:
- weightsY[v] = 0
- weightsN[v] = 0
- else:
- pY += weightsY[v]
- pN += weightsN[v]
- p = 0
- if pY > pN:
- p = 1
- return p, pY-pN
- 0
- ###
- summary = 1
- rush = 1000
- # import numpy as np ### very much recommended 2018
- print ('Pattern Recognition Sequence Is Ready To Commence...')
- if 1: # for testing
- # random.seed(0)
- right = 0
- wrong = 0
- prev_gain = 0
- percent = '0.0'
- gain = 0.0
- weightsY = {}
- weightsN = {}
- go = 0
- while not go:
- full = cpbd()
- if '# yn -- combos -- at' in full:
- full = full.split('# yn -- combos -- at')[-1].strip().splitlines()
- if len(full) > 50000:
- random.shuffle(full)
- full = full[:20000]
- zzz = full[:]
- end = len(zzz)
- count_to_end = 0
- else:
- full = []
- while full:
- while zzz:
- z = zzz.pop(0)
- yn, data, at = ast.literal_eval(z)
- data = ''.join(data)
- at = ''.join(at)
- nodes = []
- prediction, ppp = guess()
- gym()
- if prediction == yn:
- right += 1
- count_to_end += 1
- else:
- wrong += 1
- count_to_end = 0
- if not (go+1)%rush:
- percent = '{:.1f}'.format(((right-prev_gain)*100.0)/rush)
- gain = max(gain,float(percent))
- if okay: ### for other tests
- t = str(go+1).zfill(8)
- print ('.')
- print ('.','>>> actual vs prediction =',[yn, prediction],ppp,' '*(7-len(str(ppp))),'::: Remaining', max(0,end-count_to_end))
- print ('.',data,':::','test#',t,'::: wrong =',wrong,'::: right =',right,':::','{:.1f}'.format(gain)+' / '+percent+'%')
- print ('.',at)
- print ('.')
- prev_gain = right
- if count_to_end >= end:
- zzz = []
- break
- zzz.append(z)
- go += 1
- full = []
- print ('.','*'*10,'End Of Cycle','*'*10)
- print ('.')
- if summary:
- ttt = list(weightsY.items())
- ttt.sort(key=lambda x: (x[-1],x[0]), reverse=1)
- for t in ttt[:1000]:
- print ('.',t)
- print ('.')
- for t in ttt[-1000:]:
- print ('.',t)
- print ('.')
- print ('.',len(ttt))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement