Skip to content

Commit 4a03dc4

Browse files
committed
perf(math): change math formula processor to mathjax
1 parent 0e8efc9 commit 4a03dc4

6 files changed

Lines changed: 45 additions & 35 deletions

File tree

.github/workflows/documentation.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
run: |
3434
sudo apt-get install -y doxygen gource libgs-dev
3535
pip install git+https://${{ secrets.GH_SQUID_TOKEN }}@github.com/squidfunk/mkdocs-material-insiders.git
36-
pip install jinja2 Pygments mkdocs mkdocs-same-dir mkdocs-minify-plugin mkdocs-redirects mkdocs-exclude mkdocs-git-committers-plugin-2 mkdocs-git-revision-date-localized-plugin mkdocs-with-pdf
36+
pip install jinja2 Pygments mkdocs mkdocs-same-dir mkdocs-minify-plugin mkdocs-redirects mkdocs-exclude mkdocs-git-committers-plugin-2 mkdocs-git-revision-date-localized-plugin mkdocs-with-pdf beautifulsoup4==4.9.3
3737
npm install
3838
3939
- name: Configure

artificialintelligence/assignments/flocking/README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ Flocking is a behavior that is observed in birds, fish and other animals that mo
88

99
!!! note "Formal Notation Review"
1010

11-
- $\overrightarrow{F}$ means a vector $F$ that has components. In a 2 dimensional vector it will hold $F_x$ and $F_y$. For example, if $F_x = 1$ and $F_y = 1$, then $\overrightarrow{F} = (1,1)$
11+
- $\overrightarrow{F}$ means a vector $F$ that has components. In a 2 dimensional vector it will hold $F_x$ and $F_y$. For example, if $F_x = 1$ and $F_y = 3$, then $\overrightarrow{F} = (1,3)$
1212
- Simple math operations between vectors are done component-wise. For example, if $\overrightarrow{F} = (1,1)$ and $\overrightarrow{G} = (2,2)$, then $\overrightarrow{F} + \overrightarrow{G} = (3,3)$
1313
- $\overrightarrow{P_1P_2}$ means the vector that goes from $P_1$ to $P_2$. It is the same as $P_2-P_1$
1414
- The modulus notation means the length (magnitude) of the vector. $|\overrightarrow{F}| = \sqrt{F_x^2+F_y^2}$ For example, if $\overrightarrow{F} = (1,1)$, then $|\overrightarrow{F}| = \sqrt{2}$
15-
- The hat ^ notation means the unitary vector of the vector. $\hat{F} = \frac{\overrightarrow{F}}{|\overrightarrow{F}|}$ For example, if $\overrightarrow{F} = (1,1)$, then $\hat{F} = (\frac{1}{\sqrt{2}},\frac{1}{\sqrt{2}})$
16-
- The hat notation over 2 points means the unit vector that goes from the first point to the second point. $\widehat{P_1P_2} = \frac{\overrightarrow{P_1P_2}}{|\overrightarrow{P_1P_2}|}$ For example, if $P_1 = (0,0)$ and $P_2 = (1,1)$, then $\widehat{P_1P_2} = (\frac{1}{\sqrt{2}},\frac{1}{\sqrt{2}})$
15+
- The hat ^ notation means the normalized vector(magnitude is 1) of the vector. $\hat{F} = \frac{\overrightarrow{F}}{|\overrightarrow{F}|}$ For example, if $\overrightarrow{F} = (1,1)$, then $\hat{F} = (\frac{1}{\sqrt{2}},\frac{1}{\sqrt{2}})$
16+
- The hat notation over 2 points means the normalized vector that goes from the first point to the second point. $\widehat{P_1P_2} = \frac{\overrightarrow{P_1P_2}}{|\overrightarrow{P_1P_2}|}$ For example, if $P_1 = (0,0)$ and $P_2 = (1,1)$, then $\widehat{P_1P_2} = (\frac{1}{\sqrt{2}},\frac{1}{\sqrt{2}})$
1717
- The sum $\sum$ notation means the sum of all elements in the list going from `0` to `n-1`. Ex. $\sum_{i=0}^{n-1} \overrightarrow{V_i} = \overrightarrow{V_0} + \overrightarrow{V_1} + \overrightarrow{V_2} + ... + \overrightarrow{V_{n-1}}$
1818

1919
It is your job to implement those 3 behaviors following the ruleset below:
@@ -22,7 +22,7 @@ It is your job to implement those 3 behaviors following the ruleset below:
2222

2323
Apply a force towards the center of mass of the group.
2424

25-
1. The $n$ neighbors of an agent are all the other agents that are within a certain radius of the agent;
25+
1. The $n$ neighbors of an agent are all the other agents that are within a certain radius of the agent. It doesnt include the agent itself;
2626
2. Compute the location of the center of mass of the group ($P_{CM}$);
2727
3. Compute the force that will move the agent towards the center of mass($\overrightarrow{F_{c}}$); The farther the agent is from the center of mass, the force increases linearly up to the limit of the cohesion radius $r_c$.
2828

@@ -48,12 +48,11 @@ It will move the agent away from other agents when they get too close.
4848
1. The $n$ neighbors of an agent are all the other agents that are within the separation radius of the agent;
4949
2. If the distance to a neighbor is less than the separation radius, then the agent will move away from it inversely proportionally to the distance between them.
5050
3. Accumulate the forces that will move the agent away from each neighbor ($\overrightarrow{F_{s}}$). And then, clamp the force to a maximum value of $F_{Smax}$.
51-
51+
5252
$$
5353
\overrightarrow{F_s} = \sum_{i=0}^{n-1} \begin{cases}
54-
0 & \text{if } |\overrightarrow{AN_i}| = 0 \\
55-
\widehat{AN_i} / |\overrightarrow{AN_i}| & \text{if } 0 < |\overrightarrow{AN_i}| \leq r_s \\
56-
0 & \text{if } |\overrightarrow{AN_i}| > r_s
54+
\frac{\widehat{AN_i}}{|\overrightarrow{AN_i}|} & \text{if } 0 < |\overrightarrow{AN_i}| \leq r_s \\
55+
0 & \text{if } |\overrightarrow{AN_i}| = 0 \lor |\overrightarrow{AN_i}| > r_s
5756
\end{cases}
5857
$$
5958

@@ -66,7 +65,7 @@ The force will go near infinite when the distance between the agent and the $n$
6665
$$
6766
\overrightarrow{F_{s}} = \begin{cases}
6867
\overrightarrow{F_s} & \text{if } |\overrightarrow{F_s}| \leq F_{Smax} \\
69-
\frac{\overrightarrow{F_s}}{|\overrightarrow{F_s}|} \cdot F_{Smax} & \text{if } |\overrightarrow{F_s}| > F_{Smax}
68+
\widehat{F_s} \cdot F_{Smax} & \text{if } |\overrightarrow{F_s}| > F_{Smax}
7069
\end{cases}
7170
$$
7271

@@ -91,16 +90,16 @@ $$
9190

9291
The force composition is made by a weighted sum of the influences of those 3 behaviors. This is the way we are going to work, this is not the only way to do it, nor the more correct. It is just a way to do it.
9392

94-
- $ \overrightarrow{F} = K_c \cdot \overrightarrow{F_c} + K_s \cdot \overrightarrow{F_s} + K_a \cdot \overrightarrow{F_a} $ `This is a weighted sum!`
95-
- $ \overrightarrow{V_{new}} = \overrightarrow{V_{cur}} + \overrightarrow{F} \cdot \Delta t $ `This is a simplification!`
96-
- $ P_{new} = P_{cur}+\overrightarrow{V_{new}} \cdot \Delta t $ `This is an approximation!`
93+
- \( \overrightarrow{F} = K_c \cdot \overrightarrow{F_c} + K_s \cdot \overrightarrow{F_s} + K_a \cdot \overrightarrow{F_a} \) `This is a weighted sum!`
94+
- \( \overrightarrow{V_{new}} = \overrightarrow{V_{cur}} + \overrightarrow{F} \cdot \Delta t \) `This is a simplification!`
95+
- \( P_{new} = P_{cur}+\overrightarrow{V_{new}} \cdot \Delta t \) `This is an approximation!`
9796

9897
!!! warning
9998

10099
A more precise way for representing the new position would be to use full equations of motion. But given timestep is usually very small and it even squared, it is acceptable to ignore it. But here they are anyway, just dont use them in this assignment:
101100

102-
- $ \overrightarrow{V_{new}} = \overrightarrow{V_{cur}}+\frac{\overrightarrow{F}}{m} \cdot \Delta t $
103-
- $ P_{new} = P_{cur}+\overrightarrow{V_{cur}} \cdot \Delta t + \frac{\overrightarrow{F}}{m} \cdot \frac{\Delta t^2}{2} $
101+
- \( \overrightarrow{V_{new}} = \overrightarrow{V_{cur}}+\frac{\overrightarrow{F}}{m} \cdot \Delta t \)
102+
- \( P_{new} = P_{cur}+\overrightarrow{V_{cur}} \cdot \Delta t + \frac{\overrightarrow{F}}{m} \cdot \frac{\Delta t^2}{2} \)
104103

105104
Where:
106105

artificialintelligence/assignments/life/README.md

Whitespace-only changes.

javascripts/katex.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

javascripts/mathjax.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
window.MathJax = {
2+
tex: {
3+
inlineMath: [['$', '$'],["\\(", "\\)"]],
4+
displayMath: [['$$', '$$'],["\\[", "\\]"]],
5+
processEscapes: true,
6+
processEnvironments: true
7+
},
8+
options: {
9+
ignoreHtmlClass: ".*|",
10+
processHtmlClass: "arithmatex"
11+
}
12+
};
13+
14+
document$.subscribe(() => {
15+
MathJax.typesetPromise()
16+
})

mkdocs.yml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ theme:
6565
- pymdownx.superfences
6666
- announce.dismiss
6767
- content.action.edit
68-
- content.action.view
68+
# - content.action.view
6969
- content.code.annotate
7070
- content.code.copy
7171
- content.code.select
@@ -75,8 +75,8 @@ theme:
7575
# - navigation.expand
7676
- navigation.footer
7777
- navigation.indexes
78-
# - navigation.instant
79-
# - navigation.instant.prefetch
78+
- navigation.instant
79+
- navigation.instant.prefetch
8080
- navigation.prune # prune is incompatible with expand
8181
# - navigation.sections
8282
- navigation.tabs
@@ -156,7 +156,7 @@ markdown_extensions:
156156
anchor_linenums: true
157157
- pymdownx.inlinehilite
158158
- pymdownx.keys
159-
# - pymdownx.magiclink:
159+
- pymdownx.magiclink
160160
# repo_url_shorthand: true
161161
# user: InfiniBrains
162162
# repo: Awesome-GameDev-Resources
@@ -271,13 +271,18 @@ extra:
271271
# - icon: fontawesome/brands/twitter
272272
# link: https://twitter.com/squidfunk
273273

274-
extra_javascript:
275-
- javascripts/katex.js
276-
- https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/katex.min.js
277-
- https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/contrib/auto-render.min.js
274+
#extra_javascript:
275+
# - javascripts/katex.js
276+
# - https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/katex.min.js
277+
# - https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/contrib/auto-render.min.js
278+
#
279+
#extra_css:
280+
# - https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/katex.min.css
278281

279-
extra_css:
280-
- https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.16.7/katex.min.css
282+
extra_javascript:
283+
- javascripts/mathjax.js
284+
- https://polyfill.io/v3/polyfill.min.js?features=es6
285+
- https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js
281286

282287
watch:
283288
- advanced

0 commit comments

Comments
 (0)