Matthew Davison /stor-i-student-sites/matthew-davison STOR-i Student Since 2020 Thu, 19 May 2022 14:05:02 +0000 en-US hourly 1 https://wordpress.org/?v=6.9.4 /stor-i-student-sites/matthew-davison/wp-content/uploads/sites/19/2020/11/cropped-mugjoinednobackgroundsquare-1-32x32.png Matthew Davison /stor-i-student-sites/matthew-davison 32 32 FST Science Week 2022 /stor-i-student-sites/matthew-davison/2022/05/19/fst-science-week-2022/ Thu, 19 May 2022 13:46:29 +0000 /stor-i-student-sites/matthew-davison/?p=735 Read More »FST Science Week 2022]]> On Friday the 1st of April 2022, I took part in the Faculty of Science and Technology Science Week poster session. This was a great opportunity to talk with other students and staff about my work. I was very inspired by all the posters presented by the other students.

I also took a break from looking at posters to go and watch the PhD Speed Talks which were three-minute thesis style talks giving a very brief overview of up to 4 years of research!

It was a great networking opportunity and I left the event with ideas I want to try and feed into my research. I was also awarded “runner up” for my poster submission, which was a nice surprise to round off a great event.

If you are interested in having a closer look at my poster, I have left a copy below!

Poster about timetabling for university courses
The poster that I presented at the FST Science Week 2022.
]]>
IMRT Planning Process: Leaf Sequencing Optimization /stor-i-student-sites/matthew-davison/2021/04/12/imrt-planning-process-leaf-sequencing-optimization/ Mon, 12 Apr 2021 08:43:00 +0000 /stor-i-student-sites/matthew-davison/?p=511 Read More »IMRT Planning Process: Leaf Sequencing Optimization]]> This post is part of series about IMRT Planning, if you haven’t read the introduction to this series you can find it here. This blog series was inspired by the research I did as part of STOR601.

What is the problem?

In the previous phase, matrices known as fluence maps were derived for each angle that will be used in the treatment plan. Most of the planning is complete at this stage. The planning process now focuses on working out the best way of bringing this plan into the real world using real equipment.

As mentioned in the introduction to this blog series, a multi-leaf collimator (MLC) is used to modulate the beam from the accelerator. The beam can be thought of as a grid of beamlets and a leaf can force a beamlet to be either on or off. Therefore, the problem is to decompose the fluence maps into a collection of 0-1 matrices (also known as apertures) that the collimator can deliver. This is known as Leaf Sequencing Optimization or LSO.

There are three main goals when solving this problem:

  1. Make the treatment deliverable: The angles and fluence maps from BAO and FMO respectively are the “blueprints” of the treatment, the LSO provides the “instructions” on how to build the treatment.
  2. Minimise the beam-on time: Beam-on time is the total length of time the accelerator is turned on for and needs to be minimised to increase patient comfort and quality of treatment.
  3. Minimise number of apertures: Minimising the number of apertures means that there is less time wasted changing between them.
Example of decomposing an integer fluence map into 0-1 matrices. Notice that the total beam-on time is the sum of the coefficients for the 0-1 matrices (2+1+3=6).

What are the challenges?

The main challenge with this problem involves the physical limitations of different collimator systems. gives a really good review of using different collimator systems and they are summed up here:

Regular MLC: As seen in the featured image for this blog post. Two sets of leaves, one left set and one right set, that can move in and out of the way of the beam. Notice that if the left leaf is covering a beamlet, then all beamlets to the left of that one must also be covered. This is similar in reverse for right leaves. This collimator also demonstrates what is known as the “consecutive ones” property where there has to be a continuous gap between ends of the leaves (no “floating” bits).

Rotating MLC: Similar to the regular MLC in every way except the whole unit can rotate 90 degrees to turn the left-right leaves into top-bottom leaves.

Dual MLC: Similar to the regular MLC except has a pair of left-right leaves and a pair of top-bottom leaves. This allows for more complex shapes to be made but is also harder to operate due to the potential collisions of the leaves.

Freeform MLC: This MLC is a purely theoretical collimator that can independently turn a beamlet on or off. This is useful to think about as it provides a starting decomposition that can be modified to work on a different collimator. If your algorithm or optimisation fails to find a decomposition for this MLC in good time (or at fails to find one at all!) then it’s a sign that your algorithm or optimisation will also struggle finding a decomposition for the others.

As can be seen from above, the number of constraints in your LSO problem depend heavily on the choice of collimator. There exist further constraints in some cases such as disallowing opposing leaves in adjacent rows to brush against each other (known as interdigitation), as well as potentially including maximum and minimum sized opening constraints.

The secondary challenge with the LSO problem is it’s complexity. The problem of minimising the sum of the total beam-on time and the total time taken to change between shapes is proven to be . Normally the time taken to switch between shapes is considered negligible and ignored.

This becomes an issue when trying to solve a perfectly fine mathematical model of the problem on a computer. A formulation can be fine on paper but can’t be solved quickly even using up-to-date commercial solvers on moderately powerful computers.

Therefore, research has been done in relaxing constraints in the problem and trying to exploit the structure of the LSO problem to use other mathematical optimisation tools, restating parts of the problem as .

What is the next step?

In the traditional three phase approach, this was the final step! The planning stage is complete. Although the research doesn’t stop here. Improvements have been made to all phases individually, but there is promise in combining some of these steps in the hope that this increases the treatment quality and decreases planning/treatment time.

Further Reading

My own report (produced for STOR601 research topic 2) gives an overview of all three phases and touches on where the research is heading

]]>
IMRT Planning Process: Fluence Map Optimization /stor-i-student-sites/matthew-davison/2021/04/03/imrt-planning-process-fluence-map-optimization/ Sat, 03 Apr 2021 09:02:00 +0000 /stor-i-student-sites/matthew-davison/?p=509 Read More »IMRT Planning Process: Fluence Map Optimization]]> This post is part of series about IMRT Planning, if you haven’t read the introduction to this series you can find it here. This blog series was inspired by the research I did as part of STOR601.

What is the problem?

In IMRT the radiation delivered by the accelerator is one beam, but thanks to the multi-leaf collimator this beam can be imagined as a grid of “beamlets” or “bixels” that can be independently turned on or off. We can also (rather morbidly) imagine slicing the volume of tissue around a tumour into many cubes called “voxels”.

A multi-leaf collimator can produce shapes that are subsets of “bixels”.

Given a small enough cube size then the tumour can be roughly modelled as a subset of all the voxels. Likewise, healthy tissue which we do not wish to irradiate can be modelled as a separate subset of voxels. The aim is to deliver a high amount of radiation to the tumour, but a low amount to the healthy tissue.

Given an angle, each individual bixel has a certain effect on each individual voxel. So for every angle (the angles given in BAO), the total intensity or strength of each bixel needs to be decided so that every voxel gets the correct total dose. Dosages are decided by the clinician.

More precisely, if x_i represents the decision variable for intensity of bixel i, b_i represent the required dose in voxel j, and A is the matrix such that a_{ij} is the dose delivered to voxel j per unit of x_i, then a simplified problem can be formulated as

A{\bf x} ={\bf b}

The {\bf x} vector determined here can be converted into a matrix to correspond with the grid of bixels. This is also know as a fluence map and hence the name Fluence Map Optimization or FMO.

What are the challenges?

The first challenge with solving this problem is that not every voxel contains only one tissue type. Since the voxels are a discrete approximation to continuous shapes that all share a boundary, then some voxels will contain a bit of cancerous tissue and a bit of healthy tissue.

This is problematic as it causes conflicting treatment goals. Do we provide a high dose to kill the cancer, but also kill the healthy cells? or do we provide a low dose to spare the healthy cells, but risk not getting rid of the cancer?

This is a tricky question as the tumour may be close to an important part of the body (such as the spinal cord) which if damaged could cause life-changing (or life-threatening) injury, although normally the cancer is the priority. Any formulation of the Fluence Map Optimization problem needs to take this into account.

Usually this manifests as what are known as dose-volume constraints. These constraints say that we must relax the conflicting constraints, but for only so much of the “at risk” tissue (healthy tissue we do not want to damage). The optimisation works out exactly what voxels go into that percentage to minimise risk of injury to the patient.

The second challenge is the scale of the problem. There can be a grid containing 100 bixels that the collimator can generate and 1000s of voxels to consider, and if dose-volume constraints are used then 1000s of binary variables for each voxel.

This makes the problem a lot harder to solve although popular ways of dealing with this challenge is by using techniques such as and . One of my favourite formulations of this problem uses a concept from economics called to produce dose-volume constraints that are linear (which makes solving this problem a lot easier).

What is the next step?

The next step in this process is to figure out the best way of delivering the dosage specified by the Fluence Maps for each angle.

Read about the challenges of Leaf Sequencing Optimization (LSO) here – Coming Soon!

Further Reading

(One of my favourite approaches)

]]>
IMRT Planning Process: Beam Angle Optimization /stor-i-student-sites/matthew-davison/2021/03/25/imrt-planning-process-bao/ Thu, 25 Mar 2021 11:50:00 +0000 /stor-i-student-sites/matthew-davison/?p=507 Read More »IMRT Planning Process: Beam Angle Optimization]]> This post is part of series about IMRT Planning, if you haven’t read the introduction to this series you can find it here. This blog series was inspired by the research I did as part of STOR601.

What is the problem?

The first part of IMRT that needs to be determined are the angles that the radiation is delivered from the accelerator. For patient comfort the number of angles is normally limited (more angles, longer treatment) so three to nine different angles are used.

Traditionally, these are selected by a clinician based on experience but mathematical optimisation has shown that sometimes unintuitive angles can be optimal. The process of determining an optimal (or near optimal) group of angles to use is called Beam Angle Optimization or BAO.

What are the challenges?

One challenge with selecting the angles is that there are infinitely many angles to choose from. The linear accelerator providing the radiation can rotate a full 360 degrees about a point, known as the isocentre. This means it is impossible to try every conceivable combination of angles to find the best set.

It can be argued that if two angles are sufficiently close together then there is no difference to which one is chosen. Therefore, it is not necessary to consider infinitely many angles but choose n angles from a pool of m equally spaced angles. For example, choose eight angles from the following set of angles:

\{0^\circ,10^\circ,20^\circ,\dots,350^\circ\}.

This helps reduce the number of angles considered but has it been reduced enough. In our example above there are over 30 million ways to choose 8 different angles from a pool of 36 angles (precisely 30,260,340 combinations).

Another challenge with selecting the angles to use is that there needs to be a way of evaluating this choice of angles before treatment. This is so it is possible to compare two different groups of angles and deciding which group is better. It also provides a way of deriving gradient based searches to find locally optimal groups of angles

Normally a simplified version of the next phase, Fluence Map Optimization, is used. Given a group of angles, it is possible to get a number relating to the quality of the treatment, or to find how this number changes as the chosen angles change slightly.

More precisely, for a given group of angles an optimisation problem is solved and the resulting objective value is compared with objective values from different groups of angles. Alternatively, the gradient of the objective function with respect the the angles can be found, allowing us to start with a group of angles and iteratively adjust these angles to move towards a better objective value.

What is the next step?

The next step in this process to solve the Fluence Map Optimization problem in full. The simplified versions solved above to evaluate a group of angles are not accurate enough to to be used in practice.

Read about the challenges of Fluence Map Optimization (FMO) here

Further Reading

]]>
IMRT Planning Process: Introduction /stor-i-student-sites/matthew-davison/2021/03/10/imrt-planning-process-introduction/ Wed, 10 Mar 2021 14:55:00 +0000 /stor-i-student-sites/matthew-davison/?p=503 Read More »IMRT Planning Process: Introduction]]> According to a it is anticipated that 1 in 2 people in the UK will get cancer at some point in their lives. This is due to a number of factors but it is mostly because cancer is more common in the elderly, and due to advances in medicine and healthcare, there is a growing elderly population.

There are things that can be done to make getting cancer less likely (not smoking, reducing alcohol intake, eating healthy) but if you get cancer what can be done to treat it?

One treatment that may be employed is Intensity Modulated Radiation Therapy (IMRT). In this treatment, you are secured to a bed and a linear accelerator fires beams of radiation at the cancer cells from various angles. The beams are modulated by leaves that block parts of the beam, and the aim is to concentrate the beams on all of the cancer cells to fully irradiate it. This set of leaves is called a multi-leaf collimator.

An example set of leaves in a multi-leaf collimator.

IMRT machines have improved a lot over the past two decades and more complex treatments are possible. This allows more people to survive cancer with a low risk of the cancer returning.

This is great news, but complex treatment requires careful planning and traditionally this has been done by a skilled practitioner who often has years of experience. Ideally, much of the planning should be optimized automatically by computers (with guidance from practitioners) and this is what this blog series will explore.

The planning process is split into three phases, click each part to find out about the mathematical challenges to each part:

Beam Angle Optimization (BAO)

Fluence Map Optimization (FMO)

Leaf Sequencing Optimization (LSO)

]]>
Adding R Package Documentation /stor-i-student-sites/matthew-davison/2021/03/02/adding-r-package-documentation-rcpp-roxygen2/ Tue, 02 Mar 2021 20:48:45 +0000 http://www.lancaster.ac.uk/stor-i-student-sites/matthew-davison/?p=464 Read More »Adding R Package Documentation]]> This blog will assume you are able to build a package for R and are comfortable with Linux. Fellow STOR-i student Hamish wrote a blog post on how to do this if you haven’t reached this point yet. His post covers how add C++ code to this package also. In this post I will show you how to add documentation for both C++ functions and R functions.

At any level of computer programming you may need help. I have worked with R for quite some time now and mainly use for its friendly user interface. Despite this experience I still get stuck, forget what a function does, forget what I need to input into a function for it to work, etc.

If this happens in R the quickest way to resolve these issues is to use the “help” function. For example, if I forget what “rnorm” does I can type “help(rnorm)” and it will direct me to the documentation telling me all about what it does. What if this documentation didn’t exist?

I feel that providing documentation for the R packages you make is really important.

Required Packages

To use this tutorial you need both the “Rcpp” package (if you are implementing C++ functions) and “roxygen2” package. In R you can do this using the following code.

install.packages(Rcpp) # Installs the Rcpp package
install.packages(roxygen2) # Installs the roxygen2 package

The following parts will assume that you have an existing packages skeleton (see Step 1 of Hamish’s blog), with either an R function in the “R” folder of the skeleton or a C++ file in the “src” folder.

First use a text editor of choice to edit the file named “DESCRIPTION”. Simply edit the fields and save. Now navigate into the “man” folder and delete it’s contents, roxygen should generate new documentation files automatically.

Documentation For R Function

To add documentation for an R function open up the folder “R” and find the function you wish to add documentation to. Add the following code above your R function.

#' Name
#'
#' Description
#' @param variable Parameter_Description
#' @return Return_Description

Replace “Name” and “Description” with the name of your function and a short description of the function respectively.

“@param” lets roxygen2 know it should add an argument named “variable” (note the naming needs to be the same as in the function). Replace “Parameter_Description” with a short description of the variable. Each variable of the function needs a line with it’s own details.

“@return” lets roxygen2 know it should add a “value” section. Replace “Return_Description” with a short description of what the function outputs.

Documentation For C++ Function

To add documentation for a C++ function open up the folder “src” and find the function you wish to add documentation to. Add the following code above your C++ function (and above the [[Rcpp::export]] line).

//' Name
//'
//' Description
//' @param variable Parameter_Description
//' @return Return_Description

All of these fields are the same as described in the R function section of this tutorial.

Building And Installing The Function

Navigate into the skeleton folder in a Linux terminal window and start R. You need to run the following code.

library(Rcpp)
library(roxygen2)
Rcpp::compileAttributes()           # this updates the Rcpp layer from C++ to R
roxygen2::roxygenize(roclets="rd")  # this updates the documentation

You can now exit R and move up a folder level using the command “cd ..”

To build the program run the following terminal command making sure to replace “PackageSkeletonName” with the name of your package skeleton. This will produce a package tarball that you can distribute and install.

R CMD build PackageSkeletonName

For installation follow Step 3 in Hamish’s blog post.

Example Code

The example code contains an algorithm named “Jarvis March” implemented in C++ with documentation that takes a set of 2D points and returns the convex hull, and an R function with documentation that plots the convex hull of a set of 2D points.

The details of these are not important for the tutorial but instead try to spot where the code in this blog has been used.

Further Reading

]]>
Is Yawning Contagious? /stor-i-student-sites/matthew-davison/2021/01/27/is-yawning-contagious/ Wed, 27 Jan 2021 19:37:20 +0000 http://www.lancaster.ac.uk/stor-i-student-sites/matthew-davison/?p=259 Read More »Is Yawning Contagious?]]> Over the last month I have reignited my love for the television show . If you haven’t seen it before, it consists of a team of special effects artists who try to prove if certain urban legends are fact or fiction.

In this blog post we turn our attention to Episode 4 Season 3 (according to IMDB). In this they test if yawning is contagious. That is, if you see someone else yawn then you yourself will feel the need to yawn. You can watch the experiment below.

From the percentages, the sample size, and the fact they give the “yawn stimulus” to 2 out of 3 people it can be determined that in the “control” group 4 out of 16 people yawned, and in the “stimulus” group 10 out of 34 people yawned.

This is a 4% increase in yawns therefore yawning is contagious, right?

Given how large our sample was I would say it’s confirmed.

Adam Savage

In each group, a person either yawns, or they don’t. We can model this as fifty (1 if yawn occurs, 0 otherwise). We will assume that members of the “control” group have a probability p_1 of yawning, while the “stimulus” group have probability p_2.

Our question, “Is yawning contagious?”, is now a mathematical one. Is p_1 \neq p_2?

In hypothesis testing, p_1 \neq p_2 is called our “alternative hypothesis” and it is often denoted as H_A. On the other hand, p_1=p_2 is called our “null hypothesis” and it is often denoted by H_0.

We will perform a to see if there is enough evidence to reject our null hypothesis. Rejecting the null hypothesis means it has been determined that if it were true the two probabilities were equal, then we would have a very low chance of getting the data we have, implying that our assumption is untrue since we got that data.

For example, if a child comes up to you and claims they rolled a fair dice 100 times and got a 3 every time then they are either lying to you, or the dice isn’t fair (probability of getting each number is not the same).

By using calculus we find values for p_1 and p_2 that maximise the . This is where the data that the Mythbusters gathered gets introduced into the problem, giving the following likelihood function:

L(p_1,p_2)=p_1^4 p_2^{10}(1-p_1)^{12}(1-p_2)^{24}.

If we assume that the probabilities are not equal (as in the alternative hypothesis), then the values that maximise the above likelihood function are {p}_1^A = 4/16 and {p}_2^A=10/34.

If we assume that the probabilities are equal (as in the null hypothesis), then the values that maximise the likelihood function are {p}_1^N = {p}_2^N = 14/50.

We now construct what is called a “test statistic”, denoted as T, and then compare this with an appropriate distribution to see how likely we are to observe this test statistic. If we are not likely to see it, then this suggests we need to reject H_0 (myth confirmed).

Since we are performing a Likelihood-Ratio test, the following test statistic is used:

T = 2\log\left( L({p}_1^A,{p}_2^A) \div L({p}_1^N,{p}_2^N) \right)

By inserting the values that were found above T = 0.1063772 .

The probability of seeing this test statistic value is 0.74. This means that the data the Mythbusters collected doesn’t suggest that yawning is more likely if you are stimulus group. For us to reject the null hypothesis we would want the test statistic value to be less than approximately 0.05 (also known as a 5% significance level).

In summary, the 4% increase in yawns that the Mythbusters found isn’t enough evidence to confidently say that yawning is contagious. My recommendation would be to change the status of this myth from “confirmed” to “plausible”.

Further Reading

For the further reading I leave two resources. The first for the reader who is interested in hypothesis testing, the second for the reader who is interested in Mythbusters.

]]>