praca-magisterska/docs/images/plots.ipynb

195 lines
72 KiB
Plaintext
Raw Normal View History

2020-04-06 19:23:25 +02:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
2020-04-06 19:23:25 +02:00
"metadata": {},
"outputs": [],
"source": [
"import music21\n",
"from music21.midi import MidiFile\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
2020-04-06 19:23:25 +02:00
"import mido"
]
},
{
"cell_type": "markdown",
2020-04-06 19:23:25 +02:00
"metadata": {},
"source": [
"# midi messages"
2020-04-06 19:23:25 +02:00
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": "<meta message set_tempo tempo=500000 time=0>\n<meta message time_signature numerator=4 denominator=4 clocks_per_click=24 notated_32nd_notes_per_beat=8 time=0>\n<meta message end_of_track time=1>\n<meta message track_name name='Guitar' time=0>\nprogram_change channel=0 program=30 time=0\nnote_on channel=0 note=48 velocity=100 time=0\nnote_on channel=0 note=53 velocity=100 time=0\nnote_on channel=0 note=60 velocity=100 time=0\nnote_on channel=0 note=48 velocity=0 time=220\nnote_on channel=0 note=48 velocity=100 time=0\nnote_on channel=0 note=53 velocity=0 time=0\nnote_on channel=0 note=55 velocity=100 time=0\nnote_on channel=0 note=60 velocity=0 time=0\nnote_on channel=0 note=60 velocity=100 time=0\nnote_on channel=0 note=48 velocity=0 time=220\nnote_on channel=0 note=48 velocity=100 time=0\nnote_on channel=0 note=55 velocity=0 time=0\nnote_on channel=0 note=55 velocity=100 time=0\nnote_on channel=0 note=60 velocity=0 time=0\nnote_on channel=0 note=60 velocity=100 time=0\nnote_on channel=0 note=48 velocity=0 time=440\nnote_on channel=0 note=55 velocity=0 time=0\nnote_on channel=0 note=60 velocity=0 time=0\nnote_on channel=0 note=48 velocity=0 time=110\nnote_on channel=0 note=48 velocity=100 time=0\nnote_on channel=0 note=45 velocity=100 time=770\nnote_on channel=0 note=50 velocity=100 time=0\nnote_on channel=0 note=57 velocity=100 time=0\nnote_on channel=0 note=45 velocity=0 time=220\nnote_on channel=0 note=46 velocity=100 time=0\nnote_on channel=0 note=50 velocity=0 time=0\nnote_on channel=0 note=53 velocity=100 time=0\nnote_on channel=0 note=57 velocity=0 time=0\nnote_on channel=0 note=58 velocity=100 time=0\nnote_on channel=0 note=46 velocity=0 time=220\nnote_on channel=0 note=46 velocity=100 time=0\nnote_on channel=0 note=53 velocity=0 time=0\nnote_on channel=0 note=53 velocity=100 time=0\nnote_on channel=0 note=58 velocity=0 time=0\nnote_on channel=0 note=58 velocity=100 time=0\nnote_on channel=0 note=46 velocity=0 time=220\nnote_on channel=0 note=46 velocity=100 time=0\nnote_on channel=0 note=53 velocity=0 time=0\nnote_on channel=0 note=53 velocity=100 time=0\nnote_on channel=0 note=58 velocity=0 time=0\nnote_on channel=0 note=58 velocity=100 time=0\nnote_on channel=0 note=46 velocity=0 time=440\nnote_on channel=0 note=48 velocity=100 time=0\nnote_on channel=0 note=53 velocity=0 time=0\nnote_on channel=0 note=53 velocity=100 time=0\nnote_on channel=0 note=58 velocity=0 time=0\nnote_on channel=0 note=60 velocity=100 time=0\nnote_on channel=0 note=48 velocity=0 time=440\nnote_on channel=0 note=48 velocity=100 time=0\nnote_on channel=0 note=53 velocity=0 time=0\nnote_on channel=0 note=53 velocity=100 time=0\nnote_on channel=0 note=60 velocity=0 time=0\nnote_on channel=0 note=60 velocity=100 time=0\nnote_on channel=0 note=48 velocity=0 time=220\nnote_on channel=0 note=48 velocity=100 time=0\nnote_on channel=0 note=53 velocity=0 time=0\nnote_on channel=0 note=60 velocity=0 time=0\nnote_on channel=0 note=48 velocity=0 time=220\nnote_on channel=0 note=51 velocity=100 time=0\nnote_on channel=0 note=48 velocity=100 time=220\nnote_on channel=0 note=51 velocity=0 time=0\nnote_on channel=0 note=48 velocity=0 time=220\nnote_on channel=0 note=60 velocity=100 time=0\nnote_on channel=0 note=51 velocity=100 time=220\nnote_on channel=0 note=60 velocity=0 time=0\nnote_on channel=0 note=51 velocity=0 time=220\nnote_on channel=0 note=51 velocity=100 time=0\nnote_on channel=0 note=51 velocity=0 time=220\nnote_on channel=0 note=53 velocity=100 time=0\nnote_on channel=0 note=46 velocity=100 time=440\nnote_on channel=0 note=53 velocity=0 time=0\nnote_on channel=0 note=53 velocity=100 time=0\nnote_on channel=0 note=58 velocity=100 time=0\nnote_on channel=0 note=46 velocity=0 time=990\nnote_on channel=0 note=53 velocity=0 time=0\nnote_on channel=0 note=58 velocity=0 time=0\nnote_on channel=0 note=46 velocity=100 time=110\nnote_on channel=0 note=53 velocity=100 time=0\nnote_on channel=0 note=58 velocity=100 time=0\nnote_on channel=0 note=46 velocity=0 time=220\nnote_on channel=0 note=46 velocity=100 time=0\nnote_on channel=0 note
}
],
"source": [
"filepath = '/home/altarin/praca-magisterska/docs/images/seq2seq_generated_midi_7.mid'\n",
2020-04-06 19:23:25 +02:00
"mid = mido.MidiFile(filepath)\n",
"for i, track in enumerate(mid.tracks):\n",
" for msg in track:\n",
" print(msg)"
]
},
2020-04-07 07:40:35 +02:00
{
"cell_type": "markdown",
2020-04-07 07:40:35 +02:00
"metadata": {},
"source": [
"# Regresja liniowa"
]
2020-04-07 07:40:35 +02:00
},
2020-04-06 19:23:25 +02:00
{
"cell_type": "code",
"execution_count": 7,
2020-04-06 19:23:25 +02:00
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": "[<matplotlib.lines.Line2D at 0x7fe0d90a1580>]"
},
"metadata": {},
"execution_count": 7
},
2020-04-06 19:23:25 +02:00
{
"output_type": "display_data",
"data": {
"text/plain": "<Figure size 432x288 with 1 Axes>",
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAtUAAAHwCAYAAABpOpNzAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAWJQAAFiUBSVIk8AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy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K8jhL2EYTgiC4FVgGlDX7tJLwLVfHgvp4DO2Wlx9wQr2NwrRpyRJUuLefReOPBJuuim/vvfecOWVsMYayfSlbinU7h8nATcD1xKtUC8PbAW8DFwfBMGFhXiOJElSyQpDuO46GD48P1CvuSbccktUM1CXrG6H6iAIvgtcAPwpDMPjwjB8OQzDmWEYPgnsBbwJHB8EwYbdfZYkSVJJ+s9/YNdd4cADoznqhQ46CGbMgB/9KLneVBCFWKnefcHX+758IQzDmcBjC57jpoqSJKlvyeVg0iQYORLuuSeub7ABtLRELyiutFJi7alwCjFTvdyCrx1tm7ewPqcAz5IkSSoNzz8PY8bAgw/GtSCI5qnPOQdWWCG53lRwhVipfmDB1/ogCNZufyEIgl2B7YHZwMMFeJYkSVJxmzs32l96883zA/Vmm0XfX365gboMFWKl+mbgXmBn4LkgCG4F3gGGE42GBMDYMAw/LMCzJEmSitdTT0FtbfR1of79YexYOP306LhxlaVC7FOdC4Lg+8DhwL5ELycOAT4C7gImhmHY0t3nSJIkFa3Zs6GxES68EObPj+tbbQXNzdGqtcpaofapngtMWPBLkiSp73jooWh1+vn
2020-04-06 19:23:25 +02:00
},
"metadata": {
"image/png": {
"width": 362,
"height": 248
},
"needs_background": "light"
}
}
],
"source": [
"x = np.arange(0,10)\n",
"y = np.arange(0,10) + np.random.random(10)-0.5\n",
"y_hat = np.arange(0,10)\n",
"plt.scatter(x, y, c='k')\n",
"plt.plot(x,y_hat, c='r')\n",
"# plt.labels\n",
2020-04-06 19:23:25 +02:00
"# plt.savefig('linear_reg.png')"
]
},
{
"cell_type": "code",
2020-04-07 07:40:35 +02:00
"execution_count": 20,
2020-04-06 19:23:25 +02:00
"metadata": {},
"outputs": [],
"source": [
"# Gradient descent\n",
"\n",
"fx = x^2\n",
"dx = 2x + c\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 92,
"metadata": {},
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": "<Figure size 432x288 with 1 Axes>",
"image/png":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/AOJZNCggvHnn0u7dv3qFP8PX/8VOQAIB272BSKL8A8kklNPldq0CYxzcqSJE391iv+H75w5c5Sbmxup6gAkmJ07d2rVqlWSpJSUFLVu3dpxRUD8I/wDieYorT8NGjRQnTp1JElZWVlasWJFpCoDkGD8rYUtW7ZUxYoVHVYDJAbCP5Bo/OF/8mRp375CTxtj1LFjR28+e/bsSFUGIMHQ8gNEHuEfSDQNG0pNmwbGBw8GfgEogvAPIBK42ReIPMI/kIiO0vpD+AcQbjk5OYWWE+bKPxAZhH8gEfnD/8cfS4cOFXq6ZcuWqlChgiRp48aN+umnnyJZHYAEsHz5cu3du1eSdMoppyg9Pd1xRUBiIPwDiah5c6l+/cA4K0uaNq3Q06mpqWrbtq035+o/gFDz9/vT8gNEDuEfSETG0PoDwCn/9xVafoDIIfwDiSozs2A8fnxg3X8fwj+AcJo1a5Y3Pv/88x1WAiQWwj+QqM47T6pbNzDetk3y/SCWCv8ZfvHixdpXZElQADhe33//vTZt2iRJqly5slq0aOG4IiBxEP6BRJWUJA0aVDAv0vpTs2ZNNWnSRJKUm5ur+fPnR7I6AHHM/9fEdu3aKSUlxWE1QGIh/AOJrGjff15eoadp/QEQDrT8AO4Q/oFE1rmzVLNmYPzjj9LXXxd6mvAPIBz84d//fQZA+BH+gURWrpw0YEDBvEjrj/+K3Jw5c5RX5C8DAHCsdu/erWXLlkmSkpKS1K5dO8cVAYmF8A8kOn/rz9ixkrXetEGDBqpTp46kwA/sFStWRLo6AHFm7ty53oWEFi1aqGrVqo4rAhIL4R9IdL16SZUrB8b
},
"metadata": {
"image/png": {
"width": 383,
"height": 252
},
"needs_background": "light"
}
}
],
"source": [
"func = lambda x: x**2\n",
"func_dx = lambda x:2*x\n",
"\n",
"x = np.arange(-20,20,0.1)\n",
"y = func(x)\n",
"\n",
"point_x = -6\n",
"point_y = func(point_x)\n",
"\n",
"\n",
"\n",
"dx = styczna(x)\n",
"\n",
"learning_points_xs = np.arange(point_x, 0, 0.8)\n",
"learning_points_ys = func(learning_points_xs)\n",
"\n",
"fig, ax = plt.subplots()\n",
"ax.plot(x, y, c='k')\n",
"\n",
"for px in learning_points_xs[0:1]:\n",
" slope = func_dx(px)\n",
" intercept = -px**2\n",
" styczna = lambda x: slope*x + intercept\n",
" dx = styczna(x)\n",
" ax.plot(x, dx, c='r', zorder=1)\n",
"\n",
"ax.scatter(x=point_x, y=point_y, c='r', zorder=6) #start\n",
"# ax.scatter(x=0, y=0, c='g', zorder=6) #min\n",
"# ax.scatter(x=learning_points_xs, y=learning_points_ys, c='y', zorder=5)\n",
"plt.ylim((-20,80))\n",
"plt.xlim((-20,20))\n",
"# plt.xlabel('x')\n",
"# plt.ylabel('f(x) = x^2')\n",
"\n",
"plt.savefig('gradient_descent_1.png')\n",
"\n",
"# https://towardsdatascience.com/understanding-the-mathematics-behind-gradient-descent-dde5dc9be06e?\n",
"# https://medium.com/code-heroku/gradient-descent-for-machine-learning-3d871fa48b4c"
]
2020-04-06 19:23:25 +02:00
},
{
"cell_type": "code",
2020-04-07 07:40:35 +02:00
"execution_count": null,
2020-04-06 19:23:25 +02:00
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"language_info": {
"name": "python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"version": "3.8.3-final"
},
"orig_nbformat": 2,
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"npconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": 3,
"kernelspec": {
"name": "python38264bit90963b6dfcff4977b23d3abddad7c054",
"display_name": "Python 3.8.2 64-bit"
}
},
"nbformat": 4,
"nbformat_minor": 2
2020-04-06 19:23:25 +02:00
}