Skip to content

feature/csv error columns#1127

Merged
Jammy2211 merged 30 commits intomainfrom
feature/csv_error_columns
Apr 9, 2025
Merged

feature/csv error columns#1127
Jammy2211 merged 30 commits intomainfrom
feature/csv_error_columns

Conversation

@rhayes777
Copy link
Copy Markdown
Collaborator

Resolves #1087

New usage:

aggregate_csv.add_variable(
    "galaxies.lens.bulge.centre.centre_0",
    value_types=[ValueType.Median, ValueType.ValueAt1Sigma],
)

Median is included by default

@Jammy2211
Copy link
Copy Markdown
Collaborator

I ran the example here and most functionality works:

https://github.com/Jammy2211/autogalaxy_workspace/blob/main/scripts/results/workflow/csv_make.py

However, the values_at_sigma_1 (and I think the values_at_sigma_3 are incorrect in samples_summary.json.

For example, I make the following .csv file:

"""
__Errors__

We can also output PDF values at a given sigma confidence of each parameter to the .csv file, using 
the `use_values_at_sigma` input and specifying the sigma confidence.

Below, we add the values at 3.0 sigma confidence to the .csv file, in order to compute the errors you would 
subtract the median value from these values.

The method below adds two columns to the .csv file, corresponding to the values at the lower and upper sigma values.
"""
agg_csv = af.AggregateCSV(aggregator=agg)

agg_csv.add_variable(
    argument="galaxies.galaxy.bulge.effective_radius",
    name="bulge_effective_radius_sigma",
    value_types=[af.ValueType.Median, af.ValueType.ValuesAt3Sigma]
)

agg_csv.save(path=workflow_path / "csv_simple_errors.csv")

The .csv file is:

id,bulge_effective_radius_sigma,bulge_effective_radius_sigma_lower_1_sigma,bulge_effective_radius_sigma_upper_1_sigma
441ad79fb6081c6f9ee07d3fff9eb838,1.4477396552296486,0.0003599749979079485,0.0015501703932636415
ab8a6e5d61cf0a5644e34235161bb658,1.4070892640122448,-0.002349170789082214,-0.0010475369447976472

The values for bulge_effective_radius_sigma_lower_1_sigma,bulge_effective_radius_sigma_upper_1_sigma are tiny, 0.001, when they should be much larger, heres one example of them from model.results:

            effective_radius                                                    1.6688 (1.6329, 1.7025)

The values in the .csv file are in the samples_summary.json, so the problem is how the values are being output theres as opposed to AggregateCSV itself.

@Jammy2211
Copy link
Copy Markdown
Collaborator

I have confirmed that the correct values are in samples_summary.json, but that it is simply associating the wrong parameter to that value.

This implies that the order of the values in the samples_summary.json file (which are stored in a list) is not consistent with the model in some way.

@rhayes777
Copy link
Copy Markdown
Collaborator Author

I have confirmed that the correct values are in samples_summary.json, but that it is simply associating the wrong parameter to that value.

This implies that the order of the values in the samples_summary.json file (which are stored in a list) is not consistent with the model in some way.

Ah that's not good. This is why we need a dict really

@Jammy2211
Copy link
Copy Markdown
Collaborator

Is there a reason why getting the dict thats in samples_summary.json in this format for the errors is diffcult, given we already have it for the median_pdf?

    "median_pdf_sample": {
            "type": "instance",
            "class_path": "autofit.non_linear.samples.sample.Sample",
            "arguments": {
                "log_likelihood": -3761.9537991206726,
                "log_prior": 0.3401980233075243,
                "weight": 1.0,
                "kwargs": {
                    "type": "dict",
                    "arguments": {
                        "galaxies.galaxy.bulge.ell_comps.ell_comps_0": 0.10795954960076128,
                        "galaxies.galaxy.bulge.ell_comps.ell_comps_1": 0.07779982311130317,
                        "galaxies.galaxy.bulge.effective_radius": 2.38834396240422,
                        "galaxies.galaxy.bulge.sersic_index": 3.59010139964543,
                        "galaxies.galaxy.disk.centre.centre_0": 0.0454336546817012,
                        "galaxies.galaxy.disk.centre.centre_1": 0.1027471736412032,
                        "galaxies.galaxy.disk.ell_comps.ell_comps_0": 0.17483925334984612,
                        "galaxies.galaxy.disk.ell_comps.ell_comps_1": 0.018374008497923464,
                        "galaxies.galaxy.disk.effective_radius": 11.85494112289763
                    }
                }
            }
        },

@rhayes777
Copy link
Copy Markdown
Collaborator Author

Is there a reason why getting the dict thats in samples_summary.json in this format for the errors is diffcult, given we already have it for the median_pdf?

    "median_pdf_sample": {
            "type": "instance",
            "class_path": "autofit.non_linear.samples.sample.Sample",
            "arguments": {
                "log_likelihood": -3761.9537991206726,
                "log_prior": 0.3401980233075243,
                "weight": 1.0,
                "kwargs": {
                    "type": "dict",
                    "arguments": {
                        "galaxies.galaxy.bulge.ell_comps.ell_comps_0": 0.10795954960076128,
                        "galaxies.galaxy.bulge.ell_comps.ell_comps_1": 0.07779982311130317,
                        "galaxies.galaxy.bulge.effective_radius": 2.38834396240422,
                        "galaxies.galaxy.bulge.sersic_index": 3.59010139964543,
                        "galaxies.galaxy.disk.centre.centre_0": 0.0454336546817012,
                        "galaxies.galaxy.disk.centre.centre_1": 0.1027471736412032,
                        "galaxies.galaxy.disk.ell_comps.ell_comps_0": 0.17483925334984612,
                        "galaxies.galaxy.disk.ell_comps.ell_comps_1": 0.018374008497923464,
                        "galaxies.galaxy.disk.effective_radius": 11.85494112289763
                    }
                }
            }
        },

It means changing the interface of the Samples classes

@rhayes777
Copy link
Copy Markdown
Collaborator Author

It's weird it definitely looks like things should always be ordered by prior id

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.48%. Comparing base (0eba4c4) to head (71c5859).
Report is 141 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1127      +/-   ##
==========================================
+ Coverage   81.32%   81.48%   +0.16%     
==========================================
  Files         202      207       +5     
  Lines       15611    15893     +282     
==========================================
+ Hits        12695    12951     +256     
- Misses       2916     2942      +26     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Jammy2211 Jammy2211 merged commit df37c5e into main Apr 9, 2025
4 checks passed
@Jammy2211 Jammy2211 deleted the feature/csv_error_columns branch June 24, 2025 13:49
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.

Aggregator for csv building

2 participants