二次元的肥宅科学家们与宇宙物理生物计算机的异世界转生后创建的高级研究所的日常站点 - 代码-Code
type: channel
link: https://anime.bbmi.me/index.php/category/%E4%BB%A3%E7%A0%81-Code/
items: SYSC5108_A3
items: SYSC5108_A2
items: SYSC5401_Assignment 2
items: SYS5405F_A1

SYSC5108_A3
type: item
date: 2025-03-06T23:33:00-05:00
description: SYSC 5108 W25 Assignment 3.pdfSYSC 5108 W25 ssignment 3William Wang101191168Q1From the Beta–Binomial conjugacy principle, a uniform $\theta \sim \text{Beta}(1,1)$ prior combined with the Binomial likelihood (with $x$ successes out of $n$ yields a posterior distribution$$ p(\theta \mid x) = \text{Beta}\bigl(x + 1,\; n - x + 1\bigr). $$Q2(a)Weighted sum = $0.20 \cdot 1 + (-0.10) \cdot 0.2 + 0.25 \cdot 0.5 + 0.05 \cdot 0.7 = 0.34$(b)Threshold ($\theta = 1$) output =$$ \begin{cases} 1 & \text{if } 0.34 \ge 1 \\ 0 & \text{otherwise} \end{cases} $$$$ $$So output = 0.(c)Logistic ($\varphi$) output =$$ \frac{1}{1 + e^{-0.34}} \approx 0.58. $$(d)ReLU output = $\max(0,\,0.34) = 0.34.$Q3(a) Logistic (sigmoid) activationNeuron 3$a_3 = \sigma(z_3)= \tfrac{1}{1 + e^{-(1.0 \times 0.7) + (0.6 \times 0.3) + 0.1 = 0.7 + 0.18 + 0.1}} = \tfrac{1}{1 + e^{-0.98}} \approx 0.73.$Neuron 4$a_4 = \sigma(z_4)= \tfrac{1}{1 + e^{-(0.9 \times 0.7) + (-0.8 \times 0.3) + 0.5 = 0.63 - 0.24 + 0.5 }} = \tfrac{1}{1 + e^{-0.89}} \approx 0.71.$Neuron 5$a_5 = \sigma(z_5) = \tfrac{1}{1 + e^{-(0.3 \times 0.73) + (0.2 \times 0.71) + 0.9 \approx 0.219 + 0.142 + 0.9}} = \tfrac{1}{1 + e^{-1.261}} \approx 0.78.$Neuron 5’s output $\approx 0.78$.(b) ReLU activationNeuron 3$a_3 = \max(0,\,0.98) = 0.98.$Neuron 4$a_4 = \max(0,\,0.89) = 0.89.$Neuron 5$a_5 = \max(0,\,1.372) = 1.372.$Hence, Neuron 5’s output $\approx 1.37$.(c) Filling in the network diagram (ReLU case)Weights and biases :$w_{3,1} = 1.0,\; w_{3,2} = 0.6,\; b_3 = 0.1$$w_{4,1} = 0.9,\; w_{4,2} = -0.8,\; b_4 = 0.5$$w_{5,3} = 0.3,\; w_{5,4} = 0.2,\; b_5 = 0.9$Neuron 3Weighted sum: $z_3 = 1.0 \times 0.7 + 0.6 \times 0.3 + 0.1 = 0.98$Activation: $a_3 = \mathrm{ReLU}(0.98) = 0.98$Neuron 4Weighted sum: $z_4 = 0.9 \times 0.7 + (-0.8) \times 0.3 + 0.5 = 0.89$Activation: $a_4 = \mathrm{ReLU}(0.89) = 0.89$Neuron 5Weighted sum: $z_5 = 0.3 \times a_3 + 0.2 \times a_4 + 0.9 = 1.372$Activation: $a_5 = \mathrm{ReLU}(1.372) = 1.372$Q4(a) Network Output$$ \begin{aligned} &…

SYSC5108_A2
type: item
date: 2025-02-14T03:07:00-05:00
description: Q1Given n independent sample points $ x_i, i = 1, \dots, n $ from a Laplace distribution with PDF$$ f(x) = \frac{\lambda}{2} e^{-\lambda |x|} $$Provide MLE estimators for the parameter $ \lambda $.The log-likelihood for $n$ i.i.d. samples $x_1,\dots,x_n$ from the Laplace distribution$$ f(x)=\frac{\lambda}{2} e^{-\lambda|x|}\space \Rightarrow \space \ell(\lambda) =\sum_{i=1}^n \ln\left(\frac{\lambda}{2}\right) - \lambda\sum_{i=1}^n |x_i| = n \ln(\lambda) - n\ln(2) - \lambda \sum_{i=1}^n |x_i|. $$Differentiate and set to zero:$$ \frac{d\,\ell(\lambda)}{d\lambda} = \frac{n}{\lambda} - \sum_{i=1}^n |x_i| = 0 \quad\Longrightarrow\quad \hat{\lambda} = \frac{n}{\displaystyle \sum_{i=1}^n |x_i|}. $$The second derivative$\frac{d^2\,\ell(\lambda)}{d\lambda^2}=-\frac{n}{\lambda^2}<0$confirms a maximum.Thus, the MLE for $\lambda$ is$$ \boxed{\hat{\lambda} = \frac{n}{\sum_{i=1}^n |x_i|}}. $$Q2Maximum entropy is often used to select an a priori distribution when there is very little information about the RV. Consider the Bernoulli distribution $ p(x) = \begin{cases} p, & x = 1 \\ 1 - p, & x = 0 \\ 0, & \text{otherwise} \end{cases} $. Find its entropy $ H(X) $ and prove analytically that $ H(X) $ achieves its maximum when $ p = \frac{1}{2} $.For a Bernoulli random variable $X$ with $\Pr(X=1)=p$ and $\Pr(X=0)=1-p$, its entropy is$$ H(X)=-p\ln p-(1-p)\ln(1-p). $$Differentiate$$ \frac{d\,H}{dp} = -\ln p - 1 + \ln(1-p) + 1 = \ln\!\bigl(\tfrac{1-p}{p}\bigr) = 0 \quad\Longrightarrow\quad \tfrac{1-p}{p}=1 \quad\Longrightarrow\quad p=\tfrac12. $$Second derivative $ \tfrac{d^2\,H}{dp^2}=-\tfrac{1}{p} - \tfrac{1}{1-p} $ is negative for $0<p<1$, implying a maximum at $p=\tfrac12$.Q3A multivariate logistic regression model has been built to predict the propensity of shoppers to perform a repeat purchase of a free gift that they are given. The input features used by the model are the age of the customer, the socioeconomic band to which the customer belongs (a, b, or c), the average amount of m…

SYSC5401_Assignment 2
type: item
date: 2025-02-11T17:49:00-05:00
description: Assignment2.pdfQuestion 1: The Instrumental Variable ApproachStep 1) InitializationFirst, we define the number of time steps （$N$） along with the coefficients $a_1$ and $a_2$. To introduce noise, we set the standard deviation of white noise corresponding to variances of 4.0 and 9.0. Additionally, we initialize the arrays for the clean system output ($y$), the noisy system output ($y_m$), and the noise vector ($e$).% Simulation parameters N = 400; % Number of time steps a1 = 1.5; % Colored noise coefficient a2 = -0.7; % Colored noise coefficient sigma_e = 3; % Standard deviation of white noise (3 for variance = 9.0) rng(109); %set random seed % Initialize arrays y = zeros(N, 1); ym = zeros(N, 1); u = 2*(randi([0, 1], N, 1))-1; % Random binary input signal e = sigma_e * randn(N, 1); % White noise v = zeros(N, 1); % Initialize colored noiseStep 2) System SimulationFor the simulation, we first apply the clean filter:$$ y(k) = 1.5 y(k-1) - 0.7 y(k-2) + u(k-1) $$Then, we create the white noise vector:$$ e(k) = 2 \cdot \text{randn}(N,1) $$Finally, the actual system output is simulated:$$ y_m(k) = y(k) + e(k) $$We start the simulation from $k=3$ due to dependencies.Matlab Code% System simulation (start from k=3 due to dependencies) for k = 3:N y(k) = 1.5*y(k-1) - 0.7*y(k-2) + u(k-1); ym(k) = y(k) + e(k); % Measurement signal endStep 3) Initial Parameters for IV IterationsTo get the first instrumental solution, we compute the Least Squares (LS) estimate:$$ \theta_{LS} = (\varphi^T \varphi)^{-1} \varphi^T Y $$where $\varphi$ is the design matrix containing the regressors $[y_m(k-1), y_m(k-2), u(k-1)]$ and $Y$ is the output vector $y_m(3), y_m(4), ... y_m(N)$.Matlab Code% Design matrix for noise case Phi_noise_4 = [ym(2:end-1), ym(1:end-2), u(2:end-1)]; Y_noise_4 = ym(3:end); % Design matrix for clean case Phi_clean = [y(2:end-1), y(1:end-2), u(2:end-1)]; Y_clean = y(3:end);From the Matlab output, the LS estimations for clean, noisy (variance $4.0$), and noisy (variance $9.0$)…

SYS5405F_A1
type: item
date: 2024-09-26T03:31:00-05:00
description: import pandas as pd import os # change your path data_path = r'C:\Users\rtgtx\Desktop\SYSC5703\Destination_Prediction_Project' test_data = pd.read_csv(r'C:\Users\rtgtx\Desktop\SYSC5703\Destination_Prediction_Project\test.csv') submission_file_path = r'C:\Users\rtgtx\Desktop\SYSC5703\Destination_Prediction_Project\submission.csv' zone_feature_files_paths = { "Chukyo": os.path.join(data_path, "Zone_features", "Chukyo_zone_feature_area.csv"), "Higashisurugawan": os.path.join(data_path, "Zone_features", "Higashisurugawan_zone_feature_area.csv"), "Kinki": os.path.join(data_path, "Zone_features", "Kinki_zone_feature_area.csv"), "Kyushu": os.path.join(data_path, "Zone_features", "Kyushu_zone_feature_area.csv"), "Tokyo": os.path.join(data_path, "Zone_features", "Tokyo_zone_feature_area.csv") } train_files_paths = { "Chukyo": os.path.join(data_path, "train", "Chukyo.csv"), "Higashisurugawan": os.path.join(data_path, "train", "Higashisurugawan.csv"), "Kyushu": os.path.join(data_path, "train", "Kyushu.csv"), "Tokyo": os.path.join(data_path, "train", "Tokyo.csv") } # Load the data zone_feature_files = {name: pd.read_csv(path) for name, path in zone_feature_files_paths.items()} train_files = {name: pd.read_csv(path) for name, path in train_files_paths.items()} # Missing values def check_missing_values(dataframes): missing_values = {} for name, df in dataframes.items(): missing = df.isnull().sum() missing_values[name] = missing[missing > 0] return missing_values missing_zone_features = check_missing_values(zone_feature_files) missing_train_data = check_missing_values(train_files) missing_zone_features, missing_train_data import pandas as pd from sklearn.model_selection import train_test_split from sklearn.metrics import accuracy_score, confusion_matrix, classification_report from xgboost import XGBClassifier from sklearn.impute import SimpleImputer from sklearn.preprocessing import StandardScaler, LabelEncoder from sklearn.neighbors import KNeighborsClassifier def merge_zone_feat…