Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0bdf0d5
HW1
rahulrathnakumar Aug 31, 2021
8e9d716
HW1 updated
rahulrathnakumar Aug 31, 2021
8d5b9c5
Merge branch 'main' of https://github.com/DesignInformaticsLab/Design…
rahulrathnakumar Sep 7, 2021
e673e7d
Problems 1 and 2 (theory part)
rahulrathnakumar Sep 14, 2021
b7ef2ee
Problems 3 and 5
rahulrathnakumar Sep 15, 2021
df9c5a1
Problems 3 and 5 partial
rahulrathnakumar Sep 15, 2021
9149d1d
Problem 2 coding part
rahulrathnakumar Sep 16, 2021
1877ba9
updated code for problem 2 - decrement newton
rahulrathnakumar Sep 16, 2021
4fa9bdf
code final changes - convergence plots
rahulrathnakumar Sep 16, 2021
ed24733
Updating New uploads from Dr Ren
rahulrathnakumar Oct 7, 2021
b3d6e9e
Delete Homework 2.pdf
rahulrathnakumar Oct 7, 2021
b444b09
begun homework 3 problem 2 - objective function and GP prediction for…
rahulrathnakumar Oct 8, 2021
635a1c9
Merge branch 'DesignInformaticsLab-main' of https://github.com/rahulr…
rahulrathnakumar Oct 8, 2021
aecda30
Expected improvement function
rahulrathnakumar Oct 9, 2021
74575e6
Problem 1 started w/o line search
rahulrathnakumar Oct 12, 2021
6e600a3
Problem 2 completed... Problem 1 loss not converging...
rahulrathnakumar Oct 14, 2021
3a2f40b
Improved problem 1... mistake in p_sat calculation.
rahulrathnakumar Oct 14, 2021
2e15fdb
corrected ground truth objective function output in problem 2
rahulrathnakumar Oct 14, 2021
246ae9e
Add files via upload
rahulrathnakumar Oct 17, 2021
4264cf9
Drag w/ unit mass
rahulrathnakumar Oct 18, 2021
4aca36c
Merge branch 'DesignInformaticsLab-main' of https://github.com/rahulr…
rahulrathnakumar Oct 18, 2021
b27d6b7
3 DOF w/ Drag dynamics
rahulrathnakumar Oct 19, 2021
33889cc
more changes... added fpa control var for action
rahulrathnakumar Oct 21, 2021
6b7d657
description of the problem...
rahulrathnakumar Oct 21, 2021
f4f5e23
description
rahulrathnakumar Oct 21, 2021
e620a71
description
rahulrathnakumar Oct 21, 2021
cb5cda6
Add files via upload
rahulrathnakumar Nov 24, 2021
5f1ed2b
Delete HW4.pdf
rahulrathnakumar Nov 24, 2021
e81f913
Add files via upload
rahulrathnakumar Nov 24, 2021
77cd656
Add files via upload
rahulrathnakumar Dec 3, 2021
a50ee14
Homework5 - QP w/ active set
rahulrathnakumar Dec 5, 2021
eccf587
updated SQP subproblem
rahulrathnakumar Dec 8, 2021
818da6a
Merge branch 'DesignInformaticsLab-main' of https://github.com/rahulr…
rahulrathnakumar Dec 8, 2021
e9cdc8a
BFGS
rahulrathnakumar Dec 8, 2021
9ccc9ec
w/o line search
rahulrathnakumar Dec 9, 2021
c384030
finalized with plots
rahulrathnakumar Dec 9, 2021
636b0be
QP subproblem description
rahulrathnakumar Dec 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Project/rocket_v2.ipynb
774 changes: 774 additions & 0 deletions Demo/Example on Model Selection.ipynb

Large diffs are not rendered by default.

56 changes: 56 additions & 0 deletions Homework/1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Problem 1 : Least squares fitting for vapor-liquid equilibrium
import torch
import numpy as np
import matplotlib.pyplot as plt

SMOOTH = 1e-5


def model(X, A, p_sat):
# Question : Temporary variables and the computational graph ...
k1 = A[0]*(A[1]*X[1]/(A[0]*X[0] + A[1]*X[1]))
k2 = A[1]*(A[0]*X[0]/(A[0]*X[0] + A[1]*X[1]))
t1 = X[0]*torch.exp((k1**2))*p_sat[0]
t2 = X[1]*torch.exp((k2**2))*p_sat[1]
return t1 + t2


# Define the variables to be optimized over
A = torch.tensor([2.5,2.8], requires_grad = True, dtype = torch.float64)
# Data
X = np.asarray([np.arange(0,1.1,0.1), 1-np.arange(0,1.1,0.1)])
X = torch.from_numpy(X)
p = torch.tensor([28.1, 34.4, 36.7, 36.9, 36.8, 36.7, 36.5, 35.4, 32.9, 27.8, 17.5], requires_grad = False, dtype = torch.float64)

# Constants
# a = torch.tensor([[8.07131, 1730.63, 233.426],[7.43155, 1554.679, 240.337]], requires_grad= False)
# T = 20
# p_sat_water = torch.tensor(a[0][0] - (a[0][1]/(T + a[0][2])))
# p_sat_dioxane = torch.tensor(a[1][0] - (a[1][1]/(T + a[1][2])))
p_sat = torch.tensor([1.2424, 1.4598], requires_grad = False, dtype = torch.float64)


def phi(alpha,X, A, p_sat):
return model(X, A, p_sat) - alpha*0.8*np.dot(A.grad.detach().numpy(), A.grad.detach().numpy())

def line_search(X, A, p_sat):
alpha = 0.001 # initialize step size
while np.linalg.norm(np.nan_to_num(phi(alpha,X, A, p_sat).detach().numpy()))<np.linalg.norm(np.nan_to_num(model(X = X, A = A-alpha*A.grad, p_sat = p_sat).detach().numpy())): # if f(x+a*d)>phi(a) then backtrack. d is the search direction
# print("Backtracking...")
alpha = 0.5*alpha
return alpha

for i in range(5000):
# Define the loss function
loss = torch.sum((p - model(X, A, p_sat))**2)
loss.backward()
alpha = line_search(X = X, A = A, p_sat = p_sat)
print("Alpha:", alpha, "Loss:", loss.data.numpy(), "Gradient:", A.grad.numpy(), "Parameter:", A.data.numpy())

with torch.no_grad():
A -= alpha * A.grad
A.grad.zero_()

p_final = model(X, A, p_sat)
print("Model: ", p_final)
print("Truth: ", p)
110 changes: 101 additions & 9 deletions Homework/Homework 1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true,
"pycharm": {
"name": "#%% md\n"
}
},
"source": [
"Solve the following problem using [Python SciPy.optimize][]. Please attach your code and\n",
"results. Specify your initial guesses of the solution. If you change\n",
Expand Down Expand Up @@ -65,6 +59,41 @@
"[Jupyter Notebook]: https://jupyter.org/try\n",
"[Markdown]: https://guides.github.com/features/mastering-markdown/\n",
"[Markdown Math]: http://luvxuan.top/posts/Markdown-math/"
<<<<<<< HEAD
],
"metadata": {
"collapsed": true,
"pycharm": {
"name": "#%% md\n"
}
}
},
{
"cell_type": "code",
"execution_count": 1,
"source": [
"import scipy.optimize as opt\n",
"fun = lambda x: (x[0] - x[1])**2 + (x[1] + x[2] - 2)**2 + (x[3] - 1)**2 + (x[4] - 1)**2\n",
"cons = (\n",
" {'type': 'eq', 'fun': lambda x: x[0] + 3*x[1]},\n",
" {'type': 'eq', 'fun': lambda x: x[2] + x[3] - 2*x[4]},\n",
" {'type': 'eq', 'fun': lambda x: x[1] - x[4]}\n",
")\n",
"bnds = ((-10,10), (-10,10), (-10,10), (-10,10), (-10,10))\n",
"\n",
"res = opt.minimize(fun, (1,1,1,1,1), method = 'SLSQP', bounds = bnds, constraints = cons)\n",
"res\n"
],
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" fun: 4.09302326452976\n",
" jac: array([-2.04664832, -0.18578869, -2.23243701, -2.23257673, -1.48833793])\n",
" message: 'Optimization terminated successfully'\n",
" nfev: 38\n",
=======
]
},
{
Expand Down Expand Up @@ -101,10 +130,67 @@
" jac: array([-1.05454643, -1.34545355, -0.29090709, -0.29091084, 0.58181781])\n",
" message: 'Optimization terminated successfully'\n",
" nfev: 37\n",
>>>>>>> 8f90ced4bec79abb8b5d9fde08e3e33db602bff0
" nit: 6\n",
" njev: 6\n",
" status: 0\n",
" success: True\n",
<<<<<<< HEAD
" x: array([-0.76749312, 0.25583104, 0.62795044, -0.11628835, 0.25583104])"
]
},
"metadata": {},
"execution_count": 1
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 2,
"source": [
"# Changing the initial guess\n",
"x_init = (2,3,1,4,5)\n",
"fun = lambda x: (x[0] - x[1])**2 + (x[1] + x[2] - 2)**2 + (x[3] - 1)**2 + (x[4] - 1)**2\n",
"cons = (\n",
" {'type': 'eq', 'fun': lambda x: x[0] + 3*x[1]},\n",
" {'type': 'eq', 'fun': lambda x: x[2] + x[3] - 2*x[4]},\n",
" {'type': 'eq', 'fun': lambda x: x[1] - x[4]}\n",
")\n",
"bnds = ((-10,10), (-10,10), (-10,10), (-10,10), (-10,10))\n",
"\n",
"res = opt.minimize(fun,x0 = x_init, method = 'SLSQP', bounds = bnds, constraints = cons)\n",
"res"
],
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" fun: 4.093023288479049\n",
" jac: array([-2.04646897, -0.18635827, -2.23282731, -2.2323209 , -1.4883827 ])\n",
" message: 'Optimization terminated successfully'\n",
" nfev: 43\n",
" nit: 7\n",
" njev: 7\n",
" status: 0\n",
" success: True\n",
" x: array([-0.76742588, 0.25580863, 0.62777771, -0.11616046, 0.25580863])"
]
},
"metadata": {},
"execution_count": 2
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"Changing the initial guess does not change the minimum"
],
"metadata": {}
=======
" x: array([ 1.2 , -0.4 , 1.72727322, 0.85454457, 1.2909089 ])"
]
},
Expand All @@ -116,20 +202,23 @@
"source": [
"res"
]
<<<<<<< HEAD
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
>>>>>>> 8f90ced4bec79abb8b5d9fde08e3e33db602bff0
=======
>>>>>>> 5690077459f148361cc6fc1d86ad868d764ff9b2
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
"name": "python3",
"display_name": "Python 3.7.3 64-bit ('base': conda)"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -151,6 +240,9 @@
},
"source": []
}
},
"interpreter": {
"hash": "283a19fe1c80cc8d674e9be3676f3725f85ae6255e6112c9eba9160b54893d27"
}
},
"nbformat": 4,
Expand Down
Binary file added Homework/Homework 1.pdf
Binary file not shown.
85 changes: 0 additions & 85 deletions Homework/Homework 2.ipynb

This file was deleted.

Loading