Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/examples/trees.ipynb
Views: 531
Trees
Modeling and Simulation in Python
Copyright 2021 Allen Downey
License: Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
Modeling tree growth
This case study is based on "Height-Age Curves for Planted Stands of Douglas Fir, with Adjustments for Density", a working paper by Flewelling, Collier, Gonyea, Marshall, and Turnblom.
It provides "site index curves", which are curves that show the expected height of the tallest tree in a stand of Douglas firs as a function of age, for a stand where the trees are the same age.
Depending on the quality of the site, the trees might grow more quickly or slowly. So each curve is identified by a "site index" that indicates the quality of the site.
I'll start with some of the data from their Table 1. Here's the sequence of ages.
And here's the series of heights for a site with index 45, indicating that height at 30 years is 45 feet.
Here's the series for site index 65.
And for site index 85.
Here's what the curves look like:
For my examples I'll work with the SI 65 data; as an exercise, you can run the notebook again with either of the other curves.
Model 1
As a starting place, let's assume that the ability of the tree to gain mass is limited by the area it exposes to sunlight, and that the growth rate (in mass) is proportional to that area. In that case we can write:
where is the mass of the tree at time step , is the area exposed to sunlight, and is an unknown growth parameter.
To get from to , I'll make the additional assumption that mass is proportional to height raised to an unknown power:
where is height, is an unknown constant of proportionality, and is the dimension that relates height and mass. We'll start by assuming , but we'll revisit that assumption.
Finally, we'll assume that area is proportional to height squared:
I'll specify height in feet, and choose units for mass and area so that and .
Putting all that together, we can write a difference equation for height:
Now let's simulate this system. Here's a system object with the parameters and initial conditions.
And here's an update function that takes the current height as a parameter and returns the height during the next time step.
I'll test the update function with the initial conditions.
Here's our usual version of run_simulation
.
And here's how we run it.
Here's what the results look like:
The model converges to a straight line.
I chose the value of alpha
to fit the data as well as I could, but it is clear that the data have curvature that's not captured by the model.
Here are the errors, that is, the differences between the model and the data.
And here's the mean absolute error.
This model might explain why the height of a tree grows roughly linearly:
If area is proportional to and mass is proportional to , and
Change in mass is proportional to area, and
Height grows linearly, then
Area grows in proportion to , and
Mass grows in proportion to .
If the goal is to explain (approximate) linear growth, we might stop there. But this model does not fit the data particularly well, and it implies that trees could keep growing forever.
So we might want to do better.
Model 2
As a second attempt, let's suppose that we don't know . In fact, we don't, because trees are not like simple solids; they are more like fractals, which have fractal dimension.
I would expect the fractal dimension of a tree to be between 2 and 3, so I'll guess 2.5.
I'll wrap the code from the previous section in a function that takes the parameters as inputs and makes a System
object.
Here's how we use it.
With different values for the parameters, we get curves with different behavior. Here are a few that I chose by hand.
To find the parameters that best fit the data, I'll use leastsq
.
We need an error function that takes parameters and returns errors:
Here's how we use it:
Now we can pass error_func
to leastsq
, which finds the parameters that minimize the squares of the errors.
Using the best parameters we found, we can run the model and plot the results.
The mean absolute error is better than for Model 1, but that doesn't mean much. The model still doesn't fit the data well.
And the estimated fractal dimension is 3.11, which doesn't seem likely.
Let's try one more thing.
Model 3
Models 1 and 2 imply that trees can grow forever, but we know that's not true. As trees get taller, it gets harder for them to move water and nutrients against the force of gravity, and their growth slows.
We can model this effect by adding a term to the model similar to what we saw in the logistic model of population growth. Instead of assuming:
Let's assume
where is similar to the carrying capacity of the logistic model. As approaches , the factor goes to 0, causing growth to level off.
Here's what the implementation of this model looks like:
Here's an updated version of make_system
Here's the new System
object.
And here's the new update function.
As always, we'll test the update function with the initial conditions.
And we'll test the error function with the new update function.
Now let's search for the best parameters.
With these parameters, we can fit the data much better.
And the mean absolute error is substantially smaller.
The estimated fractal dimension is about 2.6, which is plausible; it suggests that if you double the height of the tree, the mass grows by a factor of
In other words, the mass of the tree scales faster than area, but not as fast as it would for a solid 3-D object.
What is this model good for?
It offers a possible explanation for the shape of tree growth curves.
It provides a way to estimate the fractal dimension of a tree based on a growth curve (probably with different values for different species).
It might provide a way to predict future growth of a tree, based on measurements of past growth. As with the logistic population model, this would probably only work if we have observed the part of the curve where the growth rate starts to decline.
Analysis
With some help from my colleague, John Geddes, we can do some analysis.
Starting with the difference equation in terms of mass:
We can write the corresponding differential equation:
(1)
With
(2)
and
(3)
Taking the derivative of the previous equation (3) yields
(4)
Combining (1), (2), and (4), we can write a differential equation for :
(5)
Now let's consider two cases:
With infinite , the factor approaches 1, so we have Model 2.
With finite , we have Model 3.
Model 2
Within Model 2, we'll consider two special cases, with and .
With , we have
which yields exponential growth with parameter .
With , we have Model 1, with this equation:
which yields linear growth with parameter . This result explains why Model 1 is linear.
Model 3
Within Model 3, we'll consider two special cases, with and .
With , we have
which yields logisitic growth with parameters and .
With , we have
which yields a first order step response; that is, it converges to like a negative exponential:
where is a constant that depends on the initial conditions.
Open Exercise Find an analytic solution when is between 2 and 3, and compare it to the data. Note: The parameters we estimated for the difference equation might not be right for the differential equation.
Additional resources:
Garcia, A stochastic differential equation model for the height growth of forest stands