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

WIP: Brute force method to find the optimal number of harmonics for WaveX, DMWaveX, and CMWaveX #1822

Closed
wants to merge 43 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5cbd67d
add cmwavex
abhisrkckl Jul 11, 2024
e9b0d35
init
abhisrkckl Jul 11, 2024
557ab55
test_dmwavex
abhisrkckl Jul 11, 2024
fd87992
cmwavex_setup
abhisrkckl Jul 11, 2024
86a83b9
test_cmwavex
abhisrkckl Jul 11, 2024
19c3521
CHANGELOG
abhisrkckl Jul 11, 2024
5ddf707
validation for correlated noise components
abhisrkckl Jul 11, 2024
75a5cf5
changelog#
abhisrkckl Jul 11, 2024
9c97955
sourcery
abhisrkckl Jul 11, 2024
38f3b30
Merge branch 'chromatic' into cmwavex
abhisrkckl Jul 11, 2024
30c8f4b
validation
abhisrkckl Jul 11, 2024
a826cde
Merge branch 'master' into cmwavex
abhisrkckl Jul 11, 2024
b841455
Merge branch 'master' into cmwavex
abhisrkckl Jul 12, 2024
236cf25
Merge branch 'master' into cmwavex
abhisrkckl Jul 22, 2024
74fe0dd
Merge branch 'nanograv:master' into cmwavex
abhisrkckl Jul 23, 2024
8bcdb83
Merge branch 'nanograv:master' into cmwavex
abhisrkckl Aug 1, 2024
4bdbc65
Merge branch 'nanograv:master' into cmwavex
abhisrkckl Aug 7, 2024
fa6a9d6
--
abhisrkckl Aug 7, 2024
4b931c3
plchromnoise_from_cmwavex
abhisrkckl Aug 7, 2024
b39395a
tests
abhisrkckl Aug 7, 2024
e5f6783
CHANGELOG
abhisrkckl Aug 7, 2024
e9e1771
float
abhisrkckl Aug 8, 2024
5492daf
Merge branch 'master' into cmwavex
abhisrkckl Aug 8, 2024
27c7c4e
move functions
abhisrkckl Aug 8, 2024
d1dfcf8
CHANGELOG
abhisrkckl Aug 9, 2024
fa95894
find_optimal_nharms
abhisrkckl Aug 9, 2024
f51474d
move function
abhisrkckl Aug 9, 2024
b66d989
fix test
abhisrkckl Aug 9, 2024
b64d743
test_prepare_model_for_find_optimal_nharms
abhisrkckl Aug 9, 2024
37877a4
refactor
abhisrkckl Aug 9, 2024
a47b4f2
fix epochs
abhisrkckl Aug 9, 2024
03f0de6
test_noise_analysis
abhisrkckl Aug 9, 2024
829a5ba
don't subtract aic_min
abhisrkckl Aug 9, 2024
5fbdc5f
parallel
abhisrkckl Aug 9, 2024
e9ae79e
Merge branch 'master' into opt-nharm
abhisrkckl Aug 11, 2024
6402740
black
abhisrkckl Aug 11, 2024
6690d91
Merge branch 'master' into cmwavex
abhisrkckl Aug 11, 2024
524fc8f
setup.cfg
abhisrkckl Aug 11, 2024
1dde7d6
float
abhisrkckl Aug 12, 2024
354d18b
Merge branch 'cmwavex' into opt-nharm
abhisrkckl Aug 12, 2024
95702e2
wavex_setup
abhisrkckl Aug 12, 2024
2a5321d
tests
abhisrkckl Aug 12, 2024
ddac595
Merge branch 'master' into opt-nharm
abhisrkckl Aug 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
parallel
abhisrkckl committed Aug 9, 2024
commit 5fbdc5f3a019e3dcb607130fd4ad540b52ceb0b2
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -10,3 +10,4 @@ uncertainties
loguru
nestle>=0.2.0
numdifftools
joblib
96 changes: 56 additions & 40 deletions src/pint/noise_analysis.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from copy import deepcopy
from typing import List, Tuple
from typing import List, Optional, Tuple
from itertools import product as cartesian_product

from joblib import Parallel, cpu_count, delayed
import numpy as np
from astropy import units as u
from scipy.optimize import minimize
@@ -14,10 +15,10 @@
from pint.models.phase_offset import PhaseOffset
from pint.models.timing_model import TimingModel
from pint.models.wavex import wavex_setup
from pint.polycos import tqdm
from pint.toa import TOAs
from pint.utils import (
akaike_information_criterion,
)
from pint.utils import akaike_information_criterion
from pint.logging import setup as setup_log


def _get_wx2pl_lnlike(
@@ -269,6 +270,7 @@ def find_optimal_nharms(
include_components: List[str] = ["WaveX", "DMWaveX", "CMWaveX"],
nharms_max: int = 45,
chromatic_index: float = 4,
num_parallel_jobs: Optional[int] = None,
):
assert len(set(include_components).intersection(set(model.components.keys()))) == 0

@@ -278,9 +280,17 @@ def find_optimal_nharms(
)
)

aics = np.zeros(np.repeat(nharms_max, len(include_components)))
for ii in idxs:
aics[ii] = compute_aic(model, toas, include_components, ii, chromatic_index)
if num_parallel_jobs is None:
num_parallel_jobs = cpu_count()

aics_flat = Parallel(n_jobs=num_parallel_jobs)(
delayed(
lambda ii: compute_aic(model, toas, include_components, ii, chromatic_index)
)(ii)
for ii in idxs
)

aics = np.reshape(aics_flat, [nharms_max + 1] * len(include_components))

assert all(np.isfinite(aics)), "Infs/NaNs found in AICs!"

@@ -294,6 +304,8 @@ def compute_aic(
ii: np.ndarray,
chromatic_index: float,
):
setup_log(level="WARNING")

model1 = prepare_model(
model, toas.get_Tspan(), include_components, ii, chromatic_index
)
@@ -331,48 +343,52 @@ def prepare_model(
if nharms_wx > 0:
wavex_setup(model1, Tspan, n_freqs=nharms_wx, freeze_params=False)
elif comp == "DMWaveX":
if "DispersionDM" not in model1.components:
model1.add_component(DispersionDM())
nharms_dwx = nharms[jj]
if nharms_dwx > 0:
if "DispersionDM" not in model1.components:
model1.add_component(DispersionDM())

model1["DM"].frozen = False
model1["DM"].frozen = False

if model1["DM1"].quantity is None:
model1["DM1"].quantity = 0 * model1["DM1"].units
model1["DM1"].frozen = False
if model1["DM1"].quantity is None:
model1["DM1"].quantity = 0 * model1["DM1"].units
model1["DM1"].frozen = False

if "DM2" not in model1.params:
model1.components["DispersionDM"].add_param(model["DM1"].new_param(2))
if model1["DM2"].quantity is None:
model1["DM2"].quantity = 0 * model1["DM2"].units
model1["DM2"].frozen = False
if "DM2" not in model1.params:
model1.components["DispersionDM"].add_param(
model["DM1"].new_param(2)
)
if model1["DM2"].quantity is None:
model1["DM2"].quantity = 0 * model1["DM2"].units
model1["DM2"].frozen = False

if model1["DMEPOCH"].quantity is None:
model1["DMEPOCH"].quantity = model1["PEPOCH"].quantity
if model1["DMEPOCH"].quantity is None:
model1["DMEPOCH"].quantity = model1["PEPOCH"].quantity

nharms_dwx = nharms[jj]
if nharms_dwx > 0:
dmwavex_setup(model1, Tspan, n_freqs=nharms_dwx, freeze_params=False)
elif comp == "CMWaveX":
if "ChromaticCM" not in model1.components:
model1.add_component(ChromaticCM())
model1["TNCHROMIDX"].value = chromatic_index

model1["CM"].frozen = False
if model1["CM1"].quantity is None:
model1["CM1"].quantity = 0 * model1["CM1"].units
model1["CM1"].frozen = False

if "CM2" not in model1.params:
model1.components["ChromaticCM"].add_param(model1["CM1"].new_param(2))
if model1["CM2"].quantity is None:
model1["CM2"].quantity = 0 * model1["CM2"].units
model1["CM2"].frozen = False

if model1["CMEPOCH"].quantity is None:
model1["CMEPOCH"].quantity = model1["PEPOCH"].quantity

nharms_cwx = nharms[jj]
if nharms_cwx > 0:
if "ChromaticCM" not in model1.components:
model1.add_component(ChromaticCM())
model1["TNCHROMIDX"].value = chromatic_index

model1["CM"].frozen = False
if model1["CM1"].quantity is None:
model1["CM1"].quantity = 0 * model1["CM1"].units
model1["CM1"].frozen = False

if "CM2" not in model1.params:
model1.components["ChromaticCM"].add_param(
model1["CM1"].new_param(2)
)
if model1["CM2"].quantity is None:
model1["CM2"].quantity = 0 * model1["CM2"].units
model1["CM2"].frozen = False

if model1["CMEPOCH"].quantity is None:
model1["CMEPOCH"].quantity = model1["PEPOCH"].quantity

cmwavex_setup(model1, Tspan, n_freqs=nharms_cwx, freeze_params=False)
else:
raise ValueError(f"Unsupported component {comp}.")