.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_example/plot_example_GENN.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_example_plot_example_GENN.py: Use of Gradient Enhanced Neural Network Model --------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 7-17 .. code-block:: default from smt.sampling_methods import LHS from smt.problems import Sphere from smt.surrogate_models.genn import GENN, load_smt_data import numpy as np import otsmt import openturns as ot .. GENERATED FROM PYTHON SOURCE LINES 18-19 | Definition of Initial data .. GENERATED FROM PYTHON SOURCE LINES 19-33 .. code-block:: default # Construction of the DOE fun = Sphere(ndim=2) sampling = LHS(xlimits=fun.xlimits, criterion="m") xt = sampling(40) yt = fun(xt) # Compute the gradient for i in range(2): yd = fun(xt, kx=i) yt = np.concatenate((yt, yd), axis=1) xv = ot.Sample([[0.1,1.],[1.,2.]]) .. GENERATED FROM PYTHON SOURCE LINES 34-35 | Training of smt model for Neural Network .. GENERATED FROM PYTHON SOURCE LINES 35-41 .. code-block:: default genn = GENN() load_smt_data( genn, xt, yt[:,0], yt[:,1:]) # convenience function to read in data that is in SMT format genn.train() .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ___________________________________________________________________________ GENN ___________________________________________________________________________ Problem size # training points. : 40 ___________________________________________________________________________ Training Training ... epoch = 0, mini-batch = 0, avg cost = 1.518 epoch = 1, mini-batch = 0, avg cost = 1.282 epoch = 2, mini-batch = 0, avg cost = 1.168 epoch = 3, mini-batch = 0, avg cost = 1.152 epoch = 4, mini-batch = 0, avg cost = 1.134 epoch = 5, mini-batch = 0, avg cost = 1.110 epoch = 6, mini-batch = 0, avg cost = 1.097 epoch = 7, mini-batch = 0, avg cost = 1.097 epoch = 8, mini-batch = 0, avg cost = 1.097 epoch = 9, mini-batch = 0, avg cost = 1.097 Training - done. Time (sec): 2.8779452 .. GENERATED FROM PYTHON SOURCE LINES 42-43 | Creation of OpenTurns PythonFunction for prediction .. GENERATED FROM PYTHON SOURCE LINES 43-51 .. code-block:: default otgenn = otsmt.smt2ot(genn) otgennprediction = otgenn.getPredictionFunction() otgenngradient = otgenn.getPredictionDerivativesFunction() print('Predicted values by GENN:',otgennprediction(xv)) print('Prediction derivatives by GENN:',otgenngradient(xv)) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none ___________________________________________________________________________ Evaluation # eval points. : 2 Predicting ... Predicting - done. Time (sec): 0.0000725 Prediction time/pt. (sec) : 0.0000362 Predicted values by GENN: [ y0 ] 0 : [ 34.0542 ] 1 : [ 35.4242 ] ___________________________________________________________________________ Evaluation # eval points. : 2 Predicting ... Predicting - done. Time (sec): 0.0002291 Prediction time/pt. (sec) : 0.0001146 ___________________________________________________________________________ Evaluation # eval points. : 2 Predicting ... Predicting - done. Time (sec): 0.0001798 Prediction time/pt. (sec) : 0.0000899 Prediction derivatives by GENN: [ y0 y1 ] 0 : [ 0.28395 1.73131 ] 1 : [ -0.420781 1.15612 ] .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 2.883 seconds) .. _sphx_glr_download_auto_example_plot_example_GENN.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_example_GENN.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_example_GENN.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_