Giter Club home page Giter Club logo

math-for-programmers's People

Contributors

orlandpm 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

math-for-programmers's Issues

Probable Error in rotate_by functions (missing minus sign).

Hi. In chapter 5 when doing exercise on infer_matrix (exercise 5.1) I didnt receive same basis vectors, when I inferred matrix and when I rotated standard basis manually. The problem is, that I think you are missing the minus sign in your rotate_by functions. See picture.

image

Here is the testing code I did with original functions for rotation, with unchanged sign. And result below shows difference.

%load_ext autoreload
%autoreload 2
%matplotlib qt
import sys
sys.path.append(os.getcwd())
from draw3d import *
from draw2d import *
import math

def length(v):
    return sqrt(sum([coord ** 2 for coord in v]))

def to_polar(vector):
    x, y = vector[0], vector[1]
    angle = math.atan2(y,x)
    return (length(vector), angle)

def to_cartesian(polar_vector):
    length, angle = polar_vector[0], polar_vector[1]
    return (length*math.cos(angle), length*math.sin(angle))

def rotate2d(angle, vector):
    l,a = to_polar(vector)
    return to_cartesian((l, a+angle))

def rotate_y(angle,vector):
    x,y,z = vector
    new_x, new_z = rotate2d(angle, (x,z))
    return new_x, y, new_z

def rotate_y_by(angle):
    def new_function(v):
        return rotate_y(angle,v)
    return new_function

rotate_y_by_90 = rotate_y_by(pi/2)

x = (1,0,0)
y = (0,1,0)
z = (0,0,1)


x_by_y_90 = rotate_y_by_90(x)
y_by_y_90 = rotate_y_by_90(y)
z_by_y_90 = rotate_y_by_90(z)



def infer_matrix(n, transformation):
    def standard_basis_vector(i):
        return tuple(1 if i==j else 0 for j in range(1,n+1))
    standard_basis = [standard_basis_vector(i) for i in range(1,n+1)]
    cols = [transformation(v) for v in standard_basis]
    return tuple(zip(*cols))


infered_x = infer_matrix(3,rotate_y_by_90)[0]
infered_y = infer_matrix(3,rotate_y_by_90)[1]
infered_z = infer_matrix(3,rotate_y_by_90)[2]

draw3d(
    Arrow3D(x, color=cnames['green']),
    Arrow3D(y, color=cnames['blue']),
    Arrow3D(z, color=cnames['purple']),

    Arrow3D(infered_x, color=cnames['lime']),
    Arrow3D(infered_y, color=cnames['aqua']),
    Arrow3D(infered_z, color=cnames['magenta']),
)

# Manual
print("Manual")
print(x_by_y_90)
print(y_by_y_90)
print(z_by_y_90)

# Infered
print("Infered:")
print(infered_x)
print(infered_y)
print(infered_z)

And result:
Manual
(6.123233995736766e-17, 0, 1.0)
(0.0, 1, 0.0)
(-1.0, 0, 1.2246467991473532e-16)
Infered:
(6.123233995736766e-17, 0.0, -1.0)
(0, 1, 0)
(1.0, 0.0, 1.2246467991473532e-16)

After I change the sign, it all matches.

Also here is a source saying that when we do rotation by 90 degrees counterclockwise, we multiply one of the parts by -1, and swap:
https://limnu.com/sketch-easy-90-degree-rotate-vectors/

Is it correct? Thanks

Chapter 3: Exception using Arrow3D

I am unable to run through the examples in the Jupyter notebook file for chapter 3.

matplotlib          3.5.0
matplotlib-inline   0.1.3

Showing the top of the callstack

~/projects/math/venv/lib/python3.9/site-packages/mpl_toolkits/mplot3d/axes3d.py in draw(self, renderer)
    445                                     for axis in self._get_axis_list()) + 1
    446                 collection_zorder = patch_zorder = zorder_offset
--> 447                 for artist in sorted(collections_and_patches,
    448                                      key=do_3d_projection,
    449                                      reverse=True):

~/projects/math/venv/lib/python3.9/site-packages/mpl_toolkits/mplot3d/axes3d.py in do_3d_projection(artist)
    434                     "do_3d_projection() was deprecated in Matplotlib "
    435                     "%(since)s and will be removed %(removal)s.")
--> 436                 return artist.do_3d_projection(renderer)
    437 
    438             collections_and_patches = (

AttributeError: 'FancyArrow3D' object has no attribute 'do_3d_projection'

16.4.3 Exercises: error raised with MLPClassifier predict method

Seems like mlp._predict may be deprecated(?), as the following error is raised when running 16.4.3 (scikit-learn v0.24.2):

AttributeError Traceback (most recent call last)
in
----> 1 mlp._predict(x)[0]

AttributeError: 'MLPClassifier' object has no attribute '_predict'

From scikit-learn, seems like the method to use is predict_proba(x).

So, mlp.predict_proba(x)[0] seems to work correctly.

scikit-learn source

Exercise 3.3

Arrow3D((-1,0,1), (3,0,4) ,color=red) should be Arrow3D((3,0,4), (-1,0,1) ,color=red) ?

Thanks,

Exercise 3.11 No correspondence

Snapshot_for_311_of_Math_for_programmers

There are no correspondence between picture and the text. Impossible to definitely recognize wich letter corresponds to wich vector.

TypeError: Unrecognized object: <draw3d.Points3D object at 0x7f83cdf68a00>

When running the following code from ch03_walkthrough.ipynb
draw3d( Points3D((2,2,2),(1,-2,-2)), Arrow3D((2,2,2)), Arrow3D((1,-2,-2)), Segment3D((2,2,2), (1,-2,-2)) )

The following exception is thrown:
TypeError Traceback (most recent call last)
/media/data/asim/devel/python/math/Math-for-Programmers/Chapter 03/ch03_walkthrough.ipynb Cell 6 line 1
----> 1 draw3d(
2 Points3D((2,2,2),(1,-2,-2)),
3 Arrow3D((2,2,2)),
4 Arrow3D((1,-2,-2)),
5 Segment3D((2,2,2), (1,-2,-2))
6 )

File /media/data/asim/devel/python/math/Math-for-Programmers/Chapter 03/draw3d.py:84, in draw3d(origin, axes, width, save_as, azim, elev, xlim, ylim, zlim, xticks, yticks, zticks, depthshade, *objects)
81 ax = fig.add_subplot(111, projection='3d')
82 ax.view_init(elev=elev,azim=azim)
---> 84 all_vectors = list(extract_vectors_3D(objects))
85 if origin:
86 all_vectors.append((0,0,0))

File /media/data/asim/devel/python/math/Math-for-Programmers/Chapter 03/draw3d.py:76, in extract_vectors_3D(objects)
74 yield object.vector
75 else:
---> 76 raise TypeError("Unrecognized object: {}".format(object))

TypeError: Unrecognized object: <draw3d.Points3D object at 0x7f83cdf68a00>

Add a requirements.txt

At this time, there are multiple failures that can be encountered in the code base due to difference in dependency versions like matplotlib.
A requirements.txt file should be added in the project to list the dependencies and their versions compatible with the code base so users can easily run the examples and exercises.

Exercises already filled out

It seems like the notebooks should serve two purposes. 1. to provide code boilerplate code and be able to follow along and play with the code that has been created in the book. And 2, let the user do the exercises in the context of the existing boilerplate.

For some reason all of the exercises are already solved which takes away much of the advantage of using the notebook. Why aren't there two notebooks? One for following along with the book and solving exercises, and another for seeing the solutions to those exercises?

There is a hidden folder with a copy of the notebook but which have the same name except append the file name with "-checkpoint" for some unexplained reason.

Section 9.3.1 Table Values for Eulars method

In section 9.3.1 "Carrying out Euler's method by hand" an initial table is provided and a walk through for completing the first 3 rows begins. There appears to be a contradiction in the explained vector value for row 2, where we calculate this value for the vector column as (1, 0.4) but the table is completed as an example with the value (1,0) for v(2).

Either the table is incorrect and should appear as

t s(t) v(t) a(t)
0 (0,0) (1,0) (0, 0.2)
2 (2,0) (1, 0.4) (0, 0.2)
4 (0, 0.2)
6 (0, 0.2)
8 (0, 0.2)

Or the table is correct but the discrepancy for the v(2) value should be explained.

Chapter 13 sound not playing.

When I run this cell:

sound = pygame.sndarray.make_sound(arr)
sound.play()

I get this error:

ValueError                                Traceback (most recent call last)
<ipython-input-18-f6cf0bf38cc3> in <module>
----> 1 sound = pygame.sndarray.make_sound(arr)
      2 sound.play()

~/anaconda3/envs/intern/lib/python3.7/site-packages/pygame/sndarray.py in make_sound(array)
     92     global numpysnd
     93     try:
---> 94         return numpysnd.make_sound(array)
     95     except AttributeError:
     96         import pygame._numpysndarray as numpysnd

~/anaconda3/envs/intern/lib/python3.7/site-packages/pygame/_numpysndarray.py in make_sound(array)
     72     """
     73 
---> 74     return mixer.Sound(array=array)

ValueError: Unsupported integer size 8

I am using Python 3.7.9 on Ubuntu 20.04 LTS.

Exercise 2.19 coordinates are incorrect.

On page 47 of the book, mini-project 2.19, solution says the coordinates are:

(2,4), (4,2), (2,4), and (4, -2)

Should be:

(-2,4), (-4,2), (2,4), and (4, -2)

Not sure if this is the right place to submit or not. Is there a public errata anywhere?

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.