Skip to content

Commit 36572e0

Browse files
Merge pull request #3 from LambdaGeo/ch01_ecosystem
Ch01 ecosystem
2 parents 550ade7 + fd30762 commit 36572e0

File tree

1 file changed

+157
-1
lines changed

1 file changed

+157
-1
lines changed

docs/part1/ch01_ecosystem.ipynb

Lines changed: 157 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,163 @@
312312
"id": "92bf3621",
313313
"metadata": {},
314314
"source": [
315-
"You likely already know that computers are the best tool for automating repetitive tasks, but I hope you will soon realize that this is best achieved by writing scripts."
315+
"You likely already know that computers are the best tool for automating repetitive tasks, but I hope you will soon realize that this is best achieved by writing scripts. Therefore, we need a different mindset—one that many authors refer to as 'computational thinking'. Computational Thinking is the thought processes involved in formulating a problem and its solution(s) so that the solutions are represented in a form that can be effectively carried out by an information-processing agent.\n",
316+
"\n",
317+
"\n",
318+
"<div class=\"admonition quote\">\n",
319+
"<p class=\"admonition-title\">Computational Thinking</p>\n",
320+
"<p>\"Computational thinking is a fundamental skill for everyone, not just for computer scientists.\" — Jeannette Wing (2006)</p>\n",
321+
"</div>\n",
322+
"\n",
323+
"Computational thinking helps solve problems across different disciplines and is incredibly valuable for data scientists. It is built upon four main pillars: decomposition, pattern recognition, abstraction, and algorithmic thinking.\n",
324+
"\n",
325+
"1. Decomposition: Breaking down a complex problem into smaller, manageable parts.\n",
326+
"2. Pattern Recognition: Identifying trends or similarities within or among problems.\n",
327+
"3. Abstraction: Focusing on the important information only, ignoring irrelevant details.\n",
328+
"4. Algorithmic Thinking: Developing a step-by-step solution to the problem.\n",
329+
"\n",
330+
"To see these pillars in action, let's look at a practical problem: Calculating the percentage of the world's GDP contributed by each country.\n",
331+
"\n",
332+
"### Decomposition\n",
333+
"\n",
334+
"Instead of trying to solve the whole problem at once, we divide it into smaller, manageable tasks:\n",
335+
"\n",
336+
"1. Calculate the total world GDP by summing the values for all countries.\n",
337+
"2. For each specific country, divide its individual GDP by the total world GDP.\n",
338+
"3. Multiply the result by 100 to get the percentage.\n",
339+
"\n",
340+
"### Pattern Recognition\n",
341+
"\n",
342+
"We notice a recurring pattern: the calculation for one country is identical to the calculation for any other. We can apply a single expression to all rows:\n",
343+
"\n",
344+
"$$\n",
345+
"\\text{GDP Percentage} = \\left( \\frac{\\text{Country GDP}}{\\text{Total World GDP}} \\right) \\times 100\n",
346+
"$$\n",
347+
"\n",
348+
"### Abstraction\n",
349+
"\n",
350+
"Abstraction refers to filtering out unnecessary details to focus on the essential attributes of a system. In our case, it means treating a complex nation simply as a GDP value. Through abstraction, we realize that we are not just looking at countries and economies; we are dealing with a standard percentage calculation. This allows us to use existing tools and functions in Python that were designed for this exact purpose.\n",
351+
"\n",
352+
"### Algorithms \n",
353+
"\n",
354+
"<div class=\"admonition quote\">\n",
355+
"<p class=\"admonition-title\">What is an Algorithm?</p>\n",
356+
"<p>\n",
357+
" \"An algorithm is a finite method, written in a fixed vocabulary, governed by precise instructions, moving in discrete steps, 1, 2, 3, ..., whose execution requires no insight, cleverness, intuition, intelligence, or perspicuity, and that sooner or later comes to an end.\"\n",
358+
"</p>\n",
359+
"<p style=\"text-align: right;\">— <strong>David Berlinski</strong> (2000)</p>\n",
360+
"</div>\n",
361+
"\n",
362+
"This definition captures a crucial characteristic: the intelligence lies in the construction of the algorithm, not in its execution. The algorithm is a way to represent and share knowledge about a specific problem so that it can be executed by a computer and understood by anyone who speaks the language. A computer can execute the algorithm, and any person familiar with the language can understand it.\n",
363+
"\n",
364+
"The following section presents, at a high level, the steps to calculate the percentage of the total GDP for each country. We will show how these steps are translated into the Python programming language using the Pandas library. Don’t worry about the technical details of the code yet; focus on the algorithmic concept. Notice how we can perform all these operations with just a few lines of code.\n",
365+
"\n",
366+
"**Step 1: Load the input data**"
367+
]
368+
},
369+
{
370+
"cell_type": "code",
371+
"execution_count": 31,
372+
"id": "758de0a0",
373+
"metadata": {},
374+
"outputs": [],
375+
"source": [
376+
"# Using the Natural Earth dataset we loaded earlier\n",
377+
"import geopandas as gpd\n",
378+
"url = \"https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip\"\n",
379+
"world = gpd.read_file(url)"
380+
]
381+
},
382+
{
383+
"cell_type": "markdown",
384+
"id": "b5e4f8c0",
385+
"metadata": {},
386+
"source": [
387+
"**Step 2: Calculate the total world GDP**"
388+
]
389+
},
390+
{
391+
"cell_type": "code",
392+
"execution_count": 32,
393+
"id": "57251122",
394+
"metadata": {},
395+
"outputs": [],
396+
"source": [
397+
"total_gdp = world['GDP_MD'].sum()"
398+
]
399+
},
400+
{
401+
"cell_type": "markdown",
402+
"id": "5b59d8f0",
403+
"metadata": {},
404+
"source": [
405+
"**Step 3: Calculate the GDP percentage for each country**"
406+
]
407+
},
408+
{
409+
"cell_type": "code",
410+
"execution_count": 33,
411+
"id": "38e41ba7",
412+
"metadata": {},
413+
"outputs": [],
414+
"source": [
415+
"world['GDP_Share'] = (world['GDP_MD'] / total_gdp) * 100"
416+
]
417+
},
418+
{
419+
"cell_type": "markdown",
420+
"id": "67141d6a",
421+
"metadata": {},
422+
"source": [
423+
"**Step 4: Display the results**"
424+
]
425+
},
426+
{
427+
"cell_type": "code",
428+
"execution_count": 34,
429+
"id": "2013e41b",
430+
"metadata": {},
431+
"outputs": [
432+
{
433+
"data": {
434+
"text/plain": [
435+
"NAME\n",
436+
"United States of America 24.538620\n",
437+
"China 16.421002\n",
438+
"Japan 5.818051\n",
439+
"Germany 4.420549\n",
440+
"India 3.284599\n",
441+
" ... \n",
442+
"Vanuatu 0.001069\n",
443+
"W. Sahara 0.001038\n",
444+
"Antarctica 0.001028\n",
445+
"Falkland Is. 0.000323\n",
446+
"Fr. S. Antarctic Lands 0.000018\n",
447+
"Name: GDP_Share, Length: 177, dtype: float64"
448+
]
449+
},
450+
"execution_count": 34,
451+
"metadata": {},
452+
"output_type": "execute_result"
453+
}
454+
],
455+
"source": [
456+
"world.set_index(\"NAME\")['GDP_Share'].sort_values(ascending=False)"
457+
]
458+
},
459+
{
460+
"cell_type": "markdown",
461+
"id": "d7238d18",
462+
"metadata": {},
463+
"source": [
464+
"By looking at these four steps, we can see Berlinski’s definition in action. The intelligence of this process lies in the construction of the algorithm—the logical sequence we designed—rather than in its execution. Once the instructions are written in the fixed vocabulary of Python and Pandas, the computer simply follows them to reach the final result. In this sense, an algorithm is a way to represent and share our knowledge about a problem in a format that both humans and machines can understand.\n",
465+
"\n",
466+
"<div class=\"admonition success\">\n",
467+
"<p class=\"admonition-title\">The Intelligence is Yours</p>\n",
468+
"<p>\n",
469+
" As Berlinski noted, the execution of an algorithm requires no \"insight\" or \"cleverness\" from the computer. The true intelligence belongs to <strong>you</strong>, the author. By breaking the problem down and writing these steps, you have transformed your knowledge into a reusable tool that any computer can run.\n",
470+
"</p>\n",
471+
"</div>"
316472
]
317473
},
318474
{

0 commit comments

Comments
 (0)