Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

pooya changes #246

Merged
merged 16 commits into from
Nov 7, 2018
10 changes: 5 additions & 5 deletions rst_files/fundamental_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Arrays, Tuples, Ranges, and Other Fundamental Types
Overview
============================

In Julia, arrays and tuples are the most important data type sfor working with numerical data
In Julia, arrays and tuples are the most important data type for working with numerical data

In this lecture we give more details on

Expand Down Expand Up @@ -400,7 +400,7 @@ An alternative is to call the ``view`` function directly--though it is generally

As with most programming in Julia, it is best to avoid prematurely assuming that ``@views`` will have a significant impact on performance, and stress code clarity above all else

Another important lesson about views is that they **are not** normal, dense arrays
Another important lesson about ``@views`` is that they **are not** normal, dense arrays

.. code-block:: julia

Expand Down Expand Up @@ -941,7 +941,7 @@ Nonetheless the syntax is convenient
Linear Algebra
-------------------

(`See linear algebra documentation <https://docs.julialang.org/en/stable/manual/linear-algebra/>`_)
(`See linear algebra documentation <https://docs.julialang.org/en/v1/stdlib/LinearAlgebra/>`_)


Julia provides some a great deal of additional functionality related to linear operations
Expand Down Expand Up @@ -1020,7 +1020,7 @@ Tuples and Named Tuples

(`See tuples <https://docs.julialang.org/en/v1/manual/functions/#Tuples-1>`_ and `named tuples documentation <https://docs.julialang.org/en/v1/manual/functions/#Named-Tuples-1>`_)

We were introduced to Tuples earlier, which provide high-performance immutable sets of distinct types
We were introduced two Tuples earlier, which provide high-performance immutable sets of distinct types

.. code-block:: julia

Expand Down Expand Up @@ -1233,7 +1233,7 @@ An alternative to ``nothing``, which can be useful and sometimes higher performa

Note that in this case, the return type is ``Float64`` regardless of the input for ``Float64`` input

Keep in mind, though, that this only works if the return type of a function is a ``Float64``
Keep in mind, though, that this only works if the return type of a function is ``Float64``


Exceptions
Expand Down
12 changes: 6 additions & 6 deletions rst_files/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Otherwise, if there are errors when you attempt to use an online Jupyterhub, you
Installing a Pre-built Jupyter Image
======================================

`Docker <https://www.docker.com/>`_ is a technology that you to host a "`virtual <https://en.wikipedia.org/wiki/Operating-system-level_virtualization>`_ " version of a minimal, self-contained operating system on another computer
`Docker <https://www.docker.com/>`_ is a technology that you use to host a "`virtual <https://en.wikipedia.org/wiki/Operating-system-level_virtualization>`_ " version of a minimal, self-contained operating system on another computer

While it is largely used for running code in the cloud and in distributed computing, it is also convenient for using on local computers

Expand All @@ -106,7 +106,7 @@ Open a terminal on OS/X and Linux, or a "Windows PowerShell" terminal on Windows
..
.. Run ``docker version`` in the terminal to check there are no obvious errors

Download the QuantEcon Docker image by running the following in your terminal (this may some time depending on your internet connection)
Download the QuantEcon Docker image by running the following in your terminal (this may take some time depending on your internet connection)

.. code-block:: none

Expand All @@ -122,7 +122,7 @@ After this is finished, first clear any existing volumes and then create a persi
Running in a Local Folder
--------------------------

The Docker image has can exchange files locally (and recursively below in the tree) to where it is run
The Docker image can exchange files locally (and recursively below in the tree) to where it is run

Open a terminal and ``cd`` to the directory you are interested in storing local files

Expand Down Expand Up @@ -394,10 +394,10 @@ Now we ``Shift + Enter`` to produce this
:scale: 70%


Inserting unicode (e.g., Greek letters)
Inserting unicode (e.g. Greek letters)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Julia supports the use of `unicode characters <https://docs.julialang.org/en/release-0.4/manual/unicode-input/>`__
Julia supports the use of `unicode characters <https://docs.julialang.org/en/v1/manual/unicode-input/>`__
such as α and β in your code

Unicode characters can be typed quickly in Jupyter using the `tab` key
Expand All @@ -417,7 +417,7 @@ These shell commands are handled by your default system shell and hence are plat
Package Manager
^^^^^^^^^^^^^^^^

You can enter the package manager prepending a ``]``
You can enter the package manager by prepending a ``]``

For example, ``] st`` will give the the current status of installed pacakges in the current environment

Expand Down
23 changes: 12 additions & 11 deletions rst_files/julia_by_example.rst
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ Let us make this example slightly better by "remembering" that ``randn`` can ret
end
data = generatedata(5)

While better, the looping over the `i` index to square the results is difficult to read
While better, the looping over the ``i`` index to square the results is difficult to read

Instead of looping, we can instead **broadcast** the ``^2`` square function over a vector using a ``.``

Expand Down Expand Up @@ -373,7 +373,7 @@ While broadcasting above superficially looks like vectorizing functions in Matla

The other additional function ``plot!`` adds a graph to the existing plot

This follows a general convention in Julia, where an function which modifies the arguments or a global state has a ``!`` at the end of it the name
This follows a general convention in Julia, where a function which modifies the arguments or a global state has a ``!`` at the end of it the name


A Slightly More Useful Function
Expand Down Expand Up @@ -447,7 +447,7 @@ In Julia these alternative versions of a function are called **methods**
Example: Variations on Fixed-Points
================================================

For our second example, we will start with a simple example of solving a fixed-points
For our second example, we will start with a simple example of determining fixed-points of a function

The goal is to start with code in a matlab style, and move towards a more **Julian** style with high mathematical clarity

Expand Down Expand Up @@ -704,16 +704,16 @@ In particular, we can use the ``Anderson acceleration`` with a memory of 5 itera
p = 1.0
β = 0.9
iv = [0.8]
sol = fixedpoint(v -> p .+ β * v, iv, inplace = false, method = :anderson, m = 3)
sol = fixedpoint(v -> p .+ β * v, iv, inplace = false, method = :anderson, m = 5)
arnavs marked this conversation as resolved.
Show resolved Hide resolved
println("Fixed point = $(sol.zero), and |f(x) - x| = $(norm(f(sol.zero) - sol.zero)) in $(sol.iterations) iterations")

Note that this completes in ``3`` iterations vs ``177`` for the naive fixed point iteration algorithm

Since Anderson iteration is doing more calculations in an iteration, whether it is faster or not would depend on the complexity of the `f` function
Since Anderson iteration is doing more calculations in an iteration, whether it is faster or not would depend on the complexity of the ``f`` function

But this demonstrates the value of keeping the math separate from the algorithm, since by decoupling the mathematical definition of the fixed point from the implementation in :eq:`fixed_point_naive`, we were able to exploit new algorithms for finding a fixed point

The only other change in this function as the move from directly defining ``f(v)`` and using an **anonymous** function
The only other change in this function is the move from directly defining ``f(v)`` and using an **anonymous** function

Similar to anonymous functions in Matlab, and lambda functions in Python, Julia enables the creation of small functions without any names

Expand Down Expand Up @@ -745,7 +745,7 @@ The only change we will need to our model in order to use a different floating p
iv = [BigFloat(0.8)] # higher precision

# otherwise identical
sol = fixedpoint(v -> p .+ β * v, iv, inplace = false, m = 3)
sol = fixedpoint(v -> p .+ β * v, iv, inplace = false, m = 5)
arnavs marked this conversation as resolved.
Show resolved Hide resolved
println("Fixed point = $(sol.zero), and |f(x) - x| = $(norm(f(sol.zero) - sol.zero)) in $(sol.iterations) iterations")

Here, the literal `BigFloat(0.8)` takes the number `0.8` and changes it to an arbitrary precision number
Expand Down Expand Up @@ -781,7 +781,7 @@ This also works without any modifications with the ``fixedpoint`` library functi
iv =[0.8, 2.0, 51.0]
f(v) = p .+ β * v

sol = fixedpoint(v -> p .+ β * v, iv, inplace = false, method = :anderson, m = 3)
sol = fixedpoint(v -> p .+ β * v, iv, inplace = false, method = :anderson, m = 5)
arnavs marked this conversation as resolved.
Show resolved Hide resolved
println("Fixed point = $(sol.zero), and |f(x) - x| = $(norm(f(sol.zero) - sol.zero)) in $(sol.iterations) iterations")

Finally, to demonstrate the importance of composing different libraries, use a ``StaticArrays.jl`` type, which provides an efficient implementation for small arrays and matrices
Expand All @@ -794,7 +794,7 @@ Finally, to demonstrate the importance of composing different libraries, use a `
iv = @SVector [0.8, 2.0, 51.0]
f(v) = p .+ β * v

sol = fixedpoint(v -> p .+ β * v, iv, inplace = false, method = :anderson, m = 3)
sol = fixedpoint(v -> p .+ β * v, iv, inplace = false, method = :anderson, m = 5)
arnavs marked this conversation as resolved.
Show resolved Hide resolved
println("Fixed point = $(sol.zero), and |f(x) - x| = $(norm(f(sol.zero) - sol.zero)) in $(sol.iterations) iterations")

The ``@SVector`` in front of the ``[1.0, 2.0, 0.1]`` is a macro for turning a vector literal into a static vector
Expand Down Expand Up @@ -855,7 +855,7 @@ Your hints are as follows:

* If :math:`U_1,\ldots,U_n` are iid copies of :math:`U`, then, as :math:`n` gets large, the fraction that falls in :math:`B` converges to the probability of landing in :math:`B`

* For a circle, area = π * radius^2
* For a circle, area = π * :mat:`radius^2`


.. _jbe_ex4:
Expand Down Expand Up @@ -1112,7 +1112,8 @@ Exercise 5
Here's one solution

.. code-block:: julia

using Plots
gr(fmt=:png) # setting for easier display in jupyter notebooks
α = 0.9
n = 200
x = zeros(n + 1)
Expand Down
14 changes: 7 additions & 7 deletions rst_files/julia_essentials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ The ``$`` inside of a string is used to interpolate a variable

"x = $x"

With brackets, you can splice the results of expressions into strings as well
With parentheses, you can splice the results of expressions into strings as well

.. code-block:: julia

Expand Down Expand Up @@ -381,7 +381,7 @@ Iterating
One of the most important tasks in computing is stepping through a
sequence of data and performing a given action

Julia's provides neat, flexible tools for iteration as we now discuss
Julia's provides neat and flexible tools for iteration as we now discuss

Iterables
----------------
Expand All @@ -394,7 +394,7 @@ These include sequence data types like arrays

actions = ["surf", "ski"]
for action in actions
println("Charlie don't $action")
println("Charlie doen't $action")
arnavs marked this conversation as resolved.
Show resolved Hide resolved
end


Expand Down Expand Up @@ -548,7 +548,7 @@ As we saw earlier, when testing for equality we use ``==``
x == 2


For "not equal" use ``!=`` or ``≠``
For "not equal" use ``!=`` or ``≠`` (``\ne<TAB>``)

.. code-block:: julia

Expand Down Expand Up @@ -850,7 +850,7 @@ Another place that you may use a ``Ref`` is to fix a function parameter you do n

.. code-block:: julia

f(x, y) = [1, 2, 3] ⋅ x + y
f(x, y) = [1, 2, 3] ⋅ x + y # "⋅" can be typed by \cdot<tab>
f([3, 4, 5], 2) # uses vector as first parameter
f.(Ref([3,4, 5]), [2,3]) # broadcasting over 2nd parameter, fixing first

Expand All @@ -877,7 +877,7 @@ The scope of a variable name determines where it is valid to refer to it, and ho

Think of the scope as having a list of all of the name bindings that variables would be relevant, where different scopes could have the same name mean different things

An obvious place to start is to notice that functions introduce there own local names
An obvious place to start is to notice that functions introduce their own local names

.. code-block:: julia

Expand Down Expand Up @@ -1015,7 +1015,7 @@ For example, if you wanted to calculate a ``(a, b, c)`` from :math:`a = f(x), b
Loops
---------------

The ``for`` and ``while`` loops also introduce a local scope, and you can roughly reason about then the same way you would a function/closure
The ``for`` and ``while`` loops also introduce a local scope, and you can roughly reason about them the same way you would a function/closure

In particular

Expand Down