コード例 #1
0
ファイル: find_roots.py プロジェクト: DCPROGS/HJCFIT
def step(context):
  from dcprogs.likelihood import find_roots
  context.roots = []
  for equation in context.equations:
    try: roots = find_roots(equation)
    except: roots = None
    context.roots.append(roots)
コード例 #2
0
ファイル: find_roots.py プロジェクト: jenshnielsen/HJCFIT
def step(context):
    from dcprogs.likelihood import find_roots

    eigsearch = [
        r[0] for r in context.intervals
        if r[0][1] - r[0][0] > context.resolution
    ]
    brusearch = [r[0] for r in context.intervals_brute_force]

    eigsearch = sorted(eigsearch)
    brusearch = sorted(eigsearch)

    if len(eigsearch) != len(brusearch):
        raise AssertionError(
            "Different number of intervals found be methods.\n" +
            str(context.equation))

    for a, b in zip(eigsearch, brusearch):
        interval = [max(a[0], b[0]), min(a[1], b[1])]
        roots = find_roots(context.equation, [interval])
        if len(roots) == 0                                                         \
           and context.equation(interval[0]) * context.equation(interval[1]) < 0e0 :
            raise AssertionError("Could not find root in interval\n" +
                                 str(context.equation))
        root = roots[0][0]
        if root < interval[0] or root > interval[1]:
            raise AssertionError("Root is outside of expected bound.\n" +
                                 str(context.equation))
コード例 #3
0
ファイル: find_roots.py プロジェクト: jenshnielsen/HJCFIT
def step(context):
    from dcprogs.likelihood import find_roots
    context.roots = []
    for equation in context.equations:
        try:
            roots = find_roots(equation)
        except:
            roots = None
        context.roots.append(roots)
コード例 #4
0
ファイル: find_roots.py プロジェクト: DCPROGS/HJCFIT
def step(context):
  from dcprogs.likelihood import find_roots

  intervals = [r[0] for r in context.intervals]
  intervals = sorted(intervals)

  for interval in intervals:
    roots = find_roots(context.equation, [interval])
    if len(roots) == 0                                                         \
       and context.equation(interval[0]) * context.equation(interval[1]) < 0e0 :
      raise AssertionError("Could not find root in interval");
    root = roots[0][0]
    if root < interval[0] or root > interval[1]:                  
      raise AssertionError("Root is outside of expected bound.")
コード例 #5
0
ファイル: find_roots.py プロジェクト: jenshnielsen/HJCFIT
def step(context):
    from dcprogs.likelihood import find_roots

    intervals = [r[0] for r in context.intervals]
    intervals = sorted(intervals)

    for interval in intervals:
        roots = find_roots(context.equation, [interval])
        if len(roots) == 0                                                         \
           and context.equation(interval[0]) * context.equation(interval[1]) < 0e0 :
            raise AssertionError("Could not find root in interval")
        root = roots[0][0]
        if root < interval[0] or root > interval[1]:
            raise AssertionError("Root is outside of expected bound.")
コード例 #6
0
ファイル: find_roots.py プロジェクト: DCPROGS/HJCFIT
def step(context):
  from dcprogs.likelihood import find_roots

  eigsearch = [r[0] for r in context.intervals if r[0][1]- r[0][0] > context.resolution]
  brusearch = [r[0] for r in context.intervals_brute_force]

  eigsearch = sorted(eigsearch)
  brusearch = sorted(eigsearch)

  if len(eigsearch) != len(brusearch):
    raise AssertionError( "Different number of intervals found be methods.\n"
                          + str(context.equation) )
  
  for a, b in zip(eigsearch, brusearch):
    interval = [max(a[0], b[0]), min(a[1], b[1])]
    roots = find_roots(context.equation, [interval])
    if len(roots) == 0                                                         \
       and context.equation(interval[0]) * context.equation(interval[1]) < 0e0 :
        raise AssertionError("Could not find root in interval\n"
                             + str(context.equation));
    root = roots[0][0]
    if root < interval[0] or root > interval[1]:                  
      raise AssertionError("Root is outside of expected bound.\n"
                           + str(context.equation))
コード例 #7
0
                    [    0,         0,    10,      0,  -10] ], 2)
det = DeterminantEq(qmatrix, 1e-4);


upper_bound = find_upper_bound_for_roots(det);
lower_bound = find_lower_bound_for_roots(det);

get_eigenvalues = lambda s: eig(det.H(s))[0].T
assert all(get_eigenvalues(lower_bound) > lower_bound) 
assert all(get_eigenvalues(upper_bound) < upper_bound) 


print("Root Determination\n"                                         \
      "==================\n\n"                                       \
      "  * Interval containing roots: {lower}, {upper}\n"            \
      "  * Eigenvalues of H at lower bound: {eiglow}\n"              \
      "  * Eigenvalues of H at upper bound: {eigup}\n"               \
      .format( lower=lower_bound, upper=upper_bound,
               eiglow = get_eigenvalues(lower_bound),
               eigup  = get_eigenvalues(upper_bound) ))

intervals = find_root_intervals(det, lower_bound, upper_bound)
for (start, end), multiplicity in intervals:
  root, iterations, function_calls = brentq(det, start, end)
  print("  * Root interval: [{0}, {1}]\n"
        "    Corresponding root: {2}\n".format(start, end, root))


roots = find_roots(det);
print("  * All roots: {0}\n".format([root for root, multiplicity in roots]))