├── .DS_Store
├── .gitignore
├── 3DGraphics
├── Manifest.toml
├── Project.toml
└── Untitled.ipynb
├── Algorithms
├── ClosestPair.ipynb
├── DominanceReport.jl
├── ECDFAlgorithm.ipynb
├── Manifest.toml
└── Project.toml
├── Artifacts
├── Artifacts.toml
└── ExampleArtifactsUtils.jl
├── CatLab
├── 1-Catlab.ipynb
├── 1-Programming with Categories.ipynb
├── ACSets.ipynb
├── ACSets2.ipynb
├── Manifest.toml
└── Project.toml
├── CategoryTheory
├── .DS_Store
├── 1 - Types.ipynb
├── 10 - Applicative.ipynb
├── 11 - Monads Revisited.ipynb
├── 11-2 Monads Revisited.ipynb
├── 12 - Monad Parsing.ipynb
├── 12-2 - Monad Parsing.ipynb
├── 13 - MonadPlus.ipynb
├── 13 - Operads.ipynb
├── 14 - Arithmetic Expressions.ipynb
├── 14 - Recursion Schemes.ipynb
├── 15 - Free Monad.ipynb
├── 15 - Nested Datatypes.ipynb
├── 15-3 - Free Monad.ipynb
├── 15.2 - Free Monad.ipynb
├── 16 - Freer Monads.ipynb
├── 2 - Morphisms.ipynb
├── 3 - Functors.ipynb
├── 4 - Natural Transformations.ipynb
├── 5 - Adjunctions.ipynb
├── 6 - Monoids and Monads.ipynb
├── 7 - Algebras, Recursions and Folds.ipynb
├── 7.2 - F-Algebra and F-Coalgebra.ipynb
├── 7.3 - F-CoAlgebra.ipynb
├── 7.4 - Ordered Tree Monad.ipynb
├── 7.5 - Rose Tree.ipynb
├── 8 - Paper Monoids.ipynb
├── 9 - Folds.ipynb
├── CURRENT Marks and Diagrams.ipynb
├── Chapter 14 Nested Data.ipynb
├── Chapter 18 Reactive.ipynb
├── Chapters 1, 2, 3.ipynb
├── Co-Monads.ipynb
├── Currier.jl
├── Do Operator.ipynb
├── Extra - MLStyle ADT.ipynb
├── Extra
│ ├── 1_Vizagrams.ipynb
│ ├── AlgebraCoalgebra.ipynb
│ ├── CategoricalDataBases.ipynb
│ ├── Hylomorphism.ipynb
│ ├── Manifest.toml
│ ├── Project.toml
│ └── StateMonad.ipynb
├── FreerMonads.ipynb
├── Haskell
│ ├── ForestTree.hs
│ ├── FreeMonads.hs
│ ├── FreeMonads2.hs
│ ├── FreeMonads3.hs
│ ├── FreeMonads4.hs
│ ├── FreeMonads5.hs
│ ├── FreeMonads6.hs
│ ├── ListMonad.hs
│ ├── MyModule.hs
│ ├── RoseTree.hs
│ └── TypeDeclaration.hs
├── Manifest.toml
├── Nested Spaces as Monoid.ipynb
├── PatternMatching.ipynb
├── Poly.ipynb
├── Project.toml
├── Untitled.ipynb
├── Untitled1.ipynb
├── Untitled2.ipynb
├── aux_functors.jl
├── freelist.jl
└── old
│ ├── Chapters 1, 2, 3.ipynb
│ ├── Do Operator.ipynb
│ ├── FunctionalProgrammingPackages.ipynb
│ ├── Manifest.toml
│ ├── Project.toml
│ └── README.md
├── DataBases
├── Manifest.toml
├── Project.toml
└── RelationalDataBases.ipynb
├── Diagrams
├── Drawing_SVG.ipynb
├── Envelopes.ipynb
├── Manifest.toml
├── Monoids-Refactor.ipynb
├── Monoids.ipynb
├── Project.toml
└── Untitled.ipynb
├── DiscreteDifferentialGeometry
└── sandbox
│ ├── DifferentialForms.ipynb
│ ├── KForms-Copy1.ipynb
│ ├── KForms.ipynb
│ ├── Manifest.toml
│ ├── Project.toml
│ ├── Untitled.ipynb
│ └── bunny.obj
├── Dispatch-Design
├── Dispatch.ipynb
├── Manifest.toml
└── Project.toml
├── DockerJulia
├── .DS_Store
├── FirstDocker
│ ├── Dockerfile
│ └── hellodocker.jl
├── NotesOnDocker.md
└── SecondDocker
│ ├── Dockerfile
│ ├── README.md
│ ├── app-image-config-input.json
│ ├── create-domain-input.json
│ └── update-domain-input.json
├── FunctionalProgramming
├── I - FP Introduction.ipynb
├── II - FP and Category Theory.ipynb
├── III - FP Patterns.ipynb
├── IV - FP Data Structures.ipynb
├── Manifest.toml
├── Optics.ipynb
├── Project.toml
├── Transducers.ipynb
└── Untitled.ipynb
├── Generative_Art
├── JuliaDevBrasil.ipynb
├── Manifest.toml
├── Project.toml
├── strange-vector.png
└── strange-vector.svg
├── GeometricAlgebra
├── 1 - Introduction.ipynb
├── 10 - Plotting Transformations.ipynb
├── 11 - Plotting CGA Beyond the Basics.ipynb
├── 12 - CGA Summary.ipynb
├── 13 - CGA and Viz.ipynb
├── 2 - Transformations and Versors.ipynb
├── 3 - Other Topics.ipynb
├── 4 - Conformal Geometric Algebra PartI.ipynb
├── 5 - Conformal Geometric Algebra PartII.ipynb
├── 6 - CGA Part III.ipynb
├── 7 - CGA Intersections.ipynb
├── 8 - CGA and Interpolations.ipynb
├── 9 - Plotting CGA Elements.ipynb
├── Checking against Python.ipynb
├── Exercises - CGA.ipynb
├── Homogeneous Model.ipynb
├── Manifest.toml
├── Project.toml
├── Python - visualization-tools.ipynb
├── auxiliary.jl
├── constructions.jl
├── plottingfunctions.jl
├── reflection.png
└── reflection.svg
├── GeometricModeling
├── Curves.ipynb
├── DiscreteGeometry-I.ipynb
├── Harmonic_Map.ipynb
├── Manifest.toml
├── Meshes1.ipynb
├── Meshes2.ipynb
├── Project.toml
└── SplineManifold.ipynb
├── Geospatial
├── Manifest.toml
├── Project.toml
├── Untitled.ipynb
└── data
│ ├── land.shp
│ ├── ne_110m_admin_0_countries.geojson
│ └── ne_110m_land.geojson
├── Graphs
├── Graphs_Tutorial.ipynb
├── Manifest.toml
├── Project.toml
└── data_example.csv
├── HeatMethod
├── HeatMethod.ipynb
├── Manifest.toml
├── Project.toml
└── bunny.obj
├── Julia+Javascript
└── Tutorial_JSServe.ipynb
├── LICENSE
├── LinearAlgebra
├── 1-Basico.ipynb
└── Extra-Performance.ipynb
├── MachineLearning
├── Flux_Tutorial1.ipynb
├── Flux_Tutorial_img1.png
├── Flux_Tutorial_img2.png
├── MLJ.ipynb
├── Manifest.toml
├── Project.toml
└── RecommendationSystem.ipynb
├── Manifest.toml
├── Manifolds
├── 2106.08777.pdf
├── Manifest.toml
├── Manifolds - The Basics.ipynb
├── Project.toml
├── Viz - Manifolds.ipynb
├── boundarysimplex.svg
├── combinatorialmanifold.svg
├── geodesic.svg
├── lengths.svg
├── manifoldplot.jl
├── manifoldplot.svg
├── orientationmanifoldcomb.svg
├── orientationsimplex.svg
└── sphere.obj
├── Maps
├── Manifest.toml
├── Project.toml
├── Untitled.ipynb
└── gmt.history
├── MetaProgramming
├── Intro-Metaprogramming.ipynb
├── Manifest.toml
├── Project.toml
└── Untitled.ipynb
├── NLP
├── CondaPkg.toml
├── Manifest.toml
├── NLP-NonEnglish.ipynb
├── NLP-TextAnalysis.ipynb
├── Project.toml
└── Py_NLP.ipynb
├── OptimalTransport
├── 1DOptimalTransport.ipynb
├── 2DOptimalTransport.ipynb
├── Manifest.toml
├── MultivariateGauss.ipynb
└── Project.toml
├── ParallelComputing
├── Asynchronous.ipynb
└── Multi-Threading.ipynb
├── Parsing XML
├── EzXML.ipynb
├── Manifest.toml
├── Project.toml
└── xml.jl
├── Project.toml
├── README.md
├── Speeding_up_Julia_Precompilation
├── Precompile_DataPackages.ipynb
└── Precompile_Flux.ipynb
├── TDA
├── AbstactAlgebra.ipynb
├── CombinatorialSpaces.ipynb
├── Hodge.ipynb
├── Manifest.toml
├── Metrics.ipynb
├── OSCAR_SimplicialComplexes.ipynb
├── Project.toml
├── Ripserer.ipynb
├── SimplicialComplexes.ipynb
├── Untitled.ipynb
└── tda.ipynb
├── TimeSeries
├── Manifest.toml
├── Project.toml
└── TimeSeriesAnalysis.ipynb
└── Visualizations
├── 1-Makie-Basics.ipynb
├── 1-SVB-Example.ipynb
├── 2-WGLMakie.ipynb
├── MakieTutorial.jl
├── Manifest.toml
├── Project.toml
├── Untitled.ipynb
├── VegaLite.ipynb
├── figure.png
├── figure.svg
├── luxor-drawing-210931_348.svg
└── my-drawing.svg
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/davibarreira/Julia_Tutorials/60c0d8309d0077c4297f9a188e6a947b61ed38ac/.DS_Store
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.ipynb_checkpoints/
2 | *.CondaPkg/
3 | *textcat_demo/
4 | *textcat_docs_issues/
5 |
--------------------------------------------------------------------------------
/3DGraphics/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | MeshCat = "283c5d60-a78f-5afe-a0af-af636b173e11"
3 |
--------------------------------------------------------------------------------
/3DGraphics/Untitled.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "id": "c65ea2ec-0ed6-4837-aea8-dda2a68ae5c3",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Documents/GitHub/Julia_Tutorials/3DGraphics`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg\n",
19 | "Pkg.activate(\".\")"
20 | ]
21 | },
22 | {
23 | "cell_type": "code",
24 | "execution_count": 2,
25 | "id": "33ae1363-e2f1-4908-9fc5-add9b046da5f",
26 | "metadata": {},
27 | "outputs": [],
28 | "source": [
29 | "# Pkg.add(\"MeshCat\")"
30 | ]
31 | },
32 | {
33 | "cell_type": "code",
34 | "execution_count": 3,
35 | "id": "0da94334-360b-45a8-81ee-219422a9ca9a",
36 | "metadata": {},
37 | "outputs": [],
38 | "source": [
39 | "using MeshCat"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": null,
45 | "id": "6776fc0c-3fc8-4266-b4fd-06b7811cac04",
46 | "metadata": {},
47 | "outputs": [],
48 | "source": []
49 | }
50 | ],
51 | "metadata": {
52 | "kernelspec": {
53 | "display_name": "Julia 1.10.2",
54 | "language": "julia",
55 | "name": "julia-1.10"
56 | },
57 | "language_info": {
58 | "file_extension": ".jl",
59 | "mimetype": "application/julia",
60 | "name": "julia",
61 | "version": "1.10.2"
62 | }
63 | },
64 | "nbformat": 4,
65 | "nbformat_minor": 5
66 | }
67 |
--------------------------------------------------------------------------------
/Algorithms/DominanceReport.jl:
--------------------------------------------------------------------------------
1 | using LinearAlgebra
2 | using Random
3 | # using CairoMakie
4 | using Distances
5 | # CairoMakie.activate!(type = "svg")
6 | using StatsBase
7 |
8 |
9 |
10 | # function Merge(y1,y2)
11 | # N1 = length(y1)
12 | # N2 = length(y2)
13 | # N = N1 + N2
14 | # i,j,k,b = 1,1,1,0
15 | # y = zeros(N)
16 | # while i ≤ N1 && j ≤ N2
17 | # if y1[i] ≤ y2[j]
18 | # y[k] = y1[i]
19 | # b = b+1
20 | # i = i+1
21 | # else
22 | # y[k] = y2[j]
23 | # z[y2[j]] = z[y2[j]] + b
24 | # j = j+1
25 | # end
26 | # k = k+1
27 | # end
28 | # if i ≤ N1
29 | # y[k:end] .= y2[k:end]
30 | # end
31 | # end
32 |
33 | function Sort(y)
34 | N = length(y)
35 | if N == 1
36 | return y
37 | else
38 | m = floor(Int,N/2)
39 | y1= Sort(y[1:m])
40 | y2= Sort(y[m+1:N])
41 | # y = Merge(y1,y2)
42 | return y
43 | end
44 | end
45 |
46 | y = [2,4,5,3,1]
47 | Sort(y)
48 | z = zeros(length(y))
--------------------------------------------------------------------------------
/Algorithms/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
3 | Debugger = "31a5f54b-26ea-5ae9-a837-f05ce5417438"
4 | Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
5 | LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
6 | StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
7 |
--------------------------------------------------------------------------------
/Artifacts/Artifacts.toml:
--------------------------------------------------------------------------------
1 | [JuliaMono]
2 | git-tree-sha1 = "75ccf55c84a197ab5a793bdf934fc4561f27ec26"
3 | lazy=true
4 |
5 | [[JuliaMono.download]]
6 | sha256 = "f0a503cec84157b9b1abffa613c1328aaee2159d938da0efef56ab877db2676d"
7 | url = "https://github.com/cormullion/juliamono/releases/download/v0.043/JuliaMono-ttf.tar.gz"
8 |
--------------------------------------------------------------------------------
/Artifacts/ExampleArtifactsUtils.jl:
--------------------------------------------------------------------------------
1 | using ArtifactUtils
2 | using Artifacts
3 |
4 | add_artifact!(
5 | "Artifacts.toml",
6 | "JuliaMono",
7 | "https://github.com/cormullion/juliamono/releases/download/v0.043/JuliaMono-ttf.tar.gz",
8 | force=true,
9 | )
10 |
11 | import Pkg; Pkg.instantiate()
12 |
--------------------------------------------------------------------------------
/CatLab/1-Programming with Categories.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "ff7fa2b2-e73b-43c6-9044-0ee814373b26",
6 | "metadata": {},
7 | "source": [
8 | "# 1 - Programming with Categories\n",
9 | "\n",
10 | "This is the \"applied\" part of Category Theory, focusing on programming."
11 | ]
12 | },
13 | {
14 | "cell_type": "code",
15 | "execution_count": 18,
16 | "id": "85c1fbc7-34e7-41e5-b9f7-a13fca8b6622",
17 | "metadata": {},
18 | "outputs": [
19 | {
20 | "name": "stderr",
21 | "output_type": "stream",
22 | "text": [
23 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/MEGA/EMAp/Mathematical-Short-Notes/Fields/Category-Theory/notebooks`\n"
24 | ]
25 | }
26 | ],
27 | "source": [
28 | "using Pkg\n",
29 | "Pkg.activate(\".\")"
30 | ]
31 | },
32 | {
33 | "cell_type": "markdown",
34 | "id": "f15519e6-7130-43db-b849-a60b4ecf3406",
35 | "metadata": {},
36 | "source": [
37 | "We start be defining the composition operator. This is actually already present in Julia via `\\circ`. But here we'll implement it\n",
38 | "again using the code from Julia's Base.\n",
39 | "\n",
40 | "The implementation relys on function-like objects that are structs that can be called, similar to a function."
41 | ]
42 | },
43 | {
44 | "cell_type": "code",
45 | "execution_count": 19,
46 | "id": "5c030b08-1892-4e58-b1b3-f3aa7e32038f",
47 | "metadata": {},
48 | "outputs": [],
49 | "source": [
50 | "struct Comp{O,I} <: Function\n",
51 | " outer::O\n",
52 | " inner::I\n",
53 | " Comp{O, I}(outer, inner) where {O, I} = new{O, I}(outer, inner)\n",
54 | " Comp(outer, inner) = new{Core.Typeof(outer),Core.Typeof(inner)}(outer, inner)\n",
55 | "end\n",
56 | "\n",
57 | "function (c::Comp)(x...; kw...)\n",
58 | " return c.outer(c.inner(x...; kw...))\n",
59 | "end"
60 | ]
61 | },
62 | {
63 | "cell_type": "markdown",
64 | "id": "188dfb49-9be8-4cdf-856f-240422a4ac3d",
65 | "metadata": {},
66 | "source": [
67 | "In the code above, the last two lines in the `struct`are constructors, where the first one allow us to do\n",
68 | "`Comp{Function, Function}(g, f)` and for the second we do `Comp(g,f)`. In the last line we are defining a function\n",
69 | "to be dispatched on `Comp`, but this function is nameless.\n",
70 | "\n",
71 | "With this, our composition is now working."
72 | ]
73 | },
74 | {
75 | "cell_type": "code",
76 | "execution_count": 20,
77 | "id": "4ff9cd05-6c67-4f6b-9a2c-ebc4fb0b2d95",
78 | "metadata": {},
79 | "outputs": [
80 | {
81 | "data": {
82 | "text/plain": [
83 | "(::Comp{var\"#55#57\", var\"#56#58\"}) (generic function with 1 method)"
84 | ]
85 | },
86 | "execution_count": 20,
87 | "metadata": {},
88 | "output_type": "execute_result"
89 | }
90 | ],
91 | "source": [
92 | "Comp{Function, Function}(x->x, y->y^2)\n",
93 | "Comp(x->x, y->y^2)\n"
94 | ]
95 | },
96 | {
97 | "cell_type": "code",
98 | "execution_count": 21,
99 | "id": "77f5c50c-6adb-4f6f-b60a-0afa13c2622a",
100 | "metadata": {},
101 | "outputs": [],
102 | "source": [
103 | "using MLStyle"
104 | ]
105 | },
106 | {
107 | "cell_type": "code",
108 | "execution_count": null,
109 | "id": "f06993ec-6563-4f13-bdb2-2aca4212c50a",
110 | "metadata": {},
111 | "outputs": [],
112 | "source": []
113 | }
114 | ],
115 | "metadata": {
116 | "kernelspec": {
117 | "display_name": "Julia 1.10.5",
118 | "language": "julia",
119 | "name": "julia-1.10"
120 | },
121 | "language_info": {
122 | "file_extension": ".jl",
123 | "mimetype": "application/julia",
124 | "name": "julia",
125 | "version": "1.10.5"
126 | }
127 | },
128 | "nbformat": 4,
129 | "nbformat_minor": 5
130 | }
131 |
--------------------------------------------------------------------------------
/CatLab/ACSets2.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 4,
6 | "id": "c839c45f-07ec-470c-a1c2-3bd0ff660701",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Documents/GitHub/Julia_Tutorials/CatLab`\n",
14 | "\u001b[36m\u001b[1m[ \u001b[22m\u001b[39m\u001b[36m\u001b[1mInfo: \u001b[22m\u001b[39mPrecompiling ACSets [227ef7b5-1206-438b-ac65-934d6da304b8]\n"
15 | ]
16 | }
17 | ],
18 | "source": [
19 | "using Pkg\n",
20 | "Pkg.activate(\".\")\n",
21 | "using ACSets"
22 | ]
23 | },
24 | {
25 | "cell_type": "code",
26 | "execution_count": 5,
27 | "id": "577fd18e-edc6-45a1-84b7-028739559688",
28 | "metadata": {},
29 | "outputs": [
30 | {
31 | "data": {
32 | "text/plain": [
33 | "3"
34 | ]
35 | },
36 | "execution_count": 5,
37 | "metadata": {},
38 | "output_type": "execute_result"
39 | }
40 | ],
41 | "source": [
42 | "SchemaGraph = BasicSchema([:E,:V], [(:src,:E,:V),(:tgt,:E,:V)],\n",
43 | " [:L,:W], [(:x,:V,:W),(:y,:V,:W),(:label,:V,:L),(:weight,:E,:W),(:radius,:V,:W)])\n",
44 | "\n",
45 | "# Creates the ACData{:L,:W} struct\n",
46 | "@acset_type AcData(SchemaGraph, index=[:src,:tgt])\n",
47 | "\n",
48 | "acd = AcData{Symbol,Real}()\n",
49 | "add_part!(acd, :V, label=:a, radius=1,x=1,y=2)\n",
50 | "add_part!(acd, :V, label=:b, radius=1,x=2,y=2)\n",
51 | "add_part!(acd, :V, label=:c, radius=1,x=1,y=1)\n",
52 | "add_part!(acd, :V, label=:d, radius=1,x=2,y=1)\n",
53 | "\n",
54 | "add_part!(acd, :E, src=1,tgt=2, weight=1)\n",
55 | "add_part!(acd, :E, src=1,tgt=3, weight=1)\n",
56 | "add_part!(acd, :E, src=4,tgt=2, weight=1)\n"
57 | ]
58 | },
59 | {
60 | "cell_type": "code",
61 | "execution_count": 12,
62 | "id": "fbc3a294-e575-48ff-bdd7-0bbbe6bb9c84",
63 | "metadata": {},
64 | "outputs": [
65 | {
66 | "data": {
67 | "text/plain": [
68 | "1"
69 | ]
70 | },
71 | "execution_count": 12,
72 | "metadata": {},
73 | "output_type": "execute_result"
74 | }
75 | ],
76 | "source": [
77 | "acd[1,:x]"
78 | ]
79 | }
80 | ],
81 | "metadata": {
82 | "kernelspec": {
83 | "display_name": "Julia 1.10.5",
84 | "language": "julia",
85 | "name": "julia-1.10"
86 | },
87 | "language_info": {
88 | "file_extension": ".jl",
89 | "mimetype": "application/julia",
90 | "name": "julia",
91 | "version": "1.10.5"
92 | }
93 | },
94 | "nbformat": 4,
95 | "nbformat_minor": 5
96 | }
97 |
--------------------------------------------------------------------------------
/CatLab/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | ACSets = "227ef7b5-1206-438b-ac65-934d6da304b8"
3 | Catlab = "134e5e36-593f-5add-ad60-77f754baafbe"
4 | GATlab = "f0ffcf3b-d13a-433e-917c-cc44ccf5ead2"
5 | MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
6 |
--------------------------------------------------------------------------------
/CategoryTheory/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/davibarreira/Julia_Tutorials/60c0d8309d0077c4297f9a188e6a947b61ed38ac/CategoryTheory/.DS_Store
--------------------------------------------------------------------------------
/CategoryTheory/11-2 Monads Revisited.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "c7248405-aa52-4749-9508-f5b77843f232",
6 | "metadata": {},
7 | "source": [
8 | "# Monads Revisited - 2\n",
9 | "\n",
10 | "Remember, the Category of Endofunctors over $\\mathbf{C}$ is a monoidal category. Thus, we can\n",
11 | "define monoids over such category by using the "
12 | ]
13 | },
14 | {
15 | "cell_type": "code",
16 | "execution_count": 41,
17 | "id": "2bce338e-5cd7-46b2-9bb3-1afa9ecc5589",
18 | "metadata": {},
19 | "outputs": [
20 | {
21 | "data": {
22 | "text/plain": [
23 | "converttovec (generic function with 1 method)"
24 | ]
25 | },
26 | "execution_count": 41,
27 | "metadata": {},
28 | "output_type": "execute_result"
29 | }
30 | ],
31 | "source": [
32 | "struct Nil end\n",
33 | "struct Cons{T}\n",
34 | " val::T\n",
35 | " next::Union{Cons{T},Nil} # n.b. abstract type!\n",
36 | "end\n",
37 | "List{T} = Union{Cons{T}, Nil}\n",
38 | "fmap(f::Function, x::Nil) = Nil()\n",
39 | "fmap(f::Function, x::Cons) = Cons(f(x.val),fmap(f, x.next))\n",
40 | "\n",
41 | "foldrList(f::Function, e, ::Nil) = e\n",
42 | "foldrList(f::Function, e, x::Cons{T}) where T = f(x.val,foldrList(f, e, x.next))\n",
43 | "\n",
44 | "concatenate(x::Nil ,y::List) = y\n",
45 | "concatenate(x::Cons,y::List) = Cons(x.val, concatenate(x.next, y))\n",
46 | "\n",
47 | "μ(x::Nil) = Nil()\n",
48 | "μ(x::Cons{<:List}) = concatenate(x.val, μ(x.next))\n",
49 | "η(x,::Type{List}) = Cons(x,Nil())\n",
50 | "bind(x::List, f::Function) = μ(fmap(f, x))\n",
51 | "\n",
52 | "converttovec(l::List) = foldrList(vcat,[],l)"
53 | ]
54 | },
55 | {
56 | "cell_type": "code",
57 | "execution_count": 47,
58 | "id": "396d7255-7f64-4a13-8f8c-5aff1a26c86c",
59 | "metadata": {
60 | "tags": []
61 | },
62 | "outputs": [
63 | {
64 | "data": {
65 | "text/plain": [
66 | "Cons{Int64}(1, Cons{Int64}(2, Cons{Int64}(3, Nil())))"
67 | ]
68 | },
69 | "execution_count": 47,
70 | "metadata": {},
71 | "output_type": "execute_result"
72 | }
73 | ],
74 | "source": [
75 | "l1 = Cons(1, Cons(2, Nil()))\n",
76 | "l2 = Cons(3, Nil())\n",
77 | "l3 = Cons(l1, Cons(l2, Nil()))\n",
78 | "\n",
79 | "μ(l3)"
80 | ]
81 | },
82 | {
83 | "cell_type": "code",
84 | "execution_count": 23,
85 | "id": "e4199368-da11-4a46-a784-cc6db37599c4",
86 | "metadata": {
87 | "tags": []
88 | },
89 | "outputs": [
90 | {
91 | "data": {
92 | "text/plain": [
93 | "Cons{Cons{Int64}}(Cons{Int64}(3, Cons{Int64}(2, Nil())), Nil())"
94 | ]
95 | },
96 | "execution_count": 23,
97 | "metadata": {},
98 | "output_type": "execute_result"
99 | }
100 | ],
101 | "source": [
102 | "Cons(Cons(3,Cons(2,Nil())),Nil())\n",
103 | "Cons(Cons(3,Cons(2,Nil())),Nil())"
104 | ]
105 | },
106 | {
107 | "cell_type": "code",
108 | "execution_count": 40,
109 | "id": "b46e4d56-878e-49b8-af09-7b7cf468e1e9",
110 | "metadata": {
111 | "tags": []
112 | },
113 | "outputs": [],
114 | "source": [
115 | "# foldr((x,y)->Cons(x,y),[1,2]; init=Nil())\n",
116 | "# Cons(1,Cons(Cons(2,Nil())))"
117 | ]
118 | }
119 | ],
120 | "metadata": {
121 | "kernelspec": {
122 | "display_name": "Julia 1.9.3",
123 | "language": "julia",
124 | "name": "julia-1.9"
125 | },
126 | "language_info": {
127 | "file_extension": ".jl",
128 | "mimetype": "application/julia",
129 | "name": "julia",
130 | "version": "1.9.3"
131 | }
132 | },
133 | "nbformat": 4,
134 | "nbformat_minor": 5
135 | }
136 |
--------------------------------------------------------------------------------
/CategoryTheory/13 - MonadPlus.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "id": "a4985343-999d-4022-9dbe-f89113fb9b5f",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/MEGA/EMAP/Julia_Tutorials/CategoryTheory`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg\n",
19 | "Pkg.activate(\".\")\n",
20 | "using MLStyle\n",
21 | "\n",
22 | "flatmap(f,v::Vector; init) = foldr(vcat, map(f,v), init=init);"
23 | ]
24 | },
25 | {
26 | "cell_type": "code",
27 | "execution_count": 2,
28 | "id": "c64b0117-5c2f-4922-9e71-a5cb81982fc3",
29 | "metadata": {},
30 | "outputs": [
31 | {
32 | "data": {
33 | "text/plain": [
34 | "univ (generic function with 1 method)"
35 | ]
36 | },
37 | "execution_count": 2,
38 | "metadata": {},
39 | "output_type": "execute_result"
40 | }
41 | ],
42 | "source": [
43 | "struct Leaf end\n",
44 | "struct Node{a}\n",
45 | " _1::a\n",
46 | " _2::Vector{Union{Leaf, Node{a}}} # Forest{a} = Vector{Tree{a}} = Vector{Union{Leaf, Node{a}}}\n",
47 | "end\n",
48 | "Tree{a} = Union{Leaf, Node{a}}\n",
49 | "Forest{a} = Vector{Tree{a}};\n",
50 | "\n",
51 | "Forest(n::Node{a}) where a = Tree{a}[n]\n",
52 | "zero(::Forest{a}) where a = Tree{a}[]\n",
53 | "one(::Forest{a}) where a = Tree{a}[Leaf()]\n",
54 | "⊕(x::Forest, y::Forest) = vcat(x,y)\n",
55 | "⊗(x::Forest, y::Forest) = begin\n",
56 | " g(::Leaf) = y\n",
57 | " g(n::Node{a}) where a = Tree{a}[Node(n._1, n._2 ⊗ y)]\n",
58 | " flatmap(g, x, init=zero(x))\n",
59 | "end\n",
60 | "\n",
61 | "inj(x::T) where T = Forest(Node{T}(x, one(Forest{T}())))\n",
62 | "univ(h::Function, xs::Forest) = begin\n",
63 | " univT(::Leaf) = one(xs)\n",
64 | " univT(n::Node) = h(n._1) ⊕ univ(h, n._2)\n",
65 | " foldr(⊕, map(univT(xs)))\n",
66 | " end"
67 | ]
68 | },
69 | {
70 | "cell_type": "code",
71 | "execution_count": 4,
72 | "id": "a0e32dc8-d4cd-47a0-bc73-98e5e17204a8",
73 | "metadata": {},
74 | "outputs": [
75 | {
76 | "data": {
77 | "text/plain": [
78 | "Union{Leaf, Node{Int64}}[]"
79 | ]
80 | },
81 | "execution_count": 4,
82 | "metadata": {},
83 | "output_type": "execute_result"
84 | }
85 | ],
86 | "source": [
87 | "Forest{Int}()"
88 | ]
89 | },
90 | {
91 | "cell_type": "code",
92 | "execution_count": 3,
93 | "id": "38831656-603e-4148-b5c7-db9a6f195557",
94 | "metadata": {},
95 | "outputs": [
96 | {
97 | "data": {
98 | "text/plain": [
99 | "1-element Vector{Union{Leaf, Node{Float64}}}:\n",
100 | " Node{Float64}(10.0, Union{Leaf, Node{Float64}}[Leaf()])"
101 | ]
102 | },
103 | "execution_count": 3,
104 | "metadata": {},
105 | "output_type": "execute_result"
106 | }
107 | ],
108 | "source": [
109 | "inj(10.0)\n",
110 | "inj(10.0)"
111 | ]
112 | },
113 | {
114 | "cell_type": "code",
115 | "execution_count": 19,
116 | "id": "8b3f3de6-b442-4dc5-abf5-503dd572cb17",
117 | "metadata": {},
118 | "outputs": [
119 | {
120 | "name": "stdout",
121 | "output_type": "stream",
122 | "text": [
123 | "zero(Forest{Int}()) = Union{Leaf, Node{Int64}}[]\n",
124 | "one(Forest{Int}()) = Union{Leaf, Node{Int64}}[Leaf()]\n",
125 | "Node(1, Tree{Int}[Leaf()]) = Node{Int64}(1, Union{Leaf, Node{Int64}}[Leaf()])\n"
126 | ]
127 | }
128 | ],
129 | "source": [
130 | "@show zero(Forest{Int}())\n",
131 | "@show one(Forest{Int}())\n",
132 | "@show Node(1,Tree{Int}[Leaf()]);"
133 | ]
134 | },
135 | {
136 | "cell_type": "code",
137 | "execution_count": 20,
138 | "id": "cbaa9ee7-2a41-4720-b85b-00c44f1917c2",
139 | "metadata": {},
140 | "outputs": [
141 | {
142 | "name": "stdout",
143 | "output_type": "stream",
144 | "text": [
145 | "zero(Forest{Int}()) ⊕ x == x == x ⊕ zero(Forest{Int}()) = true\n",
146 | "one(Forest{Int}()) ⊗ x == x = true\n"
147 | ]
148 | }
149 | ],
150 | "source": [
151 | "x = Tree{Int}[Node(3,zero(Forest{Int}())),Node(4,Tree{Int}[Node(10,Tree{Int}[Leaf()])]),Leaf()]\n",
152 | "@show zero(Forest{Int}()) ⊕ x == x == x ⊕ zero(Forest{Int}())\n",
153 | "@show one(Forest{Int}()) ⊗ x == x;"
154 | ]
155 | },
156 | {
157 | "cell_type": "code",
158 | "execution_count": 23,
159 | "id": "8197fda5-7712-4908-a4af-bdb604d378d2",
160 | "metadata": {},
161 | "outputs": [
162 | {
163 | "data": {
164 | "text/plain": [
165 | "2-element Vector{Union{Leaf, Node{Int64}}}:\n",
166 | " Node{Int64}(3, Union{Leaf, Node{Int64}}[])\n",
167 | " Node{Int64}(4, Union{Leaf, Node{Int64}}[Node{Int64}(10, Union{Leaf, Node{Int64}}[])])"
168 | ]
169 | },
170 | "execution_count": 23,
171 | "metadata": {},
172 | "output_type": "execute_result"
173 | }
174 | ],
175 | "source": [
176 | "x = Tree{Int}[Node(3,zero(Forest{Int}())),Node(4,Tree{Int}[Node(10,Tree{Int}[Leaf()])]),Leaf()]\n",
177 | "y = zero(x)\n",
178 | "x ⊗ y"
179 | ]
180 | },
181 | {
182 | "cell_type": "code",
183 | "execution_count": 24,
184 | "id": "f65080e5-556c-434c-befe-65b288de8d53",
185 | "metadata": {},
186 | "outputs": [
187 | {
188 | "data": {
189 | "text/plain": [
190 | "Union{Leaf, Node{Int64}}[]"
191 | ]
192 | },
193 | "execution_count": 24,
194 | "metadata": {},
195 | "output_type": "execute_result"
196 | }
197 | ],
198 | "source": [
199 | "y ⊗ x"
200 | ]
201 | },
202 | {
203 | "cell_type": "code",
204 | "execution_count": 25,
205 | "id": "4a1c862a-50c9-41f4-bc00-974950eea11e",
206 | "metadata": {},
207 | "outputs": [
208 | {
209 | "data": {
210 | "text/plain": [
211 | "2-element Vector{Union{Leaf, Node{Int64}}}:\n",
212 | " Node{Int64}(3, Union{Leaf, Node{Int64}}[])\n",
213 | " Node{Int64}(1, Union{Leaf, Node{Int64}}[])"
214 | ]
215 | },
216 | "execution_count": 25,
217 | "metadata": {},
218 | "output_type": "execute_result"
219 | }
220 | ],
221 | "source": [
222 | "Forest(Node{Int}(3,zero(Forest{Int}()))) ⊕ Forest(Node{Int}(1,zero(Forest{Int}())))"
223 | ]
224 | }
225 | ],
226 | "metadata": {
227 | "kernelspec": {
228 | "display_name": "Julia 1.9.2",
229 | "language": "julia",
230 | "name": "julia-1.9"
231 | },
232 | "language_info": {
233 | "file_extension": ".jl",
234 | "mimetype": "application/julia",
235 | "name": "julia",
236 | "version": "1.9.2"
237 | }
238 | },
239 | "nbformat": 4,
240 | "nbformat_minor": 5
241 | }
242 |
--------------------------------------------------------------------------------
/CategoryTheory/13 - Operads.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "c5b164b8-1a0b-4be8-a6d3-bc911035bb62",
6 | "metadata": {},
7 | "source": [
8 | "# Operads\n",
9 | "\n",
10 | "Think of the algebra of trees. "
11 | ]
12 | },
13 | {
14 | "cell_type": "code",
15 | "execution_count": null,
16 | "id": "4076ba5e-0fd3-4989-97b8-66875d24fc36",
17 | "metadata": {},
18 | "outputs": [],
19 | "source": []
20 | }
21 | ],
22 | "metadata": {
23 | "kernelspec": {
24 | "display_name": "Julia 1.9.3",
25 | "language": "julia",
26 | "name": "julia-1.9"
27 | },
28 | "language_info": {
29 | "file_extension": ".jl",
30 | "mimetype": "application/julia",
31 | "name": "julia",
32 | "version": "1.9.3"
33 | }
34 | },
35 | "nbformat": 4,
36 | "nbformat_minor": 5
37 | }
38 |
--------------------------------------------------------------------------------
/CategoryTheory/14 - Arithmetic Expressions.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "id": "4084363b-6fad-45df-af1c-22fc20efa3e4",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/MEGA/EMAP/Julia_Tutorials/CategoryTheory`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg\n",
19 | "Pkg.activate(\".\")\n",
20 | "using MLStyle"
21 | ]
22 | },
23 | {
24 | "cell_type": "code",
25 | "execution_count": 2,
26 | "id": "984241b9-d8c8-4813-9eb5-ebcbfde8f9a6",
27 | "metadata": {},
28 | "outputs": [],
29 | "source": [
30 | "# # @data D{a} begin\n",
31 | "# # Add(D{a},D{a})\n",
32 | "# # Mult(D{a},D{a})\n",
33 | "# # Zero()\n",
34 | "# # Leaf(::Vector{a})\n",
35 | "# # end\n",
36 | "# struct Empty end\n",
37 | "# struct Add\n",
38 | "# _1\n",
39 | "# _2\n",
40 | "# end\n",
41 | "# struct Mult\n",
42 | "# _1\n",
43 | "# _2\n",
44 | "# end\n",
45 | "# struct Leaf{T}\n",
46 | "# _1::T\n",
47 | "# end\n",
48 | "\n",
49 | "# struct D{a}\n",
50 | " \n",
51 | "# end"
52 | ]
53 | },
54 | {
55 | "cell_type": "code",
56 | "execution_count": 3,
57 | "id": "6f1e3507-f054-44e7-b146-042685e1e66b",
58 | "metadata": {},
59 | "outputs": [],
60 | "source": [
61 | "struct Leaf{T}\n",
62 | " _1::T\n",
63 | "end\n",
64 | "\n",
65 | "@data D{a} begin\n",
66 | " Empty()\n",
67 | " Factor(::Leaf{<:D}, ::Vector{a})\n",
68 | " Mult(::Factor,::Union{D{a},Empty})\n",
69 | " Add(::Mult,::Union{D{a},Empty})\n",
70 | "end"
71 | ]
72 | },
73 | {
74 | "cell_type": "code",
75 | "execution_count": 16,
76 | "id": "ae340799-7913-4762-b9fa-1922fdaef568",
77 | "metadata": {},
78 | "outputs": [
79 | {
80 | "data": {
81 | "text/plain": [
82 | "Factor{Int64}(Leaf{Empty{String}}(Empty{String}()), [10])"
83 | ]
84 | },
85 | "execution_count": 16,
86 | "metadata": {},
87 | "output_type": "execute_result"
88 | }
89 | ],
90 | "source": []
91 | },
92 | {
93 | "cell_type": "code",
94 | "execution_count": 12,
95 | "id": "0f99fc9b-4238-474b-bbc9-d5af2470adbd",
96 | "metadata": {},
97 | "outputs": [
98 | {
99 | "data": {
100 | "text/plain": [
101 | "Factor{Int64}(Leaf{Add{Int64}}(Add{Int64}(Mult{Int64}(Factor{Int64}(Leaf{Empty{Int64}}(Empty{Int64}()), [0]), Factor{Int64}(Leaf{Empty{Int64}}(Empty{Int64}()), [0])), Mult{Int64}(Factor{Int64}(Leaf{Empty{Int64}}(Empty{Int64}()), [0]), Empty{Int64}()))), [0])"
102 | ]
103 | },
104 | "execution_count": 12,
105 | "metadata": {},
106 | "output_type": "execute_result"
107 | }
108 | ],
109 | "source": [
110 | "ϵ = Empty{Int}()\n",
111 | "factor = Factor(Leaf(Empty{Int}()), [0])\n",
112 | "m1 = Mult(factor,factor)\n",
113 | "m2 = Mult(factor,ϵ)\n",
114 | "\n",
115 | "Add(m1,ϵ)\n",
116 | "a = Add(m1,m2)\n",
117 | "factor = Factor(Leaf(a) , [0])"
118 | ]
119 | }
120 | ],
121 | "metadata": {
122 | "kernelspec": {
123 | "display_name": "Julia 1.9.1",
124 | "language": "julia",
125 | "name": "julia-1.9"
126 | },
127 | "language_info": {
128 | "file_extension": ".jl",
129 | "mimetype": "application/julia",
130 | "name": "julia",
131 | "version": "1.9.1"
132 | }
133 | },
134 | "nbformat": 4,
135 | "nbformat_minor": 5
136 | }
137 |
--------------------------------------------------------------------------------
/CategoryTheory/15 - Nested Datatypes.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "ac335163-a20e-4ba7-977c-f450ae938504",
6 | "metadata": {},
7 | "source": [
8 | "# Nested Datatypes\n",
9 | "\n",
10 | "Consider the following binary functor:\n",
11 | "$$\n",
12 | "F(a,b) := 1 + a \\times b\n",
13 | "$$\n",
14 | "\n",
15 | "Fix an $a$ and define $F_a(b) := F(a,b)$. We then have the category of $F_a$-algebras,\n",
16 | "where an object in this category is a tuple $(alg, x)$ such that $alg:F_a(x) \\to x$,\n",
17 | "and the morphisms are homomorphisms between the algebras. We then have an initial\n",
18 | "object for such category, which will be the `List a` object in $\\mathbf Set$ (remember\n",
19 | "that we consider sets to be types).\n",
20 | "Thus, we have the initial algebra $(\\phi, List a)$, where:\n",
21 | "$$\n",
22 | "\\alpha_a: F_a(List a) \\to List a.\n",
23 | "$$\n"
24 | ]
25 | },
26 | {
27 | "cell_type": "code",
28 | "execution_count": null,
29 | "id": "9a8b6fc3-f608-4937-8a5c-faf5a4652c27",
30 | "metadata": {},
31 | "outputs": [],
32 | "source": []
33 | }
34 | ],
35 | "metadata": {
36 | "kernelspec": {
37 | "display_name": "Julia 1.9.3",
38 | "language": "julia",
39 | "name": "julia-1.9"
40 | },
41 | "language_info": {
42 | "file_extension": ".jl",
43 | "mimetype": "application/julia",
44 | "name": "julia",
45 | "version": "1.9.3"
46 | }
47 | },
48 | "nbformat": 4,
49 | "nbformat_minor": 5
50 | }
51 |
--------------------------------------------------------------------------------
/CategoryTheory/16 - Freer Monads.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 2,
6 | "id": "e5bf5f49-0641-4db0-ae86-b6970bd79741",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Documents/GitHub/Julia_Tutorials/CategoryTheory`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg\n",
19 | "Pkg.activate(\".\")\n",
20 | "using MLStyle"
21 | ]
22 | },
23 | {
24 | "cell_type": "code",
25 | "execution_count": null,
26 | "id": "9c415dd8-98fc-44aa-a163-01be18812f5e",
27 | "metadata": {},
28 | "outputs": [],
29 | "source": []
30 | }
31 | ],
32 | "metadata": {
33 | "kernelspec": {
34 | "display_name": "Julia 1.10.3",
35 | "language": "julia",
36 | "name": "julia-1.10"
37 | },
38 | "language_info": {
39 | "file_extension": ".jl",
40 | "mimetype": "application/julia",
41 | "name": "julia",
42 | "version": "1.10.3"
43 | }
44 | },
45 | "nbformat": 4,
46 | "nbformat_minor": 5
47 | }
48 |
--------------------------------------------------------------------------------
/CategoryTheory/9 - Folds.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "6914e819-1e2e-445f-ab19-e346072edecf",
6 | "metadata": {},
7 | "source": [
8 | "## Folds\n",
9 | "\n",
10 | "*Folds are catamorphisms of the catgory of List-algebras*.\n",
11 | "\n",
12 | "Remember that for an endofunctor $F$, an $F$-algebra is a tuple $(\\phi, a)$ where\n",
13 | "$a$ is a type and $\\phi:Fa \\to a$ is an evaluator. For a fixed functor, the collection of\n",
14 | "$F$-algebras form a category. If the functor $F$ is polynomial, then this algebra has an initial\n",
15 | "object. Remember that for an initial object, there is a unique morphism that goes from it\n",
16 | "to every other object in the category. In the category of $F$-alebras, this unique morphism\n",
17 | "leaving the initial object is called a catamorphism."
18 | ]
19 | },
20 | {
21 | "cell_type": "code",
22 | "execution_count": 1,
23 | "id": "2f791cce-24bd-4ac6-8b76-168ed4852a61",
24 | "metadata": {},
25 | "outputs": [
26 | {
27 | "data": {
28 | "text/plain": [
29 | "nil (generic function with 2 methods)"
30 | ]
31 | },
32 | "execution_count": 1,
33 | "metadata": {},
34 | "output_type": "execute_result"
35 | }
36 | ],
37 | "source": [
38 | "abstract type List{T} end\n",
39 | "struct Nil{T} <: List{T} end\n",
40 | "struct Cons{T} <: List{T}\n",
41 | " v::T\n",
42 | " next::List{T}\n",
43 | "end\n",
44 | "\n",
45 | "wrap(x::T) where T = Cons{T}(x, Nil{T}())\n",
46 | "nil(x::Nil{T}) where T = true\n",
47 | "nil(x::Cons{T}) where T = false"
48 | ]
49 | },
50 | {
51 | "cell_type": "code",
52 | "execution_count": 2,
53 | "id": "54a204e1-236e-43bf-8a4e-7e0c35e8f6a6",
54 | "metadata": {},
55 | "outputs": [
56 | {
57 | "data": {
58 | "text/plain": [
59 | "foldrList (generic function with 2 methods)"
60 | ]
61 | },
62 | "execution_count": 2,
63 | "metadata": {},
64 | "output_type": "execute_result"
65 | }
66 | ],
67 | "source": [
68 | "foldrList(f::Function, e::T, ::Nil{T}) where T = e\n",
69 | "foldrList(f::Function, e::T, x::Cons{T}) where T = f(x.v,foldrList(f, e, x.next))"
70 | ]
71 | },
72 | {
73 | "cell_type": "code",
74 | "execution_count": 3,
75 | "id": "3c51a1f6-bf28-43fb-9c3a-5a9b0d342a14",
76 | "metadata": {},
77 | "outputs": [
78 | {
79 | "name": "stdout",
80 | "output_type": "stream",
81 | "text": [
82 | "foldrList(+, 10, Nil{Int}()) = 10\n",
83 | "foldrList(+, 10, Cons(2, wrap(10))) = 22\n"
84 | ]
85 | }
86 | ],
87 | "source": [
88 | "@show foldrList(+, 10, Nil{Int}())\n",
89 | "@show foldrList(+, 10, Cons(2,wrap(10)));"
90 | ]
91 | },
92 | {
93 | "cell_type": "code",
94 | "execution_count": null,
95 | "id": "9f29a919-fa28-4adf-bbd4-30218b27e018",
96 | "metadata": {},
97 | "outputs": [],
98 | "source": []
99 | },
100 | {
101 | "cell_type": "code",
102 | "execution_count": null,
103 | "id": "2e5e02f3-857d-4041-8520-01165b5a2347",
104 | "metadata": {},
105 | "outputs": [],
106 | "source": []
107 | },
108 | {
109 | "cell_type": "code",
110 | "execution_count": null,
111 | "id": "f4b3a32e-d201-4aa6-b24d-6be0737ce83b",
112 | "metadata": {},
113 | "outputs": [],
114 | "source": []
115 | }
116 | ],
117 | "metadata": {
118 | "kernelspec": {
119 | "display_name": "Julia 1.10.0",
120 | "language": "julia",
121 | "name": "julia-1.10"
122 | },
123 | "language_info": {
124 | "file_extension": ".jl",
125 | "mimetype": "application/julia",
126 | "name": "julia",
127 | "version": "1.10.0"
128 | }
129 | },
130 | "nbformat": 4,
131 | "nbformat_minor": 5
132 | }
133 |
--------------------------------------------------------------------------------
/CategoryTheory/Chapter 18 Reactive.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 2,
6 | "id": "c36a1f0a-90ac-4d5b-bed3-f1468d83fd8c",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Main/EMAp/PhDThesis/notes/FunctionalProgrammingCategoryTheory/julia`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg\n",
19 | "Pkg.activate(\".\")"
20 | ]
21 | },
22 | {
23 | "cell_type": "code",
24 | "execution_count": 3,
25 | "id": "e5ab9a30-2087-4421-b27a-57bd96deb6b8",
26 | "metadata": {},
27 | "outputs": [
28 | {
29 | "data": {
30 | "text/plain": [
31 | "Cart(Clothing[Clothing(\"shirt\", 13)])"
32 | ]
33 | },
34 | "execution_count": 3,
35 | "metadata": {},
36 | "output_type": "execute_result"
37 | }
38 | ],
39 | "source": [
40 | "# struct Options\n",
41 | "# color::String\n",
42 | "# size::Int\n",
43 | "# end\n",
44 | "struct Clothing\n",
45 | " name::String\n",
46 | " price::Real\n",
47 | " # options::Options\n",
48 | "end\n",
49 | "\n",
50 | "struct Cart\n",
51 | " products::Vector{Clothing}\n",
52 | "end\n",
53 | "\n",
54 | "Cart(shirt::Clothing) = Cart([shirt])\n",
55 | "\n",
56 | "shirt = Clothing(\"shirt\", 13)\n",
57 | "\n",
58 | "cart = Cart(shirt)"
59 | ]
60 | },
61 | {
62 | "cell_type": "code",
63 | "execution_count": 11,
64 | "id": "c330de5b-c2fd-4bf0-8e78-907533f473e7",
65 | "metadata": {},
66 | "outputs": [
67 | {
68 | "data": {
69 | "text/plain": [
70 | "additem (generic function with 2 methods)"
71 | ]
72 | },
73 | "execution_count": 11,
74 | "metadata": {},
75 | "output_type": "execute_result"
76 | }
77 | ],
78 | "source": [
79 | "# This implementation guarantees that the original\n",
80 | "# cart is not mutated.\n",
81 | "function additem(cart, item)\n",
82 | " return push!(copy(cart.products),shirt)\n",
83 | "end"
84 | ]
85 | },
86 | {
87 | "cell_type": "code",
88 | "execution_count": 12,
89 | "id": "087d13f6-8aad-416f-b994-3cf27cfc5053",
90 | "metadata": {},
91 | "outputs": [
92 | {
93 | "data": {
94 | "text/plain": [
95 | "valuecell (generic function with 1 method)"
96 | ]
97 | },
98 | "execution_count": 12,
99 | "metadata": {},
100 | "output_type": "execute_result"
101 | }
102 | ],
103 | "source": [
104 | "function valuecell(initialvalue)\n",
105 | " currentvalue = initialvalue\n",
106 | " return (\n",
107 | " val = x->currentvalue,\n",
108 | " update = f -> begin\n",
109 | " oldvalue = currentvalue\n",
110 | " newvalue = f(oldvalue)\n",
111 | " currentvalue = newvalue\n",
112 | " end\n",
113 | " )\n",
114 | "end"
115 | ]
116 | },
117 | {
118 | "cell_type": "code",
119 | "execution_count": 18,
120 | "id": "70c35a25-c388-42e9-8624-e22ba7e37d02",
121 | "metadata": {},
122 | "outputs": [
123 | {
124 | "data": {
125 | "text/plain": [
126 | "(val = var\"#9#11\"(Core.Box(Any[])), update = var\"#10#12\"(Core.Box(Any[])))"
127 | ]
128 | },
129 | "execution_count": 18,
130 | "metadata": {},
131 | "output_type": "execute_result"
132 | }
133 | ],
134 | "source": [
135 | "shopppingcart = valuecell([])"
136 | ]
137 | },
138 | {
139 | "cell_type": "code",
140 | "execution_count": 19,
141 | "id": "7b4e0fbf-799d-450e-9569-2534c8badb26",
142 | "metadata": {},
143 | "outputs": [
144 | {
145 | "ename": "LoadError",
146 | "evalue": "type Array has no field products",
147 | "output_type": "error",
148 | "traceback": [
149 | "type Array has no field products",
150 | "",
151 | "Stacktrace:",
152 | " [1] getproperty",
153 | " @ ./Base.jl:42 [inlined]",
154 | " [2] additem(cart::Vector{Any}, item::Clothing)",
155 | " @ Main ./In[11]:4",
156 | " [3] (::var\"#21#22\"{Clothing})(cart::Vector{Any})",
157 | " @ Main ./In[19]:3",
158 | " [4] (::var\"#10#12\")(f::var\"#21#22\"{Clothing})",
159 | " @ Main ./In[12]:7",
160 | " [5] additemcart(name::String, price::Int64)",
161 | " @ Main ./In[19]:3",
162 | " [6] top-level scope",
163 | " @ In[19]:6",
164 | " [7] eval",
165 | " @ ./boot.jl:373 [inlined]",
166 | " [8] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)",
167 | " @ Base ./loading.jl:1196"
168 | ]
169 | }
170 | ],
171 | "source": [
172 | "function additemcart(name, price)\n",
173 | " item = Clothing(name,price)\n",
174 | " shopppingcart.update(cart-> additem(cart, item))\n",
175 | "end\n",
176 | "\n",
177 | "additemcart(\"Davi\", 10)"
178 | ]
179 | },
180 | {
181 | "cell_type": "code",
182 | "execution_count": null,
183 | "id": "d41faa01-e419-4476-a6c6-9380ec589f7d",
184 | "metadata": {},
185 | "outputs": [],
186 | "source": [
187 | "# shopppingcart.update(cart -> additem(cart,"
188 | ]
189 | },
190 | {
191 | "cell_type": "code",
192 | "execution_count": null,
193 | "id": "b6af8497-bc69-4bc7-9c24-dcda88122281",
194 | "metadata": {},
195 | "outputs": [],
196 | "source": []
197 | }
198 | ],
199 | "metadata": {
200 | "kernelspec": {
201 | "display_name": "Julia (4 threads) 1.7.2",
202 | "language": "julia",
203 | "name": "julia-(4-threads)-1.7"
204 | },
205 | "language_info": {
206 | "file_extension": ".jl",
207 | "mimetype": "application/julia",
208 | "name": "julia",
209 | "version": "1.7.2"
210 | }
211 | },
212 | "nbformat": 4,
213 | "nbformat_minor": 5
214 | }
215 |
--------------------------------------------------------------------------------
/CategoryTheory/Co-Monads.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "id": "3aef9529-1336-452f-93cb-dd1bf342af8c",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Documents/GitHub/Julia_Tutorials/CategoryTheory`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg\n",
19 | "Pkg.activate(\".\")\n",
20 | "using MLStyle"
21 | ]
22 | },
23 | {
24 | "cell_type": "markdown",
25 | "id": "97ceb8cc-5cb6-4e74-a756-02ab03147763",
26 | "metadata": {},
27 | "source": [
28 | "## Comonads\n",
29 | "\n",
30 | "A comonad is a triple $(W,\\epsilon,\\delta)$, where\n",
31 | "$$W:\\mathcal C \\to \\mathcal C$$\n",
32 | "$$\\epsilon: W \\Rightarrow Id_\\mathcal C$$\n",
33 | "$$\\delta: W \\Rightarrow W \\circ W$$\n",
34 | "\n",
35 | "The counit ($\\epsilon$) is commonly called `extract`, since $\\epsilon_A: WA \\to A$.\n",
36 | "\n",
37 | "The codiagonal ($\\delta$) is commonly called `duplicate`, since $\\delta_A: WA \\to W WA$.\n",
38 | "\n",
39 | "Lastly, we have `extend`, which is just another way of using these natural transformations.\n",
40 | "More specifically, $\\text{extend}:(WA\\to B)\\times WA \\to WB$. Thus, given a function $f:WA \\to B$, and a value\n",
41 | " $x$ of $WA$, the `extend` simply computes \n",
42 | "$$\n",
43 | "\\text{extend}(f,x) := Wf \\circ \\delta\n",
44 | "$$\n",
45 | "Note that, $Wf: WWA\\to WB$, thus $Wf \\circ \\delta_A: WA \\to W B$.\n",
46 | "\n",
47 | "\n",
48 | "According to [this](https://github.com/Moelf/functional-programming-jargon.jl?tab=readme-ov-file#equational-reasoning]),\n",
49 | "it is an object that has extract and extend functions. Ref is a natural condidate:"
50 | ]
51 | },
52 | {
53 | "cell_type": "code",
54 | "execution_count": 2,
55 | "id": "67e8d481-fa4e-40ee-91bf-da92be86fe59",
56 | "metadata": {},
57 | "outputs": [
58 | {
59 | "data": {
60 | "text/plain": [
61 | "true"
62 | ]
63 | },
64 | "execution_count": 2,
65 | "metadata": {},
66 | "output_type": "execute_result"
67 | }
68 | ],
69 | "source": [
70 | "fmap(f::Function,x::Ref) = Ref(f(x[]))\n",
71 | "\n",
72 | "extract(x::Ref) = x[]\n",
73 | "extend(f,x::T) where T<:Ref = T(f(x[]))\n",
74 | "duplicate(wa::Ref) = Ref(wa)\n",
75 | "\n",
76 | "extract(Ref(10))\n",
77 | "\n",
78 | "extend(x->3,Ref(1.0))\n",
79 | "\n",
80 | "ext(f::Function,x::Ref) = fmap(f,duplicate(x))\n",
81 | "\n",
82 | "\n",
83 | "ext(x->3,Ref(1.0))[] == extend(x->3,Ref(1.0))[]"
84 | ]
85 | },
86 | {
87 | "cell_type": "markdown",
88 | "id": "0c65d71c-be38-4255-9563-b26e50f91722",
89 | "metadata": {},
90 | "source": [
91 | "### Non-empty Lists\n",
92 | "\n",
93 | "Let $F_A X = 1 + A \\times X$, the list of A functor is the fixed point \n",
94 | "$$\n",
95 | "\\mu L_A X= 1 + A \\times \\mu L_A X\n",
96 | "$$\n",
97 | "\n",
98 | "Another example of comonad is the non-empty list:\n",
99 | "$$\n",
100 | "NL_A X = A + \\mu L_A\n",
101 | "$$"
102 | ]
103 | },
104 | {
105 | "cell_type": "code",
106 | "execution_count": 42,
107 | "id": "4994b04a-5b1e-4a4a-909a-03338e634bfb",
108 | "metadata": {},
109 | "outputs": [
110 | {
111 | "data": {
112 | "text/plain": [
113 | "1-element Vector{Int64}:\n",
114 | " 23"
115 | ]
116 | },
117 | "execution_count": 42,
118 | "metadata": {},
119 | "output_type": "execute_result"
120 | }
121 | ],
122 | "source": [
123 | "[1,23][begin+1:end]"
124 | ]
125 | },
126 | {
127 | "cell_type": "code",
128 | "execution_count": 55,
129 | "id": "3c9ea153-ec0a-4a83-8352-8b819003c78c",
130 | "metadata": {},
131 | "outputs": [
132 | {
133 | "data": {
134 | "text/plain": [
135 | "NL{Any}(NL{Int64}(0, [1, 2, 3, 4]), Any[NL{Int64}(1, [2, 3, 4]), NL{Int64}(2, [3, 4]), NL{Int64}(3, [4]), NL{Int64}(4, Int64[])])"
136 | ]
137 | },
138 | "execution_count": 55,
139 | "metadata": {},
140 | "output_type": "execute_result"
141 | }
142 | ],
143 | "source": [
144 | "struct NL{A}\n",
145 | " head::A\n",
146 | " tail::Vector{A}\n",
147 | "end\n",
148 | "NL(a::A) where A = NL(a,A[])\n",
149 | "\n",
150 | "ϵ(nl::NL) = nl.head\n",
151 | "\n",
152 | "δ(tail::Vector) = begin\n",
153 | " if tail == []\n",
154 | " return []\n",
155 | " end\n",
156 | " vcat(NL(tail[1], tail[2:end]), lst2nlst(tail[2:end]))\n",
157 | "end\n",
158 | "δ(nl::NL) = NL(nl,δ(nl.tail))\n",
159 | "\n",
160 | "nl = NL(0,[1,2,3,4])\n",
161 | "\n",
162 | "δ(nl)"
163 | ]
164 | },
165 | {
166 | "cell_type": "code",
167 | "execution_count": 57,
168 | "id": "19573826-ee5a-4d1d-8380-f847a3ce6eb2",
169 | "metadata": {},
170 | "outputs": [
171 | {
172 | "data": {
173 | "text/plain": [
174 | "NL{Any}(NL{Any}(0, Any[]), Any[])"
175 | ]
176 | },
177 | "execution_count": 57,
178 | "metadata": {},
179 | "output_type": "execute_result"
180 | }
181 | ],
182 | "source": [
183 | "nl = NL(0,[])\n",
184 | "δ(nl)"
185 | ]
186 | },
187 | {
188 | "cell_type": "code",
189 | "execution_count": null,
190 | "id": "0dd38bf9-36d8-44ce-80f8-5908fdd9ffc2",
191 | "metadata": {},
192 | "outputs": [],
193 | "source": []
194 | }
195 | ],
196 | "metadata": {
197 | "kernelspec": {
198 | "display_name": "Julia-lts 1.10.7",
199 | "language": "julia",
200 | "name": "julia-lts-1.10"
201 | },
202 | "language_info": {
203 | "file_extension": ".jl",
204 | "mimetype": "application/julia",
205 | "name": "julia",
206 | "version": "1.10.7"
207 | }
208 | },
209 | "nbformat": 4,
210 | "nbformat_minor": 5
211 | }
212 |
--------------------------------------------------------------------------------
/CategoryTheory/Currier.jl:
--------------------------------------------------------------------------------
1 | module Currier
2 |
3 | export @curried, @reverse_curried
4 |
5 | struct FullyCurried end
6 |
7 | macro curried(fdef)
8 | f = esc(fdef.args[1].args[1])
9 | fargs = esc.(fdef.args[1].args[2:end])
10 | arity = length(fargs)
11 | body = esc(fdef.args[2])
12 | err_str = "Too many arguments. Function $f only takes $arity arguments"
13 | quote
14 | begin
15 | function $f(args...)
16 | if length(args) < $arity
17 | x -> $f((args..., x)...)
18 | elseif length(args) == $arity
19 | $f(FullyCurried(), args...)
20 | else
21 | throw($err_str)
22 | end
23 | end
24 | $f(::FullyCurried, $(fargs...)) = $body
25 | end
26 | end
27 | end
28 |
29 | macro reverse_curried(fdef)
30 | f = esc(fdef.args[1].args[1])
31 | fargs = esc.(fdef.args[1].args[2:end])
32 | arity = length(fargs)
33 | body = esc(fdef.args[2])
34 | err_str = "Too many arguments. Function $f only takes $arity arguments"
35 | quote
36 | begin
37 | function $f(args...)
38 | if length(args) < $arity
39 | x -> $f((x, args...)...)
40 | elseif length(args) == $arity
41 | $f(FullyCurried(), args...)
42 | else
43 | throw($err_str)
44 | end
45 | end
46 | $f(::FullyCurried, $(fargs...)) = $body
47 | end
48 | end
49 | end
50 |
51 |
52 | end # module
53 |
--------------------------------------------------------------------------------
/CategoryTheory/Do Operator.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "8ad74696-f951-45ff-9c9c-4ab198cadeac",
6 | "metadata": {},
7 | "source": [
8 | "# Getting Rid of For-Loops with Do-Block\n",
9 | "by: Nicolau Leal Werneck\n",
10 | "\n",
11 | "[Check this talk](https://live.juliacon.org/talk/WKNY78)"
12 | ]
13 | },
14 | {
15 | "cell_type": "markdown",
16 | "id": "03523db8-9fed-4369-a5a7-e008acac14c8",
17 | "metadata": {},
18 | "source": [
19 | "### A Simple Loop"
20 | ]
21 | },
22 | {
23 | "cell_type": "code",
24 | "execution_count": 3,
25 | "id": "b2d6d602-9024-4c25-aa7e-70d8a8b2aa60",
26 | "metadata": {},
27 | "outputs": [
28 | {
29 | "data": {
30 | "text/plain": [
31 | "3-element Vector{Int64}:\n",
32 | " 1\n",
33 | " 4\n",
34 | " 9"
35 | ]
36 | },
37 | "execution_count": 3,
38 | "metadata": {},
39 | "output_type": "execute_result"
40 | }
41 | ],
42 | "source": [
43 | "a1 = [j*j for j in 1:3]"
44 | ]
45 | },
46 | {
47 | "cell_type": "code",
48 | "execution_count": 4,
49 | "id": "4331f85b-db55-4202-9697-00cc41917d4a",
50 | "metadata": {},
51 | "outputs": [
52 | {
53 | "data": {
54 | "text/plain": [
55 | "3-element Vector{Int64}:\n",
56 | " 1\n",
57 | " 4\n",
58 | " 9"
59 | ]
60 | },
61 | "execution_count": 4,
62 | "metadata": {},
63 | "output_type": "execute_result"
64 | }
65 | ],
66 | "source": [
67 | "a1 = map(1:3) do j j*j end"
68 | ]
69 | },
70 | {
71 | "cell_type": "markdown",
72 | "id": "6bceccf1-eb45-4e57-8a8b-362425b74be5",
73 | "metadata": {},
74 | "source": [
75 | "### A Nested Loop"
76 | ]
77 | },
78 | {
79 | "cell_type": "code",
80 | "execution_count": 5,
81 | "id": "8cf567d3-fe4a-43ba-907e-f54a6d602101",
82 | "metadata": {},
83 | "outputs": [
84 | {
85 | "data": {
86 | "text/plain": [
87 | "12-element Vector{Int64}:\n",
88 | " 2\n",
89 | " 3\n",
90 | " 4\n",
91 | " 5\n",
92 | " 2\n",
93 | " 6\n",
94 | " 8\n",
95 | " 10\n",
96 | " 3\n",
97 | " 6\n",
98 | " 12\n",
99 | " 15"
100 | ]
101 | },
102 | "execution_count": 5,
103 | "metadata": {},
104 | "output_type": "execute_result"
105 | }
106 | ],
107 | "source": [
108 | "[j*k for j in 1:3 for k in 1:5 if j != k]"
109 | ]
110 | },
111 | {
112 | "cell_type": "code",
113 | "execution_count": 11,
114 | "id": "576e13a7-9019-4b68-9674-5ed6e630ae79",
115 | "metadata": {},
116 | "outputs": [
117 | {
118 | "data": {
119 | "text/plain": [
120 | "12-element Vector{Any}:\n",
121 | " 2\n",
122 | " 3\n",
123 | " 4\n",
124 | " 5\n",
125 | " 2\n",
126 | " 6\n",
127 | " 8\n",
128 | " 10\n",
129 | " 3\n",
130 | " 6\n",
131 | " 12\n",
132 | " 15"
133 | ]
134 | },
135 | "execution_count": 11,
136 | "metadata": {},
137 | "output_type": "execute_result"
138 | }
139 | ],
140 | "source": [
141 | "a = []\n",
142 | "for j in 1:3\n",
143 | " for k in 1:5\n",
144 | " j != k ? push!(a, j*k) : continue\n",
145 | " end\n",
146 | "end\n",
147 | "a"
148 | ]
149 | },
150 | {
151 | "cell_type": "markdown",
152 | "id": "a59745ff-5842-4ec7-9bfc-a7eecfe0ab94",
153 | "metadata": {},
154 | "source": [
155 | "Let's now use the do-block. For this, we'll need to use `flatten` and create a `flatmap`. "
156 | ]
157 | },
158 | {
159 | "cell_type": "code",
160 | "execution_count": 16,
161 | "id": "b14a31aa-6c84-4dde-a3c0-03b0adef6153",
162 | "metadata": {},
163 | "outputs": [
164 | {
165 | "data": {
166 | "text/plain": [
167 | "6-element Vector{Any}:\n",
168 | " 1\n",
169 | " 2\n",
170 | " 3\n",
171 | " 'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)\n",
172 | " 'b': ASCII/Unicode U+0062 (category Ll: Letter, lowercase)\n",
173 | " 'c': ASCII/Unicode U+0063 (category Ll: Letter, lowercase)"
174 | ]
175 | },
176 | "execution_count": 16,
177 | "metadata": {},
178 | "output_type": "execute_result"
179 | }
180 | ],
181 | "source": [
182 | "collect(Iterators.flatten((1:3,'a':'c')))"
183 | ]
184 | },
185 | {
186 | "cell_type": "code",
187 | "execution_count": 17,
188 | "id": "5508d3cb-a43c-44c7-a2a9-398e5cbea573",
189 | "metadata": {},
190 | "outputs": [
191 | {
192 | "data": {
193 | "text/plain": [
194 | "5-element Vector{Any}:\n",
195 | " 1\n",
196 | " 2\n",
197 | " 3\n",
198 | " \"ok\"\n",
199 | " \"nope\""
200 | ]
201 | },
202 | "execution_count": 17,
203 | "metadata": {},
204 | "output_type": "execute_result"
205 | }
206 | ],
207 | "source": [
208 | "collect(Iterators.flatten((1:3,[\"ok\", \"nope\"])))"
209 | ]
210 | },
211 | {
212 | "cell_type": "markdown",
213 | "id": "01491f75-5902-4d3a-bf33-448f5ac2138c",
214 | "metadata": {},
215 | "source": [
216 | "Note that `flatten` creates a generator that \"concatenates\" the two \"lists\"."
217 | ]
218 | },
219 | {
220 | "cell_type": "code",
221 | "execution_count": 19,
222 | "id": "de71703a-2e8c-411c-ac1b-a6c7757209d8",
223 | "metadata": {},
224 | "outputs": [],
225 | "source": [
226 | "flatmap(f,x) = collect(Iterators.flatten(map(f,x)));"
227 | ]
228 | },
229 | {
230 | "cell_type": "code",
231 | "execution_count": 24,
232 | "id": "ee898de0-3022-4091-b6f0-c0a6e256ae31",
233 | "metadata": {},
234 | "outputs": [
235 | {
236 | "data": {
237 | "text/plain": [
238 | "12-element Vector{Int64}:\n",
239 | " 2\n",
240 | " 3\n",
241 | " 4\n",
242 | " 5\n",
243 | " 2\n",
244 | " 6\n",
245 | " 8\n",
246 | " 10\n",
247 | " 3\n",
248 | " 6\n",
249 | " 12\n",
250 | " 15"
251 | ]
252 | },
253 | "execution_count": 24,
254 | "metadata": {},
255 | "output_type": "execute_result"
256 | }
257 | ],
258 | "source": [
259 | "flatmap(1:3) do j\n",
260 | " flatmap(1:5) do k\n",
261 | " j != k ? (j*k,) : ()\n",
262 | " end\n",
263 | "end"
264 | ]
265 | },
266 | {
267 | "cell_type": "code",
268 | "execution_count": null,
269 | "id": "4a37493c-5ee3-4070-a99f-5d5f4580f4a0",
270 | "metadata": {},
271 | "outputs": [],
272 | "source": []
273 | }
274 | ],
275 | "metadata": {
276 | "kernelspec": {
277 | "display_name": "Julia 1.10.0",
278 | "language": "julia",
279 | "name": "julia-1.10"
280 | },
281 | "language_info": {
282 | "file_extension": ".jl",
283 | "mimetype": "application/julia",
284 | "name": "julia",
285 | "version": "1.10.0"
286 | }
287 | },
288 | "nbformat": 4,
289 | "nbformat_minor": 5
290 | }
291 |
--------------------------------------------------------------------------------
/CategoryTheory/Extra - MLStyle ADT.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "3601013b-0ff6-48cc-b4b5-e45bc984630d",
6 | "metadata": {},
7 | "source": [
8 | "# 5. MLStyle for ADT\n",
9 | "\n",
10 | "MLStyle.jl is a Julia package that provides functionality for Functional Programming.\n",
11 | "One of the things it provides are Algebraic Data Types (ADT). I'll show how to do it in Julia,\n",
12 | "but then I'll use MLStyle to show how easier it can be."
13 | ]
14 | },
15 | {
16 | "cell_type": "code",
17 | "execution_count": 1,
18 | "id": "5bad0cc7-4a2d-4db0-8273-da98deb627a3",
19 | "metadata": {},
20 | "outputs": [
21 | {
22 | "name": "stderr",
23 | "output_type": "stream",
24 | "text": [
25 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/MEGA/EMAP/PhDThesis/notes/FunctionalProgrammingCategoryTheory/julia`\n"
26 | ]
27 | }
28 | ],
29 | "source": [
30 | "using Pkg\n",
31 | "Pkg.activate(\".\")"
32 | ]
33 | },
34 | {
35 | "cell_type": "code",
36 | "execution_count": 2,
37 | "id": "ce355190-d6b6-47b0-ad8f-53af85ac8379",
38 | "metadata": {},
39 | "outputs": [
40 | {
41 | "name": "stderr",
42 | "output_type": "stream",
43 | "text": [
44 | "\u001b[32m\u001b[1m Updating\u001b[22m\u001b[39m registry at `~/.julia/registries/General.toml`\n",
45 | "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n",
46 | "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/MEGA/EMAP/PhDThesis/notes/FunctionalProgrammingCategoryTheory/julia/Project.toml`\n",
47 | "\u001b[32m\u001b[1m No Changes\u001b[22m\u001b[39m to `~/MEGA/EMAP/PhDThesis/notes/FunctionalProgrammingCategoryTheory/julia/Manifest.toml`\n"
48 | ]
49 | }
50 | ],
51 | "source": [
52 | "Pkg.add(\"MLStyle\")"
53 | ]
54 | },
55 | {
56 | "cell_type": "code",
57 | "execution_count": 3,
58 | "id": "209053e9-ee2a-4cc8-9413-a379b6e3f9fc",
59 | "metadata": {},
60 | "outputs": [],
61 | "source": [
62 | "using MLStyle"
63 | ]
64 | },
65 | {
66 | "cell_type": "code",
67 | "execution_count": 4,
68 | "id": "91e7ec63-be43-4a4e-ad73-6e27c513e2f1",
69 | "metadata": {},
70 | "outputs": [],
71 | "source": [
72 | "@data Arith begin\n",
73 | " Number(Int)\n",
74 | " Add(Arith, Arith)\n",
75 | " Minus(Arith, Arith)\n",
76 | " Mult(Arith, Arith)\n",
77 | " Divide(Arith, Arith)\n",
78 | "end"
79 | ]
80 | },
81 | {
82 | "cell_type": "markdown",
83 | "id": "ef00a6d5-bf55-407d-9854-db36ab113ea1",
84 | "metadata": {},
85 | "source": [
86 | "The code above created an abstract type Arith, and several subtypes of it. \n",
87 | "\n",
88 | "Here is how to do in basic Julia code."
89 | ]
90 | },
91 | {
92 | "cell_type": "code",
93 | "execution_count": 5,
94 | "id": "193c677b-e7c1-4e6c-bf66-a8dc0336f736",
95 | "metadata": {},
96 | "outputs": [],
97 | "source": [
98 | "abstract type Arith2 end\n",
99 | "struct Number2 <: Arith2\n",
100 | " _1::Int\n",
101 | "end\n",
102 | "\n",
103 | "struct Add2 <: Arith2\n",
104 | " _1::Arith2\n",
105 | " _2::Arith2\n",
106 | "end"
107 | ]
108 | },
109 | {
110 | "cell_type": "markdown",
111 | "id": "556ec630-60a6-4e36-a82a-52ff608d8b54",
112 | "metadata": {},
113 | "source": [
114 | "Next, we want to define functions over these types. \n",
115 | "In Functional Programming language this is done via pattern matching."
116 | ]
117 | },
118 | {
119 | "cell_type": "code",
120 | "execution_count": 6,
121 | "id": "c4453222-3c71-4bc9-8981-14ea439f1e41",
122 | "metadata": {},
123 | "outputs": [
124 | {
125 | "data": {
126 | "text/plain": [
127 | "eval_arith (generic function with 1 method)"
128 | ]
129 | },
130 | "execution_count": 6,
131 | "metadata": {},
132 | "output_type": "execute_result"
133 | }
134 | ],
135 | "source": [
136 | "eval_arith(arith :: Arith) =\n",
137 | " # locally and hygienically change the meaning of '!'\n",
138 | " let ! = eval_arith\n",
139 | " @match arith begin\n",
140 | " Number(v) => v\n",
141 | " Add(fst, snd) => !fst + !snd\n",
142 | " Minus(fst, snd) => !fst - !snd\n",
143 | " Mult(fst, snd) => !fst * !snd\n",
144 | " Divide(fst, snd) => !fst / !snd\n",
145 | " end\n",
146 | " end"
147 | ]
148 | },
149 | {
150 | "cell_type": "markdown",
151 | "id": "7ced8f34-477c-494e-844b-6f19918ecaea",
152 | "metadata": {},
153 | "source": [
154 | "The awesome thing about the code above is that it already works recursively.\n",
155 | "For this to work, the code above is overloading the `!`, in order to more beautifully\n",
156 | "apply the funciton recursively.\n",
157 | "Check the example below: "
158 | ]
159 | },
160 | {
161 | "cell_type": "code",
162 | "execution_count": 7,
163 | "id": "e4dd7747-d317-440d-9661-620c51426c35",
164 | "metadata": {},
165 | "outputs": [
166 | {
167 | "data": {
168 | "text/plain": [
169 | "-1.5"
170 | ]
171 | },
172 | "execution_count": 7,
173 | "metadata": {},
174 | "output_type": "execute_result"
175 | }
176 | ],
177 | "source": [
178 | "# This is what we have below (2 - (2 + (3 * (2/4)))) \n",
179 | "eval_arith(\n",
180 | " Minus(\n",
181 | " Number(2),\n",
182 | " Add(Number(2),\n",
183 | " Mult(Number(3),\n",
184 | " Divide(Number(2),Number(4)))\n",
185 | " )))"
186 | ]
187 | }
188 | ],
189 | "metadata": {
190 | "kernelspec": {
191 | "display_name": "Julia 1.8.1",
192 | "language": "julia",
193 | "name": "julia-1.8"
194 | },
195 | "language_info": {
196 | "file_extension": ".jl",
197 | "mimetype": "application/julia",
198 | "name": "julia",
199 | "version": "1.8.1"
200 | }
201 | },
202 | "nbformat": 4,
203 | "nbformat_minor": 5
204 | }
205 |
--------------------------------------------------------------------------------
/CategoryTheory/Extra/1_Vizagrams.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 2,
6 | "id": "a0b11ded-236f-4ecc-af6b-4be5b8153b0d",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Documents/GitHub/CTViz_Workshop/Julia`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg\n",
19 | "Pkg.activate(\".\")"
20 | ]
21 | },
22 | {
23 | "cell_type": "code",
24 | "execution_count": 3,
25 | "id": "a7f27c6b-92c6-4f95-8c39-43024c1e16d3",
26 | "metadata": {},
27 | "outputs": [
28 | {
29 | "name": "stderr",
30 | "output_type": "stream",
31 | "text": [
32 | "\u001b[36m\u001b[1m[ \u001b[22m\u001b[39m\u001b[36m\u001b[1mInfo: \u001b[22m\u001b[39mPrecompiling Vizagrams [8c229dad-8b3a-4031-83d6-73545c88426d] (cache misses: wrong dep version loaded (2), incompatible header (12), dep missing source (6))\n"
33 | ]
34 | }
35 | ],
36 | "source": [
37 | "using Vizagrams"
38 | ]
39 | },
40 | {
41 | "cell_type": "code",
42 | "execution_count": 4,
43 | "id": "a7a9a346-76a7-4c5d-a828-e250e7f6776b",
44 | "metadata": {},
45 | "outputs": [
46 | {
47 | "data": {
48 | "image/svg+xml": [
49 | "\n",
50 | ""
51 | ],
52 | "text/html": [
53 | ""
54 | ],
55 | "text/plain": [
56 | ""
57 | ]
58 | },
59 | "execution_count": 4,
60 | "metadata": {},
61 | "output_type": "execute_result"
62 | }
63 | ],
64 | "source": [
65 | "d = Circle()\n",
66 | "\n",
67 | "draw(d)"
68 | ]
69 | },
70 | {
71 | "cell_type": "code",
72 | "execution_count": 13,
73 | "id": "2ffaed37-c713-4867-9dc5-b8634b78a03c",
74 | "metadata": {},
75 | "outputs": [
76 | {
77 | "data": {
78 | "image/svg+xml": [
79 | "\n",
80 | ""
81 | ],
82 | "text/html": [
83 | ""
84 | ],
85 | "text/plain": [
86 | ""
87 | ]
88 | },
89 | "execution_count": 13,
90 | "metadata": {},
91 | "output_type": "execute_result"
92 | }
93 | ],
94 | "source": [
95 | "d = S()TextMark(text=\"\")\n",
96 | "draw(d)\n",
97 | "\n",
98 | "# envelope(d,[1,0])"
99 | ]
100 | },
101 | {
102 | "cell_type": "code",
103 | "execution_count": 16,
104 | "id": "7f7dbdcb-05ff-4d04-8963-de505e8834c5",
105 | "metadata": {},
106 | "outputs": [],
107 | "source": [
108 | "TextGeom(fontsize=15, text=\"hello\")\n",
109 | "TextGeom(\"hello\", [0, 0], 15, 0, \"Helvetica\")\n",
110 | "\n",
111 | "envelope(TextGeom(fontsize=15, text=\"\"), S(), [1,0])"
112 | ]
113 | },
114 | {
115 | "cell_type": "code",
116 | "execution_count": 22,
117 | "id": "031d5c08-7b8e-4843-aa08-e0d45415893a",
118 | "metadata": {},
119 | "outputs": [
120 | {
121 | "ename": "LoadError",
122 | "evalue": "BoundsError: attempt to access 0-element Vector{Vector{Vector{Float32}}} at index [1]",
123 | "output_type": "error",
124 | "traceback": [
125 | "BoundsError: attempt to access 0-element Vector{Vector{Vector{Float32}}} at index [1]",
126 | "",
127 | "Stacktrace:",
128 | " [1] throw_boundserror(A::Vector{Vector{Vector{Float32}}}, I::Tuple{Int64})",
129 | " @ Base ./essentials.jl:14",
130 | " [2] getindex",
131 | " @ ./essentials.jl:916 [inlined]",
132 | " [3] stringinkbox(face::FreeTypeAbstraction.FTFont, str::String)",
133 | " @ Vizagrams ~/.julia/packages/Vizagrams/mVsVF/src/primitives/envelopes.jl:96",
134 | " [4] top-level scope",
135 | " @ In[22]:1"
136 | ]
137 | }
138 | ],
139 | "source": [
140 | "Vizagrams.stringinkbox(Vizagrams.load_font(\"helvetica\"),\"\")"
141 | ]
142 | }
143 | ],
144 | "metadata": {
145 | "kernelspec": {
146 | "display_name": "Julia 1.11.2",
147 | "language": "julia",
148 | "name": "julia-1.11"
149 | },
150 | "language_info": {
151 | "file_extension": ".jl",
152 | "mimetype": "application/julia",
153 | "name": "julia",
154 | "version": "1.11.2"
155 | }
156 | },
157 | "nbformat": 4,
158 | "nbformat_minor": 5
159 | }
160 |
--------------------------------------------------------------------------------
/CategoryTheory/Extra/CategoricalDataBases.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "85345e29-fa94-4901-8139-e72e8c73740a",
6 | "metadata": {},
7 | "source": [
8 | "# Category Theory Applied to DataBases"
9 | ]
10 | },
11 | {
12 | "cell_type": "code",
13 | "execution_count": 132,
14 | "id": "9b872703-bb22-41c7-b192-5f99e3f249c1",
15 | "metadata": {},
16 | "outputs": [
17 | {
18 | "name": "stderr",
19 | "output_type": "stream",
20 | "text": [
21 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Documents/GitHub/CTViz_Workshop/Julia`\n"
22 | ]
23 | }
24 | ],
25 | "source": [
26 | "using Pkg\n",
27 | "Pkg.activate(\".\")\n",
28 | "using Tables"
29 | ]
30 | },
31 | {
32 | "cell_type": "code",
33 | "execution_count": 133,
34 | "id": "f0e82c66-0e9d-4ea6-8098-e16d8637467c",
35 | "metadata": {},
36 | "outputs": [
37 | {
38 | "data": {
39 | "text/plain": [
40 | "Tables.Schema:\n",
41 | " :x Real\n",
42 | " :y Real\n",
43 | " :z String"
44 | ]
45 | },
46 | "execution_count": 133,
47 | "metadata": {},
48 | "output_type": "execute_result"
49 | }
50 | ],
51 | "source": [
52 | "S1 = Tables.Schema([:a,:b],[Real,String])\n",
53 | "S2 = Tables.Schema([:x,:y,:z],[Real,Real,String])"
54 | ]
55 | },
56 | {
57 | "cell_type": "code",
58 | "execution_count": 134,
59 | "id": "309660f7-d393-4c49-b6ef-872f51fd9133",
60 | "metadata": {},
61 | "outputs": [],
62 | "source": [
63 | "using DataFrames"
64 | ]
65 | },
66 | {
67 | "cell_type": "code",
68 | "execution_count": 140,
69 | "id": "eec894a6-e194-45e4-90f6-88c6a70f478f",
70 | "metadata": {},
71 | "outputs": [],
72 | "source": [
73 | "df = DataFrame(x=Real[1,2,3],y=Real[1,1,1],z=Real[0,0,0]);"
74 | ]
75 | },
76 | {
77 | "cell_type": "code",
78 | "execution_count": 141,
79 | "id": "b998148c-0a9a-45b2-992c-873a6e4a1da1",
80 | "metadata": {},
81 | "outputs": [
82 | {
83 | "data": {
84 | "text/plain": [
85 | "Tables.Schema:\n",
86 | " :x Real\n",
87 | " :y Real\n",
88 | " :z Real"
89 | ]
90 | },
91 | "execution_count": 141,
92 | "metadata": {},
93 | "output_type": "execute_result"
94 | }
95 | ],
96 | "source": [
97 | "Tables.schema(df)"
98 | ]
99 | },
100 | {
101 | "cell_type": "code",
102 | "execution_count": 143,
103 | "id": "070e88ff-f8f5-4841-95c2-338c396bed1e",
104 | "metadata": {},
105 | "outputs": [
106 | {
107 | "data": {
108 | "text/plain": [
109 | "ΔF (generic function with 1 method)"
110 | ]
111 | },
112 | "execution_count": 143,
113 | "metadata": {},
114 | "output_type": "execute_result"
115 | }
116 | ],
117 | "source": [
118 | "F = Dict(:a=>(:x,x->x+1),:b=>(:y,string))\n",
119 | "function δF(df,F,col)\n",
120 | " map(F[col][2],df[!,F[col][1]])\n",
121 | "end\n",
122 | "function ΔF(df,F)\n",
123 | " DataFrame(map(k->k=>δF(df,F,k),collect(keys(F))))\n",
124 | "end"
125 | ]
126 | },
127 | {
128 | "cell_type": "code",
129 | "execution_count": 144,
130 | "id": "71663845-6434-4478-a6b7-e488596c8623",
131 | "metadata": {},
132 | "outputs": [
133 | {
134 | "data": {
135 | "text/plain": [
136 | "3-element Vector{String}:\n",
137 | " \"1\"\n",
138 | " \"1\"\n",
139 | " \"1\""
140 | ]
141 | },
142 | "execution_count": 144,
143 | "metadata": {},
144 | "output_type": "execute_result"
145 | }
146 | ],
147 | "source": [
148 | "δF(df,F,:b)"
149 | ]
150 | },
151 | {
152 | "cell_type": "code",
153 | "execution_count": 145,
154 | "id": "593a6c4a-85cd-4e80-a857-854bfc9aa182",
155 | "metadata": {},
156 | "outputs": [
157 | {
158 | "data": {
159 | "text/html": [
160 | "
"
161 | ],
162 | "text/latex": [
163 | "\\begin{tabular}{r|cc}\n",
164 | "\t& a & b\\\\\n",
165 | "\t\\hline\n",
166 | "\t& Int64 & String\\\\\n",
167 | "\t\\hline\n",
168 | "\t1 & 2 & 1 \\\\\n",
169 | "\t2 & 3 & 1 \\\\\n",
170 | "\t3 & 4 & 1 \\\\\n",
171 | "\\end{tabular}\n"
172 | ],
173 | "text/plain": [
174 | "\u001b[1m3×2 DataFrame\u001b[0m\n",
175 | "\u001b[1m Row \u001b[0m│\u001b[1m a \u001b[0m\u001b[1m b \u001b[0m\n",
176 | " │\u001b[90m Int64 \u001b[0m\u001b[90m String \u001b[0m\n",
177 | "─────┼───────────────\n",
178 | " 1 │ 2 1\n",
179 | " 2 │ 3 1\n",
180 | " 3 │ 4 1"
181 | ]
182 | },
183 | "execution_count": 145,
184 | "metadata": {},
185 | "output_type": "execute_result"
186 | }
187 | ],
188 | "source": [
189 | "ΔF(df,F)"
190 | ]
191 | },
192 | {
193 | "cell_type": "code",
194 | "execution_count": null,
195 | "id": "1d90e1e4-4bc8-405f-ba86-75f1d6e1ef6c",
196 | "metadata": {},
197 | "outputs": [],
198 | "source": []
199 | }
200 | ],
201 | "metadata": {
202 | "kernelspec": {
203 | "display_name": "julia 1.11.3",
204 | "language": "julia",
205 | "name": "julia-1.11"
206 | },
207 | "language_info": {
208 | "file_extension": ".jl",
209 | "mimetype": "application/julia",
210 | "name": "julia",
211 | "version": "1.11.3"
212 | }
213 | },
214 | "nbformat": 4,
215 | "nbformat_minor": 5
216 | }
217 |
--------------------------------------------------------------------------------
/CategoryTheory/Extra/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
3 | JLLWrappers = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
4 | MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
5 | StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
6 | Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
7 | Vizagrams = "8c229dad-8b3a-4031-83d6-73545c88426d"
8 |
--------------------------------------------------------------------------------
/CategoryTheory/Extra/StateMonad.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "0e45698c-2c4d-4065-86b2-f675b243c9cd",
6 | "metadata": {},
7 | "source": [
8 | "# State Monad\n",
9 | "\n",
10 | "```haskell\n",
11 | "newtype State s a = State (s -> (a, s))\n",
12 | "```"
13 | ]
14 | },
15 | {
16 | "cell_type": "code",
17 | "execution_count": 1,
18 | "id": "c8526fc1-bcfb-4325-9e14-7244420f3093",
19 | "metadata": {},
20 | "outputs": [
21 | {
22 | "name": "stderr",
23 | "output_type": "stream",
24 | "text": [
25 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Documents/GitHub/CTViz_Workshop/Julia`\n"
26 | ]
27 | }
28 | ],
29 | "source": [
30 | "using Pkg\n",
31 | "Pkg.activate(\".\")"
32 | ]
33 | },
34 | {
35 | "cell_type": "code",
36 | "execution_count": 16,
37 | "id": "9e4929e9-1800-4b8e-b0db-c67521f0b443",
38 | "metadata": {},
39 | "outputs": [
40 | {
41 | "name": "stdout",
42 | "output_type": "stream",
43 | "text": [
44 | "s1(1) = (0, 1)\n",
45 | "s2(1) = (1, 1)\n",
46 | "s3(1) = (2, 1)\n"
47 | ]
48 | }
49 | ],
50 | "source": [
51 | "struct State{S}\n",
52 | " \"s->(a,s)\"\n",
53 | " f::Function\n",
54 | "end\n",
55 | "\n",
56 | "# runstate is the same as doing s(s)\n",
57 | "runstate(state::State{S}, g::S) where S = state.f(g)\n",
58 | "function (s::State)(g)\n",
59 | " s.f(g)\n",
60 | "end\n",
61 | "\n",
62 | "fmap(f::Function, state::State{S}) where S = State{S}(\n",
63 | " s-> begin\n",
64 | " a,s_new = runstate(state,s)\n",
65 | " f(a), s_new\n",
66 | " end\n",
67 | ")\n",
68 | "\n",
69 | "s1 = State{Int}(s::Int-> (0,s))\n",
70 | "runstate(s1, 1) == s1(1)\n",
71 | "@show s1(1);\n",
72 | "\n",
73 | "s2 = fmap(x->x+1,s1)\n",
74 | "@show s2(1);\n",
75 | "\n",
76 | "s3 = fmap(x->x+1,s2)\n",
77 | "@show s3(1);"
78 | ]
79 | },
80 | {
81 | "cell_type": "code",
82 | "execution_count": null,
83 | "id": "c0bd06bb-31ea-44c0-97cb-d0a30e3fae80",
84 | "metadata": {},
85 | "outputs": [],
86 | "source": []
87 | },
88 | {
89 | "cell_type": "code",
90 | "execution_count": null,
91 | "id": "f49b3403-a5a7-4247-90ea-82e3776001ac",
92 | "metadata": {},
93 | "outputs": [],
94 | "source": []
95 | },
96 | {
97 | "cell_type": "code",
98 | "execution_count": null,
99 | "id": "b820775a-71d5-442d-a665-ff43f624df16",
100 | "metadata": {},
101 | "outputs": [],
102 | "source": [
103 | "function (s::State)(state = nothing)\n",
104 | " s.f(state)\n",
105 | "end\n",
106 | "\n",
107 | "fmap(f::Function, g::State) = State(s-> begin\n",
108 | " a,s_new = g(s)\n",
109 | " f(a), s_new\n",
110 | " end)\n",
111 | "\n",
112 | "s1 = State(s -> (0, s))\n",
113 | "s1_update = fmap(x->x+2,s1)\n",
114 | "\n",
115 | "s1_update(\"ok\")"
116 | ]
117 | },
118 | {
119 | "cell_type": "code",
120 | "execution_count": null,
121 | "id": "bb20b881-c238-46c1-9470-72b442fe5dda",
122 | "metadata": {},
123 | "outputs": [],
124 | "source": []
125 | },
126 | {
127 | "cell_type": "code",
128 | "execution_count": 30,
129 | "id": "b6846386-9036-4acb-a12c-9f516ebbc625",
130 | "metadata": {},
131 | "outputs": [
132 | {
133 | "data": {
134 | "text/plain": [
135 | "220.0"
136 | ]
137 | },
138 | "execution_count": 30,
139 | "metadata": {},
140 | "output_type": "execute_result"
141 | }
142 | ],
143 | "source": [
144 | "sumlist(n) = n*(n+1)/2\n",
145 | "\n",
146 | "sumlist(10)\n",
147 | "split(n) = 0:n |> collect\n",
148 | "split(10) |> sum\n",
149 | "\n",
150 | "sum(map(sumlist,split(10)))"
151 | ]
152 | }
153 | ],
154 | "metadata": {
155 | "kernelspec": {
156 | "display_name": "Julia-lts 1.10.7",
157 | "language": "julia",
158 | "name": "julia-lts-1.10"
159 | },
160 | "language_info": {
161 | "file_extension": ".jl",
162 | "mimetype": "application/julia",
163 | "name": "julia",
164 | "version": "1.10.7"
165 | }
166 | },
167 | "nbformat": 4,
168 | "nbformat_minor": 5
169 | }
170 |
--------------------------------------------------------------------------------
/CategoryTheory/FreerMonads.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "id": "ecc30ed7-e54f-47c7-a06a-4dbfa31f1483",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Documents/GitHub/Julia_Tutorials/CategoryTheory`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg\n",
19 | "Pkg.activate(\".\")"
20 | ]
21 | },
22 | {
23 | "cell_type": "code",
24 | "execution_count": 2,
25 | "id": "b9c13f04-810a-484d-a7ce-2688f8c7df78",
26 | "metadata": {},
27 | "outputs": [],
28 | "source": [
29 | "using MLStyle"
30 | ]
31 | },
32 | {
33 | "cell_type": "code",
34 | "execution_count": 18,
35 | "id": "cd0eafe5-aaa7-48b1-bb61-15dec2df63a7",
36 | "metadata": {},
37 | "outputs": [
38 | {
39 | "data": {
40 | "text/plain": [
41 | "Lan{Array, Int64}([1, 2, 3], myfunc ∘ identity)"
42 | ]
43 | },
44 | "execution_count": 18,
45 | "metadata": {},
46 | "output_type": "execute_result"
47 | }
48 | ],
49 | "source": [
50 | "struct C{T}\n",
51 | " x::T\n",
52 | "end\n",
53 | "myfunc(x::Int)::String = string(x)\n",
54 | "\n",
55 | "# Define a type for Lan\n",
56 | "struct Lan{T, A}\n",
57 | " ga::T # T{X}\n",
58 | " f# X->A\n",
59 | "end\n",
60 | "function Lan(ga::T,f::Function) where T\n",
61 | " t = T.name.wrapper\n",
62 | " A = isempty(typeof(ga).parameters) ? Any : typeof(ga).parameters[1] # Extract the type A from ga\n",
63 | " return Lan{t, A}(ga, f)\n",
64 | "end\n",
65 | "# Note that if `f = identity` , then id:A->A thus ga::T{A}\n",
66 | "\n",
67 | "# Lifting a parametric type to a Lan functor\n",
68 | "function lan(ga::T) where T\n",
69 | " t = T.name.wrapper\n",
70 | " A = isempty(typeof(ga).parameters) ? Any : typeof(ga).parameters[1] # Extract the type A from ga\n",
71 | " return Lan{t, A}(ga, identity)\n",
72 | "end\n",
73 | "\n",
74 | "fmap(f::Function, l::Lan) = Lan(l.ga, f ∘ l.f)\n",
75 | "\n",
76 | "ga = [1, 2, 3] # Sample input for ga\n",
77 | "result = lan(ga)\n",
78 | "fmap(myfunc,result)"
79 | ]
80 | }
81 | ],
82 | "metadata": {
83 | "kernelspec": {
84 | "display_name": "Julia 1.10.5",
85 | "language": "julia",
86 | "name": "julia-1.10"
87 | },
88 | "language_info": {
89 | "file_extension": ".jl",
90 | "mimetype": "application/julia",
91 | "name": "julia",
92 | "version": "1.10.5"
93 | }
94 | },
95 | "nbformat": 4,
96 | "nbformat_minor": 5
97 | }
98 |
--------------------------------------------------------------------------------
/CategoryTheory/Haskell/ForestTree.hs:
--------------------------------------------------------------------------------
1 | class Nearsemiring a where
2 | zero :: a
3 | one :: a
4 | (⊕) :: a -> a -> a
5 | (⊗) :: a -> a -> a
6 |
7 | data Forest a = Forest [Tree a]
8 | deriving (Show)
9 | data Tree a = Leaf | Node a (Forest a)
10 | deriving (Show)
11 |
12 | instance Nearsemiring (Forest a) where
13 | zero = Forest []
14 | one = Forest [Leaf]
15 | (Forest xs) ⊕ (Forest ys) = Forest (xs ++ ys)
16 | (Forest xs) ⊗ (Forest ys) = Forest (concatMap g xs)
17 | where
18 | g Leaf = ys
19 | g (Node a n) = [Node a (n ⊗ Forest ys)]
20 |
21 |
22 |
23 | example :: Forest Int
24 | example = Forest [Node 1 (Forest [Leaf]), Node 2 (Forest [Leaf, Node 3 (Forest [Leaf])])]
25 |
--------------------------------------------------------------------------------
/CategoryTheory/Haskell/FreeMonads.hs:
--------------------------------------------------------------------------------
1 | {-# LANGUAGE UndecidableInstances #-}
2 | {-# LANGUAGE DeriveFunctor #-}
3 |
4 |
5 | data Free f a = Pure a | Free (f (Free f a))
6 |
7 | instance (Show (f (Free f a)), Show a) => Show (Free f a) where
8 | show (Pure a) = "Pure " ++ show a
9 | show (Free fa) = "Free (" ++ show fa ++ ")"
10 |
11 |
12 | instance Functor f => Functor (Free f) where
13 | fmap g (Pure a) = Pure (g a)
14 | fmap g (Free fa) = Free (fmap (fmap g) fa)
15 |
16 | instance Functor f => Applicative (Free f) where
17 | pure = Pure
18 | Pure g <*> Pure a = Pure (g a)
19 | Pure g <*> Free fa = Free (fmap (g <$>) fa)
20 | Free fg <*> x = Free ((<*> x) <$> fg)
21 |
22 | instance Functor f => Monad (Free f) where
23 | return = Pure
24 | Pure x >>= f = f x
25 | Free g >>= f = Free ((>>= f) <$> g)
26 |
27 | liftF :: Functor f => f a -> Free f a
28 | liftF cmd = Free (fmap Pure cmd)
29 |
30 | data F a = Add Double a | Mult Double a | Nil deriving (Show)
31 |
32 | instance Functor F where
33 | fmap _ Nil = Nil
34 | fmap f (Add r x) = Add r (f x)
35 | fmap f (Mult r x) = Mult r (f x)
36 |
37 | example :: Free Maybe Int
38 | example = Free (Just (Pure 42))
39 |
40 | exampleAdd :: Free F Int
41 | exampleAdd = liftF (Add 5 10) >>= (\_ -> liftF (Add 3 7) >>= (\_ -> liftF Nil))
42 |
43 | -- fmap (\x->x+1) exampleAdd
44 | exampleCombo :: Free F Int
45 | exampleCombo = do
46 | liftF (Add 10 7)
47 | liftF (Mult 2 3)
48 | liftF (Add 5 4)
49 | liftF Nil
50 |
51 |
52 |
53 | -- | Key value store functionality.
54 | data KeyValF a
55 | = GetKey String (Maybe String -> a)
56 | | PutKey String String a
57 | deriving (Functor)
58 |
59 | -- | Console functionality.
60 | data ConsoleF a
61 | = PutStrLn String a
62 | | GetLine (String -> a)
63 | deriving (Functor)
64 | type Console = Free ConsoleF
65 | type KeyVal = Free KeyValF
66 |
67 | getKey :: String -> KeyVal (Maybe String)
68 | getKey k = liftF (GetKey k id)
69 |
70 | putStrLn :: String -> Console ()
71 | putStrLn s = liftF (PutStrLn s ())
72 |
73 | getLine :: Console String
74 | getLine = liftF (GetLine id)
75 |
--------------------------------------------------------------------------------
/CategoryTheory/Haskell/FreeMonads2.hs:
--------------------------------------------------------------------------------
1 | {-# LANGUAGE UndecidableInstances #-}
2 | {-# LANGUAGE DeriveFunctor #-}
3 |
4 |
5 | data Free f a = Pure a | Free (f (Free f a))
6 |
7 | instance (Show (f (Free f a)), Show a) => Show (Free f a) where
8 | show (Pure a) = "Pure " ++ show a
9 | show (Free fa) = "Free (" ++ show fa ++ ")"
10 |
11 |
12 | instance Functor f => Functor (Free f) where
13 | fmap g (Pure a) = Pure (g a)
14 | fmap g (Free fa) = Free (fmap (fmap g) fa)
15 |
16 | instance Functor f => Applicative (Free f) where
17 | pure = Pure
18 | Pure g <*> Pure a = Pure (g a)
19 | Pure g <*> Free fa = Free (fmap (g <$>) fa)
20 | Free fg <*> x = Free ((<*> x) <$> fg)
21 |
22 | instance Functor f => Monad (Free f) where
23 | return = Pure
24 | Pure x >>= f = f x
25 | Free g >>= f = Free ((>>= f) <$> g)
26 |
27 | liftF :: Functor f => f a -> Free f a
28 | liftF cmd = Free (fmap Pure cmd)
29 |
30 | data FilesF a
31 | = FilesLs ([FilePath] -> a)
32 | | FilesMkdir FilePath a -- équivalent à: FilesMkdir FilePath (() -> a)
33 | | FilesRmdir FilePath a
34 | deriving (Functor)
35 |
36 | type Files = Free FilesF
37 |
--------------------------------------------------------------------------------
/CategoryTheory/Haskell/FreeMonads3.hs:
--------------------------------------------------------------------------------
1 | data Free f a = Pure a | Roll (f (Free f a))
2 | --it needs to be a functor
3 | instance Functor f => Functor (Free f) where
4 | fmap f (Pure a) = Pure (f a)
5 | fmap f (Roll x) = Roll (fmap (fmap f) x)
6 |
7 | --this is the same thing as (++) basically
8 | concatFree :: Functor f => Free f (Free f a) -> Free f a
9 | concatFree (Pure x) = x
10 | concatFree (Roll y) = Roll (fmap concatFree y)
11 |
12 | data F a = One a | Two a a | Two' a a | Three Int a a a
13 | deriving Show
14 |
15 | -- Lift F into the Free monad
16 | type FreeF a = Free F a
17 |
18 | tree :: FreeF String
19 | tree = Roll (One (Pure "A"))
20 |
21 | example1 :: F (FreeF String)
22 | example1 = One (Roll (One (Pure "A")))
23 |
24 | -- result :: FreeF (FreeF String)
25 | -- result = Roll (One (Roll (One (Pure "A"))))
26 |
--------------------------------------------------------------------------------
/CategoryTheory/Haskell/FreeMonads4.hs:
--------------------------------------------------------------------------------
1 | import Control.Monad.Trans.Free (Free, liftF)
2 |
3 | data CommandLineInstruction next =
4 | ReadLine (String -> next)
5 | | WriteLine String next
6 | deriving (Functor)
7 |
8 | type CommandLineProgram = Free CommandLineInstruction
9 |
10 | readLine :: CommandLineProgram String
11 | readLine = liftF (ReadLine id)
12 |
13 | writeLine :: String -> CommandLineProgram ()
14 | writeLine s = liftF (WriteLine s ())
15 |
--------------------------------------------------------------------------------
/CategoryTheory/Haskell/FreeMonads5.hs:
--------------------------------------------------------------------------------
1 | {-# LANGUAGE FlexibleInstances #-}
2 | data Free f a = Pure a | Free (f (Free f a))
3 | --it needs to be a functor
4 | instance Functor f => Functor (Free f) where
5 | fmap f (Pure a) = Pure (f a)
6 | fmap f (Free x) = Free (fmap (fmap f) x)
7 |
8 | instance Functor f => Applicative (Free f) where
9 | pure = Pure
10 | Pure g <*> Pure a = Pure (g a)
11 | Pure g <*> Free fa = Free (fmap (g <$>) fa)
12 |
13 | --this is the same thing as (++) basically
14 | concatFree :: Functor f => Free f (Free f a) -> Free f a
15 | concatFree (Pure x) = x
16 | concatFree (Free y) = Free (fmap concatFree y)
17 |
18 | instance Functor f => Monad (Free f) where
19 | return = Pure -- just like []
20 | x >>= f = concatFree (fmap f x)
21 |
22 | -- this is essentially the same as \x -> [x]
23 | liftFree :: Functor f => f a -> Free f a
24 | liftFree x = Free (fmap Pure x)
25 |
26 | -- this is essentially the same as folding a list
27 | foldFree :: Functor f => (f r -> r) -> Free f r -> r
28 | foldFree _ (Pure a) = a
29 | foldFree f (Free x) = f (fmap (foldFree f) x)
30 |
31 | data F a = One a | Two a a | Two' a a | Three Int a a a
32 | deriving Show
33 |
34 | -- Lift F into the Free monad
35 | type FreeF a = Free F a
36 |
37 | tree :: FreeF String
38 | tree = Free (One (Pure "A"))
39 |
40 | example1 :: F (FreeF String)
41 | example1 = One (Free (One (Pure "A")))
42 |
43 | instance Show a => Show (Free F a) where
44 | show (Pure a) = "Pure " ++ show a
45 | show (Free x) = "Free (" ++ show x ++ ")"
46 |
47 | -- result :: FreeF (FreeF String)
48 | -- result = Free (One (Free (One (Pure "A"))))
49 | result :: F (FreeF Int)
50 | result = One (Free (One (Pure 1)))
51 |
--------------------------------------------------------------------------------
/CategoryTheory/Haskell/FreeMonads6.hs:
--------------------------------------------------------------------------------
1 | {-# LANGUAGE DeriveFunctor #-}
2 |
3 | data Free f a
4 | = Pure a
5 | | Free (f (Free f a))
6 |
7 | instance Functor f => Functor (Free f) where
8 | fmap f (Pure a) = Pure (f a)
9 | fmap f (Free x) = Free (fmap f <$> x)
10 |
11 | instance Functor f => Applicative (Free f) where
12 | pure = Pure
13 | Pure f <*> Pure a = Pure (f a)
14 | Pure f <*> Free x = Free (fmap f <$> x)
15 | Free x <*> my = Free ((<*> my) <$> x)
16 |
17 | instance Functor f => Monad (Free f) where
18 | return = pure
19 | Pure a >>= f = f a
20 | Free x >>= f = Free ((>>= f) <$> x)
21 |
22 | data Terminal a
23 | = GetLine (String -> a)
24 | | PrintLine String a
25 | deriving Functor
26 |
--------------------------------------------------------------------------------
/CategoryTheory/Haskell/ListMonad.hs:
--------------------------------------------------------------------------------
1 | data List a = Nil | Cons a (List a)
2 | deriving Show
3 |
4 | join :: List (List a) -> List a
5 | join Nil = Nil
6 | join (Cons xs xss) = cat xs (join xss)
7 |
8 | cat :: List a -> List a -> List a
9 | cat Nil ys = ys
10 | cat (Cons x xs) ys = Cons x (cat xs ys)
11 |
12 |
--------------------------------------------------------------------------------
/CategoryTheory/Haskell/MyModule.hs:
--------------------------------------------------------------------------------
1 | type Algebra f a = f a -> a
2 | data ListF c a = NilF | ConsF c a
3 | data List c = Nil | Cons c (List c)
4 |
5 | phi :: ListF c (List c) -> List c
6 | phi NilF = Nil
7 | phi (ConsF c lst) = Cons c lst
8 |
9 | evalSum :: Algebra (ListF Int) Int
10 | evalSum (ConsF n x) = n + x
11 | evalSum NilF = 0
12 |
13 | cataSum :: List Int -> Int
14 | cataSum Nil = evalSum NilF
15 | cataSum (Cons n ns) = evalSum (ConsF n (cataSum ns))
16 |
17 |
18 | --
19 | -- Run ---
20 | -- evalSum(ConsF 10 10)
21 | -- evalSum(NilF)
22 | -- cataSum(Cons 10 (Cons 20 Nil))
23 |
--------------------------------------------------------------------------------
/CategoryTheory/Haskell/RoseTree.hs:
--------------------------------------------------------------------------------
1 | data Rose a = Node a [Rose a]
2 |
--------------------------------------------------------------------------------
/CategoryTheory/Haskell/TypeDeclaration.hs:
--------------------------------------------------------------------------------
1 | data M a = Nil | J a
2 | deriving (Show)
3 |
4 | -- data F a = Nil | J a
5 | -- deriving (Show)
6 |
7 | -- checkType :: M a -> Bool
8 | -- checkType Nil = False
9 | -- checkType (J _) = True
10 | checkNilType :: M Int -> String
11 | checkNilType Nil = "Nil is of type M Int"
12 | checkNilType _ = "Nil is not of type M Int"
13 |
14 |
--------------------------------------------------------------------------------
/CategoryTheory/Nested Spaces as Monoid.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "4204da53-992e-42ce-9a85-5fa151a12b59",
6 | "metadata": {},
7 | "source": [
8 | "# Nested Spaces as Monoid"
9 | ]
10 | },
11 | {
12 | "cell_type": "code",
13 | "execution_count": 9,
14 | "id": "315c0036-391a-4807-b1cb-4c2adab9b3c6",
15 | "metadata": {},
16 | "outputs": [
17 | {
18 | "name": "stderr",
19 | "output_type": "stream",
20 | "text": [
21 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/MEGA/EMAP/PhDThesis/notes/FunctionalProgrammingCategoryTheory/julia`\n"
22 | ]
23 | }
24 | ],
25 | "source": [
26 | "using Pkg\n",
27 | "Pkg.activate(\".\")"
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": 17,
33 | "id": "87c4f42b-aa3d-4d31-9b10-2f267885b394",
34 | "metadata": {},
35 | "outputs": [
36 | {
37 | "data": {
38 | "text/plain": [
39 | "2-element SVector{2, Float64} with indices SOneTo(2):\n",
40 | " 4.5\n",
41 | " 3.5"
42 | ]
43 | },
44 | "execution_count": 17,
45 | "metadata": {},
46 | "output_type": "execute_result"
47 | }
48 | ],
49 | "source": [
50 | "using CoordinateTransformations, Rotations, StaticArrays, Luxor\n",
51 | "\n",
52 | "x = [1.0, 2.0] \n",
53 | "trans = Translation(3.5, 1.5)\n",
54 | "\n",
55 | "y = trans(x)"
56 | ]
57 | },
58 | {
59 | "cell_type": "code",
60 | "execution_count": null,
61 | "id": "f6403233-c058-40a3-bd84-f017c7c4e956",
62 | "metadata": {},
63 | "outputs": [],
64 | "source": [
65 | "abstract type Space end\n",
66 | "\n",
67 | "struct Finite2D\n",
68 | "end"
69 | ]
70 | },
71 | {
72 | "cell_type": "code",
73 | "execution_count": 18,
74 | "id": "a36580ec-f81a-4d71-b3f0-68e68776c257",
75 | "metadata": {},
76 | "outputs": [
77 | {
78 | "data": {
79 | "image/svg+xml": [
80 | "\n",
81 | "\n"
86 | ],
87 | "text/plain": []
88 | },
89 | "execution_count": 18,
90 | "metadata": {},
91 | "output_type": "execute_result"
92 | }
93 | ],
94 | "source": [
95 | "drawheight = 400\n",
96 | "drawwidth = 400\n",
97 | "\n",
98 | "d = Drawing(drawheight,drawwidth,:svg)\n",
99 | "background(\"antiquewhite\")\n",
100 | "sethue(\"lightgrey\")\n",
101 | "\n",
102 | "finish()\n",
103 | "d"
104 | ]
105 | },
106 | {
107 | "cell_type": "code",
108 | "execution_count": null,
109 | "id": "d288f8a8-169a-4095-ac1f-4bcf29764257",
110 | "metadata": {},
111 | "outputs": [],
112 | "source": []
113 | }
114 | ],
115 | "metadata": {
116 | "kernelspec": {
117 | "display_name": "Julia 1.8.1",
118 | "language": "julia",
119 | "name": "julia-1.8"
120 | },
121 | "language_info": {
122 | "file_extension": ".jl",
123 | "mimetype": "application/julia",
124 | "name": "julia",
125 | "version": "1.8.1"
126 | }
127 | },
128 | "nbformat": 4,
129 | "nbformat_minor": 5
130 | }
131 |
--------------------------------------------------------------------------------
/CategoryTheory/Poly.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "id": "671f35e6-6e40-44c5-b0d3-08f3a1a76c7b",
7 | "metadata": {},
8 | "outputs": [],
9 | "source": []
10 | }
11 | ],
12 | "metadata": {
13 | "kernelspec": {
14 | "display_name": "Julia 1.9.0",
15 | "language": "julia",
16 | "name": "julia-1.9"
17 | },
18 | "language_info": {
19 | "file_extension": ".jl",
20 | "mimetype": "application/julia",
21 | "name": "julia",
22 | "version": "1.9.0"
23 | }
24 | },
25 | "nbformat": 4,
26 | "nbformat_minor": 5
27 | }
28 |
--------------------------------------------------------------------------------
/CategoryTheory/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | CanonicalTraits = "a603d957-0e48-4f86-8fbd-0b7bc66df689"
3 | ExtensibleEffects = "67377c25-f533-4d0b-9328-1721380cc1f1"
4 | FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"
5 | Functors = "d9f16b24-f501-4c13-a1f2-28368ffc5196"
6 | MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
7 | Moshi = "2e0e35c7-a2e4-4343-998d-7ef72827ed2d"
8 | PartialFunctions = "570af359-4316-4cb7-8c74-252c00c2016b"
9 | SumTypes = "8e1ec7a9-0e02-4297-b0fe-6433085c89f2"
10 | TypeClasses = "addcc920-e0cf-11e8-30b7-0fb08706b574"
11 |
--------------------------------------------------------------------------------
/CategoryTheory/Untitled1.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "id": "c29737c6-6029-4491-ab0a-1f687b9be66f",
7 | "metadata": {},
8 | "outputs": [],
9 | "source": []
10 | }
11 | ],
12 | "metadata": {
13 | "kernelspec": {
14 | "display_name": "Julia 1.10.5",
15 | "language": "julia",
16 | "name": "julia-1.10"
17 | },
18 | "language_info": {
19 | "file_extension": ".jl",
20 | "mimetype": "application/julia",
21 | "name": "julia",
22 | "version": "1.10.5"
23 | }
24 | },
25 | "nbformat": 4,
26 | "nbformat_minor": 5
27 | }
28 |
--------------------------------------------------------------------------------
/CategoryTheory/aux_functors.jl:
--------------------------------------------------------------------------------
1 | struct Just{T}
2 | _1::T
3 | end
4 | struct Nothing end
5 | Maybe{T} = Union{Just{T}, Nothing};
6 |
7 | fmap(f::Function, x::Nothing) = Nothing()
8 | fmap(f::Function, x::Just) = Just(f(x._1))
9 |
10 | struct Nil end
11 | struct Cons{T}
12 | val::T
13 | next::Union{Cons{T},Nil} # n.b. abstract type!
14 | end
15 | List{T} = Union{Cons{T}, Nil}
16 | fmap(f::Function, x::Nil) = Nil()
17 | fmap(f::Function, x::Cons) = Cons(f(x.val),fmap(f, x.next))
18 |
--------------------------------------------------------------------------------
/CategoryTheory/freelist.jl:
--------------------------------------------------------------------------------
1 | using Pkg
2 | Pkg.activate(".")
3 | using MLStyle
4 |
5 | abstract type List{T} end
6 | struct Nil{T} <: List{T} end
7 | struct Cons{T} <: List{T}
8 | _1::T
9 | _2::List{T}
10 | end
11 | fmap(f::Function, x::Nil) = x
12 | fmap(f::Function, x::Cons{T}) where T = Cons(f(x._1),fmap(f, x._2))
13 |
14 | @data FreeList{a} begin
15 | Pure(::a)
16 | FreeNil()
17 | FreeCons(::Union{Pure{a},Pure{<:FreeList}},::Union{FreeNil{a},FreeCons{a}})
18 | end
19 |
--------------------------------------------------------------------------------
/CategoryTheory/old/Do Operator.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "8ad74696-f951-45ff-9c9c-4ab198cadeac",
6 | "metadata": {},
7 | "source": [
8 | "# Getting Rid of For-Loops with Do-Block\n",
9 | "by: Nicolau Leal Werneck\n",
10 | "\n",
11 | "[Check this talk](https://live.juliacon.org/talk/WKNY78)"
12 | ]
13 | },
14 | {
15 | "cell_type": "markdown",
16 | "id": "03523db8-9fed-4369-a5a7-e008acac14c8",
17 | "metadata": {},
18 | "source": [
19 | "### A Simple Loop"
20 | ]
21 | },
22 | {
23 | "cell_type": "code",
24 | "execution_count": 3,
25 | "id": "b2d6d602-9024-4c25-aa7e-70d8a8b2aa60",
26 | "metadata": {},
27 | "outputs": [
28 | {
29 | "data": {
30 | "text/plain": [
31 | "3-element Vector{Int64}:\n",
32 | " 1\n",
33 | " 4\n",
34 | " 9"
35 | ]
36 | },
37 | "execution_count": 3,
38 | "metadata": {},
39 | "output_type": "execute_result"
40 | }
41 | ],
42 | "source": [
43 | "a1 = [j*j for j in 1:3]"
44 | ]
45 | },
46 | {
47 | "cell_type": "code",
48 | "execution_count": 4,
49 | "id": "4331f85b-db55-4202-9697-00cc41917d4a",
50 | "metadata": {},
51 | "outputs": [
52 | {
53 | "data": {
54 | "text/plain": [
55 | "3-element Vector{Int64}:\n",
56 | " 1\n",
57 | " 4\n",
58 | " 9"
59 | ]
60 | },
61 | "execution_count": 4,
62 | "metadata": {},
63 | "output_type": "execute_result"
64 | }
65 | ],
66 | "source": [
67 | "a1 = map(1:3) do j j*j end"
68 | ]
69 | },
70 | {
71 | "cell_type": "markdown",
72 | "id": "6bceccf1-eb45-4e57-8a8b-362425b74be5",
73 | "metadata": {},
74 | "source": [
75 | "### A Nested Loop"
76 | ]
77 | },
78 | {
79 | "cell_type": "code",
80 | "execution_count": 5,
81 | "id": "8cf567d3-fe4a-43ba-907e-f54a6d602101",
82 | "metadata": {},
83 | "outputs": [
84 | {
85 | "data": {
86 | "text/plain": [
87 | "12-element Vector{Int64}:\n",
88 | " 2\n",
89 | " 3\n",
90 | " 4\n",
91 | " 5\n",
92 | " 2\n",
93 | " 6\n",
94 | " 8\n",
95 | " 10\n",
96 | " 3\n",
97 | " 6\n",
98 | " 12\n",
99 | " 15"
100 | ]
101 | },
102 | "execution_count": 5,
103 | "metadata": {},
104 | "output_type": "execute_result"
105 | }
106 | ],
107 | "source": [
108 | "[j*k for j in 1:3 for k in 1:5 if j != k]"
109 | ]
110 | },
111 | {
112 | "cell_type": "code",
113 | "execution_count": 11,
114 | "id": "576e13a7-9019-4b68-9674-5ed6e630ae79",
115 | "metadata": {},
116 | "outputs": [
117 | {
118 | "data": {
119 | "text/plain": [
120 | "12-element Vector{Any}:\n",
121 | " 2\n",
122 | " 3\n",
123 | " 4\n",
124 | " 5\n",
125 | " 2\n",
126 | " 6\n",
127 | " 8\n",
128 | " 10\n",
129 | " 3\n",
130 | " 6\n",
131 | " 12\n",
132 | " 15"
133 | ]
134 | },
135 | "execution_count": 11,
136 | "metadata": {},
137 | "output_type": "execute_result"
138 | }
139 | ],
140 | "source": [
141 | "a = []\n",
142 | "for j in 1:3\n",
143 | " for k in 1:5\n",
144 | " j != k ? push!(a, j*k) : continue\n",
145 | " end\n",
146 | "end\n",
147 | "a"
148 | ]
149 | },
150 | {
151 | "cell_type": "markdown",
152 | "id": "a59745ff-5842-4ec7-9bfc-a7eecfe0ab94",
153 | "metadata": {},
154 | "source": [
155 | "Let's now use the do-block. For this, we'll need to use `flatten` and create a `flatmap`. "
156 | ]
157 | },
158 | {
159 | "cell_type": "code",
160 | "execution_count": 16,
161 | "id": "b14a31aa-6c84-4dde-a3c0-03b0adef6153",
162 | "metadata": {},
163 | "outputs": [
164 | {
165 | "data": {
166 | "text/plain": [
167 | "6-element Vector{Any}:\n",
168 | " 1\n",
169 | " 2\n",
170 | " 3\n",
171 | " 'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)\n",
172 | " 'b': ASCII/Unicode U+0062 (category Ll: Letter, lowercase)\n",
173 | " 'c': ASCII/Unicode U+0063 (category Ll: Letter, lowercase)"
174 | ]
175 | },
176 | "execution_count": 16,
177 | "metadata": {},
178 | "output_type": "execute_result"
179 | }
180 | ],
181 | "source": [
182 | "collect(Iterators.flatten((1:3,'a':'c')))"
183 | ]
184 | },
185 | {
186 | "cell_type": "code",
187 | "execution_count": 17,
188 | "id": "5508d3cb-a43c-44c7-a2a9-398e5cbea573",
189 | "metadata": {},
190 | "outputs": [
191 | {
192 | "data": {
193 | "text/plain": [
194 | "5-element Vector{Any}:\n",
195 | " 1\n",
196 | " 2\n",
197 | " 3\n",
198 | " \"ok\"\n",
199 | " \"nope\""
200 | ]
201 | },
202 | "execution_count": 17,
203 | "metadata": {},
204 | "output_type": "execute_result"
205 | }
206 | ],
207 | "source": [
208 | "collect(Iterators.flatten((1:3,[\"ok\", \"nope\"])))"
209 | ]
210 | },
211 | {
212 | "cell_type": "markdown",
213 | "id": "01491f75-5902-4d3a-bf33-448f5ac2138c",
214 | "metadata": {},
215 | "source": [
216 | "Note that `flatten` creates a generator that \"concatenates\" the two \"lists\"."
217 | ]
218 | },
219 | {
220 | "cell_type": "code",
221 | "execution_count": 19,
222 | "id": "de71703a-2e8c-411c-ac1b-a6c7757209d8",
223 | "metadata": {},
224 | "outputs": [],
225 | "source": [
226 | "flatmap(f,x) = collect(Iterators.flatten(map(f,x)));"
227 | ]
228 | },
229 | {
230 | "cell_type": "code",
231 | "execution_count": 24,
232 | "id": "ee898de0-3022-4091-b6f0-c0a6e256ae31",
233 | "metadata": {},
234 | "outputs": [
235 | {
236 | "data": {
237 | "text/plain": [
238 | "12-element Vector{Int64}:\n",
239 | " 2\n",
240 | " 3\n",
241 | " 4\n",
242 | " 5\n",
243 | " 2\n",
244 | " 6\n",
245 | " 8\n",
246 | " 10\n",
247 | " 3\n",
248 | " 6\n",
249 | " 12\n",
250 | " 15"
251 | ]
252 | },
253 | "execution_count": 24,
254 | "metadata": {},
255 | "output_type": "execute_result"
256 | }
257 | ],
258 | "source": [
259 | "flatmap(1:3) do j\n",
260 | " flatmap(1:5) do k\n",
261 | " j != k ? (j*k,) : ()\n",
262 | " end\n",
263 | "end"
264 | ]
265 | },
266 | {
267 | "cell_type": "code",
268 | "execution_count": null,
269 | "id": "4a37493c-5ee3-4070-a99f-5d5f4580f4a0",
270 | "metadata": {},
271 | "outputs": [],
272 | "source": []
273 | }
274 | ],
275 | "metadata": {
276 | "kernelspec": {
277 | "display_name": "Julia 1.10.0",
278 | "language": "julia",
279 | "name": "julia-1.10"
280 | },
281 | "language_info": {
282 | "file_extension": ".jl",
283 | "mimetype": "application/julia",
284 | "name": "julia",
285 | "version": "1.10.0"
286 | }
287 | },
288 | "nbformat": 4,
289 | "nbformat_minor": 5
290 | }
291 |
--------------------------------------------------------------------------------
/CategoryTheory/old/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | Folds = "41a02a25-b8f0-4f67-bc48-60067656b558"
3 | MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
4 | StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
5 |
--------------------------------------------------------------------------------
/CategoryTheory/old/README.md:
--------------------------------------------------------------------------------
1 | # Functional Programming with Julia
2 |
3 | These notes are based on the "Grokking Simplicty" book.
4 |
--------------------------------------------------------------------------------
/DataBases/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
3 | LibPQ = "194296ae-ab2e-5f79-8cd4-7183a0a5a0d1"
4 | PalmerPenguins = "8b842266-38fa-440a-9b57-31493939ab85"
5 | SQLStrings = "af517c2e-c243-48fa-aab8-efac3db270f5"
6 | Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
7 |
--------------------------------------------------------------------------------
/Diagrams/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | Luxor = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
3 | MathTeXEngine = "0a4f8689-d25c-4efe-a92b-7142dfc1aa53"
4 |
--------------------------------------------------------------------------------
/DiscreteDifferentialGeometry/sandbox/DifferentialForms.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 21,
6 | "id": "d13724fc-18b6-4953-b760-63b2ffffd2bc",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Documents/GitHub/Julia_Tutorials/DifferentialGeometry`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg\n",
19 | "Pkg.activate(\".\")\n",
20 | "using Meshes\n",
21 | "import WGLMakie as Mke\n",
22 | "using LinearAlgebra\n",
23 | "using DataFrames"
24 | ]
25 | },
26 | {
27 | "cell_type": "code",
28 | "execution_count": null,
29 | "id": "cd9a6014-a17f-404e-ab21-3b42f78c9fe4",
30 | "metadata": {},
31 | "outputs": [],
32 | "source": []
33 | }
34 | ],
35 | "metadata": {
36 | "kernelspec": {
37 | "display_name": "Julia 1.10.5",
38 | "language": "julia",
39 | "name": "julia-1.10"
40 | },
41 | "language_info": {
42 | "file_extension": ".jl",
43 | "mimetype": "application/julia",
44 | "name": "julia",
45 | "version": "1.10.5"
46 | }
47 | },
48 | "nbformat": 4,
49 | "nbformat_minor": 5
50 | }
51 |
--------------------------------------------------------------------------------
/DiscreteDifferentialGeometry/sandbox/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
3 | CliffordAlgebras = "ca841f6f-225c-4bbd-a467-7a3512dfa6f6"
4 | CoDa = "5900dafe-f573-5c72-b367-76665857777b"
5 | CoordRefSystems = "b46f11dc-f210-4604-bfba-323c1ec968cb"
6 | DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
7 | DelaunayTriangulation = "927a84f5-c5f4-47a5-9785-b46e178433df"
8 | DifferentialForms = "9e54b8bf-1ae4-4c45-8656-f6b46e7970a3"
9 | GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
10 | GeoIO = "f5a160d5-e41d-4189-8b61-d57781c419e3"
11 | GeoStats = "dcc97b0b-8ce5-5539-9008-bb190f959ef6"
12 | GeoTables = "e502b557-6362-48c1-8219-d30d308dcdb0"
13 | GeometricAlgebra = "11bbe1ca-eae6-48c2-942c-9f17e43de0f0"
14 | Grassmann = "4df31cd9-4c27-5bea-88d0-e6a7146666d8"
15 | Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
16 | Manifolds = "1cead3c2-87b3-11e9-0ccd-23c62b72b94e"
17 | Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
18 | PairPlots = "43a3c2be-4208-490b-832a-a21dcd55d7da"
19 | Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
20 | WGLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008"
21 |
--------------------------------------------------------------------------------
/DiscreteDifferentialGeometry/sandbox/Untitled.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "id": "0d7d17f5-9943-478a-9c0b-712c157ef2d6",
7 | "metadata": {},
8 | "outputs": [],
9 | "source": []
10 | }
11 | ],
12 | "metadata": {
13 | "kernelspec": {
14 | "display_name": "Julia 1.10.5",
15 | "language": "julia",
16 | "name": "julia-1.10"
17 | },
18 | "language_info": {
19 | "file_extension": ".jl",
20 | "mimetype": "application/julia",
21 | "name": "julia",
22 | "version": "1.10.5"
23 | }
24 | },
25 | "nbformat": 4,
26 | "nbformat_minor": 5
27 | }
28 |
--------------------------------------------------------------------------------
/Dispatch-Design/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | Cassette = "7057c7e9-c182-5462-911a-8362d720325c"
3 | Mixers = "2a8e4939-dab8-5edc-8f64-72a8776f13de"
4 | Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
5 | Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
6 | WhereTraits = "c9d4e05b-6318-49cb-9b56-e0e2b0ceadd8"
7 |
--------------------------------------------------------------------------------
/DockerJulia/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/davibarreira/Julia_Tutorials/60c0d8309d0077c4297f9a188e6a947b61ed38ac/DockerJulia/.DS_Store
--------------------------------------------------------------------------------
/DockerJulia/FirstDocker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM julia:1.6.7-alpine
2 | COPY . ./app
3 | WORKDIR /app
4 | CMD julia hellodocker.jl
5 |
--------------------------------------------------------------------------------
/DockerJulia/FirstDocker/hellodocker.jl:
--------------------------------------------------------------------------------
1 | println("Hello Docker.")
2 |
--------------------------------------------------------------------------------
/DockerJulia/NotesOnDocker.md:
--------------------------------------------------------------------------------
1 | # Mastering Docker
2 |
3 | Docker has a client and a server. The docker server
4 | is called the Docker Engine. They communicate via a
5 | REST API.
6 | ## Containers Vs. Images
7 |
8 | In Docker, an image is described in a `Dockerfile`. It contains
9 | information such as the kernel (you can think of this as the OS)
10 | the installed packages, and so on.
11 | Hence, an image is like the configuration of the machine
12 | where you want to deploy your application.
13 |
14 | A container is just an instance of an image, i.e. you can
15 | have many containers running and all of them have the same
16 | underlying configuration. Hence, when we create a `Dockerfile`
17 | and we run a build command from Docker, we are creating an image.
18 |
19 | After that, once we do the `docker run my-image` command, we
20 | create a container running with that image.
21 |
22 | # FirstDocker
23 |
24 | ## Creating your own image and running your first container
25 |
26 | The information regarding containers are inside a `Dockerfile`.
27 | We start specifying the image we'll use. We can use pre-set
28 | images from Docker-Hub. This can ease the process of installing different packages.
29 |
30 | The folder `FirstDocker` has an example of a very simple
31 | container that run a julia script.
32 |
33 | Here is the content of the dockerfile in this folder:
34 | ```
35 | FROM julia:1.6.7-alpine
36 | COPY . ./app
37 | WORKDIR /app
38 | CMD julia hellodocker.jl
39 | ```
40 |
41 | The first line is specifying that we are going to use the
42 | container `julia` from Docker Hub, with version 1.6.7, which is
43 | the current stable version. The `alpine` is a Linux distro
44 | that is very lightweight, and hence good for keeping
45 | containers small.
46 |
47 | Next, the `COPY . ./app` is copying everything in the current
48 | where the Dockerfile is, and is saving these files inside a folder
49 | called `app/`. The following line is setting the `/app` folder
50 | as the working directory.
51 |
52 | The last line is declaring what command should be ran when we build
53 | this container. Thus, once we run the container, it will
54 | always start by running the `hellodocker.jl` script.
55 |
56 | Go inside the `FirstDocker` folder and run the following:
57 | ```
58 | sudo docker build -t hellodocker .
59 | ```
60 |
61 | This command will build a docker image with the name `hellodocker`.
62 | Note that the `.` in the end of the command specifies where the
63 | Dockerfile is.
64 |
65 | Note that this command will not actually run the container,
66 | but just build it. Run the command `sudo docker images`
67 | to get a list of available images. The `hellodocker`
68 | should be there.
69 |
70 | If it's there, then just run `sudo docker run hellodocker`, and
71 | this will run the `hellodocker.jl` script.
72 |
73 |
74 | ## Creating more complicated images
75 |
76 | We started with a very simple image. But how do we customize it?
77 | For example, how can we create an image where our Julia environment
78 | is already setup and we can perhaps use a System Image?
79 |
80 | First, you might not know what a system image is. Since you are using Julia,
81 | you know that it can take a bit of time to get it to start running, due to
82 | pre-compilation time. We can speed this up with a system image, which is
83 | a binary where we already have all our desired dependencies pre-compiled.
84 | This is great when we want to quickly run some code. The downside is that
85 | the system image can be quite large, and we need to delete it and create
86 | a new one if we wish to update the packages in it.
87 |
88 | Yet, if we want to run Julia code in, say, an AWS Lambda function, then
89 | this is a must.
90 |
91 | # LambdaDocker
92 |
93 | This next example is on how to use Julia with AWS Lambda.
94 | Run the following from within the directory:
95 | ```
96 | sudo docker build -t julia-lambda:latest . && sudo docker run -it --rm -p 9000:8080 julia-lambda:latest
97 | ```
98 |
99 | Wait for
100 |
--------------------------------------------------------------------------------
/DockerJulia/SecondDocker/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM jupyter/datascience-notebook:julia-1.7.3
2 |
3 | # Install the AWS CLI:
4 | RUN curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" && \
5 | unzip awscliv2.zip
6 | USER root
7 | RUN ./aws/install
8 | USER $NB_UID
9 |
10 | # Install various Python utilities for SageMaker, and PyCall to enable using them from Julia:
11 | # (Pinned to last tested major version for repeatability)
12 | RUN julia -e 'import Pkg; Pkg.update()' && \
13 | julia -e 'using Pkg; pkg"add PyCall@1"; pkg"precompile"' && \
14 | pip install \
15 | 'boto3>=1,<2' \
16 | 'sagemaker>=2,<3' \
17 | 'sagemaker-experiments>=0.1,<0.2' \
18 | 'sagemaker-studio-image-build>=0.4,<0.5' \
19 | 'smdebug>=0.9,<0.10'
20 |
--------------------------------------------------------------------------------
/DockerJulia/SecondDocker/README.md:
--------------------------------------------------------------------------------
1 | ## Jupyter Docker Stacks Data Science
2 |
3 |
4 | ### Overview
5 |
6 | This custom image uses the [Jupyter Docker Stacks Data Science image](https://github.com/jupyter/docker-stacks/tree/master/datascience-notebook) in SageMaker Studio.
7 |
8 | ### Building the image
9 |
10 | Build the Docker image and push to Amazon ECR.
11 | ```
12 | # Modify these as required. The Docker registry endpoint can be tuned based on your current region from https://docs.aws.amazon.com/general/latest/gr/ecr.html#ecr-docker-endpoints
13 | REGION=
14 | ACCOUNT_ID=
15 | IMAGE_NAME=julia-datascience
16 |
17 | # Create ECR Repository. Ignore if it exists. For simplcity, all examples in the repo
18 | # use same ECR repo with different image tags
19 | aws --region ${REGION} ecr create-repository --repository-name smstudio-custom
20 |
21 | # Build the image
22 | aws --region ${REGION} ecr get-login-password | docker login --username AWS --password-stdin ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/smstudio-custom
23 | docker build . -t ${IMAGE_NAME} -t ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/smstudio-custom:${IMAGE_NAME}
24 | ```
25 |
26 | ```
27 | docker push ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/smstudio-custom:${IMAGE_NAME}
28 | ```
29 |
30 | ### Using with SageMaker Studio
31 |
32 | Create a SageMaker Image (SMI) with the image in ECR. Request parameter RoleArn value is used to get
33 | ECR image information when and Image version is created. After creating Image, create an Image Version during which
34 | SageMaker stores image metadata like SHA etc. Everytime an image is updated in ECR, a new image version should be created.
35 | See [Update Image](#updating-image-with-sageMaker-studio)
36 |
37 | ```
38 | # Role in your account to be used for SMI. Modify as required.
39 |
40 | ROLE_ARN=arn:aws:iam::421258792169:role/Admin
41 | aws --region ${REGION} sagemaker create-image \
42 | --image-name ${IMAGE_NAME} \
43 | --role-arn ${ROLE_ARN}
44 |
45 | aws --region ${REGION} sagemaker create-image-version \
46 | --image-name ${IMAGE_NAME} \
47 | --base-image "${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/smstudio-custom:${IMAGE_NAME}"
48 |
49 | # Verify the image-version is created successfully. Do NOT proceed if image-version is in CREATE_FAILED state or in any other state apart from CREATED.
50 | aws --region ${REGION} sagemaker describe-image-version --image-name ${IMAGE_NAME}
51 | ```
52 |
53 | Create a AppImageConfig for this image
54 |
55 | ```
56 | aws --region ${REGION} sagemaker create-app-image-config --cli-input-json file://app-image-config-input.json
57 |
58 | ```
59 |
60 | NOTE: This image contains multiple kernels (R, Julia, Python). However, we can only specify one image in the AppImageConfig API. Only this kernel will be shown to users *before* the image has started. Once the image is running, all the kernels will be visible in JupyterLab.
61 |
62 | Create a Domain, providing the SageMaker Image and AppImageConfig in the Domain creation. Replace the placeholders for VPC ID, Subnet IDs, and Execution Role in `create-domain-input.json`
63 |
64 | ```
65 | aws --region ${REGION} sagemaker create-domain --cli-input-json file://create-domain-input.json
66 | ```
67 |
68 | If you have an existing Domain, you can also use the `update-domain`
69 |
70 | ```
71 | aws --region ${REGION} sagemaker update-domain --cli-input-json file://update-domain-input.json
72 | ```
73 |
74 | Now create a user, and start a Notebook using the SageMaker Studio launcher
75 |
76 | ### Update Image with SageMaker Studio
77 | If you found an issue with your image or want to update Image with new features, Use following steps
78 |
79 | Re-Build and push the image to ECR
80 |
81 | ```
82 | # Build and push the image
83 | aws --region ${REGION} ecr get-login-password | docker login --username AWS --password-stdin ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/smstudio-custom
84 | docker build . -t ${IMAGE_NAME} -t ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/smstudio-custom:${IMAGE_NAME}
85 | docker push ${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/smstudio-custom:${IMAGE_NAME}
86 | ```
87 |
88 |
89 | Create new App Image Version.
90 | ```
91 | aws --region ${REGION} sagemaker create-image-version \
92 | --image-name ${IMAGE_NAME} \
93 | --base-image "${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com/smstudio-custom:${IMAGE_NAME}"
94 |
95 | # Verify the image-version is created successfully. Do NOT proceed if image-version is in CREATE_FAILED state or in any other state apart from CREATED.
96 | aws --region ${REGION} sagemaker describe-image-version --image-name ${IMAGE_NAME}
97 | ```
98 |
99 |
100 | Re-Create App in SageMaker studio.
101 |
--------------------------------------------------------------------------------
/DockerJulia/SecondDocker/app-image-config-input.json:
--------------------------------------------------------------------------------
1 | {
2 | "AppImageConfigName": "julia-datascience-image-config",
3 | "KernelGatewayImageConfig": {
4 | "KernelSpecs": [
5 | {
6 | "Name": "julia-1.5",
7 | "DisplayName": "Julia 1.5"
8 | }
9 | ],
10 | "FileSystemConfig": {
11 | "MountPath": "/home/jovyan/work",
12 | "DefaultUid": 1000,
13 | "DefaultGid": 100
14 | }
15 | }
16 | }
--------------------------------------------------------------------------------
/DockerJulia/SecondDocker/create-domain-input.json:
--------------------------------------------------------------------------------
1 | {
2 | "DomainName": "domain-with-custom-datascience",
3 | "VpcId": "",
4 | "SubnetIds": [
5 | ""
6 | ],
7 | "DefaultUserSettings": {
8 | "ExecutionRole": "",
9 | "KernelGatewayAppSettings": {
10 | "CustomImages": [
11 | {
12 | "ImageName": "julia-datascience",
13 | "AppImageConfigName": "julia-datascience-image-config"
14 | }
15 | ]
16 | }
17 | },
18 | "AuthMode": "IAM"
19 | }
--------------------------------------------------------------------------------
/DockerJulia/SecondDocker/update-domain-input.json:
--------------------------------------------------------------------------------
1 | {
2 | "DomainId": "",
3 | "DefaultUserSettings": {
4 | "KernelGatewayAppSettings": {
5 | "CustomImages": [
6 | {
7 | "ImageName": "julia-datascience",
8 | "AppImageConfigName": "julia-datascience-image-config"
9 | }
10 | ]
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/FunctionalProgramming/IV - FP Data Structures.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "beab363e-8c81-487a-a0d5-ca9c78fa366b",
6 | "metadata": {},
7 | "source": [
8 | "# **Functional Programming - Data Structures**\n",
9 | "\n",
10 | "This is based on the book \"Learning Functionl Programming\" (Jack Widman).\n",
11 | "\n",
12 | "The main data structures here are the `Option`, `Either`, `Try` and `List` monads.\n",
13 | "We've coded some of them already, but let's recap.\n",
14 | "\n",
15 | "Quote from Alan Perlis:\n",
16 | "It is better to have 100 functions operate on one data structure than to\n",
17 | "have 10 functions operate on 10 data structures."
18 | ]
19 | },
20 | {
21 | "cell_type": "code",
22 | "execution_count": 1,
23 | "id": "b6fd8918-f140-4a31-9e67-6814efcde5e5",
24 | "metadata": {},
25 | "outputs": [
26 | {
27 | "name": "stderr",
28 | "output_type": "stream",
29 | "text": [
30 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/MEGA/EMAP/Julia_Tutorials/FunctionalProgramming`\n"
31 | ]
32 | }
33 | ],
34 | "source": [
35 | "using Pkg\n",
36 | "Pkg.activate(\".\")"
37 | ]
38 | },
39 | {
40 | "cell_type": "markdown",
41 | "id": "a99a65f5-6362-4a68-ba64-b1bfe04f7cf7",
42 | "metadata": {},
43 | "source": [
44 | "## 1. Option\n",
45 | "\n",
46 | "Since `Option` is a monad, this means that it's a functor\n",
47 | "with a `flatmap` and a `unit`."
48 | ]
49 | },
50 | {
51 | "cell_type": "code",
52 | "execution_count": null,
53 | "id": "29bb48bd-a1c2-4057-8640-77ac90268e71",
54 | "metadata": {},
55 | "outputs": [],
56 | "source": [
57 | "unit()"
58 | ]
59 | },
60 | {
61 | "cell_type": "code",
62 | "execution_count": null,
63 | "id": "900bfcda-e3f3-4ecb-8edc-c8f6cafd8ec7",
64 | "metadata": {},
65 | "outputs": [],
66 | "source": [
67 | "Option{T} = Union{Some{T},Nothing}\n",
68 | "\n",
69 | "Option(::Nothing) = nothing\n",
70 | "Option(x) = Some(x)\n",
71 | "Option() = nothing\n",
72 | "\n",
73 | "fmap(f, a::Nothing) = nothing\n",
74 | "fmap(f, a::Some{T}) where T = Some(f(something(a)))\n",
75 | "Option(f::Function) = a::Option -> fmap(f,a)\n",
76 | "\n",
77 | "l = list(Some(1),nothing,Some(8))"
78 | ]
79 | },
80 | {
81 | "cell_type": "code",
82 | "execution_count": 2,
83 | "id": "cc2cf260-a062-439c-aa99-297243e50db9",
84 | "metadata": {},
85 | "outputs": [
86 | {
87 | "data": {
88 | "text/plain": [
89 | "getuserfromdb (generic function with 1 method)"
90 | ]
91 | },
92 | "execution_count": 2,
93 | "metadata": {},
94 | "output_type": "execute_result"
95 | }
96 | ],
97 | "source": [
98 | "struct User\n",
99 | " name::String\n",
100 | "end\n",
101 | "DATABASE = Dict( 4 =>User(\"James\"), 2 =>User(\"John\"), 1 =>User(\"Peter\"));\n",
102 | "\n",
103 | "function getuserfromdb(uid::Int)::Option\n",
104 | " result = nothing\n",
105 | " if uid in keys(DATABASE)\n",
106 | " result = DATABASE[uid]\n",
107 | " end\n",
108 | " return Option(result)\n",
109 | "end"
110 | ]
111 | },
112 | {
113 | "cell_type": "code",
114 | "execution_count": null,
115 | "id": "ca3af5f5-e3c1-4591-86c7-06872c070a79",
116 | "metadata": {},
117 | "outputs": [],
118 | "source": []
119 | }
120 | ],
121 | "metadata": {
122 | "kernelspec": {
123 | "display_name": "Julia 1.11.2",
124 | "language": "julia",
125 | "name": "julia-1.11"
126 | },
127 | "language_info": {
128 | "file_extension": ".jl",
129 | "mimetype": "application/julia",
130 | "name": "julia",
131 | "version": "1.11.2"
132 | }
133 | },
134 | "nbformat": 4,
135 | "nbformat_minor": 5
136 | }
137 |
--------------------------------------------------------------------------------
/FunctionalProgramming/Optics.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 6,
6 | "id": "a198696b-dc16-407f-98ce-880a2521ca68",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Documents/GitHub/Julia_Tutorials/FunctionalProgramming`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg\n",
19 | "Pkg.activate(\".\")\n",
20 | "using Accessors"
21 | ]
22 | },
23 | {
24 | "cell_type": "code",
25 | "execution_count": 7,
26 | "id": "93336aec-99f8-41e7-a3c6-1d8ff6451bf0",
27 | "metadata": {},
28 | "outputs": [],
29 | "source": [
30 | "struct T;a;b; end"
31 | ]
32 | },
33 | {
34 | "cell_type": "code",
35 | "execution_count": 9,
36 | "id": "747f117b-0a3e-4176-b788-520147d501d3",
37 | "metadata": {},
38 | "outputs": [
39 | {
40 | "data": {
41 | "text/plain": [
42 | "(@optic _.a)"
43 | ]
44 | },
45 | "execution_count": 9,
46 | "metadata": {},
47 | "output_type": "execute_result"
48 | }
49 | ],
50 | "source": [
51 | "obj = T(\"AA\", \"BB\");\n",
52 | "lens = @optic _.a"
53 | ]
54 | },
55 | {
56 | "cell_type": "code",
57 | "execution_count": 20,
58 | "id": "49dc24e0-c02e-4a30-be1e-5a8724c5e822",
59 | "metadata": {},
60 | "outputs": [
61 | {
62 | "data": {
63 | "text/plain": [
64 | "\"AA\""
65 | ]
66 | },
67 | "execution_count": 20,
68 | "metadata": {},
69 | "output_type": "execute_result"
70 | }
71 | ],
72 | "source": [
73 | "lens(obj)"
74 | ]
75 | },
76 | {
77 | "cell_type": "code",
78 | "execution_count": null,
79 | "id": "86f6e610-8343-416b-9196-e0c303aee382",
80 | "metadata": {},
81 | "outputs": [],
82 | "source": []
83 | }
84 | ],
85 | "metadata": {
86 | "kernelspec": {
87 | "display_name": "Julia 1.10.1",
88 | "language": "julia",
89 | "name": "julia-1.10"
90 | },
91 | "language_info": {
92 | "file_extension": ".jl",
93 | "mimetype": "application/julia",
94 | "name": "julia",
95 | "version": "1.10.1"
96 | }
97 | },
98 | "nbformat": 4,
99 | "nbformat_minor": 5
100 | }
101 |
--------------------------------------------------------------------------------
/FunctionalProgramming/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
3 | IsDef = "2704c575-34db-4e2b-9135-fc0075949e5a"
4 | IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e"
5 | Transducers = "28d57a85-8fef-5791-bfe6-a80928e7c999"
6 |
--------------------------------------------------------------------------------
/FunctionalProgramming/Untitled.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "id": "99501e80-bf91-4dfc-8b7b-20f23b143158",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Documents/GitHub/Julia_Tutorials/FunctionalProgramming`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg\n",
19 | "Pkg.activate(\".\")\n",
20 | "using MLStyle"
21 | ]
22 | },
23 | {
24 | "cell_type": "code",
25 | "execution_count": 7,
26 | "id": "ba577043-b1df-476e-87ac-ed6555f6005a",
27 | "metadata": {},
28 | "outputs": [
29 | {
30 | "data": {
31 | "text/plain": [
32 | "μ (generic function with 2 methods)"
33 | ]
34 | },
35 | "execution_count": 7,
36 | "metadata": {},
37 | "output_type": "execute_result"
38 | }
39 | ],
40 | "source": [
41 | "@data FreeF{a} begin\n",
42 | " Pure(::a)\n",
43 | " FreeList(::FreeF{a})\n",
44 | "end\n",
45 | "fmap(f::Function, x::Pure) = Pure(f(x._1))\n",
46 | "fmap(f::Function, x::FreeF) = free(fmap(y -> fmap(f, y), unfree(x)))\n",
47 | "unfree(x::Pure) = x._1\n",
48 | "unfree(x::FreeList) = List{FreeF}(x._1)\n",
49 | "free(x::Vector) = FreeList(x._1)\n",
50 | "\n",
51 | "fmap(f::Function, l::Vector) = map(f,l)\n",
52 | "mcata(λ, ρ, x::Pure) = λ(x._1)\n",
53 | "mcata(λ, ρ, x::FreeF) = ρ(fmap(y -> mcata(λ, ρ, y), unfree(x)))\n",
54 | "cata(alg::Function, x::Pure) = x._1\n",
55 | "cata(alg::Function, x::FreeF) = alg(fmap(y -> cata(alg, y), unfree(x)))\n",
56 | "\n",
57 | "# The η and μ make FreeF a monad\n",
58 | "η(x) = Pure(x)\n",
59 | "μ(x::Pure{<:FreeF}) = x._1\n",
60 | "μ(x::FreeF{<:FreeF}) = free(fmap(μ, unfree(x)))"
61 | ]
62 | },
63 | {
64 | "cell_type": "code",
65 | "execution_count": 11,
66 | "id": "39399c16-3df1-4523-b669-ac1f7dcbfe52",
67 | "metadata": {},
68 | "outputs": [
69 | {
70 | "data": {
71 | "text/plain": [
72 | "Pure{Vector{Int64}}([12, 3])"
73 | ]
74 | },
75 | "execution_count": 11,
76 | "metadata": {},
77 | "output_type": "execute_result"
78 | }
79 | ],
80 | "source": [
81 | "foldl("
82 | ]
83 | },
84 | {
85 | "cell_type": "code",
86 | "execution_count": 31,
87 | "id": "4095ddbb-2e6e-461d-948d-a5b399f0939e",
88 | "metadata": {},
89 | "outputs": [
90 | {
91 | "data": {
92 | "text/plain": [
93 | "map (generic function with 47 methods)"
94 | ]
95 | },
96 | "execution_count": 31,
97 | "metadata": {},
98 | "output_type": "execute_result"
99 | }
100 | ],
101 | "source": [
102 | "function unfix(x::Vector{T}) where T\n",
103 | " @match x begin\n",
104 | " [] => T[]\n",
105 | " _ => [x[begin]]\n",
106 | " end\n",
107 | "end\n",
108 | "\n",
109 | "fmap = map"
110 | ]
111 | },
112 | {
113 | "cell_type": "code",
114 | "execution_count": 32,
115 | "id": "fca60994-2366-4ddf-a226-f3bfe3bfe396",
116 | "metadata": {},
117 | "outputs": [
118 | {
119 | "data": {
120 | "text/plain": [
121 | "cata (generic function with 2 methods)"
122 | ]
123 | },
124 | "execution_count": 32,
125 | "metadata": {},
126 | "output_type": "execute_result"
127 | }
128 | ],
129 | "source": [
130 | "cata(alg, x::Vector) = alg(fmap(y -> cata(alg, y), unfix(x)))\n",
131 | "# cata(alg, x) = 1"
132 | ]
133 | },
134 | {
135 | "cell_type": "code",
136 | "execution_count": 33,
137 | "id": "f4edc5db-e48f-4570-bd1a-1da6b37e135d",
138 | "metadata": {},
139 | "outputs": [
140 | {
141 | "data": {
142 | "text/plain": [
143 | "algsum (generic function with 1 method)"
144 | ]
145 | },
146 | "execution_count": 33,
147 | "metadata": {},
148 | "output_type": "execute_result"
149 | }
150 | ],
151 | "source": [
152 | "function algsum(x::Vector{Int})\n",
153 | " @match x begin\n",
154 | " [] => 0\n",
155 | " _ => x[begin] + x[end]\n",
156 | " end\n",
157 | "end"
158 | ]
159 | },
160 | {
161 | "cell_type": "code",
162 | "execution_count": 34,
163 | "id": "3482e27a-d3e2-417f-9ff3-0e7b92e33385",
164 | "metadata": {},
165 | "outputs": [
166 | {
167 | "data": {
168 | "text/plain": [
169 | "2"
170 | ]
171 | },
172 | "execution_count": 34,
173 | "metadata": {},
174 | "output_type": "execute_result"
175 | }
176 | ],
177 | "source": [
178 | "cata(algsum, [1,2,3])"
179 | ]
180 | },
181 | {
182 | "cell_type": "code",
183 | "execution_count": null,
184 | "id": "89a9472a-44c6-4161-ba7a-a3e016fea25b",
185 | "metadata": {},
186 | "outputs": [],
187 | "source": []
188 | }
189 | ],
190 | "metadata": {
191 | "kernelspec": {
192 | "display_name": "Julia 1.10.1",
193 | "language": "julia",
194 | "name": "julia-1.10"
195 | },
196 | "language_info": {
197 | "file_extension": ".jl",
198 | "mimetype": "application/julia",
199 | "name": "julia",
200 | "version": "1.10.1"
201 | }
202 | },
203 | "nbformat": 4,
204 | "nbformat_minor": 5
205 | }
206 |
--------------------------------------------------------------------------------
/Generative_Art/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
3 | Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
4 | LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
5 | Luxor = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
6 | MathTeXEngine = "0a4f8689-d25c-4efe-a92b-7142dfc1aa53"
7 | Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
8 | Thebes = "8b424ff8-82f5-59a4-86a6-de3761897198"
9 |
--------------------------------------------------------------------------------
/Generative_Art/strange-vector.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/davibarreira/Julia_Tutorials/60c0d8309d0077c4297f9a188e6a947b61ed38ac/Generative_Art/strange-vector.png
--------------------------------------------------------------------------------
/GeometricAlgebra/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | CliffordAlgebras = "ca841f6f-225c-4bbd-a467-7a3512dfa6f6"
3 | GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
4 | LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
5 | Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
6 | PlotlyBase = "a03496cd-edff-5a9b-9e67-9cda94a718b5"
7 | PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
8 | PlotlyKaleido = "f2990250-8cf9-495f-b13a-cce12b45703c"
9 | Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
10 |
--------------------------------------------------------------------------------
/GeometricAlgebra/constructions.jl:
--------------------------------------------------------------------------------
1 | # Functions to Construct Elements in the Conformal Model.
2 |
3 | """
4 | line(p::MultiVector, q::MultiVector) = p ∧ q ∧ n∞
5 | """
6 | line(p::MultiVector, q::MultiVector) = p ∧ q ∧ n∞
7 |
8 | """
9 | line(v::Vector, p::MultiVector=point(0,0,0))
10 |
11 | Creates a line in the Conformal Model from a vector
12 | `v` passing through a point `p`.
13 | """
14 | function line(v::Vector, p::MultiVector=point(0,0,0))
15 | return p ∧ multivector(v) ∧ n∞
16 | end
17 |
18 |
19 | """
20 | plane(a::MultiVector,b::MultiVector,c::MultiVector) = a ∧ b ∧ c ∧ n∞
21 |
22 | Plane passing through points `a`, `b` and `c`.
23 | """
24 | plane(a::MultiVector,b::MultiVector,c::MultiVector) = a ∧ b ∧ c ∧ n∞
25 |
26 | """
27 | plane(n::MultiVector,δ::Union{Real,MultiVector}) = cdual(n + δ*n∞)
28 |
29 | Plane normal to vector `n` at a distance `δ` from the origin.
30 | """
31 | plane(n::MultiVector,δ::Union{Real,MultiVector}) = cdual(n + δ*n∞)
32 | function plane(n::Vector,δ::Real)
33 | n = n/norm(n)
34 | n = multivector(n)
35 | return plane(n, δ)
36 | end
37 |
38 |
39 | """
40 | circle(c::MultiVector, n::MultiVector, ρ::Real = 1.0)
41 |
42 | Circle centered at point `c`, with rotation plane
43 | normal to vector `n` and with radius `ρ`.
44 | """
45 | function circle(c::MultiVector, n::MultiVector, ρ::Real = 1.0)
46 | E = edual(n / norm(n))
47 | return (c + ρ^2 * n∞/2) ∧ (-c ⨼ (grin(E)*n∞))
48 | end
49 |
50 |
51 | """
52 | sphere(ρ::Real=1.0, c::MultiVector=point(0,0,0))
53 |
54 | Sphere centered at point `c` with radius `ρ`.
55 | """
56 | function sphere(ρ::Real=1.0, c::MultiVector=point(0,0,0))
57 | cdual(c - ρ^2 * n∞ /2)
58 | end
59 | function sphere(ρ::Real, c::Vector)
60 | cdual(point(c...) - ρ^2 * n∞ /2)
61 | end
62 | """
63 | sphere(a::MultiVector,b::MultiVector,c::MultiVector,d::MultiVector)
64 |
65 | Sphere passing through points `a`, `b`, `c` and `d`.
66 | """
67 | function sphere(a::MultiVector,b::MultiVector,c::MultiVector,d::MultiVector)
68 | a ∧ b ∧ c ∧ d
69 | end
70 |
71 | """
72 | getroundcenter(Σ)
73 |
74 | Returns the center of a round (e.g. circle or sphere).
75 |
76 | ```
77 | -(1/2)*(Σ * n∞ * Σ)/((n∞ ⨼ Σ)^2) # center
78 | ```
79 | """
80 | function getroundcenter(Σ)
81 | -(1/2)*(Σ * n∞ * Σ)/((n∞ ⨼ Σ)^2) # center
82 | end
83 |
84 |
85 | function getradius(Σ)
86 | ρsqr = scalar((Σ * grin(Σ))/((n∞ ⨼ Σ)^2));
87 | if ρsqr < 0
88 | return - √abs(ρsqr)
89 | end
90 | return √abs(ρsqr)
91 | end
92 |
93 | function getcircledirection(C)
94 | E = C ∧ n∞ # Carrier
95 | c = -(1/2)*(C * n∞ * C)/((n∞ ⨼ C)^2) # center
96 | weight = norm(n∞ ⨼ (no ⨼ E))
97 | A = n∞ ⨼ (no ⨼ E)/weight
98 | n = edual(A)
99 | return n
100 | end
101 |
--------------------------------------------------------------------------------
/GeometricAlgebra/plottingfunctions.jl:
--------------------------------------------------------------------------------
1 | using PlotlyJS
2 |
3 | """
4 | plotpoint(pts::Vector;
5 | mode="markers",
6 | plottype="scatter3d",
7 | kwargs...)
8 |
9 | Returns a scatter object from `PlotlyJS.jl` package.
10 | Use `p1 = plotpoint([point(1,1,1), point(2,2,2)])` then
11 | `plot(p1)` to visualize the plot. You can also
12 | define another plot such as `p2 = plotploint([point(0,0,0)])`
13 | and do `plot([p1,p2])`.
14 | """
15 | function plotpoint(pts::Vector;
16 | mode="markers",
17 | plottype="scatter3d",
18 | kwargs...)
19 |
20 | x = [i.e1 for i in pts]
21 | y = [i.e2 for i in pts]
22 | z = [i.e3 for i in pts]
23 |
24 | scatter(x=x,y=y,z=z,mode=mode,type=plottype;kwargs...)
25 | end
26 |
27 | """
28 | plotpoint(p::MultiVector; plottype="scatter3d", kwargs...)
29 |
30 | Returns a scatter object from `PlotlyJS.jl` package.
31 | """
32 | function plotpoint(p::MultiVector; plottype="scatter3d", kwargs...)
33 | plotpoint([p];plottype=plottype, kwargs...)
34 | end
35 |
36 |
37 | function extractpairpoints(p_q::MultiVector)
38 | T = p_q
39 | G = T/√scalar(T^2)
40 | Prj = (1+G)/2
41 | p = Prj * ((T) ⋅ n∞) * reverse(Prj)
42 | q = -reverse(Prj) * ((T) ⋅ n∞) * Prj
43 | return p,q
44 | end
45 |
46 | """
47 | plotpointpair(p_q::MultiVector;
48 | marker=attr(symbol="circle-open"),
49 | plottype="scatter3d", kwargs...)
50 |
51 | It takes as input a point pair e.g. `point(1,1,1) ∧ point(0,0,0)`.
52 | Returns a scatter object from `PlotlyJS.jl`.
53 | """
54 | function plotpointpair(p_q::MultiVector;
55 | marker=attr(symbol="circle-open"),
56 | plottype="scatter3d", kwargs...)
57 |
58 | p,q = extractpairpoints(p_q)
59 | plotpoint([p,q]; plottype = plottype, marker = marker, kwargs...)
60 | end
61 |
62 |
63 | """
64 | plotline(l::MultiVector,
65 | linelengthfactor=1;
66 | anchor=nothing,
67 | mode="lines",
68 | plottype="scatter3d",
69 | kwargs...)
70 |
71 | It takes a line `l` from the Conformal Model.
72 | One can define a line by `p ∧ q ∧ n∞`, or using the
73 | helper function `line(p,q)`.
74 | The `anchor` is a point from where the line is spanned.
75 | If none is provided, the function uses the support point as anchor,
76 | i.e. the line is spanned from the closes point to the origin.
77 |
78 | Returns a scatter object from `PlotlyJS.jl`.
79 | """
80 | function plotline(l::MultiVector,
81 | linelengthfactor=1;
82 | anchor=nothing,
83 | mode="lines",
84 | plottype="scatter3d",
85 | kwargs...)
86 |
87 | weight = norm(n∞ ⨼ (no ⨼ l))
88 | v = n∞ ⨼ (no ⨼ l)/weight
89 |
90 | if isnothing(anchor)
91 | d = getblades((no ⨼ l) / l)
92 | else
93 | d = getblades((anchor ⨼ l)/l)
94 | end
95 |
96 | lstart = linelengthfactor*v + d
97 | lend = -linelengthfactor*v + d
98 |
99 | x = [i.e1 for i in [lstart,lend]]
100 | y = [i.e2 for i in [lstart,lend]]
101 | z = [i.e3 for i in [lstart,lend]]
102 |
103 | scatter(x=x,y=y,z=z,mode=mode,type=plottype;kwargs...)
104 | end
105 |
106 |
107 | """
108 | plotplane(Π::MultiVector,
109 | planelengthfactor=1;
110 | color="rgba(244,22,100,0.6)",
111 | kwargs...)
112 |
113 | It takes a direct plane object from the Conformal Model,
114 | e.g. `plane(a,b,c) = a ∧ b ∧ c ∧ n∞`.
115 | Returns a mesh3d object from `PlotlyJS.jl`.
116 | """
117 | function plotplane(Π::MultiVector,
118 | planelengthfactor=1;
119 | color="rgba(244,22,100,0.6)",
120 | kwargs...)
121 |
122 | weight = norm(n∞ ⨼ (no ⨼ Π))
123 | A = n∞ ⨼ (no ⨼ Π)/weight
124 | n = edual(A)
125 |
126 | d_vec = getblades((no ⨼ Π) / Π)
127 | d = F(d_vec)
128 |
129 | δ = norm(d_vec)
130 | pts = [
131 | translate(d, planelengthfactor* point(1,0,0)),
132 | translate(d, planelengthfactor* point(0,1,0)),
133 | translate(d, planelengthfactor* point(0,0,1)),
134 | translate(d, planelengthfactor* point(-1,0,0)),
135 | translate(d, planelengthfactor* point(0,-1,0)),
136 | translate(d, planelengthfactor* point(0,0,-1)),
137 | ]
138 |
139 | # Project points into plane Π
140 | pts = [(p ⨼ Π)/Π for p in pts]
141 |
142 | x = [i.e1 for i in pts]
143 | y = [i.e2 for i in pts]
144 | z = [i.e3 for i in pts]
145 |
146 | mesh3d(x=x,y=y,z=z;color=color, kwargs...)
147 | end
148 |
149 |
150 | """
151 | plotcircle(C::MultiVector; mode = "lines", kwargs...)
152 |
153 | Takes a direct circle in the Conformal Model.
154 | Returns a scatter object from `PlotlyJS.jl`.
155 | """
156 | function plotcircle(C::MultiVector; mode = "lines", kwargs...)
157 | E = C ∧ n∞ # Carrier
158 | c = -(1/2)*(C * n∞ * C)/((n∞ ⨼ C)^2) # center
159 | ρ = √scalar(C*grin(C)/(n∞ ⨼ C)^2) # radius
160 |
161 | weight = norm(n∞ ⨼ (no ⨼ E))
162 | A = n∞ ⨼ (no ⨼ E)/weight
163 | n = edual(A)
164 | A = translate(A, c)
165 |
166 | u = n + cl.e1
167 | if n == cl.e1
168 | u = n + cl.e2
169 | end
170 | t = c ∧ ( c ⨼ ( u ∧ n∞)) # Tangent vector translated to c
171 | t = (t ⨼ E) / E
172 | u = getblades(-(n∞ ⨼ t))
173 |
174 | ϕs = 0:0.1:2π
175 | ϕs = vcat(ϕs,0)
176 | tp = F(ρ* u/norm(u) + getblades(c))
177 | ts = []
178 | push!(ts,tp)
179 | for ϕ in ϕs
180 | R = exp(-A*ϕ/2)
181 | tr = R*tp*reverse(R)
182 | push!(ts,tr)
183 | end
184 | plotpoint(ts; mode=mode, kwargs...)
185 | end
186 |
187 |
188 |
189 | """
190 | generatespherepoints(Σ)
191 |
192 | Helper function to generate points in the sphere.
193 | """
194 | function generatespherepoints(Σ)
195 | ρ = √scalar((Σ * grin(Σ))/((n∞ ⨼ Σ)^2));
196 | c = -(1/2)*(Σ * n∞ * Σ)/((n∞ ⨼ Σ)^2)
197 |
198 | n = 100
199 | u = range(-π, π; length = n)
200 | v = range(0, π; length = n)
201 | x = ρ.*cos.(u) * sin.(v)' .+ c.e1
202 | y = ρ.*sin.(u) * sin.(v)' .+ c.e2
203 | z = ρ.*ones(n) * cos.(v)' .+ c.e3
204 | return x,y,z
205 | end
206 |
207 |
208 | """
209 | plotsphere(Σ::MultiVector;showscale=false,kwargs...)
210 |
211 | Takes a direct sphere from the Conformal Model.
212 |
213 | Returns a surface object from `PlotlyJS.jl` package.
214 | """
215 | function plotsphere(Σ::MultiVector;showscale=false,kwargs...)
216 | x,y,z = generatespherepoints(Σ)
217 | surface(x=x, y=y, z=z;showscale=showscale, kwargs...)
218 | end
219 |
--------------------------------------------------------------------------------
/GeometricAlgebra/reflection.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/davibarreira/Julia_Tutorials/60c0d8309d0077c4297f9a188e6a947b61ed38ac/GeometricAlgebra/reflection.png
--------------------------------------------------------------------------------
/GeometricAlgebra/reflection.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
87 |
--------------------------------------------------------------------------------
/GeometricModeling/DiscreteGeometry-I.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "id": "7a6cc55e-5f32-4b23-a606-45cae1413fee",
7 | "metadata": {},
8 | "outputs": [],
9 | "source": []
10 | }
11 | ],
12 | "metadata": {
13 | "kernelspec": {
14 | "display_name": "Julia 1.8.2",
15 | "language": "julia",
16 | "name": "julia-1.8"
17 | },
18 | "language_info": {
19 | "file_extension": ".jl",
20 | "mimetype": "application/julia",
21 | "name": "julia",
22 | "version": "1.8.2"
23 | }
24 | },
25 | "nbformat": 4,
26 | "nbformat_minor": 5
27 | }
28 |
--------------------------------------------------------------------------------
/GeometricModeling/Harmonic_Map.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 2,
6 | "id": "4b7d5892-ad32-4326-ba21-17a819803e5f",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/MEGA/EMAP/Julia_Tutorials`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg, Revise\n",
19 | "Pkg.activate(\"../.\")\n",
20 | "using BasicBSpline\n",
21 | "using StaticArrays\n",
22 | "using Plots\n",
23 | "using LinearAlgebra"
24 | ]
25 | },
26 | {
27 | "cell_type": "code",
28 | "execution_count": null,
29 | "id": "07b31936-7db8-4e0e-bb05-2127e6c1a29d",
30 | "metadata": {},
31 | "outputs": [],
32 | "source": []
33 | }
34 | ],
35 | "metadata": {
36 | "kernelspec": {
37 | "display_name": "Julia 1.10.3",
38 | "language": "julia",
39 | "name": "julia-1.10"
40 | },
41 | "language_info": {
42 | "file_extension": ".jl",
43 | "mimetype": "application/julia",
44 | "name": "julia",
45 | "version": "1.10.3"
46 | }
47 | },
48 | "nbformat": 4,
49 | "nbformat_minor": 5
50 | }
51 |
--------------------------------------------------------------------------------
/GeometricModeling/Meshes2.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "id": "a9441335-381e-4ecd-ac23-a58a670cae51",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/MEGA/EMAP/Julia_Tutorials`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg, Revise\n",
19 | "Pkg.activate(\"../.\")\n",
20 | "using Plots\n",
21 | "using LinearAlgebra\n",
22 | "using Dictionaries"
23 | ]
24 | },
25 | {
26 | "cell_type": "code",
27 | "execution_count": 18,
28 | "id": "e0678336-92d6-4d1e-a356-e4dd3f313e17",
29 | "metadata": {},
30 | "outputs": [],
31 | "source": [
32 | "struct Vertex\n",
33 | " vertexid::Int\n",
34 | " position::Vector\n",
35 | " halfedge::Int\n",
36 | "end\n",
37 | "\n",
38 | "struct Face\n",
39 | " faceid::Int\n",
40 | " halfegde::Int\n",
41 | "end\n",
42 | "\n",
43 | "struct Edge\n",
44 | " length::Real\n",
45 | " lefthalfedge::Int\n",
46 | " righthalfedge::Int\n",
47 | "end\n",
48 | "\n",
49 | "struct HalfEdge\n",
50 | " prevhalfedge::Int\n",
51 | " nexthalfedge::Int\n",
52 | " edge::Int\n",
53 | " face::Int\n",
54 | " vertex::Int\n",
55 | "end\n",
56 | "\n",
57 | "struct Mesh\n",
58 | " V::Vector{Vertex}\n",
59 | " F::Vector{Face}\n",
60 | "end"
61 | ]
62 | },
63 | {
64 | "cell_type": "code",
65 | "execution_count": 89,
66 | "id": "b057c392-9708-4ce6-ae52-8290c5eccbbc",
67 | "metadata": {},
68 | "outputs": [
69 | {
70 | "data": {
71 | "text/plain": [
72 | "1-element Dictionary{String, Int64}\n",
73 | " \"face\" │ 1"
74 | ]
75 | },
76 | "execution_count": 89,
77 | "metadata": {},
78 | "output_type": "execute_result"
79 | }
80 | ],
81 | "source": [
82 | "# function Mesh(V,F) \n",
83 | "# F = []\n",
84 | "# E = []\n",
85 | "# H = Dict()\n",
86 | "# for f in faces\n",
87 | "# v1,v2,v3 = V[f[1]],V[f[2]],V[f[3]]\n",
88 | "# e1 = Edge(v1,v2)\n",
89 | "# e2 = Edge(v2,v3)\n",
90 | "# e3 = Edge(v3,v1)\n",
91 | "# E = vcat([e1,e2,e3],E)\n",
92 | "# F = vcat([Face([v1,v2,v3])],F)\n",
93 | "# end\n",
94 | "# Mesh(V,E,F) \n",
95 | "# end\n",
96 | "\n",
97 | "vlist = [[0,0,0],[1,0,0],[0,1,0],[-1,0,0]]\n",
98 | "flist = [[1,2,3],[1,4,3]]\n",
99 | "\n",
100 | "V = Dictionary()\n",
101 | "map(x -> insert!(V,x[1],x[2]),enumerate(vlist));\n",
102 | "H = Dictionary()\n",
103 | "\n",
104 | "for (i,f) in enumerate(flist)\n",
105 | " insert!(H,(f[1],f[2]),Dictionary([\"face\"],[i]))\n",
106 | " # H[(f[1],f[2])] = Dict(\"face\"=>i)\n",
107 | "end\n",
108 | "# V[1]\n",
109 | "# insert!(V, 1, vlist[1])\n",
110 | "# insert!(V, 2, vlist[1])\n",
111 | "# insert!(V, 3, vlist[1])\n",
112 | "\n",
113 | "# map(x->x[1], enumerate(vlist))\n",
114 | "\n",
115 | "# [i for i in keys(H)]\n",
116 | "# H[(1,2)][1][2]\n",
117 | "H[(1,2)]\n"
118 | ]
119 | },
120 | {
121 | "cell_type": "code",
122 | "execution_count": 14,
123 | "id": "54310b14-4262-4845-a149-9c6eeceae228",
124 | "metadata": {},
125 | "outputs": [],
126 | "source": [
127 | "V = [[0,0,0],[1,0,0],[0,1,0],[-1,0,0]]\n",
128 | "F = [[1,2,3],[1,4,3]]\n",
129 | "obj = (V,F);\n",
130 | "\n",
131 | "function generatemesh(V::Vector, faces::Vector) \n",
132 | " listfaces = []\n",
133 | " listhalfedges = []\n",
134 | " listvertices = []\n",
135 | " for (i,f) in faces\n",
136 | " push!(listfaces,i)\n",
137 | " V[f[1]]\n",
138 | " end\n",
139 | "end\n",
140 | "\n",
141 | "generatemesh(V,F)"
142 | ]
143 | },
144 | {
145 | "cell_type": "code",
146 | "execution_count": 8,
147 | "id": "c233f808-9bdc-4851-99fe-e7d9c623a897",
148 | "metadata": {},
149 | "outputs": [
150 | {
151 | "name": "stdout",
152 | "output_type": "stream",
153 | "text": [
154 | "1"
155 | ]
156 | }
157 | ],
158 | "source": [
159 | "for (i,f) in enumerate(F)\n",
160 | " print(i)\n",
161 | "end"
162 | ]
163 | },
164 | {
165 | "cell_type": "code",
166 | "execution_count": null,
167 | "id": "5f58628e-da88-40da-95cf-0e4adb09d572",
168 | "metadata": {},
169 | "outputs": [],
170 | "source": []
171 | }
172 | ],
173 | "metadata": {
174 | "kernelspec": {
175 | "display_name": "Julia 1.8.2",
176 | "language": "julia",
177 | "name": "julia-1.8"
178 | },
179 | "language_info": {
180 | "file_extension": ".jl",
181 | "mimetype": "application/julia",
182 | "name": "julia",
183 | "version": "1.8.2"
184 | }
185 | },
186 | "nbformat": 4,
187 | "nbformat_minor": 5
188 | }
189 |
--------------------------------------------------------------------------------
/GeometricModeling/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | BasicBSpline = "4c5d9882-2acf-4ea4-9e48-968fd4518195"
3 | IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
4 | Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
5 | StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
6 |
--------------------------------------------------------------------------------
/Geospatial/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
3 | GeoJSON = "61d90e0f-e114-555e-ac52-39dfb47a3ef9"
4 | Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4"
5 |
--------------------------------------------------------------------------------
/Geospatial/Untitled.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 11,
6 | "id": "efa4b456-7dfb-4a0c-8f73-21ec2803c70c",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Documents/GitHub/Julia_Tutorials/Geospatial`\n",
14 | "\u001b[36m\u001b[1m[ \u001b[22m\u001b[39m\u001b[36m\u001b[1mInfo: \u001b[22m\u001b[39mPrecompiling DataFrames [a93c6f00-e57d-5684-b7b6-d8193f3e46c0]\n"
15 | ]
16 | }
17 | ],
18 | "source": [
19 | "using Pkg\n",
20 | "Pkg.activate(\".\")\n",
21 | "using GeoJSON\n",
22 | "using DataFrames"
23 | ]
24 | },
25 | {
26 | "cell_type": "code",
27 | "execution_count": 10,
28 | "id": "9349aaf6-e38c-4b57-8eb5-7326adf29880",
29 | "metadata": {},
30 | "outputs": [
31 | {
32 | "data": {
33 | "text/plain": [
34 | "FeatureCollection with 127 Features"
35 | ]
36 | },
37 | "execution_count": 10,
38 | "metadata": {},
39 | "output_type": "execute_result"
40 | }
41 | ],
42 | "source": [
43 | "fc = GeoJSON.read(\"./data/ne_110m_land.geojson\")"
44 | ]
45 | },
46 | {
47 | "cell_type": "code",
48 | "execution_count": 16,
49 | "id": "9a45cb32-3613-4cbb-b291-e62574964e55",
50 | "metadata": {},
51 | "outputs": [],
52 | "source": [
53 | "df = DataFrame(fc);"
54 | ]
55 | },
56 | {
57 | "cell_type": "code",
58 | "execution_count": 21,
59 | "id": "3e32b488-150d-458c-9281-d97f42d49638",
60 | "metadata": {},
61 | "outputs": [
62 | {
63 | "data": {
64 | "text/plain": [
65 | "1-element Vector{Vector{Tuple{Float32, Float32}}}:\n",
66 | " [(-59.572094, -80.04018), (-59.86585, -80.54966), (-60.159657, -81.00033), (-62.255394, -80.863174), (-64.48813, -80.921936), (-65.74167, -80.58883), (-65.74167, -80.54966), (-66.29003, -80.255775), (-64.03769, -80.294945), (-61.883247, -80.39287), (-61.138977, -79.98137), (-60.61012, -79.62868), (-59.572094, -80.04018)]"
67 | ]
68 | },
69 | "execution_count": 21,
70 | "metadata": {},
71 | "output_type": "execute_result"
72 | }
73 | ],
74 | "source": [
75 | "df[1,:geometry].coordinates"
76 | ]
77 | }
78 | ],
79 | "metadata": {
80 | "kernelspec": {
81 | "display_name": "julia 1.11.4",
82 | "language": "julia",
83 | "name": "julia-1.11"
84 | },
85 | "language_info": {
86 | "file_extension": ".jl",
87 | "mimetype": "application/julia",
88 | "name": "julia",
89 | "version": "1.11.4"
90 | }
91 | },
92 | "nbformat": 4,
93 | "nbformat_minor": 5
94 | }
95 |
--------------------------------------------------------------------------------
/Geospatial/data/land.shp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/davibarreira/Julia_Tutorials/60c0d8309d0077c4297f9a188e6a947b61ed38ac/Geospatial/data/land.shp
--------------------------------------------------------------------------------
/Graphs/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
3 | Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
4 | DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
5 | GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
6 | Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
7 | SimpleWeightedGraphs = "47aef6b3-ad0c-573a-a1e2-d07658019622"
8 |
--------------------------------------------------------------------------------
/HeatMethod/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
3 | CoDa = "5900dafe-f573-5c72-b367-76665857777b"
4 | CoordRefSystems = "b46f11dc-f210-4604-bfba-323c1ec968cb"
5 | DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
6 | DelaunayTriangulation = "927a84f5-c5f4-47a5-9785-b46e178433df"
7 | GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
8 | GeoIO = "f5a160d5-e41d-4189-8b61-d57781c419e3"
9 | GeoStats = "dcc97b0b-8ce5-5539-9008-bb190f959ef6"
10 | GeoTables = "e502b557-6362-48c1-8219-d30d308dcdb0"
11 | Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
12 | Manifolds = "1cead3c2-87b3-11e9-0ccd-23c62b72b94e"
13 | Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
14 | PairPlots = "43a3c2be-4208-490b-832a-a21dcd55d7da"
15 | Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
16 | WGLMakie = "276b4fcb-3e11-5398-bf8b-a0c2d153d008"
17 |
--------------------------------------------------------------------------------
/Julia+Javascript/Tutorial_JSServe.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "147d523c-0048-41ca-a490-09b169d82711",
6 | "metadata": {},
7 | "source": [
8 | "# **Julia + Javascript** 💻\n",
9 | "\n",
10 | "It might be very useful to have a fast connection between Julia and Javascript. Take for example interactive plots,\n",
11 | "where the user is moving the mouse aroung the graph and you wish to showcase tooltips. It's very common for users to\n",
12 | "be in the browser (e.g. Jupyter or Pluto notebooks), so you can make use of it.\n",
13 | "Hence, we need to create a server that runs Javascript and communicates with Julia, in order to execute commands in Julia\n",
14 | "based on what the user did on the browser.\n",
15 | "\n",
16 | "Here is where `JSServe.jl` comes in. This package creates a fast connection between Julia and Javascript, which is exactly what we\n",
17 | "wish to use. Unfortunantely, at this moment, the documentation is not very good, so we are going to use this tutorial as a way\n",
18 | "of organizing a bit more how it's used."
19 | ]
20 | },
21 | {
22 | "cell_type": "code",
23 | "execution_count": 1,
24 | "id": "591ac91e-b424-4c6b-a730-077c92ab818a",
25 | "metadata": {},
26 | "outputs": [
27 | {
28 | "name": "stderr",
29 | "output_type": "stream",
30 | "text": [
31 | "┌ Info: Precompiling JSServe [824d6782-a2ef-11e9-3a09-e5662e0c26f9]\n",
32 | "└ @ Base loading.jl:1423\n"
33 | ]
34 | }
35 | ],
36 | "source": [
37 | "using JSServe"
38 | ]
39 | },
40 | {
41 | "cell_type": "code",
42 | "execution_count": null,
43 | "id": "1030d55e-8987-41a1-97a5-3d173a36ec75",
44 | "metadata": {},
45 | "outputs": [],
46 | "source": []
47 | }
48 | ],
49 | "metadata": {
50 | "kernelspec": {
51 | "display_name": "Julia 1.7.0",
52 | "language": "julia",
53 | "name": "julia-1.7"
54 | },
55 | "language_info": {
56 | "file_extension": ".jl",
57 | "mimetype": "application/julia",
58 | "name": "julia",
59 | "version": "1.7.0"
60 | }
61 | },
62 | "nbformat": 4,
63 | "nbformat_minor": 5
64 | }
65 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Davi Sales Barreira
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/MachineLearning/Flux_Tutorial_img1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/davibarreira/Julia_Tutorials/60c0d8309d0077c4297f9a188e6a947b61ed38ac/MachineLearning/Flux_Tutorial_img1.png
--------------------------------------------------------------------------------
/MachineLearning/Flux_Tutorial_img2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/davibarreira/Julia_Tutorials/60c0d8309d0077c4297f9a188e6a947b61ed38ac/MachineLearning/Flux_Tutorial_img2.png
--------------------------------------------------------------------------------
/MachineLearning/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | BetaML = "024491cd-cc6b-443e-8034-08ea7eb7db2b"
3 | DecisionTree = "7806a523-6efd-50cb-b5f6-3fa6f1930dbb"
4 | EvoTrees = "f6006082-12f8-11e9-0c9c-0d5d367ab1e5"
5 | MLJ = "add582a8-e3ab-11e8-2d5e-e98b27df1bc7"
6 | MLJDecisionTreeInterface = "c6f25543-311c-4c74-83dc-3ea6d1015661"
7 | MLJModels = "d491faf4-2d78-11e9-2867-c94bc002c0b7"
8 | VegaLite = "112f6efa-9a02-5b7d-90c0-432ed331239a"
9 |
--------------------------------------------------------------------------------
/MachineLearning/RecommendationSystem.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "id": "df3e569b-367e-435b-95bb-22673556046d",
7 | "metadata": {},
8 | "outputs": [],
9 | "source": []
10 | }
11 | ],
12 | "metadata": {
13 | "kernelspec": {
14 | "display_name": "julia 1.7.1",
15 | "language": "julia",
16 | "name": "julia-1.7"
17 | },
18 | "language_info": {
19 | "file_extension": ".jl",
20 | "mimetype": "application/julia",
21 | "name": "julia",
22 | "version": "1.7.1"
23 | }
24 | },
25 | "nbformat": 4,
26 | "nbformat_minor": 5
27 | }
28 |
--------------------------------------------------------------------------------
/Manifolds/2106.08777.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/davibarreira/Julia_Tutorials/60c0d8309d0077c4297f9a188e6a947b61ed38ac/Manifolds/2106.08777.pdf
--------------------------------------------------------------------------------
/Manifolds/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
3 | ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
4 | Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
5 | Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
6 | Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
7 | Luxor = "ae8d54c2-7ccd-5906-9d76-62fc9837b5bc"
8 | Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
9 | Manifolds = "1cead3c2-87b3-11e9-0ccd-23c62b72b94e"
10 | ManifoldsBase = "3362f125-f0bb-47a3-aa74-596ffd7ef2fb"
11 | Manopt = "0fc0a36d-df90-57f3-8f93-d78a9fc72bb5"
12 | MeshViz = "9ecf9c4f-6e5a-4b5e-83ae-06f2c7a661d8"
13 | Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
14 | MultivariateStats = "6f286f6a-111f-5878-ab1e-185364afe411"
15 | PlyIO = "42171d58-473b-503a-8d5f-782019eb09ec"
16 | Thebes = "8b424ff8-82f5-59a4-86a6-de3761897198"
17 |
--------------------------------------------------------------------------------
/Maps/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | GMT = "5752ebe1-31b9-557e-87aa-f909b540aa54"
3 |
--------------------------------------------------------------------------------
/Maps/gmt.history:
--------------------------------------------------------------------------------
1 | # GMT 6 Session common arguments shelf
2 | BEGIN GMT 6.5.0
3 | B g
4 | J N
5 | JN N12
6 | JX X15c/0
7 | R d
8 | @L 2
9 | END
10 |
--------------------------------------------------------------------------------
/MetaProgramming/Manifest.toml:
--------------------------------------------------------------------------------
1 | # This file is machine-generated - editing it directly is not advised
2 |
3 | julia_version = "1.10.0"
4 | manifest_format = "2.0"
5 | project_hash = "979e40bc411ca0078d9ff46f9e8a5534572dbe2a"
6 |
7 | [[deps.Artifacts]]
8 | uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
9 |
10 | [[deps.Base64]]
11 | uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
12 |
13 | [[deps.Compat]]
14 | deps = ["TOML", "UUIDs"]
15 | git-tree-sha1 = "75bd5b6fc5089df449b5d35fa501c846c9b6549b"
16 | uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
17 | version = "4.12.0"
18 | weakdeps = ["Dates", "LinearAlgebra"]
19 |
20 | [deps.Compat.extensions]
21 | CompatLinearAlgebraExt = "LinearAlgebra"
22 |
23 | [[deps.CompilerSupportLibraries_jll]]
24 | deps = ["Artifacts", "Libdl"]
25 | uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
26 | version = "1.0.5+1"
27 |
28 | [[deps.DataAPI]]
29 | git-tree-sha1 = "abe83f3a2f1b857aac70ef8b269080af17764bbe"
30 | uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
31 | version = "1.16.0"
32 |
33 | [[deps.DataStructures]]
34 | deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
35 | git-tree-sha1 = "ac67408d9ddf207de5cfa9a97e114352430f01ed"
36 | uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
37 | version = "0.18.16"
38 |
39 | [[deps.Dates]]
40 | deps = ["Printf"]
41 | uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
42 |
43 | [[deps.DocStringExtensions]]
44 | deps = ["LibGit2"]
45 | git-tree-sha1 = "2fb1e02f2b635d0845df5d7c167fec4dd739b00d"
46 | uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
47 | version = "0.9.3"
48 |
49 | [[deps.InteractiveUtils]]
50 | deps = ["Markdown"]
51 | uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
52 |
53 | [[deps.IrrationalConstants]]
54 | git-tree-sha1 = "630b497eafcc20001bba38a4651b327dcfc491d2"
55 | uuid = "92d709cd-6900-40b7-9082-c6be49f344b6"
56 | version = "0.2.2"
57 |
58 | [[deps.LibGit2]]
59 | deps = ["Base64", "LibGit2_jll", "NetworkOptions", "Printf", "SHA"]
60 | uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
61 |
62 | [[deps.LibGit2_jll]]
63 | deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll"]
64 | uuid = "e37daf67-58a4-590a-8e99-b0245dd2ffc5"
65 | version = "1.6.4+0"
66 |
67 | [[deps.LibSSH2_jll]]
68 | deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
69 | uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"
70 | version = "1.11.0+1"
71 |
72 | [[deps.Libdl]]
73 | uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
74 |
75 | [[deps.LinearAlgebra]]
76 | deps = ["Libdl", "OpenBLAS_jll", "libblastrampoline_jll"]
77 | uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
78 |
79 | [[deps.LogExpFunctions]]
80 | deps = ["DocStringExtensions", "IrrationalConstants", "LinearAlgebra"]
81 | git-tree-sha1 = "7d6dd4e9212aebaeed356de34ccf262a3cd415aa"
82 | uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688"
83 | version = "0.3.26"
84 |
85 | [deps.LogExpFunctions.extensions]
86 | LogExpFunctionsChainRulesCoreExt = "ChainRulesCore"
87 | LogExpFunctionsChangesOfVariablesExt = "ChangesOfVariables"
88 | LogExpFunctionsInverseFunctionsExt = "InverseFunctions"
89 |
90 | [deps.LogExpFunctions.weakdeps]
91 | ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
92 | ChangesOfVariables = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0"
93 | InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112"
94 |
95 | [[deps.MacroTools]]
96 | deps = ["Markdown", "Random"]
97 | git-tree-sha1 = "2fa9ee3e63fd3a4f7a9a4f4744a52f4856de82df"
98 | uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
99 | version = "0.5.13"
100 |
101 | [[deps.Markdown]]
102 | deps = ["Base64"]
103 | uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
104 |
105 | [[deps.MbedTLS_jll]]
106 | deps = ["Artifacts", "Libdl"]
107 | uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
108 | version = "2.28.2+1"
109 |
110 | [[deps.Missings]]
111 | deps = ["DataAPI"]
112 | git-tree-sha1 = "f66bdc5de519e8f8ae43bdc598782d35a25b1272"
113 | uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28"
114 | version = "1.1.0"
115 |
116 | [[deps.NetworkOptions]]
117 | uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
118 | version = "1.2.0"
119 |
120 | [[deps.OpenBLAS_jll]]
121 | deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
122 | uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
123 | version = "0.3.23+2"
124 |
125 | [[deps.OrderedCollections]]
126 | git-tree-sha1 = "dfdf5519f235516220579f949664f1bf44e741c5"
127 | uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
128 | version = "1.6.3"
129 |
130 | [[deps.Printf]]
131 | deps = ["Unicode"]
132 | uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
133 |
134 | [[deps.Random]]
135 | deps = ["SHA"]
136 | uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
137 |
138 | [[deps.SHA]]
139 | uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
140 | version = "0.7.0"
141 |
142 | [[deps.Serialization]]
143 | uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
144 |
145 | [[deps.SortingAlgorithms]]
146 | deps = ["DataStructures"]
147 | git-tree-sha1 = "66e0a8e672a0bdfca2c3f5937efb8538b9ddc085"
148 | uuid = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
149 | version = "1.2.1"
150 |
151 | [[deps.SparseArrays]]
152 | deps = ["Libdl", "LinearAlgebra", "Random", "Serialization", "SuiteSparse_jll"]
153 | uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
154 | version = "1.10.0"
155 |
156 | [[deps.Statistics]]
157 | deps = ["LinearAlgebra", "SparseArrays"]
158 | uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
159 | version = "1.10.0"
160 |
161 | [[deps.StatsAPI]]
162 | deps = ["LinearAlgebra"]
163 | git-tree-sha1 = "1ff449ad350c9c4cbc756624d6f8a8c3ef56d3ed"
164 | uuid = "82ae8749-77ed-4fe6-ae5f-f523153014b0"
165 | version = "1.7.0"
166 |
167 | [[deps.StatsBase]]
168 | deps = ["DataAPI", "DataStructures", "LinearAlgebra", "LogExpFunctions", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics", "StatsAPI"]
169 | git-tree-sha1 = "1d77abd07f617c4868c33d4f5b9e1dbb2643c9cf"
170 | uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
171 | version = "0.34.2"
172 |
173 | [[deps.SuiteSparse_jll]]
174 | deps = ["Artifacts", "Libdl", "libblastrampoline_jll"]
175 | uuid = "bea87d4a-7f5b-5778-9afe-8cc45184846c"
176 | version = "7.2.1+1"
177 |
178 | [[deps.TOML]]
179 | deps = ["Dates"]
180 | uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
181 | version = "1.0.3"
182 |
183 | [[deps.UUIDs]]
184 | deps = ["Random", "SHA"]
185 | uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
186 |
187 | [[deps.Unicode]]
188 | uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
189 |
190 | [[deps.libblastrampoline_jll]]
191 | deps = ["Artifacts", "Libdl"]
192 | uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"
193 | version = "5.8.0+1"
194 |
--------------------------------------------------------------------------------
/MetaProgramming/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
3 | Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
4 | StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
5 |
--------------------------------------------------------------------------------
/MetaProgramming/Untitled.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 5,
6 | "id": "1bbe59c1-ddd5-4011-972a-e1f499f98a3e",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Main/EMAp/Julia_Tutorials/MetaProgramming`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg\n",
19 | "Pkg.activate(\".\")\n",
20 | "using MLStyle"
21 | ]
22 | },
23 | {
24 | "cell_type": "code",
25 | "execution_count": 13,
26 | "id": "7781e0cc-5faf-4ff7-870c-19e678df2241",
27 | "metadata": {},
28 | "outputs": [
29 | {
30 | "data": {
31 | "text/plain": [
32 | "true"
33 | ]
34 | },
35 | "execution_count": 13,
36 | "metadata": {},
37 | "output_type": "execute_result"
38 | }
39 | ],
40 | "source": [
41 | "f = (x,y)->(x^2+y)\n",
42 | "ex = :($f(a, b))\n",
43 | "\n",
44 | "f == @match ex begin\n",
45 | " :($f(a, b)) => f\n",
46 | "end # => true"
47 | ]
48 | },
49 | {
50 | "cell_type": "code",
51 | "execution_count": 12,
52 | "id": "438c6fe7-40b1-4bab-84f6-f1dc9493f0d4",
53 | "metadata": {},
54 | "outputs": [
55 | {
56 | "data": {
57 | "text/plain": [
58 | "#7 (generic function with 1 method)"
59 | ]
60 | },
61 | "execution_count": 12,
62 | "metadata": {},
63 | "output_type": "execute_result"
64 | }
65 | ],
66 | "source": [
67 | "f"
68 | ]
69 | },
70 | {
71 | "cell_type": "code",
72 | "execution_count": null,
73 | "id": "80a4e6e3-eba0-48da-a32f-769c72d742cf",
74 | "metadata": {},
75 | "outputs": [],
76 | "source": []
77 | }
78 | ],
79 | "metadata": {
80 | "kernelspec": {
81 | "display_name": "Julia (4 threads) 1.7.2",
82 | "language": "julia",
83 | "name": "julia-(4-threads)-1.7"
84 | },
85 | "language_info": {
86 | "file_extension": ".jl",
87 | "mimetype": "application/julia",
88 | "name": "julia",
89 | "version": "1.7.2"
90 | }
91 | },
92 | "nbformat": 4,
93 | "nbformat_minor": 5
94 | }
95 |
--------------------------------------------------------------------------------
/NLP/CondaPkg.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | ipython = ""
3 | nltk = ""
4 | spacy = ""
5 | cupy = ""
6 |
--------------------------------------------------------------------------------
/NLP/NLP-TextAnalysis.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "dbddcdcd-d2d5-4d44-82c6-066b42292243",
6 | "metadata": {},
7 | "source": [
8 | "# NLP with Julia"
9 | ]
10 | },
11 | {
12 | "cell_type": "code",
13 | "execution_count": 2,
14 | "id": "5ec65ffe-51a3-44b4-bdbc-606440d07194",
15 | "metadata": {},
16 | "outputs": [
17 | {
18 | "name": "stderr",
19 | "output_type": "stream",
20 | "text": [
21 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Main/EMAp/Julia_Tutorials/NLP`\n",
22 | "\u001b[32m\u001b[1m CondaPkg \u001b[22m\u001b[39m\u001b[0mFound dependencies: /home/davibarreira/Main/EMAp/Julia_Tutorials/NLP/CondaPkg.toml\n",
23 | "\u001b[32m\u001b[1m CondaPkg \u001b[22m\u001b[39m\u001b[0mFound dependencies: /home/davibarreira/.julia/packages/PythonCall/XUf6D/CondaPkg.toml\n",
24 | "\u001b[32m\u001b[1m CondaPkg \u001b[22m\u001b[39m\u001b[0mDependencies already up to date\n"
25 | ]
26 | }
27 | ],
28 | "source": [
29 | "using Pkg\n",
30 | "Pkg.activate(\".\")\n",
31 | "\n",
32 | "using DataFrames\n",
33 | "using VegaLite\n",
34 | "using TextAnalysis\n",
35 | "using PythonCall"
36 | ]
37 | },
38 | {
39 | "cell_type": "markdown",
40 | "id": "4f4a6e47-1bd4-47fd-993a-288c9c55330d",
41 | "metadata": {},
42 | "source": [
43 | "## 1. Importing a Corpus\n",
44 | "\n",
45 | "Let's start by importing some sample texts. For that, let's use python's nltk package."
46 | ]
47 | },
48 | {
49 | "cell_type": "code",
50 | "execution_count": 3,
51 | "id": "aa9ff3dc-193b-45f5-a282-cfb62ccd23b5",
52 | "metadata": {},
53 | "outputs": [
54 | {
55 | "data": {
56 | "text/plain": [
57 | "\u001b[0m\u001b[1mPython module: \u001b[22m"
58 | ]
59 | },
60 | "execution_count": 3,
61 | "metadata": {},
62 | "output_type": "execute_result"
63 | }
64 | ],
65 | "source": [
66 | "nltk = pyimport(\"nltk\")"
67 | ]
68 | },
69 | {
70 | "cell_type": "code",
71 | "execution_count": null,
72 | "id": "80d6e372-303b-4f33-ab5f-1d76a28eb7e3",
73 | "metadata": {},
74 | "outputs": [],
75 | "source": []
76 | }
77 | ],
78 | "metadata": {
79 | "kernelspec": {
80 | "display_name": "Julia (4 threads) 1.7.2",
81 | "language": "julia",
82 | "name": "julia-(4-threads)-1.7"
83 | },
84 | "language_info": {
85 | "file_extension": ".jl",
86 | "mimetype": "application/julia",
87 | "name": "julia",
88 | "version": "1.7.2"
89 | }
90 | },
91 | "nbformat": 4,
92 | "nbformat_minor": 5
93 | }
94 |
--------------------------------------------------------------------------------
/NLP/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
3 | CorpusLoaders = "214a0ac2-f95b-54f7-a80b-442ed9c2c9e8"
4 | Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
5 | Languages = "8ef0a80b-9436-5d2c-a485-80b904378c43"
6 | ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
7 | PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
8 | TextAnalysis = "a2db99b7-8b79-58f8-94bf-bbc811eef33d"
9 | TextModels = "77b9cbda-2a23-51df-82a3-24144d1cd378"
10 | Transformers = "21ca0261-441d-5938-ace7-c90938fde4d4"
11 | VegaLite = "112f6efa-9a02-5b7d-90c0-432ed331239a"
12 |
--------------------------------------------------------------------------------
/OptimalTransport/2DOptimalTransport.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 2,
6 | "id": "b70ee2eb-642b-4dae-b0fd-fea2880753b9",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Documents/GitHub/Julia_Tutorials/OptimalTransport`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg\n",
19 | "\n",
20 | "Pkg.activate(\".\")\n",
21 | "# Pkg.add(\"OptimalTransport\")\n",
22 | "# Pkg.add(\"Distances\")\n",
23 | "# Pkg.add(\"Tulip\")\n",
24 | "using OptimalTransport\n",
25 | "using Distances\n",
26 | "using Tulip\n",
27 | "\n",
28 | "using LinearAlgebra\n",
29 | "using Random"
30 | ]
31 | },
32 | {
33 | "cell_type": "code",
34 | "execution_count": 3,
35 | "id": "cdb36b88-fdb1-47c3-a902-0506abe31648",
36 | "metadata": {},
37 | "outputs": [],
38 | "source": [
39 | "Random.seed!(1234)\n",
40 | "M = 5\n",
41 | "μ = normalize!(rand(M),1)\n",
42 | "μsupport = rand(M,2)\n",
43 | "\n",
44 | "N = 2\n",
45 | "ν = normalize!(rand(N),1)\n",
46 | "νsupport = rand(N,2);\n",
47 | "\n",
48 | "C = pairwise(sqeuclidean, μsupport', νsupport'; dims=2);\n",
49 | "C2 = pairwise(euclidean, μsupport', νsupport'; dims=2);"
50 | ]
51 | },
52 | {
53 | "cell_type": "code",
54 | "execution_count": 9,
55 | "id": "eb22053f-ca46-4a1a-bd52-fe1485898c32",
56 | "metadata": {},
57 | "outputs": [
58 | {
59 | "data": {
60 | "text/plain": [
61 | "5×2 Matrix{Float64}:\n",
62 | " 0.639562 0.951162\n",
63 | " 0.839622 0.0739957\n",
64 | " 0.967143 0.110817\n",
65 | " 0.205168 0.0727161\n",
66 | " 0.527184 0.701116"
67 | ]
68 | },
69 | "execution_count": 9,
70 | "metadata": {},
71 | "output_type": "execute_result"
72 | }
73 | ],
74 | "source": [
75 | "μsupport"
76 | ]
77 | },
78 | {
79 | "cell_type": "code",
80 | "execution_count": 5,
81 | "id": "ff118ae1-01c7-4890-a01f-1fdc86436c70",
82 | "metadata": {},
83 | "outputs": [],
84 | "source": [
85 | "γ = emd(μ, ν, C, Tulip.Optimizer());"
86 | ]
87 | },
88 | {
89 | "cell_type": "code",
90 | "execution_count": 6,
91 | "id": "cc563832-d26c-4987-80a2-d2ba6f425e01",
92 | "metadata": {},
93 | "outputs": [],
94 | "source": [
95 | "γ2 = emd(μ, ν, C2, Tulip.Optimizer());"
96 | ]
97 | },
98 | {
99 | "cell_type": "code",
100 | "execution_count": 7,
101 | "id": "5169a11e-4a7c-4df5-b61c-cf5b4e7683d9",
102 | "metadata": {},
103 | "outputs": [
104 | {
105 | "data": {
106 | "text/plain": [
107 | "5×2 Matrix{Float64}:\n",
108 | " -3.10273e-12 0.139248\n",
109 | " 2.12961e-11 0.23454\n",
110 | " 7.08917e-12 0.0933743\n",
111 | " 0.101216 0.280781\n",
112 | " 1.19145e-11 0.15084"
113 | ]
114 | },
115 | "execution_count": 7,
116 | "metadata": {},
117 | "output_type": "execute_result"
118 | }
119 | ],
120 | "source": [
121 | "γ"
122 | ]
123 | },
124 | {
125 | "cell_type": "code",
126 | "execution_count": 8,
127 | "id": "5b2c1673-6615-4564-8dc2-c80d600293c3",
128 | "metadata": {},
129 | "outputs": [
130 | {
131 | "data": {
132 | "text/plain": [
133 | "5×2 Matrix{Float64}:\n",
134 | " -1.78435e-12 0.139248\n",
135 | " 1.99562e-11 0.23454\n",
136 | " 4.37437e-12 0.0933743\n",
137 | " 0.101216 0.280781\n",
138 | " 6.77589e-12 0.15084"
139 | ]
140 | },
141 | "execution_count": 8,
142 | "metadata": {},
143 | "output_type": "execute_result"
144 | }
145 | ],
146 | "source": [
147 | "γ2"
148 | ]
149 | },
150 | {
151 | "cell_type": "code",
152 | "execution_count": null,
153 | "id": "16077d44-695e-4f85-a8e5-fe0b718b7b0f",
154 | "metadata": {},
155 | "outputs": [],
156 | "source": []
157 | }
158 | ],
159 | "metadata": {
160 | "kernelspec": {
161 | "display_name": "Julia 1.10.3",
162 | "language": "julia",
163 | "name": "julia-1.10"
164 | },
165 | "language_info": {
166 | "file_extension": ".jl",
167 | "mimetype": "application/julia",
168 | "name": "julia",
169 | "version": "1.10.3"
170 | }
171 | },
172 | "nbformat": 4,
173 | "nbformat_minor": 5
174 | }
175 |
--------------------------------------------------------------------------------
/OptimalTransport/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
3 | Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
4 | OptimalTransport = "7e02d93a-ae51-4f58-b602-d97af76e3b33"
5 | Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
6 | StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
7 | Tulip = "6dd1b50a-3aae-11e9-10b5-ef983d2400fa"
8 |
--------------------------------------------------------------------------------
/ParallelComputing/Asynchronous.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "a23fae0d-b2e9-471a-8801-eb2415d4075e",
6 | "metadata": {},
7 | "source": [
8 | "# Asyncrhonous Programming with Julia\n",
9 | "\n",
10 | "Usually, one thinks of running a code as\n",
11 | "running each line and code in succetion. Although this is the most common scenario,\n",
12 | "there are many situations where one wishes to write code and run commands depending\n",
13 | "on what task finishes first. This is what asynchronous programming is about.\n",
14 | "\n",
15 | "Consider for example, the case where you have to download large data files and do some\n",
16 | "calculations. Now, it might be the case that the calculation performed in each\n",
17 | "file is indepedent of the others. Thus, one might wish to start to run the calculations\n",
18 | "once a file is downloaded, instead of waiting for all of them to finish downloading.\n",
19 | "\n",
20 | "This can be thought as a type of parallel programming. Yet, it's a different idea\n",
21 | "compared to Multi-Threading. In this case, you are not actually running code in parallel,\n",
22 | "but, instead, you are better cordinating which line of code to run depending on\n",
23 | "some information outside of the program (e.g. the download of a file, the input of a user,\n",
24 | "the response of a webpage, and so on)."
25 | ]
26 | },
27 | {
28 | "cell_type": "markdown",
29 | "id": "924a676e-50b0-4dc6-803f-7f9d361a3a0f",
30 | "metadata": {},
31 | "source": [
32 | "### 1. Tasks\n",
33 | "\n",
34 | "The first thing we'll talk about are tasks. You can think of a task as a line of code\n",
35 | "to be ran, similar to a function. In Julia, the macro `@task` is a way of creating a task.\n",
36 | "The difference between running a task and running a function is that the function needs to finish\n",
37 | "all of it's commands before the code can move on. While the taks allow one to \"stop what you are doing\", and\n",
38 | "move to another taks.\n",
39 | "Look the example below:"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": 73,
45 | "id": "61211ec4-6e41-4675-93d4-03e1927491ec",
46 | "metadata": {},
47 | "outputs": [
48 | {
49 | "data": {
50 | "text/plain": [
51 | "f (generic function with 1 method)"
52 | ]
53 | },
54 | "execution_count": 73,
55 | "metadata": {},
56 | "output_type": "execute_result"
57 | }
58 | ],
59 | "source": [
60 | "t = @task begin \n",
61 | " println(\"starttask\")\n",
62 | " sleep(5);\n",
63 | " println(\"endtask\");\n",
64 | "end\n",
65 | "\n",
66 | "function f()\n",
67 | " println(\"startfunction\")\n",
68 | " sleep(5);\n",
69 | " println(\"endfunction\")\n",
70 | "end"
71 | ]
72 | },
73 | {
74 | "cell_type": "markdown",
75 | "id": "9a7abf4c-180a-4106-86a7-8ffd565e7ae0",
76 | "metadata": {},
77 | "source": [
78 | "So how do we tell the computer to run the task? This can be done with the\n",
79 | "`schedule()` function. This function schedules the task to be ran in the queu\n",
80 | "of tasks. If there is nothing in the queue, the command runs immeadiatly."
81 | ]
82 | },
83 | {
84 | "cell_type": "code",
85 | "execution_count": 74,
86 | "id": "18cb5e4e-b7f2-485b-8e47-e5735b1a0829",
87 | "metadata": {},
88 | "outputs": [
89 | {
90 | "name": "stdout",
91 | "output_type": "stream",
92 | "text": [
93 | "starttask\n",
94 | "startfunction\n",
95 | "endtask\n",
96 | "endfunction\n"
97 | ]
98 | }
99 | ],
100 | "source": [
101 | "schedule(t)\n",
102 | "sleep(1)\n",
103 | "f()"
104 | ]
105 | },
106 | {
107 | "cell_type": "markdown",
108 | "id": "77faa786-0cb5-46d1-8700-c043bccc7b04",
109 | "metadata": {},
110 | "source": [
111 | "Here, we scheduled our task, which starts to run. Before it finishes, we run the function.\n",
112 | "We can see this by the intertwined outputs (e.g. `starttask` followed by `startfunction`).\n",
113 | "\n",
114 | "This next example shows the opposite behavior."
115 | ]
116 | },
117 | {
118 | "cell_type": "code",
119 | "execution_count": 78,
120 | "id": "eac49c97-0cea-4d6f-8fb7-8b54333ab391",
121 | "metadata": {},
122 | "outputs": [
123 | {
124 | "name": "stdout",
125 | "output_type": "stream",
126 | "text": [
127 | "t1\n",
128 | "startfunction\n",
129 | "endfunction\n",
130 | "runtask\n"
131 | ]
132 | },
133 | {
134 | "data": {
135 | "text/plain": [
136 | "Task (done) @0x00007f2d6f716850"
137 | ]
138 | },
139 | "execution_count": 78,
140 | "metadata": {},
141 | "output_type": "execute_result"
142 | }
143 | ],
144 | "source": [
145 | "t = @task begin \n",
146 | " println(\"runtask\")\n",
147 | "end\n",
148 | "f()\n",
149 | "sleep(1)\n",
150 | "schedule(t)"
151 | ]
152 | },
153 | {
154 | "cell_type": "code",
155 | "execution_count": null,
156 | "id": "e853295c-0fe0-4129-9bca-4e1bfd3bc9a5",
157 | "metadata": {},
158 | "outputs": [],
159 | "source": []
160 | }
161 | ],
162 | "metadata": {
163 | "kernelspec": {
164 | "display_name": "Julia (4 threads) 1.7.2",
165 | "language": "julia",
166 | "name": "julia-(4-threads)-1.7"
167 | },
168 | "language_info": {
169 | "file_extension": ".jl",
170 | "mimetype": "application/julia",
171 | "name": "julia",
172 | "version": "1.7.2"
173 | }
174 | },
175 | "nbformat": 4,
176 | "nbformat_minor": 5
177 | }
178 |
--------------------------------------------------------------------------------
/ParallelComputing/Multi-Threading.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "b98ef915-6008-4559-931f-d86732b3c266",
6 | "metadata": {},
7 | "source": [
8 | "# Multi-Threading em Julia\n",
9 | "\n",
10 | "Para computação em paralelo, podemos dizer de forma simplificada que existem duas maneiras de fazer. Um é\n",
11 | "utilizando threads, onde rodamos o código em \"cores\" separados. A outra forma, que está ficando mais popular\n",
12 | "hoje em dia, é utilizando GPUs.\n",
13 | "\n",
14 | "Nesse notebook o foco é em threads.\n",
15 | "\n",
16 | "A primeira coisa a fazer é iniciar um REPL com `julia -t auto`. Isso irá fazer com que se detecte quantos\n",
17 | "cores tem na sua máquina, e inicia o REPL utilizando todas as cores possíveis.\n",
18 | "Caso queira rodar em um notebook jupyter, deve-se instalar um kernel com os threads habilitados.\n",
19 | "\n",
20 | "Para isso, entre num REPL de Julia e rode:\n",
21 | "```\n",
22 | "using IJulia\n",
23 | "installkernel(\"Julia (4 threads)\", env=Dict(\"JULIA_NUM_THREADS\"=>\"4\"))\n",
24 | "```\n",
25 | "\n",
26 | "Agora basta abrir o notebook com esse kernel.\n",
27 | "Uma vez que tiver seu notebook rodando, use\n",
28 | "o comando `Threads.nthreads()` para ver quantos threads estão sendo utilizados."
29 | ]
30 | },
31 | {
32 | "cell_type": "code",
33 | "execution_count": 6,
34 | "id": "4094e47b-0b86-4a5e-be45-929fb1fbd178",
35 | "metadata": {},
36 | "outputs": [],
37 | "source": [
38 | "using Base.Threads"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": 7,
44 | "id": "98238dca-50e9-436c-9b58-de37e0433de6",
45 | "metadata": {},
46 | "outputs": [
47 | {
48 | "data": {
49 | "text/plain": [
50 | "4"
51 | ]
52 | },
53 | "execution_count": 7,
54 | "metadata": {},
55 | "output_type": "execute_result"
56 | }
57 | ],
58 | "source": [
59 | "nthreads()"
60 | ]
61 | },
62 | {
63 | "cell_type": "markdown",
64 | "id": "4b16066d-9995-4311-8439-6cd8d4392fc4",
65 | "metadata": {},
66 | "source": [
67 | "No meu notebook tenho 4 threads habilitados. Assim, posso rodar até 4 operações em paralelo. \n",
68 | "\n",
69 | "Abaixo temos a forma mais simples de rodar em paralelo."
70 | ]
71 | },
72 | {
73 | "cell_type": "code",
74 | "execution_count": 14,
75 | "id": "9a246d7d-5d79-4f09-bdee-7a001292b909",
76 | "metadata": {},
77 | "outputs": [
78 | {
79 | "name": "stdout",
80 | "output_type": "stream",
81 | "text": [
82 | "1 -> 1\n",
83 | "9 -> 4\n",
84 | "10 -> 4\n",
85 | "2 -> 1\n",
86 | "4 -> 2\n",
87 | "5 -> 2\n",
88 | "6 -> 2\n",
89 | "3 -> 1\n",
90 | "7 -> 3\n",
91 | "8 -> 3\n"
92 | ]
93 | }
94 | ],
95 | "source": [
96 | "@threads for i in 1:10\n",
97 | " println(\"$i -> $(threadid())\")\n",
98 | "end"
99 | ]
100 | },
101 | {
102 | "cell_type": "markdown",
103 | "id": "74e40b64-94c7-4f24-aab1-41081c24cb0b",
104 | "metadata": {},
105 | "source": [
106 | "O exemplo acima pode ser muito útil. Mas note que não temos controle \n",
107 | "sobre a ordem do processo! Como assim? Olhe o exemplo abaixo:"
108 | ]
109 | },
110 | {
111 | "cell_type": "code",
112 | "execution_count": 18,
113 | "id": "3ce7b718-8434-4798-953a-7f419c1b069e",
114 | "metadata": {},
115 | "outputs": [
116 | {
117 | "name": "stdout",
118 | "output_type": "stream",
119 | "text": [
120 | "l = Any[1, 2, 3, 9, 10, 4, 5, 6, 7, 8]\n"
121 | ]
122 | },
123 | {
124 | "data": {
125 | "text/plain": [
126 | "10-element Vector{Any}:\n",
127 | " 1\n",
128 | " 2\n",
129 | " 3\n",
130 | " 9\n",
131 | " 10\n",
132 | " 4\n",
133 | " 5\n",
134 | " 6\n",
135 | " 7\n",
136 | " 8"
137 | ]
138 | },
139 | "execution_count": 18,
140 | "metadata": {},
141 | "output_type": "execute_result"
142 | }
143 | ],
144 | "source": [
145 | "l = []\n",
146 | "@threads for i in 1:10\n",
147 | " push!(l,i)\n",
148 | "end\n",
149 | "@show l"
150 | ]
151 | },
152 | {
153 | "cell_type": "markdown",
154 | "id": "da1b1dd3-8cb7-49bd-98ec-fff130fa4d96",
155 | "metadata": {},
156 | "source": [
157 | "Os elementos são inseridos na lista sem uma ordem específica."
158 | ]
159 | },
160 | {
161 | "cell_type": "code",
162 | "execution_count": null,
163 | "id": "fe6a62c1-ec1a-4cf3-b606-59009335fb51",
164 | "metadata": {},
165 | "outputs": [],
166 | "source": []
167 | }
168 | ],
169 | "metadata": {
170 | "kernelspec": {
171 | "display_name": "Julia (4 threads) 1.7.1",
172 | "language": "julia",
173 | "name": "julia-(4-threads)-1.7"
174 | },
175 | "language_info": {
176 | "file_extension": ".jl",
177 | "mimetype": "application/julia",
178 | "name": "julia",
179 | "version": "1.7.1"
180 | }
181 | },
182 | "nbformat": 4,
183 | "nbformat_minor": 5
184 | }
185 |
--------------------------------------------------------------------------------
/Parsing XML/Manifest.toml:
--------------------------------------------------------------------------------
1 | # This file is machine-generated - editing it directly is not advised
2 |
3 | julia_version = "1.10.1"
4 | manifest_format = "2.0"
5 | project_hash = "cf8d6a6e66ffb3f427671a7fe2b948f89bd6f936"
6 |
7 | [[deps.Artifacts]]
8 | uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
9 |
10 | [[deps.Dates]]
11 | deps = ["Printf"]
12 | uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"
13 |
14 | [[deps.EzXML]]
15 | deps = ["Printf", "XML2_jll"]
16 | git-tree-sha1 = "380053d61bb9064d6aa4a9777413b40429c79901"
17 | uuid = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
18 | version = "1.2.0"
19 |
20 | [[deps.JLLWrappers]]
21 | deps = ["Artifacts", "Preferences"]
22 | git-tree-sha1 = "7e5d6779a1e09a36db2a7b6cff50942a0a7d0fca"
23 | uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
24 | version = "1.5.0"
25 |
26 | [[deps.Libdl]]
27 | uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
28 |
29 | [[deps.Libiconv_jll]]
30 | deps = ["Artifacts", "JLLWrappers", "Libdl"]
31 | git-tree-sha1 = "f9557a255370125b405568f9767d6d195822a175"
32 | uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531"
33 | version = "1.17.0+0"
34 |
35 | [[deps.Preferences]]
36 | deps = ["TOML"]
37 | git-tree-sha1 = "00805cd429dcb4870060ff49ef443486c262e38e"
38 | uuid = "21216c6a-2e73-6563-6e65-726566657250"
39 | version = "1.4.1"
40 |
41 | [[deps.Printf]]
42 | deps = ["Unicode"]
43 | uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7"
44 |
45 | [[deps.TOML]]
46 | deps = ["Dates"]
47 | uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
48 | version = "1.0.3"
49 |
50 | [[deps.Unicode]]
51 | uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
52 |
53 | [[deps.XML2_jll]]
54 | deps = ["Artifacts", "JLLWrappers", "Libdl", "Libiconv_jll", "Zlib_jll"]
55 | git-tree-sha1 = "801cbe47eae69adc50f36c3caec4758d2650741b"
56 | uuid = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a"
57 | version = "2.12.2+0"
58 |
59 | [[deps.Zlib_jll]]
60 | deps = ["Libdl"]
61 | uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
62 | version = "1.2.13+1"
63 |
--------------------------------------------------------------------------------
/Parsing XML/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
3 |
--------------------------------------------------------------------------------
/Parsing XML/xml.jl:
--------------------------------------------------------------------------------
1 | using Pkg
2 | Pkg.activate(".")
3 | Pkg.add("EzXML")
4 | using EzXML
5 |
--------------------------------------------------------------------------------
/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | BasicBSpline = "4c5d9882-2acf-4ea4-9e48-968fd4518195"
3 | Dictionaries = "85a47980-9c8c-11e8-2b9f-f7ca1fa99fb4"
4 | IntervalSets = "8197267c-284f-5f27-9208-e0e47529a953"
5 | Meshes = "eacbb407-ea5a-433e-ab97-5258b1ca43fa"
6 | PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
7 | Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
8 | StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
9 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Julia Tutorials
2 |
3 | ### A repository for interesting Tutorials in Julia.
4 |
5 | Since Julia is still a "new" language, there is not as much material
6 | out there, with easy to follow tutorials on how to do many things. Hence,
7 | this is a personal repository to collect Tutorials in Julia,
8 |
9 | This repository is related to the publication [Coffee in a Klein Bottle](https://medium.com/coffee-in-a-klein-bottle).
10 |
11 | Below, the List of Contents of tutorial related to Coffee in a Klein Bottle:
12 |
13 | * [Speeding Up Julia Precompilation](https://github.com/davibarreira/Julia_Tutorials/tree/main/Speeding_up_Julia_Precompilation) - How to use PackageCompiler.jl
14 | to create precompiled versions of Julia with your favorite packages, and speed up the process of starting a new kernel;
15 | * [Deep Learning with Julia](https://github.com/davibarreira/Julia_Tutorials) - A brief tutorial on training a Neural Network with Flux.jl.The notebook [here](https://github.com/davibarreira/Julia_Tutorials/blob/main/MachineLearning/Flux_Tutorial1.ipynb) corresponds to the code shown in the article;
16 | * [Analyzing Graphs with Julia](https://medium.com/coffee-in-a-klein-bottle/analyzing-graphs-with-julia-38e26d1d2f62) - A brief tutorial on how to use Julia to analyze graphs using the JuliaGraphs packages. The notebook [here](https://github.com/davibarreira/Julia_Tutorials/blob/main/Graphs/Graphs_Tutorial.ipynb) corresponds to the code shown in the article.
17 |
18 | ## Useful External Links
19 | * [Autoencoders tutorial with Flux](https://wildart.github.io/)
20 |
--------------------------------------------------------------------------------
/Speeding_up_Julia_Precompilation/Precompile_DataPackages.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Creating PreCompiled Julia File\n",
8 | "\n",
9 | "This notebook shows the commands to create a precompiled Julia file that can\n",
10 | "be used to speed-up the initialization of a new kernel. The gist is to use the PackageCompile.jl\n",
11 | "which creates a source file with the disered packages already precompiled. Then, install\n",
12 | "the new kernel on Jupyter, and you can significantly increase the speed when starting a new kernel.\n",
13 | "\n",
14 | "The only downside is that such sourcefiles can be quite large (e.g 500 mb)."
15 | ]
16 | },
17 | {
18 | "cell_type": "code",
19 | "execution_count": 3,
20 | "metadata": {},
21 | "outputs": [],
22 | "source": [
23 | "using Pkg"
24 | ]
25 | },
26 | {
27 | "cell_type": "code",
28 | "execution_count": 6,
29 | "metadata": {},
30 | "outputs": [
31 | {
32 | "name": "stderr",
33 | "output_type": "stream",
34 | "text": [
35 | "┌ Info: Precompiling StatsPlots [f3b207a7-027a-5e70-b257-86293d7955fd]\n",
36 | "└ @ Base loading.jl:1278\n"
37 | ]
38 | }
39 | ],
40 | "source": [
41 | "using StatsPlots"
42 | ]
43 | },
44 | {
45 | "cell_type": "code",
46 | "execution_count": 7,
47 | "metadata": {},
48 | "outputs": [
49 | {
50 | "name": "stderr",
51 | "output_type": "stream",
52 | "text": [
53 | "┌ Info: Precompiling PackageCompiler [9b87118b-4619-50d2-8e1e-99f35a4d4d9d]\n",
54 | "└ @ Base loading.jl:1278\n"
55 | ]
56 | }
57 | ],
58 | "source": [
59 | "# using Flux\n",
60 | "using PackageCompiler"
61 | ]
62 | },
63 | {
64 | "cell_type": "code",
65 | "execution_count": 13,
66 | "metadata": {},
67 | "outputs": [
68 | {
69 | "name": "stderr",
70 | "output_type": "stream",
71 | "text": [
72 | "┌ Info: Precompiling CSV [336ed68f-0bac-5ca0-87d4-7b16caf5d00b]\n",
73 | "└ @ Base loading.jl:1278\n",
74 | "┌ Info: Precompiling Cairo [159f3aea-2a34-519c-b102-8c37f9878175]\n",
75 | "└ @ Base loading.jl:1278\n"
76 | ]
77 | }
78 | ],
79 | "source": [
80 | "using Plots, Flux, Gadfly, PackageCompiler\n",
81 | "using VegaLite\n",
82 | "using LaTeXStrings, Distributions\n",
83 | "using Statistics\n",
84 | "using MLDatasets\n",
85 | "using DataFrames\n",
86 | "using KernelDensity\n",
87 | "using CSV\n",
88 | "using Cairo"
89 | ]
90 | },
91 | {
92 | "cell_type": "code",
93 | "execution_count": 14,
94 | "metadata": {},
95 | "outputs": [
96 | {
97 | "name": "stderr",
98 | "output_type": "stream",
99 | "text": [
100 | "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n",
101 | "\u001b[32m\u001b[1mNo Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.5/Project.toml`\n",
102 | "\u001b[32m\u001b[1mNo Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.5/Manifest.toml`\n",
103 | "\u001b[32m\u001b[1m Resolving\u001b[22m\u001b[39m package versions...\n",
104 | "\u001b[32m\u001b[1mNo Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.5/Project.toml`\n",
105 | "\u001b[32m\u001b[1mNo Changes\u001b[22m\u001b[39m to `~/.julia/environments/v1.5/Manifest.toml`\n"
106 | ]
107 | }
108 | ],
109 | "source": [
110 | "Pkg.add(\"CSV\")\n",
111 | "Pkg.add(\"Cairo\")"
112 | ]
113 | },
114 | {
115 | "cell_type": "code",
116 | "execution_count": 19,
117 | "metadata": {},
118 | "outputs": [
119 | {
120 | "name": "stderr",
121 | "output_type": "stream",
122 | "text": [
123 | "┌ Info: PackageCompiler: creating system image object file, this might take a while...\n",
124 | "└ @ PackageCompiler /home/davibarreira/.julia/packages/PackageCompiler/3BsME/src/PackageCompiler.jl:301\n"
125 | ]
126 | }
127 | ],
128 | "source": [
129 | "# create_sysimage([:Flux,:Plots,:LaTeXStrings],sysimage_path=\"/home/davi/JuliaSysImageEnv/sys_flux_plots.so\")\n",
130 | "create_sysimage([:Flux,:Gadfly,:MLDatasets,:LaTeXStrings,:DataFrames,:StatsPlots,:Plots,\n",
131 | " :CSV,:Cairo],sysimage_path=\"/home/davibarreira/JuliaSysImageEnv/sys_ml.so\")"
132 | ]
133 | },
134 | {
135 | "cell_type": "code",
136 | "execution_count": 20,
137 | "metadata": {},
138 | "outputs": [
139 | {
140 | "name": "stderr",
141 | "output_type": "stream",
142 | "text": [
143 | "┌ Info: Installing JuliaML kernelspec in /home/davibarreira/.local/share/jupyter/kernels/juliaml-1.5\n",
144 | "└ @ IJulia /home/davibarreira/.julia/packages/IJulia/IDNmS/deps/kspec.jl:94\n"
145 | ]
146 | },
147 | {
148 | "data": {
149 | "text/plain": [
150 | "\"/home/davibarreira/.local/share/jupyter/kernels/juliaml-1.5\""
151 | ]
152 | },
153 | "execution_count": 20,
154 | "metadata": {},
155 | "output_type": "execute_result"
156 | }
157 | ],
158 | "source": [
159 | "using IJulia\n",
160 | "installkernel(\"JuliaML\", \"--sysimage=/home/davibarreira/JuliaSysImageEnv/sys_ml.so\")"
161 | ]
162 | },
163 | {
164 | "cell_type": "code",
165 | "execution_count": null,
166 | "metadata": {},
167 | "outputs": [],
168 | "source": [
169 | " "
170 | ]
171 | }
172 | ],
173 | "metadata": {
174 | "kernelspec": {
175 | "display_name": "Julia 1.5.3",
176 | "language": "julia",
177 | "name": "julia-1.5"
178 | },
179 | "language_info": {
180 | "file_extension": ".jl",
181 | "mimetype": "application/julia",
182 | "name": "julia",
183 | "version": "1.5.3"
184 | }
185 | },
186 | "nbformat": 4,
187 | "nbformat_minor": 4
188 | }
189 |
--------------------------------------------------------------------------------
/Speeding_up_Julia_Precompilation/Precompile_Flux.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Creating PreCompiled Julia File\n",
8 | "\n",
9 | "This notebook shows the commands to create a precompiled Julia file that can\n",
10 | "be used to speed-up the initialization of a new kernel. The gist is to use the PackageCompile.jl\n",
11 | "which creates a source file with the disered packages already precompiled. Then, install\n",
12 | "the new kernel on Jupyter, and you can significantly increase the speed when starting a new kernel.\n",
13 | "\n",
14 | "The only downside is that such sourcefiles can be quite large (e.g 500 mb)."
15 | ]
16 | },
17 | {
18 | "cell_type": "code",
19 | "execution_count": 12,
20 | "metadata": {},
21 | "outputs": [],
22 | "source": [
23 | "using Pkg\n",
24 | "using Flux\n",
25 | "using Plots\n",
26 | "Pkg.add(\"PackageCompiler\")\n",
27 | "using PackageCompiler"
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": 16,
33 | "metadata": {},
34 | "outputs": [
35 | {
36 | "name": "stderr",
37 | "output_type": "stream",
38 | "text": [
39 | "┌ Info: PackageCompiler: creating system image object file, this might take a while...\n",
40 | "└ @ PackageCompiler /home/davi/.julia/packages/PackageCompiler/vsMJE/src/PackageCompiler.jl:287\n"
41 | ]
42 | }
43 | ],
44 | "source": [
45 | "create_sysimage([:Flux,:Plots],sysimage_path=\"sys_flux_plots.so\")"
46 | ]
47 | },
48 | {
49 | "cell_type": "code",
50 | "execution_count": 17,
51 | "metadata": {},
52 | "outputs": [],
53 | "source": [
54 | "using IJulia\n",
55 | "installkernel(\"JuliaFluxPlots\", \"--sysimage=/home/davi/JuliaSysImageEnv/sys_flux_plots.so\")"
56 | ]
57 | }
58 | ],
59 | "metadata": {
60 | "kernelspec": {
61 | "display_name": "Julia-1.6 1.6.3",
62 | "language": "julia",
63 | "name": "julia-1.6-1.6"
64 | },
65 | "language_info": {
66 | "file_extension": ".jl",
67 | "mimetype": "application/julia",
68 | "name": "julia",
69 | "version": "1.6.3"
70 | }
71 | },
72 | "nbformat": 4,
73 | "nbformat_minor": 4
74 | }
75 |
--------------------------------------------------------------------------------
/TDA/AbstactAlgebra.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "id": "4ca4d6ea-e9f0-4ae9-b9e2-790184db97a3",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Documents/GitHub/PhDThesis/implementations/TDA`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg\n",
19 | "Pkg.activate(\".\")\n",
20 | "using AbstractAlgebra"
21 | ]
22 | },
23 | {
24 | "cell_type": "code",
25 | "execution_count": 4,
26 | "id": "0fd0b434-9f8e-4e68-9b4d-ce6be8c9cafa",
27 | "metadata": {},
28 | "outputs": [
29 | {
30 | "data": {
31 | "text/plain": [
32 | "(0, 1, 0, 1)"
33 | ]
34 | },
35 | "execution_count": 4,
36 | "metadata": {},
37 | "output_type": "execute_result"
38 | }
39 | ],
40 | "source": [
41 | "ℤ_2ℤ, = residue_ring(ZZ, 2)\n",
42 | "\n",
43 | "R = ℤ_2ℤ\n",
44 | "⊕(x,y) = R(x) + R(y)\n",
45 | "⊙(x,y) = R(x) * R(y)\n",
46 | "\n",
47 | "R(0),R(1),R(2),R(3)"
48 | ]
49 | },
50 | {
51 | "cell_type": "code",
52 | "execution_count": 11,
53 | "id": "7bf0b8b2-213d-4dfe-9f43-08de95db937e",
54 | "metadata": {},
55 | "outputs": [
56 | {
57 | "name": "stdout",
58 | "output_type": "stream",
59 | "text": [
60 | "0 ⊕ 0 = 0\n",
61 | "0 ⊕ 1 = 1\n",
62 | "1 ⊕ 0 = 1\n",
63 | "1 ⊕ 1 = 0\n",
64 | "---------\n",
65 | "0 ⊙ 0 = 0\n",
66 | "0 ⊙ 1 = 0\n",
67 | "1 ⊙ 0 = 0\n",
68 | "1 ⊙ 1 = 1\n"
69 | ]
70 | }
71 | ],
72 | "source": [
73 | "@show 0 ⊕ 0\n",
74 | "@show 0 ⊕ 1\n",
75 | "@show 1 ⊕ 0\n",
76 | "@show 1 ⊕ 1\n",
77 | "\n",
78 | "println(\"---------\")\n",
79 | "\n",
80 | "@show 0 ⊙ 0\n",
81 | "@show 0 ⊙ 1\n",
82 | "@show 1 ⊙ 0\n",
83 | "@show 1 ⊙ 1\n",
84 | ";"
85 | ]
86 | },
87 | {
88 | "cell_type": "code",
89 | "execution_count": null,
90 | "id": "708473e9-7a56-4074-a65a-40edbd76acfd",
91 | "metadata": {},
92 | "outputs": [],
93 | "source": []
94 | }
95 | ],
96 | "metadata": {
97 | "kernelspec": {
98 | "display_name": "Julia 1.10.5",
99 | "language": "julia",
100 | "name": "julia-1.10"
101 | },
102 | "language_info": {
103 | "file_extension": ".jl",
104 | "mimetype": "application/julia",
105 | "name": "julia",
106 | "version": "1.10.5"
107 | }
108 | },
109 | "nbformat": 4,
110 | "nbformat_minor": 5
111 | }
112 |
--------------------------------------------------------------------------------
/TDA/CombinatorialSpaces.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "id": "dc229254-c563-411b-9177-4b0caf3ff4d3",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Documents/GitHub/PhDThesis/implementations/TDA`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg\n",
19 | "Pkg.activate(\".\")\n",
20 | "using CGPlots"
21 | ]
22 | },
23 | {
24 | "cell_type": "code",
25 | "execution_count": 3,
26 | "id": "3a48d7ac-9575-40c3-8fc8-1f33cca1d80b",
27 | "metadata": {},
28 | "outputs": [
29 | {
30 | "name": "stderr",
31 | "output_type": "stream",
32 | "text": [
33 | "\u001b[36m\u001b[1m[ \u001b[22m\u001b[39m\u001b[36m\u001b[1mInfo: \u001b[22m\u001b[39mPrecompiling TransducersLazyArraysExt [cdbecb60-77cf-500a-86c2-8d8bbf22df88]\n"
34 | ]
35 | }
36 | ],
37 | "source": [
38 | "using CombinatorialSpaces"
39 | ]
40 | },
41 | {
42 | "cell_type": "code",
43 | "execution_count": null,
44 | "id": "a55826ab-4c6c-40c7-957b-3e41bf78fd1c",
45 | "metadata": {},
46 | "outputs": [],
47 | "source": []
48 | }
49 | ],
50 | "metadata": {
51 | "kernelspec": {
52 | "display_name": "Julia 1.10.5",
53 | "language": "julia",
54 | "name": "julia-1.10"
55 | },
56 | "language_info": {
57 | "file_extension": ".jl",
58 | "mimetype": "application/julia",
59 | "name": "julia",
60 | "version": "1.10.5"
61 | }
62 | },
63 | "nbformat": 4,
64 | "nbformat_minor": 5
65 | }
66 |
--------------------------------------------------------------------------------
/TDA/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
3 | CombinatorialSpaces = "b1c52339-7909-45ad-8b6a-6e388f7c67f2"
4 | Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
5 | Distances = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
6 | Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
7 | Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
8 | Hodge = "3c44080d-357b-4062-ad7b-6cab49ad4f79"
9 | NetworkLayout = "46757867-2c16-5918-afeb-47bfcb05e46a"
10 | OptimalTransport = "7e02d93a-ae51-4f58-b602-d97af76e3b33"
11 | OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
12 | Oscar = "f1435218-dba5-11e9-1e4d-f1a5fab5fc13"
13 | PersistenceDiagrams = "90b4794c-894b-4756-a0f8-5efeb5ddf7ae"
14 | Ripserer = "aa79e827-bd0b-42a8-9f10-2b302677a641"
15 | StructArrays = "09ab397b-f2b6-538f-b94a-2f83cf4a842a"
16 | Tulip = "6dd1b50a-3aae-11e9-10b5-ef983d2400fa"
17 | Vizagrams = "8c229dad-8b3a-4031-83d6-73545c88426d"
18 |
--------------------------------------------------------------------------------
/TDA/Untitled.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "id": "0b50713c-0735-4db6-8bf8-e18489ecfed5",
6 | "metadata": {},
7 | "source": []
8 | },
9 | {
10 | "cell_type": "code",
11 | "execution_count": 3,
12 | "id": "56997db4-c6f8-4c78-b4d1-b27b605fa5cd",
13 | "metadata": {},
14 | "outputs": [
15 | {
16 | "name": "stderr",
17 | "output_type": "stream",
18 | "text": [
19 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m project at `~/Documents/GitHub/PhDThesis/implementations/TDA`\n"
20 | ]
21 | }
22 | ],
23 | "source": [
24 | "using Pkg\n",
25 | "Pkg.activate(\".\")"
26 | ]
27 | },
28 | {
29 | "cell_type": "code",
30 | "execution_count": 6,
31 | "id": "f75fe84d-d7c3-492c-a1d9-f5a0f228bae6",
32 | "metadata": {},
33 | "outputs": [],
34 | "source": [
35 | "# Pkg.add(\"ToMATo\")"
36 | ]
37 | },
38 | {
39 | "cell_type": "code",
40 | "execution_count": null,
41 | "id": "a292960e-115e-41d4-ae90-1a0d1da0d5dc",
42 | "metadata": {},
43 | "outputs": [],
44 | "source": []
45 | }
46 | ],
47 | "metadata": {
48 | "kernelspec": {
49 | "display_name": "Julia 1.10.5",
50 | "language": "julia",
51 | "name": "julia-1.10"
52 | },
53 | "language_info": {
54 | "file_extension": ".jl",
55 | "mimetype": "application/julia",
56 | "name": "julia",
57 | "version": "1.10.5"
58 | }
59 | },
60 | "nbformat": 4,
61 | "nbformat_minor": 5
62 | }
63 |
--------------------------------------------------------------------------------
/TDA/tda.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 3,
6 | "id": "19009788-69b5-4933-8a4d-f9adbb852e8c",
7 | "metadata": {},
8 | "outputs": [],
9 | "source": [
10 | "from simplicial import *\n",
11 | "\n",
12 | "c = SimplicialComplex()"
13 | ]
14 | },
15 | {
16 | "cell_type": "code",
17 | "execution_count": 4,
18 | "id": "6f832b64-46d2-44b8-b6c2-68c56658a436",
19 | "metadata": {},
20 | "outputs": [],
21 | "source": [
22 | "# add a simplex with a generated name\n",
23 | "s1 = c.addSimplex()\n",
24 | "\n",
25 | "# add simplices whose names we want to specify\n",
26 | "s2 = c.addSimplex(id = 2)\n",
27 | "s3 = c.addSimplex(id = 3)"
28 | ]
29 | },
30 | {
31 | "cell_type": "code",
32 | "execution_count": null,
33 | "id": "a4626463-34dc-4ac3-ad55-66166be5454d",
34 | "metadata": {},
35 | "outputs": [],
36 | "source": []
37 | }
38 | ],
39 | "metadata": {
40 | "kernelspec": {
41 | "display_name": "tda",
42 | "language": "python",
43 | "name": "tda"
44 | },
45 | "language_info": {
46 | "codemirror_mode": {
47 | "name": "ipython",
48 | "version": 3
49 | },
50 | "file_extension": ".py",
51 | "mimetype": "text/x-python",
52 | "name": "python",
53 | "nbconvert_exporter": "python",
54 | "pygments_lexer": "ipython3",
55 | "version": "3.12.3"
56 | }
57 | },
58 | "nbformat": 4,
59 | "nbformat_minor": 5
60 | }
61 |
--------------------------------------------------------------------------------
/TimeSeries/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
3 | DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
4 | MarketData = "945b72a4-3b13-509d-9b46-1525bb5c06de"
5 | Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
6 | StateSpaceModels = "99342f36-827c-5390-97c9-d7f9ee765c78"
7 | TimeSeries = "9e3dc215-6440-5c97-bce1-76c03772f85e"
8 | VegaLite = "112f6efa-9a02-5b7d-90c0-432ed331239a"
9 |
--------------------------------------------------------------------------------
/Visualizations/MakieTutorial.jl:
--------------------------------------------------------------------------------
1 | # Let's cover some basics of Makie
2 | #
3 | using CairoMakie
4 | using AlgebraOfGraphics
5 | kwargs = AlgebraOfGraphics.aog_theme()
6 | set_theme!(;resolution=(500, 500),kwargs...)
7 | fig, ax, pltobj = scatterlines(1:10);
--------------------------------------------------------------------------------
/Visualizations/Project.toml:
--------------------------------------------------------------------------------
1 | [deps]
2 | DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
3 | VegaDatasets = "0ae4a718-28b7-58ec-9efb-cded64d6d5b4"
4 | VegaLite = "112f6efa-9a02-5b7d-90c0-432ed331239a"
5 |
--------------------------------------------------------------------------------
/Visualizations/Untitled.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": 1,
6 | "id": "58d2badf-a3cb-4802-8d4f-86df73ee2591",
7 | "metadata": {},
8 | "outputs": [
9 | {
10 | "name": "stderr",
11 | "output_type": "stream",
12 | "text": [
13 | "\u001b[32m\u001b[1m Activating\u001b[22m\u001b[39m environment at `~/MEGA/EMAp/Julia_Tutorials/Visualizations/Project.toml`\n"
14 | ]
15 | }
16 | ],
17 | "source": [
18 | "using Pkg\n",
19 | "Pkg.activate(\".\")"
20 | ]
21 | },
22 | {
23 | "cell_type": "code",
24 | "execution_count": 2,
25 | "id": "3b670900-c458-4710-9640-23bb92d3b903",
26 | "metadata": {},
27 | "outputs": [],
28 | "source": [
29 | "using Luxor"
30 | ]
31 | },
32 | {
33 | "cell_type": "code",
34 | "execution_count": 3,
35 | "id": "5a270f1a-73bc-48c2-ba10-06e55c02a4f4",
36 | "metadata": {},
37 | "outputs": [
38 | {
39 | "data": {
40 | "image/svg+xml": [
41 | "\n",
42 | "\n"
47 | ],
48 | "text/plain": []
49 | },
50 | "execution_count": 3,
51 | "metadata": {},
52 | "output_type": "execute_result"
53 | }
54 | ],
55 | "source": [
56 | "Drawing(500, 500, \"my-drawing.svg\")\n",
57 | "origin()\n",
58 | "setcolor(\"red\")\n",
59 | "circle(Point(0, 0), 100, :fill)\n",
60 | "finish()\n",
61 | "preview()"
62 | ]
63 | },
64 | {
65 | "cell_type": "code",
66 | "execution_count": null,
67 | "id": "e7ff92a1-f460-4bfa-8e58-a4200abbf0f6",
68 | "metadata": {},
69 | "outputs": [],
70 | "source": []
71 | }
72 | ],
73 | "metadata": {
74 | "kernelspec": {
75 | "display_name": "Julia-1.6 1.6.3",
76 | "language": "julia",
77 | "name": "julia-1.6-1.6"
78 | },
79 | "language_info": {
80 | "file_extension": ".jl",
81 | "mimetype": "application/julia",
82 | "name": "julia",
83 | "version": "1.6.3"
84 | }
85 | },
86 | "nbformat": 4,
87 | "nbformat_minor": 5
88 | }
89 |
--------------------------------------------------------------------------------
/Visualizations/figure.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/davibarreira/Julia_Tutorials/60c0d8309d0077c4297f9a188e6a947b61ed38ac/Visualizations/figure.png
--------------------------------------------------------------------------------
/Visualizations/luxor-drawing-210931_348.svg:
--------------------------------------------------------------------------------
1 |
2 |
10 |
--------------------------------------------------------------------------------
/Visualizations/my-drawing.svg:
--------------------------------------------------------------------------------
1 |
2 |
7 |
--------------------------------------------------------------------------------