Shapeshift is a machine learning experiment that aims to optimize the construction of earthquake-resistant buildings in third world countries.

The approach uses novel fourier analysis on earthquake waveforms in three dimensions to model how seismic frequencies decay as a function of distance from its epicentre. The goal was to identify the X, Y and Z frequencies to test a building design with to maximize its earthquake-resistance in a geographical area, at the lowest cost. Using LSTMs and Attention Mechanisms to evaluate risk in geographical regions, we can then construct multi-layer perceptron networks to model the seismic frequencies and propose designs to maximize resistance at the lowest cost.

My work was accelerated by the RippleX Fellowship & RBCx, under the guidance of Dominic Lau & advisors, alongside various micro-grants. I spent my 2023 summer identifying and researching ways to better construct buildings. Recently, I decided to improve previous work, as well as train the models on larger datasets.


Parallels to Portugal

In November 1755, hell broke out in the capital of Portugal. Lisbon, and all that the country encompassed, fell to one of the largest natural disasters in European history. The city was overtaken by tsunamis, forcing the surviving population to higher ground. For the few that were left, the earthquake caused candles to fall in buildings, leaving Portugal in flames.

The king, who unironically developed a life-long phobia of stone walls, fled the city to live in the royal campsite, leaving the Marquee in control. Within a couple weeks, the city was rebuilt with seismic resistance in mind. The placement of each piece of wood and stone was calculated to resist the next disaster, encouraging newfound engineering to optimize these buildings, not for unique design but for sustainability. These practices continued throughout the next several centuries, including seismic practices by Salazar, the fascist patriot, war-neutrality advocate and faux-dictator, in modernizing Portugese infrastructure and accelerating economic growth by enforcing policy—some avant-garde, others beyond control of the people.

The country moved out of a state of disarray and towards a functioning state beyond the scope of natural disasters. This was, nevertheless, as a function of state-wide disaster, necessitating thoughtful engineering practices to revive the country. Not all cities have this same opportunity.

Fast-forward to 2023. In the recent Turkey-Syrian earthquakes, buildings broke in a similar fashion. This time, however, it was avoidable. A few years prior, in 2018, it was reported that over 50% of constructed buildings in Turkey were in violation of regulations — an attempt to prioritize affordability over policy. Later, it was found that nearly all fallen buildings during the earthquakes were constructed as such.

earthquakes don’t kill people, bad buildings do

The earthquake building crisis is at fault to:

  1. the dire need for affordability
  2. the disregard of existing seismic policy that optimizes zoning and urban planning yet reduces the speed of development

It is for this reason that billions went to the reconstruction of the Turkish buildings, while nearly none to effective building analysis.

Intention: Data Driven Decisions

These case studies and countless more — research into the decay of earthquake frequencies in South-East Australia and personal conversations with UNICEF representatives after 2015 Nepal earthquakes — have culminated to three key insights that I have been trying to solve.

  1. Affordability and speed often trump detail in building design, meaning reconstructed/new buildings prioritize going from idea to production with the fewest resources in the least amount of time.
  2. Policies, while restrictive, are difficult to identify for zoning and increase the time for due diligence; for buildings that remain within regulations, time required to complete planning in urban metros often takes up to 3 months, reducing time spent on ensuring sustainability.
  3. If planning for seismic resistance is encountered, it is timely, incomplete and expensive. To ensure resistance, often all permutations are considered, geological/geographical data are not considered and facilities attempt to achieve accuracy through high-cost testing.

Fourier Analysis

If we can receive waveforms from multiple detection points around an epicenter, we can apply mathematical techniques to retrieve frequencies/amplitudes and find patterns with frequency decay as a function of distance. Using these patterns and previous earthquakes, we can identify testing values for earthquakes in 3 dimensions to minimize the overall cost for testing.

Consider a building. Under standard conditions, its movement is defined by a Single Degree of Freedom as it can be modeled by one frequency. However, earthquake movements, similar to most signals, are an intricate series of waves that are superimposed on one another. These waves have Multiple Degrees of Freedom, and can be broken down into a series of sinusoidal functions. These building movements and, by extension, earthquake movements, can be simplified to a series of modes that produce frequencies in complement to each other. So, building movements can be modeled as a sum of waves, allowing us to break it down into component waves.

Raw Waveforms

Three-dimensional earthquake ground motion waves, collected at multiple points (KTP, TVU, PTN, THM) with respect to longitude, latitude and elevation (NS, EW, UD), are in the time domain. This data, however, is fairly abstract and does not immediately provide the necessary information to find frequencies. This is where the Fourier series is important, a mathematical concept that defines each wave as a signal that can be represented as the sum of harmonic sinusoidal functions; in this way, asymmetrical—and often convoluted—waves produced by earthquakes can be approximated as a sum of cosine (even) and sine (odd) functions.

alt text

Insights are difficult to extract from this type of data. This is mostly attributed to the fact that these waveforms are as a function of time. So, we can apply the Fourier Transform to represent it in the frequency domain.

Deriving the Transform

If you love math like I do, here’s how the transform works! Calculating the frequencies of a continuous function first requires an understanding of how the individual building blocks, sine and cosine components, interact. Consider the sum as follows.

By Euler’s Theorem and DeMoivre’s Theorem, the sine and cosine values from each can be represented as complex numbers.

Let represent the complex coefficient, where and its conjugate is at . By interpreting the sum in the complex plane,

Given our complex numbers, these equations can be simplified into a sum on the complex plane. By complex properties and simplifications,

This sum represents both the imaginary and real components of a continuous function. Despite this effectively modelling seismic readings in their components, a function is required to transform a signal between domains. Therefore, this sum should act as a filtering mechanism to transform a function f(t) between the time and frequency domain.

Here, can be simplified for , such that:

With these two equations, a continuous function in the time domain can be transformed into a discrete function in the frequency domain. This is what we call a Fourier Transform, which can be applied to the intricate signal processing of seismic waves in earthquakes and can then be filtered into separate frequency distributions.

Applying the Transform

Given some raw waveforms in the time domain, a discrete filtering function would transform this function to be relative to frequencies instead of time.

So, for example suppose we model a wave to be represented by , a simple dampened sine wave. By calculating the coefficient and creating the differentials for the transform, a discrete function can be generated to create data based on frequencies.

We can now create our Discrete Fourier Transform, using .

This equation proves the most fundamental principle of this investigation: the frequency of seismic waves. This filtering function, for the continuous series of a seismic wave, can create a distribution of frequencies.

Particle Distribution

This function, for each wave, can generate a Particle Velocity & Frequency plot, mapping out the core frequencies in three dimensions. alt text

A distribution was created, that reduces a large amount of the noise. Then, once reconstructed, it plots the frequencies in each of the dimensions. By using our discrete transform to estimate discrete values, and then reconstructing a wave in the new domain using an existing filtering function, frequency distributions can be produced.

alt text

With this method, datasets with a weighted average of peak frequencies can be created given our parent dataset of 350,000 earthquakes, each with waveforms in the X, Y and Z directions. After removing outliers using IQR, the maximum frequencies for each sliding window can be computed for our training/testing dataset, using the envelope method.

alt text

Using a multi-layer perceptron network, with two hidden layers of 64 nodes, we can approximate the frequency decay of maximal values (represented in red).

alt text

Given set of coordinates, we can apply a KNN to find surrounding earthquakes within the past 20 years. Since the frequency decay is independent of magnitude, patterns of nearby earthquakes is all we need. The model can likely be improved to account for both, but this would require a completely different approach to the problem. (Message me if you have ideas!)

alt text

Now, given a distance from an estimated epicentre, we can identify the maximal X, Y and Z frequencies that a building must sustain to maximize its chance of earthquake resistance.

Risk Assessment

Attention Mechanisms

To evaluate risk, LSTMs & Attention Mechanisms were used to estimate the distance from a coordinate an earthquake can be reasonably estimated. The process begins by taking input sequences that represent features like latitude, longitude, time, magnitude, and depth, shaped as (seq_length, 5). First, these sequences pass through an LSTM layer with 128 units, which returns sequences while incorporating a dropout and recurrent dropout of 0.1 to prevent overfitting. Following this, another LSTM layer with 64 units, also returning sequences and with a dropout of 0.1, processes the output from the first LSTM layer.

Next, attention scores are calculated using a dot product between the output of the second LSTM layer and itself. These scores are then normalized using a softmax activation function to form a proper attention distribution. A context vector then performs another dot product between the normalized attention scores and the second LSTM’s output. We concatenate this context vector with the output of the second LSTM layer to enhance the feature set before making predictions. A time-distributed dense layer follows, which outputs the predicted values for each time step.

alt text

By feeding in the predictions from this model into the original frequency model, the pipeline is complete. We now have a mechanism that, given input latitude and longtiude, can evaluate the optimal testing frequencies to maximize earthquake resistance in the geographical region, at the lowest cost.


This part was not very technical, but very analytical. No more than uploading datasets and modelling tectonic plate movement over time.

alt text

The derived insights from the simulations involved the types of dominant frequencies that were emitted from each plate. This allowed me to generate a dataset of the plate and the direction in which these frequencies were dominant. As a result, exploration into how convergent, divergent and transform plate movements differed in types of ground movements arose. I am currently in the process of refining the relationship between emitted waves and the type of plate interaction.

Seismic Policy Search

The aforementioned theory is — well — theoretical. Conversations with planners, architects and seismic builders led to one final conclusion: automating the development process. This implied making the seismic policy and requirement analysis as efficient as possible, based on the geographical and local conditions. This involved (1) scraping the web for policies and (2) creating efficient summaries through semantic searching for properties.


The process involves searching for region-specific seismic policies, for example in Turkey the TS500 along many others, and parsing through the document in batches. These batches were then embedded, using the cohere-embed-v3 model, and stored in a vector DB with a location and reference in that policy.

Then, for the different characteristics, a soft cosine similarity search was performed, returning parts of the policies with the most similarities (ie legal requirements, documentation, dimensional requirements). This context was fed into an LLM which returned a summary of requirements for that subtopic, with citations to policies and a location within them.

During buildspace n&w seasons 3 & 4, I prototyped an interface for running simulations, evaluating risk and searching policies. This was an AI agent with function-calling. The video below summarizes my work:

Shapeshift was an incredible experiment that taught me a lot about how earthquakes work and existing preventative infrastructure. My investigation is open sourced, available on Github.