Skip to content

Commit

Permalink
finetuned the parameters of numerical algorithms, used good asymptoti…
Browse files Browse the repository at this point in the history
…c approximation in some regimes. now passing fdp to approxdp conversion test.
  • Loading branch information
yuxiangw committed Feb 25, 2021
1 parent 9e0b3ca commit 5c72013
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
16 changes: 12 additions & 4 deletions autodp/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,15 +637,23 @@ def normal_equation(logx):
else:
return min(abs(high),abs(low))

def normal_equation_loglogx(loglogx):
logx = np.exp(loglogx)
return normal_equation(logx)

# find x such that y = 1-\delta
tmp = fun1(np.log(1 - delta))
bound1 = np.log(-tmp - tmp**2 / 2 - tmp**3 / 6)
#bound1 = np.log(1-np.exp(fun1(np.log(1-delta))))
if abs(tmp) < 1e-5:
bound1 = np.log(-tmp - tmp**2 / 2 - tmp**3 / 6)
else:
bound1 = np.log(1-np.exp(fun1(np.log(1-delta))))
#results = minimize_scalar(normal_equation, bounds=[-np.inf,0], bracket=[-1,-2])
results = minimize_scalar(normal_equation, method="Bounded", bounds=[bound1,0],
options={'xatol': 1e-6, 'maxiter': 500, 'disp': 0})
options={'xatol': 1e-10, 'maxiter': 500, 'disp': 0})
if results.success:
if abs(results.fun) > 1e-4:
if abs(results.fun) > 1e-4 and abs(results.x)>1e-10:
# This means that we hit xatol (x is close to 0, but
# the function value is not close to 0) In this case let's do an even larger search.
raise RuntimeError("'find_logx' fails to find the tangent line.")
else:
return results.x
Expand Down
2 changes: 1 addition & 1 deletion autodp/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def stable_norm_ppf_one_minus_x(logx):
:param logx:
:return: ppf(1-e^logx)
"""
if logx < -20:
if logx < -30:
# asymptotic approximation
norm_ppf_one_minus_x = np.sqrt(-2 * logx - np.log(-2*logx) - np.log(2*np.pi))
# # if logx < -10:
Expand Down
4 changes: 2 additions & 2 deletions test/unit_test_fdp_to_approxdp_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from absl.testing import absltest
from absl.testing import parameterized

params = [0.05, 0.1, 0.2, 0.5,1.0, 2.0, 5.0, 10.0]
params = [0.05, 0.1, 0.2, 0.5, 1.0, 2.0, 5.0, 10.0]


def _fdp_conversion(sigma):
Expand All @@ -32,7 +32,7 @@ def _fdp_conversion(sigma):
return rel_diff


_fdp_conversion(0.05)
_fdp_conversion(1.0)

class Test_approxDP2fDP_Conversion(parameterized.TestCase):

Expand Down

0 comments on commit 5c72013

Please sign in to comment.