質問編集履歴
1
ソースコード を見やすいように、```を入れました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
```
|
12
12
|
|
13
13
|
### 該当のソースコード
|
14
|
-
|
14
|
+
```
|
15
15
|
def rosenbrock(x):
|
16
16
|
global FUNCCALLS
|
17
17
|
FUNCCALLS += 1
|
@@ -21,10 +21,10 @@
|
|
21
21
|
gradient = np.matrix([(400*(x[0]**3)-400*x[0]*x[1]+2*x[0]-2), (200*(x[1]-x[0]**2))]).T
|
22
22
|
|
23
23
|
return funcValue, gradient
|
24
|
+
```
|
24
25
|
|
25
|
-
|
26
26
|
#この関数を、optimize に呼び出します。
|
27
|
-
|
27
|
+
```
|
28
28
|
def optimize(func, x0, epsilon_g,n):
|
29
29
|
|
30
30
|
H=np.identity(n)
|
@@ -92,9 +92,9 @@
|
|
92
92
|
outputs=k
|
93
93
|
|
94
94
|
return xopt, fopt, outputs
|
95
|
-
|
95
|
+
```
|
96
96
|
#アルファの値を見つけるために、bracketing (線形探索)のコードを呼び出します。
|
97
|
-
|
97
|
+
```
|
98
98
|
def bracket(t,p,func):
|
99
99
|
print("in the blacket")
|
100
100
|
print(t[0,0])
|
@@ -159,10 +159,10 @@
|
|
159
159
|
|
160
160
|
|
161
161
|
i=I+1
|
162
|
+
```
|
162
163
|
|
163
|
-
|
164
164
|
#最小値が見つかりそうな場所に入ったら、pinpointにて値を出します。
|
165
|
-
|
165
|
+
```
|
166
166
|
def pinpoint(l,h,mu_1,mu_2,x,p,func):
|
167
167
|
print("in the pinpoint")
|
168
168
|
global high
|
@@ -243,12 +243,55 @@
|
|
243
243
|
print(high)
|
244
244
|
|
245
245
|
j=j+1
|
246
|
+
```
|
246
247
|
|
247
|
-
|
248
248
|
上記のピンポイントのループから抜け出せなくなり、困ってます。
|
249
249
|
助けて頂けないでしょうか。
|
250
250
|
|
251
|
+
#よび出し関数です。
|
252
|
+
```
|
253
|
+
testFuncs = [rosenbrock]
|
251
254
|
|
255
|
+
|
256
|
+
|
257
|
+
for _, func in enumerate(testFuncs):
|
258
|
+
|
259
|
+
# set the seed so every one is tested at the same points
|
260
|
+
np.random.seed(0)
|
261
|
+
|
262
|
+
trialScore = 0
|
263
|
+
for _ in range(nTrails):
|
264
|
+
FUNCCALLS = 0
|
265
|
+
|
266
|
+
|
267
|
+
# get a random starting point
|
268
|
+
x0 = np.random.normal(size=2)*3
|
269
|
+
|
270
|
+
|
271
|
+
# call the optimizer
|
272
|
+
xopt, fopt, output = uncon(func, x0, 1e-6)
|
273
|
+
|
274
|
+
|
275
|
+
l=xopt[0,0]
|
276
|
+
m=xopt[0,1]
|
277
|
+
xopt=[l,m]
|
278
|
+
_, gopt = rosenbrock(np.array(xopt))
|
279
|
+
#_, gopt = matyas(np.array(xopt))
|
280
|
+
#_, gopt = paraboloid(np.array(xopt))
|
281
|
+
if (not (np.linalg.norm(gopt, ord = np.inf) <= 1e-6)):
|
282
|
+
|
283
|
+
|
284
|
+
continue
|
285
|
+
|
286
|
+
|
287
|
+
print(xopt)
|
288
|
+
print('fopt ', fopt, FUNCCALLS)
|
289
|
+
|
290
|
+
print(output['alias'], score)
|
291
|
+
|
292
|
+
```
|
293
|
+
|
294
|
+
|
252
295
|
```ここに言語名を入力
|
253
296
|
python
|
254
297
|
```
|