アットウィキロゴ

評価関数bb

Function nearu(s As Single, mx As Single, nx As Single, u) As Single
Dim m1 As Single
Dim m2 As Single
Dim m3 As Single
Dim n1 As Single
Dim n2 As Single
Dim n3 As Single
Dim pp As Single
Dim dm As Single
Dim dn As Single
Dim nu As Single
pp = 0
m1 = mx
n1 = nx
If n1 < -10 Then pp = 1
If n1 < -10 Then n1 = -10
If n1 > 9 Then pp = 1
If n1 > 9 Then n1 = 9
n2 = Int(n1)
n3 = n2 + 1
dn = (n1 - n2) * (u(s, m2, n3) - u(s, m2, n2))
nu = u(s, m2, n2) + dn
If pp = 1 Then nu = -999
nearu = nu
End Function
Function nearv(s As Single, mx As Single, nx As Single, v) As Single
Dim m1 As Single
Dim m2 As Single
Dim m3 As Single
Dim n1 As Single
Dim n2 As Single
Dim n3 As Single
Dim pp As Single
Dim dm As Single
Dim dn As Single
Dim nv As Single
pp = 0
m1 = mx
n1 = nx
If m1 < -9 Then pp = 1
If m1 < -9 Then m1 = -9
If m1 > 9 Then pp = 1
If m1 > 9 Then m1 = 9
If n1 < -49 Then pp = 1
If n1 < -49 Then n1 = 9
If n1 > 49 Then pp = 1
If n1 > 49 Then n1 = 9
m2 = Int(m1)
m3 = m2 + 1
n2 = Int(n1)
n3 = n2 + 1
dm = (m1 - m2) * (v(s, m3, n2) - v(s, m2, n2))
dn = (n1 - n2) * (v(s, m2, n3) - v(s, m2, n2))
nv = v(s, m2, n2) + dm + dn
If pp = 1 Then nv = -999
nearv = nv
End Function

Function seeku(s As Single, th, wp As Single, bp As Single) As Single
Dim ls As Single
Dim cs As Single
Dim us As Single
Dim ys As Single
Dim ws As Single
Dim l1 As Single
Dim c1 As Single
Dim u1 As Single
Dim l2 As Single
Dim y2 As Single
Dim y1 As Single
Dim c2 As Single
Dim u2 As Single
Dim h As Single
Dim lp As Single
Dim t1 As Single
Dim t2 As Single
Dim e As Single
e = 10 ^ (-5)
h = 0.1
ls = (bp + 0.1) / th(s)
ys = th(s) * ls
cs = ys - bp
us = Log(cs) + Log(1 - ls)
ws = Log(cs) + Log(1 - ys / th(s + 1))
If ws > wp Then us = -999
t2 = 0
Do Until t2 > 10
t1 = 0
Do Until t1 > 100
l1 = ls + h
If l1 > 0.99 Then l1 = ls
c1 = th(s) * l1 - bp
y1 = th(s) * l1
u1 = Log(c1) + Log(1 - l1)
w1 = Log(c1) + Log(1 - y1 / th(s + 1))
If w1 > wp Then u1 = -999
l2 = ls - h
If l2 < 0.01 Then l2 = ls
c2 = th(s) * l2 - bp
If c2 < 0.01 Then l2 = ls
c2 = th(s) * l2 - bp
y2 = th(s) * l2
u2 = Log(c2) + Log(1 - l2)
w2 = Log(c2) + Log(1 - y2 / th(s + 1))
If w2 > wp Then u2 = -999
If u1 > us Then ls = l1
If u1 > us Then us = u1
If u2 > us Then ls = l2
If u2 > us Then us = u2
If (lp - ls) ^ 2 < e Then t1 = 1000
lp = ls
t1 = t1 + 1
Loop
h = h / 2
t2 = t2 + 1
Loop
seeku = us
End Function

Function seekw(wp As Single) As Single
Dim x1 As Single
Dim x2 As Single
Dim x3 As Single
Dim w1 As Single
Dim w2 As Single
Dim t As Single
Dim limit As Single
limit = 2 * Log(0.01)
x1 = 0.3
x2 = 0.7
t = 0
If wp < limit Then x2 = 0.01
If wp < limit Then t = 1000
Do Until t > 100
w1 = 2 * Log(x1)
w2 = 2 * Log(x2)
x3 = x2 + (wp - w2) * (x2 - x1) / (w2 - w1)
If x3 < 0 Then x3 = 0.01
If x3 = 0 Then x3 = 0.01
x1 = x2
x2 = x3
If (wp - w2) ^ 2 < 10 ^ (-5) Then t = 1000
t = t + 1
Loop
seekw = x2
End Function


Function lx(s As Single, th, tl As Single, tr As Single) As Single
Dim ls As Single
ls = ((1 - tl) * th(s) - tr) / (2 * (1 - tl) * th(s))
If ls < 0 Then ls = 0
lx = ls
End Function
Function cx(s As Single, th, tl As Single, tr As Single) As Single
Dim ls As Single
ls = ((1 - tl) * th(s) - tr) / (2 * (1 - tl) * th(s))
If ls < 0 Then ls = 0
cx = (1 - tl) * th(s) * ls + tr
End Function

Function tls(th) As Single
Dim maxw As Single
Dim tl As Single
Dim tr As Single
Dim tp As Single
Dim w1 As Single
Dim n As Single
maxw = -999
For n = 1 To 400
tl = 0.001 * n
tr = trs(th, tl)
w1 = wel(th, tl, tr)
If w1 > maxw Then tp = tl
If w1 > maxw Then maxw = w1
Next
tls = tp
End Function

Function trs(th, tl As Single) As Single
Dim tr1 As Single
Dim tr2 As Single
Dim tr3 As Single
Dim b1 As Single
Dim b2 As Single
Dim t As Single
tr1 = 0
tr2 = 0.1
t = 0
Do Until t > 100
b1 = bud(th, tl, tr1)
b2 = bud(th, tl, tr2)
tr3 = tr2 - b2 * (tr2 - tr1) / (b2 - b1)
tr1 = tr2
tr2 = tr3
If (tr1 - tr2) ^ 2 < 10 ^ (-5) Then t = 1000
t = t + 1
Loop
trs = tr2
End Function
Function wel(th, tl As Single, tr As Single) As Single
Dim w1 As Single
Dim s As Single
Dim ls As Single
Dim cs As Single
w1 = 0
For s = 1 To 100
ls = lx(s, th, tl, tr)
If ls < 0 Then ls = 0
cs = cx(s, th, tl, tr)
w1 = w1 + Log(cs) + Log(1 - ls)
Next
wel = w1
End Function
Function bud(th, tl As Single, tr As Single) As Single
Dim w1 As Single
Dim s As Single
Dim ls As Single
Dim cs As Single
Dim ys As Single
ys = 0
cs = 0
For s = 1 To 100
ls = lx(s, th, tl, tr)
If ls < 0 Then ls = 0
ys = ys + th(s) * ls
cs = cs + cx(s, th, tl, tr)
Next
bud = ys - cs
End Function
Private Sub Command1_Click()
Dim th(1 To 100) As Single
Dim s As Single
Dim m As Single
Dim n As Single
Dim tl As Single
Dim tr As Single
Dim bs(1 To 100) As Single
Dim ws(1 To 99) As Single
Dim u(1 To 99, -10 To 10, -10 To 10) As Single
Dim v(1 To 99, -10 To 10, -50 To 50) As Single
Dim w1 As Single
Dim wp As Single
Dim bp As Single
For s = 1 To 100
th(s) = 0.5 + 0.01 * s
Next
tl = tls(th)
tr = trs(th, tl)
Debug.Print tl, tr
For s = 1 To 100
bs(s) = th(s) * lx(s, th, tl, tr) - cx(s, th, tl, tr)
Next
For s = 1 To 99
w1 = Log(cx(s, th, tl, tr)) + Log(1 - th(s) * lx(s, th, tl, tr) / th(s + 1))
ws(s) = seekw(w1)
Next
h = 10 ^ (-3)
For s = 1 To 99
For m = -10 To 10
For n = -10 To 10
wp = 2 * Log(ws(s) + h * m)
bp = bs(s) + h * n
u(s, m, n) = seeku(s, th, wp, bp)
Next
Next
Debug.Print s, u(s, 0, 0)
Next
For s = 1 To 99
For m = -10 To 10
For n = -50 To 50
v(s, m, n) = -999
Next
Next
Next
s = 1
For m = -10 To 10
For n = -10 To 10
v(s, m, n) = u(s, m, n)
Next
Next
Dim nxs As Single
Dim nx1 As Single
Dim nx2 As Single
Dim uxs As Single
Dim mys As Single
Dim nys As Single
Dim vxs As Single
Dim ux1 As Single
Dim my1 As Single
Dim ny1 As Single
Dim vx1 As Single
Dim ux2 As Single
Dim my2 As Single
Dim ny2 As Single
Dim vx2 As Single
Dim j As Single
Dim t As Single
For s = 2 To 99
For m = -10 To 10
For n = -50 To 50
nxs = 0
uxs = nearu(s, m, nxs, u)
mys = (seekw(uxs) - ws(s - 1)) / h
nys = n - nxs
vxs = uxs + nearv(s - 1, mys, nys, v)
t2 = 0
j = 3
Do Until t2 > 10
nn = 700
t1 = 0
Do Until t1 > 100
nx1 = nxs + j
If nx1 > 10 Then nx1 = nxs
ux1 = nearu(s, m, nx1, u)
my1 = (seekw(ux1) - ws(s - 1)) / h
ny1 = n - nx1
vx1 = uxs + nearv(s - 1, my1, ny1, v)
nx2 = nxs - j
If nx2 < -10 Then nx2 = nxs
ux2 = nearu(s, m, nx2, u)
my2 = (seekw(ux2) - ws(s - 1)) / h
ny2 = n - nx2
vx2 = uxs + nearv(s - 1, my2, ny2, v)
If vx1 > vxs Then nxs = nx1
If vx1 > vxs Then vxs = vx1
If vx2 > vxs Then nxs = nx2
If vx2 > vxs Then vxs = vx2
If (nn - nxs) ^ 2 < 10 ^ (-5) Then t1 = 1000
nn = nxs
t1 = t1 + 1
Loop
t2 = t2 + 1
j = j / 2
Loop
v(s, m, n) = vxs
Next
Next
Debug.Print s, v(s, 0, 0)
Next


End Sub
最終更新:2009年08月13日 06:05