Add files via upload
This commit is contained in:
parent
c338b6dc5f
commit
d7b3d8560b
8 changed files with 905 additions and 127 deletions
|
|
@ -4,15 +4,16 @@
|
|||
! COMPILATION: a f 'f77 -O3 -o symbolic_regress1.x symbolic_regress1.f |& more'
|
||||
! SAMPLE USAGE: call symbolic_regress1.x 10ops.txt arity2templates.txt mystery_constant.dat results.dat
|
||||
! functions.dat contains a single line (say "0>+*-/") with the single-character symbols
|
||||
! that will be used, drawn from this list:
|
||||
! that will be used, drawn from this list:
|
||||
!
|
||||
! Binary:
|
||||
! +: add
|
||||
! *: multiply
|
||||
! -: subtract
|
||||
! /: divide (Put "D" instead of "/" in file, since f77 can't load backslash
|
||||
!
|
||||
! Unary:
|
||||
! O: double (x->2*x); note that this is the letter "O", not zero
|
||||
! J: double+1 (x->2*x+1)
|
||||
! >: increment (x -> x+1)
|
||||
! <: decrement (x -> x-1)
|
||||
! ~: negate (x-> -x)
|
||||
|
|
@ -25,12 +26,10 @@
|
|||
! N: arcsin (x->arcsin(x))
|
||||
! T: arctan (x->arctan(x))
|
||||
! R: sqrt (x->sqrt(x))
|
||||
! O: double (x->2*x); note that this is the letter "O", not zero
|
||||
! J: double+1 (x->2*x+1)
|
||||
! nonary:
|
||||
! 0
|
||||
! 1
|
||||
! P = pi
|
||||
! P: pi
|
||||
! a, b, c, ...: input variables for function (need not be listed in functions.dat)
|
||||
|
||||
program symbolic_regress
|
||||
|
|
@ -44,7 +43,7 @@
|
|||
integer arities(21), nvar, nvarmax, nmax, lnblnk
|
||||
parameter(nvarmax=20, nmax=10000000)
|
||||
real*8 f, newloss, minloss, maxloss, rmsloss, xy(nvarmax+1,nmax), epsilon, DL, DL2, DL3
|
||||
parameter(epsilon=0.000000000000000000001)
|
||||
parameter(epsilon=0.00000001)
|
||||
data arities /2,2,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0/
|
||||
data functions /"+*-/><~\OJLESCANTR01P"/
|
||||
integer nn(0:2), ii(nmax), kk(nmax), radix(nmax)
|
||||
|
|
@ -155,116 +154,4 @@
|
|||
stop
|
||||
end
|
||||
|
||||
|
||||
|
||||
real*8 function f(n,arities,ops,x) ! n=number of ops, x=arg vector
|
||||
implicit none
|
||||
integer nmax, n, i, j, arities(n), arity, lnblnk
|
||||
character*60 ops
|
||||
parameter(nmax=100)
|
||||
real*8 x(nmax), y, stack(nmax)
|
||||
character op
|
||||
!write(*,*) 'Evaluating function with ops = ',ops(1:n)
|
||||
!write(*,'(3f10.5,99i3)') (x(i),i=1,3), (arities(i),i=1,n)
|
||||
j = 0 ! Number of numbers on the stack
|
||||
do i=1,n
|
||||
arity = arities(i)
|
||||
op = ops(i:i)
|
||||
if (arity.eq.0) then ! This is a nonary function
|
||||
if (op.eq."0") then
|
||||
y = 0.
|
||||
else if (op.eq."1") then
|
||||
y = 1.
|
||||
else if (op.eq."P") then
|
||||
y = 4.*atan(1.) ! pi
|
||||
else
|
||||
y = x(ichar(op)-96)
|
||||
end if
|
||||
else if (arity.eq.1) then ! This is a unary function
|
||||
if (op.eq.">") then
|
||||
y = stack(j) + 1
|
||||
else if (op.eq."<") then
|
||||
y = stack(j) - 1
|
||||
else if (op.eq."~") then
|
||||
y = -stack(j)
|
||||
else if (op.eq."\") then
|
||||
y = 1./stack(j)
|
||||
else if (op.eq."L") then
|
||||
y = log(stack(j))
|
||||
else if (op.eq."E") then
|
||||
y = exp(stack(j))
|
||||
else if (op.eq."S") then
|
||||
y = sin(stack(j))
|
||||
else if (op.eq."C") then
|
||||
y =cos(stack(j))
|
||||
else if (op.eq."A") then
|
||||
y = abs(stack(j))
|
||||
else if (op.eq."N") then
|
||||
y = asin(stack(j))
|
||||
else if (op.eq."T") then
|
||||
y = atan(stack(j))
|
||||
else if (op.eq."O") then
|
||||
y = 2.*stack(j)
|
||||
else if (op.eq."J") then
|
||||
y = 1+2.*stack(j)
|
||||
else
|
||||
y = sqrt(stack(j))
|
||||
end if
|
||||
else ! This is a binary function
|
||||
if (op.eq."+") then
|
||||
y = stack(j-1)+stack(j)
|
||||
else if (op.eq."-") then
|
||||
y = stack(j-1)-stack(j)
|
||||
else if (op.eq."*") then
|
||||
y = stack(j-1)*stack(j)
|
||||
else
|
||||
y = stack(j-1)/stack(j)
|
||||
end if
|
||||
end if
|
||||
j = j + 1 - arity
|
||||
stack(j) = y
|
||||
! write(*,'(9f10.5)') (stack(k),k=1,j)
|
||||
end do
|
||||
if (j.ne.1) stop 'DEATH ERROR: STACK UNBALANCED'
|
||||
f = stack(1)
|
||||
!write(*,'(9f10.5)') 666.,x(1),x(2),x(3),f
|
||||
return
|
||||
end
|
||||
|
||||
subroutine multiloop(n,bases,i,done)
|
||||
! Handles <n> nested loops with loop variables i(1),...i(n).
|
||||
! Example: With n=3, bases=2, repeated calls starting with i=(000) will return
|
||||
! 001, 010, 011, 100, 101, 110, 111, 000 (and done=.true. the last time).
|
||||
! All it's doing is counting in mixed radix specified by the array <bases>.
|
||||
implicit none
|
||||
integer n, bases(n), i(n), k
|
||||
logical done
|
||||
done = .false.
|
||||
k = 1
|
||||
555 i(k) = i(k) + 1
|
||||
if (i(k).lt.bases(k)) return
|
||||
i(k) = 0
|
||||
k = k + 1
|
||||
if (k.le.n) goto 555
|
||||
done = .true.
|
||||
return
|
||||
end
|
||||
|
||||
subroutine LoadMatrixTranspose(nd,n,mmax,m,A,f)
|
||||
! Reads the n x m matrix A from the file named f, stored as its transpose
|
||||
implicit none
|
||||
integer nd,mmax,n,m,j
|
||||
real*8 A(nd,mmax)
|
||||
character*60 f
|
||||
open(2,file=f,status='old')
|
||||
m = 0
|
||||
555 m = m + 1
|
||||
if (m.gt.mmax) stop 'DEATH ERROR: m>mmax in LoadVectorTranspose'
|
||||
read(2,*,end=666) (A(j,m),j=1,n)
|
||||
goto 555
|
||||
666 close(2)
|
||||
m = m - 1
|
||||
print *,m,' rows read from file ',f
|
||||
return
|
||||
end
|
||||
|
||||
include 'tools.f'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue