<?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 Arnon Rokprai on Medium]]></title>
        <description><![CDATA[Stories by Arnon Rokprai on Medium]]></description>
        <link>https://medium.com/@arnonrokprai?source=rss-6f711626d31a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*qVIJGLOQ5tQ4kcMS</url>
            <title>Stories by Arnon Rokprai on Medium</title>
            <link>https://medium.com/@arnonrokprai?source=rss-6f711626d31a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 03:18:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arnonrokprai/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[From Camera-Trap Photos to Habitat Maps: Lessons from a Leopard Cat SDM in Google Earth Engine]]></title>
            <link>https://medium.com/@arnonrokprai/from-camera-trap-photos-to-habitat-maps-lessons-from-a-leopard-cat-sdm-in-google-earth-engine-c5068ec53df4?source=rss-6f711626d31a------2</link>
            <guid isPermaLink="false">https://medium.com/p/c5068ec53df4</guid>
            <category><![CDATA[google-earth-engine]]></category>
            <category><![CDATA[gbif]]></category>
            <category><![CDATA[biodiversity]]></category>
            <category><![CDATA[remote-sensing]]></category>
            <dc:creator><![CDATA[Arnon Rokprai]]></dc:creator>
            <pubDate>Fri, 06 Nov 2026 02:25:22 GMT</pubDate>
            <atom:updated>2026-11-06T02:25:22.596Z</atom:updated>
            <content:encoded><![CDATA[<h3>Why pair camera traps with GBIF data</h3><p>A model that scores an AUC of 0.87 in cross-validation may predict real study sites with an AUC of only 0.62. That is the main lesson from mapping habitat suitability for the leopard cat (<em>Prionailurus bengalensis</em>) across Thailand in Google Earth Engine (GEE).</p><p>Camera traps give reliable data on both detections and non-detections, but cover a small area. Presence records from GBIF and iNaturalist span the whole country, but contain presences only and carry survey bias. This article describes how I combined the two: train the model on national-scale data, then validate it independently with camera traps. It also covers the GEE technical problems I hit along the way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*szssenqwlYDuFGwqrikLKA.png" /></figure><p>[Image: leopard cat habitat suitability map (hide the camera and occurrence layers before taking the screenshot)]</p><h3>The camera-trap data pipeline</h3><p>Monthly field visits produce large volumes of photos and videos, so most of the work is data preparation. I wrote a chain of Python and R scripts:</p><ol><li><strong>Filter empty images with MegaDetector:</strong> automatically separate animals, people, vehicles and blanks, then label species in a sorting tool with one hotkey per image</li><li><strong>Correct camera clocks:</strong> some cameras reset their clocks after battery changes. The script compares timestamps with the recorded deployment dates and writes corrected times to image EXIF and video metadata, with a review plan before any change is applied</li><li><strong>Extract records to a table:</strong> read species from folder names and times from files, split sheets by survey round, and sort by camera and time</li><li><strong>Compute independent events and trap-nights:</strong> photos of the same species less than 30 minutes apart count as one event, giving a relative abundance index (RAI) as events per 100 trap-nights</li><li><strong>Fit occupancy models in R:</strong> use the unmarked package to separate detection probability from occupancy</li><li><strong>Summarise per camera station for the SDM:</strong> each station records detection or non-detection per species plus trap-nights; a non-detection counts as an absence only with at least 20 trap-nights</li></ol><p>This final dataset holds what a GBIF-based SDM lacks: true absences with known survey effort.</p><h3>Presence records from GBIF and iNaturalist</h3><p>All leopard cat records were quality-filtered and spatially thinned before training. I downloaded them through the GBIF and iNaturalist APIs with Python and applied these filters:</p><ul><li>Merge synonyms of the species name and remove duplicates between the two sources (iNaturalist also publishes to GBIF)</li><li>iNaturalist: Research grade only; drop captive animals and records with obscured coordinates</li><li>GBIF: drop some museum specimen types and records flagged with geospatial issues</li><li>Coordinate uncertainty no more than 1,000 m, with at least 2 decimal places</li><li>Records from 2000 onwards, to match the time span of the environmental predictors</li></ul><p>Spatial thinning then keeps one record per 1 km pixel, reducing bias from repeated surveys at popular places such as national parks. Our own camera stations were not used for training; they are kept as an independent validation set.</p><h3>15 environmental predictors at 1 km</h3><p>All predictors come from the public GEE data catalog, resampled to 1 km in UTM. This grain matches the coordinate uncertainty of GBIF records.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*kcC8uFIUlG3BT2ezuxRgaw.png" /></figure><p>Before training, the script computes Spearman correlations from 5,000 random points and flags pairs with |rho| &gt; 0.7 for possible removal.</p><h3>Modelling approach after Crego et al. (2022)</h3><p>I followed the approach of Crego, Stabach and Connette, who also provide a hands-on tutorial for SDMs in GEE, and adjusted some settings for a national scale.</p><ol><li><strong>Pseudo-absences by environmental profiling:</strong> k-means splits the area into 2 environmental clusters, and absences are sampled from the cluster without presences, at a 1:1 ratio to presences</li><li><strong>Random Forest:</strong> 500 trees, minimum leaf size 10, bag fraction 0.5, in probability mode to give suitability from 0 to 1</li><li><strong>Spatial block cross-validation:</strong> 50 km blocks (Crego used 200 km at continental scale), with 70% of blocks for training and 30% for testing, repeated 10 times, so nearby points never fall in both sets</li><li><strong>Evaluation:</strong> AUC-ROC and AUC-PR for each run, plus the threshold that maximises sensitivity + specificity</li><li><strong>Output maps:</strong> mean suitability over the 10 runs, an SD map of uncertainty, a binary map at the mean threshold, and a map of areas where predictors fall outside the training range (extrapolation)</li><li><strong>Independent validation with camera traps:</strong> extract predictions at camera stations and compute AUC against actual detections and non-detections</li></ol><p>All results appear on the map in the Code Editor, with a colour legend, a summary panel and click-to-inspect predictor values.</p><h3>Google Earth Engine pitfalls I actually hit</h3><p>Scripts that run fine on a small area often break at national scale. Here are three problems I hit, in case they help anyone doing similar work.</p><h3>1. User memory limit exceeded in the Code Editor</h3><p>Computing every predictor on the fly for a whole country exceeds the interactive quota. The fix is a two-stage workflow. First, export the predictors to an asset with Export.image.toAsset, which runs as a batch task with much higher limits. Then build the model from that lightweight asset.</p><h3>2. Reprojection output too large</h3><p>Aggregating 30–100 m data to 1 km with reduceResolution forces GEE to fetch native-resolution data over an area of about 850 km at once. That is roughly 9,500 × 9,300 pixels, which exceeds the limit even in a batch task.</p><p>Two chained reduceResolution steps do not help, because the first step still fetches the same area. What worked was reading the first step at 250 m from GEE&#39;s pyramids, which hold precomputed means, then using reduceResolution to go to 1 km, which needs only 16 pixels per cell.</p><pre>function toGrain(img, reducer, viaScale) {<br>  var r = reducer || ee.Reducer.mean();<br>  // Step 1: read from the pyramid at 250 m (no native-resolution fetch)<br>  var out = viaScale ? img.reproject({crs: CRS, scale: viaScale}) : img;<br>  // Step 2: aggregate 250 m to 1 km<br>  return out.reduceResolution({reducer: r, maxPixels: 1024})<br>            .reproject({crs: CRS, scale: GRAIN});<br>}</pre><p>The trade-off is that slope and roughness computed from a 250 m DEM run slightly lower than from 30 m, but remain comparable between areas.</p><p>A debugging tip: the pixel dimensions in the error tell you which layer is the problem. Two of my errors differed in size by a factor of 1.11, the ratio of 100 m to 90 m, so they came from different layers covering the same area.</p><h3>3. Asset not found because of a duplicated path</h3><p>Asset IDs must take the form projects/&lt;cloud-project&gt;/assets/&lt;name&gt;. If projects/ appears twice, the asset is not found. The safest approach is to copy the Table ID straight from the Assets tab.</p><h3>Results: strong CV scores, but camera stations not separated</h3><p>The model performed well in cross-validation, but at camera stations its mean suitability was the same for detections and non-detections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*jx1MD6ThA0--ooiwSqEqJg.png" /></figure><p>A specificity of 0 means the model rated every non-detection station as suitable. The map shows nearly all forest in the north and west classed as “suitable”, while the central plains have high uncertainty and predictors outside the training range.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*BeiArmZIzIs3PUIQsKLAvw.png" /></figure><p>[Image: uncertainty (SD) map and extrapolation areas]</p><h3>Lessons and next steps</h3><p>A cross-validation score only shows that the model separates presences from pseudo-absences. It does not show that it predicts where the animal is truly absent, because the pseudo-absences were already drawn from areas that differ from the presences.</p><ul><li><strong>The leopard cat is a habitat generalist:</strong> at 1 km, regional predictors cannot separate camera stations within the same landscape</li><li><strong>Non-detection is not absence:</strong> a camera may miss the species because detection probability is low, not because the habitat is unsuitable, so the SDM should be read alongside occupancy results that separate detection from occupancy</li><li><strong>Few presence records:</strong> a small training set makes runs vary (SD of AUC 0.08) and leaves high uncertainty where there are no records</li></ul><p>Planned next steps:</p><ol><li>Expand the training area to mainland Southeast Asia for more records and a wider range of environmental conditions</li><li>Build a local 100 m model directly from camera-trap data once several survey rounds are complete</li><li>Extend to other species, especially habitat specialists</li></ol><p>A caution for anyone publishing similar results: hide camera locations and occurrence points on maps, as they can enable poaching or camera theft.</p><h3>References</h3><ul><li>Crego, R.D., Stabach, J.A. &amp; Connette, G. (2022). Implementation of species distribution models in Google Earth Engine. <em>Diversity and Distributions</em>, 28, 904–916. Tutorial: <a href="https://ramirodcrego.com/teaching/gee/">ramirodcrego.com/teaching/gee</a></li><li>Beery, S., Morris, D. &amp; Yang, S. (2019). Efficient pipeline for camera trap image review. arXiv:1907.06772.</li><li>Fiske, I. &amp; Chandler, R. (2011). unmarked: An R package for fitting hierarchical models of wildlife occurrence and abundance. <em>Journal of Statistical Software</em>, 43(10), 1–23.</li><li>Gorelick, N. et al. (2017). Google Earth Engine: Planetary-scale geospatial analysis for everyone. <em>Remote Sensing of Environment</em>, 202, 18–27.</li><li>Hansen, M.C. et al. (2013). High-resolution global maps of 21st-century forest cover change. <em>Science</em>, 342, 850–853.</li><li>Hijmans, R.J. et al. (2005). Very high resolution interpolated climate surfaces for global land areas. <em>International Journal of Climatology</em>, 25, 1965–1978.</li><li>Kennedy, C.M. et al. (2019). Managing the middle: A shift in conservation priorities based on the global human modification gradient. <em>Global Change Biology</em>, 25, 811–826.</li><li>Yamazaki, D. et al. (2019). MERIT Hydro: A high-resolution global hydrography map based on latest topography dataset. <em>Water Resources Research</em>, 55, 5053–5073.</li><li>Occurrence data: <a href="https://www.gbif.org/">GBIF</a> and <a href="https://www.inaturalist.org/">iNaturalist</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c5068ec53df4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[การหา Shortest Path และ MST โดยใช้ R Studio #Network Analysis]]></title>
            <link>https://medium.com/data-growing/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%AB%E0%B8%B2-shortest-path-%E0%B9%81%E0%B8%A5%E0%B8%B0-mst-%E0%B9%82%E0%B8%94%E0%B8%A2%E0%B9%83%E0%B8%8A%E0%B9%89-r-studio-network-analysis-194a19bc6b2b?source=rss-6f711626d31a------2</link>
            <guid isPermaLink="false">https://medium.com/p/194a19bc6b2b</guid>
            <category><![CDATA[network-analysis]]></category>
            <category><![CDATA[minimum-spanning-tree]]></category>
            <category><![CDATA[shortest-path]]></category>
            <dc:creator><![CDATA[Arnon Rokprai]]></dc:creator>
            <pubDate>Thu, 02 May 2019 03:01:00 GMT</pubDate>
            <atom:updated>2019-05-06T08:36:58.510Z</atom:updated>
            <content:encoded><![CDATA[<h3>การหา Shortest Path และ MST โดยใช้ R Studio #Social Network Analysis</h3><blockquote>สวัสดีครับ วันนี้เราจะมาลองหา Shortest Path และ Minimum Spanning Tree (MST) ใน R studio จาก dataset ของ <a href="http://networkrepository.com/eco-stmarks.php">eco-stmarks</a></blockquote><blockquote>ก่อนอื่นเรามาทำความรู้จักกับ Shortest Path และ Minimum Spanning Tree (MST) กันก่อนดีกว่านะครับ</blockquote><h3>Shortest Path คืออะไร….</h3><blockquote>Shortest path เป็นกราฟแบบ connected graph คือการหาเส้นทางที่สั้นที่สุดจาก Vertex หนึ่งไปยัง Vertex หนึ่ง เช่น</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*4qDOXMiYHkzwfc8KT5BvHA.png" /><figcaption>Connected graph</figcaption></figure><p>จากกราฟนี้ เราจะบอกได้ว่า shortest path จาก V1 ไป V6 มี cost เป็น 6 นั่นคือจาก V1 -&gt; V4 -&gt; V6</p><p>แต่ถ้าเป็นแบบ unweight graph จะเห็นว่า shortest path ของมันจะมี cost เป็น 2 นั่นคือจาก V1-&gt;V3-&gt;V6 หรือ V1-&gt;V4-&gt;V6 เนื่องจากมันจะมองว่า cost ของแต่ละกิ่งมีค่าเป็น 1</p><p>ในกรณีที่ graph มี negative cost เช่นจากตัวอย่างต่อไปนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*Egdwh7pAdrVvovCqlZvFTA.png" /><figcaption>Connected graph แบบมี negative cost</figcaption></figure><p>ถ้ามองผ่าน ๆ เราจะบอกว่า shortest path จาก V5 ไป V4 คือ cost 1 แต่ความจริงแล้วเราสามารถ loop เพื่อให้ได้ shortest path ที่สั้นกว่านั้นได้คือ V5 -&gt; V4 -&gt; V2 -&gt; V5 -&gt; V4 ซึ่งมี cost เป็น -6</p><p>แต่มันก็ยังไม่สิ้นสุด เพราะเราสามารถวนกี่รอบก็ได้ ค่า cost ก็จะติดลบไปเรื่อย ๆ ดังนั้นสรุปได้ว่า shortest path ระหว่าง 2 จุดนั้น undefined</p><p>ที่มา : <a href="https://myalgo.wordpress.com/2010/09/04/shortest-path-algorithm/">https://myalgo.wordpress.com/2010/09/04/shortest-path-algorithm/</a></p><h3><strong>Minimum Spanning Tree (MST) คืออะไร….</strong></h3><blockquote>Minimum Spanning Tree คือ Tree อิสระที่เชื่อมต่อทุกๆ Vertex ใน Graph โดยพยายามหาค่าให้มีค่าต่ำที่สุดในการสร้าง</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*4qDOXMiYHkzwfc8KT5BvHA.png" /></figure><p><strong>Prim’s Algorithm</strong></p><p>แนวคิดของ Prim’s algorithm นั้นคือเริ่มจาก node เริ่มต้นของมันนั้นให้เราดูว่ากิ่งไหนมีน้ำหนักน้อยสุดก็ให้ไปกิ่งนั้น ๆ ก่อน โดยที่กิ่งนั้น ๆ จะต้องไม่ไป node ที่มัน span ไปแล้ว และจะต้อง span ไปให้ครบทุก node นั่นคือ initial graph ใหม่ได้ดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*jmKp6U5JhlDbReLdY41dTA.png" /></figure><p>กำหนดให้ vertex 1 เป็นจุดเริ่มต้น ดังนั้นจะเห็นว่ากิ่งของ vertex 1 นั้นกิ่งที่มีค่าน้อยสุดคือจาก vertex 1 ไปยัง vertex 4 ดังนั้นจะได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*Hgo1mrrdsNHbRCb8m1fpmw.png" /></figure><p>จากนั้นเราก็ดูอีกว่ากิ่งไหนน้อย โดยให้ดูจาก vertex 1 กับ vertex 4 เพราะมันถูก span ไว้แล้ว ซึ่งก็คือ กิ่งจาก vertex 1 ไปยัง vertex 2 หรือ vertex 4 ไปยัง vertex 3 เพราะมันมีน้ำหนักกิ่งเท่ากัน เราสามารถเลือกทำอันไหนก่อนก็ได้ เช่นเลือกทำที่ vertex 1 ไปยัง vertex 2 ก่อนดังนั้นจะได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*njezT6pEVMgleWouhhWKSA.png" /></figure><p>ต่อมาให้เราดูที่ vertex 1, 2, 4 ว่ากิ่งไหนมีค่าน้อยสุด ซึ่งก็คือกิ่งจาก vertex 4 ไปยัง vertex 3 เพราะมันมีน้ำหนักเพียง 2 เท่านั้น ดังนั้นให้ทำที่กิ่งนี้ก่อน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*llyWTZC8_oOmtrTQoaqBZg.png" /></figure><p>จากนั้นก็ให้เราดูว่า vertex 1, 2, 4, 3 มันมีกิ่งไหนมีน้ำหนักน้อยสุด โดยที่กิ่งนั้นจะต้องไม่ span ไปยัง node ที่ถูก span ไปแล้ว ซึ่งก็คือกิ่งระหว่าง vertex 4 ไปยัง vertex 7</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*tKq1zKIrOtu8RToN6nB29g.png" /></figure><p>จากนั้นก็ให้ดูว่า vertex 1, 2, 4, 3, 7 นั้นมีกิ่งไหนที่มีน้ำหนักน้อยสุด นั่นคือกิ่ง vertex 7 ไปยัง vertex 6 ดังนั้น</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*-AHh-xQTgej2do0fkP0CIw.png" /></figure><p>จากนั้นก็ให้ดูว่า vertex 1, 2, 4, 3, 7, 6 ว่ามีกิ่งไหนที่มีน้ำหนักน้อยสุด นั่นก็คือกิ่งของ vertex 7 ไปยัง vertex 5</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*YSG6zR5YD5Yew5Z-c0AKaw.png" /></figure><p>จากด้านบนเป็นหลักการ วิธีการของ Prim’s Algorithm ดังนั้นตอนนี้เรามาดู algorithm ของ prim’s algorithm ที่ represent เป็นตารางข้อมูลที่มีลักษณะเหมือนกับ Dijkster algorithm กัน เพียงแต่มันต่างกันตรงที่เวลาเราใส่น้ำหนัก dv ให้กับ vertex นั้น ๆ ให้เราใส่ค่าตามน้ำหนักกิ่งนั้น ๆ ไปเลย เช่นกำหนดให้ vertex 1 เป็นจุดเริ่มต้น</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/285/1*OaiJuQEmML6JHdS0KtyCLw.png" /></figure><p>dv ของ vertex 1 นั้นน้อยสุด ดังนั้นให้ process vertex 1 ก่อน จะได้ดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*xtwajbYIzrJ-eP2rOGWm8w.png" /></figure><p>ซึ่งจะเห็นว่า vertex 1 มันชี้ไปยัง vertex 2, 3, 4 ซึ่งเราจะทำการใส่ค่าน้ำหนักของ dv ไปตามน้ำหนักกิ่งของมันเลย ต่อมาจะเห็นว่า vertex 4 มีน้ำหนัก dv น้อยสุด ดังนั้นให้ process vertex 4 ต่อ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/276/1*hxRmaoLUPr-k4W8fV8TlqA.png" /></figure><p>จะเห็นว่า vertex 4 มันมีกิ่งไปยัง vertex 3, 5, 6, 7 ซึ่งจะเห็นว่าตารางที่แล้ว vertex 3 มันมีค่า dv แล้วซึ่งมีค่าเป็น 4 แต่ว่าเมื่อ process vertex 4 มันกลับพบเส้นทางที่มีน้ำหนักน้อยกว่า ดังนั้นให้เปลี่ยน dv ของ vertex 3 เป็นค่าตามน้ำหนักนั้น ๆ นั่นคือค่า 2 แล้วเปลี่ยน pv เป็น vertex 3</p><p>จากนั้นจะเห็นว่า dv ที่มีน้ำหนักน้อยสุดก็คือ vertex 2, 3 ซึ่งมีน้ำหนักเท่ากัน ดังนั้นเราสามารถเลือก process ไหนก่อนก็ได้ ดังนั้นเราเลือก process vertex 2 ก่อน จะได้ค่าตามตารางนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*_ePxBqbNu5Qr0RqYVUVwuA.png" /></figure><p>ต่อมาให้ทำการ process vertex 3 จะได้ผลตามตารางนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*CuRNQ4Hxvca28o7B3E8j-w.png" /></figure><p>จากการ process vertex 3 จะเห็นว่ามันไปแก้ไขค่า dv ของ vertex 6 เพราะว่ามันพบกิ่งที่มีน้ำหนักน้อยกว่าค่าเดิมของมัน จากนั้นให้เราทำการ process vertex 7 เพราะมันมีค่า dv น้อยสุด</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/278/1*j7qKit5l14HsHrD_zZP6Lg.png" /></figure><p>หลังจากนั้นก็ให้ทำการ process vertex 6 จะได้ค่าตามตารางนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*aXtgR-To6lzAWzw-odnVDg.png" /></figure><p>จะเหลือเพียง vertex เดียวเท่านั้นที่ยังไม่ process ดังนั้นให้เรา process มันเลย จะได้ผลดังนี้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*e7Zfdx0ksCoNKQXEqLxfxQ.png" /></figure><p>จะพบว่า minimum spanning tree ของ graph โจทย์ มีผลรวมของทุกกิ่งที่มีค่าน้อยสุดคือ 16 (total cost) นั่นเอง</p><p>ที่มา : <a href="https://myalgo.wordpress.com/2010/09/04/minimum-spanning-tree/">https://myalgo.wordpress.com/2010/09/04/minimum-spanning-tree/</a></p><blockquote><strong>ต่อไปจะเป็นส่วนของวิธีการหา Shortest Path และ Minimum Spanning Tree (MST)</strong></blockquote><blockquote>“มาลองทำด้วยกันนะครับ ”</blockquote><h3>Let’s go — — — — →</h3><p><strong>Step 1 </strong>: นำข้อมูลเข้าและทำการ plot กราฟ โดยใช้คำสั่ง ดังนี้</p><p>1. ทำการติดตั้ง library (igraph)</p><p>2. นำเข้าข้อมูลโดยใช้คำสั่ง eco &lt;- read.table(file.choose(new = FALSE))</p><p>3. ทำการสร้างกราฟโดยใช้คำสั่ง g &lt;- graph_from_data_frame(A, directed = FALSE, vertices = NULL)</p><p>4. plot กราฟโดยใช้คำสั่ง plot(g)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/559/1*EOqMEkJuAnXLX6fGmgBikw.jpeg" /><figcaption>ตัวอย่าง Code ในการเขียนคำสั่ง</figcaption></figure><blockquote>จะได้โครงสร้างของกราฟ ดังภาพ</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*Rn2ICM2JQ65C2tNVhZtO_w.jpeg" /><figcaption>โครงสร้างของกราฟ (eco-stmarks) ที่ได้จาก R studio</figcaption></figure><p><strong>Step 2</strong> : ทำการหา <strong>Shortest Path</strong>โดยมีขั้นตอน ดังนี้</p><ol><li>ทำการหา shortest path โดยใช้คำสั่ง shortest.paths(g)</li><li>ทำการ shortest path ที่มีค่าเท่ากับ 5 โดยใช้คำสั่ง</li></ol><p>get.shortest.paths(g, 5)</p><p>3. ทำการหาค่าเฉลี่ยของ path ทั้งหมด โดยใช้คำสั่ง average.path.length(g)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/637/1*2FJ1Vp1bmgTgMQQodEZl8w.jpeg" /><figcaption>ตัวอย่าง code ในการหา shortest path</figcaption></figure><p><strong>จะได้ Output ออกมา ดังภาพ</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*f2XBnYZlh8k8gClulMf3ww.jpeg" /><figcaption>Output 1</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*HHuGNFlRTNn0mb-awytEMg.jpeg" /><figcaption>Output 2</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/1*-1PLvHiygDyFuFDFAK_qBg.jpeg" /><figcaption>Output 3</figcaption></figure><p><strong>Step 3</strong>: ทำการหา <strong>Minimum Spanning Tree</strong> โดยมีขั้นตอน ดังนี้</p><ol><li>ทำการหา Minimum Spanning Tree<strong> </strong>โดยใช้คำสั่ง<strong> </strong>mst(g)</li><li>ทำการ plot กราฟ Minimum Spanning Tree โดยใช้คำสั่ง plot(mst(g))</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*iXEOG14Hzmg-a8DY3Lmpxw.jpeg" /><figcaption>ตัวอย่าง code ในการหา MST</figcaption></figure><p><strong>จะได้กราฟออกมา ดังภาพ</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*hP2PrrCc2mEiLPugKGbP-w.jpeg" /><figcaption>โครงสร้างของกราฟ (eco-stmarks) แบบ MST ที่ได้จาก R studio</figcaption></figure><p>บทความนี้ เป็นส่วนหนึ่งของรายวิชา Social Network Analysis (BD517)</p><p>สอนโดย Eakasit Pacharawongsakda, Ph.D.</p><p>Big Data Engineering Program, CITE, DPU</p><p>****หมายเหตุ ถ้ามีเนื้อหาส่วนใดในบทความผิดพลาดสามารถแนะนำได้นะครับ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=194a19bc6b2b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-growing/%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%AB%E0%B8%B2-shortest-path-%E0%B9%81%E0%B8%A5%E0%B8%B0-mst-%E0%B9%82%E0%B8%94%E0%B8%A2%E0%B9%83%E0%B8%8A%E0%B9%89-r-studio-network-analysis-194a19bc6b2b">การหา Shortest Path และ MST โดยใช้ R Studio #Network Analysis</a> was originally published in <a href="https://medium.com/data-growing">Data Growing</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>