class_docstr: This class is responsible for analyzing the results and outputting various types of analysis to the results folder.
class_docstr_tok: ["This","class","is","responsible","for","analyzing","the","results","and","outputting","various","types","of","analysis","to","the","results","folder","."]
code: def outputResultsFolder(
      self, optimizer, detailed=True, workers=1, directory=None
  ):
      parameters = Hyperparameter(
          optimizer.config.data["hyperparameters"]
      ).getFlatParameters()
  
      if directory is None:
          directory = self.directory
  
      # Ensure the directory we want to store results in is there
      self.makeDirs(directory)
  
      resultsFile = os.path.join(directory, "results.csv")
      optimizer.exportResultsCSV(resultsFile)
      guidanceFile = os.path.join(directory, "guidance.json")
      optimizer.exportGuidanceJSON(guidanceFile)
  
      with open(
          os.path.join(directory, "search.json"), "wt"
      ) as paramsFile:
          json.dump(
              optimizer.config.data,
              paramsFile,
              indent=4,
              sort_keys=True,
          )
  
      clonedSortedResults = sorted(
          copy.deepcopy(
              [
                  result
                  for result in optimizer.results
                  if result["loss"] is not None
              ]
          ),
          key=lambda result: result["loss"],
      )
      if len(clonedSortedResults) > 0:
          best = clonedSortedResults[0]
          with open(
              os.path.join(directory, "best.json"), "wt"
          ) as paramsFile:
              json.dump(best, paramsFile, indent=4, sort_keys=True)
      if len(clonedSortedResults) > 1:
          second_best = clonedSortedResults[1]
          with open(
              os.path.join(directory, "second_best.json"), "wt"
          ) as paramsFile:
              json.dump(
                  second_best, paramsFile, indent=4, sort_keys=True
              )
      if len(clonedSortedResults) > 2:
          third_best = clonedSortedResults[2]
          with open(
              os.path.join(directory, "third_best.json"), "wt"
          ) as paramsFile:
              json.dump(
                  third_best, paramsFile, indent=4, sort_keys=True
              )
  
      with open(
          os.path.join(directory, "current_trials.json"), "wt"
      ) as paramsFile:
          trials = []
          for trial in optimizer.currentTrials:
              trialData = {
                  key: value
                  for key, value in trial.items()
                  if key != "start"
              }
              trials.append(trialData)
          trials = list(
              sorted(trials, key=lambda trial: trial["worker"])
          )
          json.dump(trials, paramsFile, indent=4, sort_keys=True)
  
      def onChartCompleted(e):
          self.completedCharts += 1
  
      # Only do these results if detailed is enabled, since they take a lot more computation
      if len(optimizer.results) > 5 and detailed:
          correlationsFile = os.path.join(directory, "correlations.csv")
          self.exportCorrelationsToCSV(correlationsFile, optimizer)
  
          self.completedCharts = 0
          self.totalCharts = 0
          self.totalCharts = len(parameters) + (len(parameters) - 1) * (
              len(parameters) - 1
          )
  
          # We use concurrent.futures.ProcessThreadPool here for two reasons. One for speed (since generating the images can be slow)
          # The other is because  matplotlib is not inherently thread safe.
          futures = []
          with concurrent.futures.ProcessPoolExecutor(
              max_workers=workers
          ) as executor:
              for parameter1 in parameters:
                  # self.generateSingleParameterExports(list(optimizer.results), parameter1)
                  if parameter1.config["type"] == "number":
                      futures.append(
                          executor.submit(
                              self.generateSingleParameterExports,
                              list(optimizer.results),
                              parameter1,
                              directory,
                          )
                      )
                      for parameter2 in parameters:
                          if parameter2.config["type"] == "number":
                              if parameter1.root != parameter2.root:
                                  # self.generateMultiParameterExports(list(optimizer.results), parameter1, parameter2)
                                  futures.append(
                                      executor.submit(
                                          self.generateMultiParameterExports,
                                          list(optimizer.results),
                                          parameter1,
                                          parameter2,
                                          directory,
                                      )
                                  )
              for future in futures:
                  future.add_done_callback(onChartCompleted)
  
                  def shutdown():
                      future.cancel()
  
                  atexit.register(shutdown)
                  future.add_done_callback(
                      lambda a: atexit.unregister(shutdown)
                  )
  
          for future in futures:
              if future.result() is not None:
                  print(
                      traceback.format_exception_only(
                          Exception, future.result()
                      )
                  )
                  raise future.result()
  
imports: import jsonschema
  import os
  import os.path
  import math
  import csv
  from hypermax.hyperparameter import Hyperparameter
  import sklearn.covariance
  import numpy
  from hypermax.utils import roundPrecision
  import matplotlib
  import matplotlib.cm
  import matplotlib.style
  import matplotlib.pyplot
  from pprint import pprint
  import concurrent.futures
  import colors
  import traceback
  import functools
  import warnings
  import scipy.optimize
  import random
  import json
  import atexit
  import matplotlib.ticker
  import traceback
  import copy
label_desc: Use image node_id 7 for calling the ResultsAnalyzer obj's underlying member method code with example usage: obj.outputResultsFolder(optimizer, detailed, workers, directory) without return types