diff --git a/notebooks/dataset_1d/advanced/database/examples/models.ipynb b/notebooks/dataset_1d/advanced/database/examples/models.ipynb index 85c3855..5b0b1ab 100644 --- a/notebooks/dataset_1d/advanced/database/examples/models.ipynb +++ b/notebooks/dataset_1d/advanced/database/examples/models.ipynb @@ -103,7 +103,12 @@ "tutorial.\n", "\n", "We get a CTI generator via the `ac.agg.CTIAgg` object, where this `cti_gen` contains the maximum log\n", - "likelihood `CTI `object of every model-fit." + "likelihood `CTI` model of every model-fit.\n", + "\n", + "Each fit in this database fitted several 1D datasets at once (one per charge injection level) with a\n", + "`FactorGraphModel`, so for each fit the generator gives a list with one `CTI` object per dataset. The CTI model\n", + "is shared across the datasets, so every entry is the same model and we use the first, `[0]`. (A fit to a single\n", + "dataset gives one `CTI` object instead of a list.)" ] }, { @@ -120,15 +125,15 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We can now iterate over our `CTI `object generator to make the plots we desire." + "We can now iterate over our `CTI` object generator to make the plots we desire." ] }, { "cell_type": "code", "metadata": {}, "source": [ - "for cti in cti_gen:\n", - " print(cti)" + "for cti_list in cti_gen:\n", + " print(cti_list[0])" ], "outputs": [], "execution_count": null @@ -151,8 +156,8 @@ "\n", "print(\"Maximum Log Likelihood Spurious Ellipticity:\")\n", "\n", - "for cti in cti_gen:\n", - " delta_ellipticity = cti.delta_ellipticity\n", + "for cti_list in cti_gen:\n", + " delta_ellipticity = cti_list[0].delta_ellipticity\n", "\n", " print(\"Delta Ellipticity = \", delta_ellipticity)" ], @@ -204,8 +209,8 @@ "for cti_gen, weight_gen in zip(cti_list_gen, weight_list_gen):\n", " delta_ellipticity_list = []\n", "\n", - " for cti in cti_gen:\n", - " delta_ellipticity = cti.delta_ellipticity\n", + " for cti_list in cti_gen:\n", + " delta_ellipticity = cti_list[0].delta_ellipticity\n", "\n", " delta_ellipticity_list.append(delta_ellipticity)\n", "\n", @@ -253,8 +258,8 @@ "for cti_gen in cti_list_gen:\n", " delta_ellipticity_list = []\n", "\n", - " for cti in cti_gen:\n", - " delta_ellipticity = cti.delta_ellipticity\n", + " for cti_list in cti_gen:\n", + " delta_ellipticity = cti_list[0].delta_ellipticity\n", "\n", " delta_ellipticity_list.append(delta_ellipticity)\n", "\n", diff --git a/notebooks/dataset_1d/advanced/database/examples/samples.ipynb b/notebooks/dataset_1d/advanced/database/examples/samples.ipynb index 4023cbe..b2aeea6 100644 --- a/notebooks/dataset_1d/advanced/database/examples/samples.ipynb +++ b/notebooks/dataset_1d/advanced/database/examples/samples.ipynb @@ -354,16 +354,21 @@ "We can use the `Aggregator` to create a list of instances of the model, using the Python class structure of the \n", "model composition.\n", "\n", - "For example, we can return a list of the model instances corresponding to the maximum log likelihood sample." + "For example, we can return a list of the model instances corresponding to the maximum log likelihood sample.\n", + "\n", + "Each fit in this database fitted several 1D datasets at once (one per charge injection level) with a\n", + "`FactorGraphModel`. Its instance therefore holds one entry per dataset, indexed `[0]`, `[1]`, ..., and the CTI\n", + "model of a dataset is that entry's `cti`. The model is shared across the datasets, so every entry carries the same\n", + "CTI model and we use the first, `[0]`." ] }, { "cell_type": "code", "metadata": {}, "source": [ - "print(ml_instances[0].cti)\n", - "print(ml_instances[1].cti)\n", - "print(ml_instances[2].cti)" + "print(ml_instances[0][0].cti)\n", + "print(ml_instances[1][0].cti)\n", + "print(ml_instances[2][0].cti)" ], "outputs": [], "execution_count": null @@ -372,16 +377,16 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "These galaxies will be named according to the model composed and fitted by the search (in this case, only `cti`)." + "The model components are named according to the model composed and fitted by the search (in this case, only `cti`)." ] }, { "cell_type": "code", "metadata": {}, "source": [ - "print(ml_instances[0].cti.trap_list)\n", + "print(ml_instances[0][0].cti.trap_list)\n", "print()\n", - "print(ml_instances[1].cti.ccd)" + "print(ml_instances[1][0].cti.ccd)" ], "outputs": [], "execution_count": null @@ -397,8 +402,8 @@ "cell_type": "code", "metadata": {}, "source": [ - "print(ml_instances[0].cti.trap_list[0].density)\n", - "print(ml_instances[1].cti.ccd.well_fill_power)" + "print(ml_instances[0][0].cti.trap_list[0].density)\n", + "print(ml_instances[1][0].cti.ccd.well_fill_power)" ], "outputs": [], "execution_count": null @@ -426,7 +431,7 @@ "\n", "print(\"Median PDF Model Instances: \\n\")\n", "print(mp_instances, \"\\n\")\n", - "print(mp_instances[0].cti.trap_list[0])\n", + "print(mp_instances[0][0].cti.trap_list[0])\n", "print()" ], "outputs": [], @@ -531,7 +536,7 @@ "for samples in agg.values(\"samples\"):\n", " instance = samples.from_sample_index(sample_index=-1)\n", "\n", - " print(instance.cti.trap_list)" + " print(instance[0].cti.trap_list)" ], "outputs": [], "execution_count": null @@ -857,17 +862,21 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We can keep and remove entire paths of the samples, for example keeping only the parameters of the trap list." + "We can keep and remove entire paths of the samples, for example keeping only the parameters of the trap list.\n", + "\n", + "The paths printed above start with the dataset index (`0`, `1`, ...), because each fit used a `FactorGraphModel`\n", + "with one entry per dataset. Filtering these multi-dataset samples by path does not work yet (a PyAutoFit bug with\n", + "parameters shared across datasets), so this example is switched off until it is fixed." ] }, { "cell_type": "code", "metadata": {}, "source": [ - "samples = list(agg.values(\"samples\"))[0]\n", - "samples = samples.with_paths([\"cti.trap_list\"])\n", - "print(\"Parameters of the first sample of CTI trap list\")\n", - "print(samples.parameter_lists[0])\n" + "# samples = list(agg.values(\"samples\"))[0]\n", + "# samples = samples.with_paths([\"0.cti.trap_list\"])\n", + "# print(\"Parameters of the first sample of CTI trap list\")\n", + "# print(samples.parameter_lists[0])\n" ], "outputs": [], "execution_count": null diff --git a/notebooks/dataset_1d/results/examples/samples.ipynb b/notebooks/dataset_1d/results/examples/samples.ipynb index 26c5db1..6029ee2 100644 --- a/notebooks/dataset_1d/results/examples/samples.ipynb +++ b/notebooks/dataset_1d/results/examples/samples.ipynb @@ -488,19 +488,21 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "They can also be returned at the values of the parameters at their error values." + "The size of each parameter's error can also be returned. These are error sizes, not parameter values, so they\n", + "are returned as lists (`as_instance=False`): as a model instance they could break the model's rules (for example,\n", + "that the release timescales of the trap species are in increasing order)." ] }, { "cell_type": "code", "metadata": {}, "source": [ - "instance_upper_values = samples.errors_at_upper_sigma(sigma=3.0)\n", - "instance_lower_values = samples.errors_at_lower_sigma(sigma=3.0)\n", + "errors_upper_list = samples.errors_at_upper_sigma(sigma=3.0, as_instance=False)\n", + "errors_lower_list = samples.errors_at_lower_sigma(sigma=3.0, as_instance=False)\n", "\n", - "print(\"Errors Instances: \\n\")\n", - "print(instance.cti.trap_list, \"\\n\")\n", - "print(instance.cti.trap_list, \"\\n\")" + "print(\"Errors Lists: \\n\")\n", + "print(errors_upper_list, \"\\n\")\n", + "print(errors_lower_list, \"\\n\")" ], "outputs": [], "execution_count": null diff --git a/scripts/dataset_1d/advanced/database/examples/models.py b/scripts/dataset_1d/advanced/database/examples/models.py index c12ff68..0f3c535 100644 --- a/scripts/dataset_1d/advanced/database/examples/models.py +++ b/scripts/dataset_1d/advanced/database/examples/models.py @@ -38,16 +38,21 @@ tutorial. We get a CTI generator via the `ac.agg.CTIAgg` object, where this `cti_gen` contains the maximum log -likelihood `CTI `object of every model-fit. +likelihood `CTI` model of every model-fit. + +Each fit in this database fitted several 1D datasets at once (one per charge injection level) with a +`FactorGraphModel`, so for each fit the generator gives a list with one `CTI` object per dataset. The CTI model +is shared across the datasets, so every entry is the same model and we use the first, `[0]`. (A fit to a single +dataset gives one `CTI` object instead of a list.) """ cti_agg = ac.agg.CTIAgg(aggregator=agg) cti_gen = cti_agg.max_log_likelihood_gen_from() """ -We can now iterate over our `CTI `object generator to make the plots we desire. +We can now iterate over our `CTI` object generator to make the plots we desire. """ -for cti in cti_gen: - print(cti) +for cti_list in cti_gen: + print(cti_list[0]) """ __CTI Delta Ellipticity Requirement__ @@ -59,8 +64,8 @@ print("Maximum Log Likelihood Spurious Ellipticity:") -for cti in cti_gen: - delta_ellipticity = cti.delta_ellipticity +for cti_list in cti_gen: + delta_ellipticity = cti_list[0].delta_ellipticity print("Delta Ellipticity = ", delta_ellipticity) @@ -101,8 +106,8 @@ for cti_gen, weight_gen in zip(cti_list_gen, weight_list_gen): delta_ellipticity_list = [] - for cti in cti_gen: - delta_ellipticity = cti.delta_ellipticity + for cti_list in cti_gen: + delta_ellipticity = cti_list[0].delta_ellipticity delta_ellipticity_list.append(delta_ellipticity) @@ -139,8 +144,8 @@ for cti_gen in cti_list_gen: delta_ellipticity_list = [] - for cti in cti_gen: - delta_ellipticity = cti.delta_ellipticity + for cti_list in cti_gen: + delta_ellipticity = cti_list[0].delta_ellipticity delta_ellipticity_list.append(delta_ellipticity) diff --git a/scripts/dataset_1d/advanced/database/examples/samples.py b/scripts/dataset_1d/advanced/database/examples/samples.py index 6b38d7a..ade6ca8 100644 --- a/scripts/dataset_1d/advanced/database/examples/samples.py +++ b/scripts/dataset_1d/advanced/database/examples/samples.py @@ -191,23 +191,28 @@ model composition. For example, we can return a list of the model instances corresponding to the maximum log likelihood sample. + +Each fit in this database fitted several 1D datasets at once (one per charge injection level) with a +`FactorGraphModel`. Its instance therefore holds one entry per dataset, indexed `[0]`, `[1]`, ..., and the CTI +model of a dataset is that entry's `cti`. The model is shared across the datasets, so every entry carries the same +CTI model and we use the first, `[0]`. """ -print(ml_instances[0].cti) -print(ml_instances[1].cti) -print(ml_instances[2].cti) +print(ml_instances[0][0].cti) +print(ml_instances[1][0].cti) +print(ml_instances[2][0].cti) """ -These galaxies will be named according to the model composed and fitted by the search (in this case, only `cti`). +The model components are named according to the model composed and fitted by the search (in this case, only `cti`). """ -print(ml_instances[0].cti.trap_list) +print(ml_instances[0][0].cti.trap_list) print() -print(ml_instances[1].cti.ccd) +print(ml_instances[1][0].cti.ccd) """ Their individual parameters can be printed. """ -print(ml_instances[0].cti.trap_list[0].density) -print(ml_instances[1].cti.ccd.well_fill_power) +print(ml_instances[0][0].cti.trap_list[0].density) +print(ml_instances[1][0].cti.ccd.well_fill_power) """ __Posterior / PDF__ @@ -224,7 +229,7 @@ print("Median PDF Model Instances: \n") print(mp_instances, "\n") -print(mp_instances[0].cti.trap_list[0]) +print(mp_instances[0][0].cti.trap_list[0]) print() """ @@ -296,7 +301,7 @@ for samples in agg.values("samples"): instance = samples.from_sample_index(sample_index=-1) - print(instance.cti.trap_list) + print(instance[0].cti.trap_list) """ __Search Plots__ @@ -497,11 +502,15 @@ """ We can keep and remove entire paths of the samples, for example keeping only the parameters of the trap list. + +The paths printed above start with the dataset index (`0`, `1`, ...), because each fit used a `FactorGraphModel` +with one entry per dataset. Filtering these multi-dataset samples by path does not work yet (a PyAutoFit bug with +parameters shared across datasets), so this example is switched off until it is fixed. """ -samples = list(agg.values("samples"))[0] -samples = samples.with_paths(["cti.trap_list"]) -print("Parameters of the first sample of CTI trap list") -print(samples.parameter_lists[0]) +# samples = list(agg.values("samples"))[0] +# samples = samples.with_paths(["0.cti.trap_list"]) +# print("Parameters of the first sample of CTI trap list") +# print(samples.parameter_lists[0]) """ diff --git a/scripts/dataset_1d/results/examples/samples.py b/scripts/dataset_1d/results/examples/samples.py index e003273..a661a4c 100644 --- a/scripts/dataset_1d/results/examples/samples.py +++ b/scripts/dataset_1d/results/examples/samples.py @@ -281,14 +281,16 @@ print(instance_lower_sigma.cti.trap_list, "\n") """ -They can also be returned at the values of the parameters at their error values. +The size of each parameter's error can also be returned. These are error sizes, not parameter values, so they +are returned as lists (`as_instance=False`): as a model instance they could break the model's rules (for example, +that the release timescales of the trap species are in increasing order). """ -instance_upper_values = samples.errors_at_upper_sigma(sigma=3.0) -instance_lower_values = samples.errors_at_lower_sigma(sigma=3.0) +errors_upper_list = samples.errors_at_upper_sigma(sigma=3.0, as_instance=False) +errors_lower_list = samples.errors_at_lower_sigma(sigma=3.0, as_instance=False) -print("Errors Instances: \n") -print(instance.cti.trap_list, "\n") -print(instance.cti.trap_list, "\n") +print("Errors Lists: \n") +print(errors_upper_list, "\n") +print(errors_lower_list, "\n") """ __Sample Instance__ diff --git a/smoke_tests.txt b/smoke_tests.txt index 7a33bfa..afd5518 100644 --- a/smoke_tests.txt +++ b/smoke_tests.txt @@ -1,3 +1,6 @@ dataset_1d/modeling/start_here.py dataset_1d/modeling/features/species_x3.py imaging_ci/modeling/start_here.py +dataset_1d/advanced/database/start_here.py +dataset_1d/advanced/database/examples/samples.py +dataset_1d/results/examples/samples.py