jordyvl commited on
Commit
3a2a2ed
1 Parent(s): 9d4511f

fixed reliability plot

Browse files
Files changed (1) hide show
  1. local_app.py +7 -7
local_app.py CHANGED
@@ -58,7 +58,7 @@ metric = ECE()
58
  # module = evaluate.load("jordyvl/ece")
59
  # launch_gradio_widget(module)
60
 
61
- """
62
  Switch inputs and compute_fn
63
  """
64
 
@@ -105,7 +105,7 @@ def over_under_confidence(results):
105
 
106
 
107
  def reliability_plot(results):
108
- #DEV: might still need to write tests in case of equal mass binning
109
  fig = plt.figure()
110
  ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan=2)
111
  ax2 = plt.subplot2grid((3, 1), (2, 0))
@@ -118,8 +118,8 @@ def reliability_plot(results):
118
  # if upper edge then minus binsize; same for center [but half]
119
  # rwidth is dependent on the binning
120
  B, bins, patches = ax1.hist(
121
- results["y_bar"], weights=results["p_bar"][:-1] #rwidth=len(results["p_bar"]/len(results["p_bar"]-1 )) #, range=(0,1),
122
- ) # , rwidth=1, align="right") #
123
  colors = over_under_confidence(results)
124
  for b in range(len(B)):
125
  patches[b].set_facecolor(colors[b]) # color based on over/underconfidence
@@ -141,7 +141,7 @@ def reliability_plot(results):
141
  anindices = np.where(~np.isnan(results["p_bar"][:-1]))[0]
142
  bin_freqs = np.zeros(n_bins)
143
  bin_freqs[anindices] = results["bin_freq"]
144
- ax2.hist(results["y_bar"], weights=bin_freqs, color="midnightblue") #bins=results["y_bar"],
145
 
146
  # DEV: nicer would be to plot like a polygon
147
  # see: https://github.com/markus93/fit-on-the-test/blob/main/Experiments_Synthetic/binnings.py
@@ -191,13 +191,13 @@ def compute_and_plot(data, n_bins, bin_range, scheme, proxy, p):
191
  p=p,
192
  detail=True,
193
  )
194
-
195
  plot = reliability_plot(results)
196
  return results["ECE"], plot
197
 
198
 
199
  outputs = [gr.outputs.Textbox(label="ECE"), gr.Plot(label="Reliability diagram")]
200
- # outputs[1].value = default_plot().__dict__
201
 
202
  iface = gr.Interface(
203
  fn=compute_and_plot,
 
58
  # module = evaluate.load("jordyvl/ece")
59
  # launch_gradio_widget(module)
60
 
61
+ """l
62
  Switch inputs and compute_fn
63
  """
64
 
 
105
 
106
 
107
  def reliability_plot(results):
108
+ # DEV: might still need to write tests in case of equal mass binning
109
  fig = plt.figure()
110
  ax1 = plt.subplot2grid((3, 1), (0, 0), rowspan=2)
111
  ax2 = plt.subplot2grid((3, 1), (2, 0))
 
118
  # if upper edge then minus binsize; same for center [but half]
119
  # rwidth is dependent on the binning
120
  B, bins, patches = ax1.hist(
121
+ results["y_bar"], weights=p.nan_to_num(results["p_bar"][:-1], copy=True, nan=0)
122
+ )
123
  colors = over_under_confidence(results)
124
  for b in range(len(B)):
125
  patches[b].set_facecolor(colors[b]) # color based on over/underconfidence
 
141
  anindices = np.where(~np.isnan(results["p_bar"][:-1]))[0]
142
  bin_freqs = np.zeros(n_bins)
143
  bin_freqs[anindices] = results["bin_freq"]
144
+ ax2.hist(results["y_bar"], bins=results["y_bar"], weights=bin_freqs, color="midnightblue")
145
 
146
  # DEV: nicer would be to plot like a polygon
147
  # see: https://github.com/markus93/fit-on-the-test/blob/main/Experiments_Synthetic/binnings.py
 
191
  p=p,
192
  detail=True,
193
  )
194
+ print(results)
195
  plot = reliability_plot(results)
196
  return results["ECE"], plot
197
 
198
 
199
  outputs = [gr.outputs.Textbox(label="ECE"), gr.Plot(label="Reliability diagram")]
200
+ # outputs[1].value = default_plot().__dict__ #Does not work; yet needs to be JSON encoded
201
 
202
  iface = gr.Interface(
203
  fn=compute_and_plot,