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

Refactoring and improvement of msm covariance matrices #31

Merged
merged 2 commits into from
Dec 13, 2022

Conversation

AldoGl
Copy link
Contributor

@AldoGl AldoGl commented Dec 12, 2022

Proposed changes

  • change None to 'identity' for the default behaviour of the covariance matrix
  • add the 'inverse_variance' option for the covariance matrix of Franke (2009)
  • add the 'standardise_moments' flag to only consider relative changes wrt the target moments

Types of changes

What types of changes does your code introduce?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING doc
  • I am making a pull request against the develop branch (left side). Also you should start your branch off our develop.
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works

raise ValueError(
"please specify a valid covariance matrix. Supported options are: 'identity', 'inverse_variance', "
"or directly a numpy array."
)
Copy link
Contributor

Choose a reason for hiding this comment

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

at this point it is probably missing a check on the type of covariance_mat? Below we assume that if covariance_mat is not a str, then it is a NDArray, but this is not enforced anywhere. On one hand, this follows the Python philosophy "we are all consenting adults" and the user is responsible of what he's doing. Perhaps a one-more check is not a bad idea though.

Suggested change
)
)
if not isinstance(covariance_mat, np.ndarray):
raise ValueError(...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you, I added this check

1.0 / np.mean((real_mom_1d[None, :] - ensemble_sim_mom_1d) ** 2, axis=0)
)
else:
cast(self._covariance_mat, NDArray[np.float64])
Copy link
Contributor

@marcofavoritobi marcofavoritobi Dec 12, 2022

Choose a reason for hiding this comment

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

this is ok if the check in the constructor is added. It is slightly-less OK otherwise, but still good enough :)

@AldoGl AldoGl force-pushed the add_basic_weight_matrix_estimator_in_msm branch from ab2696b to 8b60174 Compare December 12, 2022 15:41
# if we were given no covariance matrix, then we'll use a default
# one, and we can't do any further validation (without executing the
# moment_calculator)
if covariance_mat in ("identity", "inverse_variance"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Possible improvement. Instead of this, we could have an Enum class:

class CovarianceMatrixType:
    IDENTITY = "identity"
    INVERSE_VARIANCE = "inverse_variance"

And then here (we should first check it is not a string!):

try:
    covariance_mat = CovarianceMatrixType(covariance_mat)
except ValueError:
    raise ValueError(f"expected one of {list(map(lambda x: x.value, CovarianceMatrixType))}, got {covariance_mat})

Copy link
Contributor Author

@AldoGl AldoGl Dec 12, 2022

Choose a reason for hiding this comment

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

Ok thanks, I implemented this too

@AldoGl AldoGl force-pushed the add_basic_weight_matrix_estimator_in_msm branch from 8b60174 to 2f63037 Compare December 12, 2022 15:45
@AldoGl AldoGl force-pushed the add_basic_weight_matrix_estimator_in_msm branch from 2f63037 to 80c7805 Compare December 12, 2022 16:26
@AldoGl AldoGl force-pushed the add_basic_weight_matrix_estimator_in_msm branch from 7a74765 to 26396ca Compare December 12, 2022 17:39
@AldoGl AldoGl merged commit b040e22 into main Dec 13, 2022
@AldoGl AldoGl deleted the add_basic_weight_matrix_estimator_in_msm branch December 13, 2022 13:01
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