18 subroutine prop(x, conec, n, units, u)
28 integer n, u, conec(n,2)
29 double precision x(n), units(u)
31 integer src, trg, ctrg, xn
44 units(ctrg) = 1./(1.+exp(-units(ctrg)))
49 units(ctrg) = units(src) * x(xn)
53 units(ctrg) = units(ctrg) + x(xn)
55 units(ctrg) = units(ctrg) + units(src) * x(xn)
59 units(ctrg) = 1./(1.+exp(-units(ctrg)))
66 subroutine sqerror(x, conec, n, units, u, inno, i, outno, o,
67 & Input, Targ, p, sqerr)
74 integer n, u, i, o, p, conec(n,2), inno(i), outno(o)
75 double precision x(n), units(u), Input(p,i), Targ(p,o), sqerr
86 units(inno(k)) = input(pat,k)
89 call prop(x, conec, n, units, u)
92 sqerr = sqerr + (units(outno(k)) - targ(pat,k))**2
101 subroutine grad(x, conec, n, bconecno, bn, units, u, inno, i,
102 & outno, o, Input, Targ, p, xprime)
110 integer n, bn, u, i, o, p
111 integer conec(n,2), bconecno(bn), inno(i), outno(o)
112 double precision x(n), units(u), Input(p,i), Targ(p,o)
113 double precision xprime(n), diff(o), bunits(u)
115 integer k, pat, src, trg, ctrg
116 double precision deriv, cx
128 units(inno(k)) = input(pat,k)
130 call prop(x, conec, n, units, u)
133 diff(k) = units(outno(k)) - targ(pat,k)
134 deriv = units(outno(k)) * (1. - units(outno(k)))
135 bunits(outno(k)) = diff(k) * deriv
139 ctrg = conec(bconecno(1),1)
142 src = conec(bconecno(k),2)
143 trg = conec(bconecno(k),1)
145 if (trg.ne.ctrg)
then
146 deriv = units(ctrg) * (1. - units(ctrg))
147 bunits(ctrg) = bunits(ctrg) * deriv
149 bunits(ctrg) = bunits(src) * cx
151 bunits(ctrg) = bunits(ctrg) + bunits(src) * cx
154 deriv = units(ctrg) * (1 - units(ctrg))
155 bunits(ctrg) = bunits(ctrg) * deriv
162 xprime(k) = xprime(k) + bunits(trg)
164 xprime(k) = xprime(k) + units(src) * bunits(trg)
173 subroutine recall(x, conec, n, units, u, inno, i, outno, o,
181 integer n, u, i, o, conec(n,2), inno(i), outno(o)
182 double precision x(n), units(u), input(i), output(o)
190 units(inno(k)) = input(k)
193 call prop(x, conec, n, units, u)
196 output(k) = units(outno(k))
203 subroutine diff(x, conec, n, dconecno, dn, dconecmk, units, u,
204 & inno, i, outno, o, input, deriv)
213 integer n, dn, u, i, o, conec(n,2), dconecno(dn), dconecmk(i+1)
214 integer inno(i), outno(o)
215 double precision x(n), units(u), dunits(u), input(i), deriv(o,i)
217 integer k, di, trg, src, ctrg, xn
224 units(inno(k)) = input(k)
225 dunits(inno(k)) = 0d0
230 call prop(x, conec, n, units, u)
232 units(k) = units(k) * (1d0 - units(k))
239 dunits(outno(k)) = 0d0
244 dunits(inno(di)) = units(inno(di))
248 ctrg = conec(dconecno(dconecmk(di)+1),2)
250 do xn=dconecmk(di)+1,dconecmk(di+1)
251 src = conec(dconecno(xn),1)
252 trg = conec(dconecno(xn),2)
254 if (trg.ne.ctrg)
then
255 dunits(ctrg) = dunits(ctrg) * units(ctrg)
257 dunits(ctrg) = dunits(src) * dx
259 dunits(ctrg) = dunits(ctrg) + dunits(src) * dx
262 dunits(ctrg) = dunits(ctrg) * units(ctrg)
266 deriv(k, di) = dunits(outno(k))
267 dunits(outno(k)) = 0d0
270 dunits(inno(di)) = 0d0
285 subroutine func(x, conec, n, bconecno, bn, units, u, inno, i,
286 & outno, o, Input, Targ, p, sqerr)
295 integer n, bn, u, i, o, p
296 integer conec(n,2), bconecno(bn), inno(i), outno(o)
297 double precision x(n), units(u), Input(p,i), Targ(p,o), sqerr
301 call sqerror(x, conec, n, units, u, inno, i, outno, o,
302 & input, targ, p, sqerr)
308 subroutine pikaiaff(x, ffn, conec, n, units, u, inno, i, outno, o,
309 & Input, Targ, p, bound1, bound2, isqerr)
319 integer n, ffn, u, i, o, p, conec(n,2), inno(i), outno(o)
320 double precision x(n), x2(n), units(u), Input(p,i), Targ(p,o)
321 double precision bound1, bound2, isqerr
326 call vmapa(x, n, 0d0, 1d0, bound1, bound2, x2)
328 call sqerror(x2, conec, n, units, u, inno, i, outno, o,
329 & input, targ, p, isqerr)
337 subroutine normcall(x, conec, n, units, u, inno, i, outno, o,
338 & eni, deo, input, output)
348 integer n, u, i, o, conec(n,2), inno(i), outno(o)
349 double precision x(n), units(u), input(i), output(o)
350 double precision eni(i,2), deo(o,2)
355 call setin(input, inno, i, eni, units, u)
357 call prop(x, conec, n, units, u)
359 call getout(units, u, outno, o, deo, output)
365 subroutine normdiff(x, conec, n, dconecno, dn, dconecmk, units,
366 & u, inno, i, outno, o, eni, ded, input, deriv)
379 integer n, dn, u, i, o, conec(n,2), dconecno(dn), dconecmk(i+1)
380 integer inno(i), outno(o)
381 double precision x(n), units(u), dunits(u), input(i), deriv(o,i)
382 double precision eni(i,2), ded(o,i)
384 integer k, di, trg, src, ctrg, xn
390 call setin(input, inno, i, eni, units, u)
392 call prop(x, conec, n, units, u)
397 units(k) = units(k) * (1d0 - units(k))
405 dunits(outno(k)) = 0d0
410 dunits(inno(di)) = units(inno(di))
414 ctrg = conec(dconecno(dconecmk(di)+1),2)
416 do xn=dconecmk(di)+1,dconecmk(di+1)
417 src = conec(dconecno(xn),1)
418 trg = conec(dconecno(xn),2)
420 if (trg.ne.ctrg)
then
421 dunits(ctrg) = dunits(ctrg) * units(ctrg)
423 dunits(ctrg) = dunits(src) * dx
425 dunits(ctrg) = dunits(ctrg) + dunits(src) * dx
428 dunits(ctrg) = dunits(ctrg) * units(ctrg)
432 deriv(k, di) = dunits(outno(k))*ded(k,di)
433 dunits(outno(k)) = 0d0
436 dunits(inno(di)) = 0d0
443 subroutine normcall2(x, conec, n, units, u, inno, i, outno, o,
444 & eni, deo, input, p, output)
451 integer n, u, i, o, conec(n,2), inno(i), outno(o), p
452 double precision x(n), units(u), input(p,i), output(p,o)
453 double precision eni(i,2), deo(o,2)
455 double precision tmpinp(i), tmpout(o)
463 tmpinp(k) = input(j,k)
465 call normcall(x, conec, n, units, u, inno, i, outno, o,
466 & eni, deo, tmpinp, tmpout)
468 output(j,k) = tmpout(k)
476 subroutine normdiff2(x, conec, n, dconecno, dn, dconecmk, units,u,
477 & inno, i, outno, o, eni, ded, input, p, deriv)
484 integer n, dn, u, i, o, p, conec(n,2), dconecno(dn), dconecmk(i+1)
485 integer inno(i), outno(o)
486 double precision x(n), units(u), input(p,i), deriv(p,o,i)
487 double precision eni(i,2), ded(o,i)
490 double precision tmpinp(i), tmpder(o,i)
497 tmpinp(k) = input(j,k)
499 call normdiff(x, conec, n, dconecno, dn, dconecmk, units,
500 & u, inno, i, outno, o, eni, ded, tmpinp, tmpder)
503 deriv(j,k,l) = tmpder(k,l)
520 subroutine momentum(x, conec, n, bconecno, bn, units, u, inno, i,
521 & outno, o, Input, Targ, p, eta, moment, maxiter)
528 integer n, bn, u, i, o, p, maxiter
529 integer conec(n,2), bconecno(bn), inno(i), outno(o)
530 double precision x(n), units(u), Input(p,i), Targ(p,o)
531 double precision xprime(n), update, update0(n), eta, moment
543 do while (k.lt.maxiter)
544 call grad(x, conec, n, bconecno, bn, units, u, inno, i,
545 & outno, o, input, targ, p, xprime)
547 update = -eta*xprime(j)
548 x(j) = x(j) + update + moment*update0(j)
558 subroutine rprop(x, conec, n, bconecno, bn, units, u, inno, i,
559 & outno, o, Input, Targ, p,
560 & a, b, mimin, mimax, xmi, maxiter)
567 integer n, bn, u, i, o, p, maxiter
568 integer conec(n,2), bconecno(bn), inno(i), outno(o)
569 double precision x(n), units(u), Input(p,i), Targ(p,o)
570 double precision xprime(n), xprime0(n), xmi(n)
571 double precision a, b, mimax, mimin
583 do while (k.lt.maxiter)
584 call grad(x, conec, n, bconecno, bn, units, u, inno, i,
585 & outno, o, input, targ, p, xprime)
588 if ( xprime(j) * xprime0(j) .gt. 0 )
then
589 xmi(j) =
min( a * xmi(j), mimax )
590 elseif ( xprime(j) * xprime0(j) .lt. 0 )
then
591 xmi(j) =
max( b * xmi(j), mimin )
596 x(j) = x(j) -
sign( xmi(j), xprime(j) )
597 xprime0(j) = xprime(j)
614 subroutine setin(input, inno, i, eni, units, u)
621 integer i, u, inno(i)
622 double precision input(i), units(u), eni(i,2)
629 units(inno(k)) = eni(k,1) * input(k) + eni(k,2)
636 subroutine getout(units, u, outno, o, deo, output)
643 integer o, u, outno(o)
644 double precision output(o), units(u), deo(o,2)
651 output(k) = deo(k,1) * units(outno(k)) + deo(k,2)
658 function mapa(f, a, b, c, d)
665 double precision a, b, c, d,
f,
mapa
670 t = ( d - c ) / ( b - a )
671 mapa = c + (
f - a ) * t
677 function dmapa(f, a, b, c, d)
685 double precision a, b, c, d,
f,
dmapa
688 dmapa = ( d - c ) / ( b - a )
694 subroutine vmapa(vin, n, a, b, c, d, vout)
702 double precision a, b, c, d, vin(n), vout(n)
710 t = ( d - c ) / ( b - a )
712 vout(k) = c + ( vin(k) - a ) * t
719 subroutine mmapa(mmin, m, n, a, b, c, d, mmout)
727 double precision a, b, c, d, mmin(m, n), mmout(m,n)
735 t = ( d - c ) / ( b - a )
738 mmout(j,k) = c + ( mmin(j,k) - a ) * t