<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by ChiChienWang on Medium]]></title>
        <description><![CDATA[Stories by ChiChienWang on Medium]]></description>
        <link>https://medium.com/@kennywang2003?source=rss-da3fd5348c54------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2ejeUXIVFpRkR26da0TY7w.jpeg</url>
            <title>Stories by ChiChienWang on Medium</title>
            <link>https://medium.com/@kennywang2003?source=rss-da3fd5348c54------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 01:17:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kennywang2003/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Transport & Topological Data Analysis]]></title>
            <link>https://medium.com/@kennywang2003/transport-topological-data-analysis-70ff644659c8?source=rss-da3fd5348c54------2</link>
            <guid isPermaLink="false">https://medium.com/p/70ff644659c8</guid>
            <dc:creator><![CDATA[ChiChienWang]]></dc:creator>
            <pubDate>Tue, 19 Aug 2025 06:58:58 GMT</pubDate>
            <atom:updated>2025-08-19T06:58:58.259Z</atom:updated>
            <content:encoded><![CDATA[<p>In the previous article, I mentioned how TDA works in LLMs. It is intuitive to use persistent homology in high-dimensional spaces, but what about transport? Here, we are instead dealing with a space of two-dimensional maps. I did some research on this and found several interesting studies. In this article, I will introduce three papers related to traffic.</p><blockquote>Note: all of the figures below are from its corresponding paper</blockquote><h3>Congestion barcodes: Exploring the topology of urban congestion using persistent homology</h3><p>This study constructed a graph of the road network, where the speed represents the connections (edges) between roads (nodes). An interesting aspect of applying persistent homology (PH) in this context is to decrease the speed threshold and observe its persistence [1].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/825/1*OVKT5EBup2pwBRihmvzHog.png" /><figcaption>Figure 1</figcaption></figure><p>You can learn how most persistence diagrams work in my previous article. Simply put, they are built by adding a radius threshold in high-dimensional space and identifying the connected components, eventually obtaining simplices in different dimensions. In this field, however, we decrease the speed instead.</p><p>The reason for decreasing the speed is to identify persistent road connections at high speeds, which can then be useful for route planning, future predictions, and analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*G4bNANVl9kcEQPbQuWTkTQ.png" /><figcaption>Figure 2</figcaption></figure><h3>Topological analysis of traffic pace via persistent homology</h3><p>The paper above only focuses on how PH is applied to traffic, whereas this paper focuses more on the different persistent topologies in two counties [2]. It splits the graph into a directed graph matrix, where the edges represent the distance from one road to another. Moreover, it considers not only 0-dimensional connected components but also 1-dimensional ones. The authors also applied the Louvain algorithm (Figure 3), which is a method for simplifying networks — I highly recommend learning more about it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*-_HgvDxKbh4xM3f8fGIefw.png" /><figcaption>Figure 3</figcaption></figure><p>Finally, the study computed the Wasserstein distance, a method for measuring how one persistence diagram differs from another. Using three different Louvain parameters (Pₖ) across two counties, they produced a 6×6 matrix.</p><p>This gives me the idea that it might be useful for identifying heterogeneity across different locations and could potentially help classify certain types of road traffic accidents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/914/1*Jfyj0vSkKtKZol1ZC--nPw.png" /><figcaption>Figure 4</figcaption></figure><h3>Temporal network analysis using zigzag persistence</h3><p>In the previous article, I mentioned a study that applied zigzag persistence to LLMs. Surprisingly, there is also a study that applied zigzag to transport networks [3]. I won’t go into depth about zigzag in this article, but this paper provides a clear explanation for readers, and I recommend reading it if you want to learn this method (Figure 5).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*XOD4ekcW63C_AM6wID__ZQ.png" /><figcaption>Figure 5</figcaption></figure><p>This study generates topological features at different timestamps. It also detects changes in the network and identifies features that are missed by traditional statistical methods (Figure 6).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/1*maergNq0icHYA__QKEWFrA.png" /><figcaption>Figure 6</figcaption></figure><h3>Conclusion</h3><p>Although there is some research on traffic — for example, predicting traffic flow by combining TDA with neural networks [4], or applying time-embedding methods to traffic flow [5] — I would like to focus on what topology itself can contribute to traffic analysis, rather than relying on hybrid approaches such as the former, or on data structured as flow charts rather than maps, as in the latter.</p><p>If you have any questions about TDA and would like to discuss, or if you have feedback for me, please feel free to contact me !</p><h4>References</h4><p>[1] Wu, Y., Shindnes, G., Karve, V., Yager, D., Work, D. B., Chakraborty, A., &amp; Sowers, R. B. (2017, October). Congestion barcodes: Exploring the topology of urban congestion using persistent homology. In <em>2017 IEEE 20th International Conference on Intelligent Transportation Systems (ITSC)</em> (pp. 1–6). IEEE.</p><p>[2] Carmody, D. R., &amp; Sowers, R. B. (2021). Topological analysis of traffic pace via persistent homology. <em>Journal of Physics: Complexity</em>, <em>2</em>(2), 025007.</p><p>[3] Myers, A., Muñoz, D., Khasawneh, F. A., &amp; Munch, E. (2023). Temporal network analysis using zigzag persistence. <em>EPJ Data Science</em>, <em>12</em>(1), 6.</p><p>[4] Chen, Y., Segovia-Dominguez, I., Coskunuzer, B., &amp; Gel, Y. (2022). TAMP-S2GCNets: coupling time-aware multipersistence knowledge representation with spatio-supra graph convolutional networks for time-series forecasting. In <em>International conference on learning representations</em>.</p><p>[5] Zha, X. (2019). <em>Topological Data Analysis on Road Network Data</em> (Master’s thesis, The Ohio State University).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=70ff644659c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[LLMs & Topological Data Analysis]]></title>
            <link>https://medium.com/@kennywang2003/llms-topological-data-analysis-e93fdf41b954?source=rss-da3fd5348c54------2</link>
            <guid isPermaLink="false">https://medium.com/p/e93fdf41b954</guid>
            <dc:creator><![CDATA[ChiChienWang]]></dc:creator>
            <pubDate>Sun, 16 Feb 2025 06:21:45 GMT</pubDate>
            <atom:updated>2025-08-19T05:16:40.422Z</atom:updated>
            <content:encoded><![CDATA[<p>In most research, Topological Data Analysis (TDA) aims to uncover the latent structure of data, whether through the Mapper algorithm or Persistent Homology (PH). Initially, TDA was widely applied in the medical field, but in recent years, more studies have focused on the structural analysis of neural networks. In this article, I will introduce two research studies related to large language models (LLMs), providing insight into the broader applications of TDA and promoting its adoption among more researchers.</p><h3>Vulnerability Detection via Topological Analysis of Attention Maps</h3><p>This research is about uncovering the shape of the high dimension nural network model of vulnerability detection, and made a comparable model which is better than the pretrained CodeBERTa [1].</p><p>The original concept of combining BERT-based models with TDA utilizes the attention matrix [4], which only considers the results of the <strong>query and key</strong> for TDA input, excluding the value component in the BERT model. The resulting matrix represents each word and its corresponding weight, allowing the construction of <strong>word as nodes and weighted as edges</strong>, as shown in Figure 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/1*tpM8Y_ZojoVasyeOUNGPFw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d3_4Spy5wtoEyAQiLOYbbA.png" /><figcaption>Figure 1</figcaption></figure><p>This approach differs slightly from the original structure of Persistent Homology, which typically captures shape using the multiscale properties of each node (Figure 2). Instead, this research obtains persistence by incrementally increasing the weight threshold from 0 to 1, ultimately producing a persistence barcode or diagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/413/1*0wSsjI_FwWlPjAXP9S8sJw.png" /><figcaption>Figure 2</figcaption></figure><p>Based on the persistence diagram, the following features can be computed: average lifetime, variance of lifetime, maximum lifetime, number of points, and <strong>persistence entropy</strong>[6]. These features capture the interactions between tokens.</p><p>By using Logistic Regression (LR), Support Vector Machine (SVM), and Gradient Boosting (GB) to fit the topological features extracted from BERT, it is observed that the combination of topological features with machine learning methods outperforms the pre-trained CodeBERTa. However, there is still a gap compared to fine-tuned models. This suggests that only semantic information is utilized in the attention heads, while structural information is not considered, indicating room for further improvement.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*dOajSLc2ZaT-3JJhMpSFKg.png" /><figcaption>Figure 3</figcaption></figure><h3>Persistent Topological Features In Large Language Models</h3><p>This study introduces <strong>persistence similarity</strong>, a method for quantifying topological features across layers in language models. By analyzing layer progression, this approach helps identify redundant layers and provides insights into the behavior of different layers within the model [2].</p><p>Although large language models (LLMs) are highly powerful, their black-box nature necessitates greater interpretability. Previous research has explored explainability through weight matrices, neural activations, and geometric approaches. However, these methods struggle to track variations between layers. Persistent homology offers an effective solution in this context.</p><p>By leveraging multi-scale analysis, persistent homology enables the observation of relationships between layers. Specifically, LLM layers can be treated as spatial points, with the persistence of each layer computed individually. By using <strong>zigzag persistent</strong>, a variant of persistent homology, layer-wise changes can be effectively analyzed.</p><p>This paper introduces persistence similarity as a representation for computing inter-layer matrices, facilitating the identification of <strong>redundant layers for pruning</strong> and hyperparameter tuning.</p><h4>Zigzag</h4><p>In this study, the zigzag persistent<strong> </strong>is performed by constructing a k-nearest neighbors (KNN) for <strong>each layer</strong>. This means that every point in layer is connected to its nearest neighbors, leading to representations in different dimensions. Specifically, when four points are connected, they form a <strong>1-cycle</strong>, while structures with fewer than four points represent <strong>0-cycles </strong>(Figure 4).</p><p>Additionally, there are <strong>intersection layers</strong> between adjacent layers, as illustrated in the figure above. These intersection layers help capture the relationships between consecutive layers. As a result, the final computed value follows the pattern <strong>2N — 1</strong>, where <strong>N</strong> represents the number of layers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*udd4o39qEi1Y7gxZW0JsGw.png" /><figcaption>Figure 4</figcaption></figure><p>By incorporating the <strong>Effective Persistent Image (EPI)</strong>, the persistence of each layer within a single model can be effectively captured. Figure 5 further demonstrates how different k-nearest neighbors (KNN) configurations result in varying EPIs, highlighting the impact of different connectivity structures on persistence representation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ls5AurrYP_-OAIPXIsi8Dw.png" /><figcaption>Figure 5</figcaption></figure><p><strong>Persistence Similarity</strong> is defined as the EPI of two layers divided by the number of cycles present in layer <em>l</em>. This metric quantifies the similarity between layers within the same model. A higher similarity score indicates that the layers capture more comparable features during training, as shown in the figure above.</p><p>Figure 6 presents the comparison of two different LLaMA models, using KNN = 5 and 1-cycles for computation. This similarity measure is an extension of previously proposed methods, such as <strong>Bi-score</strong> and <strong>Angular Distance</strong>, both of which rely on cosine similarity to evaluate inter-layer relationships.</p><p>Ultimately, Figure 7 presents the results for the same model with different KNN values and different models with the same KNN value. This comparison highlights how the persistence similarity varies based on the choice of neighborhood size and model architecture, providing insights into the structural consistency of different layers across models.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6KZe6445-mI3caO9HGKo9A.png" /><figcaption>Figure 6</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xGGYL3Bw7tA9Es2N1xuHVQ.png" /><figcaption>Figure 7</figcaption></figure><p>By comparing the proposed topological method with traditional approaches from previous research (other works), the results demonstrate greater stability (Figure 8, LLaMA 3 8B) while achieving performance comparable to conventional methods. However, this study also notes that only 10% and 20% pruning rates were considered. If an iterative pruning approach were applied until the optimal performance is reached, even better results could potentially be achieved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tKizWY-5WYM0yiM3NVGnlw.png" /><figcaption>Figure 8</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e0CgJKXUQQHmsrHjOuIYMQ.png" /><figcaption>Figure 9</figcaption></figure><h3>Conclusion</h3><p>Although I would like to share more TDA-related research, covering everything in detail would result in an article with hundreds of thousands of words, making it too lengthy. Therefore, I have introduced only two TDA-related studies in this article. However, there is another interesting study [3] exploring the relationship between LLMs and the human brain, which provides an intuitive way to understand how LLMs function.</p><p>In my opinion, TDA still holds great potential across various fields, beyond its applications in medicine, neural networks, and image analysis. I am currently developing an R package called <a href="https://cran.r-project.org/web/packages/MapperAlgo/index.html">MapperAlgo</a> and conducting research on traffic accidents using TDA. If you have any questions about TDA applications, feel free to ask!</p><p>email: kennywang2003@gmail.com</p><p>[1] Snopov, P., &amp; Golubinskiy, A. N. (2024). Vulnerability Detection via Topological Analysis of Attention Maps. <em>arXiv preprint arXiv:2410.03470</em>.</p><p>[2] Gardinazzi, Y., Panerai, G., Viswanathan, K., Ansuini, A., Cazzaniga, A., &amp; Biagetti, M. (2024). Persistent topological features in large language models. <em>arXiv preprint arXiv:2410.11042</em>.</p><p>[3] Li, J. (2024). On the Shape of Brainscores for Large Language Models (LLMs). <em>arXiv preprint arXiv:2405.06725</em>.</p><p>[4] Kushnareva, L., Cherniavskii, D., Mikhailov, V., Artemova, E., Barannikov, S., Bernstein, A., … &amp; Burnaev, E. (2021). Artificial text detection via examining the topology of attention maps. <em>arXiv preprint arXiv:2109.04825</em>.</p><p>[5] Chazal, F., &amp; Michel, B. (2021). An introduction to topological data analysis: fundamental and practical aspects for data scientists. <em>Frontiers in artificial intelligence</em>, <em>4</em>, 667963.</p><p>[6] Atienza, N., Gonzalez-Diaz, R., &amp; Rucco, M. (2019). Persistent entropy for separating topological features from noise in vietoris-rips complexes. <em>Journal of Intelligent Information Systems</em>, <em>52</em>, 637–655.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e93fdf41b954" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Topological Data Analysis: Persistent Homology]]></title>
            <link>https://medium.com/@kennywang2003/topological-data-analysis-persistent-homology-22636f4e34bf?source=rss-da3fd5348c54------2</link>
            <guid isPermaLink="false">https://medium.com/p/22636f4e34bf</guid>
            <dc:creator><![CDATA[ChiChienWang]]></dc:creator>
            <pubDate>Sat, 05 Oct 2024 15:31:44 GMT</pubDate>
            <atom:updated>2025-10-24T06:45:28.268Z</atom:updated>
            <content:encoded><![CDATA[<p>This article aims to introduce readers to the basics of Topological Data Analysis (TDA), focusing on persistent homology and its applications. This concept is crucial because it serves as the foundation for most TDA algorithms. For example, you may have heard of Persistence Diagrams, Landscapes, Barcodes, or even methods like Mapper, Zigzag Persistence, CROCKER, and Wasserstein Distance. All of these are based on the concept of persistent homology. I hope to explain it in the simplest way to help you enter the world of topology.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*lMjeXEL58ukNLdFlFv0ZLQ.png" /><figcaption>This image is credited to [1].</figcaption></figure><p>If you search for Persistent Homology, you might come across images like the figure above, but then you realize it’s simpler than it seems! First, consider a two-dimensional space, where each data point expands its radius over time. As the radii grow, the points begin to touch, eventually forming a high-dimensional complexes. But what exactly is a complex, and why are there multiple edges and faces?</p><p><strong>Complexes </strong>are usually collections of data points that are connected to each other. For example, a single data point that doesn’t coincide with any other points is a <strong>0-dimensional simplex</strong> (0-simplex). When the radii of two data points overlap, they create an <strong>edge</strong>, known as a 1-dimensional simplex. As more points connect, you get faces and higher-dimensional simplices. Now, let’s move on to the right-hand side, which is a diagram.</p><p>You might notice two different colors representing H0 and H1. These indicate whether there is a 1-simplex or a 2-simplex at specific radii. For example, at a radius of 7.26, you can see a hole in the data points, which corresponds to the birth of an H0 (<strong>0-dimensional homology</strong>) point. When this feature disappears at a radius of 10.21 (or you could say it evolves into a higher-dimensional homology, although higher dimensions are typically not computed), the point “dies.” In this diagram, the <strong>X-axis represents birth, and the Y-axis represents death</strong>.</p><p>Note: You might get different results depending on the persistent homology method you use, such as Vietoris-Rips, Delaunay-Rips, Alpha complex, and others. However, I won’t go into detail about these, as they’re essentially just different rules of the game. But here[1,2] are some useful methods if you’re interested.</p><h4>Why is Persistent Homology important?</h4><p>This question puzzled me for a long time, but once I finally understood it, I thought I’d share my thoughts. Although homology appears to track the radii of data points, it’s incredibly useful for revealing underlying structures. A simple example is the homology of a sphere or a torus, since they have structured data; or the image of a “0” with a hole in it. While real-world data is often more complex, homology clearly captures persistent features in the data.</p><p>You can also see its usefulness in filtering out noise. Data points that appear close to signals but “die” quickly after being “born” may indicate noise that can be ignored, which is valuable for your analysis.</p><h4>Prepare for your knowledge</h4><p>There are multiple approaches that can be used in data analysis, and how they integrate with machine learning or deep learning methods should be introduced first. Various types of visualizations, such as diagrams and barcodes, can be used to represent persistent homology. However, the most suitable format for embedding in classification or prediction tasks is the <strong>Persistence Landscape</strong>. The concept is straightforward: it involves rotating the diagram by 45 degrees, resulting in a new representation, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*yeszKgHvRSwY1vk1vLih5w.png" /></figure><p>Here is a useful <a href="https://www.youtube.com/watch?v=j5x_-4hxDWg&amp;list=LL&amp;index=5">link </a>if you want to dive deeper into how the diagram is transformed. You’ll notice that if the diagram is not converted into a landscape, it becomes difficult to work with because it’s not in a function that can be easily embedded into your model or used as a feature.If you want to see how to classify a sphere and a torus using persistence landscapes and PCA, <a href="https://persim.scikit-tda.org/en/latest/notebooks/Persistence%20Landscapes%20and%20Machine%20Learning.html">here’s </a>how you can do it.</p><p><strong>Machine Learning</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kWc9fnc6El5khAVadUefew.jpeg" /><figcaption>This image is credited to [3].</figcaption></figure><p>The image above shows research using persistence landscapes combined with SVM to classify different types of clouds. In this method, they enhanced both the <strong>transparency </strong>and <strong>explainability </strong>of the model. This serves as a great introduction to TDA methods because one of the key reasons TDA is often used in the medical field is its transparency, especially in high-risk analysis. At the same time, TDA achieves strong results. This research extends the use of TDA to environmental science, making it accessible and not difficult to understand.</p><p><strong>Deep learning</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*WLPxiF_tZVOvFaYc_5Nyew.png" /><figcaption>This image is credited to [4].</figcaption></figure><p>This method integrates persistent landscapes into a neural network structure, achieving better accuracy in classifying the MNIST and ORBIT5k datasets. Additionally, it demonstrated the robustness of the landscape to noise by improving accuracy on a noisier version of the MNIST dataset. It’s important to note that the complex used here is a <strong>cubical complex</strong>, similar to the machine learning method I introduced earlier, both of which are particularly suitable for image data. This method works by assigning values to each pixel, ranging from 0 (black) to 255 (white), to capture features. For instance, it detects a single hole in digits like 0 and 9, showcasing strong feature extraction capabilities for figure classification.</p><h4>Conclusion</h4><p>In this article, I introduced the basics of persistent homology and explained why it’s important for analyzing data, including high-dimensional structures like Spheres and Torus. Although these examples involve structured data, they serve as a good introduction for future work. For instance, concepts like <strong>ZigZag persistence</strong> and the <strong>CROCKER plot</strong> are based on these types of complexes rather than cubical complexes. Lastly, I discussed two papers that combine this approach with machine learning and deep learning for classification tasks. I hope this provides you with some inspiration for your own research, and I look forward to seeing what you share in the future. I’ll keep updating this soon!</p><p>[1] <em>Fasy, B. T., Kim, J., Lecci, F., &amp; Maria, C. (2014). Introduction to the R package TDA. arXiv preprint arXiv:1411.1830.</em></p><p>[2] <em>Mishra, A., &amp; Motta, F. C. (2023). Stability and machine learning applications of persistent homology using the Delaunay-Rips complex. Frontiers in Applied Mathematics and Statistics, 9, 1179301.</em></p><p>[3] <em>Ver Hoef, L., Adams, H., King, E. J., &amp; Ebert-Uphoff, I. (2023). A primer on topological data analysis to support image analysis tasks in environmental science. Artificial Intelligence for the Earth Systems, 2(1).</em></p><p>[4]<em>Kim, K., Kim, J., Zaheer, M., Kim, J., Chazal, F., &amp; Wasserman, L. (2020). Pllay: Efficient topological layer based on persistent landscapes. Advances in Neural Information Processing Systems, 33, 15965–15977.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22636f4e34bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Topological Data Analysis: Distance to measure]]></title>
            <link>https://medium.com/@kennywang2003/go-beyond-hausdorff-distance-to-measure-841812d3d5c9?source=rss-da3fd5348c54------2</link>
            <guid isPermaLink="false">https://medium.com/p/841812d3d5c9</guid>
            <dc:creator><![CDATA[ChiChienWang]]></dc:creator>
            <pubDate>Fri, 13 Sep 2024 03:56:19 GMT</pubDate>
            <atom:updated>2025-10-31T10:29:30.936Z</atom:updated>
            <content:encoded><![CDATA[<p>As Topological Data Analysis (TDA) becomes more widely recognized, it remains a more complex field compared to traditional data analysis methods. This article will introduce a function called Distance to Measure (DTM), as a continuation of the topic mentioned in the previous article. DTM, known for its stability in data and featured in numerous papers, is a robust variation of the distance function. However, before diving into this powerful method, I will first introduce the Hausdorff distance, which will be covered in the initial section.</p><p><strong>Hausdorff distance</strong></p><p>Given two compact subsets in a set <strong><em>M</em></strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/86/1*GdBDo9aLaz_estMs-1waCg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/267/1*6-mfkgwZTPm9NYwqT_WLOw.png" /><figcaption>This image is taken from paper (1)</figcaption></figure><p>then housdorff distance expressed as the equation below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*S6q0iaO0symsYk06huJIRA.png" /></figure><p>where suprepresents the superemum, and there are two distances to consider: the distance from a point bto the subset<strong> </strong>Aand the distance from a point a to the subset B. For example, for any compact subset A in a set<strong> </strong>M, the distance function to<em> </em>Adefined as follow:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/1*ilqNWOFitNHpB0QSNojeOA.png" /></figure><p>for any <strong><em>x</em></strong> in <strong><em>M</em></strong>, <em>inf</em> represents the infimum.</p><p>Although it quantifies the proximity between different data sets within the same ambient metric space, this method is distance-based and, therefore, sensitive to outliers. To address the lack of robustness to noise, a method called ‘distance to measure’ has been proposed.</p><p><strong>Distance to measure (DTM)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r-p3HYZ1XyBWLSOw0OJ34g.jpeg" /><figcaption>intuitive way to understand DTM</figcaption></figure><p>Given a probability distribution P<strong><em> </em></strong>and a real parm<em> </em>ubetween 0 and 1, distance to the support of Pcan generalized as <strong><em>delta</em></strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*I1DQ8Btols2fu2GezAyO4g.png" /></figure><p>which B is the ball I had mentioned in the previous article with the radius t, representing how x captures its neighboring points within this specific radius; In the image above, the large circle represents the support of the set, while a data point at the bottom of the image has a non-zero distance from the support of P.</p><p>To avoid discontinuities of the map P to <strong><em>delta</em></strong>, DTM with param m in [0,1] and power r that equal or greater than 1 is defined by</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*x8FL2NyFK3YExPNvzKvtGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2JpGbikFK3S9NydyYCxhjA.png" /><figcaption>This image is taken from paper (2)</figcaption></figure><p>As the tuning parameter mmm increases, the function becomes smoother. Compared to traditional distance functions, this can be viewed as a smoother version because it calculates the distance to the support of P. In this example, the support is the circular data, where the distance to support on the circle is considered 0. This contrasts with methods like kNN and KDE.</p><p><strong>Conclusion</strong></p><p>This article aims to provide an introduction to some basic methods in TDA. First, I discussed the Hausdorff distance, which measures the distance between two subsets. However, this method is not robust to noise, leading to the introduction of the Distance to Measure (DTM) method. For example, Kim et al. (2020) calculated DTM before applying the data to a new layer that combines the persistent landscape, also known as Pllay, and achieved greater accuracy compared to other neural network frameworks. Although the Hausdorff distance is sensitive to noise, the <strong>Gromov-Hausdorff</strong> distance is a method that explores stability properties and persistence diagrams. Since I’m still familiarizing myself with this method, I won’t dive deeply into it here. Lastly, I hope this article provides some inspiration for your own analysis. See you next time!</p><p><strong>Reference</strong></p><p>[1] Chazal, F., &amp; Michel, B. (2021). An introduction to topological data analysis: fundamental and practical aspects for data scientists. <em>Frontiers in artificial intelligence</em>, <em>4</em>, 667963.</p><p>[2] Fasy, B. T., Kim, J., Lecci, F., &amp; Maria, C. (2014). Introduction to the R package TDA. <em>arXiv preprint arXiv:1411.1830</em>.</p><p>[3] Kim, K., Kim, J., Zaheer, M., Kim, J., Chazal, F., &amp; Wasserman, L. (2020). Pllay: Efficient topological layer based on persistent landscapes. <em>Advances in Neural Information Processing Systems</em>, <em>33</em>, 15965–15977.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=841812d3d5c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deep dive into Mapper Algoritm]]></title>
            <link>https://medium.com/@kennywang2003/deep-dive-into-mapper-algoritm-750766f56dce?source=rss-da3fd5348c54------2</link>
            <guid isPermaLink="false">https://medium.com/p/750766f56dce</guid>
            <dc:creator><![CDATA[ChiChienWang]]></dc:creator>
            <pubDate>Wed, 11 Sep 2024 15:06:25 GMT</pubDate>
            <atom:updated>2024-09-11T15:18:14.848Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6hvQslbu5Hx9Ai9cSGAikQ.jpeg" /></figure><p>Mapper, as one of the most renowned methods in Topological Data Analysis (TDA), is often used to explore hidden structures in spatial data. Gunnar Carlsson’s establishment of Ayasdi has played a key role in advancing TDA methods, contributing significantly to various fields. In the previous discussion, we covered some research papers utilizing this method and briefly outlined the basic steps of Mapper. Today, I would like to dive into the core concepts of Mapper.</p><p>First, I want to review the content mentioned last time, which is the four steps of the Mapper algorithm:</p><p>1. Identify a lower-dimensional mapping function for mapping.</p><p>2. Determine the intervals and overlaps.</p><p>3. Map back to identify which data points correspond to the intervals and overlaps.</p><p>4. Cluster the data points for data compression.</p><p>We are all familiar with the significance of these steps, but how are they related to topology itself? To explain this, I would like to mention two concepts: the <strong>Nerve Theorem</strong> and <strong>Simplicial Complex</strong>.</p><blockquote>I need to clarify that I am not a topologist. My interest in Topological Data Analysis (TDA) led me to study it on my own, so I won’t be discussing the strictly defined spatial concepts of topology. Instead, I’ll focusing on how these concepts can be applied to data to uncover the value of topology.</blockquote><p><strong>Simplicial Complex</strong></p><p>A Simplicial Complex is a collection of <strong>connections </strong>between data points. If two data points are connected, they form a 1-dimensional simplex, while a connection among three points creates a triangle/hole, or what is known as a 2-dimensional simplex, and so on. A simplicial complex is a collection that contains all the <strong>simplices </strong>within a given space. The ways in which data points connect can vary, such as through <strong>Vietoris-Rips, Čech, Alpha complexes</strong>, or the more computationally efficient <strong>Delaunay-Rips complex</strong>, which was later proposed. These methods connect points by gradually <strong>increasing the</strong> <strong>radius </strong>around each point or <strong>selecting a specific radius</strong>. Multi-scale issues can further be explored through persistent homology, but I would like to introduce that concept separately.</p><p>If we represent simplices using a formula, they can be viewed as a <strong>ball</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/230/1*X9AD3zvsWRthffZ-4ACmZA.png" /></figure><p>Depending on the type of simplicial complex (such as those mentioned above), there may be slight variations in their definitions, but the core concept remains consistent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9XkjBo-Q2cKn-WwgGHzKSg.png" /><figcaption><em>This figure is taken from paper (2)，this image mentioned the concept of multi-scale of the simplex, and at the right hand side, it’s a persistent diagram which records the birth and death of the simplices.</em></figcaption></figure><p><strong>Nerve Theorem</strong></p><p>The nerve describes a way to summarize a simplicial complex <strong>C(u)</strong>, where <strong>u</strong> is a cover, defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/92/1*okLqL93gEIf6i_8igssB7g.png" /></figure><p>This represents the covering of the dataset, which also serves as the <strong>vertices </strong>of the compressed data. For example, if a circular dataset has three covers, its nerve will be a triangle because the three covers compress into vertices, and the overlapping regions form the <strong>edges</strong>. The nerve is defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*INftjnG5Ld6VEE0emgiNvw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/493/1*skh4UQsIWvgDUbRlUd7NyA.png" /><figcaption>This figure is taken from paper (1)</figcaption></figure><p>Do you see how this structure forms the foundation of Mapper? Its <strong>framework is based on the Nerve Theorem</strong>, and the <strong>output is a type of simplicial complex</strong>!</p><p><strong>Conclusion</strong></p><p>This article is relatively short, as I tend to supplement or update my previous discussions whenever I have some free time. There are still many topics I want to share, such as the <strong>persistent families</strong>, the robustness of <strong>Hausdorff distance </strong>in identifying outliers, and so on. Recently, I’ve started learning Geographic Information Systems (GIS), which has helped me understand the connection between topology and methods like <strong>Voronoi/Theissen</strong> diagrams.</p><p>In general, while topology might seem abstract, I believe it offers great flexibility and potential for exploratory data analysis. After all, there are still relatively few papers related to Topological Data Analysis (TDA). Currently, I’m studying the Mapper algorithm and comparing it with both linear and non-linear dimensionality reduction methods, as well as various clustering techniques. Although I’m eager to share my findings, I prefer to wait until they are confirmed by a conference before doing so.</p><p>Lastly, if there are any errors in this article, feel free to correct me ! My understanding as a senior undergraduate student might be somewhat limited. :)</p><p><strong>Reference</strong></p><p>(1) Chazal, F., &amp; Michel, B. (2021). An introduction to topological data analysis: fundamental and practical aspects for data scientists. Frontiers in artificial intelligence, 4, 667963.</p><p>(2) Mishra, A., &amp; Motta, F. C. (2023). Stability and machine learning applications of persistent homology using the Delaunay-Rips complex. Frontiers in Applied Mathematics and Statistics, 9, 1179301.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=750766f56dce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Topological Data Analysis: Mapper Algorithm]]></title>
            <link>https://medium.com/@kennywang2003/topological-data-analysis-mapper-f0c44ecbbb3d?source=rss-da3fd5348c54------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0c44ecbbb3d</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[topological-data-analysis]]></category>
            <dc:creator><![CDATA[ChiChienWang]]></dc:creator>
            <pubDate>Sat, 03 Aug 2024 01:31:52 GMT</pubDate>
            <atom:updated>2025-10-24T06:44:40.546Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*MkEsfBkmHM0ZpASFkQrlHQ.png" /><figcaption>MNIST Mapper using R package MapperAlgo</figcaption></figure><p>This article focuses on the Mapper Algorithm in Topological Data Analysis (TDA), understanding its design principles and advantages, and introducing several examples of this method. It is assumed that the readers have a basic understanding of TDA, but the concepts will still be briefly explained.</p><h4>What does Topological Data Analysis do?</h4><p>This method has made contributions in fields such as healthcare, transportation, environment, and climate, and its applications are continually increasing. What it does is to find the <strong>shape</strong> of the data. The importance of the shape lies in the fact that once you understand the shape of a dataset, you can infer its state when embedding a data point. The figure below is an example of structured data being compressed using Mapper (Mapper will be explained later). The red and blue points can be understood as specific data points within a point cloud that has a shape. The key point is that regardless of the data you acquire, there always exists a shape. Once this shape is identified and analyzed, you can understand what each segment of the data represents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*MZ2Ywbq9fCIDfsfdlINfbA.png" /><figcaption>This image was taken from a <a href="https://www.youtube.com/watch?v=x3Hl85OBuc0&amp;t=3429s">Stanford Seminar</a>.</figcaption></figure><h4>Theory</h4><p>When using PCA, the goal is often to reduce dimensionality while preserving important information, and to perform further analysis such as plotting, classification, or clustering by identifying the principal components. However, this approach has several drawbacks:</p><ol><li>Visualization is done using the first few principal components (PCs)with the highest variance. While good components can separate different regions, how do we explain the poor components?</li><li>The result of linear dimensionality reduction may lose important information, and small variations may also have valuable outcomes.</li></ol><p>There is a method that can mitigate these drawbacks, which is the Mapper Algorithm. But first, we need to introduce the basic concept of Mapper before discussing its advantages.</p><p>According to <a href="https://www.sciencedirect.com/science/article/pii/S1532046422000983?ref=pdf_download&amp;fr=RR-2&amp;rr=87c89b378a4d8f1f">this paper</a>, the steps of Mapper are as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*GSBYVLM3umSjuGXAIDka0A.png" /></figure><ol><li>Identify a lower-dimensional mapping function for mapping.</li><li>Determine the intervals and overlaps.</li><li>Map back to identify which data points correspond to the intervals and overlaps.</li><li>Cluster the data points for data compression.</li></ol><p>The mapping function can be PCA, KDE, or even Centrality, to perform filtering. Its main role is to enable more efficient computation. The purpose of the <strong>Interval</strong> is to divide the data into several regions, and the <strong>Overlap </strong>is used to find the overlap ratio between intervals. Ultimately, each interval will be individually clustered to form <strong>nodes</strong>, and the overlap will act as <strong>edges</strong> forming lines between two nodes. This means that a data point can be in both node A and node B simultaneously, indicating that it has characteristics of <strong>both categories</strong>. This is a concept of Mapper that is less mentioned but should not be ignored.</p><h3>Examples</h3><p>The most classic example is the <a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4780757/">analysis of diabetes subgroups</a> (1), identifying the characteristics of diabetic patients in different states. Another example is using Mapper for dimensionality reduction and analysis of images such as <a href="https://www.nature.com/articles/s41467-018-03664-4.pdf">MRI</a> (2). These examples illustrate how Mapper can analyze the structure and shape of data clusters.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*dvhW9OIR1uCTGud4jct-IQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*9cbZEAnSJ76h4kJG8sLuhA.png" /></figure><h3>Conclusion</h3><p>Overall, Mapper achieves what traditional analysis methods find difficult. It does not assume your understanding of the data characteristics but instead visualizes the data first before conducting analysis. It helps to understand the distribution patterns of unlabeled data and, according to the Mapper process, it is a nonlinear dimensionality reduction method that effectively compresses data. Many papers have used this method to find nodes and then make predictions for each node, enhancing classification capabilities. This is a brief introduction to Mapper. More in-depth comparisons with methods like t-SNE and UMAP can be explored. Additionally, more topological approaches will be shared in the future, such as time series CROCKER plots, Zigzag persistence, and the frequently discussed concept of persistent homology.</p><h3>References</h3><p>[1] Chazal, F., &amp; Michel, B. (2021). An introduction to topological data analysis: fundamental and practical aspects for data scientists. <em>Frontiers in artificial intelligence</em>, <em>4</em>, 667963.<br>[2] Li, L., Cheng, W. Y., Glicksberg, B. S., Gottesman, O., Tamler, R., Chen, R., … &amp; Dudley, J. T. (2015). Identification of type 2 diabetes subgroups through topological analysis of patient similarity. <em>Science translational medicine</em>, <em>7</em>(311), 311ra174–311ra174.<br>[3] Skaf, Y., &amp; Laubenbacher, R. (2022). Topological data analysis in biomedicine: A review. <em>Journal of Biomedical Informatics</em>, <em>130</em>, 104082.<br>[4] Kim, H., &amp; Vogel, C. (2019). Deciphering active wildfires in the Southwestern USA using topological data analysis. <em>Climate</em>, <em>7</em>(12), 135.<br>[5] Saggar, M., Sporns, O., Gonzalez-Castillo, J., Bandettini, P. A., Carlsson, G., Glover, G., &amp; Reiss, A. L. (2018). Towards a new approach to reveal dynamical organization of the brain using topological data analysis. <em>Nature communications</em>, <em>9</em>(1), 1399.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0c44ecbbb3d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to practically apply TDA in time series prediction/clustering]]></title>
            <link>https://medium.com/@kennywang2003/how-to-practically-apply-tda-in-time-series-prediction-clustering-404e959ed32c?source=rss-da3fd5348c54------2</link>
            <guid isPermaLink="false">https://medium.com/p/404e959ed32c</guid>
            <dc:creator><![CDATA[ChiChienWang]]></dc:creator>
            <pubDate>Sat, 06 Apr 2024 17:19:11 GMT</pubDate>
            <atom:updated>2026-04-15T15:14:33.672Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>How to practically apply TDA in time series</strong></h3><p>In the previous article, I discussed the use of Topological Data Analysis (TDA) to analyse time series data and summarised a real-world application of this method in vehicle flow. In this article, I will introduce how TDA is used to analyse both <strong>vehicle flow</strong> and <strong>heart rate</strong> data, enhancing our understanding of predictive modelling using topological machine learning. At last, <strong>I will perform an easy TDA with economic data using R</strong>.</p><h3><strong>Papers</strong></h3><p>We know that the heart of Topological Data Analysis (TDA) is persistent homology, which identifies persistent features by observing holes or connected components that persist across multiple scales. A previous article discussed how we can detect these holes in time series data using time-delay (Takens) embedding. But have you ever considered what comes after this initial workflow? Next, I will introduce some practical processes derived from academic papers, rather than focusing on conclusions.</p><h4><a href="https://www.frontiersin.org/journals/physiology/articles/10.3389/fphys.2021.637684/full">Sleep-Wake</a></h4><p>The first paper focuses on Sleep-Wake Classification and follows the same procedures as previously described. This paper reconstructs the data using time-delay embedding, computes the Vietoris-Rips complex, extracts persistence statistics, and then applies models such as <strong>Random Forest, k-means, and neural networks</strong>. It undergoes training on the CGMH dataset, followed by validation and testing on the DREAMS and UCDSADB datasets. Subsequently, it calculates<strong> True Positives (TP), False Positives (FP), True Negatives (TN), False Negatives (FN), sensitivity (se), specificity (sp), accuracy (acc), precision (pr), F1 score (f1), AUC score (auc), and kappa coefficient (kappa)</strong>. Although this process shares similarities with the aforementioned paper, it enriches the discussion by providing a useful chart that depicts the relationships among TDA tools, including <strong>barcode, persistence images, landscapes, curves, and codebooks, etc</strong>.</p><blockquote>Method: Time-delay embedding → Persistent diagram → persistence statistics → Random Forest, k-means, and neural networks</blockquote><h4><a href="https://www.researchgate.net/publication/368935769_Stability_and_Machine_Learning_Applications_of_Persistent_Homology_Using_the_Delaunay-Rips_Complex"><strong>Instantaneous Heart Rate</strong></a></h4><p>The second paper focuses on classifying a participant&#39;s sleep stages using observed instantaneous heart rate (IHR). This study primarily revolves around the <strong>Delaunay-Rips Complex</strong>, which optimises the Vietoris-Rips and Alpha Complexes filtration by speeding up the computation without impacting the model’s accuracy. After subsequent vectorisations using <strong>persistence statistics</strong>, the model is trained and validated using <strong>SVM</strong>. Subsequently, the performance is evaluated by computing <strong>sensitivity (se), specificity (sp), accuracy (acc), precision (pr), F1 score (f1), AUC-score (auc), average precision score (aps), and kappa coefficient (kappa).</strong></p><blockquote>Method: Time-delay embedding → Persistent diagram → persistence statistics → SVM</blockquote><h4><a href="https://etd.ohiolink.edu/acprod/odb_etd/etd/r/1501/10?clear=10&amp;p10_accession_num=osu155563664988436"><strong>Traffic flow</strong></a></h4><p>The third paper contrasts traffic flow across different weeks, where one can easily discern peaks and normal moments, akin to a wave pattern. By combining these into an image resembling a wave and then applying Time-delay embedding, we transition into another dimensional space. However, in real-world data, the cycle won’t be regular. Therefore, a denoising step is employed using the <strong>ParfreeDeclutter Algorithm</strong>. After denoising, the time-delay embedding dimension is set to 5 to capture more complex dynamics, with a 250-minute delay time. Subsequently, <strong>Principal components analysis(PCA)</strong> is used to map the data into a 2-dimensional space.</p><p>After data preprocessing, the author carried out the TDA workflow described above and obtained <strong>Vietoris-Rips persistence diagrams</strong> across different weeks. Then, <strong>hierarchical clustering and K-means clustering</strong> were performed based on the <strong>Bottleneck distance and Wasserstein distance,</strong> respectively.</p><blockquote>Method: Time-delay embedding → Denoising → PCA → Persistent diagram → compute Distance → Clustering</blockquote><p><strong>Note</strong></p><p>It is evident that when data involves time series, Takens’ embedding is necessary, as real-world data often requires preprocessing to reveal any underlying structures. Subsequently, the use of persistent diagrams becomes crucial for identifying these structures. However, these structures can be computed in various ways.</p><p>The first paper extends certain tools to provide insights during analysis, while the second paper proposes filtration methods that optimise Vietoris-Rips (VR) and Alpha complexes, offering valuable perspectives for analysis. These two papers employ similar methodologies for obtaining their results, with the second citing the first for reference.</p><p>The third paper, however, diverges by introducing an algorithm to denoise the data. Instead of directly mapping the data to a two-dimensional space from the embedding, it employs Principal Component Analysis (PCA) and utilises unsupervised learning (clustering) to analyse the processed data.</p><p>These papers mention several packages that are useful for <strong>TDA</strong>, including <a href="https://github.com/DIPHA/dipha">DIPHA</a>, <a href="https://github.com/Ripser/ripser">Ripser</a>, <a href="https://gudhi.inria.fr/introduction/">GUDHI</a>, <a href="https://github.com/appliedtopology/javaplex">Javaplex</a>, <a href="https://www.sas.upenn.edu/~vnanda/perseus/">Perseus</a>, <a href="https://pypi.org/project/dionysus/">Dionysus</a>, <a href="https://web.cse.ohio-state.edu/~dey.8/SimBa/Simba.html">Simba</a>, etc.</p><h4>Example Code</h4><p>In this example, I will perform some simple analyses to help both you and me understand more about the workflow of TDA. However, I won’t delve into predictions due to the length of this article.</p><p>These are the libraries that we will use later:</p><pre># Processing the Economics data and TDA<br>library(plotly)<br>library(TDA)<br>library(tseriesChaos)<br># Applying mapper function and visualization<br>library(TDAmapper)<br>library(networkD3)</pre><p>Analyse the ‘<em>unemploy</em>’ variable, filter the data to obtain the relatively stable portion, take the square root, and plot it. The square root is used to reduce the time for computing the persistence. As we can see, this plot resembles a wave, so we can proceed with <strong>Time-delay embedding</strong> next.</p><pre>data &lt;- economics%&gt;%as.data.frame()%&gt;%filter(date &lt; &quot;2009-01-01&quot; &amp; date &gt; &quot;1975-01-01&quot;)<br>data$unemploy &lt;- data$unemploy%&gt;%sqrt()<br>data%&gt;%ggplot()+geom_line(aes(date, unemploy))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*QhLCjrGpjuQnx8mBe9Z5NA.png" /></figure><p>As we can see, after embedding, we can rotate the plot and find a hole. However, since we cannot control how PCA computes or how the Mapper function is applied, I will use a <strong>rotation matrix</strong> to adjust my plot. This will make it easier to observe a hole from the 2-dimensional plot.</p><pre>embedded_data &lt;- embedd(data$unemploy, m = 3, d = 24)%&gt;%as.data.frame()<br><br>fig &lt;- plot_ly(embedded_data, x = ~`V1/0`, y = ~`V1/24`, z = ~`V1/48`, size = 1)<br>fig &lt;- fig %&gt;% add_markers()<br>fig &lt;- fig %&gt;% layout(scene = list(xaxis = list(title = &#39;x1&#39;),<br>                                   yaxis = list(title = &#39;x2&#39;),<br>                                   zaxis = list(title = &#39;x3&#39;)),<br>                      title = &#39;Point Cloud&#39;)<br>fig</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*8qECQEGOMtHUBSs_hw9Utw.png" /></figure><p>By mapping onto a 2-dimensional space, we can clearly observe a hole in the plot. Next, we’ll compute and plot the <strong>Rips diagram</strong>.</p><pre>theta_y &lt;- 45 * (pi / 180)<br>theta_x &lt;- 45 * (pi / 180)<br><br>rotate_y &lt;- matrix(c(cos(theta_y), 0, sin(theta_y),<br>                     0, 1, 0,<br>                     -sin(theta_y), 0, cos(theta_y)), nrow = 3, byrow = TRUE)<br>rotate_x &lt;- matrix(c(1, 0, 0,<br>                     0, cos(theta_x), -sin(theta_x),<br>                     0, sin(theta_x), cos(theta_x)), nrow = 3, byrow = TRUE)<br><br><br>data_rotated_y &lt;- as.matrix(embedded_data) %*% t(rotate_y)<br>data_rotated_final &lt;- data_rotated_y %*% t(rotate_x)%&gt;%as.data.frame()<br><br>data_rotated_final%&gt;%ggplot()+geom_point(aes(`V2`, `V3`))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*qKM2LNYqJdfa1exYUIKBww.png" /></figure><p>Since <em>data_rotated_final</em> is used solely for visualising the hole and applying the Mapper function later, ‘<em>embedded_data</em>’ remains in use here for calculating complexes for the diagram. Additionally, I have drawn a loop around the data point (<a href="https://cran.r-project.org/web/packages/TDA/vignettes/article.pdf">here</a> for more information).</p><pre>par(mfrow = c(1, 2))<br><br>DiagRips &lt;- embedded_data%&gt;%ripsDiag(<br>  maxdimension = 1, maxscale = 10,<br>  library = c(&quot;GUDHI&quot;, &quot;Dionysus&quot;), location = TRUE, printProgress = TRUE)<br>plot(DiagRips[[&quot;diagram&quot;]], main = &quot;Rips Diagram&quot;)<br><br>one &lt;- which(DiagRips[[&quot;diagram&quot;]][, 1] == 1)<br>one &lt;- one[which.max(<br>  DiagRips[[&quot;diagram&quot;]][one, 3] - DiagRips[[&quot;diagram&quot;]][one, 2])]<br>plot(embedded_data[,2], embedded_data[,3], col = 1)<br>for (i in seq(along = one)) {<br>  for (j in seq_len(dim(DiagRips[[&quot;cycleLocation&quot;]][[one[i]]])[1])) {<br>    lines(DiagRips[[&quot;cycleLocation&quot;]][[one[i]]][j, , ], col = i + 1)<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DaDdZaKIkJYLebIvuaZ0Kw.png" /></figure><p>As we know, the second and third dimensions of the data have a better visual performance, the filter value will use <em>data_rotated_final[,2:3]</em> as an example to show how it performs in the Mapper Algorithm, but in real-world applications, this might use PCA, KDE, or a better feature space. The version of MapperAlgo is now 1.1.0, make sure to update to input the latest params.</p><p>The full code is stored on <a href="https://github.com/kennywang112/Topology/blob/main/Analysis/Economics.R">GitHub</a>, and other practices will also be updated in this repository</p><pre>library(MapperAlgo)<br><br>Economics.mapper &lt;- MapperAlgo(<br>  data_rotated_final,<br>  filter_values = data_rotated_final[,2:3],<br>  percent_overlap = 50,<br>  methods = &quot;kmeans&quot;,<br>  method_params = list(max_kmeans_clusters = 2),<br>  cover_type = &#39;stride&#39;,<br>  interval_width = 10,<br>  num_cores = 12<br>)<br><br>MapperPlotter(Economics.mapper, label=data_rotated_final$V3, original_data=data, avg=TRUE, use_embedding=FALSE)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4dpKLd3D2qViAKvDcEurfA.png" /></figure><h4><strong>Conclusion</strong></h4><p>This article aims to provide a glimpse into how research papers analyse time series data using topological data analysis. At the core of persistent homology is the concept of identifying ‘<em>holes</em>’ or connected components by expanding radii, a process that is fundamentally not as complex as it might seem.</p><p>I recommend gaining an understanding of how complexes operate, particularly how the Delaunay-Rips Complex distinguishes itself from others, and grasping the mathematical basis of distances.</p><p>Hope this article will inspire you to analyse data by integrating various methods. It’s always thrilling to review papers that employ diverse analytical approaches. I believe that creativity can render your analysis more vivid and engaging.</p><h4>Reference</h4><p>[1] Zha, X. (2019). <em>Topological Data Analysis on Road Network Data</em> (Master’s thesis, The Ohio State University).</p><p>[2] Mishra, A., &amp; Motta, F. C. (2023). Stability and machine learning applications of persistent homology using the Delaunay-Rips complex. <em>Frontiers in Applied Mathematics and Statistics</em>, <em>9</em>, 1179301.</p><p>[3] Chung, Y. M., Hu, C. S., Lo, Y. L., &amp; Wu, H. T. (2021). A persistent homology approach to heart rate variability analysis with an application to sleep-wake classification. <em>Frontiers in physiology</em>, <em>12</em>, 637684.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=404e959ed32c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Time Series Topology]]></title>
            <link>https://medium.com/@kennywang2003/%E6%99%82%E9%96%93%E5%BA%8F%E5%88%97%E7%9A%84%E6%8B%93%E6%A8%B8-5350587e4557?source=rss-da3fd5348c54------2</link>
            <guid isPermaLink="false">https://medium.com/p/5350587e4557</guid>
            <dc:creator><![CDATA[ChiChienWang]]></dc:creator>
            <pubDate>Mon, 01 Apr 2024 03:57:52 GMT</pubDate>
            <atom:updated>2024-04-03T03:53:02.167Z</atom:updated>
            <content:encoded><![CDATA[<p>The previous discussion talked about Topological Data Analysis (TDA) as a method for analyzing and studying the shape of data from point clouds. Among the article discussed, Persistent Homology was mentioned as an analytical method. This article will delve into the applications of <strong>Persistent Homology in real-life time series data</strong>.</p><h4>Takens embedding</h4><p>First, i would like to introduce an embedding method, also known as <strong>time-delay embedding</strong>. This method was used by <strong>Floris Takens</strong> in his research on dynamical systems. But what role does it play in Topological Data Analysis (TDA)? When you have a dataset with <strong>periodic data</strong>, whether it’s in two dimensions or multidimensional, it’s challenging to find persistent features in the persistent diagram. However, time-delay embedding can achieve the following effects:</p><pre># Time series data<br>t = np.linspace(0, 10, 1000)<br>x = np.sin(t) + np.sin(2*t)<br># Embedding dimension and time-delay<br>m = 3 <br>tau = 10<br># Reconstruct time-delay vector<br>V = np.array([x[:-2*tau], x[tau:-tau], x[2*tau:]])<br># Original data<br>plt.figure(figsize=(12, 6))<br>plt.subplot(121)<br>plt.plot(t, x)<br>plt.title(&#39;Original Time Series&#39;)<br># After reconstruct<br>plt.subplot(122, projection=&#39;3d&#39;)<br>plt.plot(V[0], V[1], V[2])<br>plt.title(&#39;Reconstructed State Space&#39;)<br>plt.tight_layout()<br>plt.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Np1EFKlrfNOj5Uu-GcbI-g.png" /></figure><ol><li>I assume the time series formula is <em>x</em>(<em>t</em>)=sin(<em>t</em>)+sin(2<em>t</em>), where <em>t</em> represents time. The goal is to reconstruct its dynamical framework from this time series.</li><li>Next, we select two parameters: the embedding dimension <em>m</em> and the time delay <em>T</em>. For the sake of visualization, we set <em>m</em> to 3, meaning the data points will be presented in a three-dimensional reconstruction. The time delay is set to 1 second.</li><li>Finally, each vector is composed of an original data point from the time series and its subsequent <em>m</em>−1 delayed data points. Therefore, for a delay of 1 second, the vector can be represented as <em>V</em>(<em>t</em>)=[<em>x</em>(<em>t</em>),<em>x</em>(<em>t</em>+<em>T</em>),<em>x</em>(<em>t</em>+2<em>T</em>)], which corresponds to the graphical representation shown on the right.</li></ol><p>It’s important to note that the periodic pattern depicted in the graph, while not perfect, still allows us to discern its holes. When using the <strong>Rips (Vietoris-Rips) Diagram</strong>, we can observe some information. The analysis method of the Rips Diagram involves continuously expanding the <strong>radius </strong>of data points in the point cloud, and when a data point touches another, they are connected, eventually forming a <strong>simplicial complex</strong>. Therefore, data points that appear on the diagonal are <strong>considered noise</strong>, as they <strong>die shortly after they are born</strong>, indicating impermanence. In this graph, points on the diagonal are ignored, and the focus is on the persistent H1 (or loops). However, although there are clearly two holes, why are three detected here?</p><pre>from gtda.time_series import SingleTakensEmbedding<br>from gtda.homology import VietorisRipsPersistence<br><br>mbedder_nonperiodic = SingleTakensEmbedding(<br>    parameters_type = &quot;fixed&quot;,<br>    n_jobs = 2,<br>    time_delay = 16,<br>    dimension = 3,<br>    stride = 3,<br>)<br><br>y_nonperiodic_embedded = embedder_nonperiodic.fit_transform(x)<br>plot_point_cloud(y_nonperiodic_embedded)<br><br>y_nonperiodic_embedded = y_nonperiodic_embedded[None, :, :]<br><br>nonperiodic_persistence = VietorisRipsPersistence(<br>    homology_dimensions = [0, 1, 2], n_jobs = 6<br>)<br>nonperiodic_persistence.fit_transform_plot(y_nonperiodic_embedded);</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*tbgoTKAXz-j35voe8RJ4sw.png" /></figure><pre>y_nonperiodic_embedded = embedder_nonperiodic.fit_transform(x)<br>plot_point_cloud(y_nonperiodic_embedded)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/398/1*zT9Q70HVeqMR4m9N4OrLMA.png" /></figure><p>First we note the persistence point that dies at about 0.5, which might be a smaller circle that connected first into a loop due to its <strong>higher density</strong>. Then, there’s the second death at about 1, resulting from the cloud points finally connecting to form a <strong>larger circle</strong>. But how does the last one appear? My understanding is that the graph narrows in the middle, meaning that as the radius of each data point continues to expand, the edge of the smaller circle, indicated in yellow, and the narrower edge of the larger circle connected to form a new loop. However, it’s important to note that the original loop does not disappear due to this division (more details <a href="https://appliednetsci.springeropen.com/articles/10.1007/s41109-019-0179-3">here</a>).</p><h4>PCA</h4><p>Principal Component Analysis (PCA) can be effectively combined with Topological Data Analysis (TDA). First, we create an attractive periodic dataset, which, after Takens embedding, can yield a well-defined elliptical shape. However, at this point, we have embedded it into a six-dimensional space, assuming the real data is six-dimensional. Finally, by applying PCA, we can reduce the dimensionality from six-dimensional space and identify outliers in the data, while simultaneously discovering its persistent features (loops).</p><pre>x_periodic = np.linspace(0, 10, 1000)<br>y_periodic = np.cos(5 * x_periodic)<br><br>fig = go.Figure(data=go.Scatter(x=x_periodic, y=y_periodic))<br>fig.update_layout(xaxis_title=&quot;Timestamp&quot;, yaxis_title=&quot;Amplitude&quot;)<br>fig.show()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MImiwsSN0StBgh96wWETjQ.png" /></figure><pre>embedder_periodic = SingleTakensEmbedding(<br>    parameters_type=&quot;fixed&quot;,<br>    n_jobs=2,<br>    time_delay = 6,<br>    dimension = 8,<br>    stride = 10,<br>)<br>y_periodic_embedded = embedder_periodic.fit_transform(y_periodic)<br>plot_point_cloud(y_periodic_embedded)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*71fPzHcDclMwFjnisL2AWQ.png" /></figure><pre>from sklearn.decomposition import PCA<br><br>pca = PCA(n_components=3)<br>y_periodic_embedded_pca = pca.fit_transform(y_periodic_embedded)<br>plot_point_cloud(y_periodic_embedded_pca)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/1*5SDTm7GFIt7E4AkoaPxFyQ.png" /></figure><p>Despite Principal Component Analysis (PCA) being a powerful tool, there are limitations to what it can analyze. For example, PCA cannot identify holes in data structures like a <strong>Torus</strong>, which was mentioned in the previous article. This limitation arises because PCA’s primary function is not to uncover topological structures but to compute <strong>variance</strong>. Since projection from directly above does not result in the smallest variance, PCA will not automatically identify the holes unless adjustments are made specifically for this purpose.</p><p>TDA offers a method, known as the <strong>Mapper Algorithm</strong>, that can identify such features. However, this article will not delve into the Mapper Algorithm in detail. You can read more information by coding with R and learn some more <a href="http://bertrand.michel.perso.math.cnrs.fr/Enseignements/TDA/Mapper.html">here</a>.</p><h4>Summary</h4><p>This article mainly discusses Takens embedding, Rips Diagram, and PCA. These analysis methods have actually been used in traffic flow studies in this <a href="https://etd.ohiolink.edu/acprod/odb_etd/etd/r/1501/10?clear=10&amp;p10_accession_num=osu155563664988436">paper</a>, where y-axis mentioned above can be replaced with traffic flow. Similar waveforms are observed at different times for analysis. The approach taken is even more detailed, involving the use of the <strong>Declutter Algorithm, Bottleneck Distance, and Clustering</strong> to analyze specific periodic traffic flow patterns. I think it is a very accessible paper. However, since PCA was used to reduce dimensions, I suggest the Mapper Algorithm as an approach that can capture data better under certain circumstances.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5350587e4557" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why topology shapes matter]]></title>
            <link>https://medium.com/@kennywang2003/%E6%8B%93%E5%A2%A3%E5%AD%B8%E7%9A%84%E5%BD%A2%E7%8B%80-003917fd38ec?source=rss-da3fd5348c54------2</link>
            <guid isPermaLink="false">https://medium.com/p/003917fd38ec</guid>
            <dc:creator><![CDATA[ChiChienWang]]></dc:creator>
            <pubDate>Fri, 29 Mar 2024 07:53:33 GMT</pubDate>
            <atom:updated>2025-10-24T06:48:57.827Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Topological Data Analysis (TDA)</strong> [1][2] is a fascinating and less commonly discussed topic, so I’m taking this opportunity to introduce and lay the groundwork for practical applications of topology in data analysis. However, we must first understand some topological concepts and the shapes involved by exploring a few classic examples.</p><h3>Example</h3><p>There are various shapes that data can take, and recognizing them can provide valuable insights. If you’re familiar with data science, you might apply specific methods depending on the shape of the data. For instance, if the data shows a trend where the y-axis gradually increases as the x-axis does, this suggests a regression problem. If you observe subgroups, clustering methods may come to mind. Similarly, if you notice a loop or cyclic pattern, and it shows some regularity, it could indicate time series data. A more unusual shape, like flared data with three distinct modes, could come from sensors on an airliner, corresponding to takeoff, landing, and cruising conditions.</p><p>Each shape represents different conditions, and even with minimal information, you can infer a lot about what’s happening in the data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/1*Ac8YVHnvklwhAjCyQr7Btg.png" /><figcaption>This image is taken from<a href="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4780757/pdf/nihms760576.pdf"> here</a></figcaption></figure><p><strong>Issue &amp; Solution</strong></p><p>The previous section provided an example of 2-dimensional data, but in reality, your data might have many more dimensions. Even when visualizing with Principal Components Analysis (PCA), the plot may not reveal enough information, which can hinder decision-making. You might then wonder how to identify all types of shapes in the data at once, this is where a powerful method called the <strong>Mapper Algorithm [3] </strong>comes into play. Mapper is a type of non-linear dimensionality reduction technique, similar to t-distributed stochastic neighbor embedding (<strong>t-SNE</strong>), which is a form of <strong>manifold learning</strong>. Both methods rely on fundamental concepts from topology to uncover meaningful structures in the, but Mapper focuses more on <strong>connectivity</strong>.</p><p>The Mapper algorithm reduces high-dimensional data to a lower-dimensional representation while preserving more information compared to PCA. Although PCA or Kernel Density Estimation (KDE) are often used as initial steps in this method, they are not the focus of the Mapper algorithm. Since I’ve already written an article primarily about the Mapper algorithm, I won’t delve further into its details here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/355/1*D0sgqsVUCID0D5FL7B-e4A.png" /><figcaption>Mapper finding subgroups of diabetes from (1)</figcaption></figure><p>In addition to the Mapper algorithm, there’s another concept in Topological Data Analysis (TDA) called <strong>persistent homology</strong> (PH). This is a fascinating approach that focuses on identifying persistent features in data, whether it be traditional data or images. Persistent homology captures these features and represents them using a persistence diagram (PD), which shows how long specific topological features last across different scales. The concept involves simplicial complexes, which can seem abstract and challenging if you’re not familiar with TDA. Understanding the basics of simplicial complexes and persistence is essential to fully interpret the resulting diagrams.</p><p>For example, the diagram below shows the persistence diagram of image 0 and image 8, where the <strong>cubical complex</strong> is computed. In the first plot, you can observe a 1 dimension <strong>hole</strong>, while the second plot shows two holes. Points near the diagonal in the diagram are typically considered noise. This is a simple example, but there are other types of complexes, such as <strong>Alpha, Vietoris-Rips, and Čech complexes</strong>, which can result in more intricate diagrams that might be harder to interpret.</p><p>Although persistent homology is a powerful tool for understanding shapes and extracting features for machine learning or deep learning models, it’s essential to have a solid understanding of TDA to use it correctly and interpret its results effectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*qP_dkuJyi0057DGN4Uc4-g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*YN1eVj0CKOoya3Jrnzb-9Q.png" /></figure><p><strong>Conclusion</strong></p><p>This article focuses on why the shape of data is important. The examples demonstrate that every dataset has a shape, and this shape holds valuable information that can aid further analysis. One common issue you may face, as I did, is how to approach data that isn’t easily visualized. To address this, I provide methods to delve deeper into topological concepts for data analysis. Although I’d like to introduce more examples to show how powerful and robust these methods are, this article’s aim is to emphasize the significance of shape. I have written other articles that cover the fundamentals of each method in greater detail.</p><h4>Reference</h4><p>[1] Chazal, F., &amp; Michel, B. (2021). An introduction to topological data analysis: fundamental and practical aspects for data scientists. <em>Frontiers in artificial intelligence</em>, <em>4</em>, 667963.</p><p>[2] Carlsson, G. (2009). Topology and data. <em>Bulletin of the American Mathematical Society</em>, <em>46</em>(2), 255–308.</p><p>[3] Singh, G., Mémoli, F., &amp; Carlsson, G. E. (2007). Topological methods for the analysis of high dimensional data sets and 3d object recognition. <em>PBG@ Eurographics</em>, <em>2</em>, 091–100.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=003917fd38ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>