Mark Fisher's Mathematica packages and notebooks


Version 7 Packages


StereoImagery

The package contains two main functions, MakeStereo and MakeAnaglyph. MakeStereo takes a Graphics3D object and returns a GraphicsRow that contains a pair of Graphics3D objects viewed from slightly different angles. Positive values of the option AngularSeparation correspond to parrallel viewing (as opposed to cross-eyed viewing). MakeAnaglyph takes a pair of Graphics3D objects (such as the output of ShowStereo), converts them to bitmaps (using Image), removes (1) the green and blue from the left image and (2) the red from the right image, and combines the two images into one.

MakeStereo was modified from ShowStero by Larry Calmer. His version was designed to work with external graphics device. I modified (and simplified and updated) the code to produce a GraphicsRow in a notebook.


Version 6 Packages


PagePrint

This provides a simple way to print a graphic on a single page without header or footer. I use it all the time at work to produce handouts for presentations.

RandomWalkMetropolis

This package implements the random-walk Metropolis version of the Markov Chain Monte Carlo (MCMC) algorithm. MCMC algorithms are used to draw from probability distributions. To use this package, put the file RandomWalkMetropolis.m in the directory ToFileName[{$UserAddOnsDirectory, "Applications", "RandomWalkMetropolis"}]. Load the package with Get["RandomWalkMetropolis`"] or Needs["RandomWalkMetropolis`"].


Version 5 Packages


Plotting and Printing

PagePring

This provides a simple way to print a graphic on a single page without header or footer.

DotPlot

The package DotPlot.m defines the function DotPlot, an enhnaced version of ListPlot combining points with "connecting" lines that leave a gap near the points. DotPlot effectively replicates the kind of plot used in Edward R. Tufte's The Visual Display of Quantitative Information (1983, Graphics Press: Cheshire, Connecticut) on pages 74–75 and elsewhere. This version (April 2006) also includes CirclePlot, which shows the data points as circles.

SpinGraphics

This package defines the function SpinGraphics, which has the same functionality as SpinShow (from Graphics`Animation`), except that SpinGraphics returns the list of Graphics objects it produces, facilitating the construction of animated GIFs, for example.

StereoImagery

The package contains two main functions, MakeStereo and MakeAnaglyph. MakeStereo takes a Graphics3D object (or SurfaceGraphics object) and returns a pair of Graphics3D objects viewed from slightly different angles in a GraphicsArray. Positive values of the option AngularSeparation correspond to parrallel viewing (as opposed to cross-eyed viewing). MakeAnaglyph takes a pair of Graphics3D objects (such as the output of ShowStereo) or a pair of Graphics objects, converts them to bitmaps (using Rasterize, which uses the portable bitmap format), removes (1) the green and blue from the left image and (2) the red from the right image, and combines the two images into one.

MakeStereo was modified from ShowStero by Larry Calmer. His version was designed to work with external graphics device. I modified (and simplified and updated) the code to produce a GraphicsArray in a notebook.

ShowLive

This package provides a function (ShowLive) that passes 3-dimensional Graphics objects and animations to a "live" window using LiveGrahics3D.

ShowLive.m is adapted from code found at Omega Consulting. It uses LiveGraphics3D.


Utilities

Difference

The file Difference.m contains the code for Difference for differencing vectors (and higher order tensors). Difference is implemented using polynomials in the lag operator to compute the kernel for ListConvolve. Note: There is a Difference function in the Times Series package available from Wolfram. Loading both packages creates a name "shadowing" problem.

DateFunctions

This package provides a number of functions to convert dates between list, string, and integer representations. The options have the same form as ConversionOptions for Import for CSV files. Also included are functions to convert between dates and index numbers suitable for alignment and plotting.


Stochastic Calculus

ItosLemma

This package implements Itô's lemma for any number of Itô processes with any number of arbitrarily-correlated Brownian motions. The notebook ItosLemma.nb contains usage examples.

EulerSimulate

EulerSimulate.m provides tools to simulate Itô processes with using the Euler approximation. Some usage examples are included. (Previous versions of this package required my package StandardNormal. This version of the package takes advantage of the speed improvements to RandomArray in Version 4 of Mathematica.)


Statistics-Related

MaxEntSimplexDistribution

This package provides functions for working with the Maximum Entropy distribution on a simplex. It is a useful alternative to the Dirichlet distribution (for example). A companion paper is available.

JRandomArray

JRandomArray uses JLink to implement a variety of pseudorandom number generators from the colt.jar Java library. The library includes a number of "random engines" (including the Mersenne Twister) that drive a number of probability distributions.

Unfortunately, most of the random number distributions do not produce arrays. However, the tiny class JRandomArray.class computes arrays of random numbers directly in Java, making the overall speed competitive with Mathematica itself. (If you are interested, see the code in JRandomArray.java.)

You will need to modify the line (in JRandomArray.m)
AddToClassPath["d:/data/packages/java"]
to reflect the directory where you place colt.jar and JRandomArray.class.

Note that if you want to produce an array of 107 random deviates, you will probably need to install JLink with the CommandLine option in order to increase the maximum amount of memory Java is allowed. (See the notes in JRandomArray.m and JRandomArray.nb.)

Additional information on the colt library (including documentation) can be found here.

ParticleFilter

This package implements a sampling-importance-resampling particle filter and backward simulation particle smoother.

MetropolisMCMC

This package implements the Metropolis version of the Markov Chain Monte Carlo (MCMC) algorithm. MCMC algorithms are used to draw from probability distributions.

GMM

The package GMM.m implements the Generalized Method of Moments estimator. This package requires the package EmpiricalLikelihood.m.

EmpiricalLikelihood

The package EmpiricalLikelihood.m implements Art Owen's empirical likelihood estimator. This package requires the package MetropolisMCMC.m.


Term Structure

YieldCurve

The file YieldCurve.zip contains the Mathematica code files and the sample data files. The included version of BSplineBasis incorporates the bugfix. For further information read the included ReadMe.txt.

Bug fix for YieldCurve/BSplineBasis

The file BSplineBasisFix.m contains a bugfix for the package BSplineBasis.m, which is included with the YieldCurve splining package that accompanied Computational economics and finance: Modeling and analysis with Mathematica, (1996, Springer-Verlag) edited by Hal Varian. The file fixes a problem that arose in Version 3 when the internal structure of InterpolatingFunction was changed. The problem occurs when the option FunctionalForm -> DLogDelta is set for the function DiscountFunction. The bug fix covers Versions 3 and 4 of Mathematica. A comment at the beginning of BSplineBasisFix.m explains how to use the fix.

User's Guide for YieldCurve

This is a user's guide for the package YieldCurve. The guide was written when the typsetting capabilities of Mathematica were not as well developed as now. Consequently, mathematical expressions within the text is written in TeX (between dollar signs).

AnnuitySolve

The package AnnuitySolve.m is designed to compute the series solution to a quasi-linear 2nd-order PDE. This PDE is central to general equilibrium models where the representative agent has recursive preferences. In such models, equilibrium consumption can be viewed as a dividend to be capitalized. By a change of numeraire, the problem can be transformed into an annuity problem. The notebook AnnuitySolve Examples.nb provides some examples. The notebook is, however, a work in progress.


Other

GaussianQuadrature

This package provides two functions: GaussianQuadraturePairs and GaussianProductRule.

GaussianQuadraturePairs produces a list of n abscissa/weight pairs {x,w} for n-point Gaussian quadrature. Four types of orthogonal polynomials are supported: HermiteH, LaguerreL, LegendreP, and ChebyshevT. (The Standard Package NumericalMath`GaussianQuadrature` computes abscissa/weight pairs only for the LegendreP case.) WorkingPrecision can be specified (including Infinity). The option ScalingParameters can be used to rescale the interval and/or weight function, depending on the type. GaussianProductRule takes a sequence of pairs (produced by GaussianQuadraturePairs) and returns a tensor array of abscissa/weight tuples that can be used for multidimensional Gaussian quadrature.

PartialEvaluation

The file PartialEvaluation.m contains the code for PartialEvaluation, a debugging tool. PartialEvaluation[f[args], n] evaluates the first n expressions in the "main" CompoundExpression in f[args]. (The position of the "main" CompoundExpression can be specified by an option.) An arbitrary expression can be appended as an optional third argument: PartialEvaluation[f[args], n, expr].

DifferentialEvolution

(Note: Differential evolution is built into version 5.0 of Mathematica as an option to NMinimize.)

The package DifferentialEvolution.m implements a genetic algorithm for optimization. The algorithm is due to Kenneth Price and Rainer Storn (Dr. Dobb's Journal, April 1997).

The algorithm starts with a randomly chosen population of n real vectors, each with d >= 2 components. A cost function is given. (Cost is "negative fitness.") The cost of each member of the current population is determined. Each member then becomes a "target." The target is "mated" with a noisy vector randomly constructed from other members of the current generation to produce an offspring. The offspring replaces the target in the next generation if its cost is lower.

The mate is the sum of a "base" vector (whose construction is described below) and the scaled difference between two randomly chosen vectors. (The scale is given by the "weighting factor.") The offspring is constructed from the target and the mate by randomly choosing "genes" (i.e. components) from either the target or the mate. The probability that a gene comes from the mate is determined by the "cross-over rate." (At least one gene always comes from the mate, even if the cross-over rate is zero.) There are two ways to choose the base vector: (1) the base vector is chosen randomly from the current generation; (2) the base vector is a linear combination of the target and the "best" vector of the current generation (in terms of cost). The linear combination is determined by the "use-best weighting factor."

There is no convergence criterion built in. One simply runs the algorithm for a given number of generations. Convergence could be based on the dispersion of the costs or the population.


Back to
Home page for Mark Fisher