cs410
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # CS410 Homework 5: Linear Algebra & Probability > **Due Date: 10/16/2024** > **Need help?** Remember to check out Edstem and our website for TA assistance. ## Assignment Overview ### Learning Objectives What you will know: * Reinforce your knowledge of linear algebra * Become proficient in introductory NumPy functions * Be able to translate mathematical equations into code What you will be able to do: * develop... * interpret... ## Data Structures & Algorithms ## Tasks ### Latest Version of Topics - MAKE QUESTIONS ABOUT THESE: We need several linear algebra questions on the following subjects: - Invertable Linear Transformations - When you can invert a matrix + how - Projections (for PCA) - Matrix multiplication and dot products and other manipulations of matrices ### Step 1: Written Questions We need 3-4 mathematical writing questions on the above topics. Make these examples extremely applied as to not bore the students! Examples are more fun than "please find the eigenvalue and eigenvectors for this matrix :(" For reference, look at these slides: https://ocw.mit.edu/courses/9-40-introduction-to-neural-computation-spring-2018/23203cb47ede79bfc5c8c6b1ae2774f2_MIT9_40S18_Lec17.pdf add some questions about probability also :::info **Possible ideas** 1.Proving PCA/Explaining PCA -> why do you want to maximize variance? -> How do you maximize variance? -> Can you calculate/formulate the covariance matrix? What is the diagonal? [Refer to this link pages 3-4](https://www.stat.cmu.edu/~cshalizi/uADA/12/lectures/ch18.pdf) 2.smoothness of a fabric physics based eigenvalue explanation problem or stock market explanation 3.[minecraft related image compression pack.png](https://docs.google.com/document/d/1PpZqHWXPLjOsXf_T7uyH4rWuxUMxzBlxvv5gm19P_Z8/edit) 4.Bayesian problems (not strictly bayes rule but using bayesian notations ) ::: ### Question 1: Invertible Linear Transformations **Scenario:** You are developing a cryptographic system where data is encrypted using a linear transformation. The encryption matrix $\mathbf{A} = \begin{pmatrix} 2 & 1 \\ 3 & 2 \end{pmatrix}$ is used to encode data vectors. However, during testing, you need to verify the correctness of the decryption process by recovering the original data. **Task:** 1. Compute the inverse matrix $\mathbf{A}^{-1}$ using both the determinant method and row reduction method. Verify that both methods yield the same result. 2. Given an encoded data vector $\mathbf{b} = \begin{pmatrix} 7 \\ 10 \end{pmatrix}$, use $\mathbf{A}^{-1}$ to decrypt and recover the original data vector $\mathbf{x}$ such that $\mathbf{A} \mathbf{x} = \mathbf{b}$. 3. Now consider that a slight error was introduced during encryption, and the vector became $\mathbf{b}' = \begin{pmatrix} 7.1 \\ 10.2 \end{pmatrix}$. Calculate the impact of this error on the decrypted data vector using $\mathbf{A}^{-1}$. 4. Discuss the significance of the condition number of matrix $\mathbf{A}$ in the context of error propagation during decryption. ### Question 2: Projections for PCA #### Eigenvector refresher: An eigenvector is a special kind of vector in linear algebra. When a matrix acts on an eigenvector, it simply stretches or shrinks the vector but doesn't change its direction. In other words, if you have a square matrix $A$ and a vector $\mathbf{v}$, the vector $\mathbf{v}$ is an eigenvector of $A$ if applying $A$ to $\mathbf{v}$ results in a new vector that is just a scaled version of $\mathbf{v}$. This scaling factor is called the eigenvalue $\lambda$. Mathematically, this relationship is written as: $$ A \mathbf{v} = \lambda \mathbf{v} $$ Here: - $A$ is the matrix. - $\mathbf{v}$ is the eigenvector. - $\lambda$ is the eigenvalue. **Scenario:** You are analyzing a dataset for a robotics project where you must reduce the dimensionality to focus on the most significant movement patterns. After computing the covariance matrix, you find the principal eigenvectors: *Reminder: An eigenvector * $$ \mathbf{v}_1 = \begin{pmatrix} 0.6 \\ 0.8 \end{pmatrix}, \quad \mathbf{v}_2 = \begin{pmatrix} 0.8 \\ -0.6 \end{pmatrix} $$ **Task:** 1. Given a data vector $\mathbf{x} = \begin{pmatrix} 3 \\ 4 \end{pmatrix}$, compute the projection of $\mathbf{x}$ onto the principal eigenvectors $\mathbf{v}_1$ and $\mathbf{v}_2$. 2. Generalize the process by deriving the formula for projecting any vector $\mathbf{y}$ onto an arbitrary eigenvector $\mathbf{v}$. 3. Using the projections onto $\mathbf{v}_1$ and $\mathbf{v}_2$, reconstruct an approximation of the original vector $\mathbf{x}$ in the reduced space and calculate the reconstruction error. 4. If an additional eigenvector $\mathbf{v}_3 = \begin{pmatrix} 1 \\ 0 \end{pmatrix}$ is added, discuss how this would change the projection process and the implications for dimensionality reduction. <!-- ### Question 3: Eigenvalues and Eigenvectors **Scenario:** You are working on a data clustering algorithm for social network analysis, where the adjacency matrix of the network is given by $\mathbf{M} = \begin{pmatrix} 0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0 \end{pmatrix}$. Eigenvalues and eigenvectors of this matrix can help identify community structures and influential individuals. **Task:** 1. Use `numpy.linalg.eig` to compute the eigenvalues and eigenvectors of the matrix $\mathbf{M}$. 2. Manually derive the characteristic polynomial of $\mathbf{M}$, solve for the eigenvalues $\lambda$, and verify them against the results from `numpy.linalg.eig`. 3. For each eigenvalue, find the corresponding eigenvectors by solving the system $(\mathbf{M} - \lambda \mathbf{I}) \mathbf{v} = 0$. Normalize the eigenvectors. 4. Analyze the eigenvectors and explain what they reveal about the network structure, such as the presence of clusters or central nodes. Specifically, interpret the significance of the eigenvector corresponding to the largest eigenvalue. --> ### Question 3: Matrix Multiplication and Manipulations **Scenario:** You are processing an image represented by the matrix $\mathbf{I} = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}$, and you want to apply a series of transformations to enhance specific features. The transformations include applying a filter matrix $\mathbf{F} = \begin{pmatrix} 0 & 1 \\ -1 & 0 \end{pmatrix}$, followed by a scaling operation using a matrix $\mathbf{S} = \begin{pmatrix} 2 & 0 \\ 0 & 2 \end{pmatrix}$. **Task:** 1. Perform the matrix multiplication $\mathbf{I}' = \mathbf{F} \mathbf{I}$ to apply the filter to the image. 2. Apply the scaling transformation to the filtered image by computing $\mathbf{I}'' = \mathbf{S} \mathbf{I}'$. 3. If instead of applying the transformations sequentially, you want to combine them into a single transformation matrix $\mathbf{T}$, derive $\mathbf{T} = \mathbf{S} \mathbf{F}$ and use it to transform the original image matrix $\mathbf{I}$ in one step. 4. Discuss how the order of multiplication affects the final result and what this implies for image processing tasks where multiple transformations are applied. ### Question 4: Naive Bayes To address the challenge of distinguishing between legitimate emails and spam, various techniques have been developed, the first of which was known as a Naive Bayes classifier. Naive Bayes is a probabilistic algorithm commonly used in machine learning for classification tasks, including spam detection. It leverages the probability of observing certain features (such as words or phrases) in different classes (e.g., normal messages versus spam) to make predictions about the class of new instances. In this context, the provided data serves as an example illustrating the application of Naive Bayes in spam email detection. The table presents counts of specific words ("Dear," "Friend," "Lunch," and "Money") in both normal and spam emails. These counts are used to calculate the probabilities of encountering each word in each class, forming the foundation for the Naive Bayes classifier's decision-making process. | | "Dear" | "Friend" | "Lunch" | "Money" | Total | |----------------|--------|----------|---------|---------|-------| | Normal Emails | 8 | 5 | 3 | 1 | 17 | | Spam Emails | 2 | 1 | 0 | 4 | 7 | | Total | 10 | 6 | 3 | 5 | 24 | Naive Bayes is a simple probabilistic classifier based on Bayes' theorem with strong independence assumptions between the features. Here's a quick explanation of how it works using the provided equation for the case with multiple features (our case): $$\text{Pr}(A | B_1, B_2, \ldots, B_n) = \frac{ \prod_{i=1}^n \text{Pr}(B_i|A) \cdot \text{P}(A)}{ \prod_{i=1}^n \text{Pr}(B_i)} \propto \prod_{i=1}^n \text{Pr}(B_i|A) \cdot \text{P}(A)$$ Naive Bayes predicts the class of a given data point by calculating the probabilities of each class given the features and selecting the class with the highest probability. Despite its simplicity and strong assumptions, Naive Bayes often performs well in practice, especially for text classification and spam filtering tasks. 1. Calculate the conditional probability of each word appearing given the email is either normal or spam. 2. Let's say we have just received an email that reads "Dear Friend". Use the Naive Bayes algorithm to calculate the relative probability that the email is normal and spam, then classify the email. 3. You just received another email that reads "Lunch Money Money Money". Do the same process as last time to calculate the relative probability that the email is normal and spam, then classify the email. Notice anything off (Hint: you should get a classification error)? Come up with a method to change the algorithm to avoid this? ### Step 2: Coding Questions Use this DL lab for reference (note: it's in tensorflow, not numpy): https://colab.research.google.com/drive/1mvwO8ELQNjiyIZnY-4RC09G-T9R6h2WA?usp=sharing These need to be something like "given this formula in the handout, implement this in code with numpy" The goal is that they will translate existing equations into numpy so that they will learn the functions and how numpy works. We will also need an introduction to numpy (ex: explain how a list in python is an ArrayList and numpy is an array!) as we are assuming this is the students' first times using this module. It would be helpful to link the docs so they can see what functions to use, but also suggest the most common/helpful functions that you've used. HAVE FUN WITH IT! Suggestion: Implementing gradient descent without using the function call (seems like this would be helpful/very re-usable in the later homeworks and other classes) :::info **Task 1** ::: :::spoiler **Hint: Signature** ::: :::info **Task 2** ::: :::spoiler **Hint: Signature** ::: ## Downloads Please click [here](https://github.com) to download the assignment code. ### Support Code Please click [here](https://github.com) to get the stencil code. It should contain these files: `asssignment.py`, and `local_test.py`. ### Stencil Code :::warning **Reminder:** Your solution should modify the stencil code *only*. You will be penalized for modifying the support code, especially if it interferes with the autograder. ::: ## Submission ### Grading ### Handin Your handin should contain: - all modified files, including comments describing the logic of your algorithmic modifications, and your tests - a README, containing a brief overview of your implementation, and the outcomes of all tests ### Gradescope Submit your assignment via Gradescope. To submit through GitHub, follow these commands: 1. `git add -A` 2. `git commit -m "commit message"` 3. `git push` Now, you are ready to upload your repo to Gradescope. *Tip*: If you are having difficulties submitting through GitHub, you may submit by zipping up your hw folder. ### Rubric > <span style="color: red">will we include a rubric for all assignments with the handout?</span> :::success Congrats on submitting your homework; Steve is proud of you!! ![image](https://hackmd.io/_uploads/B1yxPsk2C.png) ![image](https://hackmd.io/_uploads/S1OQ2aCwA.png) :::

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully