Skip to content

Commit

Permalink
golden optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
tjlane committed Oct 26, 2024
1 parent c5bbece commit 5641960
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 23 deletions.
13 changes: 2 additions & 11 deletions meteor/scripts/compute_difference_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
log = structlog.get_logger()


# TO OPTMIZE
TV_WEIGHTS_TO_SCAN = np.linspace(0.0, 0.1, 101)


class TvDiffmapArgParser(DiffmapArgParser):
def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -153,16 +149,11 @@ def denoise_diffmap_according_to_mode(
"""
if tv_denoise_mode == WeightMode.optimize:
log.info(
"Searching for max-negentropy TV denoising weight",
min=np.min(TV_WEIGHTS_TO_SCAN),
max=np.max(TV_WEIGHTS_TO_SCAN),
points_to_test=len(TV_WEIGHTS_TO_SCAN),
"Searching for max-negentropy TV denoising weight", method="golden ration optimization"
)
log.info("This may take some time...")

final_map, metadata = tv_denoise_difference_map(
diffmap, full_output=True, weights_to_scan=TV_WEIGHTS_TO_SCAN
)
final_map, metadata = tv_denoise_difference_map(diffmap, full_output=True)

log.info(
"Optimal TV weight found",
Expand Down
4 changes: 2 additions & 2 deletions meteor/settings.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from __future__ import annotations

TV_WEIGHT_RANGE: tuple[float, float] = (0.0, 1.0)
TV_WEIGHT_RANGE: tuple[float, float] = (0.0, 0.05) # for golden optimization
TV_STOP_TOLERANCE: float = 0.00000005
TV_MAX_NUM_ITER: int = 50
MAP_SAMPLING: int = 3

KWEIGHT_PARAMETER_DEFAULT: float = 0.05
TV_WEIGHT_DEFAULT: float = 0.01 # TO OPTIMIZE
TV_WEIGHT_DEFAULT: float = 0.01

COMPUTED_MAP_RESOLUTION_LIMIT: float = 1.0
GEMMI_HIGH_RESOLUTION_BUFFER: float = 1e-6
4 changes: 0 additions & 4 deletions test/functional/test_compute_difference_map.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pathlib import Path
from unittest import mock

import numpy as np
import pytest
Expand All @@ -11,10 +10,7 @@
from meteor.tv import TvDenoiseResult
from meteor.utils import filter_common_indices

TV_WEIGHTS_TO_SCAN = np.array([0.005, 0.01, 0.025, 0.5])


@mock.patch("meteor.scripts.compute_difference_map.TV_WEIGHTS_TO_SCAN", TV_WEIGHTS_TO_SCAN)
@pytest.mark.parametrize("kweight_mode", list(WeightMode))
@pytest.mark.parametrize("tv_weight_mode", list(WeightMode))
def test_script_produces_consistent_results(
Expand Down
8 changes: 2 additions & 6 deletions test/unit/scripts/test_compute_difference_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import Any
from unittest import mock

import numpy as np
import pytest

from meteor.rsmap import Map
Expand All @@ -18,10 +17,6 @@
)
from meteor.tv import TvDenoiseResult

# ensure tests complete quickly by monkey-patching a limited number of weights
compute_difference_map.TV_WEIGHTS_TO_SCAN = np.linspace(0.0, 0.1, 6)


TV_WEIGHT = 0.1


Expand Down Expand Up @@ -80,7 +75,8 @@ def test_denoise_diffmap_according_to_mode(mode: WeightMode, random_difference_m
assert isinstance(metadata, TvDenoiseResult)

if mode == WeightMode.optimize:
assert metadata.optimal_weight in [0.04, 0.06] # random test; alternates
# random test; changes
assert 0.04 < metadata.optimal_weight < 0.06

elif mode == WeightMode.fixed:
assert metadata.optimal_weight == TV_WEIGHT
Expand Down

0 comments on commit 5641960

Please sign in to comment.