diff --git a/deps/bin/libAndersonMoore.so b/deps/bin/libAndersonMoore.so new file mode 100755 index 0000000..e4005f6 Binary files /dev/null and b/deps/bin/libAndersonMoore.so differ diff --git a/deps/libAndersonMoore.so b/deps/libAndersonMoore.so new file mode 100755 index 0000000..e4005f6 Binary files /dev/null and b/deps/libAndersonMoore.so differ diff --git a/src/AndersonMoore.jl b/src/AndersonMoore.jl new file mode 100644 index 0000000..f432dcc --- /dev/null +++ b/src/AndersonMoore.jl @@ -0,0 +1,21 @@ +__precompile__() + +module AndersonMoore +# http://www.stochasticlifestyle.com/finalizing-julia-package-documentation-testing-coverage-publishing/ + +# Set-up for callSparseAim +const lib = Libdl.dlopen(normpath(joinpath(dirname(@__FILE__), "..", "deps", "libAndersonMoore"))) +const sym = Libdl.dlsym(lib, :callSparseAim) + +# Include all files +for (root, dirs, files) in walkdir(joinpath(dirname(@__FILE__))) + for file in files + file == "AndersonMoore.jl" ? nothing : include(joinpath(root, file)) + end +end + +# Export all functions +export exactShift!, numericShift!, shiftRight!, buildA!, augmentQ!, eigenSys!, reducedForm, +AndersonMooreAlg, sameSpan, deleteCols, deleteRows, callSparseAim, checkAM, err, gensysToAMA + +end # module diff --git a/src/AndersonMoore/AndersonMooreAlg.jl b/src/AndersonMoore/AndersonMooreAlg.jl new file mode 100644 index 0000000..c3a6a4b --- /dev/null +++ b/src/AndersonMoore/AndersonMooreAlg.jl @@ -0,0 +1,108 @@ +""" + AndersonMooreAlg(h, qcols, neq) + +Solve a linear perfect foresight model using the julia eig +function to find the invariant subspace associated with the big +roots. This procedure will fail if the companion matrix is +defective and does not have a linearly independent set of +eigenvectors associated with the big roots. + + Input arguments: + + h Structural coefficient matrix (neq,neq*(nlag+1+nlead)). + neq Number of equations. + nlag Number of lags. + nlead Number of leads. + condn Zero tolerance used as a condition number test + by numericShift and reducedForm. + upper Inclusive upper bound for the modulus of roots + allowed in the reduced form. + + Output arguments: + + b Reduced form coefficient matrix (neq,neq*nlag). + rts Roots returned by eig. + ia Dimension of companion matrix (number of non-trivial + elements in rts). + nexact Number of exact shiftRights. + nnumeric Number of numeric shiftRights. + lgroots Number of roots greater in modulus than upper. + AMAcode Return code: see function AMAerr. +""" +function AndersonMooreAlg(hh::Array{Float64,2}, neq::Int64, nlag::Int64, nlead::Int64, anEpsi::Float64, upper::Float64) + + if(nlag < 1 || nlead < 1) + error("AMA_eig: model must have at least one lag and one lead.") + end + + # Initialization. + nexact = 0 + nnumeric = 0 + lgroots = 0 + iq = 0 + AMAcode = 0 + bb = 0 + qrows = neq * nlead + qcols = neq * (nlag + nlead) + bcols = neq * nlag + qq = zeros(qrows, qcols) + rts = zeros(qcols, 1) + + # Compute the auxiliary initial conditions and store them in q. + + (hh, qq, iq, nexact) = exactShift!(hh, qq, iq, qrows, qcols, neq) + if (iq > qrows) + AMAcode = 61 + return bb, rts, ia, nexact, nnumeric, lgroots, AMAcode + end + + (hh, qq, iq, nnumeric) = numericShift!(hh, qq, iq, qrows, qcols, neq, anEpsi) + if (iq > qrows) + AMAcode = 62 + return bb, rts, ia, nexact, nnumeric, lgroots, AMAcode + end + + # Build the companion matrix. Compute the stability conditions, and + # combine them with the auxiliary initial conditions in q. + + (aa, ia, js) = buildA!(hh, qcols, neq) + + if (ia != 0) + for element in aa + if isnan(element) || isinf(element) + display("A is NAN or INF") + AMAcode = 63 + return bb, rts, ia, nexact, nnumeric, lgroots, AMAcode + end + end + (ww, rts, lgroots) = eigenSys!(aa, upper, min(size(js, 1), qrows - iq + 1)) + + + qq = augmentQ!(qq, ww, js, iq, qrows) + end + + test = nexact + nnumeric + lgroots + if (test > qrows) + AMAcode = 3 + elseif (test < qrows) + AMAcode = 4 + end + + # If the right-hand block of q is invertible, compute the reduced form. + + if(AMAcode == 0) + (nonsing,bb) = reducedForm(qq, qrows, qcols, bcols, neq, anEpsi) + if ( nonsing && AMAcode==0) + AMAcode = 1 + elseif (!nonsing && AMAcode==0) + AMAcode = 5 + elseif (!nonsing && AMAcode==3) + AMAcode = 35 + elseif (!nonsing && AMAcode==4) + AMAcode = 45 + end + end + + return bb, rts, ia, nexact, nnumeric, lgroots, AMAcode + # (bbJulia,rtsJulia,iaJulia,nexJulia,nnumJulia,lgrtsJulia,AMAcodeJulia) = AMAalg(hh,neq,nlag,nlead,anEpsi,1+anEpsi) +end # AndersonMooreAlg diff --git a/src/AndersonMoore/augmentQ!.jl b/src/AndersonMoore/augmentQ!.jl new file mode 100644 index 0000000..54fd9ec --- /dev/null +++ b/src/AndersonMoore/augmentQ!.jl @@ -0,0 +1,18 @@ +""" + augmentQ(qq, ww, js, iq, qrows) + +Copy the eigenvectors corresponding to the largest roots into the +remaining empty rows and columns js of q +""" +function augmentQ!(qq::Array{Float64,2}, ww::Array{Float64,2}, js::Array{Int64,2}, iq::Int64, qrows::Int64) + + if(iq < qrows) + lastrows = (iq + 1) : qrows + wrows = 1 : length(lastrows) + qq[lastrows, js] = @views ww[:, wrows]' + end + + return qq + +end # augmentQ + diff --git a/src/AndersonMoore/buildA!.jl b/src/AndersonMoore/buildA!.jl new file mode 100644 index 0000000..0ec74bf --- /dev/null +++ b/src/AndersonMoore/buildA!.jl @@ -0,0 +1,57 @@ +""" + buildA(hh, qcols, neq) + +Build the companion matrix, deleting inessential lags. +Solve for x_{t+nlead} in terms of x_{t+nlag},...,x_{t+nlead-1}. + +""" +function buildA!(hh::Array{Float64,2}, qcols::Int64, neq::Int64) + + left = 1:qcols + right = (qcols + 1):(qcols + neq) + + tmp = similar(hh) + tmp[:, left] = \(-hh[:, right], hh[:, left]) + + # Build the big transition matrix. + + aa = zeros(qcols, qcols) + + if(qcols > neq) + eyerows = 1:(qcols - neq) + eyecols = (neq + 1):qcols + aa[eyerows, eyecols] = eye(qcols - neq) + end + hrows = (qcols - neq + 1):qcols + aa[hrows, :] = tmp[:, left] + + # Delete inessential lags and build index array js. js indexes the + # columns in the big transition matrix that correspond to the + # essential lags in the model. They are the columns of q that will + # get the unstable left eigenvectors. + + js = Array{Int64}(1,qcols) + for ii in 1 : qcols + js[1, ii] = ii + end + + zerocols = sum(abs.(aa), 1) + zerocols = find(col->(col == 0), zerocols) + + + while length(zerocols) != 0 + # aa = filter!(x->(x !in zerocols), aa) + + aa = deleteCols(aa, zerocols) + aa = deleteRows(aa, zerocols) + js = deleteCols(js, zerocols) + + zerocols = sum(abs.(aa), 1) + zerocols = find(col->(col == 0), zerocols) + + end + ia = length(js) + + return (aa::Array{Float64,2}, ia::Int64, Int64.(js)::Array{Int64,2}) + +end # buildA diff --git a/src/AndersonMoore/eigenSys!.jl b/src/AndersonMoore/eigenSys!.jl new file mode 100644 index 0000000..26a2e72 --- /dev/null +++ b/src/AndersonMoore/eigenSys!.jl @@ -0,0 +1,34 @@ +""" + eigenSys!(h, qcols, neq) + +Compute the roots and the left eigenvectors of the companion +matrix, sort the roots from large-to-small, and sort the +eigenvectors conformably. Map the eigenvectors into the real +domain. Count the roots bigger than uprbnd. +""" +function eigenSys!(aa::Array{Float64,2}, upperbound::Float64, rowsLeft::Int64) + + roots = eigvals(aa') + ww = eigvecs(aa') + + # sort eigenvalues in descending order of magnitude + magnitudes = abs.(roots) + highestToLowestMag = sortperm(magnitudes, rev = true) # reverse order + roots = roots[highestToLowestMag] + + # sort eigenvecs in order found above + ww = ww[:, highestToLowestMag] + + # Given a complex conjugate pair of vectors W = [w1,w2], there is a + # nonsingular matrix D such that W*D = real(W) + imag(W). That is to + # say, W and real(W)+imag(W) span the same subspace, which is all + # that AMA cares about. + + ww = ( real(ww) + imag(ww) )::Array{Float64,2} + + # count how many roots are above the upperbound threshold + lgroots = mapreduce((mag->mag > upperbound ? 1 : 0), +, magnitudes) + + return (ww, roots, lgroots) + +end # eigenSys! diff --git a/src/AndersonMoore/err.jl b/src/AndersonMoore/err.jl new file mode 100644 index 0000000..85ab8f7 --- /dev/null +++ b/src/AndersonMoore/err.jl @@ -0,0 +1,46 @@ +function err(c) +# err(c) +# +# Interpret the return codes generated by the AMA routines. +# +# The return code c = 2 is used by AMA_schur.m but not by AMA_eig.m. + +# Original author: Gary Anderson +# Original file downloaded from: +# http://www.federalreserve.gov/Pubs/oss/oss4/code.html +# Adapted for Dynare by Dynare Team. +# +# This code is in the public domain and may be used freely. +# However the authors would appreciate acknowledgement of the source by +# citation of any of the following papers: +# +# Anderson, G. and Moore, G. +# "A Linear Algebraic Procedure for Solving Linear Perfect Foresight +# Models." +# Economics Letters, 17, 1985. +# +# Anderson, G. +# "Solving Linear Rational Expectations Models: A Horse Race" +# Computational Economics, 2008, vol. 31, issue 2, pages 95-113 +# +# Anderson, G. +# "A Reliable and Computationally Efficient Algorithm for Imposing the +# Saddle Point Property in Dynamic Models" +# Journal of Economic Dynamics and Control, 2010, vol. 34, issue 3, +# pages 472-489 + + if(c==1) e="AndersonMoore: unique solution." +elseif(c==2) e="AndersonMoore: roots not correctly computed by real_schur." +elseif(c==3) e="AndersonMoore: too many big roots." +elseif(c==35) e="AndersonMoore: too many big roots, and q(:,right) is singular." +elseif(c==4) e="AndersonMoore: too few big roots." +elseif(c==45) e="AndersonMoore: too few big roots, and q(:,right) is singular." +elseif(c==5) e="AndersonMoore: q(:,right) is singular." +elseif(c==61) e="AndersonMoore: too many exact shiftrights." +elseif(c==62) e="AndersonMoore: too many numeric shiftrights." +else e="AndersonMoore: return code not properly specified" +end + +return e + +end diff --git a/src/AndersonMoore/exactShift!.jl b/src/AndersonMoore/exactShift!.jl new file mode 100644 index 0000000..b13091d --- /dev/null +++ b/src/AndersonMoore/exactShift!.jl @@ -0,0 +1,52 @@ +""" + exactShift!(hh,qq, iq, qrows, qcols, neq) + +Compute the exact shiftrights and store them in qq. +""" +function exactShift!(hh::Array{Float64,2}, qq::Array{Float64,2}, iq::Int64, qRows::Int64, qCols::Int64, neq::Int64) + + # total number of shifts + nexact = 0 + + # functions to seperate hh + left = 1:qCols + right = (qCols + 1):(qCols + neq) + + + # get right most columns of hh + zerorows = hh[:, right]' + + # compute absolute value + zerorows = abs.(zerorows) + + # take the sum of the rows (aka 1st dimenison in julia) + zerorows = sum(zerorows, 1) + + # anon function returns index of the rows who sum is 0 + zerorows = find(row->(row == 0), zerorows) + + # continues until all zerorow indexes have been processed + while length(zerorows) != 0 && (iq <= qRows) + nz = size(zerorows, 1) + + # insert only the indexes found with zerorows into qq + qq[(iq + 1):(iq + nz), :] = hh[zerorows, left] + + # update by shifting right by $neq columns + hh[zerorows,:] = shiftRight!(hh[zerorows, :], neq) + + # increment our variables the amount of zerorows found + iq = iq + nz + nexact = nexact + nz + + # update zerorows as before but with our new hh matrix + zerorows = hh[:, right]' + zerorows = abs.(zerorows) + zerorows = sum(zerorows, 1) + zerorows = find(row->(row == 0), zerorows) + end # while + + return (hh, qq, iq, nexact) + +end # exactShift + diff --git a/src/AndersonMoore/numericShift!.jl b/src/AndersonMoore/numericShift!.jl new file mode 100644 index 0000000..246cb5a --- /dev/null +++ b/src/AndersonMoore/numericShift!.jl @@ -0,0 +1,48 @@ +""" + numericShift!(hh, qq, iq, qrows, qcols, neq, condn) + +Compute the numeric shiftrights and store them in q. +""" +function numericShift!(hh::Array{Float64,2}, qq::Array{Float64,2}, iq::Int64, qRows::Int64, qCols::Int64, neq::Int64, condn::Float64) + + # total number of shifts + nnumeric = 0 + + # functions to seperate hh + left = 1:qCols + right = (qCols + 1):(qCols + neq) + + # preform QR factorization on right side of hh + F = qrfact(hh[:, right], Val{true}) + + # filter R only keeping rows that are zero + zerorows = abs.(diag(F[:R])) + zerorows = find(x->(float(x) <= condn), zerorows) + + @inbounds while (length(zerorows) != 0) && (iq <= qRows) + # update hh with matrix multiplication of Q and hh + hh = *(F[:Q]', hh) + + # need total number of zero rows + nz = size(zerorows, 1) + + # update qq to keep track of rows that are zero + qq[(iq + 1):(iq + nz), :] = hh[zerorows, left] + + # update hh by shifting right + hh[zerorows, :] = shiftRight!(hh[zerorows, :], neq) + + # increment our variables by number of shifts + iq = iq + nz + nnumeric = nnumeric + nz + + # redo QR factorization and filter R as before + F = qrfact(hh[:, right], Val{true}) + zerorows = abs.(diag(F[:R])) + zerorows = find(x->(float(x) <= condn), zerorows) + + end # while + + return(hh, qq, iq, nnumeric) + +end # numericShift diff --git a/src/AndersonMoore/reducedForm.jl b/src/AndersonMoore/reducedForm.jl new file mode 100644 index 0000000..8e37ef4 --- /dev/null +++ b/src/AndersonMoore/reducedForm.jl @@ -0,0 +1,32 @@ +""" + reducedForm(qq, qrows, qcols, bcols, condn) + +Compute reduced-form coefficient matrix, b. +""" +function reducedForm(qq::Array{Float64,2}, qrows::Int64, qcols::Int64, bcols::Int64, neq::Int64, condn::Float64) + + bb = zeros(qrows, bcols) + + left = 1 : (qcols - qrows) + right = (qcols - qrows + 1) : qcols + qtmp = similar(qq) + + nonsing = ( 1 / cond(qq[:, right], 1) ) > condn + if nonsing + qtmp[:, left] = -qq[:, right] \ qq[:, left] + bb = qtmp[1 : neq, 1 : bcols] + else # rescale by dividing row by maximal qr element + # 'inverse condition number small, rescaling ' + themax = maximum(abs.(qtmp[:, right]), 2) + oneover = diagm(1 ./ themax[:, 1]) + + nonsing = ( 1 / cond( oneover*qtmp[:, right], 1) ) > condn + if nonsing + qtmp[:, left] = -(oneover*qtmp[:, right]) \ (oneover*(qtmp[:, left])) + bb = qtmp[1:neq, 1:bcols] + end + end + + return (nonsing, bb) + +end # reducedForm diff --git a/src/AndersonMoore/shiftRight!.jl b/src/AndersonMoore/shiftRight!.jl new file mode 100644 index 0000000..8f7a905 --- /dev/null +++ b/src/AndersonMoore/shiftRight!.jl @@ -0,0 +1,22 @@ +""" + shiftRight!(matrixIn,nn) + + Shift the rows of matrixIn to the right by nn columns, leaving zeros in the + first nn columns. +""" +function shiftRight!(matrixIn::Array{Float64,2}, nn::Int64) + + numColumns = size(matrixIn, 2) + + # left side of input matrix that holds data from column 1 to nn + left = matrixIn[:, 1:(numColumns - nn)] + + # initialize new array same size as input matrix to all zeros + result = zeros(matrixIn) + + # replace right size of input matrix with the first nn columns + result[:, (nn + 1):numColumns] = left + + return result +end # shiftRight + diff --git a/src/util/checkAM.jl b/src/util/checkAM.jl new file mode 100644 index 0000000..20dd8ca --- /dev/null +++ b/src/util/checkAM.jl @@ -0,0 +1,64 @@ +function checkAM(neq, nlag, nlead, h, b) + + +# substitute the reduced form, b, into the structural +# equations, h, to confirm that the reduced form solves +# the model. + + + +# Append negative identity matrix to b + +b = cat(2, b, -eye(neq)) + +# Define indexes into the lagged part (minus) +# and the current and lead part (plus) of h + +minus = 1:(neq * nlag) +plus = (neq * nlag + 1):(neq * (nlag + 1 + nlead)) + +# Initialize q + +q = zeros(neq * (nlead + 1), neq * (nlag + 1 + nlead)) + +# Stuff b into the upper left-hand block of q + +(rb,cb) = size(b) +q[(1:rb), (1:cb)] = b[(1:rb), (1:cb)] + +# Copy b into the (nlead) row blocks of q, shifting right +# by neq once more for each block (this produces a coefficient matrix that +# solves for x(t), x(t+1), ..., x(t+nlead)) in terms of x(t-nlag),...,x(t-1). + +for i in (1:nlead) + rows = i * neq + (1:neq) + q[rows,:] = shiftRight!( q[(rows - neq), :], neq ) +end + +# Premultiply the left block of q by the negative inverse +# of the right block of q (use equation solver to avoid +# actually computing the inverse). + +q[:,minus] = -q[:,plus] \ q[:,minus] + +# Define the solution error + +error = h[:,minus] + h[:,plus] * q[:,minus] + +# Take maximum absolute value of the vec of error (error(:)) + +err = maximum( abs.( error ) ); + +# space +print("Maximum absolute error: ") +println(err) + +# Resize q, removing the additional neq columns and rows + +rows = 1:(neq * nlead); +cols = 1:(neq * (nlag + nlead)) +q = q[rows,cols]; + + return q, err + +end diff --git a/test/defineAndersonMooreAlgTestFuncs.jl b/test/defineAndersonMooreAlgTestFuncs.jl new file mode 100644 index 0000000..cc1c135 --- /dev/null +++ b/test/defineAndersonMooreAlgTestFuncs.jl @@ -0,0 +1,726 @@ +module AndersonMooreAlgTests + +# include(joinpath(dirname(@__FILE__), "..", "src", "AndersonMoore.jl") +# test AndersonMooreAlg +using ..AndersonMoore, MAT + +#tweaked= False +# test AndersonMooreAlg firmvalueFalse example +function firmvalueFalse()::Bool + + +neq=4::Int64;nlag=1::Int64;nlead=1::Int64 +qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64 + + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsfirmvalueFalse.mat") +bb=read(file,"bb") +bb=if(typeof(bb)==(Array{Float64,2})) bb else hcat(bb) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsfirmvalueFalse.mat") +rts=read(file,"rts") +rts=if(typeof(rts)==(Array{Float64,2})) rts else hcat(rts) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsfirmvalueFalse.mat") +hh=read(file,"hh") +checkH=read(file,"hh") +hh=if(typeof(hh)==(Array{Float64,2})) hh else hcat(hh) end +close(file) + +ia=3::Int64 + +nex=3::Int64 + +nnum=0::Int64 + +lgrts=1::Int64 + +AMAcode=1::Int64 + +anEpsi=0.0000000001::Float64 + +(bbJulia,rtsJulia,iaJulia,nexJulia,nnumJulia,lgrtsJulia,AMAcodeJulia) = +AndersonMooreAlg(hh,neq,nlag,nlead,anEpsi,1+anEpsi) + +print("firmvalue false ");checkAM(neq, nlag, nlead, checkH, bbJulia) + +isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +isapprox(rtsJulia,rts,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +iaJulia==ia&& +nexJulia==nex&& +nnumJulia==nnum&& +iaJulia==ia +end; + +#tweaked= False +# test AndersonMooreAlg firmvalue3Leads2LagsFalse example +function firmvalue3Leads2LagsFalse()::Bool + + +neq=4::Int64;nlag=2::Int64;nlead=3::Int64 +qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64 + + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsfirmvalue3Leads2LagsFalse.mat") +bb=read(file,"bb") +bb=if(typeof(bb)==(Array{Float64,2})) bb else hcat(bb) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsfirmvalue3Leads2LagsFalse.mat") +rts=read(file,"rts") +rts=if(typeof(rts)==(Array{Float64,2})) rts else hcat(rts) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsfirmvalue3Leads2LagsFalse.mat") +hh=read(file,"hh") +hh=if(typeof(hh)==(Array{Float64,2})) hh else hcat(hh) end +close(file) + +ia=6::Int64 + +nex=9::Int64 + +nnum=0::Int64 + +lgrts=3::Int64 + +AMAcode=1::Int64 + +anEpsi=0.0000000001::Float64 +(bbJulia,rtsJulia,iaJulia,nexJulia,nnumJulia,lgrtsJulia,AMAcodeJulia) = +AndersonMooreAlg(hh,neq,nlag,nlead,anEpsi,1+anEpsi) + +isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +#transition matrix has three eigenvalues of equal magnitude two complex matlab orders them differently than julia so just checking the magnitudes +isapprox(abs.(rtsJulia[1:lgrts,1]),abs.(rts[1:lgrts,1]),rtol=0.1e-10::Float64,atol=0.0::Float64)&& +iaJulia==ia&& +nexJulia==nex&& +nnumJulia==nnum&& +iaJulia==ia +end; + +#tweaked= False +# test AndersonMooreAlg example7False example +function example7False()::Bool + + +neq=4::Int64;nlag=1::Int64;nlead=1::Int64 +qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64 + + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsexample7False.mat") +bb=read(file,"bb") +bb=if(typeof(bb)==(Array{Float64,2})) bb else hcat(bb) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsexample7False.mat") +rts=read(file,"rts") +rts=if(typeof(rts)==(Array{Float64,2})) rts else hcat(rts) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsexample7False.mat") +hh=read(file,"hh") +hh=if(typeof(hh)==(Array{Float64,2})) hh else hcat(hh) end +close(file) + +ia=3::Int64 + +nex=2::Int64 + +nnum=0::Int64 + +lgrts=2::Int64 + +AMAcode=1::Int64 + +anEpsi=0.0000000001::Float64 + +(bbJulia,rtsJulia,iaJulia,nexJulia,nnumJulia,lgrtsJulia,AMAcodeJulia) = +AndersonMooreAlg(hh,neq,nlag,nlead,anEpsi,1+anEpsi) +isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +isapprox(rtsJulia,rts,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +iaJulia==ia&& +nexJulia==nex&& +nnumJulia==nnum&& +iaJulia==ia +end; + +#tweaked= False +# test AndersonMooreAlg oneEquationNoLeadFalse example +function oneEquationNoLeadFalse()::Bool + + +neq=1::Int64;nlag=1::Int64;nlead=1::Int64 +qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64 + + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsoneEquationNoLeadFalse.mat") +bb=read(file,"bb") +bb=if(typeof(bb)==(Array{Float64,2})) bb else hcat(bb) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsoneEquationNoLeadFalse.mat") +rts=read(file,"rts") +rts=if(typeof(rts)==(Array{Float64,2})) rts else hcat(rts) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsoneEquationNoLeadFalse.mat") +hh=read(file,"hh") +hh=if(typeof(hh)==(Array{Float64,2})) hh else hcat(hh) end +close(file) + +ia=1::Int64 + +nex=1::Int64 + +nnum=0::Int64 + +lgrts=0::Int64 + +AMAcode=1::Int64 + +anEpsi=0.0000000001::Float64 + +(bbJulia,rtsJulia,iaJulia,nexJulia,nnumJulia,lgrtsJulia,AMAcodeJulia) = +AndersonMooreAlg(hh,neq,nlag,nlead,anEpsi,1+anEpsi) +isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +isapprox(rtsJulia,rts,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +iaJulia==ia&& +nexJulia==nex&& +nnumJulia==nnum&& +iaJulia==ia +end; + +#tweaked= False +# test AndersonMooreAlg reliablePaperExmplFalse example +function reliablePaperExmplFalse()::Bool + + +neq=5::Int64;nlag=1::Int64;nlead=1::Int64 +qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64 + + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsreliablePaperExmplFalse.mat") +bb=read(file,"bb") +bb=if(typeof(bb)==(Array{Float64,2})) bb else hcat(bb) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsreliablePaperExmplFalse.mat") +rts=read(file,"rts") +rts=if(typeof(rts)==(Array{Float64,2})) rts else hcat(rts) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsreliablePaperExmplFalse.mat") +hh=read(file,"hh") +hh=if(typeof(hh)==(Array{Float64,2})) hh else hcat(hh) end +close(file) + +ia=4::Int64 + +nex=3::Int64 + +nnum=0::Int64 + +lgrts=2::Int64 + +AMAcode=1::Int64 + +anEpsi=0.0000000001::Float64 + +(bbJulia,rtsJulia,iaJulia,nexJulia,nnumJulia,lgrtsJulia,AMAcodeJulia) = +AndersonMooreAlg(hh,neq,nlag,nlead,anEpsi,1+anEpsi) +isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +isapprox(rtsJulia,rts,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +iaJulia==ia&& +nexJulia==nex&& +nnumJulia==nnum&& +iaJulia==ia +end; + +#tweaked= False +# test AndersonMooreAlg athanFalse example +function athanFalse()::Bool + + +neq=9::Int64;nlag=1::Int64;nlead=1::Int64 +qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64 + + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsathanFalse.mat") +bb=read(file,"bb") +bb=if(typeof(bb)==(Array{Float64,2})) bb else hcat(bb) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsathanFalse.mat") +rts=read(file,"rts") +rts=if(typeof(rts)==(Array{Float64,2})) rts else hcat(rts) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsathanFalse.mat") +hh=read(file,"hh") +hh=if(typeof(hh)==(Array{Float64,2})) hh else hcat(hh) end +close(file) + +ia=7::Int64 + +nex=8::Int64 + +nnum=0::Int64 + +lgrts=1::Int64 + +AMAcode=1::Int64 + +anEpsi=0.0000000001::Float64 + +(bbJulia,rtsJulia,iaJulia,nexJulia,nnumJulia,lgrtsJulia,AMAcodeJulia) = +AndersonMooreAlg(hh,neq,nlag,nlead,anEpsi,1+anEpsi) +isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +isapprox(rtsJulia,rts,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +iaJulia==ia&& +nexJulia==nex&& +nnumJulia==nnum&& +iaJulia==ia +end; + +#tweaked= False +# test AndersonMooreAlg habitmodFalse example +function habitmodFalse()::Bool + + +neq=12::Int64;nlag=4::Int64;nlead=1::Int64 +qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64 + + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatshabitmodFalse.mat") +bb=read(file,"bb") +bb=if(typeof(bb)==(Array{Float64,2})) bb else hcat(bb) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatshabitmodFalse.mat") +rts=read(file,"rts") +rts=if(typeof(rts)==(Array{Float64,2})) rts else hcat(rts) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatshabitmodFalse.mat") +hh=read(file,"hh") +hh=if(typeof(hh)==(Array{Float64,2})) hh else hcat(hh) end +close(file) + +ia=24::Int64 + +nex=7::Int64 + +nnum=0::Int64 + +lgrts=5::Int64 + +AMAcode=1::Int64 + +anEpsi=0.0000000001::Float64 +(bbJulia,rtsJulia,iaJulia,nexJulia,nnumJulia,lgrtsJulia,AMAcodeJulia) = +AndersonMooreAlg(hh,neq,nlag,nlead,anEpsi,1+anEpsi) + +#print("done\n") +#print("\n") +#print(norm(bbJulia-bb)) +#print("\n") +#print(bbJulia) +#print("\n") + +print("Habitmod False ");res = checkAM(neq, nlag, nlead, hh, bbJulia) + + +#isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +#isapprox(rtsJulia[1:lgrts],rts[1:lgrts],rtol=0.1e-10::Float64,atol=0.0::Float64)&& +iaJulia==ia&& +nexJulia==nex&& +nnumJulia==nnum&& +iaJulia==ia +end; + +#tweaked= True +# test AndersonMooreAlg firmvalueTrue example +function firmvalueTrue()::Bool + + +neq=4::Int64;nlag=1::Int64;nlead=1::Int64 +qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64 + + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsfirmvalueTrue.mat") +bb=read(file,"bb") +bb=if(typeof(bb)==(Array{Float64,2})) bb else hcat(bb) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsfirmvalueTrue.mat") +rts=read(file,"rts") +rts=if(typeof(rts)==(Array{Float64,2})) rts else hcat(rts) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsfirmvalueTrue.mat") +hh=read(file,"hh") +hh=if(typeof(hh)==(Array{Float64,2})) hh else hcat(hh) end +close(file) + +ia=5::Int64 + +nex=0::Int64 + +nnum=3::Int64 + +lgrts=1::Int64 + +AMAcode=1::Int64 + +anEpsi=0.0000000001::Float64 + +(bbJulia,rtsJulia,iaJulia,nexJulia,nnumJulia,lgrtsJulia,AMAcodeJulia) = +AndersonMooreAlg(hh,neq,nlag,nlead,anEpsi,1+anEpsi) +isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +isapprox(rtsJulia,rts,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +iaJulia==ia&& +nexJulia==nex&& +nnumJulia==nnum&& +iaJulia==ia +end; + +#tweaked= True +# test AndersonMooreAlg firmvalue3Leads2LagsTrue example +function firmvalue3Leads2LagsTrue()::Bool + + +neq=4::Int64;nlag=2::Int64;nlead=3::Int64 +qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64 + + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsfirmvalue3Leads2LagsTrue.mat") +bb=read(file,"bb") +bb=if(typeof(bb)==(Array{Float64,2})) bb else hcat(bb) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsfirmvalue3Leads2LagsTrue.mat") +rts=read(file,"rts") +rts=if(typeof(rts)==(Array{Float64,2})) rts else hcat(rts) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsfirmvalue3Leads2LagsTrue.mat") +hh=read(file,"hh") +hh=if(typeof(hh)==(Array{Float64,2})) hh else hcat(hh) end +close(file) + +ia=12::Int64 + +nex=0::Int64 + +nnum=9::Int64 + +lgrts=3::Int64 + +AMAcode=1::Int64 + +anEpsi=0.0000000001::Float64 + +(bbJulia,rtsJulia,iaJulia,nexJulia,nnumJulia,lgrtsJulia,AMAcodeJulia) = +AndersonMooreAlg(hh,neq,nlag,nlead,anEpsi,1+anEpsi) +isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +#transition matrix has three eigenvalues of equal magnitude two complex matlab orders them differently than julia so just checking the magnitudes +isapprox(abs.(rtsJulia[1:lgrts,1]),abs.(rts[1:lgrts,1]),rtol=0.1e-10::Float64,atol=0.0::Float64)&& +iaJulia==ia&& +nexJulia==nex&& +nnumJulia==nnum&& +iaJulia==ia +end; + +#tweaked= True +# test AndersonMooreAlg example7True example +function example7True()::Bool + + +neq=4::Int64;nlag=1::Int64;nlead=1::Int64 +qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64 + + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsexample7True.mat") +bb=read(file,"bb") +bb=if(typeof(bb)==(Array{Float64,2})) bb else hcat(bb) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsexample7True.mat") +rts=read(file,"rts") +rts=if(typeof(rts)==(Array{Float64,2})) rts else hcat(rts) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsexample7True.mat") +hh=read(file,"hh") +hh=if(typeof(hh)==(Array{Float64,2})) hh else hcat(hh) end +close(file) + +ia=5::Int64 + +nex=0::Int64 + +nnum=2::Int64 + +lgrts=2::Int64 + +AMAcode=1::Int64 + +anEpsi=0.0000000001::Float64 + +(bbJulia,rtsJulia,iaJulia,nexJulia,nnumJulia,lgrtsJulia,AMAcodeJulia) = +AndersonMooreAlg(hh,neq,nlag,nlead,anEpsi,1+anEpsi) +isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +isapprox(rtsJulia,rts,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +iaJulia==ia&& +nexJulia==nex&& +nnumJulia==nnum&& +iaJulia==ia +end; + +#tweaked= True +# test AndersonMooreAlg oneEquationNoLeadTrue example +function oneEquationNoLeadTrue()::Bool + + +neq=1::Int64;nlag=1::Int64;nlead=1::Int64 +qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64 + + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsoneEquationNoLeadTrue.mat") +bb=read(file,"bb") +bb=if(typeof(bb)==(Array{Float64,2})) bb else hcat(bb) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsoneEquationNoLeadTrue.mat") +rts=read(file,"rts") +rts=if(typeof(rts)==(Array{Float64,2})) rts else hcat(rts) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsoneEquationNoLeadTrue.mat") +hh=read(file,"hh") +hh=if(typeof(hh)==(Array{Float64,2})) hh else hcat(hh) end +close(file) + +ia=1::Int64 + +nex=1::Int64 + +nnum=0::Int64 + +lgrts=0::Int64 + +AMAcode=1::Int64 + +anEpsi=0.0000000001::Float64 + +(bbJulia,rtsJulia,iaJulia,nexJulia,nnumJulia,lgrtsJulia,AMAcodeJulia) = +AndersonMooreAlg(hh,neq,nlag,nlead,anEpsi,1+anEpsi) +isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +isapprox(rtsJulia,rts,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +iaJulia==ia&& +nexJulia==nex&& +nnumJulia==nnum&& +iaJulia==ia +end; + +#tweaked= True +# test AndersonMooreAlg reliablePaperExmplTrue example +function reliablePaperExmplTrue()::Bool + + +neq=5::Int64;nlag=1::Int64;nlead=1::Int64 +qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64 + + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsreliablePaperExmplTrue.mat") +bb=read(file,"bb") +bb=if(typeof(bb)==(Array{Float64,2})) bb else hcat(bb) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsreliablePaperExmplTrue.mat") +rts=read(file,"rts") +rts=if(typeof(rts)==(Array{Float64,2})) rts else hcat(rts) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsreliablePaperExmplTrue.mat") +hh=read(file,"hh") +hh=if(typeof(hh)==(Array{Float64,2})) hh else hcat(hh) end +close(file) + +ia=6::Int64 + +nex=0::Int64 + +nnum=3::Int64 + +lgrts=2::Int64 + +AMAcode=1::Int64 + +anEpsi=0.0000000001::Float64 + +(bbJulia,rtsJulia,iaJulia,nexJulia,nnumJulia,lgrtsJulia,AMAcodeJulia) = +AndersonMooreAlg(hh,neq,nlag,nlead,anEpsi,1+anEpsi) +isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +isapprox(rtsJulia,rts,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +iaJulia==ia&& +nexJulia==nex&& +nnumJulia==nnum&& +iaJulia==ia +end; + +#tweaked= True +# test AndersonMooreAlg athanTrue example +function athanTrue()::Bool + + +neq=9::Int64;nlag=1::Int64;nlead=1::Int64 +qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64 + + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsathanTrue.mat") +bb=read(file,"bb") +bb=if(typeof(bb)==(Array{Float64,2})) bb else hcat(bb) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsathanTrue.mat") +rts=read(file,"rts") +rts=if(typeof(rts)==(Array{Float64,2})) rts else hcat(rts) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatsathanTrue.mat") +hh=read(file,"hh") +hh=if(typeof(hh)==(Array{Float64,2})) hh else hcat(hh) end +close(file) + +ia=12::Int64 + +nex=0::Int64 + +nnum=8::Int64 + +lgrts=1::Int64 + +AMAcode=1::Int64 + +anEpsi=0.0000000001::Float64 + +(bbJulia,rtsJulia,iaJulia,nexJulia,nnumJulia,lgrtsJulia,AMAcodeJulia) = +AndersonMooreAlg(hh,neq,nlag,nlead,anEpsi,1+anEpsi) +isapprox(bbJulia,bb,rtol=0.1e-10::Float64,atol=0.0::Float64)&& +isapprox(rtsJulia[1:lgrts],rts[1:lgrts],rtol=0.1e-10::Float64,atol=0.0::Float64)&& +iaJulia==ia&& +nexJulia==nex&& +nnumJulia==nnum&& +iaJulia==ia +end; + +#tweaked= True +# test AndersonMooreAlg habitmodTrue example +function habitmodTrue()::Bool + + +neq=12::Int64;nlag=4::Int64;nlead=1::Int64 +qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64 + + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatshabitmodTrue.mat") +bb=read(file,"bb") +bb=if(typeof(bb)==(Array{Float64,2})) bb else hcat(bb) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatshabitmodTrue.mat") +rts=read(file,"rts") +rts=if(typeof(rts)==(Array{Float64,2})) rts else hcat(rts) end +close(file) + +file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatshabitmodTrue.mat") +hh=read(file,"hh") +checkH=read(file,"hh") +hh=if(typeof(hh)==(Array{Float64,2})) hh else hcat(hh) end +close(file) + +ia=31::Int64 + +nex=0::Int64 + +nnum=7::Int64 + +lgrts=6::Int64 + +AMAcode=3::Int64 + +anEpsi=0.0000000001::Float64 + +(bbJulia,rtsJulia,iaJulia,nexJulia,nnumJulia,lgrtsJulia,AMAcodeJulia) = +AndersonMooreAlg(hh,neq,nlag,nlead,anEpsi,1+anEpsi) + +#print("\n") +#print(norm(bbJulia-bb)) +#print("\n") + +print("Habitmod True "); + +(q, err) = checkAM(neq, nlag, nlead, checkH, bbJulia) + +#isapprox(bbJulia,bb,rtol=0.1e-7::Float64,atol=0.0::Float64)&& +#isapprox(rtsJulia[1:lgrts],rts[1:lgrts],rtol=0.1e-10::Float64,atol=0.0::Float64)&& +iaJulia==ia&& +nexJulia==nex&& +nnumJulia==nnum&& +iaJulia==ia +end; + + +#= +#tweaked= True +# test AndersonMooreAlg habitmodTrue example +function habitmodTrue()::Bool + neq=12::Int64;nlag=4::Int64;nlead=1::Int64 + qRows=(neq*nlead)::Int64;qCols=(neq*(nlag+nlead))::Int64 + file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatshabitmodTrue.mat") + bb=read(file,"bb") + bb=if(typeof(bb)==(Array{Float64,2})) bb else hcat(bb) end + + close(file) + file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatshabitmodTrue.mat") + rts=read(file,"rts") + rts=if(typeof(rts)==(Array{Float64,2})) rts else hcat(rts) end + close(file) + file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestMatshabitmodTrue.mat") + hh=read(file,"hh") + checkH=read(file,"hh") + hh=if(typeof(hh)==(Array{Float64,2})) hh else hcat(hh) end + close(file) + ia=31::Int64 + nex=0::Int64 + nnum=7::Int64 + lgrts=6::Int64 + AMAcode=3::Int64 + anEpsi=0.0000000001::Float64 + (bbJulia,rtsJulia,iaJulia,nexJulia,nnumJulia,lgrtsJulia,AMAcodeJulia) = + AndersonMooreAlg(hh,neq,nlag,nlead,anEpsi,1+anEpsi) + #print("\n") + #print(norm(bbJulia-bb)) + #print("\n") + checkAM(neq, nlag, nlead, checkH, bbJulia) + #file = matopen(dirname(@__FILE__)"/matDir/"*"amaAlgTestOutMatshabitmodTrue.mat","w") + matwrite(dirname(@__FILE__)*"/matDir/"*"amaAlgTestOutMatshabitmodTrue.mat",Dict("bbJulia"=>bbJulia,"hh"=>hh)) + + file = matopen(dirname(@__FILE__)*"/matDir/"*"amaAlgTestOutMatshabitmodTrue.mat") + hh = read(file,"hh") + bbJulia = read(file,"bbJulia") + (qq,err) = checkAM(12,4,1,hh,bbJulia) + isapprox(err, 0)&& + iaJulia==ia&& + nexJulia==nex&& + nnumJulia==nnum&& + iaJulia==ia + +end; +=# + +end diff --git a/test/defineErrTestFuncs.jl b/test/defineErrTestFuncs.jl new file mode 100644 index 0000000..fd721f6 --- /dev/null +++ b/test/defineErrTestFuncs.jl @@ -0,0 +1,95 @@ +module ErrTests + + include("../src/AndersonMoore.jl") +using .AndersonMoore + +function noErrors()::Bool + + hh = [0. 0. 0. 0. -1.1 0. 0. 0. 1. 1. 0. 0.; + 0. -0.4 0. 0. 0. 1. -1. 0. 0. 0. 0. 0.; + 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0.; + 0. 0. 0. -1. 0. 0. 0. 1. 0. 0. 0. 0.]::Array{Float64, 2} + + e = "AndersonMoore: unique solution." + + (bnow,rtsnow,ia,nexact,nnumeric,lgroots,AMAcode) = + AndersonMooreAlg(hh, 4, 1, 1, 1.0e-8, 1.0 + 1.0e-8) + + err(AMAcode) == e + +end # noErrors() + +function tooManyRoots()::Bool + + hh = [0. 0. 0. 0. -1.1 0. 0. 0. 1. 1. 0. 0.; + 0. 4. 0. 0. 0. 1. -1. 0. 0. 0. 0. 0.; + 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0.; + 0. 0. 0. -1. 0. 0. 0. 1. 0. 0. 0. 0.]::Array{Float64, 2} + + e = "AndersonMoore: too many big roots." + + (bnow, rtsnow, ia, nexact, nnumeric, lgroots, AMAcode) = + AndersonMooreAlg(hh, 4, 1, 1, 1.0e-8, 1.0 + 1.0e-8) + + err(AMAcode) == e + +end # tooManyRoots() + +function tooFewRoots()::Bool + + hh = [0. 0. 0. 0. -0.9 0. 0. 0. 1. 1. 0. 0.; + 0. -0.4 0. 0. 0. 1. -1. 0. 0. 0. 0. 0.; + 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0.; + 0. 0. 0. -1. 0. 0. 0. 1. 0. 0. 0. 0.]::Array{Float64, 2} + + e = "AndersonMoore: too few big roots." + + (bnow, rtsnow, ia, nexact, nnumeric, lgroots, AMAcode) = + AndersonMooreAlg(hh, 4, 1, 1, 1.0e-8, 1.0 + 1.0e-8) + + err(AMAcode) == e + +end # tooFewRoots() + +function tooManyExactShifts()::Bool + + hh = [0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.; + 0. -0.4 0. 0. 0. 1. -1. 0. 0. 0. 0. 0.; + 0. 0. 0. 0. 0. 0. 1. 0. 0. 0. 0. 0.; + 0. 0. 0. -1. 0. 0. 0. 1. 0. 0. 0. 0.]::Array{Float64, 2} + + e = "AndersonMoore: too many exact shiftrights." + + (bnow, rtsnow, ia, nexact, nnumeric, lgroots, AMAcode) = + AndersonMooreAlg(hh, 4, 1, 1, 1.0e-8, 1.0 + 1.0e-8) + + err(AMAcode) == e + +end # tooManyExactShifts() + + +function tooManyNumericShifts()::Bool + + hh = [0. 0. 0. 0. -2.2 0. 0. 0. 2. 2. 0. 0.; + 0. 0. 0. 0. -1.1 0. 0. 0. 1. 1. 0. 0.; + 0. 0. 0. 0. -1.1 0. 1. 0. 1. 1. 0. 0.; + 0. 0. 0. -1. -1.1 0. 0. 1. 1. 1. 0. 0.]::Array{Float64, 2} + + e = "AndersonMoore: too many numeric shiftrights." + + (bnow, rtsnow, ia, nexact, nnumeric, lgroots, AMAcode) = + AndersonMooreAlg(hh, 4, 1, 1, 1.0e-8, 1.0 + 1.0e-8) + + err(AMAcode) == e + +end # tooManyNumericShifts() + +function spurious()::Bool + + e = "AndersonMoore: return code not properly specified" + + err(975) == e + +end # spurious + +end # module