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

NNsPOD #221

Closed
wants to merge 3 commits into from
Closed

NNsPOD #221

wants to merge 3 commits into from

Conversation

MMRROOO
Copy link
Contributor

@MMRROOO MMRROOO commented Jun 23, 2022

implementation of NNsPOD for ezyrb

@MMRROOO MMRROOO force-pushed the NNsPOD branch 3 times, most recently from be97435 to 37cf70a Compare July 12, 2022 13:47
@MMRROOO MMRROOO force-pushed the NNsPOD branch 2 times, most recently from 820cdd7 to dea1126 Compare July 19, 2022 15:56
ezyrb/ann.py Outdated
@@ -122,11 +122,10 @@ def fit(self, points, values):
"""

self._build_model(points, values)
self.optimizer = torch.optim.Adam(self.model.parameters())
self.optimizer = torch.optim.Adam(self.model.parameters(), lr = 0.01)
Copy link
Member

Choose a reason for hiding this comment

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

Can we add the possibility to pass the optimizer (Adam by default) and the learning_rate (0.001 by default)?

ezyrb/ann.py Outdated
@@ -143,7 +142,7 @@ def fit(self, points, values):
elif isinstance(criteria, float): # stop criteria is float
if loss.item() < criteria:
flag = False

print(loss.item())
Copy link
Member

Choose a reason for hiding this comment

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

Can we have something more customizable? Like decide the print frequency (frequency_print should be an optional argument in the constructor) like in this snippet

if epoch % frequency_print == 0 or epoch == 1:                                                                                
    print('[epoch {:05d}] {:.6e}'.format(self.trained_epoch, loss.item()))

ezyrb/ann.py Outdated
Comment on lines 160 to 167
def predict_tensor(self, new_point):

return self.model(new_point)
Copy link
Member

Choose a reason for hiding this comment

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

Such a method is just a type specification of the predict method. Please avoid that, and instead check the type inside predict and use conversion only if the input is NumPy

ezyrb/ann.py Outdated
Comment on lines 173 to 179


Copy link
Member

Choose a reason for hiding this comment

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

too many blank lines

ezyrb/ann.py Outdated
Comment on lines 181 to 187


Copy link
Member

Choose a reason for hiding this comment

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

too many blank lines

ezyrb/nnspod.py Outdated

def reshape2dto1d(self, x, y):
"""
reshapes graphable data into data that can go through the Neural Net
Copy link
Member

Choose a reason for hiding this comment

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

What do you mean with "graphable" data?

ezyrb/nnspod.py Outdated
def reshape2dto1d(self, x, y):
"""
reshapes graphable data into data that can go through the Neural Net
:param array x: x value of data
Copy link
Member

Choose a reason for hiding this comment

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

needs to be numpy.array

ezyrb/nnspod.py Outdated
return snapshots.reshape(int(np.sqrt(len(snapshots))), int(np.sqrt(len(snapshots))))


def train_InterpNet1d(self,ref_data, interp_layers, interp_function, interp_stop_training, interp_loss, retrain = False):
Copy link
Member

Choose a reason for hiding this comment

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

no capital in method names

ezyrb/nnspod.py Outdated



def train_InterpNet2d(self,ref_data, interp_layers, interp_function, interp_stop_training, interp_loss, retrain = False):
Copy link
Member

Choose a reason for hiding this comment

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

Please merge function for 1D e 2D. Keep always one general function, instead of specifying several methods for different dimensions

@ndem0
Copy link
Member

ndem0 commented Jul 21, 2022

In the NNsPOD class the fit method is not defined, so it's not totally clear to me how it works with the ReducedOrderModel class.
I report also conflicts in the database module.

@MMRROOO MMRROOO force-pushed the NNsPOD branch 2 times, most recently from 0f054a3 to 1171901 Compare July 21, 2022 12:51
@@ -99,7 +99,7 @@ def _build_model(self, points, values):
layers_torch.append(nn.Linear(layers[-2], layers[-1]))
self.model = nn.Sequential(*layers_torch)

def fit(self, points, values):
def fit(self, points, values, optimizer = torch.optim.Adam, learning_rate = 0.001, frequency_print = 0):
Copy link
Member

Choose a reason for hiding this comment

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

optimizer and learning_rate should be constructor arguments

@ndem0
Copy link
Member

ndem0 commented Feb 7, 2024

Merged in #232

@ndem0 ndem0 closed this Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants