Changeset 3034


Ignore:
Timestamp:
Sep 20, 2010 11:28:20 PM (11 years ago)
Author:
jwatson
Message:

Added computation of confidence interval width to the PySP computeconf script, leveraging the built-in t-table - if entries for the given degrees of freedom are in the table. Other output cleanup as well.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • coopr.pysp/trunk/scripts/computeconf

    r3033 r3034  
    9595                                     default=10)
    9696      conf_options_parser.add_option("--confidence-interval-alpha",
    97                                      help="The alpha level for the confidence interval. Default is 0.10",
    98                                      action="store",
    99                                      dest="Conf_Alpha",
     97                                     help="The alpha level for the confidence interval. Default is 0.05",
     98                                     action="store",
     99                                     dest="confidence_interval_alpha",
    100100                                     type="float",
    101                                      default=0.10)
     101                                     default=0.05)
    102102      conf_options_parser.add_option("--solve-xhat-with-ph",
    103103                                     help="Perform xhat solve via PH rather than an EF solve. Default is False",
     
    269269      xstar_obj_gap = ef_results.solution(0).gap # assuming this is the absolute gap
    270270      xstar_obj_bound = xstar_obj - xstar_obj_gap # HERE - watch for signs on gap - is it absolute, or can it be negative?     
    271       print "Extensive form objective value given xstar="+str(xstar_obj)+"; gap="+str(xstar_obj_gap)
     271      print "Extensive form objective value given xstar="+str(xstar_obj)+"; gap="+str(xstar_obj_gap)+"."
    272272
    273273      # to get f(xhat) for this sample, fix the first-stage variables and re-solve the extensive form.
     
    297297      g_var = g_var + (g_supk_of_xhat[k] - g_bar) * (g_supk_of_xhat[k] - g_bar)
    298298   g_var = g_var / (n_g - 1)    # sample var
     299   print ""
    299300   print "g_bar=",g_bar
    300301   print "g_stddev=",math.sqrt(g_var)
    301302   print "Average f(xhat)=",sum_xstar_obj_given_xhat / n_g
    302303
     304   if n_g in t_table_values:
     305      print ""     
     306      t_table_entries = t_table_values[n_g]
     307      for key in sorted(t_table_entries.keys()):
     308         print "Confidence interval width for alpha="+str(key)+" is "+str(t_table_entries[key] * math.sqrt(g_var) / math.sqrt(n_g))
     309   else:
     310      print "No built-in t-table entries for "+str(n_g)+" degrees of freedom - cannot calculate confidence interval width"
     311
     312   if options.write_xhat_solution is True:
     313      print ""           
     314      print "xhat solution:"
     315      scenario_tree = xhat_ph._scenario_tree
     316      first_stage = scenario_tree._stages[0]
     317      root_node = first_stage._tree_nodes[0]
     318      for key, value in root_node._solutions.items():
     319         for idx in value:
     320            if value[idx]() != 0.0:
     321               print key, idx, value[idx]()     
     322
    303323   if options.append_file is not None:
    304324      output_file = open(options.append_file, "a")
    305325      print >>output_file, "\ninstancedirectory, ",options.instance_directory, ", seed, ",options.random_seed, ", N, ",scenario_count, ", hatn, ",num_scenarios_for_solution, ", n_g, ", options.n_g, ", Eoffofxhat, ", sum_xstar_obj_given_xhat / n_g, ", gbar, ", g_bar, ", sg, ", math.sqrt(g_var), ", objforxhat, ", xhat_obj, ", n,",num_scenarios_per_sample,
     326
     327      if n_g in t_table_values:
     328         t_table_entries = t_table_values[n_g]
     329         for key in sorted(t_table_entries.keys()):
     330            print >>output_file, " , alpha="+str(key)+" , "+str(t_table_entries[key] * math.sqrt(g_var) / math.sqrt(n_g)),
    306331
    307332      if options.write_xhat_solution is True:
     
    315340                  print >>output_file, key, idx, value[idx](),
    316341      output_file.close()
     342      print ""                 
     343      print "Results summary appended to file="+options.append_file
    317344
    318345#
Note: See TracChangeset for help on using the changeset viewer.