Skip to content

Commit

Permalink
ajout de mes solutions 1-2-3
Browse files Browse the repository at this point in the history
  • Loading branch information
Benoit-Muller committed Oct 11, 2022
1 parent 242d079 commit b32276d
Show file tree
Hide file tree
Showing 11 changed files with 525 additions and 140 deletions.
78 changes: 67 additions & 11 deletions labs/ex01/template/taskA.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"source": [
"%matplotlib inline\n",
"import numpy as np\n",
Expand All @@ -25,7 +34,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {
"collapsed": true
},
Expand All @@ -36,7 +45,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {
"collapsed": true
},
Expand All @@ -56,18 +65,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {
"scrolled": false
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0.77132064 0.02075195 0.63364823 0.74880388 0.49850701]\n",
" [0.22479665 0.19806286 0.76053071 0.16911084 0.08833981]\n",
" [0.68535982 0.95339335 0.00394827 0.51219226 0.81262096]\n",
" [0.61252607 0.72175532 0.29187607 0.91777412 0.71457578]\n",
" [0.54254437 0.14217005 0.37334076 0.67413362 0.44183317]\n",
" [0.43401399 0.61776698 0.51313824 0.65039718 0.60103895]\n",
" [0.8052232 0.52164715 0.90864888 0.31923609 0.09045935]\n",
" [0.30070006 0.11398436 0.82868133 0.04689632 0.62628715]\n",
" [0.54758616 0.819287 0.19894754 0.8568503 0.35165264]\n",
" [0.75464769 0.29596171 0.88393648 0.32551164 0.1650159 ]]\n"
]
}
],
"source": [
"print(data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {
"collapsed": true
},
Expand All @@ -76,24 +102,49 @@
"def standardize(x):\n",
" ''' fill your code in here...\n",
" '''\n",
" (n,d) = np.shape(x)\n",
" x = x - x.mean(axis=0)\n",
" x = x / np.sqrt(np.sum(x**2,axis=0)/n)\n",
" return x\n",
"\n",
"std_data = standardize(data)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[ 1.0775774 -1.34411605 0.31525355 0.80665878 0.24128662]\n",
" [-1.81711634 -0.77630186 0.74088404 -1.25592235 -1.42276759]\n",
" [ 0.62228127 1.64254169 -1.797091 -0.03521894 1.51565143]\n",
" [ 0.23651339 0.90075228 -0.83122987 1.40786459 1.11788073]\n",
" [-0.13414844 -0.95529104 -0.55795449 0.54097769 0.01136005]\n",
" [-0.70898541 0.56774371 -0.08900028 0.45652209 0.65726018]\n",
" [ 1.2571441 0.25993298 1.23775021 -0.72176808 -1.4141686 ]\n",
" [-1.41508984 -1.04555188 0.96949701 -1.69076861 0.75969247]\n",
" [-0.10744434 1.21308427 -1.14296098 1.19109415 -0.35450368]\n",
" [ 0.98926822 -0.46279408 1.15485183 -0.69943932 -1.11169162]] \n",
"\n",
" [-1.66533454e-16 4.99600361e-17 -2.22044605e-17 1.11022302e-17\n",
" 3.33066907e-16] \n",
"\n",
" [1. 1. 1. 1. 1.]\n"
]
}
],
"source": [
"print(std_data, \"\\n\\n\", np.mean(std_data, axis=0), \"\\n\\n\", np.std(std_data, axis=0))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3.8.8 ('base')",
"language": "python",
"name": "python3"
},
Expand All @@ -107,7 +158,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
"version": "3.8.8"
},
"vscode": {
"interpreter": {
"hash": "233a531365d7bd5abb8382eb032c18c305e1c6b951add6f6a5c925475bc609cb"
}
}
},
"nbformat": 4,
Expand Down
161 changes: 141 additions & 20 deletions labs/ex01/template/taskB.ipynb

Large diffs are not rendered by default.

70 changes: 56 additions & 14 deletions labs/ex01/template/taskC.ipynb

Large diffs are not rendered by default.

10 changes: 3 additions & 7 deletions labs/ex02/template/costs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ def compute_loss(y, tx, w):
Args:
y: shape=(N, )
tx: shape=(N,2)
w: shape=(2,). The vector of model parameters.
tx: shape=(N,D)
w: shape=(D,). The vector of model parameters.
Returns:
the value of the loss (a scalar), corresponding to the input parameters w.
"""
# ***************************************************
# INSERT YOUR CODE HERE
# TODO: compute loss by MSE
# ***************************************************
raise NotImplementedError
return np.sum((y-tx@w)**2)/(2*len(y))
Loading

0 comments on commit b32276d

Please sign in to comment.