import math


def Log_Nash_Sutcliffe(SimulatedStreamFlow, ObservedStreamFlow):
    """
    (SimulatedStreamFlow, ObservedStreamFlow)
    Logarithmic Nash-Sutcliffe model efficiency coefficient
    """
    x = SimulatedStreamFlow
    y = ObservedStreamFlow
    A = 0.0  # dominator
    B = 0.0  # deminator
    tot = 0.0
    for i in range(0, len(y)):
        tot = tot + y[i]
    average = tot / len(y)
    for i in range(0, len(y)):
        X = x[i]
        Y = y[i]
        if X == 0:
            X = 1e-3
        if Y == 0:
            Y = 1e-3
        A = A + math.pow((math.log(Y) - math.log(X)), 2)  # log = ln or log_e
        B = B + math.pow((math.log(Y) - math.log(average)), 2)
    E = 1 - (A / B)  # Nash-Sutcliffe model eficiency coefficient
    return E