Updated chapter_19_ai_for_good

Updated Tikz images to new text version
This commit is contained in:
Zeljko Hrcek
2025-06-06 13:12:40 +02:00
parent f4a1403407
commit 8ad9b11d74
2 changed files with 212 additions and 131 deletions

View File

@@ -246,7 +246,80 @@ The Hierarchical Processing Pattern organizes systems into tiers that share resp
@fig-pattern-heirarchical depicts the interaction flow across these tiers. Starting at the edge tier with data collection, information flows through regional aggregation and processing, culminating in cloud-based advanced analysis. Bidirectional feedback loops enable model updates to flow back through the hierarchy, ensuring continuous system improvement.
![Sequence diagram illustrating the Hierarchical Processing Pattern.](images/png/pattern_hp.png){#fig-pattern-heirarchical}
::: {#fig-pattern-heirarchical fig-env="figure" fig-pos="htb"}
```{.tikz}
\begin{tikzpicture}[font=\usefont{T1}{phv}{m}{n}\small]
\tikzset{%
LineA/.style={line width=1.5pt,violet!50,-latex,text=black,shorten <=1pt},
LineB/.style={OliveLine,line width=2.5pt,-{Triangle[width = 7pt, length = 6pt]},shorten <=1.5pt,shorten >=1.5pt},
LineD/.style={GreenD!50, line width = 3pt,text=black},
Box/.style={inner xsep=2pt,
draw=BlueD,
line width=0.75pt,
node distance=1.6,
fill=BlueL!70,
align=flush center,
text width=26mm,
minimum width=26mm,
minimum height=10mm
},
Box2/.style={Box, draw=RedLine, fill=RedL}
}
\begin{scope}
\node[Box](B1){Edge (Sensor/Device)};
\node[Box,right=of B1](B2){Regional Tier};
\node[Box,right=of B2](B3){Cloud Tier};
\node[Box,right=of B3](B4){End User};
\end{scope}
%
\begin{scope}[shift={(0,-8)}]
\node[Box2](2B1){Edge (Sensor/Device)};
\node[Box2,right=of 2B1](2B2){Regional Tier};
\node[Box2,right=of 2B2](2B3){Cloud Tier};
\node[Box2,right=of 2B3](2B4){End User};
%
\end{scope}
%
\foreach \x in {1,2,3,4} {
\draw[LineD] (B\x) -- (2B\x);
}
%
\draw[LineB]($(B1)!0.28!(2B1)$)--
node[above,text=black,pos=0.5]{Send Preprocessed Data}
($(B2)!0.28!(2B2)$);
\draw[LineB]($(B2)!0.52!(2B2)$)--
node[above,text=black,pos=0.5]{Transmit Aggregated Data}
($(B3)!0.52!(2B3)$);
%
\draw[LineB]($(B3)!0.72!(2B3)$)--
node[above,text=black,pos=0.5]{Send Updated Model}
($(B2)!0.72!(2B2)$);
%
\draw[LineB]($(B2)!0.8!(2B2)$)--
node[above,text=black,pos=0.5]{Push optimized Model}
($(B1)!0.8!(2B1)$);
%
\draw[LineB]($(B1)!0.88!(2B1)$)--
node[above,text=black,pos=0.5]{Perform Real-Time Inference}
($(B4)!0.88!(2B4)$);
%%
\draw[LineA]($(B1)!0.12!(2B1)$)
to [out=10,in=350,distance=36]
node[right,text=black,pos=0.5,fill=white]{Collect Data}
($(B1)!0.16!(2B1)$);
\draw[LineA]($(B2)!0.35!(2B2)$)
to [out=10,in=350,distance=36]
node[right,text=black,pos=0.51,fill=white]{Aggregate Data}
($(B2)!0.39!(2B2)$);
\draw[LineA]($(B3)!0.59!(2B3)$)
to [out=10,in=350,distance=36]
node[right,text=black,pos=0.5,fill=white]{Train/Update Model}
($(B3)!0.63!(2B3)$);
\end{tikzpicture}
```
Sequence diagram illustrating the Hierarchical Processing Pattern.
:::
This architecture excels in environments with varying infrastructure quality, such as applications spanning urban and rural regions. Edge devices maintain critical functionalities during network or power disruptions by performing essential computations locally while queuing operations that require higher-tier resources. When connectivity returns, the system scales operations across available infrastructure tiers.
@@ -386,27 +459,25 @@ Each layer in the progressive enhancement pattern operates independently, so tha
::: {#fig-pattern-pep fig-env="figure" fig-pos="htb"}
```{.tikz}
\resizebox{.65\textwidth}{!}{%
\begin{tikzpicture}[font=\small\sf,node distance=12mm]
\definecolor{col2}{RGB}{255, 255, 128}
\definecolor{col4}{RGB}{240,240,255}
\definecolor{col5}{RGB}{170,170,51}
\definecolor{col7}{RGB}{158,122,230}
\definecolor{colorB}{RGB}{224,224,224}
\begin{tikzpicture}[line join=round,font=\small\usefont{T1}{phv}{m}{n}]
\tikzset{
LineA/.style={-{Triangle[width=10pt,length=6pt]}, line width=5pt,BrownLine!70,text=black},
AALine/.style={{Triangle[width=10pt,length=6pt]}-, line width=5pt,BrownLine!70,text=black},
Box/.style={inner xsep=2pt,
draw=col7, line width=0.75pt,
rounded corners,
fill=col4!80,
node distance=2,
draw=VioletLine, line width=0.75pt,
fill=VioletL2,
anchor=west,
text width=42mm,align=flush center,
minimum width=42mm, minimum height=10mm
text width=47mm,align=flush center,
minimum width=47mm, minimum height=10mm
},
Text/.style={inner sep=4pt,
Box2/.style={Box, draw=GreenLine,fill=GreenL!70},
Box3/.style={Box, draw=BrownLine,fill=BrownL!70},
Text/.style={inner sep=4pt,
draw=none, line width=0.75pt,
fill=colorB,
font=\footnotesize\sf,
align=flush center,
%fill=TextColor!70,
font=\footnotesize\usefont{T1}{phv}{m}{n},
align=left,
minimum width=7mm, minimum height=5mm
},
}
@@ -416,50 +487,39 @@ Each layer in the progressive enhancement pattern operates independently, so tha
\node[Box,right=of B1](B2){High Resource Requirements\\ (Global Coordination)};
%
\scoped[on background layer]
\node[draw=col5,inner xsep=8mm,
line width=0.75pt,
inner ysep=5mm,
fill=col2!10,yshift=2mm,
fit=(B1)(B2)](BB1){};
\node[draw=BackLine,inner xsep=8mm,
line width=0.75pt,inner ysep=5mm,
fill=BackColor!70,yshift=2mm,fit=(B1)(B2)](BB1){};
\node[below=1pt of BB1.north,anchor=north]{Advanced Layer};
\end{scope}
\begin{scope}[shift={(0,-3.1)}]
\node[Box](B1){Enhanced Features\\ (Data Aggregation)};
\node[Box,right=of B1](B2){Partial Resource Availability (Edge-Cloud Integration)};
\begin{scope}[shift={(0,-3.3)}]
\node[Box2](B1){Enhanced Features\\ (Data Aggregation)};
\node[Box2,right=of B1](B2){Partial Resource Availability (Edge-Cloud Integration)};
%
\scoped[on background layer]
\node[draw=col5,inner xsep=8mm,
line width=0.75pt,
inner ysep=5mm,
fill=col2!10,yshift=2mm,
fit=(B1)(B2)](BB2){};
\node[draw=BlueD,inner xsep=8mm,
line width=0.75pt,inner ysep=5mm,
fill=cyan!5,yshift=2mm,fit=(B1)(B2)](BB2){};
\node[below=1pt of BB2.north,anchor=north]{Intermediate Layer};
\end{scope}
\begin{scope}[shift={(0,-6.2)}]
\node[Box](B1){Core Operations\\(Offline Diagnostics)};
\node[Box,right=of B1](B2){Minimal Resources Required\\(Local Inference)};
\begin{scope}[shift={(0,-6.6)}]
\node[Box3](B1){Core Operations\\(Offline Diagnostics)};
\node[Box3,right=of B1](B2){Minimal Resources Required\\(Local Inference)};
%
\scoped[on background layer]
\node[draw=col5,inner xsep=8mm,
line width=0.75pt,
inner ysep=5mm,
fill=col2!10,yshift=2mm,
fit=(B1)(B2)](BB3){};
\node[draw=RedLine,inner xsep=8mm,line width=0.75pt,inner ysep=5mm,
fill=magenta!5,yshift=2mm,fit=(B1)(B2)](BB3){};
\node[below=1pt of BB3.north,anchor=north]{Baseline Layer};
\end{scope}
\draw[-latex,line width=0.5pt](BB1.200)--
node[Text,pos=0.5]{Fallback: Decreased Resources}(BB2.160);
\draw[latex-,line width=0.5pt](BB1.340)--
node[Text,pos=0.5]{Increased Resources}(BB2.20);
\draw[LineA](BB1.200)--node[Text,right=1mm]{Fallback:\\ Decreased Resources}(BB2.160);
\draw[AALine](BB1.340)--node[Text,right=1mm]{Increased\\ Resources}(BB2.20);
\draw[-latex,line width=0.5pt](BB2.200)--
node[Text,pos=0.5]{Fallback: Decreased Resources}(BB3.160);
\draw[latex-,line width=0.5pt](BB2.340)--
node[Text,pos=0.5]{Increased Resources}(BB3.20);
\end{tikzpicture}}
\draw[LineA](BB2.200)--node[Text,right=1mm]{Fallback:\\ Decreased Resources}(BB3.160);
\draw[AALine](BB2.340)--node[Text,right=1mm]{Increased\\ Resources}(BB3.20);
\end{tikzpicture}
```
Progressive enhancement pattern with specific examples of functionality at each layer.
:::
@@ -540,57 +600,42 @@ The Distributed Knowledge Pattern comprises specific architectural components de
::: {#fig-pattern_dc fig-env="figure" fig-pos="htb"}
```{.tikz}
\begin{tikzpicture}[font=\small\sf,node distance=24mm]
\definecolor{colorFill1}{RGB}{180,222,240}
\definecolor{colorFill2}{RGB}{219,253,166}
\definecolor{colorLine1}{RGB}{73,89,56}
\definecolor{colorB}{RGB}{224,224,224}
\begin{tikzpicture}[line join=round,font=\small\usefont{T1}{phv}{m}{n}]
\tikzset{
LineA/.style={-{Triangle[width=6pt,length=6pt]}, line width=2pt,BrownLine!60,text=black},
Box/.style={inner xsep=2pt,
rounded corners,
draw=colorLine1,
line width=0.75pt,
fill=colorFill2,
node distance=2,
draw=BlueD, line width=0.75pt,
fill=BlueL!70,
anchor=west,
text width=16mm,align=flush center,
minimum width=16mm, minimum height=10mm
},
Text/.style={inner sep=4pt,
draw=none, line width=0.75pt,
fill=colorB,
font=\footnotesize\sf,
align=flush center,
minimum width=7mm, minimum height=5mm
text width=20mm,align=flush center,
minimum width=20mm, minimum height=10mm
},
Box2/.style={Box, draw=GreenLine,fill=GreenL!70},
Box3/.style={Box, draw=GreenLine,fill=GreenL!70},
Box4/.style={draw=VioletLine,fill=VioletL2, trapezium,aspect=2,inner sep=-1ex, text width=30mm,
diamond, minimum width=34mm, minimum height=20mm, align= flush center},
Text/.style={fill=none,font=\footnotesize\usefont{T1}{phv}{m}{n}, align=left},
}
\node[Box](B1){Node 1};
\node[Box,right=of B1](B2){Node 2};
\node[Box,right=of B2](B3){Node \ldots};
\node[Box,node distance=2.7,right=of B2](B3){Node \ldots};
\node[Box,right=of B3](B4){Node N};
%
\draw[-latex,line width=0.5pt](B1)--(B2);
\draw[-latex,line width=0.5pt](B2)--(B3);
\draw[-latex,line width=0.5pt](B3)--(B4);
\node[Text]at ($(B1)!0.5!(B2)$){Shares\\ Insights};
\node[Text](SI2)at ($(B2)!0.5!(B3)$){Shares\\ Insights};
\node[Text]at ($(B3)!0.5!(B4)$){Shares\\ Insights};
\draw[LineA](B1)--node[Text,above]{Shares\\ Insights}(B2);
\draw[LineA](B2)--node[Text,above](SI2){Shares\\ Insights}(B3);
\draw[LineA](B3)--node[Text,above]{Shares\\ Insights}(B4);
%%
\node[Box,diamond,,node distance=10mm,
line width=0.75pt,
align=center,
below=of SI2
] (D) {Central\\ Aggregation};
\node[Box,node distance=12mm
,below=of D](DB){Central\\ Analysis};
\draw[-latex,line width=0.5pt](D)--(DB);
\node[Text]at ($(D)!0.6!(DB)$){Aggregates Knowledge};
\node[Box4,below=2of SI2] (D) {Central\\ Aggregation};
\node[Box3,node distance=12mm,below=of D](DB){Central\\ Analysis};
\draw[LineA](D)--node[Text,right,pos=0.4]{Aggregates\\ Knowledge}(DB);
%%
\draw[-latex,line width=0.5pt](B1)|-node[Text,pos=0.13]{Shares Data}(D);
\draw[-latex,line width=0.5pt](B2)|-node[Text,pos=0.13]{Shares Data}(D);
\draw[-latex,line width=0.5pt](B3)|-node[Text,pos=0.13]{Shares Data}(D);
\draw[-latex,line width=0.5pt](B4)|-node[Text,pos=0.13]{Shares Data}(D);
\draw[LineA](B1)|-node[Text,right,pos=0.12]{Shares Data}(D);
\draw[LineA](B2)|-node[Text,right,pos=0.12]{Shares Data}(D);
\draw[LineA](B3)|-node[Text,right,pos=0.12]{Shares Data}(D);
\draw[LineA](B4)|-node[Text,right,pos=0.12]{Shares Data}(D);
\end{tikzpicture}
```
Distributed Knowledge Pattern with differentiated shapes for nodes, central aggregation, and analysis.
@@ -652,58 +697,39 @@ Rather than being a standalone pattern, Adaptive Resource Pattern management is
::: {#fig-patterns_adaptive fig-env="figure" fig-pos="htb"}
```{.tikz}
\begin{tikzpicture}[font=\small\sf,node distance=9mm]
\definecolor{colorFill1}{RGB}{180,222,240}
\definecolor{colorFill2}{RGB}{219,253,166}
\definecolor{colorLine1}{RGB}{73,89,56}
\definecolor{colorB}{RGB}{224,224,224}
\tikzset{
\begin{tikzpicture}[line join=round,font=\small\usefont{T1}{phv}{m}{n}]
\tikzset{
LineA/.style={-{Triangle[width=6pt,length=6pt]}, line width=2pt,BrownLine!60,text=black},
Box/.style={inner xsep=2pt,
rounded corners,
draw=colorLine1,
line width=0.75pt,
fill=colorFill2,
node distance=1.5,
draw=BlueD, line width=0.75pt,
fill=BlueL!70,
anchor=west,
text width=34mm,align=flush center,
minimum width=34mm, minimum height=8mm
},
Text/.style={inner sep=4pt,
draw=none, line width=0.75pt,
fill=colorB,
font=\footnotesize\sf,
align=flush center,
minimum width=7mm, minimum height=5mm
text width=35mm,align=flush center,
minimum width=35mm, minimum height=10mm
},
Box2/.style={Box, draw=GreenLine,fill=GreenL!70},
Box3/.style={Box, draw=VioletLine,fill=VioletL2},
Text/.style={fill=none,font=\footnotesize\usefont{T1}{phv}{m}{n}, align=left},
}
\node[Box](B1){ High Resources};
\node[Box,right=of B1](B2){Medium Resources};
\node[Box,right=of B2](B3){Low Resources};
\begin{scope}[shift={(0,-2)}]
\node[Box](BB1){ Full Capabilities};
\node[Box,right=of BB1](BB2){Optimized Functionality};
\node[Box,right=of BB2](BB3){Basic Functionality};
\end{scope}
\node[Box,below=1.5 of $(BB2)!0.5!(BB3)$](DB){Adaptation Feedback};
\draw[-latex,line width=0.5pt](B3)--(B2);
\draw[-latex,line width=0.5pt](B2)--(B1);
\draw[-latex,line width=0.5pt](B1)--
node[Text]{Adaptation Feedback}(BB1);
\draw[-latex,line width=0.5pt](B2)--
node[Text]{Moderate Operations}(BB2);
\draw[-latex,line width=0.5pt](B3)--
node[Text]{Simplified Operations}(BB3);
\draw[-latex,line width=0.5pt](DB)|-
node[Text,pos=0.08]{Recalibration}(B2.355);
\draw[-latex,line width=0.5pt](B3.east)--++(0:0.5)|-
node[Text,pos=0.7]{Recalibration}(DB);
\draw[-latex,line width=0.5pt](BB1)|-(DB);
\draw[-latex,line width=0.5pt](BB2)|-(DB);
\draw[-latex,line width=0.5pt](BB3)|-(DB);
%
\node[Box2,below=of B1](BB1){Full Capabilities};
\node[Box2,right=of BB1](BB2){Optimized Functionality};
\node[Box2,right=of BB2](BB3){Basic Functionality};
\node[Box3,below=1.7 of $(BB2)!0.5!(BB3)$](DB){Adaptation Feedback};
\draw[LineA](B3)--(B2);
\draw[LineA](B2)--(B1);
\draw[LineA](B1)--node[Text,right]{Adaptation\\ Feedback}(BB1);
\draw[LineA](B2)--node[Text,right]{Moderate\\ Operations}(BB2);
\draw[LineA](B3)--node[Text,right]{Simplified\\ Operations}(BB3);
\draw[LineA](DB)|-node[Text,right,pos=0.05]{Recalibration}(B2.353);
\draw[LineA](B3.east)--++(0:0.5)|-node[Text,above,pos=0.7]{Recalibration}(DB);
\draw[LineA](BB1)|-(DB);
\draw[LineA](BB2)|-(DB);
\draw[LineA](BB3)|-(DB);
\end{tikzpicture}
```
The Adaptive Resource Pattern.
@@ -789,7 +815,62 @@ These dimensions can be visualized through a quadrant analysis framework that ma
@fig-quadrant provides a structured approach for pattern selection based on two key axes: resource availability and scalability/adaptability needs. The horizontal axis corresponds to the level of computational, network, and power resources available to the system. Systems designed for resource-constrained environments, such as rural or remote areas, are positioned towards the left, while those leveraging robust infrastructure, such as cloud-supported systems, are placed towards the right. The vertical axis captures the system's ability to function across diverse settings or respond dynamically to changing conditions.
![Quadrant mapping of design patterns for AI for Social Good projects based on resource availability and scalability/adaptability needs.](images/png/quadrant.png){#fig-quadrant width=70%}
::: {#fig-quadrant fig-env="figure" fig-pos="htb"}
```{.tikz}
\scalebox{0.75}{%
\begin{tikzpicture}[line join=round,font=\small\usefont{T1}{phv}{m}{n}]
\tikzset{
Box/.style={inner xsep=0pt,
node distance=-0.05,
draw=VioletLine, line width=0.75pt,
fill=VioletL!40,
minimum width=48mm, minimum height=48mm
},
Box2/.style={Box, draw=VioletLine,fill=VioletL!30},
Box3/.style={Box, draw=VioletLine,fill=VioletL!20},
Box4/.style={Box, draw=VioletLine,fill=VioletL!10},
circc/.style={circle, fill=black, inner sep=2pt},
txt/.style={font=\fontsize{8pt}{9}\selectfont\usefont{T1}{phv}{m}{n},align=center}
}
\node[Box](B1){};
\node[Box2,left=of B1](B2){};
\node[Box3,below=of B1](B3){};
\node[Box4,below=of B2](B4){};
\node[below=3pt of B1.north]{Progressive Enhancement};
\node[below=3pt of B2.north]{Hierarchical Processing};
\node[below=3pt of B3.north]{Adaptive Resource};
\node[below=3pt of B4.north]{Distributed Knowledge};
\node[below=3pt of B3.south]{High Resource Availability};
\node[below=3pt of B4.south]{Low Resource Availability};
%
\node[above=3pt of B2.west,rotate=90]{High Scalability/Adaptability};
\node[above=3pt of B4.west,rotate=90]{Low Scalability/Adaptability};
%
\node[draw=VioletLine,inner sep=0pt, line width=1.75pt, fill=none, fit=(B1)(B4)](BB1){};
\node[above=1pt of BB1.north,font=\normalsize\usefont{T1}{phv}{m}{n}]{AI for Social Good: Design Pattern Selection};
%
\coordinate(A)at(1.36,0.44);
\coordinate(B)at(0.48,1.32);
\coordinate(C)at(-3.96,-0.44);
\coordinate(D)at(-4.84,0.44);
\coordinate(E)at(-3.06,-4.87);
\coordinate(F)at(-3.94,-3.97);
\coordinate(G)at(1.36,-3.97);
\coordinate(H)at(0.5,-3.1);
%
\node[circc,label={[txt,xshift=-2mm]below:{Global Fishing\\ Watch}}] at (A){};
\node[circc,label={[txt,xshift=-2mm]below:{Google's Flood Forecasting}}] at (B){};
\node[circc,label={[txt]below:{Medic Mobile}}] at (C){};
\node[circc,label={[txt]below:{PlantVillage Nuru}}] at (D){};
\node[circc,label={[txt,xshift=-2mm]below:{WildEyes AI}}] at (E){};
\node[circc,label={[txt]below:{Wildlife Insights}}] at (F){};
\node[circc,label={[txt,xshift=-2mm]below:{Famine Action\\ Mechanism}}] at (G){};
\node[circc,label={[txt]below:{PlantVillage\\ Nuru}}] at (H){};
\end{tikzpicture}}
```
Quadrant mapping of design patterns for AI for Social Good projects based on resource availability and scalability/adaptability needs.
:::
In low-resource environments with high adaptability needs, the progressive enhancement pattern dominates. Projects like PlantVillage Nuru implement Tiny ML and Mobile ML paradigms for offline crop diagnostics on basic smartphones. Similarly, Medic Mobile leverages these paradigms to support community health workers, enabling offline data collection and basic diagnostics that sync when connectivity permits.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 168 KiB

After

Width:  |  Height:  |  Size: 166 KiB