Non-Research Tips for Information
Science Researchers (Summer 2024)
Apr 17, 2024
Week 2: Equations and pseudo-codes
https://non-research-tips.github.io/2024

Yusuke Matsui(UTokyo)1

Schedule
Date (2024)

Contents

Presented by

Week 1, Apr 10

Introduction. Review of fundamental concepts

Yusuke, Koya, Yuki, Jun

Week 2, Apr 17

Equations and pseudo-codes

Yusuke Matsui

Week 3, Apr 24

Presentation

Koya Narumi

Week 4, May 1

Tables and plots

Yusuke Matsui

Week 5, May 8

Figures

Koya Narumi

Week 6, May 22

VideosKoya Narumi

Week 7, May 29

Invited Talk 1

Dr. Yoshiaki Bando (AIST)

Week 8, June 5

Invited Talk 2

Prof. Katie Seaborn (Tokyo Tech)

Week 9, June 12

GitHub in depth

Yusuke Matsui

Week 10, June 19

Automation of research and research
dissemination (Web, Cloud, CI/CD)

Jun Kato

Week 11, June 26

Research community

Jun Kato

Week 12, July 3

3DCG illustrations

Yuki Koyama

Week 13, July 10

Final presentations-2

AuthorThe data 𝑥 is…
It's obvious from thecontext what 𝑥 is.

3

Reviewer 2

Author

The data 𝑥 is…
It's obvious from thecontext what 𝑥 is.

What is 𝑥? A scalar? A vector?
Hard to read… Reject!

4

Reviewer 2

Author

The data 𝑥 is…
It's obvious from thecontext what 𝑥 is.

What is 𝑥? A scalar? A vector?
Hard to read… Reject!

The data 𝒙 ∈ ℝ𝐷 is…
Let me explicitly define
𝒙 as a 𝐷-dim vector.

Ok, 𝒙 is a 𝐷-dim real-valued vector. This author uses
a bold alphabet as a vector. Got it. Keep reading…

5

Reviewer 2

Author

The data 𝑥 is…
What is 𝑥? A scalar? A vector?
It's obvious from the
Writing a clear, simple, and precise
Hard to mathematicalread… Reject!
context what 𝑥 is.

description is extremely important!

The data 𝒙 ∈ ℝ𝐷 is…
Let me explicitly define
𝒙 as a 𝐷-dim vector.

Ok, 𝒙 is a 𝐷-dim real-valued vector. This author uses
a bold alphabet as a vector. Got it. Keep reading…

6

Equations and pseudo-codes
Introduce the guideline of writing equations. Three important things:
1. Describe precisely what you want to say without making mistakes.
 Wrong
equations???
Confuse

Reject!

 Wrong
equations Wrong
discussions

2. Be sufficient, not overly complex or ambiguous.
 Complex
equations???
Cannot understandReject!

3. Be understandable even if it is read 10 years later.
???
 Description overfit to thecurrent technology

Future readers7Equations and pseudo-codes➢ Main target audience:✓ Researchers in CV, NLP, or related fields.

➢ Different fields have very different conventions.
✓ If the content in this lecture differs from your field's convention,please always follow your field's convention.
✓ e.g., I suggest using a bold font for vectors, but your field might
never use bold.

“OK” in US“OK” in Japan8

Reference
Dictionary for notation➢ D. A. Harville, “Matrix Algebra From a Statistician's Perspective”, Springer, 2000.
➢ D. A. ハーヴィル，”統計のための行列代数上・下”，丸善出版，2012．
➢ G. H. Golub and C. F. Van Loan, “Matrix Computations, 4th edition”, Johns Hopkins University Press, 2012.
Very precise description for Transformer➢ M. Phuong and M. Hutter, “Formal Algorithms for Transformers”, arXiv 2022. https://arxiv.org/abs/2207.09238
Higher-order tensor➢ T. G. Kolda and B. W. Bader, “Tensor Decompositions and Applications”, SIAM Review, 2009.
➢ 横田達也，”テンソル分解の基礎と応用”，MIRU チュートリアル，2022．
https://speakerdeck.com/yokotatsuya/tensorufen-jie-falseji-chu-toying-yong-miru2022tiyutoriaru
The original document for this lecture➢ 松井勇佑，”工学系の卒論生のための数式記述入門”，GitHub, 2021. https://github.com/mti-lab/math_writing

I’d like to translate it into English,
but I have no time… PR welcome!

9Equations➢ Basic notation for variables➢ String➢ Tips for sets
➢ Inputs/outputs of functions➢ Subscript/superscript➢ Don’t write numpy➢ MiscPseudo codes➢ Basic➢ What do you want to express?
➢ Misc10Equations➢ Basic notation for variables➢ String➢ Tips for sets
➢ Inputs/outputs of functions➢ Subscript/superscript➢ Don’t write numpy➢ MiscPseudo codes➢ Basic➢ What do you want to express?
➢ Misc11

Basic notation for variables➢ Having a good notation for variables is extremely important.
➢ The most important rule: to be consistent✓ Bold for vectors (recommended): This is 𝒙 ∈ ℝ3 … Here, 𝒚 ∈ ℝ3 …
✓ Non-bold for vectors (ok): This is 𝑥 ∈ ℝ3 … Here, 𝑦 ∈ ℝ3 …
✓ Mixed (REALLY BAD!
): This is 𝒙 ∈ ℝ3 … Here, 𝑦 ∈ ℝ3 …

➢ If you decide your way, keep following the way throughout the paper.
12Basic notation for variables➢ For all variables, explicitly write a domain:\in: “an element of”

domain: a set, e.g., ℝ𝑥∈ℝ𝑥 is an element of real numbers→ 𝑥 is a real number➢ Including a domain is crucial; much easier to understand.
➢ If you think you can skip a domain, you’re likely incorrect by 90%.
➢ Writing a domain only requires a bit more space. No side effects.
➢ An exceptional case is when you hide a domain intentionally.
✓ Avoid unnecessarily complex descriptions. (I’ll explain later)✓ e.g., a feature volume for time series 𝑽 ∈ ℝ𝐻×𝑊×𝑇
𝑇 depends on 𝑽…
13

First things first: real numbers, natural numbers, etc➢ Blackboard bold is used for special symbols such as real numbers.
✓ TeX: \mathbb✓ Powerpoint: e.g., \doubleR➢ Examples:✓ ℝ: Real numbers✓ ℕ: Natural numbers✓ ℤ: Integers

https://en.wikipedia.org/wiki/Blackboard_bold➢ Blackboard bold is typically used only in traditional contexts.
✓
Don’t recommend using it for a vector: 𝕩 ∈ ℝ3 (although we doso when writing a vector by hand)
14

Summary
Type

How to write

Example of domain

Example of values

ScalarLowercase or uppercase𝑎 ∈ ℝ. 𝑏 ∈ ℕ. 𝐾 ∈ 10, 20, 30 . 𝑎 = 3.2. 𝑏 = 13. 𝐾 = 20.

VectorLowercase and bold
➢ TeX: \mathbf or \bm➢ Powerpoint: bold𝒙 ∈ ℝ3 . 𝒃 ∈ 0, 1 𝐵 .

𝒙 = 0.1, 0.2, 0.3 ⊤ . 𝒃 = 0, 1, 1, 0 ⊤ .

Matrixand Tensor

Uppercase and bold
➢ TeX: \mathbf or \bm➢ Powerpoint: bold

𝑨 ∈ ℝ2×3 . 𝑰 ∈ 0, 1 𝐻×𝑊×3 .

𝑨=

Set

Calligraphy font in uppercase➢ TeX: \mathcal➢ Powerpoint: e.g., \scriptS

𝒮 ⊂ ℕ.

𝒮 = 2, 4, 8, 16 .

1
4

2
5

3
.
4

15

Scalar➢ Recommend: Lowercase or uppercase (e.g., 𝑎 ∈ ℝ, 𝐾 ∈ ℕ, 𝜇 ∈ ℂ)
➢ If you can specify the range tightly, it’s more informative.
Example𝑎 ∈ 2, 7
𝑎 ∈ 2, 7
𝑎 ∈ 2, 7

Meaning
2≤𝑎≤7
2<𝑎<7
2≤𝑎<7

𝑎 ∈ 2, 7
𝑎 ∈ 2, … , 7

𝑎 = 2 or 𝑎 = 7
If naturally interpreted, 𝑎 = 2 or 𝑎 = 3 or … or 𝑎 = 7.

2

7

2, 7
Range (remember your high-school math!)More informative than 𝑎 ∈ ℝ

All brackets are different andhave various meanings( ) : Parentheses[ ] : Square brackets{ } : Curly brackets

16Vector➢ Recommend: Lowercase and bold, e.g.,✓ 𝒙 ∈ ℝ3 3-dimensional real-valued vector✓ 𝒃 ∈ 0, 1 𝐵 𝐵-dimensional binary vector➢ How to write✓ TeX: \mathbf or \bm✓ Powerpoint: set bold
➢ \mathbf or \bm?
✓ Depends on the TeX style.
✓ Render both, compare them,and select the best one.

Default\mathbf\bm
17

Vector➢ Recommend: Lowercase and bold, e.g.,✓ 𝒙 ∈ ℝ3 3-dimensional real-valued vector✓ 𝒃 ∈ 0, 1 𝐵 𝐵-dimensional binary vector➢ How to write✓ TeX: \mathbf or \bm✓ Powerpoint: set bold

Default➢ \mathbf or \bm?
✓ Depends on the TeX style.
✓ Render both, compare them,and select the best one.

Non-italic. Very different from the default.

\mathbf
Special characters may not work\bm

Italic. Natural but hard to distinguish from the default

18Vector➢ Row-vector or column-vector?
✓ Recommend: If you write a vector (e.g., 𝒙 ∈ ℝ3 ), assume that allvectors are column-vectors.
1
𝒙 = 1, 2, 3 ⊤ = 2 Column-vector. OK.
3
𝒚 = [1, 2, 3]
Row-vector. Only write this if you explicitly need it.
➢ Why should we be careful?
✓ Need to be careful when performing matrix operations:𝑨𝒙 can be computed
Given 𝑨 ∈ ℝ3×3 ,𝑨𝒚 cannot be computed (𝑨𝒚⊤ can be computed)
19

Vector➢ More strictly, just writing “ℝ𝐷 ” cannot decide it’s colum or row.
✓ Explicitly saying 𝐷-dim column-vectors: 𝒂 ∈ ℝ𝐷×1
Recommend this way if
1×𝐷✓ Explicitly saying 𝐷-dim row-vectors: 𝒃 ∈ ℝ
you need a row vector➢ Recommend: Decide in your mind that 𝒄 ∈ ℝ𝐷 is an abbreviatednotation of 𝒄 ∈ ℝ𝐷×1
➢ Important rule: Again, make it to be consistent throughout the paper.
✓ Recommend: “column-vector 𝒙 ∈ ℝ3 and column-vector 𝒚 ∈ ℝ3 ”
✓ Not recommend but OK: “row-vector 𝒙 ∈ ℝ3 and row-vector 𝒚 ∈ ℝ3 ”✓
NO!!!: “column-vector 𝒙 ∈ ℝ3 and row-vector 𝒚 ∈ ℝ3
Same description but sometimes column,
sometimes row??? Confusing. Reject!

20

Matrix and tensor

3
𝐻➢ Recommend: Uppercase and bold, e.g.,✓ 𝑨 ∈ ℝ2×3 2x3 real-valued matrix𝑊✓ 𝑰 ∈ 0, 1 𝐻×𝑊×3 HxWx3 3rd-order tensor. Each element is in [0, 1]➢ Bold or not?
✓ Non-bold may be more usual.
✓ But a non-bold uppercase alphabet can be misinterpreted as a scalar(e.g., 𝐾 is a matrix? Scalar?). Thus, I prefer bold for a matrix.
➢ Higher-order tensor is often used in CV as an image is 3rd-order tensor.
✓ For higher-order tensors, one may use \mathsf or bold \mathcal
21

Matrix and tensor
Example𝑎∈ℝ𝒂 ∈ ℝ2𝑨 ∈ ℝ2×3
𝑩 ∈ 0, 1 2×3
𝑪 ∈ 0, 1 2×3×4
𝑫 ∈ −1, 0, 1 2×3
𝑬 ∈ 0, … , 100 2×3

Meaning
Real-valued scalarTwo-dimensional real-valued vector𝒇 ∈ ℕ1×𝑎𝑏

2x3 real-valued matrix
2x3 matrix, where each element is in [0, 1]
2x3x4 tensor, where each element is in [0, 1)
2x3 matrix, where each element is either -1 or 0 or 1
2x3 matrix, where each element is either 0 or … or 100(𝑎𝑏)-dimensional row vector of natural numbers

𝑭 ∈ ℕ𝑎×𝑏

𝑎x𝑏 matrix of natural numbers
Reshape22

Matrix and tensor➢ Accessing an element of a vector: Given 𝒂 ∈ ℝ3 ,✓ 𝑖-th element: 𝑎𝑖 ∈ ℝ, 𝑎 𝑖 ∈ ℝ, 𝑎 𝑖 ∈ ℝ
Several styles✓ Natural choice: 𝑎𝑖✓ Don’t write: 𝒂𝑖 (this implies an 𝑖-th vector from 𝒂𝑛 10
𝑛=1 )Several styles➢ Accessing an element of a matrix: Given 𝑨 ∈ ℝ3×2 ,✓ 𝑖, 𝑗 -th element: 𝐴𝑖𝑗 ∈ ℝ, 𝑎𝑖𝑗 ∈ ℝ, 𝐴 𝑖, 𝑗 ∈ ℝ, 𝐴 𝑖, 𝑗 ∈ ℝ✓ 𝑖-th row: 𝑨𝑖: ∈ ℝ1×2 , 𝑨 𝑖, ∶ ∈ ℝ1×2 , 𝑨 𝑖, ∶ ∈ ℝ1×2
One may not333
use bold✓ 𝑗-th column: 𝑨:𝑗 ∈ ℝ , 𝑨 : , 𝑗 ∈ ℝ , 𝑨 ∶, 𝑗 ∈ ℝ

23

Matrix and tensor➢ Parenthesis or square brackets?
✓ Both are fine.

1
𝐴=
3

2
4

1
𝐵=
3

2
4

➢ Personally, I prefer square brackets as parenthesis have more meanings.
➢ i.e., parenthesis for vector/matrix may conflict with other usages, e.g.,✓ Usual sentence: “We think XXX (Note that 𝒙 = (1, 2))”2
2
✓ Binomial coefficient:
Cannot distinguish with
∈ ℝ2
3
3
✓ Element-based representation of a matrix: 𝑨 = 𝑎𝑖𝑗✓ Function: 𝑓( 1, 2 )✓ Tuple: (1, 2, 3) Parenthesis is used for a tuple.
✓ etc…

24

Set➢ Recommend: Calligraphy font in uppercase, e.g.,✓ 𝒮 = 2, 13, 5, 7 ⊂ ℕ A set of natural numbers.
✓ 𝒳 = 𝒙1 , 𝒙2 , … , 𝒙𝑁 ⊂ ℝ𝐷 A set of 𝑁 𝐷-dimensional vectors.
𝐷 Can be written as 𝒳 = 𝒙𝑛 𝑁
.
Here,
𝒙
∈
ℝ
.
𝑛
𝑛=1
➢ How to write✓ TeX: \mathcal✓ Powerpoint: e.g., \scriptS➢ Cardinality (the number of elements): 𝒮 = 4➢ A set doesn’t contain duplicate elements.
✓ If does, it’s called multi-set (or bag): 𝒜 = 𝑎, 𝑎, 𝑏 .

25

Set
➢ Domain??
✓It’s a bit tough to show a domain of a set.
Powerset: Given a set 𝒜, a powerset of 𝒜 is defined as all subsets of 𝒜. E.g.,➢ 𝒜 = 1, 3, 5 , then
➢ 2 𝒜 = 𝜙, 1 , 3 , 5 , 1, 3 , 3, 5 , 5, 1 , {1, 3, 5}✓ Consider a set 𝒮 = {5, 3} ⊂ 𝒜, the domain of a set 𝒮 is: 𝒮 ∈ 2𝒜
✓ In the same way, if a set ℬ is a subset of 𝒳, ℬ’s domain is 2𝒳
 ℬ ⊂ ℝ, then ℬ ∈ 2ℝ

Usually, “ℬ ⊂ ℝ” style is easier to read.

➢ The powerset may helps when defining a function with a set-input 𝑓(ℬ):✓ 𝑓: 2ℝ → ℝ
26

Summary (again)
Type

How to write

Example of domain

Example of values

ScalarLowercase or uppercase𝑎 ∈ ℝ. 𝑏 ∈ ℕ. 𝐾 ∈ 10, 20, 30 . 𝑎 = 3.2. 𝑏 = 13. 𝐾 = 20.

VectorLowercase and bold
➢ TeX: \mathbf or \bm➢ Powerpoint: bold𝒙 ∈ ℝ3 . 𝒃 ∈ 0, 1 𝐵 .

𝒙 = 0.1, 0.2, 0.3 ⊤ . 𝒃 = 0, 1, 1, 0 ⊤ .

Matrixand Tensor

Uppercase and bold
➢ TeX: \mathbf or \bm➢ Powerpoint: bold

𝑨 ∈ ℝ2×3 . 𝑰 ∈ 0, 1 𝐻×𝑊×3 .

𝑨=

Set

Calligraphy font in uppercase➢ TeX: \mathcal➢ Powerpoint: e.g., \scriptS

𝒮 ⊂ ℕ.

𝒮 = 2, 4, 8, 16 .

1
4

2
5

3
.
4

27

Equations➢ Basic notation for variables➢ String➢ Tips for sets
➢ Inputs/outputs of functions➢ Subscript/superscript➢ Don’t write numpy➢ MiscPseudo codes➢ Basic➢ What do you want to express?
➢ Misc28

StringIt’s not easy to use strings in equations➢ If you use strings for labels, the easiest way is to define them directly.
✓ A label set ℒ = {“dog”, “cat”, “horse”}✓ Image classifier 𝑓: ℝ𝐻×𝑊×3 → ℒ
If you don't run more complex

operations on them, this should suffice.

➢ Alternatively, you can assign an integer for each label.
✓ A label set ℒ = {1, … , 𝑁}
✓ Image classifier 𝑓: ℝ𝐻×𝑊×3 → ℒ
Label
“dog”

ID

One-hot

1

1, 0, 0 ⊤➢ Alternatively, you can use one-hot vectors.
“horse” 30, 0, 1 ⊤𝑁𝑁
✓ A label set ℒ = 𝒃𝑛 𝑛=1 , 𝒃𝑛 ∈ 0, 1
✓ Image classifier 𝑓: ℝ𝐻×𝑊×3 → ℒ✓ Easy to integrate in other equations, e.g., 𝑓 𝑿 − 𝒚 22 for some 𝒚
“cat”

2

0, 1, 0 ⊤29

It’s not easy𝑁 to use strings in equations
String➢ The description 𝒃 ∈ 0, 1 is not tight; could be any 𝑁-dim binary vectors.
𝑛➢ If you use strings for labels, the easiest way is to define them directly
➢ If✓
you
emphasize
𝒃𝑛 is one-hot,
can write:
A wantlabeltosetℒ = {“dog”,“cat”, you“horse”}✓ 𝒃𝑛 ∈ ℋ1/𝑁
✓ Image classifier𝑁 𝑓: ℝ𝐻×𝑊×3 → ℒ
If you don't run more complex✓ ℋ1/𝑁 = 𝒃 ∈ 0, 1 | 𝒃 = 1
operations on them, this should suffice.
✓ Here, ℋ1/𝑁 is a set of all 1-of-𝑁 binary encoding vectors [1]➢ Alternatively, you can assign an integer for each label✓ Norouzi
A labeland
set D.
ℒ J.=Fleet,{1, …“Cartesian, 𝑁}[1] M.
k-means”, CVPR 2013
✓ Image classifier 𝑓: ℝ𝐻×𝑊×3 → ℒ
Label

ID

One-hot“dog”

1

1, 0, 0 ⊤➢ Alternatively, you can use one-hot vectors“horse” 30, 0, 1 ⊤𝑁𝑁
✓ A label set ℒ = 𝒃𝑛 𝑛=1 , 𝒃𝑛 ∈ 0, 1
✓ Image classifier 𝑓: ℝ𝐻×𝑊×3 → ℒ✓ Easy to integrate in other equations, e.g., 𝑓 𝑿 − 𝒚 22 for some 𝒚
“cat”

2

0, 1, 0 ⊤30

String

A set of character sequences 𝒱 ∗➢ If you need more detailed definition: Kleene closure for characters.
✓ Define a vocabulary 𝒱 = {“a”, “b”, …, “z”}.
✓ Here, 𝒱 2 = 𝒱 × 𝒱, 𝒱 3 = 𝒱 × 𝒱 × 𝒱, … i.e., “a” ∈ 𝒱 and “dog”∈ 𝒱 3✓ Define a set of character sequences 𝒱 ∗ = ∅ ∪ 𝒱 ∪ 𝒱 2 ∪ ⋯✓ Any string (character sequence) is in 𝒱 ∗ : “a”, “dog”, “hoge” ∈ 𝒱 ∗Kleene closure➢ A label set ℒ = {“dog”, “cat”, “horse”} ⊂ 𝒱 ∗➢ Straightforward. But not easy to connect with other equations.

Acknowledgment: I thank Hiroyuki Deguchi for the helpful discussion

31

String

A set of token sequences 𝒱

∗

char

token

“a”

1

“b”

2

➢ If you need more math-friendly representations:…
“z”
𝑁Kleene closure for tokens.
𝑁: vocabulary size
✓ Define a vocabulary 𝒱 = 1, … , 𝑁 .
✓ Here, 𝒱 2 = 𝒱 × 𝒱, 𝒱 3 = 𝒱 × 𝒱 × 𝒱, … ➢ Now it’s just a vector.
➢ Intentionally use “row-vector” style✓ i.e., 3 ∈ 𝒱 and 13, 6, 20 ∈ 𝒱 3✓ Define a set of token sequences 𝒱 ∗ = ∅ ∪ 𝒱 ∪ 𝒱 2 ∪ ⋯✓ Any token sequence (variable length integer-vectors) is in 𝒱 ∗✓ 3, 13, 6, 20 , 6, 18, 16, 7 ∈ 𝒱 ∗Kleene closure➢ This is an ASCII representation for the c-language.
➢ [2] uses this notation.
[2] M. Phuong and M. Hutter, “Formal Algorithms for Transformers”, arXiv 2022. https://arxiv.org/abs/2207.09238

32

String

A set of token sequences➢ Decoder✓ Given 𝑣 ∈ 𝒱, decoder 𝐷(𝑣) returns the original character.
✓ e.g., 𝐷 7 = “g”.
✓ Extends this to 𝒘 ∈ 𝒱 ∗ . e.g., 𝐷 4, 15, 7 = “dog”.

𝒗

𝑫 𝒗

1

“a”

2

“b”
…

𝑁

“z”

➢ Vector-style operations✓ e.g., 𝒘 = 6, 18, 16, 7 ∈ 𝒱 ∗ , then 𝐷 𝒘 = “frog”✓ Specify a character: 𝑤2 = 18, and 𝐷 𝑤2 = “r”✓ Slicing: 𝒘2:4 = 18, 16, 7 , and 𝐷 𝒘2:4 = “rog”➢ Difference to a superset? 2𝒱 vs 𝒱 ∗✓ An element of a super set is a set (not a vector). No duplicate.
✓ 3, 4 ∈ 2𝒱 Cannot have duplicates
3, 4, 4 ∈ 𝒱 ∗ Can have duplicates33

String

A set of token sequences

𝒗

𝑫 𝒗

1

“a”

2

“b”

➢ Token embedding
𝐷: dim of embedding𝑁✓ Embedding matrix 𝑾 ∈ ℝ𝐷×𝑁
✓ The vector representation (embedding) of 𝑣 ∈ 𝒱 is 𝑾 ∶, 𝑣 ∈ ℝ𝐷

…
“z”

𝑣

𝐷

𝑾
𝑁

➢ Can be a tuple?
✓ Yes. You can define so (I’ll discuss later)✓ 1, 3, 5 ∈ 𝒱 ∗34

Equations➢ Basic notation for variables➢ String➢ Tips for sets
➢ Inputs/outputs of functions➢ Subscript/superscript➢ Don’t write numpy➢ MiscPseudo codes➢ Basic➢ What do you want to express?
➢ Misc35

Tips for sets
➢ How to describe 𝒙1 , 𝒙2 , … , 𝒙𝑁 in short?
✓OK, but a bit long? 𝒙𝑖 | 𝑖 = 1, 2, … , 𝑁✓
OK, but a bit long? 𝒙𝑖 | 1 ≤ 𝑖 ≤ 𝑁✓
OK, but a bit long? 𝒙𝑖 | 𝑖 ∈ 1, 2, … , 𝑁✓
Good! Short! 𝒙𝑖 𝑁
This may seem obvious? But many𝑖=1
junior students struggle with this.

➢ How to do when I don’t want to use an alphabet for #set?
Tips to hide the number of elements✓ 𝒳 = 𝒙1 , 𝒙2 , …
You don’t consume any
additional alphabets✓ If you need the number of 𝒳, use 𝒳✓ Double brackets to enumerate natural numbers✓ 𝑁 = 1, 2, … , 𝑁✓
This form is simple, but not so much intuitive. Be careful.

36Set-builder notation➢ A way to create a set. e.g.,Such that𝑥 ∈ℝ|𝑥 >0
Target variable

Predicate (rule)
Real values such that each value is greater than 0
Positive real numbers

Domain of the variable➢ The domain can be written on the right:✓ 𝑥 ∈ ℝ | 𝑥 > 0 = 𝑥 | 𝑥 ∈ ℝ, 𝑥 > 0➢ Any function can be applied to the target variable:
For all points in the 4-dimensional unit sphere,✓ 3𝒙 + 5 | 𝒙 ∈ ℝ4 , 𝒙 2 = 1
affine-transform them by scaling 3 and shift 5
37

Set-builder notation➢ Multiple predicates✓ 𝒙 ∈ ℝ3 | 𝒙⊤ 𝒚1 = 0, 𝒙⊤ 𝒚2 = 0

All 3-dim vectors that are orthogonal toboth 𝒚1 and 𝒚2➢ Multiple variables can be used at the same time (multiple for-loop)✓ 5𝑖𝑗 | 𝑖, 𝑗 ∈ 1, 2, 3 , 𝑖 ≠ 𝑗➢ Set-builder notation is equivalent to a list comprehension in Python✓ 𝒜 = 1, 2, 3, 4, 5 , and 𝑎2 | 𝑎 ∈ 𝒜, 𝑎 > 3✓ A = [1, 2, 3, 4, 5] and {a*a for a in A if a > 3}38

Equations➢ Basic notation for variables➢ String➢ Tips for sets
➢ Inputs/outputs of functions➢ Subscript/superscript➢ Don’t write numpy➢ MiscPseudo codes➢ Basic➢ What do you want to express?
➢ Misc39

Inputs/outputs of functions➢ There are two ways to describe the inputs/outputs of a function✓ e.g., considering 𝑓 𝑥 = 𝑥 2 for 𝑥 ∈ ℝ

𝑓: ℝ → ℝ
2
𝑓: 𝑥 ↦ 𝑥

Set-based description. Use \to (→)
Element-based description. Use \mapsto (↦)➢ Describing the inputs/outputs makes functions easier to read.
➢ It’s ok to directly write the description in a sentence. No side effects.
✓“Let us define a function 𝑓 as follows …”✓“Let us define a function 𝑓: ℕ → 1, … , 10 as follows …”
40

Inputs/outputs of functions➢Domain
There are two waysCodomain
to describe the inputs/outputs of a function✓ e.g., considering 𝑓 𝑥 = 𝑥 2 for 𝑥 ∈ ℝ∈∈

𝑓: ℝ → ℝ
2
𝑓: 𝑥 ↦ 𝑥

Set-based description. Use \to (→)
Element-based description. Use \mapsto (↦)➢ Describing the inputs/outputs makes functions easier to read.
➢ It’s ok to directly write the description in a sentence. No side effects.
✓“Let us define a function 𝑓 as follows …”✓“Let us define a function 𝑓: ℕ → 1, … , 10 as follows …”
41

Inputs/outputs of functions➢ Multiple inputs: 𝑧 = 𝑓 𝑥, 𝑦 = 𝑥 2 + 𝑦 + 1✓ 𝑓: ℝ × ℝ → ℝ✓ 𝑓: 𝑥, 𝑦 ↦ 𝑧 or 𝑓: 𝑥, 𝑦 ↦ 𝑥 2 + 𝑦 + 1➢ Vector input: 𝑓 𝒙 = 𝒂⊤ 𝒙 + 𝑏, where 𝒂, 𝒙 ∈ ℝ𝐷 and 𝑏 ∈ ℝ✓ 𝑓: ℝ𝐷 → ℝ✓ 𝑓: 𝒙 ↦ 𝒂⊤ 𝒙 + 𝑏➢ Vector input and vector output: for 𝒙 = 𝑥1 , 𝑥2 ⊤ ∈ ℝ2 , 𝑓 is defined as
𝑥1 + 𝑥2✓ 𝑓: 𝒙 ↦ 3𝑥1 + log 𝑥2 by the element-based description.
𝑥23✓ Then, the set-based description is 𝑓: ℝ2 → ℝ3

42

Inputs/outputs of functions➢ When the output is a vector, should the function itself be bold?
✓ Depends.

2

3

𝑓: ℝ → ℝ
2
3
𝒇: ℝ → ℝ

With this, the equation may be beautiful: 𝒛 = 𝒇 𝒙 + 𝒂
In modern CV, all functions may have a vector-output,
thus all functions may be bold. It may seem “heavy”?
➢ In this document, I use non-bold for vector-functions.
➢➢43Set-based? Element-based?
➢ Usually, the set-based description is more informative.
➢ Readers have an interest in what are the possible values of the inputs
and outputs.
Both an input and an➢ e.g., for 𝑓 𝑥 = 𝑥 2 ,output are real-values.

𝑓: ℝ → ℝ
2
𝑓: 𝑥 ↦ 𝑥

This is just repeating
the definition.

➢ The element-based description is useful if you want to intentionallyhide the complex relationships.
44

Set-based? Element-based?
➢ Consider an object detector 𝑓, which inputs 𝐻 × 𝑊 × 3 8-bit image(each pixels is in 0, … , 255 ) and returns the followings.
Label 𝑙 ∈ 1, … , 𝐾
Bounding box 𝒃 = 𝑦, 𝑥, ℎ, 𝑤 ⊤ ∈ ℕ4
Confidence score 𝛼 ∈ ℝ➢ Set-based precise description is complex:✓ 𝑓: 0, … , 255 𝐻×𝑊×3 → 1, … , 𝐾 × ℕ4 × ℝ
The pixel value range is not important.
Don’t want to use alphabets 𝐻 and 𝑊 here.

Not so much clear about the right side.
What is each variable?

➢ May be better to moderately hide the detail:“We consider a 𝐾-class object detector 𝑓: 𝑰 ↦ 𝑙, 𝒃, 𝛼 . This function inputs an image 𝑰,
and returns a label 𝑙 ∈ 1, … , 𝐾 , a bbox 𝒃 = 𝑦, 𝑥, ℎ, 𝑤 ⊤ ∈ ℕ4 , and a confidence 𝛼 ∈ ℝ”

45

Equations➢ Basic notation for variables➢ String➢ Tips for sets
➢ Inputs/outputs of functions➢ Subscript/superscript➢ Don’t write numpy➢ MiscPseudo codes➢ Basic➢ What do you want to express?
➢ Misc46

Subscript/superscript➢ Superscripts and subscripts are used to provide additional
information to a variable.
Superscript𝑘𝑎𝑛

Subscript➢ Principal: As little use as possible!
𝑘➢ 𝑥𝑖,𝑗Three variables: No! Hard to follow…
➢ 𝑥𝑎𝑖 Subscript of subscript: No! Hard to follow…

➢ Alternatives for subscript/superscript: decorations➢ e.g., 𝑥,ො 𝑥ҧ
11➢ No: 𝑥mean = ∑𝑥𝑛 Recommend: 𝑥ҧ = ∑𝑥𝑛
𝑁

𝑁

47

Subscript/superscript➢ Tips: a loop index can be removed by re-define a variable.
➢ Consider 𝒱 = 𝑣𝑛 𝑁
𝑛=1
𝑛 is not importantfor n in range(len(V)):
f(V[n])➢”Here, 𝑓 𝑣𝑛 is …”➢”Let us consider 𝑣 ∈ 𝒱. Here, 𝑓 𝑣 is …”
Remove it!
for v in V:
f(v)

48

Subscript/superscript➢ Don’t make the subscript bold (very typical mistake)✓\mathbf{x_i}: 𝒙𝒊 ➢ Natural interpretation is that 𝒊 is a vector to✓\mathbf{x}_i: 𝒙𝑖
indicate identifiers, e.g., 𝒊 = 1, 2 , results in 𝑥1,2
➢ Moreover, this mistake smells amateurish.

➢ If two+ letters are used in the meaning of a label, make it Roman.
✓ \mathbf{x}_\mathrm{in}: 𝑥in OK✓ \mathbf{x}_{in}: 𝑥𝑖𝑛 Not recommend➢ This can be interpreted as✓ 𝑗 =𝑖 ∗𝑛✓ 𝑥𝑗

49

Subscript/superscript➢ Don’t put variables with different meanings in sub/superscript.
𝐷➢ Consider 𝒱 = 𝒗𝑛 𝑁
,
where
𝒗
∈
ℝ
𝑛
𝑛=1

➢ How to denote 𝑑-th element of 𝑛-th vector?
✓
𝑣𝑛,𝑑 ∈ ℝ Not recommend! 𝑛 and 𝑑 have different meanings!
✓
𝑣𝑛 𝑑 ∈ ℝ : OK. Combining square brackets.
✓
𝑣𝑑 ∈ ℝ or 𝑣 𝑑 ∈ ℝ for 𝒗 ∈ 𝒱 : Clear.
𝒱𝑽➢ Tips: You can stack 𝒱 to form a matrix 𝑽 ∈ ℝ𝐷×𝑁
✓ Then, 𝑣𝑑,𝑛 ∈ ℝ or 𝑣 𝑑, 𝑛 ∈ ℝ is OK (usual matrix element access)𝑛, 𝑑 is now 𝑑, 𝑛 . Be careful!

➢ Vector-set (𝒱) to matrix (𝑽) doesn’t consume an alphabet.

50Equations➢ Basic notation for variables➢ String➢ Tips for sets
➢ Inputs/outputs of functions➢ Subscript/superscript➢ Don’t write numpy➢ MiscPseudo codes➢ Basic➢ What do you want to express?
➢ Misc51

Don’t write numpy➢ Many people write numpy descriptions directly in equations. It’s wrong.
a = np.array([5, 4, 3])
b = a - 3

𝑎 = 5, 4, 3
𝑏 =𝑎−3➢ Numpy can broadcast a scalar➢ We can get b=[2, 1, 0]➢ Math equations don’t broadcast.
➢ This operation is undefined!

A horrible mistake!

➢ Recommend:➢ 𝒂 = 5, 4, 3 ⊤ . 𝒃 = 𝒂 − 3𝟏
➢ Use bold
➢ Column-vectors➢ Use all-one vector 𝟏 = 1, 1, … ⊤52

Specific examples of failures➢ Let 𝑋 and 𝑌 be 3-channel images.
➢ Consider a mask matrix 𝐵 whose elements are 0 or 1.
➢ We adopt 𝑋 when the value of the mask is one and 𝑌 when the value of themask is zero.
➢ 𝑍, the resulting image combining 𝑋 and 𝑌, is computed as follows.

𝑍 = 𝐵𝑋 + 1 − 𝐵 𝑌
=
𝑍

+
𝐵

𝑋

1−𝐵

There are three big mistakes… Can you guess?

𝑌53

Specific examples of failures➢ Let 𝑋 and 𝑌 be 3-channel images.
➢ Consider a mask matrix 𝐵 whose elements are 0 or 1.
➢ We adopt 𝑋 when the value of the mask is one and 𝑌 when the value of themask is zero.
➢ 𝑍, the resulting image combining 𝑋 and 𝑌, is computed as follows.

𝒁 = 𝑩𝑿 + 1 − 𝑩 𝒀=
𝒁 ∈ ℝ𝐻×𝑊×3

𝑩 ∈ 0, 1 𝐻×𝑊

First, make the variablesbold, and write domains+
𝑿 ∈ ℝ𝐻×𝑊×3

1−𝑩

𝒀 ∈ ℝ𝐻×𝑊×3

54

Specific examples of failures➢ Let 𝑋 and 𝑌 be 3-channel images.
➢ Consider a mask matrix 𝐵 whose elements are 0 or 1.
➢ We adopt 𝑋 when the value of the mask is one and 𝑌 when the value of themask is zero.
➢ 𝑍, the resulting image combining 𝑋 and 𝑌, is computed as follows.

𝒁 = 𝑩𝑿 + 1 − 𝑩 𝒀=
𝒁 ∈ ℝ𝐻×𝑊×3+

𝑩 ∈ 0, 1 𝐻×𝑊

First, make the variablesbold, and write domains

𝑿 ∈ ℝ𝐻×𝑊×3

1−𝑩

Mistake1: Broadcast happens here!
We need to use an all-one matrix.

𝒀 ∈ ℝ𝐻×𝑊×3

55

Specific examples of failures➢ Let 𝑋 and 𝑌 be 3-channel images.
➢ Consider a mask matrix 𝐵 whose elements are 0 or 1.
➢ We adopt 𝑋 when the value of the mask is one and 𝑌 when the value of themask is zero.
➢ 𝑍, the resulting image combining 𝑋 and 𝑌, is computed as follows.

𝒁 = 𝑩𝑿 + 𝟏 − 𝑩 𝒀=
𝒁 ∈ ℝ𝐻×𝑊×3

𝑩 ∈ 0, 1 𝐻×𝑊+
𝑿 ∈ ℝ𝐻×𝑊×3

𝟏−𝑩

𝒀 ∈ ℝ𝐻×𝑊×3

56

Specific examples of failures➢ Let 𝑋 and 𝑌 be 3-channel images.
➢ Consider
a mask𝐵 whose elements
areneed0 orper1.
Mistake2:
𝑩𝑿 ismatrix
matrix-multiplication!
We➢ Weelement
adopt 𝑋multiplication
when the valueof the mask
is one ⊙and 𝑌 when the value of the(Hadamard
product)
mask is zero.
➢ 𝑍, the resulting image combining 𝑋 and 𝑌, is computed as follows.

𝒁 = 𝑩𝑿 + 𝟏 − 𝑩 𝒀=
𝒁 ∈ ℝ𝐻×𝑊×3

𝑩 ∈ 0, 1 𝐻×𝑊+
𝑿 ∈ ℝ𝐻×𝑊×3

𝟏−𝑩

𝒀 ∈ ℝ𝐻×𝑊×3

57

Specific examples of failures➢ Let 𝑋 and 𝑌 be 3-channel images.
➢ Consider a mask matrix 𝐵 whose elements are 0 or 1.
➢ We adopt 𝑋 when the value of the mask is one and 𝑌 when the value of themask is zero.
➢ 𝑍, the resulting image combining 𝑋 and 𝑌, is computed as follows.

𝒁=𝑩⊙𝑿+ 𝟏−𝑩 ⊙𝒀=
𝒁 ∈ ℝ𝐻×𝑊×3+⊙
𝑩 ∈ 0, 1 𝐻×𝑊

𝑿 ∈ ℝ𝐻×𝑊×3⊙
𝟏−𝑩

𝒀 ∈ ℝ𝐻×𝑊×3

58

Specific examples of failures➢ Let 𝑋 and 𝑌 be 3-channel images.
➢ Consider a mask matrix 𝐵 whose elements are 0 or 1.
➢ We adopt 𝑋 when the value of the mask is one and 𝑌 when the value of themask is zero.
➢ 𝑍, the resulting image combining 𝑋 and 𝑌, is computed as follows.

𝒁=𝑩⊙𝑿+ 𝟏−𝑩 ⊙𝒀=
𝒁 ∈ ℝ𝐻×𝑊×3+⊙
𝑩 ∈ 0, 1 𝐻×𝑊

𝑿 ∈ ℝ𝐻×𝑊×3

Mistake3: 𝑩 ⊙ 𝑿 still doesn’t work because thetensor shape is different! 𝐻 × 𝑊 vs 𝐻 × 𝑊 × 3⊙
𝟏−𝑩

𝒀 ∈ ℝ𝐻×𝑊×3

80% computer visionpapers ignore this issue….

59

Specific examples of failures➢ Let 𝑋 and 𝑌 be 3-channel images.
➢ Consider a mask matrix 𝐵 whose elements are 0 or 1.
➢ We adopt 𝑋 when the value of the mask is one and 𝑌 when the value of themask is zero.
➢ 𝑍, the resulting image combining 𝑋 and 𝑌, is computed as follows.

𝒁=𝑩⊙𝑿+ 𝟏−𝑩 ⊙𝒀=
𝒁 ∈ ℝ𝐻×𝑊×3+⊙

𝑩 ∈ 0, 1 𝐻×𝑊×3

𝑿 ∈ ℝ𝐻×𝑊×3⊙
𝟏−𝑩

𝒀 ∈ ℝ𝐻×𝑊×3

Solution 1: Define 𝑩 as a stack of the original 𝑩, making the shape same.

60Specific examples of failures➢ Let 𝑋 and 𝑌 be 3-channel images.
➢ Consider a mask matrix 𝐵 whose elements are 0 or 1.
➢ We adopt 𝑋 when the value of the mask is one and 𝑌 when the value of themask is zero.
➢ 𝑍, the resulting image combining 𝑋 and 𝑌, is computed as follows.

𝒁=𝑩⊙𝑿+ 𝟏−𝑩 ⊙𝒀=
𝒁 ∈ ℝ𝐻×𝑊×3+⊙
𝑩 ∈ 0, 1 𝐻×𝑊

𝑿 ∈ ℝ𝐻×𝑊×3⊙
𝟏−𝑩

𝒀 ∈ ℝ𝐻×𝑊×3

Solution 2: Descript everything per channel, then combine the results.

61

Specific examples of failures➢ Let 𝑋 and 𝑌 be 3-channel images.
➢ Consider a mask matrix 𝐵 whose elements are 0 or 1.
➢ We adopt 𝑋 when the value of the mask is one and 𝑌 when the value of themask is zero.
➢ 𝑍, the resulting image combining 𝑋 and 𝑌, is computed as follows.

𝒁=𝑩⊙𝑿+ 𝟏−𝑩 ⊙𝒀=
𝒁 ∈ ℝ𝐻×𝑊×3+⊙
𝑩 ∈ 0, 1 𝐻×𝑊

𝑿 ∈ ℝ𝐻×𝑊×3

Solution 3: Define ⊙ loosely, e.g.,https://arxiv.org/abs/2311.15994⊙
𝟏−𝑩

𝒀 ∈ ℝ𝐻×𝑊×3

62

Equations➢ Basic notation for variables➢ String➢ Tips for sets
➢ Inputs/outputs of functions➢ Subscript/superscript➢ Don’t write numpy➢ MiscPseudo codes➢ Basic➢ What do you want to express?
➢ Misc63

Misc➢ Don’t write English words in equations➢𝑦 = 𝑠𝑐𝑜𝑟𝑒 𝑥 + 10
➢ This can be interpreted as 𝑠 ∗ 𝑐𝑜𝑟𝑒(𝑥)➢𝑦 = 𝑠 𝑥 + 10
➢ If you’re not 100% confident, don’t use quantifiers (∀, ∃).
➢ If you use variables, please always define and explain them. E.g., if you
write 𝑦 = 𝑎𝑥 + 𝑏, then explain 𝑦, 𝑎, 𝑥, 𝑏.
➢ If it is too difficult to describe what you are trying to explain inmathematical equations, please explain them in writing and figures.
✓
Writing half-wrong equations are terrible.
64Tuple➢ (something like) an ordered-set: e.g., 𝑎 = (10, 20, 30)➢ Similar to a set:
✓ Can contain any elements: e.g., 𝑏 = 1, 2, 3 ⊤ , "a", 25✓ Remember: 𝑓: 𝑰 ↦ (𝑙, 𝒃, 𝛼)This was a tuple➢ But the order is decided:✓ 1, 2, 3 ≠ (2, 1, 3)✓ 1, 2, 3 = 2, 1, 3
➢ Can contain duplicates: 𝑎 = (1, 1, 3)➢ Similar to a vector:✓ 𝒄 = 1, 2, 3 ⊤ vs 𝑑 = 1, 2, 3
➢ But (usually) no mathematical structures:No!
✓ E.g., the addition is not defined: 1, 2, 3 + 4, 5, 6
65

Cheat-sheet
Not-recommend

OK

ReasonWrite a vector as 𝑥

Write a vector as 𝒙

Use a bold font for a vector.

𝒙 = [1, 2, 3]

𝒙 = 1, 2, 3 ⊤Use column-vectors.

Consider 𝐷-dim vector 𝒙

Consider 𝐷-dim vector 𝒙 ∈ ℝ𝐷

Show the domain.

𝑘𝑥𝑖,𝑗Many sub-/superscripts

Don’t use so much.

Hard to understand.

𝑥𝑎𝑖 subscript of subscript

Avoid.

Hard to understand.

𝒙𝒊

𝒙𝑖

Don’t make an index bold.

𝑥𝑖𝑛

𝑥in

Labels should be roman.

𝑠𝑐𝑜𝑟𝑒 𝑥 + 10

𝑠 𝑥 + 10

Don’t use English words.

𝑎 ∈ ℝ3 , 𝑏 ∈ ℝ, then 𝑎 + 𝑏

𝒂 + 𝑏𝟏

Don’t broadcast.

For element-wise product, 𝑨𝑩

𝑨⊙𝑩

Element-wise product is Hadamard product.

Using ∀, ∃ but not 100% confident

Don’t use

You are wrong.

66

Equations➢ Basic notation for variables➢ String➢ Tips for sets
➢ Inputs/outputs of functions➢ Subscript/superscript➢ Don’t write numpy➢ MiscPseudo codes➢ Basic➢ What do you want to express?
➢ Misc67

Pseudo-code: Basic➢ What is pseudo-code?
✓ Describe an algorithm✓ OK to use mathematical equations✓ OK to use data structures✓ Highlight the key idea
✓ Many ways to explain the idea

Kolda and Bader, “Tensor Decompositions and Applications”, SIAM Review, 2009.

Murray+, “Randomized Numerical Linear Algebra : A Perspective on the
Field With an Eye to Software”, arXiv 2023

68

Pseudo-code: Basic➢ What is pseudo-code?
✓ Describe an algorithm✓ OK to use mathematical equations✓ OK to use data structures✓ Highlight the key idea
✓ Many ways to explain the idea

Kolda and Bader, “Tensor Decompositions and Applications”, SIAM Review, 2009.

Inputs / outputs description

Murray+, “Randomized Numerical Linear Algebra : A Perspective on the
Field With an Eye to Software”, arXiv 2023

69

Pseudo-code: Basic➢ What is pseudo-code?
✓ Describe an algorithm✓ OK to use mathematical equations✓ OK to use data structures✓ Highlight the key idea
✓ Many ways to explain the idea
Can run other functions
or pseudo-codes

Kolda and Bader, “Tensor Decompositions and Applications”, SIAM Review, 2009.

Murray+, “Randomized Numerical Linear Algebra : A Perspective on the
Field With an Eye to Software”, arXiv 2023

70

Pseudo-code: Basic➢ What is pseudo-code?
✓ Describe an algorithm✓ OK to use mathematical equations✓ OK to use data structures✓ Highlight the key idea
✓ Many ways to explain the idea

Kolda and Bader, “Tensor Decompositions and Applications”, SIAM Review, 2009.

Comments

Murray+, “Randomized Numerical Linear Algebra : A Perspective on the
Field With an Eye to Software”, arXiv 2023

71

Pseudo-code: Basic➢ What is pseudo-code?
✓ Describe an algorithm✓ OK to use mathematical equations✓ OK to use data structures
Highlight
key idea➢✓Canuse usual thesentences
to represent complex operations.
Many
ways
to explain➢✓
If youthink
it’s hard
to write theyouridea
operations by equations, use sentences.

Kolda and Bader, “Tensor Decompositions and Applications”, SIAM Review, 2009.

Murray+, “Randomized Numerical Linear Algebra : A Perspective on the
Field With an Eye to Software”, arXiv 2023

72

Pseudo-code: Basic
Look
very
different and SVD (similar algorithms) but look very different
CP decomposition➢ ➢Whatis
pseudo-code?
➢ Left: more pseudo-code-ish✓
Describeanalgorithm➢ Right: more like equations (this is actually MATLAB-ish)✓ OK to use mathematical equations✓ OK to use data structures✓ Highlight the key idea
✓ Many ways to explain the idea

Kolda and Bader, “Tensor Decompositions and Applications”, SIAM Review, 2009.

Murray+, “Randomized Numerical Linear Algebra : A Perspective on the
Field With an Eye to Software”, arXiv 2023

73

Pseudo-code: Basic➢ Compared to equations, it’s more like coding.
✓ Assigning operation is usual: 𝑎 ← 𝑎 + 1➢ Fonts✓ \textsc{Clustering}✓ \texttt{Clustering}

Can be used for function names
In Powerpoint, use“Consolas” font. Like this.

➢ Several TeX packages https://www.overleaf.com/learn/latex/Algorithms
https://www.overleaf.com/learn/latex/Algorithms

74

Pseudo-code: Basic➢ Again, consistency is important!
✓
OK: 𝑎 ← 𝑎 + 1 … 𝑏 ← 𝑓 𝑥✓
NO!: 𝑎 ← 𝑎 + 1 … 𝑏 = 𝑓 𝑥➢ You can mix a mathematical way and a coding way𝑎1✓ 𝑥←𝑓 𝜃 𝑑𝜃
‫׬‬
0Pop(𝑣)➢ Don’t write too much! Pseudo-code should be simple.

➢ Several styles
Assuming a row vector➢ 𝒗.push_back(𝑎), Append(𝒗, 𝑎), 𝒗 ← [𝒗|𝑎]➢Again, don’t use italic for function: 𝒗. 𝑝𝑢𝑠ℎ_𝑏𝑎𝑐𝑘(𝑎)75Equations➢ Basic notation for variables➢ String➢ Tips for sets
➢ Inputs/outputs of functions➢ Subscript/superscript➢ Don’t write numpy➢ MiscPseudo codes➢ Basic➢ What do you want to express?
➢ Misc76

What do you want to express?
➢ The design of pseudo-code depends on what you want to express.
➢ Consider std::vector<int> arr in your code

➢ If you use arr to represent a set of integers,✓ You can use a set:
✓ 𝒜 ← ∅ : initialization✓ 𝒜 ← 𝒜 ∪ 𝑥 : add✓ 𝒜 ← 𝒜 ∖ 𝑦 : delete➢ If 𝑂 1 access is important, or use it in a mathematical context,✓ You should use an array (vector)✓ 𝒂 ∈ ℝ𝐷
✓ 𝒂 𝑖 or 𝑎𝑖 : Implies an 𝑂 1 access.

77Case study: Beam search for neighbor search

DiskANN [Subramanya+, NeurIPS 19]

Learning to route [Baranchuk+, ICML 19]

NSG [Cong+, VLDB 19]➢ All papers have totally different pseudo code for thealmost same algorithm➢ Hint: Explicitly state the data structure or not
Full details: https://speakerdeck.com/matsui_528/cvpr23-tutorial-theory-and-applications-of-graph-based-search78

Case study: Beam search for neighbor search
Candidates are stored in
an array

Candidates are stored ina set

DiskANN [Subramanya+, NeurIPS 19]

Learning to route [Baranchuk+, ICML 19]

NSG [Cong+, VLDB 19]

When need to sort, say
Candidates are stored in a
Sort
the
array
explicitly➢ All papers have totallydifferent
pseudocode for the“closest L points”
heap; automatically sorted

almost same algorithm➢ Hint: Explicitly state the data structure or not

Full details: https://speakerdeck.com/matsui_528/cvpr23-tutorial-theory-and-applications-of-graph-based-search

79Case study: Beam search for neighbor search

DiskANN [Subramanya+, NeurIPS 19]

NSG [Cong+, VLDB 19]

Learning to route [Baranchuk+, ICML 19]

Checked items are stored in a set“check” have totally different pseudo code for the➢ JustAll papers
almost same algorithm➢ Hint: Explicitly state the data structure or not
Full details: https://speakerdeck.com/matsui_528/cvpr23-tutorial-theory-and-applications-of-graph-based-search

80Case study: Beam search for neighbor search

DiskANN [Subramanya+, NeurIPS 19]

Learning to route [Baranchuk+, ICML 19]

NSG [Cong+, VLDB 19]

VisitedVisitedare simply
to be “visited”;
implying
an code➢ All item
papershavesaid
totallydifferent
pseudoforitems
the arestored in a set
additional hidden data structure (array)almost same algorithm➢ Hint: Explicitly state the data structure or not

Full details: https://speakerdeck.com/matsui_528/cvpr23-tutorial-theory-and-applications-of-graph-based-search81Case study: Beam search for neighbor search

Termination condition??

DiskANN [Subramanya+, NeurIPS 19]

Learning to route [Baranchuk+, ICML 19]

NSG [Cong+, VLDB 19]➢ All papers have totally different pseudo code for thealmost same algorithm➢ Hint: Explicitly state the data structure or not
Full details: https://speakerdeck.com/matsui_528/cvpr23-tutorial-theory-and-applications-of-graph-based-search82

Case study

M. Douze+, “QuickCSG: Fast Arbitrary Boolean Combinations of N Solids”, arXvi 2017.

83

Case study

Enumeration for a set

Comments

Set update\textsc for a function nameReturning two variables(This is often strange in a usual math,but it’s ok in pseudo-codes)

M. Douze+, “QuickCSG: Fast Arbitrary Boolean Combinations of N Solids”, arXvi 2017.

84

OOP style?

➢ It’s ok to define a class as well
➢ Member variables can be accessed via ausual “.” notation.
➢ But don’t make the thing complex.

Wu+, “Updatable Learned Index with Precise Positions”, VLDB 2021

85

Equations➢ Basic notation for variables➢ String➢ Tips for sets
➢ Inputs/outputs of functions➢ Subscript/superscript➢ Don’t write numpy➢ MiscPseudo codes➢ Basic➢ What do you want to express?
➢ Misc86

Misc➢ Consider what are global variables!
➢ You can use a sentence to describe a difficult concept, e.g.,➢ ℐ ← Identifiers of top 𝐾 smallest values of 𝒙
➢ T ← 𝑁1 × 𝑁2 × 𝑁3 empty arrays of B-Trees.
➢ Intentionally, you can use almost-code style.
➢ Their contribution is it’s easy to implement thealgorithm in PyTotch➢ Complicated idea, such as “detach”, can be
explained in one line.
➢ But be careful! Can future readers understand?
Chen and He, “Exploring Simple Siamese Representation Learning”, CVPR 2021

87

Misc
➢ If you use almost-code style, use the minted package.
➢ https://www.overleaf.com/learn/latex/Code_Highlighting_with_minted

88

Schedule
Date (2024)

Contents

Presented by

Week 1, Apr 10

Introduction. Review of fundamental concepts

Yusuke, Koya, Yuki, Jun

Week 2, Apr 17

Equations and pseudo-codes

Yusuke Matsui

Week 3, Apr 24

Presentation

Koya Narumi

Week 4, May 1

Tables and plots

Yusuke Matsui

Week 5, May 8

Figures

Koya Narumi

Week 6, May 22

VideosKoya Narumi

Week 7, May 29

Invited Talk 1

Dr. Yoshiaki Bando (AIST)

Week 8, June 5

Invited Talk 2

Prof. Katie Seaborn (Tokyo Tech)

Week 9, June 12

GitHub in depth

Yusuke Matsui

Week 10, June 19

Automation of research and research
dissemination (Web, Cloud, CI/CD)

Jun Kato

Week 11, June 26

Research community

Jun Kato

Week 12, July 3

3DCG illustrations

Yuki Koyama

Week 13, July 10

Final presentations-

89