Unverified Commit 21533a13 authored by René Fritze's avatar René Fritze
Browse files

[models.nn] fix output_functional not properly assigned

Thanks to @jacktang for spotting the mistake and providing the fix.
This also adds a regression test for the issue
Closes #1649
parent 19d044b4
Pipeline #146427 passed with stages
in 39 minutes and 25 seconds
......@@ -95,9 +95,9 @@ class NeuralNetworkModel(BaseNeuralNetworkModel):
self.__auto_init(locals())
self.solution_space = NumpyVectorSpace(neural_network.output_dimension)
output_functional = output_functional or ZeroOperator(NumpyVectorSpace(0), self.solution_space)
assert output_functional.source == self.solution_space
self.dim_output = output_functional.range.dim
self.output_functional = output_functional or ZeroOperator(NumpyVectorSpace(0), self.solution_space)
assert self.output_functional.source == self.solution_space
self.dim_output = self.output_functional.range.dim
def _compute_solution(self, mu=None, **kwargs):
......
......@@ -83,3 +83,12 @@ def test_no_training_data():
neural_network = FullyConnectedNN([d_in, 3 * (d_in + d_out), 3 * (d_in + d_out), d_out]).double()
best_neural_network, _ = multiple_restarts_training(training_data, validation_data, neural_network)
assert np.allclose(best_neural_network(torch.DoubleTensor(np.random.rand(n, d_in))).detach(), np.zeros(d_out))
def test_issue_1649():
from pymor.models.neural_network import FullyConnectedNN
from pymor.models.neural_network import NeuralNetworkModel
from pymor.parameters.base import Parameters
neural_network = FullyConnectedNN([3, 3, 3, 3]).double()
nn_model = NeuralNetworkModel(neural_network, Parameters(mu=1))
assert nn_model.output_functional
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment