You might have heard about the Golden Ratio. It is this special number that often shows up in mathematics. The Golden Section Search uses this very ratio to solve a particular kind of problem, such as finding the minimum or maximum of a unimodal function.
Motivational Problem
Suppose we have a unimodal function
KaTeX can only parse string typed expression
f:[L,R]→R, where the function increases on
KaTeX can only parse string typed expression
[L,m] and decreases on
KaTeX can only parse string typed expression
[m,R], with
KaTeX can only parse string typed expression
m being the point where the function reaches its only local minimum/maximum (or it can be considered as global minimum/maximum in that particular function). We aim to find
KaTeX can only parse string typed expression
f(m±δ), where
KaTeX can only parse string typed expression
δ represents an acceptable error ranging in the interval
KaTeX can only parse string typed expression
[0,0.5], serving as the satisfaction threshold. We achieve this by only querying the value of the function at specific points, i.e., evaluating
KaTeX can only parse string typed expression
f(x) for chosen values of
KaTeX can only parse string typed expression
x in the interval
KaTeX can only parse string typed expression
[L,R], as efficiently as possible.
Ternary Search Method
One of the well-known algorithms, Ternary Search, uses a strategy of picking two pivot points
KaTeX can only parse string typed expression
p1 and
KaTeX can only parse string typed expression
p2 such that
KaTeX can only parse string typed expression
L<p1<p2<R, and then evaluating
KaTeX can only parse string typed expression
f(p1) and
KaTeX can only parse string typed expression
f(p2). This evaluation leads to one of three possible cases, which are listed below. For the sake of simplicity, let's assume that the unimodal function has a local maximum that we are seeking to find (if we were looking for a local minimum, we would simply invert each comparison).
Case
KaTeX can only parse string typed expression
f(p1)<f(p2):
Considering that the function is increasing before the maximum point, we are faced with one of the following scenarios:
KaTeX can only parse string typed expression
m≤p1<p2, which is a contradiction under the current assumption that
KaTeX can only parse string typed expression
f(p1)<f(p2), since the function would be increasing from
KaTeX can only parse string typed expression
L until
KaTeX can only parse string typed expression
p1; hence, it is impossible to have a maximum point on
KaTeX can only parse string typed expression
p1 and before
KaTeX can only parse string typed expression
p1.
KaTeX can only parse string typed expression
p1<m≤p2, which implies that the maximum must lie in
KaTeX can only parse string typed expression
(p1,p2].
KaTeX can only parse string typed expression
p1<p2<m, which implies that the function is still increasing until
KaTeX can only parse string typed expression
p2, meaning that the maximum must lie in
KaTeX can only parse string typed expression
(p2,R].
Figure 1 & 2
This case describes the possibilities and illustrates why, in a case where
KaTeX can only parse string typed expression
f(p1)<f(p2), we confidently narrow down our search space into
KaTeX can only parse string typed expression
(p1,p2]∪(p2,R]=(p1,R].
Case
KaTeX can only parse string typed expression
f(p1)>f(p2):
We now deal with a similar situation to the previous case. We have either:
KaTeX can only parse string typed expression
m<p1<p2, which implies that the function is now in the state of decreasing after
KaTeX can only parse string typed expression
p1, meaning that the maximum must lie in
KaTeX can only parse string typed expression
[L,p1).
KaTeX can only parse string typed expression
p1≤m<p2, which implies that the maximum must lie in
KaTeX can only parse string typed expression
[p1,p2).
KaTeX can only parse string typed expression
p1<p2≤m, which is a contradiction under the current assumption that
KaTeX can only parse string typed expression
f(p1)>f(p2), since the function would be decreasing from
KaTeX can only parse string typed expression
p2 onwards; hence, it is impossible to have a maximum point on
KaTeX can only parse string typed expression
p2 and after
KaTeX can only parse string typed expression
p2.
Figure 3 & 4
This case describes the possibilities and illustrates why, in a case where
KaTeX can only parse string typed expression
f(p1)>f(p2), we confidently narrow down our search space into
KaTeX can only parse string typed expression
[L,p1)∪[p1,p2)=[L,p2).
Case
KaTeX can only parse string typed expression
f(p1)=f(p2):
This case is quite simple as out of the possibilities below, only one is deemed valid:
KaTeX can only parse string typed expression
m≤p1<p2, which is not a valid possibility, as this case implies that the function is now decreasing from
KaTeX can only parse string typed expression
m onwards. Consequently, we have
KaTeX can only parse string typed expression
f(p1)>f(p2), which is a contradiction under the current assumption that
KaTeX can only parse string typed expression
f(p1)=f(p2).
KaTeX can only parse string typed expression
p1<m<p2, which is valid as the maximum lies in
KaTeX can only parse string typed expression
(p1,p2).
KaTeX can only parse string typed expression
p1<p2≤m, which is not a valid possibility, as this case implies that the function must be increasing before
KaTeX can only parse string typed expression
m. Consequently, we have
KaTeX can only parse string typed expression
f(p1)<f(p2), which is a contradiction under the current assumption that
KaTeX can only parse string typed expression
f(p1)=f(p2).
Figure 5
This allows us to narrow down the search space into
KaTeX can only parse string typed expression
(p1,p2).
Ternary Search partitions the current search space into three equal-sized intervals. Denote
KaTeX can only parse string typed expression
N as the length of the search space, i.e.,
KaTeX can only parse string typed expression
N=R−L, then the size of the partitioned interval is
KaTeX can only parse string typed expression
3N. This means that we want to choose
KaTeX can only parse string typed expression
p1=L+3N and
KaTeX can only parse string typed expression
p2=R−3N. Denote
KaTeX can only parse string typed expression
Q as the number of queries used to solve the motivational problem using the Ternary Search method.
Adapting Ternary Search Method Towards Binary Search
Instead of dividing the interval into three equal parts, which typically lead to reducing the search space to either the first two-thirds, the last two-thirds, or the middle one-third, we could consider a variation where the pivots
KaTeX can only parse string typed expression
p1 and
KaTeX can only parse string typed expression
p2 are chosen closer to the center of the interval. This resembles the idea of Binary Search.
By choosing both
KaTeX can only parse string typed expression
p1 and
KaTeX can only parse string typed expression
p2 as close as possible to the middle of the interval, we want to set the limits as
The approach of the Golden-section Search is quite similar to the Ternary Search, as the idea of maintaining two pivots is inherited. For the sake of simplicity, we will once again assume that the unimodal function has a local maximum that we are seeking to find. Let's denote the two pivots as
KaTeX can only parse string typed expression
p1 and
KaTeX can only parse string typed expression
p2, which satisfy
KaTeX can only parse string typed expression
L<p1<p2<R, and be certain that the point
KaTeX can only parse string typed expression
m is located in the interval
KaTeX can only parse string typed expression
[L,R]. Assume that by using the previous queries, we already have the value of
KaTeX can only parse string typed expression
f(L),
KaTeX can only parse string typed expression
f(R), and one of the
KaTeX can only parse string typed expression
f(p1) and
KaTeX can only parse string typed expression
f(p2) such that
KaTeX can only parse string typed expression
max(f(L),f(R))≤f(p1) or
KaTeX can only parse string typed expression
f(p2). Consider that we have
KaTeX can only parse string typed expression
f(p1) (in a case where we have
KaTeX can only parse string typed expression
f(p2), we only need to mirror the domain toward
KaTeX can only parse string typed expression
2L+R, i.e., the middle point), our next step is to query the value of
KaTeX can only parse string typed expression
f(p2), and we will handle it based on the following similar cases in Ternary Search Method:
Case
KaTeX can only parse string typed expression
f(p1)=f(p2):
As we agreed that in this case the point
KaTeX can only parse string typed expression
m lies in
KaTeX can only parse string typed expression
(p1,p2), we may include this case to either
KaTeX can only parse string typed expression
f(p1)<f(p2) or
KaTeX can only parse string typed expression
f(p1)>f(p2) as
KaTeX can only parse string typed expression
(p1,p2)⊂(p1,R] and
KaTeX can only parse string typed expression
(p1,p2)⊂[L,p2).
Case
KaTeX can only parse string typed expression
f(p1)<f(p2):
As explained, this case indicates that the point
KaTeX can only parse string typed expression
m lies in
KaTeX can only parse string typed expression
(p1,R]. Then, we can set
KaTeX can only parse string typed expression
L:=p1,
KaTeX can only parse string typed expression
p1:=p2, and
KaTeX can only parse string typed expression
R:=R, utilizing the value of
KaTeX can only parse string typed expression
f(p1) as the new value of
KaTeX can only parse string typed expression
f(L) and the value of
KaTeX can only parse string typed expression
f(p2) as the new value of
KaTeX can only parse string typed expression
f(p1). The choice of pivot is made accordingly; the reason is shown later.
Figure 6
Case
KaTeX can only parse string typed expression
f(p1)>f(p2):
Similarly, as explained, this case indicates that the point
KaTeX can only parse string typed expression
m lies in
KaTeX can only parse string typed expression
[L,p2). Then, we can set
KaTeX can only parse string typed expression
R:=p2,
KaTeX can only parse string typed expression
p2:=p1, and
KaTeX can only parse string typed expression
L:=L, utilizing the value of
KaTeX can only parse string typed expression
f(p2) as the new value of
KaTeX can only parse string typed expression
f(R) and the value of
KaTeX can only parse string typed expression
f(p1) as the new value of
KaTeX can only parse string typed expression
f(p2) in the new interval. Again, the choice of pivot is made accordingly; the reason is shown later.
Figure 7
Notice that after the transition, the assumptions we made are all still satisfied. With that, we manage to remove either
KaTeX can only parse string typed expression
[L,p1] or
KaTeX can only parse string typed expression
[p2,R] from our search space with only
KaTeX can only parse string typed expression
1 additional query, whereas the Ternary Search uses
KaTeX can only parse string typed expression
2 additional queries. However, it is still quite tricky to choose the value of
KaTeX can only parse string typed expression
p1 and
KaTeX can only parse string typed expression
p2 as we want the values to be optimal when we inherit them for the next interval query.
Suppose
KaTeX can only parse string typed expression
p1 is located in
KaTeX can only parse string typed expression
L+k(R−L) where
KaTeX can only parse string typed expression
k∈(0,0.5) and a constant, then,
KaTeX can only parse string typed expression
p2 should also be located in
KaTeX can only parse string typed expression
R−k(R−L). Assuming that we manage to remove the interval
ϕ>2; hence, the Golden-section Search Method provides a better and more efficient way to solve the motivational problem.
And there we have it! By strategically positioning our pivots and leveraging the mathematics of the golden ratio, we have managed to achieve an even more efficient solution.
You may compare the number of queries used for all the explained methods side-by-side in the below neat little table.
Method
Number of Queries Used
Ternary Search
KaTeX can only parse string typed expression
2×⌈log23(N)⌉
Adapted Ternary Search
KaTeX can only parse string typed expression
2×⌈log2(N)⌉
Golden-section Search
KaTeX can only parse string typed expression
3+⌈logϕ(N)⌉
In the upcoming post, I am planning to write about the Variation of the Golden-section Search on a Density Function. Stay tuned!