added introcs notes

master
Stefan 7 months ago
commit d35875913a

@ -0,0 +1,89 @@
# Creative coding and software languages
**Programming**:
- Processing information is old
- Relevant to many disciplines
---
**Tools used to develop code-based artworks**:
- Programming languages
- Text editors
- IDE
- Compilers / interpreters
- Libraries
- Hardware
---
Code must be **understandable** and **readable** for humans.
<br>
_Programming is an art._
# Creative coding
_A process based on exploration, iteration, reflection and discovery, where code is used as the primary medium to create a wide range of media artifacts._
---
### The AI era:
**AI as a tool:**
- Programming understanding is required
- _Natural language prompts_ are creative tools
**Fundamental elements of generative art**
- Repetition
- Randomness
- Decomposition
- Construction
- Pattern breaking
- Interaction
### Cartesian Coordinates
_Processing_ lang functions:
```processing
/*
* Define basic canvas
* createCanvas(width, height);
*/
createCanvas(400, 400);
```
```processing
/*
* Define a line on a given canvas
* line(x1, y1, x2, y2);
*/
line(1, 0, 4, 5);
```
---
**Basic shapes**:
- Line - `line`
- Rectangle - `rect(x, y, width, heigh)`
- Circle - `circle(x, y, radius)`
- Quadrilateral
- Elipse
- Circle
**Colors**:
- Grayscale: 1byte
| 0 | 32 | 64 | 96 | 128 | 160 | 196 | 255 |
| --- | --- | --- | --- | --- | --- | --- | --- |
**Programming Languages**:
- _GPL_ (General Purpose Programming Language)
- _DSL_ (Domain Specific Languages)
- _Language Workbenches_ (IDE for making languages)

@ -0,0 +1,93 @@
# Introduction to Computer Science
#### > [Jump to Lecture 1](#lecture-1)
Tehnical course, introducing technologies used all across computer science.
* **Professors**: Lin Wang, Balakrishnan Chandrasekaran (working in Networking & Security)
* **Contact**: introcs.vu.nl@gmail.com (rules on Canvas)
#### Goals
1. Understand the basics of CS
2. Learn how to use programming tools more effectively
## Course structure
#### Lectures
(weeks 1-6)
#### Tutorials
(weeks 1-7)
<br>
Week 7 @ *HG-KC07*
#### Exam
**October 19 Thursday, 12:15 - 14:30** @ TenT
## Content
1. Linux & shell
2. Shell scripting
3. Build system and Make
4. Version control + git
5. Working remotely
6. MD + LaTeX
## Assessment
* Quizes **[ 20% ]**
<br> Avg **6.5** on all quizes
<br> Only **1 chance** to submit
* Assignments **[ 30% ]**
<br> Avg **5.5** on each assignment
<br> Avg **6.5** across **all** assignments
<br> **!!! Limited number of attempts: 3**
* Final exam **[ 50% ]**
<br> Min score is **6.0**
<br>
No resit opportunities.
<br>
# Lecture 1
## What are computers about
**Apps:** Web, Apps, Bioinformatics
<br>**Theory:** algorithms and comp. complexity
<br>**Programming and software:** programming languages, compilers, databases
<br>**Coputer systems:** operating systems, networking, distributed systems,
mobiled and embedded systems
<br>**Hardware:** processor, mother board etc...
## Hardware
* Input (i.e peripherals)
* Output (i.e monitor, speaker, printer...)
* Compute (i.e CPU, GPU, FPU - math with decimals)
* Storage (i.e memory ram, disks)
* Networking (i.e ethernet NICs, wifi, bluetooth)
## Computer Systems
#### Operating system
* OS kernel
<br> Manages the hardware resources
<br> Interface for applications to access hardware
* Utilities for UI
#### Computer Networking
* **Forms**: wired, optical, wifi, bluetooth
* **Core concepts**: Ethernet, TCP/IP, switching, routing, congestion, DNS
#### Distributed systems
* Super computers (i.e HPE Frontier)
* Data centers (cloud)
* Peer-to-peer systems (i.e blockchain)
#### Mobile and Embedded systems
* Small devices (i.e microcontrollers, RespberryPi)
* Cyber-physical systems (CPS), Internet-of-Things (IoT)
## Theoretical computer science
### Algorithms and computation complexity
* Judges how hard a problem is
* Big O notation
* Turing machine, P vs NP, graph theory ...

@ -0,0 +1,98 @@
# Operating systems
An operating system is **system software** that manages computer hardware,
software resources and provides common services for computer programs
* The operating system takes care of managing hardware by displaying a user
interface via shell or GUI
# History of computers
### First computer design in the word - Analytical engine
* Purely mechanical and intended to do math
* Supposed to be made of brass & steam powered
* *Difference Engine* ->
computing values of polynomial functions fell through
### First programmable computer - ENIAC
* 1945
### First programmer - Ada Lovelace
* 1815 - 1852
* Diagram for an algorithm to calculate a sequence of Bernoulli numbers,
intended to be carried out by the *Analyitical Engine*
### First generation
* 1945 - 1955
* **Technology**: vacuum tubes
* Programming: switches
* Programming languages: machine code
* Tasks: tables of sin, cosin, log
* **No OS**
### Second generatiin
* 1955 - 1965
* **Technology**: transistors
* Programming: punchcards
* Language: *FORTRAN*, Assembly
* Tasks: scientific computing
* Computer: mainframes
* OS: batch systems
<br>
At this time universities starting using and buying computers
### Third generation
* **Technology**: integrated circuits (ICs)
* Programming: punchcards
* Language: *FORTRAN*, Assembly
* Tasks: scientific + **commercial**
* Computers: **IBM 360**, DEC PDPs
* OS: multiprogramming / time-sharing, spooling
<br>
Example OSes: MULTICS (father of all modern OSes), **UNIX (System V, BSD)**
<br>
*There is no reason people would want a computer at home*
#### Multics
[Time-sharing OS](https://github.com/BAN-AI-Multics) developed for mainframes (1963 - 1969)
* MIT, GE & Bell Labs
* Overdesigned and overbuilt
#### UNIX
* Originally called *Unics*
* Influenced most modern OSes
* Designed by Ken Thompson, Dennis Ritchie
* Rewritten in C (1973), originally in ASM
* C lang (created in 1970s)
**UNIX PHILOSOPHY**: *Build lots of **small** tools, each of which does
**exactly one thing well**, but which can be combined to do more powerful
things*
<br> KISS - Keep It Stupid Simple
### Fourth generation (1980 - present)
* **Technology**: Very large scale integration
* Programming: high-level lang
* Lang: C/C++, Java, Python etc...
# Linux
### Shell
A computer program that interprets your commands and sends them to the OS
* CLI: a text-based interface for interacting with the Shell
* Variants: **sh**, **bash**, **csh**, **zsh**, **fish**
### Commands
* `$ which BINARY_PATH` - path to runnable binary
* `$ pwd` - print working directory
* `$ env` - list all environment variables
* `$ echo` - print
* `$ ls` - list files in directory
* `$ touch` - create empty file
* `$ cat` - concats files
* `$ cp` - copy
* `$ mv` - move
* `$ wc` - word count
* `$ grep` - regex matcher magic

@ -0,0 +1,58 @@
# What AI errors could tell you about bias & inclusivity
- Ai detects **99%** of patients at risk and **99%** of risk-free patients
# When it detects a petient at risk, what are the chances of error?
Table of contents:
| TP | TN | FP | FN |
| ------------- | ------------- | -------------- | -------------- |
| True positive | True negative | False positive | False negative |
| \* | Actually possitive | Actually negative |
| ------------------- | ------------------ | ----------------- |
| Classfied Positive | True Positive | False Positive |
| Classified Negative | False Negative | True Negative |
## Beware of precision
If class proportions vary, precision varies.
$$ Precision = {TP \over TP+FP} $$
## Beware of accuracy
Large errors may remain undetected
$$
Accuracy = { TP + TN \over TP + TN + FP + FN }
$$
<br>
$$
TP Rate = { TP \over TP + FN }
$$
# Tuning errors
## Tuning classification errors
**Test sets** contain examples of correct classifications, to measure errors.
- Making use of a data score to balance errors between classes - **tuning parameters**
- Needs to use a **treshold**
- Often there is a tradeoff to be made in order to adjust the results
## Visualising errors
- Roc curves
- Confusion Matrix
- Classes for multiclass
## Global error rates
- Assigning **risk scors** to different people
- Github visualisation: [click](https://github.com/pyladiesams/classification-bias-beginner-apr2021)
- Errors randomly vary. We can draw confience intervals to show ranges of error to expect in practice

@ -0,0 +1,169 @@
# Shell
## sort
- Start with the 3rd column, then the 2nd column, then the 1st column
<br>
`sort -t',' -k3,3 -k1,1 -k2,2 columns.txt`
- `-v` - verbose
## uniq
Deletes duplicates
## tr
Convert what is in the first set to what is in the second test
## Sed
Replace regex strings
<br>
`sed "s/i/*/` - Replaces all _i_ with _\*_
`sed -i $OPT /path/to/file` - replace in file
# Module 2 - Shell text wrangling
**Table of contents**:
- Combine commands with _redirection_
- Declare complex patterns with regular expressions (_regex_)
- Data manipulation with redirection and regex
## Redirection
1. Reading from files `FILE -> SHELL`
2. Writing to files `SHELL -> FILE`
3. Piping between commands `SHELL -> SHELL`
## I/O in Unix
- Standard input `/dev/stdin`
- Standard output `/dev/stdout`
- Standard error `/dev/stderr`
## Ways to redirect input
1. Redirecting input with `<`
<br>`$ cat < alpha.txt`
<br>`$ uniq < alpha.txt`
<br>`$ tr 'a-z' 'A-Z' < alpha.txt`
2. Redirecting input with `>`
<br>`$ echo 'Hello, world!' > hello.txt`
<br>_Appending_ can be done with `>>`
<br>`$ echo 'Some other text' >> hello.txt`
<br>`$ cat > alpha.txt` - _fancy (kek)_ text editor
3. Redirecting **normal output** and **errors**
- **Normal output**: `1>` (`1>` equivalent to `>`)
- **Error output**: `2>`
<br>`$echo 'Hello world' 1>output.txt 2>error.txt`
4. Redirecting output and error to the same file
- Using: `> file.txt 2>&1`
- `&>` is the simpler **equivalent**
<br>`$ echo 'Hello, world! > file.txt 2>&1`
<br>`$ cat /dev/null` - empty _black hole_ file
<br>`$ wc file.txt 2>/dev/null` - redirects errors to `/dev/null`
## Piping between commands
Takes the **output** from one command and redirects it to the **input** of another command
##### !!! IMPORTANT
Commands that are called using `|` run **concurrently**! They are separated on different processes and the shell picks which command should start first
<br>**Example:**
```bash
$ cat hello.txt | sort
```
## RegEx
- `.` - any single character
- `[abc]` - any character inside []
- `[a-z]` - any character in range a-z
- `[^a-z]` - any character not in range a-z
- `(a|b)` - either a or b
**Quantifiers**:
- `*` means we want 0 or more characters of the specified kind
- `+` 1 or more characters of the specified kind
- `?` exactly 0 or 1 characters of the specified kind
- `{X}` means we want exactly **X characters** of the specified kind
- `{X,Y}` means we want **X to Y** characters of the specified kind
**Anchors**:
- `^` specifies the start of the line
- `$` specifies the end of the line
**Example:**
<br>`[a-zA-Z0-9\.-+-%_]+@([a-zA-Z]+\.)+[a-z]{2,4}`
## Data manipulation
- `grep 'REGEX' file_name` - basic regular expression (BRE)
- `grep -E 'REGEX' file_name` - extended regular expression (ERE)
- **!!!** `\b` - search for word boundary
## RegEx with sed
- `sed -E 's/REGEX/SUBSTITUTION/FLAGS'`
- `sed` can use capture groups
- `$ sed -E 's/\bmo\b/mom/g`
- `$ sed 's/[aeiou]/***/g`
- `$ sed 's/(capture group 1)(capture group 2)/**\1***\2/g`
- `$ echo "nicer" | sed -E "s/([^aeiou])([a-z]+)([^aeiou])/\1****\3/g"` - run this :)
## Awk
`$ awk -F "\t" '$2>$3 {print $1}' log.txt`
- `-F` - use tab `\t`
- `$2>$3` - **pattern**: second field is larger than 23
- `{print $1}` - **action**: print the first field
- `file.txt` - input file
**Binary operators**:
- `+` addition
- `-` subtraction
- `*` manipulation
- `/` division
**Conditional expressions**:
- `==` is equal
- all rest like C++
**RegEx**:
- `~` matches
- `!~` does not match
**Boolean operators**:
- `&&` and
- `||` or
- `!` not
**Others**:
- `$0` full record
- `$1` specify field 1
- `FS` input field separator
- `OFS` output field separator
- `NF` number of fields
- `NR` number of records
**Example**:
<br>`$ awk -F "\t" '$0 !~ /^[A#]/ && $3 == "udp" && $2 > 22 {print $1}' log.txt`

@ -0,0 +1,231 @@
# Bash scripting part 2
# Loops
```bash
#!/usr/bin/env bash
for VAR in {1..5}
do
echo "VAR is set to $VAR"
done
```
```bash
#!/usr/bin/env bash
for VAR in 1 2 3 4 5
do
echo "VAR is set to $VAR"
done
```
Wildcard `*`
```bash
for VAR in 1 * 2 bye
do
echo "VAR is set to $VAR"
done
```
```bash
for VAR in 1*2 bye
do
echo "VAR is set to $VAR"
done
```
Similar to C loops:
```bash
for (( i = 1; i <= input; ++i ))
do
echo "VAR IS SET TO $i"
done
```
# While loops
General syntax:
```bash
#!/usr/bin/env bash
while [ CONDITION ]
do
# Do something
done
```
Example:
```bash
#!/usr/bin/env/bash
num=0
while [ $num -lt 50 ] # num < 50
do
echo $num
num=$(( num + 1 ))
done
```
Always evaluates to true (while true):
<br>Exit with `break` keyword
```bash
#!/usr/bin/env bash
read input
while:
do
if [[ "$input" = "bye" ]]; then
then
echo "Byebye"
break
fi
read input
done
```
```bash
#!/usr/bin/env bash
read input
while [[ "$input" = "hi" ]]
do
if [[ "$input" = "bye" ]]; then
then
echo "Byebye"
continue
fi
read input
done
```
# Arguments and functions
`$ bash large_number.sh 101 102`
<br> large_number.sh -> arg0 `$0`
<br> 101 -> arg1 `$1`
<br> 102 -> arg2 `$2`
```bash
#!/bin/bash
num1=$1 # Argument 1
num2=$2 # Argument 2
if [ num1 -gt num2 ];
then
echo $num1
else
echo $num2
fi
```
### Useful args
- `$0` -> name of the script
- `$@` -> all aruments
- `$#` -> number of arguments
- `$?` -> return code of the previous command
- `$$` -> PID of the current command
- `!!` -> entire last command with arguments
- `$_` -> last argument of last command
# Functions
Variable scope:
```bash
#!/bin/bash
# define a user function
make_and_enter() {
mkdir -p "$1"
cd "$1"
}
make_and_enter new_folder
```
**USEFUL NOTE**: Scopes in bash are `inline`, functions do not create their one scopes, therefore variables are kept between functions.
<br> However, if a function is _piped_, a new shell is created to execute the command. Creating a new shell does not preserve variables, as a new shell creates a new scope.
<br> **Scopes** in bash are defined by different shells running concurrently.
### Return values
Return values are noted as **exit codes**, which allow the user to verify the success or failure of a previous command.
<br>In bash, a return value of 0 means **success**. A return value other than 0 (1-255) suggests that an error occured.
- `$?` -> Return value of previous command
- `true` -> command that does nothing except return an exit status of 0
- `false` -> command that does nothing except return an exit status of 1
```bash
#!/usr/bin/env bash
cat my_file 1>/dev/null 2>&1
if [ $? -ne 0 ];
then
echo "File exists"
else
echo "File does not exist"
fi
```
### Testing command validity - another approach
```bash
cat my_file &>/dev/null && echo "File exists"
cat my_file &>/dev/null || echo "File does not exist"
```
# Command substitution
Two ways:
1. $(command)
2. \`command\`
# Arrays
```bash
#!/bin/bash
# define an array
odd_num=(2 4 6 8 10 12)
# retrieve first element
${odd_num[0]}
# append new elements
odd_num+=(2 14)
```
# Awk advanced
## Control flows in `awk`
```
CS,30,1
EE,40,2
AI,35,1
```
```awk
#!/usr/bin/env bash
awk `
BEGIN { FS =","; count=0; total=-0}
$1 == subject { count++; total += $2 }
END { if (count == 0) {print "No entry"}
else { average = total / count
print "Average: ", average
}
}
subject="$1" record.txt
`
```
Loading…
Cancel
Save