Concurrency - Thread
Introduction
A new abstraction for a single running process.
Switch between threads
Each thread has it own program counter and set of registers
so, each thread has its own stack.
When switching from running thread (T1) to other (T2)
Save the register state of T1
Restore the register state of T2
The address space remains the same
Concurrency Problem
Problem Example:
Thread:
A function runs within the same memory space.
Each thread starts running in a routine call worker() (real pr ...
Virtualizing Memory - Segmentation and Paging
Segmentation
Segment is a contiguous portion of the address space of a particular length.
Different segments: code, stack, heap.
Each segment can be placed in different part of physical memory.
base and bounds exist in each segment
Address Transitionphysical \thinspace address = offset + base
The code segment starts at the virtual address 0 in address space.
Example:
Code Segment: the offset of virtual address 100 is 100 (starts at virtual address 0).
Heap Segment: the offset of virtual ...
Virtualizing Memory - Address Space
Memory Virtualization
Introduction
OS virtualizes its physical memory
OS provides an illusion memory space per each process
Benefit
Ease to use in programming
Memory efficiency in items of time and space
Isolate the processes and OS, protect from errant accesses of other processes
Multiprogramming and Time Sharing
Load multiple processes in memory
execute one process for a while
switch processes between them in the memory
increase utilization and efficiency
But it causes an important ...
Python - Bayesian Network
Bayesian Network in pgmpy
Import modules 123456import pandas as pdimport networkx as nximport matplotlib.pyplot as pltfrom pgmpy.models import BayesianNetworkfrom pgmpy.factors.discrete.CPD import TabularCPDfrom pgmpy.inference import VariableElimination
Construct the Bayesian Network 1234567891011student_model = BayesianNetwork([ ("A", "C"), ("B", "C"), ("C", "D"), ("C", "E")])# Plot the networknx.dra ...
Virtualizing CPU - Scheduling
IntroductionAssumptions
Each job runs for same among of time.
All jobs arrive at the same time.
All jobs only use the CPU (i.e., no I/O operations).
The running time of each job is known.
Scheduling Metrics
Performance Metric: Turnaround Time (往返時間)
The time at which the job completes minus the time at which the job arrived in the system.T_{turnaround} = T_{completion} - T_{arrival}
Another Metric: Fairness
New Metric: Response Time
The time from when the job arrives to the first time it i ...
Virtualizing CPU
Introduction
Process is a running program, which includes:
Memory (address space)
Instructions
Data sections
Registers
Program counter
Stack pointer
Process API
Create
create a new process to run a program
Destory
halt a runaway process
Wait
wait for a process to stop running
Miscellaneous Control
some kind of method to suspend a process and then resume it (暫停然後恢復)
Status
get some status information about a process
Process Creation
Load a program code into memory, then bui ...
I/O Devices & Storage
I/O System Architecture
Buses
Data paths that used to communicate information with the CPU(s), RAM and I/O Devices.
CPU is attached to the main memory of the system via a memory bus.
Some devices are connected to the system via a general I/O bus.
I/O Bus
data path that connects CPU to I/O Devices.
I/O Device is connected to I/O bus by three hardware components:
I/O ports
interfaces
device controllers
Canonical Device
Hardware Interface
Allows the system software to control its operatio ...
Persistence
Overall Organization
On-Disk Organization
a series of blocks (e.g. size of each block is 4KB).
the blocks are addressed from 0 to N-1.
File System Organization
Metadata Region: tracks data and file system information
Inode Table: the collection of all inodes
There are 3 to 7 blocks for inode tables and each inode size is 256 bytes.
The file system can contain $ \frac{4 \cdot 7 \cdot 1024}{256} $ = 80 inodes (i.e. maximum number of files).
Bitmap: to track whether inodes or data blocks a ...
Python - Regression
Linear Regression Curve
Import modules 1234567import numpy as npimport pandas as pdimport matplotlib.pyplot as pltfrom statistics import variancefrom sklearn.metrics import mean_squared_errornp.set_printoptions(suppress=True)
Import data through pandas 1234567train_data = pd.read_csv("train_data.csv")X_train = np.array(train_data['x'].tolist())y_train = np.array(train_data['y'].tolist())test_data = pd.read_csv("test_data.csv")X_test = test_data['x& ...
Python - ROC Curve
ROC Curve Plotter
Import modules
Using sklearn to plot the ROC Curve123import numpy as npfrom sklearn.metrics import accuracy_score, confusion_matrix, roc_auc_score, roc_curveimport matplotlib.pyplot as plt
Plot curve
get the false positive rate, true positive rate and thresholds by inputting the passing coordinates.123456789101112# Get the require elementsfpr, tpr, thresholds = roc_curve([0,1,0,1,0,1], [0.56, 0.61, 0.43, 0.78, 0.12, 0.47])# sketch the coordinatesplt.scatter([0, 0, 1/3, 1/3 ...



