Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to latest and fix code issues #5

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 5 additions & 8 deletions Library/Build_Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@
from keras.layers import Input, Dense, LSTM, Dropout, Flatten, Activation
from keras.layers import Lambda, Reshape, multiply
from keras.layers import concatenate, add, subtract, dot
from keras.wrappers.scikit_learn import KerasRegressor
from keras.layers.core import Activation
from keras.utils.generic_utils import get_custom_objects
from keras.utils.generic_utils import CustomObjectScope
from keras.utils import get_custom_objects, CustomObjectScope
from keras.callbacks import EarlyStopping

from scikeras.wrappers import KerasRegressor
from sklearn import linear_model
from sklearn.model_selection import cross_val_score, KFold
from sklearn.pipeline import Pipeline
Expand Down Expand Up @@ -156,14 +154,13 @@ def Loss_SV(V, S, gradient=False):
dLoss = 0 * V
return Loss_norm, dLoss

def Loss_Vin(V, Pin, Vin, bound, parameter, gradient=False):
def Loss_Vin(V, Pin, Vin, bound, gradient=False):
# Gradient for input boundary constraint
# Loss = ReLU(Pin . V - Vin)
# dLoss = ∂(ReLU(Pin . V - Vin)^2/∂V
# Input: Cf. Gradient_Descent
Pin = tf.convert_to_tensor(np.float32(Pin))
Loss = tf.linalg.matmul(V, tf.transpose(Pin), b_is_sparse=True) - Vin
# tf.cast(tf.multiply(Vin, parameter.scaler), tf.float32)
Loss = tf.keras.activations.relu(Loss) if bound == 'UB' else Loss
Loss_norm = tf.norm(Loss, axis=1, keepdims=True)/Pin.shape[0] # rescaled
if gradient:
Expand Down Expand Up @@ -193,7 +190,7 @@ def Loss_constraint(V, Vin, parameter, gradient=False):
# mean squared sum L2+L3+L4
L2, dL2 = Loss_SV(V, parameter.S, gradient=gradient)
L3, dL3 = Loss_Vin(V, parameter.Pin, Vin,
parameter.mediumbound, parameter, gradient=gradient)
parameter.mediumbound, gradient=gradient)
L4, dL4 = Loss_Vpos(V, parameter, gradient=gradient)
# square sum of L2, L3, L4
L2 = tf.math.square(L2)
Expand All @@ -213,7 +210,7 @@ def Loss_all(V, Vin, Vout, parameter, gradient=False):
L1, dL1 = Loss_Vout(V, parameter.Pout, Vout, gradient=gradient)
L2, dL2 = Loss_SV(V, parameter.S, gradient=gradient)
L3, dL3 = Loss_Vin(V, parameter.Pin, Vin,
parameter.mediumbound, parameter, gradient=gradient)
parameter.mediumbound, gradient=gradient)
L4, dL4 = Loss_Vpos(V, parameter, gradient=gradient)
# square sum of L1, L2, L3, L4
L1 = tf.math.square(L1)
Expand Down
4 changes: 2 additions & 2 deletions Tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,9 @@
"source": [
"# Runs the appropriate method\n",
"\n",
"if model.model_type is 'MM_QP':\n",
"if model.model_type == 'MM_QP':\n",
" Ypred, Stats = MM_QP(model, verbose=True)\n",
"if model.model_type is 'MM_LP':\n",
Comment on lines -614 to -616
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if model.model_type is 'MM_QP':
    Ypred, Stats = MM_QP(model, verbose=True)
if model.model_type is 'MM_LP':
    Ypred, Stats = MM_LP(model, verbose=True)

this warning should be gone after the changes I introduced here. Are you sure you had this branch pulled and were running Tutorial.ipynb?

"if model.model_type == 'MM_LP':\n",
" Ypred, Stats = MM_LP(model, verbose=True)\n",
"\n",
"# Printing results\n",
Expand Down
3 changes: 2 additions & 1 deletion environment_amn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ dependencies:
- pip
- ipykernel
- pip:
- silence-tensorflow
- silence-tensorflow
- scikeras