scratch.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/usr/bin/env python
  2. # coding: utf-8
  3. # (ch:intro)=
  4. # # Scratchpad
  5. #
  6. #
  7. # In this chapter, we do blah.
  8. # Specifically
  9. #
  10. # - foo
  11. # - bar.
  12. # - baz
  13. #
  14. # For more details, see
  15. # {ref}`ch:hmm` and {cite}`Sarkka13`.
  16. #
  17. #
  18. # ## Python
  19. #
  20. # We\'re now ready to start coding.
  21. # In[1]:
  22. from matplotlib import rcParams, cycler
  23. import matplotlib.pyplot as plt
  24. import numpy as np
  25. plt.ion()
  26. # In[2]:
  27. # Fixing random state for reproducibility
  28. np.random.seed(19680801)
  29. N = 10
  30. data = [np.logspace(0, 1, 100) + np.random.randn(100) + ii for ii in range(N)]
  31. data = np.array(data).T
  32. cmap = plt.cm.coolwarm
  33. rcParams['axes.prop_cycle'] = cycler(color=cmap(np.linspace(0, 1, N)))
  34. from matplotlib.lines import Line2D
  35. custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),
  36. Line2D([0], [0], color=cmap(.5), lw=4),
  37. Line2D([0], [0], color=cmap(1.), lw=4)]
  38. fig, ax = plt.subplots(figsize=(10, 5))
  39. lines = ax.plot(data)
  40. ax.legend(custom_lines, ['Cold', 'Medium', 'Hot']);
  41. # In[3]:
  42. import matplotlib.pyplot as plt
  43. import numpy as np
  44. import jax
  45. import jax.numpy as jnp
  46. print(jax.devices())
  47. # ## Images
  48. #
  49. #
  50. # <!---
  51. # ![](https://myst-parser.readthedocs.io/en/latest/_static/logo-wide.svg)
  52. #
  53. #
  54. # <img src="https://github.com/probml/probml-notebooks/blob/main/images/cat_dog.jpg"
  55. # style="height:200">
  56. # -->
  57. #
  58. # ```{figure} /figures/cat_dog.jpg
  59. # :scale: 50%
  60. # :name: cat_dog
  61. #
  62. # A photo of a cat and a dog.
  63. # ```
  64. #
  65. # ```{figure} /figures/cat_dog.jpg
  66. # :height: 300px
  67. # :name: cat_dog2
  68. #
  69. # Another photo of a cat and a dog.
  70. # ```
  71. #
  72. # In {numref}`cat_dog`
  73. # we show catdog.
  74. # In {numref}`Figure %s <cat_dog2>` we show catdog2, its twin.
  75. #
  76. # ```{note}
  77. # I am a useful note!
  78. # ```
  79. #
  80. # ## Math
  81. #
  82. # Here is $\N=10$ and blah. $\floor{42.3}= 42$. Let's try again.
  83. #
  84. # We have $E= mc^2$, and also
  85. #
  86. # ```{math}
  87. # :label: foo
  88. # a x^2 + bx+ c = 0
  89. # ```
  90. #
  91. # From {eq}`foo`, it follows that
  92. #
  93. # $$
  94. # \begin{align}
  95. # 0 &= a x^2 + bx+ c \\
  96. # 0 &= a x^2 + bx+ c
  97. # \end{align}
  98. # $$