GithubHelp home page GithubHelp logo

engineerscode / engcomp4_landlinear Goto Github PK

View Code? Open in Web Editor NEW
112.0 10.0 72.0 18.07 MB

Using computational thinking to get deep insights on the foundations of linear algebra

Home Page: http://go.gwu.edu/engcomp4

Jupyter Notebook 99.58% Python 0.36% CSS 0.06%
python jupyter engineering-computations linear-algebra

engcomp4_landlinear's Introduction

Engineering Computations Module 4

Engineering Computations is a collection of stackable learning modules, flexible for adoption in different situations. It aims to develop computational skills for students in engineering, but it can also be used by students in other science majors. The course uses the Python programming language and the Jupyter open-source tools for interactive computing.

Module 4: Land on vector spaces

Practical Linear algebra with Python.

Pre-requisite: learning module EngComp 1 of our collection.

This learning module re-imagines the teaching of linear algebra with a visually rich, intuitive approach, enabled by computing with Python. We disregard all the rules-based, memorization-heavy instruction of typical (undergraduate) courses in linear algebra. Instead, we rely on visuals to elucidate the core concepts, and on computational thinking for applying those concepts to useful settings.

Get an interactive session in MyBinder.org with these course materials by clicking on the button below. Select the folder notebooks_en to access the lessons of this course as fully executable Jupyter notebooks.

Binder

Lesson 1: Transform all the vectors

What is a vector? The physicist's view versus the computer scientist's view. Fundamental vector operations: visualizing vector addition and multiplication by a scalar. Intuitive presentation of basis vectors, linear combination and span. What is a matrix? A matrix as a linear transformation mapping a vector in one space, to another space. Visualizing linear transformations. Matrix-vector multiplication: a linear combination of the matrix columns. Some special transformations: rotation, shear, scaling. Matrix-matrix multiplication: a composition of two linear transformations. Idea of inverse of a matrix as a transformation that takes vectors back to where they came from.

Lesson 2: The matrix is everywhere

A matrix is a linear transformation… visualize it. Norm of a vector. A matrix maps a circle to an ellipse… visualize it. A vector that doesn't change direction after a linear transformation is an eigenvector of the matrix. A matrix is a system of equations… visualize it (row perspective). Inconsistent and underdetermined systems. A matrix is a change of basis… visualize it. An inverse of that matrix will change the vector's coordinates back to the original basis. Matrices in three-dimensional space: linear transformations in 3D; 3D systems of linear equations; dimension and rank. Visualize the transformations of rank-deficient matrices.

Lesson 3: Eigenvectors for the win

Geometry of eigendecomposition. Eigenvectors revisited: a matrix transforms a circle to an ellipse, whose semimajor and semiminor axes align with the eigenvectors. Composition of scaling transformation and a rotation transformation: not enough! Complete the composition. Symmetric matrices, orthogonal eigenvectors. Eigendecomposition in general. Diagonalizable matrices. Similar matrices. Eigendecomposition is similarity via a change of basis. Compute eigenthings in Python, using NumPy or SymPy. Eigenvalues in ecology: matrix population models. Markov chains. PageRank algorithm.

Lesson 4: Stick to the essentials: SVD

Geometrical interpretation of singular value decomposition (SVD). While eigendecomposition is a combination of change of basis and stretching, SVD is a combination of rotation and stretching, which can be treated as a generalization of eigendecomposition. Example: SVD in image compression. A 2D image can be represented as an array where each pixel is an element of the array. By applying SVD and dropping smaller singular values, we can reconstruct the original image at a lower computational and memory cost. Non-square matrices: SVD in general; pseudo-inverse. Application to linear least squares; linear regression with SVD.

Install the Dependencies

The notebooks are compatible with Python version 3.5 or later, all packages required are listed in environment.yml and requirements.txt. Pick any option below to install the depencies:

Create a conda environment

Use environment.yml to create a conda environment:

conda env create -f environment.yml

This creates a conda environment named "landlinear". For conda 4.6 and later versions, activate this environment with

conda activate landlinear

For conda version prior to 4.6, run source activate landlinear on Linux and MacOS, activate landlinear on Windows.

Install with conda

conda install matplotlib numpy scipy jupyter imageio ipywidgets

Install with pip

Install the packages using requirements.txt for pip:

pip install -r requirements.txt

Check Installation

Run the script check_install.py to check whether the required packages are installed correctly:

python check_install.py

engcomp4_landlinear's People

Contributors

asarmakeeva avatar labarba avatar ncclementi avatar tingyu66 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

engcomp4_landlinear's Issues

plot_helper.py outdated for JupyterLab

Trying to run a plot command from plot_helper.py in a recent installation (JupyterLab) gives the error:

Javascript Error: Can't find variable: IPython

This typically occurs when trying to use an IPython-specific feature or functionality in a JupyterLab environment where IPython is not directly accessible.

In JupyterLab, the underlying architecture and the way it interacts with JavaScript have changed compared to the classic Jupyter Notebook interface. IPython, which provides the interactive computing environment in Jupyter Notebook, is not directly available in JupyterLab in the same way.

TO DO: plot_helper.py needs to be updated to be compatible with JupyterLab's architecture.

@tingyu66 — If you have some hints on where updates are needed in the script, let me know!

Comments on lesson 1 and 2

@tingyu66 and @labarba here are my comments on the lessons so far.

General comments:

  • The students will have to download the helpers that Tingyu wrote. There
    should be instructions on how to download and import this module, where to
    locate it and explain the sys path append.
    Do we want students to do from plot_helper import *, why not
    import plot_helper as ph and access the functions by doing for example
    ph.plotvector()? This way aligns more with what they are used to
    module.function()

  • In all the 2d plots, the grid is plotted on top of the arrows, that doesn't
    look good. You cna pick an alpha or plotted on the back.

  • I think that all the Try it! should be exercises, otherwise sound like it's
    optional.

01 Transform all the vectors (it is quite long)

  • "This is the first lesson in the learning module titled "Land on Vectors
    Spaces", teaching practical linear algebra with Python"

  • The part that says "teaching practical linear..." puts the attention on the
    teaching, shouldn't be on the learning? Specially for those self-learners that
    will find the material online. I would re-write that sentence:
    "This is the first lesson in the module titled "Land on Vectors Spaces",
    learning practical linear algebra with Python"

  • Try it! before fundamental vectors operations, it says "create a list of
    vectors (either as tuples of coordinates, or as NumPy arrays" we haven't
    defined what is a tuple, and if they use a NumPy array it's not clear what
    should be the syntax.

You can recommend them to use ?plot_vector for guidance, although those
docstrings should be improved, specially the description of tails, it's not
clear if it's a list or what data structure.

tails: tail's coordinates of each vector
  • Fundamental vector operations:

"Two operations are the foundation of everything:" of everything? I'd say
something like:

"A vector space (or linear space) is a group of vectors with two operations:"

#When plotting vector addition we do:

a = numpy.array((-2,1))
b = numpy.array((1,-3))
origin = numpy.array((0,0))

Why are we using tuples inside the numpy.array() I believe it makes since we
are no changing its values, but we haven't explained this. Until now students
have always seen the square brackets syntax numpy.array([a,b])

  • Scaling vector plot

The grey of the grids in the 2d plots is a bit dark, and in this case looks
like the scaled vector is a vector that starts at the head of the original. I'd
put an alpha on that grey, or a less dark grey.

  • Basis vectors
    "With the ideas of vector addition and multiplication by a scalar fresh in
    your mind, now imagine this." Any horizontal vector

The end of the first sentences sounds weird.

Possible small exercise:
After "For any vector, its components are the scalars we need to multiply the basis vectors by to generate it. For example:"

You can add an exercise that ask to write in the same way the vector [a, b] so they generalize the idea.

  • basis vectors plot: The arrows plot over the axis are really hard to see. I
    think it is because the grid is plotted on top of the arrows.

  • Linear combination and span

# span
vectors = []
i = numpy.array((1,0))
j = numpy.array((0,1))

for _ in range(30): -->  using _ for the iterator, you should explain this!!!
  • Definition: A basis for a vector space is a set of linearly independent
    vectors that span that space.

We haven't defined what is linearly independent (in a set of vectors if no
vector in the set can be defined as a linear combination of others)

  • What's a matrix?

"We can use the NumPy dot() method to multiply the matrix A and the vector
c :" why don't we use @ since the beginning, I think that dot() can be
confused with dot product concept.

  • In the Try it says: "Create a 2×2 matrix of your choosing (as a NumPy array
    of the row list)," I don't understand the parenthesis, what are we trying to
    say?

  • Add "What we've learned" section can be useful.

No comments on lesson 2 in particular.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.