Another way to cluster data is by first assuming each data item as its own cluster. We can then take a step back and merge together two of the nearest clusters. This process forms a hierarchy of clusters.
Take, for example, an analogy relating to islands and water level. An island is nothing more than a mountain tip surrounded by water. Imagine we have islands scattered across a sea. If we were to slowly drop the water level of the sea, two nearby small islands would merge into a larger island because they are connected to the same mountain formation. We can stop the water level from dropping any time we have the desired number of larger islands.
In a new file, which we name Main.hs
, insert this code:
Import the built-in functions:
import Data.Map (Map, (!), delete) import qualified Data.Map as Map import Data.Ord (comparing) import Data.List (sort, tails, transpose, minimumBy)
Define a type synonym for points:
type Point = [Double]
Define a convenience...