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

AutoProf fails to fit isophotes of face-on galaxies #8

Open
hgao-astro opened this issue Sep 1, 2023 · 5 comments
Open

AutoProf fails to fit isophotes of face-on galaxies #8

hgao-astro opened this issue Sep 1, 2023 · 5 comments

Comments

@hgao-astro
Copy link
Contributor

hgao-astro commented Sep 1, 2023

The optimization of isophotal ellipticity fails when the initialized ellipticity is close to 0 or 1. Because the perturbation was done after converting the ellipticity to another parameter space of $[-\infty, +\infty]$ using _inv_x_to_eps and then scaling back using _x_to_eps. The functional form makes any finite perturbation at $\epsilon \rightarrow 0$ and $\epsilon \rightarrow 1$ (corresponds to $-\infty$ and $+\infty$ in the perturbed parameter space) negligible. Since there are few galaxies with global ellipticity close to 1, the problem mostly affects nearly face-on galaxies.

perturbations[-1][i]["ellip"] = _x_to_eps(
_inv_x_to_eps(perturbations[-1][i]["ellip"])
+ np.random.normal(loc=0, scale=perturb_scale)
)

I assume that the purpose of such scaling is to do optimization in a continuous parameter space. However, since the perturbation was done in a Monte-Carlo manner, I presume that it is not critical to do such scaling. I try directly perturbing the ellipticity and when it hits its parameter boundary I simply reflect it against the boundary.

tmp_eps = perturbations[-1][i]["ellip"] + np.random.normal(
    loc=0, scale=perturb_scale
)
if tmp_eps < 0:
    tmp_eps = -tmp_eps % 1
    # tmp_eps = 0
elif tmp_eps > 1:
    tmp_eps = 1 - tmp_eps % 1
    # tmp_eps = 1
perturbations[-1][i]["ellip"] = tmp_eps

This temporary solution seems working. Let me know if you have other ideas. I would be happy to initiate a pull request when ready. Below I show a failed example and a successful fit using the new code above.

fit_ellipse_shalo_099-7_v1_HSC_I_fail
fit_ellipse_shalo_099-7_v1_HSC_I_success

@hgao-astro
Copy link
Contributor Author

btw, during initialization, the optimization of global ellipticity also involves _inv_x_to_eps and _x_to_eps.

res = minimize(
lambda e, d, r, p, c, n, msk: sum(
list(
_fitEllip_loss(_x_to_eps(e[0]), d, r * m, p, c, n, msk)
for m in np.linspace(0.8, 1.2, 5)
)
),
x0=_inv_x_to_eps(ellip),
args=(
dat,
circ_ellipse_radii[-2],
phase,
results["center"],
results["background noise"],
mask,
),
method="Nelder-Mead",
options={
"initial_simplex": [
[_inv_x_to_eps(ellip) - 1 / 15],
[_inv_x_to_eps(ellip) + 1 / 15],
]
},
)

I have no evidence this will cause an issue. Please weigh in on this. Thanks!

@ConnorStoneAstro
Copy link
Member

Hi @hgao-astro,

Wow, this is great work! To me this seems clearly better for face-on galaxies. My only concern is for edge-on systems with ellip close to 1. In that case the shape becomes very sensitive to small changes in the ellipticity and so part of the remapping of _x_to_eps was to effectively decrease the step size near edge-on. Perhaps we could get the best of both worlds by adding an if statement which does the _x_to_eps scheme when ellip > 0.5 and doing your reflection scheme when ellip < 0.5. Both method are basically equivalent around ellip = 0.5 so it should be a pretty smooth transition. What do you think about that?

I agree for the initialization it is fine to just keep it since its more the optimization that encounters the issue.

@hgao-astro
Copy link
Contributor Author

Thanks for the prompt reply. Let me give it a try and see if it works as expected. btw, I forgot to mention that I used a perturbation scale = 0.1 to achieve successful face-on fits, and have not yet evaluated the impact on computation time.

@hgao-astro
Copy link
Contributor Author

Thanks for your patience. I have been occupied by job searching these days. I will try to get to it in Jan. 2024.

@ConnorStoneAstro
Copy link
Member

@hgao-astro Good luck with your job search! I look forward to hearing from you in the new year!

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

No branches or pull requests

2 participants