|
22 | 22 |
|
23 | 23 | from autoconf.output import should_output |
24 | 24 |
|
25 | | -from autoconf.jax_wrapper import numpy as xp |
26 | 25 | from autoconf import jax_wrapper |
27 | 26 |
|
28 | 27 | from autofit import exc |
@@ -913,89 +912,90 @@ def perform_update( |
913 | 912 | ) |
914 | 913 | self.paths.save_samples(samples=samples_save) |
915 | 914 |
|
| 915 | + # latent_samples = None |
| 916 | + # |
| 917 | + # if (during_analysis and conf.instance["output"]["latent_during_fit"]) or ( |
| 918 | + # not during_analysis and conf.instance["output"]["latent_after_fit"] |
| 919 | + # ): |
| 920 | + # |
| 921 | + # if conf.instance["output"]["latent_draw_via_pdf"]: |
| 922 | + # |
| 923 | + # total_draws = conf.instance["output"]["latent_draw_via_pdf_size"] |
| 924 | + # |
| 925 | + # logger.info(f"Creating latent samples by drawing {total_draws} from the PDF.") |
| 926 | + # |
| 927 | + # try: |
| 928 | + # latent_samples = samples.samples_drawn_randomly_via_pdf_from(total_draws=total_draws) |
| 929 | + # except AttributeError: |
| 930 | + # latent_samples = samples_save |
| 931 | + # logger.info( |
| 932 | + # "Drawing via PDF not available for this search, " |
| 933 | + # "using all samples above the samples weight threshold instead." |
| 934 | + # "") |
| 935 | + # |
| 936 | + # else: |
| 937 | + # |
| 938 | + # logger.info(f"Creating latent samples using all samples above the samples weight threshold.") |
| 939 | + # |
| 940 | + # latent_samples = samples_save |
| 941 | + # |
| 942 | + # latent_samples = analysis.compute_latent_samples( |
| 943 | + # latent_samples, |
| 944 | + # batch_size=fitness.batch_size |
| 945 | + # ) |
| 946 | + # |
| 947 | + # if latent_samples: |
| 948 | + # if not conf.instance["output"]["latent_draw_via_pdf"]: |
| 949 | + # self.paths.save_latent_samples(latent_samples) |
| 950 | + # self.paths.save_samples_summary( |
| 951 | + # latent_samples.summary(), |
| 952 | + # "latent/latent_summary", |
| 953 | + # ) |
| 954 | + |
| 955 | + start = time.time() |
916 | 956 |
|
917 | | - if (during_analysis and conf.instance["output"]["latent_during_fit"]) or ( |
918 | | - not during_analysis and conf.instance["output"]["latent_after_fit"] |
919 | | - ): |
920 | | - |
921 | | - if conf.instance["output"]["latent_draw_via_pdf"]: |
922 | | - |
923 | | - total_draws = conf.instance["output"]["latent_draw_via_pdf_size"] |
924 | | - |
925 | | - logger.info(f"Creating latent samples by drawing {total_draws} from the PDF.") |
926 | | - |
927 | | - try: |
928 | | - latent_samples = samples.samples_drawn_randomly_via_pdf_from(total_draws=total_draws) |
929 | | - except AttributeError: |
930 | | - latent_samples = samples_save |
931 | | - logger.info( |
932 | | - "Drawing via PDF not available for this search, " |
933 | | - "using all samples above the samples weight threshold instead." |
934 | | - "") |
935 | | - |
936 | | - else: |
937 | | - |
938 | | - logger.info(f"Creating latent samples using all samples above the samples weight threshold.") |
939 | | - |
940 | | - latent_samples = samples_save |
| 957 | + self.perform_visualization( |
| 958 | + model=model, |
| 959 | + analysis=analysis, |
| 960 | + samples_summary=samples_summary, |
| 961 | + during_analysis=during_analysis, |
| 962 | + search_internal=search_internal, |
| 963 | + ) |
941 | 964 |
|
942 | | - latent_samples = analysis.compute_latent_samples( |
943 | | - latent_samples, |
944 | | - batch_size=fitness.batch_size |
945 | | - ) |
| 965 | + visualization_time = time.time() - start |
946 | 966 |
|
947 | | - if latent_samples: |
948 | | - if not conf.instance["output"]["latent_draw_via_pdf"]: |
949 | | - self.paths.save_latent_samples(latent_samples) |
950 | | - self.paths.save_samples_summary( |
951 | | - latent_samples.summary(), |
952 | | - "latent/latent_summary", |
953 | | - ) |
| 967 | + if self.should_profile: |
954 | 968 |
|
955 | | - start = time.time() |
| 969 | + self.logger.debug("Profiling Maximum Likelihood Model") |
956 | 970 |
|
957 | | - self.perform_visualization( |
958 | | - model=model, |
959 | | - analysis=analysis, |
960 | | - samples_summary=samples_summary, |
961 | | - during_analysis=during_analysis, |
962 | | - search_internal=search_internal, |
| 971 | + analysis.profile_log_likelihood_function( |
| 972 | + paths=self.paths, |
| 973 | + instance=instance, |
963 | 974 | ) |
964 | 975 |
|
965 | | - visualization_time = time.time() - start |
966 | | - |
967 | | - if self.should_profile: |
968 | | - |
969 | | - self.logger.debug("Profiling Maximum Likelihood Model") |
970 | | - |
971 | | - analysis.profile_log_likelihood_function( |
972 | | - paths=self.paths, |
973 | | - instance=instance, |
974 | | - ) |
975 | | - |
976 | | - self.logger.debug("Outputting model result") |
| 976 | + self.logger.debug("Outputting model result") |
977 | 977 |
|
978 | | - try: |
| 978 | + try: |
979 | 979 |
|
980 | | - parameters = samples.max_log_likelihood(as_instance=False) |
| 980 | + parameters = samples.max_log_likelihood(as_instance=False) |
981 | 981 |
|
982 | | - start = time.time() |
983 | | - figure_of_merit = fitness.call_wrap(parameters) |
| 982 | + start = time.time() |
| 983 | + figure_of_merit = fitness.call_wrap(parameters) |
984 | 984 |
|
985 | | - # account for asynchronous JAX calls |
986 | | - np.array(figure_of_merit) |
| 985 | + # account for asynchronous JAX calls |
| 986 | + np.array(figure_of_merit) |
987 | 987 |
|
988 | | - log_likelihood_function_time = time.time() - start |
| 988 | + log_likelihood_function_time = time.time() - start |
989 | 989 |
|
990 | | - self.paths.save_summary( |
991 | | - samples=samples, |
992 | | - latent_samples=latent_samples, |
993 | | - log_likelihood_function_time=log_likelihood_function_time, |
994 | | - visualization_time=visualization_time, |
995 | | - ) |
| 990 | + self.paths.save_summary( |
| 991 | + samples=samples, |
| 992 | + latent_samples=latent_samples, |
| 993 | + log_likelihood_function_time=log_likelihood_function_time, |
| 994 | + visualization_time=visualization_time, |
| 995 | + ) |
996 | 996 |
|
997 | | - except exc.FitException: |
998 | | - pass |
| 997 | + except exc.FitException: |
| 998 | + pass |
999 | 999 |
|
1000 | 1000 | self._log_process_state() |
1001 | 1001 |
|
@@ -1040,15 +1040,15 @@ def perform_visualization( |
1040 | 1040 | The instance of the model that is used for visualization. If not input, the maximum log likelihood |
1041 | 1041 | instance from the samples is used. |
1042 | 1042 | """ |
1043 | | - gggg |
1044 | 1043 |
|
1045 | 1044 | self.logger.debug("Visualizing") |
1046 | 1045 |
|
1047 | 1046 | paths = paths_override or self.paths |
1048 | 1047 |
|
1049 | 1048 | if instance is None and samples_summary is None: |
1050 | 1049 | raise AssertionError( |
1051 | | - """The search's perform_visualization method has been called without an input instance or |
| 1050 | + """ |
| 1051 | + The search's perform_visualization method has been called without an input instance or |
1052 | 1052 | samples_summary. |
1053 | 1053 |
|
1054 | 1054 | This should not occur, please ensure one of these inputs is provided. |
|
0 commit comments