From 03a00e76421f831539a804d46007c04974be08b8 Mon Sep 17 00:00:00 2001 From: Kodibarba Date: Mon, 27 Nov 2023 13:08:39 +1100 Subject: [PATCH 1/4] Update python-package-conda.yml --- .github/workflows/python-package-conda.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml index 22f2deb..98a86f7 100644 --- a/.github/workflows/python-package-conda.yml +++ b/.github/workflows/python-package-conda.yml @@ -28,7 +28,7 @@ jobs: uses: microsoft/setup-msbuild@v1.0.2 - name: Conda build' env: - ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }} + ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }} shell: bash -l {0} run: | conda install -c conda-forge conda-build anaconda-client -y @@ -36,21 +36,21 @@ jobs: conda install anaconda-client -y - name: upload windows env: - ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }} + ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }} if: matrix.os == 'windows-latest' shell: bash -l {0} run: | anaconda upload --label main conda/win-64/*.tar.bz2 - name: upload linux env: - ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }} + ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }} if: matrix.os == 'ubuntu-latest' shell: bash -l {0} run: | anaconda upload --label main conda/linux-64/*.tar.bz2 - name: upload macosx env: - ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }} + ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_TOKEN }} if: matrix.os == 'macos-latest' shell: bash -l {0} run: | From 5b61214304282201104fa19fc865210e9558e142 Mon Sep 17 00:00:00 2001 From: Kodibarba Date: Wed, 29 Nov 2023 14:08:52 +1100 Subject: [PATCH 2/4] added garbage collection to improve memory handling. the optimisation gets slow after many iterations --- FoldOptLib/optimisers/axial_surface_optimiser.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/FoldOptLib/optimisers/axial_surface_optimiser.py b/FoldOptLib/optimisers/axial_surface_optimiser.py index ed9c5d9..2a4006f 100644 --- a/FoldOptLib/optimisers/axial_surface_optimiser.py +++ b/FoldOptLib/optimisers/axial_surface_optimiser.py @@ -1,4 +1,5 @@ from abc import ABC +import gc from typing import Dict, Any, Optional, Union, Tuple import numpy as np import pandas as pd @@ -166,6 +167,9 @@ def loglikelihood(self, x, predicted_foliation: np.ndarray, # Calculate the loglikelihood of the axial surface loglikelihood = loglikelihood_axial_surface(angle_difference) + geological_knowledge(x) + del angle_difference + gc.collect() + return loglikelihood def mle_optimisation(self, strike_dip: Tuple[float, float]): @@ -193,6 +197,10 @@ def mle_optimisation(self, strike_dip: Tuple[float, float]): predicted_foliation = self.fold_engine.get_predicted_foliation(axial_normal) logpdf = self.loglikelihood(axial_normal, predicted_foliation, self.geo_objective) + + del predicted_foliation, axial_normal + gc.collect() + return logpdf def angle_optimisation(self, strike_dip: Tuple[float, float]): @@ -219,6 +227,10 @@ def angle_optimisation(self, strike_dip: Tuple[float, float]): axial_normal /= np.linalg.norm(axial_normal) predicted_foliation = self.fold_engine.get_predicted_foliation(axial_normal) angle_difference = is_axial_plane_compatible(predicted_foliation, self.gradient_data) + + del predicted_foliation, axial_normal + gc.collect() + return angle_difference def setup_optimisation(self, geological_knowledge: Optional[Dict[str, Any]] = None): From 59f71d5cd3f1ea7186bf41c3df7c809769795265 Mon Sep 17 00:00:00 2001 From: Kodibarba Date: Wed, 6 Dec 2023 09:53:39 +1100 Subject: [PATCH 3/4] Update geological_knowledge.py --- FoldOptLib/objective_functions/geological_knowledge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FoldOptLib/objective_functions/geological_knowledge.py b/FoldOptLib/objective_functions/geological_knowledge.py index ac82453..c51eda0 100644 --- a/FoldOptLib/objective_functions/geological_knowledge.py +++ b/FoldOptLib/objective_functions/geological_knowledge.py @@ -51,7 +51,7 @@ def __init__(self, constraints: Dict[str, float]): 'fold_axis_wavelength': {'lb':10, 'ub':10, 'mu':10, 'sigma':10, 'w':10}, }, 'fold_axial_surface': { - 'axial_surface': {'lb':10, 'ub':10, 'mu':10, 'kappa':10, 'w':10} + 'axial_surface': {'lb':10, 'ub':10, 'mu':[0.,1.,0.], 'kappa':10, 'w':10} } } lb and ub are the lower and the upper bounds of the constraints and are used only for a restricted From a7f3a93c35934b41932f73b191f40318996c2a36 Mon Sep 17 00:00:00 2001 From: Kodibarba Date: Fri, 8 Dec 2023 10:10:15 +1100 Subject: [PATCH 4/4] fix: use bounding box instead of a grid --- FoldOptLib/examples/misc_functions.py | 41 ++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/FoldOptLib/examples/misc_functions.py b/FoldOptLib/examples/misc_functions.py index 01f61af..60cf35c 100644 --- a/FoldOptLib/examples/misc_functions.py +++ b/FoldOptLib/examples/misc_functions.py @@ -1,16 +1,43 @@ import numpy as np -def sample_random_dataset(grid, sample_size=2, seed=180): +def sample_random_dataset(bounding_box, sample_size=2, seed=180): + """ + Generate a random dataset of 3D coordinates within a specified model bounding box. + + Parameters + ---------- + bounding_box : ndarray + A 3x3 array where each row represents the minimum and maximum values of x and y coordinates. + sample_size : int, optional + The number of random samples to generate. Default is 2. + seed : int, optional + The seed for the random number generator for reproducibility. Default is 180. + + Returns + ------- + random_xyz : ndarray + A sample_size x 3 array of random 3D coordinates within the specified bounding box. + """ + # Set the seed for the random number generator for reproducible results np.random.seed(seed) - # select all xy points with z = 0 - xyz = grid[grid[:, 2] == 0] - xmax = xyz[:, 0].max() - ymax = xyz[:, 1].max() + + # Extract the maximum x and y coordinates from the bounding box + xmax, ymax = bounding_box[1, 0], bounding_box[1, 1] + + # Define the maximum z coordinate (fixed at 0 to only sample model's surface) zmax = 0. - xn = np.random.uniform(low=0, high=xmax, size=sample_size) - yn = np.random.uniform(low=0, high=ymax, size=sample_size) + + # Generate 'sample_size' number of random x-coordinates + xn = np.random.uniform(low=bounding_box[0, 0], high=xmax, size=sample_size) + + # Generate 'sample_size' number of random y-coordinates + yn = np.random.uniform(low=bounding_box[0, 1], high=ymax, size=sample_size) + + # Create an array of z-coordinates, all set to 'zmax' (fixed z-coordinate for all points) zn = np.tile(zmax, sample_size) + + # Combine the x, y, and z coordinates into a single 2D array (shape: sample_size x 3) random_xyz = np.array([xn, yn, zn]).T return random_xyz