Skip to content

Commit 03c3400

Browse files
authored
Update z3_Neural_Networks.py
1 parent 4d317ff commit 03c3400

File tree

1 file changed

+117
-2
lines changed

1 file changed

+117
-2
lines changed

Code Examples/Z3 Examples/z3_Neural_Networks.py

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@
4444
# print(f"{lhs} == {rhs}", end="\n\n")
4545

4646
layer_2_out = activation1 * weights2 + bias2
47-
print(layer_2_out.tolist()[0][0])
4847

4948
for index, elems in enumerate(layer_2_out):
5049
rhs = elems.tolist()[0][0]
5150
lhs = outputs[index]
5251
# ReLU Activation
5352
S.add(z3.If(rhs >= 0, lhs == rhs, lhs == 0))
53+
if index == 0:
54+
print(z3.If(rhs >= 0, lhs == rhs, lhs == 0))
5455
# print(f"{lhs} == {rhs}", end="\n\n")
5556

5657
sumVal = z3.Sum([(inputs[index] * outputs[index]) for index in range(4)])
@@ -70,9 +71,123 @@
7071
[S.add(j != 0) for j in outputs]
7172

7273
# Loss
73-
S.add(loss == sumVal + 10000 * z3.If(inputs[1] - inputs[-1] >= 0, inputs[1] - inputs[-1], 0))
74+
S.add(loss == sumVal ** 2 + 10000 * z3.If(inputs[1] - inputs[-1] >= 0, inputs[1] - inputs[-1], 0))
7475
S.add(loss == 0)
7576

7677
# print(S.assertions())
7778
print(S.check())
7879
print(S.model())
80+
81+
# [weight_l1_3_3 = 131073/65536,
82+
# weight_l2_2_2 = 4,
83+
# n_input_l1 = 15,
84+
# a_input_l1 = 15,
85+
# weight_l2_2_3 = 4,
86+
# weight_l1_0_6 = 33/16,
87+
# weight_l2_9_0 = 4,
88+
# weight_l2_3_1 = 4,
89+
# weight_l1_0_7 = 33/16,
90+
# weight_l1_0_2 = 33/16,
91+
# weight_l2_3_2 = 4,
92+
# weight_l1_1_5 = 513/256,
93+
# weight_l1_3_6 = 131073/65536,
94+
# weight_l2_3_0 = 4,
95+
# weight_l1_3_0 = 131073/65536,
96+
# bias_l1_1 = 65537/65536,
97+
# bias_l1_4 = 65537/65536,
98+
# weight_l1_3_1 = 131073/65536,
99+
# bias_l1_8 = 65537/65536,
100+
# C_1_l1 = -1,
101+
# weight_l1_2_5 = 8193/4096,
102+
# weight_l2_8_0 = 4,
103+
# C_3_l1 = -4888,
104+
# weight_l1_2_2 = 8193/4096,
105+
# bias_l1_0 = 65537/65536,
106+
# weight_l1_1_4 = 513/256,
107+
# y_input_l1 = 15,
108+
# weight_l1_2_4 = 8193/4096,
109+
# weight_l1_2_6 = 8193/4096,
110+
# weight_l1_3_5 = 131073/65536,
111+
# x_input_l1 = 15,
112+
# bias_l2_0 = 8,
113+
# weight_l1_0_4 = 33/16,
114+
# bias_l1_6 = 65537/65536,
115+
# weight_l1_0_1 = 33/16,
116+
# weight_l1_1_8 = 513/256,
117+
# weight_l1_3_9 = 131073/65536,
118+
# bias_l1_2 = 65537/65536,
119+
# weight_l1_0_9 = 33/16,
120+
# bias_l1_3 = 65537/65536,
121+
# weight_l1_0_8 = 33/16,
122+
# weight_l1_2_8 = 8193/4096,
123+
# weight_l2_4_0 = 4,
124+
# weight_l2_5_0 = 4,
125+
# weight_l1_2_0 = 8193/4096,
126+
# weight_l1_3_7 = 131073/65536,
127+
# C_2_l1 = 1,
128+
# weight_l1_1_0 = 513/256,
129+
# weight_l1_2_7 = 8193/4096,
130+
# weight_l1_3_4 = 131073/65536,
131+
# weight_l2_1_0 = 4,
132+
# bias_l1_9 = 65537/65536,
133+
# weight_l1_1_3 = 513/256,
134+
# weight_l2_6_0 = 4,
135+
# weight_l1_3_2 = 131073/65536,
136+
# weight_l1_3_8 = 131073/65536,
137+
# weight_l1_2_3 = 8193/4096,
138+
# weight_l1_1_9 = 513/256,
139+
# bias_l1_5 = 65537/65536,
140+
# weight_l1_2_9 = 8193/4096,
141+
# weight_l1_0_0 = 33/16,
142+
# weight_l1_1_2 = 513/256,
143+
# weight_l2_0_2 = 4,
144+
# weight_l1_1_7 = 513/256,
145+
# weight_l2_0_0 = 4,
146+
# weight_l2_2_0 = 4,
147+
# weight_l2_0_3 = 4,
148+
# weight_l2_1_1 = 4,
149+
# weight_l1_2_1 = 8193/4096,
150+
# weight_l1_1_1 = 513/256,
151+
# weight_l1_1_6 = 513/256,
152+
# weight_l2_1_2 = 4,
153+
# weight_l2_7_0 = 4,
154+
# weight_l2_1_3 = 4,
155+
# weight_l1_0_5 = 33/16,
156+
# weight_l1_0_3 = 33/16,
157+
# weight_l2_2_1 = 4,
158+
# bias_l1_7 = 65537/65536,
159+
# weight_l2_0_1 = 4,
160+
# bias_l2_3 = 8,
161+
# bias_l2_2 = 8,
162+
# bias_l2_1 = 8,
163+
# weight_l2_9_3 = 4,
164+
# weight_l2_9_2 = 4,
165+
# weight_l2_9_1 = 4,
166+
# weight_l2_8_3 = 4,
167+
# weight_l2_8_2 = 4,
168+
# weight_l2_8_1 = 4,
169+
# weight_l2_7_3 = 4,
170+
# weight_l2_7_2 = 4,
171+
# weight_l2_7_1 = 4,
172+
# weight_l2_6_3 = 4,
173+
# weight_l2_6_2 = 4,
174+
# weight_l2_6_1 = 4,
175+
# weight_l2_5_3 = 4,
176+
# weight_l2_5_2 = 4,
177+
# weight_l2_5_1 = 4,
178+
# weight_l2_4_3 = 4,
179+
# weight_l2_4_2 = 4,
180+
# weight_l2_4_1 = 4,
181+
# weight_l2_3_3 = 4,
182+
# C_0_l1 = 4888,
183+
# loss = 0,
184+
# activation_9 = 122,
185+
# activation_8 = 122,
186+
# activation_7 = 122,
187+
# activation_6 = 122,
188+
# activation_5 = 122,
189+
# activation_4 = 122,
190+
# activation_3 = 122,
191+
# activation_2 = 122,
192+
# activation_1 = 122,
193+
# activation_0 = 122]

0 commit comments

Comments
 (0)