sgdml/train.py
def _recov_int_const(self, model, task):  # TODO: document e_err_inconsist return
        """
        Estimate the integration constant for a force field model.

        The offset between the energies predicted for the original training
        data and the true energy labels is computed in the least square sense.
        Furthermore, common issues with the user-provided datasets are self
        diagnosed here.

        Parameters
        ----------
            model : :obj:`dict`
                Data structure of custom type :obj:`model`.
            task : :obj:`dict`
                Data structure of custom type :obj:`task`.

        Returns
        -------
            float
                Estimate for the integration constant.

        Raises
        ------
            ValueError
                If the sign of the force labels in the dataset from
                which the model emerged is switched (e.g. gradients
                instead of forces).
            ValueError
                If inconsistent/corrupted energy labels are detected
                in the provided dataset.
            ValueError
                If different scales in energy vs. force labels are
                detected in the provided dataset.
        """

        gdml = GDMLPredict(
            model, max_processes=self._max_processes
        )  # , use_torch=self._use_torch
        n_train = task['E_train'].shape[0]

        R = task['R_train'].reshape(n_train, -1)

        E_pred, _ = gdml.predict(R)
        E_ref = np.squeeze(task['E_train'])

        e_fact = np.linalg.lstsq(
            np.column_stack((E_pred, np.ones(E_ref.shape))), E_ref, rcond=-1
        )[0][0]
        corrcoef = np.corrcoef(E_ref, E_pred)[0, 1]

        if np.sign(e_fact) == -1:
            self.log.warning(
                'The provided dataset contains gradients instead of force labels (flipped sign). Please correct!\n'
                + ui.color_str('Note:', bold=True) + 'Note: The energy prediction accuracy of the model will thus neither be validated nor tested in the following steps!'
            )
            return None

        if corrcoef < 0.95:
            self.log.warning(
                'Inconsistent energy labels detected!\n'
                + 'The predicted energies for the training data are only weakly correlated with the reference labels (correlation coefficient {:.2f}) which indicates that the issue is most likely NOT just a unit conversion error.\n\n'.format(corrcoef)
                + ui.color_str('Troubleshooting tips:\n', bold=True)
                + ui.wrap_indent_str('(1) ', 'Verify the correct correspondence between geometries and labels in the provided dataset.') + '\n'
                + ui.wrap_indent_str('(2) ', 'Verify the consistency between energy and force labels.') + '\n'
                + ui.wrap_indent_str('    - ', 'Correspondence correct?') + '\n'
                + ui.wrap_indent_str('    - ', 'Same level of theory?') + '\n'
                + ui.wrap_indent_str('    - ', 'Accuracy of forces (if numerical)?') + '\n'
                + ui.wrap_indent_str('(3) ', 'Is the training data spread too broadly (i.e. weakly sampled transitions between example clusters)?') + '\n'
                + ui.wrap_indent_str('(4) ', 'Are there duplicate geometries in the training data?') + '\n'
                + ui.wrap_indent_str('(5) ', 'Are there any corrupted data points (e.g. parsing errors)?') + '\n\n'
                + ui.color_str('Note:', bold=True) + ' The energy prediction accuracy of the model will thus neither be validated nor tested in the following steps!'
            )
            return None

        if np.abs(e_fact - 1) > 1e-1:
            self.log.warning(
                'Different scales in energy vs. force labels detected!\n'
                + 'The integrated forces differ from the energy labels by factor ~{:.2f}, meaning that the trained model will likely fail to predict energies accurately.\n\n'.format(e_fact)
                + ui.color_str('Troubleshooting tips:\n', bold=True)
                + ui.wrap_indent_str('(1) ', 'Verify consistency of units in energy and force labels.') + '\n'
                + ui.wrap_indent_str('(2) ', 'Is the training data spread too broadly (i.e. weakly sampled transitions between example clusters)?') + '\n\n'
                + ui.color_str('Note:', bold=True) + ' The energy prediction accuracy of the model will thus neither be validated nor tested in the following steps!'
            )
            return None

        # Least squares estimate for integration constant.
        return np.sum(E_ref - E_pred) / E_ref.shape[0]

        Estimate the integration constant for a force field model.

        The offset between the energies predicted for the original training
        data and the true energy labels is computed in the least square sense.
        Furthermore, common issues with the user-provided datasets are self
        diagnosed here.

        Parameters
        ----------
            model : :obj:`dict`
                Data structure of custom type :obj:`model`.
            task : :obj:`dict`
                Data structure of custom type :obj:`task`.

        Returns
        -------
            float
                Estimate for the integration constant.

        Raises
        ------
            ValueError
                If the sign of the force labels in the dataset from
                which the model emerged is switched (e.g. gradients
                instead of forces).
            ValueError
                If inconsistent/corrupted energy labels are detected
                in the provided dataset.
            ValueError
                If different scales in energy vs. force labels are
                detected in the provided dataset.
        
Estimate the integration constant for a force field model.
The offset between the energies predicted for the original training
data and the true energy labels is computed in the least square sense.
Furthermore, common issues with the user-provided datasets are self
diagnosed here.

Parameters



Returns

float
Estimate for the integration constant.

Raises

ValueError
If the sign of the force labels in the dataset from
which the model emerged is switched .
ValueError
If inconsistent/corrupted energy labels are detected
in the provided dataset.
ValueError
If different scales in energy vs. force labels are
detected in the provided dataset.
Estimate the integration constant for a force field model . The offset between the energies predicted for the original training data and the true energy labels is computed in the least square sense . Furthermore common issues with the user - provided datasets are self diagnosed here . Parameters Returns float Estimate for the integration constant . Raises ValueError If the sign of the force labels in the dataset from which the model emerged is switched . ValueError If inconsistent / corrupted energy labels are detected in the provided dataset . ValueError If different scales in energy vs . force labels are detected in the provided dataset .
def _recov_int_const(self, model, task):  
        gdml = GDMLPredict(
            model, max_processes=self._max_processes
        )  
        n_train = task['E_train'].shape[0]
        R = task['R_train'].reshape(n_train, -1)
        E_pred, _ = gdml.predict(R)
        E_ref = np.squeeze(task['E_train'])
        e_fact = np.linalg.lstsq(
            np.column_stack((E_pred, np.ones(E_ref.shape))), E_ref, rcond=-1
        )[0][0]
        corrcoef = np.corrcoef(E_ref, E_pred)[0, 1]
        if np.sign(e_fact) == -1:
            self.log.warning(
                'The provided dataset contains gradients instead of force labels (flipped sign). Please correct!\n'
                + ui.color_str('Note:', bold=True) + 'Note: The energy prediction accuracy of the model will thus neither be validated nor tested in the following steps!'
            )
            return None
        if corrcoef < 0.95:
            self.log.warning(
                'Inconsistent energy labels detected!\n'
                + 'The predicted energies for the training data are only weakly correlated with the reference labels (correlation coefficient {:.2f}) which indicates that the issue is most likely NOT just a unit conversion error.\n\n'.format(corrcoef)
                + ui.color_str('Troubleshooting tips:\n', bold=True)
                + ui.wrap_indent_str('(1) ', 'Verify the correct correspondence between geometries and labels in the provided dataset.') + '\n'
                + ui.wrap_indent_str('(2) ', 'Verify the consistency between energy and force labels.') + '\n'
                + ui.wrap_indent_str('    - ', 'Correspondence correct?') + '\n'
                + ui.wrap_indent_str('    - ', 'Same level of theory?') + '\n'
                + ui.wrap_indent_str('    - ', 'Accuracy of forces (if numerical)?') + '\n'
                + ui.wrap_indent_str('(3) ', 'Is the training data spread too broadly (i.e. weakly sampled transitions between example clusters)?') + '\n'
                + ui.wrap_indent_str('(4) ', 'Are there duplicate geometries in the training data?') + '\n'
                + ui.wrap_indent_str('(5) ', 'Are there any corrupted data points (e.g. parsing errors)?') + '\n\n'
                + ui.color_str('Note:', bold=True) + ' The energy prediction accuracy of the model will thus neither be validated nor tested in the following steps!'
            )
            return None
        if np.abs(e_fact - 1) > 1e-1:
            self.log.warning(
                'Different scales in energy vs. force labels detected!\n'
                + 'The integrated forces differ from the energy labels by factor ~{:.2f}, meaning that the trained model will likely fail to predict energies accurately.\n\n'.format(e_fact)
                + ui.color_str('Troubleshooting tips:\n', bold=True)
                + ui.wrap_indent_str('(1) ', 'Verify consistency of units in energy and force labels.') + '\n'
                + ui.wrap_indent_str('(2) ', 'Is the training data spread too broadly (i.e. weakly sampled transitions between example clusters)?') + '\n\n'
                + ui.color_str('Note:', bold=True) + ' The energy prediction accuracy of the model will thus neither be validated nor tested in the following steps!'
            )
            return None
        return np.sum(E_ref - E_pred) / E_ref.shape[0]
def _recov_int_const ( self , model , task ) : gdml = GDMLPredict ( model , max_processes = self . _max_processes ) n_train = task [ 'E_train' ] . shape [ 0 ] R = task [ 'R_train' ] . reshape ( n_train , - 1 ) E_pred , _ = gdml . predict ( R ) E_ref = np . squeeze ( task [ 'E_train' ] ) e_fact = np . linalg . lstsq ( np . column_stack ( ( E_pred , np . ones ( E_ref . shape ) ) ) , E_ref , rcond = - 1 ) [ 0 ] [ 0 ] corrcoef = np . corrcoef ( E_ref , E_pred ) [ 0 , 1 ] if np . sign ( e_fact ) == - 1 : self . log . warning ( 'The provided dataset contains gradients instead of force labels (flipped sign). Please correct!\n' + ui . color_str ( 'Note:' , bold = True ) + 'Note: The energy prediction accuracy of the model will thus neither be validated nor tested in the following steps!' ) return None if corrcoef < 0.95 : self . log . warning ( 'Inconsistent energy labels detected!\n' + 'The predicted energies for the training data are only weakly correlated with the reference labels (correlation coefficient {:.2f}) which indicates that the issue is most likely NOT just a unit conversion error.\n\n' . format ( corrcoef ) + ui . color_str ( 'Troubleshooting tips:\n' , bold = True ) + ui . wrap_indent_str ( '(1) ' , 'Verify the correct correspondence between geometries and labels in the provided dataset.' ) + '\n' + ui . wrap_indent_str ( '(2) ' , 'Verify the consistency between energy and force labels.' ) + '\n' + ui . wrap_indent_str ( '    - ' , 'Correspondence correct?' ) + '\n' + ui . wrap_indent_str ( '    - ' , 'Same level of theory?' ) + '\n' + ui . wrap_indent_str ( '    - ' , 'Accuracy of forces (if numerical)?' ) + '\n' + ui . wrap_indent_str ( '(3) ' , 'Is the training data spread too broadly (i.e. weakly sampled transitions between example clusters)?' ) + '\n' + ui . wrap_indent_str ( '(4) ' , 'Are there duplicate geometries in the training data?' ) + '\n' + ui . wrap_indent_str ( '(5) ' , 'Are there any corrupted data points (e.g. parsing errors)?' ) + '\n\n' + ui . color_str ( 'Note:' , bold = True ) + ' The energy prediction accuracy of the model will thus neither be validated nor tested in the following steps!' ) return None if np . abs ( e_fact - 1 ) > 1e-1 : self . log . warning ( 'Different scales in energy vs. force labels detected!\n' + 'The integrated forces differ from the energy labels by factor ~{:.2f}, meaning that the trained model will likely fail to predict energies accurately.\n\n' . format ( e_fact ) + ui . color_str ( 'Troubleshooting tips:\n' , bold = True ) + ui . wrap_indent_str ( '(1) ' , 'Verify consistency of units in energy and force labels.' ) + '\n' + ui . wrap_indent_str ( '(2) ' , 'Is the training data spread too broadly (i.e. weakly sampled transitions between example clusters)?' ) + '\n\n' + ui . color_str ( 'Note:' , bold = True ) + ' The energy prediction accuracy of the model will thus neither be validated nor tested in the following steps!' ) return None return np . sum ( E_ref - E_pred ) / E_ref . shape [ 0 ]
Estimate the integration constant for a force field model.
Estimate the integration constant for a force field model .
# TODO: document e_err_inconsist return """
        Estimate the integration constant for a force field model.

        The offset between the energies predicted for the original training
        data and the true energy labels is computed in the least square sense.
        Furthermore, common issues with the user-provided datasets are self
        diagnosed here.

        Parameters
        ----------
            model : :obj:`dict`
                Data structure of custom type :obj:`model`.
            task : :obj:`dict`
                Data structure of custom type :obj:`task`.

        Returns
        -------
            float
                Estimate for the integration constant.

        Raises
        ------
            ValueError
                If the sign of the force labels in the dataset from
                which the model emerged is switched (e.g. gradients
                instead of forces).
            ValueError
                If inconsistent/corrupted energy labels are detected
                in the provided dataset.
            ValueError
                If different scales in energy vs. force labels are
                detected in the provided dataset.
        """ # , use_torch=self._use_torch # Least squares estimate for integration constant.
self
model
task