Skip to content

Conditional random fields - #3

Open
bramvandeneijnden wants to merge 13 commits into
mainfrom
CPT_conditioning
Open

Conditional random fields#3
bramvandeneijnden wants to merge 13 commits into
mainfrom
CPT_conditioning

Conversation

@bramvandeneijnden

Copy link
Copy Markdown

extension of random field generator with random field conditioning.

Uses sklear as additional requirement for efficient kriging, which is not available efficiently enough in gstools.

new file:   random_fields/generate_conditioned_field.py
modified:   random_fields/generate_conditioned_field.py
 Changes to be committed:
	modified:   ../README.md
	new file:   Makefile
	renamed:    static/random_field.png -> _static/random_field.png
	new file:   _static/random_field_1.png
	new file:   _static/random_field_2.png
	new file:   _static/random_field_3.png
	renamed:    static/random_field_3D.png -> _static/random_field_3D.png
	new file:   authors.rst
	new file:   conf.py
	new file:   contributions.rst
	new file:   index.rst
	new file:   installation.rst
	new file:   make.bat
	new file:   requirements.txt
	new file:   theory.rst
	new file:   tutorials.rst
	modified:   ../random_fields/generate_conditioned_field.py
	modified:   ../random_fields/generate_field.py
	modified:   ../random_fields/utils.py
Changes committed:
	new file:   _static/conditioned_random_field_3D.png
	new file:   _static/kriging_mean_2D.png
	new file:   _static/kriging_mean_3D.png
	new file:   _static/kriging_std_2D.png
	new file:   _static/kriging_std_3D.png
	new file:   _static/random_field_4.png
	new file:   _static/random_field_5.png
	modified:   index.rst
	modified:   tutorials.rst
	modified:   ../random_fields/utils.py
Changes to be committed:
	modified:   tutorials.rst
	modified:   ../requirements.txt

@aronnoordam aronnoordam left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

few comments about style and some stuff what is unclear for me.

Furthermore can you add tests for the added functionalities?

Comment thread docs/contributions.rst Outdated
Comment on lines +74 to +98
def create_solver_settings_dictionary(self, model: Model, mesh_file_name: str, materials_file_name: str) -> Dict[str, Any]:
"""
Creates a dictionary containing the solver settings.

Args:
- model (:class:`random_fields.model.Model`): The model object containing the solver data and model parts.
- mesh_file_name (str): The name of the mesh file.
- materials_file_name (str): The name of the materials parameters json file.

Raises:
- ValueError: if solver_settings in model are not initialised.

Returns:
- Dict[str, Any]: dictionary containing the part of the project parameters
dictionary related to problem data and solver settings.
"""

if model.project_parameters is None:
raise ValueError("Solver settings are not initialised in model.")

return self.solver_io.create_settings_dictionary(
model.project_parameters,
Path(mesh_file_name).stem,
materials_file_name,
model.get_all_model_parts(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this function and the class above do not exists within the RF repos, can you replace it with an existing function?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

updated with existing function

Comment thread docs/installation.rst
Comment thread requirements.txt Outdated
numpy==1.24.2
gstools==1.5.0
matplotlib>=3.7.0
sklearn

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

missing version, also sklearn is deprecated, i think it should be scikit-learn

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

also the dependency should be added to requirements_dev.txt

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

scikit-learn corrected ==1.5.1

I tried to set matplotlib version to the one used in the STEM package (3.7.4), but this breaks one of the tests on the plotting utils...

Comment thread setup.cfg
Comment thread docs/installation.rst Outdated
Comment thread random_fields/generate_field.py Outdated
self.kriging_std = None


def generate_conditioned(self, nodes: np.ndarray) -> None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def generate_conditioned(self, nodes: np.ndarray) -> None:
def generate_conditioned(self, nodes: npt.NDArray[np.float64]) -> None:

@bramvandeneijnden bramvandeneijnden Aug 23, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

corrected, but hot to properly document arrays in the docstrings? see my attempt in the docstrings

Comment thread random_fields/generate_field.py Outdated
Comment thread random_fields/generate_field.py Outdated
self.kriging_mean = self.mean + np.sqrt(self.variance) * z_kriged_field
#
# create single random field at nodes and conditioning points
nodes_cpoints = np.vstack([nodes,self.conditioning_points])

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

can you write out the variable names a bit more, e.g. nodes_cond_points. Also for example z_cond_rf_nodes instead of z_crf_nodes. This makes the code a bit more understandable

Comment thread random_fields/generate_field.py Outdated
Comment thread random_fields/generate_field.py Outdated
bramvandeneijnden and others added 3 commits August 15, 2024 16:32
Co-authored-by: aronnoordam <51492202+aronnoordam@users.noreply.github.com>
Co-authored-by: aronnoordam <51492202+aronnoordam@users.noreply.github.com>
	modified:   docs/contributions.rst
	modified:   docs/installation.rst
	modified:   random_fields/generate_field.py
	modified:   random_fields/utils.py
	modified:   requirements_dev.txt
	new file:   tests/data/kriging_mean_3D.txt
	new file:   tests/data/kriging_std_3D.txt
	modified:   tests/test_random_field.py
Comment thread random_fields/generate_field.py Outdated
Comment thread tests/test_random_field.py Outdated
Comment thread tests/test_random_field.py Outdated
- style changes
- update docstrings
- extended test

        modified:   docs/contributions.rst
	modified:   random_fields/generate_field.py
	modified:   random_fields/utils.py
	modified:   requirements.txt
	modified:   requirements_dev.txt
	new file:   tests/data/conditioned_rf_3D.txt
	deleted:    tests/data/kriging_mean_3D.txt
	deleted:    tests/data/kriging_std_3D.txt
	modified:   tests/test_random_field.py
	modified:   requirements_dev.txt
- z_kriged_field (array): standard-normal kriged random field
- gaussian_process (:class:sklearn.gaussian_process.GaussianProcessRegressor)
- conditioning_points (array): coordinates of the conditioning points, shape (:,`self.n_dims`)
- conditioning_values (array): values of the conditioning points, shape (:,)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

How to document arrays in the doc strings? I've seen "Sequence(float)" here and there...

and what about shapes and defaults?

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.

3 participants