@op/

DNN 3-1

Python

No description

fork
loading
Files
  • main.py

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.5168509434237529","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IG51bXB5IGFzIG5wCmZyb20gcmFuZG9tIGltcG9ydCByYW5kcmFuZ2UKCnogPSBbXQphID0gW10KbHcgPSAwCgpkZWYgYWN0KGxzdCk6CiAgcmV0dXJuICgoMStucC5leHAoLShsc3QpKSkqKi0xKQoKZGVmIGFjdHAobHN0KToKICByZXR1cm4gKChucC5leHAobHN0KSkpKigobnAuZXhwKGxzdCkrMSkqKi0yKQoKZGVmIFcobixtKToKICByZXR1cm4gNCpucC5yYW5kb20ubm9ybWFsKHNpemU9KG4sbSkpLTIKCmRlZiB3dHMoaGwpOgogIGx3ID0gbGVuKGhsKS0xCiAgdyA9IFtdCiAgZm9yIGkgaW4gcmFuZ2UobHcpOgogICAgdy5hcHBlbmQoVyhobFtpXSxobFtpKzFdKSkKICByZXR1cm4gdwoKZGVmIGZ3KEksdyk6CiAgbHc9bGVuKHcpCiAgT2hhdCA9IEkKICBhLmFwcGVuZChJKQogIGZvciBpIGluIHJhbmdlKGx3KToKICAgIE9oYXQgPSBucC5kb3QoT2hhdCx3W2ldKQogICAgei5hcHBlbmQoYWN0cChPaGF0KSkKICAgIE9oYXQgPSBhY3QoT2hhdCkKICAgIGEuYXBwZW5kKE9oYXQpCiAgcmV0dXJuIE9oYXQKCmRlZiBidyhJLHcsY29zdCk6CiAgbHcgPSBsZW4odykKICBkID0gbGlzdChyYW5nZShsdykpCiAgZFstMV09IG5wLm11bHRpcGx5KGNvc3QselstMV0pCiAgZm9yIGkgaW4gcmFuZ2UobHctMSk6CiAgICBkWy1pLTJdPSBucC5kb3QoZFstaS0xXSx3Wy1pLTFdLnRyYW5zcG9zZSgpKSp6Wy1pLTJdCiAgZm9yIGkgaW4gcmFuZ2UobHcpOgogICAgZFstaS0xXT0gbnAuZG90KG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FdKzEwMCphcnJbMl0rMTAqYXJyWzNdK2Fycls0XQogIGlmIG5bMV0gPiA3IGFuZCBub3QgKGFycl9kdXBfY2hlY2sgaW4gYXJybCk6CiAgICBhcnJsLmFwcGVuZChhcnJfZHVwX2NoZWNrKQogICAgcHJpbnQoc3RyKGludChhcnJbMF0pKSsibsKyICsgIitzdHIoaW50KGFyclsxXSkpKyJuICsgIitzdHIoaW50KGFyclsyXSkpKyIgKyAiK3N0cihpbnQoYXJyWzNdKSkrIiDDlyAiK3N0cihpbnQoYXJyWzRdKSkrIl5uIikKICAgIHByaW50KG5bMV0sInByaW1lIG51bWJlcnMgZm91bmQgXG4iKQoKCgoKCgoKCgoK"},"asBuffer":null},"loaded":true}}
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
import numpy as np
from random import randrange

z = []
a = []
lw = 0

def act(lst):
  return ((1+np.exp(-(lst)))**-1)

def actp(lst):
  return ((np.exp(lst)))*((np.exp(lst)+1)**-2)

def W(n,m):
  return 4*np.random.normal(size=(n,m))-2

def wts(hl):
  lw = len(hl)-1
  w = []
  for i in range(lw):
    w.append(W(hl[i],hl[i+1]))
  return w

def fw(I,w):
  lw=len(w)
  Ohat = I
  a.append(I)
  for i in range(lw):
    Ohat = np.dot(Ohat,w[i])
    z.append(actp(Ohat))
    Ohat = act(Ohat)
    a.append(Ohat)
  return Ohat

def bw(I,w,cost):
  lw = len(w)
  d = list(range(lw))
  d[-1]= np.multiply(cost,z[-1])
  for i in range(lw-1):
    d[-i-2]= np.dot(d[-i-1],w[-i-1].transpose())*z[-i-2]
  for i in range(lw):
    d[-i-1]= np.dot(a[-i-2].transpose(),d[-i-1])
  return d, w

def wc(dwwI):
  for i in range(len(dwwI[1])):
    dwwI[1][i]=dwwI[1][i]+dwwI[0][i]*25

def HL(li,n,lo,hlw):
  HiLa = [hlw]*(n+2)
  HiLa[0]  = li
  HiLa[-1] = lo
  return HiLa[:]

##############################################################

def check(a, s, d, n):
	x = pow(a, d, n)
	if x == 1:
		return True
	for i in range(s - 1):
		if x == n - 1:
			return True
		x = pow(x, 2, n)
	return x == n - 1

def miller_rabin1(n, k=20):
	if not n & 1:
		return 0
	if n < 6:
	  return 0
	s = 0
	d = n - 1
	while d % 2 == 0:
		d >>= 1
		s += 1
	for i in range(k):
		a = randrange(2, n-2)
		if not check(a, s, d, n):
			return 0
	return 1

###########################################################

def func(fd,i):
  fd = np.array(fd)
  fd = np.round_(fd*10-np.array([3,3,3,-1,-2])).tolist()
  return fd[0]*i*i+ fd[1]*i+ fd[2]+ fd[3]*fd[4]**i

def func2(fd,i):
  fd = np.array(fd)
  fd = np.round_(fd*10-np.array([3,3,3,-1,-2])).tolist()
  return fd[0]*i*i+ fd[1]*i+ fd[2]+ fd[3]*np.exp(fd[4]*i)

###########################################################

def seq_check(fd):
  k = 0
  for i in range(1,20):
    c = func(fd,i)
    if c < 10**100:
      k += miller_rabin1(int(c))
  return k

def seq_dis(fd):
  for i in range(1,100):
    f = int(func(fd,i))
    if f < 10**100:
      print(f,miller_rabin1(f))
  print()

##############################################################

def grad_adj(lis,nudge):
  #return lis
  return np.where(lis==np.amax(lis),nudge, 0)

def grad(fd, nudge=0.5):
  grad = np.zeros((1,len(fd[0])))
  for i in range(len(fd[0])):
    fd[0][i] = fd[0][i]+nudge
    bt = seq_check(fd[0])
    fd[0][i] = fd[0][i]-2*nudge
    grad[0][i] = 10*(bt-seq_check(fd[0]))
    fd[0][i] = fd[0][i]+nudge
  return grad_adj(grad[:],nudge)


def nn(I,nudge=0.75,iterations=500, hls=2, hlw=3):
  hl = HL(len(I[0]),hls,5,hlw)
  w = wts(hl)
  
  while seq_check(fw(I,w)[0]) < 3:
    w = wts(hl)
  rev_check = seq_check(fw(I,w)[0])
  
  fd = fw(I,w)
  for i in range(iterations):
    fd = fw(I,w)
    w1 = w[:]
    wc(bw(I,w,grad(fd,nudge)))
    
    rev_check1 = seq_check(fd[0])
    if rev_check1 < rev_check:
      w = w1
      nudge = 0.1*np.random.randn()+nudge
    rev_check = rev_check1
    
  return fd,seq_check(fd[0])


In = np.array([[0.5,1]])

arrl = []

for i in range(10000):
  n = nn(In,iterations=60)
  arr = np.round_(n[0]*10-np.array([3,3,3,-1,-2]))[0]
  arr_dup_check = 10000*arr[0]+1000*arr[1]+100*arr[2]+10*arr[3]+arr[4]
  if n[1] > 7 and not (arr_dup_check in arrl):
    arrl.append(arr_dup_check)
    print(str(int(arr[0]))+"n² + "+str(int(arr[1]))+"n + "+str(int(arr[2]))+" + "+str(int(arr[3]))+" × "+str(int(arr[4]))+"^n")
    print(n[1],"prime numbers found \n")