Git Product home page Git Product logo

naereen / notebooks Goto Github PK

View Code? Open in Web Editor NEW
123.0 9.0 43.0 33.66 MB

:notebook: A growing collection of Jupyter Notebooks written in Python, OCaml and Julia for science examples, algorithms, visualizations etc

Home Page: https://nbviewer.jupyter.org/github/Naereen/notebooks/

License: MIT License

Jupyter Notebook 94.32% Makefile 0.01% Shell 0.03% OCaml 1.87% Python 3.71% MATLAB 0.01% Julia 0.03% C 0.03%
jupyter-notebooks mybinder ocaml ipython octave bash notebooks python python-3 python-2 agregation mathematics french-education

notebooks's Introduction

This repository hosts a lot of Jupyter Notebooks, covering various subjects. Everything is open-sourced under the MIT License, you can use any of these notebooks for your own teaching activities if you want. Please open an issue, or ask me anything or drop an email if you have any questions, suggestions, or more.

Which languages? Half of the notebooks here are in 🇬🇧 English, and the other half in 🇫🇷 French (surtout pour l'agrégation de mathématiques option informatique, dans ce dossier agreg/), and most use the Python language, or OCaml, and a few notebooks use other languages like Julia, Rust, Java or even Bash, C and Octave!

How to read or use these notebooks?

You can view this repository on nbviewer to read notebooks statically, or read them directly from GitHub.

You can also launch an interactive environment to play with the code by yourself, using one of these platforms:

My use of notebooks - short story since 2015

  • At the beginning (as early as end of 2015!), this repository was only here to host some small experiments, for me to learn how to use the wonderful Jupyter tools correctly. So they were baby notebooks 🍼... Since then, I did a lot of experiments, on all the most important kernels (Python, Julia, but also less standard ones like OCaml, Rust, Java, C, Bash, etc), all the most exciting notebook extensions, and output formats (PDF, script, static HTML, slides, etc). I've kept learning and discovering more awesomeness of the Jupyter environment, and it never stops to amaze me ✨!

  • In the last 5 years (2016-2021), I've used Jupyter notebooks intensively, to teach algorithmics, programming, and (not so theoretical) computer science in general, mainly in 🇫🇷 French. I wrote notebooks to teach introduction to Java in 2020, advanced algorithms using Python in 2019, and a lot for experimenting during my PhD thesis.

  • 🇫🇷 J'ai aussi corrigé tous les textes d'annales de modélisation, en option informatique, pour le concours national de l'agrégation de maths, en utilisant OCaml ou des fois Python ! Ce sont les seuls corrigés de ce type disponibles sur tous les Internets (j'ai cherché partout !), et ils sont dans ce dossier : agreg/. Je compte déplacer ça dans un dossier à part, et bien les nettoyer et mettre à jour, en 2021.

  • I love the Jupyter environment, from the old IPython command line to the recent awesome Jupyter Lab. If you want to discover amazing things, check out: RISE for live slides in a notebook, lolviz and rcviz and tutormagic for nice data structures visualizations in a notebook.

  • In the future, I plan to mostly teach using Jupyter notebooks, using either the regular Python kernel, the OCaml-jupyter kernel for OCaml (and also IJava for Java, this one for C, and more if needed). RISE slides embed a chalk-board mode, more limited in comparison to the amazing TableauNoir.

A partial list of notebooks in this repository

I'm trying to maintain here a list of the notebooks stored in this repository, inspired by the amazing pytudes by Peter Norvig. The links open nbviewer), and the links (on GitHub?) open the notebook to be viewed directly in GitHub (it should work for almost all of them).

🐚 Bash

🐍 Python

I am a passionate user of the Python programming language.

Science

Teaching

Numerical simulations for dice games (:fr: in French)

🎨 Art

art/identicons.png

art/citation_du_roi_Loth_aleatoires.png

Experiments with Python

Experiments with Jupyter

With the C language

With Julia

🐫 OCaml

And more will come... soon! 🚅

made-with-jupyter made-with-python made-with-ocaml made-with-julia


1. How to read these documents?

1.a. View the notebooks statically 📝

1.b. Play with the notebooks dynamically 💥

MyBinder

Anyone can use the mybinder.org website (by clicking on the icon above) to run the notebook in her/his web-browser. You can then play with it as long as you like, for instance by modifying the values or experimenting with the code.

You can also launch an interactive environment to play with the code by yourself, using one of these platforms:

Note: Only the Python kernel is supported on the MyBinder interface!


2. Requirements to run the notebooks locally?

All the requirements can be installed with pip and by running a few python -m ... commands.

Note: if you use Python 3 instead of Python 2, you might have to replace pip and python by pip3 and python3 in the next commands (if both pip and pip3 are installed).

⚠️ I've not updated this section since 2016.

sudo pip install jupyter ipython

It will also install all the dependencies, afterward you should have a jupyter-notebook command (or a jupyter command, to be ran as jupyter notebook) available in your PATH:

$ whereis jupyter-notebook
jupyter-notebook: /usr/local/bin/jupyter-notebook
$ jupyter-notebook --version  # version >= 4 is recommended
4.2.1

2.b. Other kernels (optional):

They are only needed to run the notebooks written for Bash or Octave (or OCaml):

$ bash --version | head -n1
GNU bash, version 4.3.42(1)-release (x86_64-pc-linux-gnu)
  • And then install the kernel bash_kernel with these two commands:
sudo pip install bash_kernel
python -m bash_kernel.install
  • You have to have octave installed (installable with the package manager on major Linux distributions (apt-get, pacman, yum etc), installable with brew or macports on Mac OS, available on Windows through cygwin or natively):
$ octave --version | head -n1
GNU Octave, version 4.0.0
  • Your version of Octave should be installed with gnuplot support (it is usually the case):
$ gnuplot --version | head -n1
gnuplot 5.0 patchlevel 1
  • And then install the kernel bash_kernel with these two commands:
sudo pip install octave_kernel
python -m octave_kernel.install

It is quite easy to install, with opam:

opam install jupyter

I started by using this OCaml kernel called IOCaml. The instructions were not so simple, cf. the tutorial by @andrewray on iocaml's wiki. It was prone to some bugs, and I had to manually implement a script to be able to convert the notebooks to PDF with jupyter-nbconvert --to pdf. Note that I also had to write a custom Exporter for jupyter-nbconvert in order to convert the notebooks to OCaml scripts (.ml).


💁 More information?

📜 License ? GitHub license

All the notebooks in this repository are published under the terms of the MIT License (file LICENSE.txt). © Lilian Besson, 2016-21.

Maintenance Ask Me Anything ! ForTheBadge uses-badges ForTheBadge uses-git ForTheBadge built-with-science

notebooks's People

Contributors

dutc avatar naereen avatar tanu-n-prabhu 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

notebooks's Issues

Write a tiny notebook demonstrating the tiny "ocaml" pip module... it's awesome!

A picture is worth a thousand words:
Capture d’écran_2021-02-22_01-10-51

sudo pip install ocaml

Then you can use basic OCaml expressions and standard library... from IPython or Jupyter notebook with IPython kernel, without having to install OCaml yourself on your laptop!
It's pre-compiled. I don't know what version thought...

  • send an email to the developer to ask him?
  • it's not open-sourced and the file on Pypi only include the .cmi and .so files, so it's hard to know how he obtained this...
  • it would be a great project to show to students studying Python and C and OCaml : this tiny IPython magic makes the link between Python and OCaml (one way) using OCaml compiled as a dynamic extension to CPython 😍 !

Rédiger un petit texte de modélisation sur les posits

Réf: https://www.johndcook.com/blog/2018/04/11/anatomy-of-a-posit-number/ et https://www.johndcook.com/blog/2018/04/14/ieee-vs-posit/ et https://www.johndcook.com/blog/2018/04/15/eight-bit-floating-point/

Ca devrait ressembler à ce texte de 2017 sur l'arithmétique avec les flottants IEEE.

  • Je peux commencer par écrire un petit notebook qui code des trucs,
  • Puis voir comment écrire les questions "programmation" du texte,
  • Et voir ce qu'on peut demander sur un plan théorique !

Implémenter aussi la vérification de numéro IMEI

Combien de numéros de téléphones mobiles français sont premiers ?

En même temps, les probas ne sont pas favorables. (pour les numéros de téléphone premiers)

Alors en fait, environ 5.1% des numéros de téléphones mobiles français (donc entre 0600000000 et 0799999999) sont premiers !

Je croyais avoir un notebook sur ça, hm... non, donc je vais le faire !

Implement a Julia and/or Python and/or OCaml notebook showing the (basic) 4th order Runge-Kutta methods

It could be, again, a good opportunity to write the same (basic) code for a non-trivial algorithm (with visualizations) in different languages.

Tasks:

  • First read and understand the algorithm(s) again (I coded it on my TI-82 back in 2010!),
  • Quickly write a Python version, with nice examples and visualizations → Runge-Kutta_methods_for_ODE_integration_in_Python.ipynb
  • Then write a Julia version with same code and examples,
  • Try to write a (basic) OCaml version also, hopefully with visualizations (not an issue if they only work in the notebook)
  • Benchmark and compare the three implementations (possibly more: using numba or numpy/scipy in Python, using a ode package in Julia, using interpreted vs compiled vs opt-compiled OCaml code, etc)

Do some NLP data analysis on my SMS history?

I did some basic statistics on this data, can I try to use it again and perform some more advanced analysis, like a NLP data analysis?

Examples of question I could ask to this database:

  • I my grammar better than my contacts'?
  • Do I use more text based emoticons like :-) or emojis like 😄?
  • Do I conclude my text with . ? ! or nothing?
  • How is the length of my text messages and their content (?) evolves in the day?

Agreg TP3 : Union-Find add a reference

This PDF contains many details on how to get to the optimized version with O(alpha(n)) version (almost O(1)) for union and find.

I won't take the time to implement this version, but adding a link at the end of that part will suffice.

Classifier des locutions pseudo-latines comme des vraies ou fausses (détecteur de roi Loth)

Idée :

  • A partir d'un corpus de citations latines (e.g., les pages roses d'un gros dictionnaire Larousse), on veut apprendre à distinguer les locutions latines des locutions pas latines du tout.
  • Autre application : un générateur automatique de pseudo citations latines, un roi Loth en quelque sorte... Voir ces citations

Approche :

  • Trouver un corpus de citations latines (cette page
  • Faire du traitement de données et de NLP dans un joli notebook Python,
  • Donner un exemple de x phrases étant des vraies locutions latines (ou ressemblant) et y phrases étant carrément pas latines, et faire apprendre (à un réseau de neurones + NLP ?) à classifier les x comme latines et y comme pas latines,
  • Ou alors, juste générer des locutions aléatoires ? (je peux aussi faire ça avec une chaîne de Markov, cf. markov.py by @jilljenn)

A Python notebook showing a prototype of French keyboard supporting "inclusive writing"

I was discussing with a friend, and realized that I started a few months ago to write, as much as possible, my French text messages using an inclusive writing. For example:

Tu vas voir tes amis ? → Tu vas voir tes ami-e-s ?

Ideally, I would like my keyboard to suggest me words like this.
But I'm not an Android programmer, and I don't have time to learn this (right now).
So instead, I want to write a Python notebook to showcase the following feature:

  • If the keyboard suggests a word, like "amis" above, automatically decide if it's a name that should/could be written in an inclusive form,
  • And for words that can have inclusive form, automatically compute it : "amis" → "ami-e-s".

Warning: there is so many exceptions, like "chevaux" is "cheval" at plurals, but feminine is "jument" so instead of "chevaux-ales" you write "chevaux/juments". Quite hard to be perfect in an automated way.

Rédiger un TP d'intro à SQL en Python ou en OCaml pour les agrégatifs

Add links to open notebooks on a local Basthon notebook

See a link like this:
https://besson.link/Basthon/notebook/?from=../../publis/notebooks/Py_Pi_Day_2017.ipynb
It works!

For most of my notebooks, using Basthon won't work because:

  • I'm using other kernel than IPython: OCaml, C, Java, Rust, Julia, Bash, GNUPlot and even Octave!
  • I'm using IPython magic a lot, like %timeit etc, which are not (yet) supported in Basthon (see https://framagit.org/casatir/basthon-kernel/-/issues/10).
  • I'm using Jupyter notebook extensions, like itikz, lolviz, rcviz, watermark, cython, ipythonblocks, ipywidgets, etc.

But for the "pure Python" notebooks (even using numpy, matplotlib etc), I can use my locally available Basthon notebook (http://notebook.besson.link/ or https://besson.link/Basthon/notebook/) to load a notebook available from the same site.

Rédiger un texte de modélisation sur le jeu Rush Hour

Références

  1. Vidéo présentation Rush hour https://www.youtube.com/watch?v=m_A3ENh2g34
  2. https://stackoverflow.com/questions/2877724/rush-hour-solving-the-game
  3. article sur l'aspect P-SPACE complete et comment faire des portes logiques avec Rush Hour http://groups.csail.mit.edu/mac/users/bob/sliding-blocks.pdf
  4. Plank Puzzle http://clickmazes.com/planks/ixplanks.htm (inventé par une dame passionnée de puzzle).
  5. Ce solveur, https://github.com/fogleman/rush
  6. Ce post de blogue, https://www.michaelfogleman.com/rush/

Tâches

  • Implémenter un solveur brute-force pour le jeu, et un vérificateur de solution,
  • Rédiger une réduction à la main, vérifier que c'est du niveau agrég,
  • (bonus) Implémenter une visualisation interactive d'une solution...
  • Commencer à rédiger un exemple de solution dans un notebook, et s'il y a assez de contenu (je pense), commencer à rédiger un texte type modélisation.

Fix the `send:` rule of Makefile, to always send all the .html/.pdf even if they are git-ignored

When I wrote this new version of CP, I was happy to add --csv-exclude and --exclude=.git and --exclude-from=.gitignore options...

But as a results, the .html and .pdf versions of the notebooks are no longer automatically sent to this folder on my website...
I don't know how to have both a git-safe send rule and an inclusive send rule to send HTML/PDF files.

If I write something like:

send:
        CP ./*.html ./**/*.html ${Szam}publis/notebooks/

then it works for 0-depth files, but for files in sub-directories, they end up on the root directory of the target...

Runge-Kutta and numba

I have a small comment regarding: Runge-Kutta_methods_for_ODE_integration_in_Python
I know, you uploaded the notebook 6 years ago, but I still think it is a nice little resource to play around with. If you change the decorator from @jit to @njit, numba is prevented from going into "python-mode" meaning it cannot fall back to simply not compiling the runge-kutta-method. In this way you can see that you need to also compile pend() and f() with numba because a numba compiled function can only take numba compiled functions as arguments:

Time of solving this ODE for 100 points with odeint method...
143 µs ± 16.4 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each)
Time of solving this ODE for 100 points with rungekutta4_jit method...
66.3 µs ± 2.38 µs per loop (mean ± std. dev. of 7 runs, 10,000 loops each)

If you would add this small comment, I would be really glad, if not, feel free to delete this issue.

Write a small notebook showing Python/Cython code for the efficient inversion-based method to generate samples from a Binomial distribution

I was reading this article [Perturbed-History Exploration in Stochastic Multi-Armed Bandits, by Branislav Kveton, Csaba Szepesvari, Mohammad Ghavamzadeh, Craig Boutilier, 26 Feb 2019, arXiv:1902.10089].

They propose an algorithm, called PHE, to tackle the classical (stationary) Multi-Armed Bandit problem. PHE works by adding $O(t)$ pseudo-rewards at the current time step $t$.
To justify that their idea of adding $t$ samples at each time does not increase the computation time of their proposal (it has to stay $O(1)$ at each time step, to be competitive with other approaches like UCB, klUCB or Thompson Sampling), they give the following explanation.

  1. Their first claim is that generating the sum of $t$ samples from a Bernoulli distribution $B(\frac{1}{2})$ (of mean $1/2$) is equivalent to generating a sample from a Binomial distribution $Bin(t, \frac{1}{2})$. It is obvious by definition, so I agree.
  2. Their second claim is that one can generate this unique sample from a Binomial $Bin(t, \frac{1}{2})$ in a constant time $O(1)$. It is not obvious, and not justified. I disagree.

capture d ecran_2019-02-28_13-33-18

I disagree for their second claim because, up to my knowledge, the best method to generate samples from a non-degenerated Binomial distribution is a method by Luc Devroye (explained in chapter 10 of his book), based on the inversion method (inverse transform sampling), as explained on the Wikipedia page, for instance.

  • I want to write a small Jupyter notebook that implements this method manually, in Python as well as in Cython, to show that it works as well as numpy.random.binomial, and that its computation time does increase (in average) when $t$ increases.
  • I will then write a quick email to the authors. ==> I was wrong!

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.