Example #1
0
    def check_values(h2o_data, numpy_data):
        success = True
        for i in range(10):
            r = random.randint(0,row-1)
            c = random.randint(0,col-1)
            if not abs(h2o.as_list(h2o_data[r,c])[0][0] - numpy_data[r,c]) < 1e-06: success = False
        return success


        assert check_values(h2o.cos(h2o_data1), np.cos(np_data1)),       "expected equal cos values between h2o and numpy"
        assert check_values(h2o.sin(h2o_data1), np.sin(np_data1)),       "expected equal sin values between h2o and numpy"
        assert check_values(h2o.tan(h2o_data1), np.tan(np_data1)),       "expected equal tan values between h2o and numpy"
        assert check_values(h2o.acos(h2o_data2), np.arccos(np_data2)),   "expected equal acos values between h2o and numpy"
        assert check_values(h2o.asin(h2o_data2), np.arcsin(np_data2)),   "expected equal asin values between h2o and numpy"
        assert check_values(h2o.atan(h2o_data1), np.arctan(np_data1)),   "expected equal atan values between h2o and numpy"
        assert check_values(h2o.cosh(h2o_data1), np.cosh(np_data1)),     "expected equal cosh values between h2o and numpy"
        assert check_values(h2o.sinh(h2o_data1), np.sinh(np_data1)),     "expected equal sinh values between h2o and numpy"
        assert check_values(h2o.tanh(h2o_data1), np.tanh(np_data1)),     "expected equal tanh values between h2o and numpy"
        assert check_values(h2o.acosh(h2o_data3), np.arccosh(np_data3)), "expected equal acosh values between h2o and numpy"
        assert check_values(h2o.asinh(h2o_data1), np.arcsinh(np_data1)), "expected equal asinh values between h2o and numpy"
        assert check_values(h2o.atanh(h2o_data2), np.arctanh(np_data2)), "expected equal atanh values between h2o and numpy"
        assert check_values(h2o.abs(h2o_data4), np.fabs(np_data4)),      "expected equal abs values between h2o and numpy"
        assert check_values(h2o.sign(h2o_data2), np.sign(np_data2)),     "expected equal sign values between h2o and numpy"
        assert check_values(h2o.sqrt(h2o_data3), np.sqrt(np_data3)),     "expected equal sqrt values between h2o and numpy"
        assert check_values(h2o.trunc(h2o_data3), np.trunc(np_data3)),   "expected equal trunc values between h2o and numpy"
        assert check_values(h2o.ceil(h2o_data3), np.ceil(np_data3)),     "expected equal ceil values between h2o and numpy"
        assert check_values(h2o.floor(h2o_data3), np.floor(np_data3)),   "expected equal floor values between h2o and numpy"
        assert check_values(h2o.log(h2o_data3), np.log(np_data3)),       "expected equal log values between h2o and numpy"
        assert check_values(h2o.log10(h2o_data3), np.log10(np_data3)),   "expected equal log10 values between h2o and numpy"
        assert check_values(h2o.log1p(h2o_data3), np.log1p(np_data3)),   "expected equal log1p values between h2o and numpy"
        assert check_values(h2o.log2(h2o_data3), np.log2(np_data3)),     "expected equal log2 values between h2o and numpy"
        assert check_values(h2o.exp(h2o_data3), np.exp(np_data3)),       "expected equal exp values between h2o and numpy"
        assert check_values(h2o.expm1(h2o_data3), np.expm1(np_data3)),   "expected equal expm1 values between h2o and numpy"
        assert (h2o.as_list(h2o.gamma(h2o_data3))[5][5] - math.gamma(h2o.as_list(h2o_data3)[5][5])) < 1e-6, \
            "expected equal gamma values between h2o and math"
        assert (h2o.as_list(h2o.lgamma(h2o_data3))[5][5] - math.lgamma(h2o.as_list(h2o_data3)[5][5])) < 1e-6, \
            "expected equal gamma values between h2o and math"
        assert (h2o.as_list(h2o.digamma(h2o_data3))[5][5] - scipy.special.polygamma(0,h2o.as_list(h2o_data3)[5][5])) < 1e-6, \
            "expected equal gamma values between h2o and math"
        assert (h2o.as_list(h2o.trigamma(h2o_data3))[5][5] - scipy.special.polygamma(1,h2o.as_list(h2o_data3)[5][5])) < 1e-6, \
            "expected equal gamma values between h2o and math"
Example #2
0
def vec_math_ops(ip, port):
    # Connect to h2o
    h2o.init(ip, port)

    sin_cos_tan_atan_sinh_cosh_tanh_asinh_data = [
        [random.uniform(-10, 10) for r in range(10)] for c in range(10)
    ]
    asin_acos_atanh_data = [[random.uniform(-1, 1) for r in range(10)]
                            for c in range(10)]
    acosh_data = [[random.uniform(1, 10) for r in range(10)]
                  for c in range(10)]
    abs_data = [[random.uniform(-100000, 0) for r in range(10)]
                for c in range(10)]

    h2o_data1 = h2o.H2OFrame(
        python_obj=sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    h2o_data2 = h2o.H2OFrame(python_obj=asin_acos_atanh_data)
    h2o_data3 = h2o.H2OFrame(python_obj=acosh_data)
    h2o_data4 = h2o.H2OFrame(python_obj=abs_data)

    np_data1 = np.array(sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    np_data2 = np.array(asin_acos_atanh_data)
    np_data3 = np.array(acosh_data)
    np_data4 = np.array(abs_data)

    row, col = h2o_data1.dim()

    c = random.randint(0, col - 1)
    h2o.np_comparison_check(h2o.cos(h2o_data1[c]), np.cos(np_data1[:, c]), 10)
    h2o.np_comparison_check(h2o.sin(h2o_data1[c]), np.sin(np_data1[:, c]), 10)
    h2o.np_comparison_check(h2o.tan(h2o_data1[c]), np.tan(np_data1[:, c]), 10)
    h2o.np_comparison_check(h2o.acos(h2o_data2[c]), np.arccos(np_data2[:, c]),
                            10)
    h2o.np_comparison_check(h2o.asin(h2o_data2[c]), np.arcsin(np_data2[:, c]),
                            10)
    h2o.np_comparison_check(h2o.atan(h2o_data1[c]), np.arctan(np_data1[:, c]),
                            10)
    h2o.np_comparison_check(h2o.cosh(h2o_data1[c]), np.cosh(np_data1[:, c]),
                            10)
    h2o.np_comparison_check(h2o.sinh(h2o_data1[c]), np.sinh(np_data1[:, c]),
                            10)
    h2o.np_comparison_check(h2o.tanh(h2o_data1[c]), np.tanh(np_data1[:, c]),
                            10)
    h2o.np_comparison_check(h2o.acosh(h2o_data3[c]),
                            np.arccosh(np_data3[:, c]), 10)
    h2o.np_comparison_check(h2o.asinh(h2o_data1[c]),
                            np.arcsinh(np_data1[:, c]), 10)
    h2o.np_comparison_check(h2o.atanh(h2o_data2[c]),
                            np.arctanh(np_data2[:, c]), 10)
    h2o.np_comparison_check(h2o.abs(h2o_data4[c]), np.fabs(np_data4[:, c]), 10)
    h2o.np_comparison_check(h2o.sign(h2o_data2[c]), np.sign(np_data2[:, c]),
                            10)
    h2o.np_comparison_check(h2o.sqrt(h2o_data3[c]), np.sqrt(np_data3[:, c]),
                            10)
    h2o.np_comparison_check(h2o.trunc(h2o_data3[c]), np.trunc(np_data3[:, c]),
                            10)
    h2o.np_comparison_check(h2o.ceil(h2o_data3[c]), np.ceil(np_data3[:, c]),
                            10)
    h2o.np_comparison_check(h2o.floor(h2o_data3[c]), np.floor(np_data3[:, c]),
                            10)
    h2o.np_comparison_check(h2o.log(h2o_data3[c]), np.log(np_data3[:, c]), 10)
    h2o.np_comparison_check(h2o.log10(h2o_data3[c]), np.log10(np_data3[:, c]),
                            10)
    h2o.np_comparison_check(h2o.log1p(h2o_data3[c]), np.log1p(np_data3[:, c]),
                            10)
    h2o.np_comparison_check(h2o.log2(h2o_data3[c]), np.log2(np_data3[:, c]),
                            10)
    h2o.np_comparison_check(h2o.exp(h2o_data3[c]), np.exp(np_data3[:, c]), 10)
    h2o.np_comparison_check(h2o.expm1(h2o_data3[c]), np.expm1(np_data3[:, c]),
                            10)
    h2o_val = h2o.gamma(h2o_data3[c])[5, 0]
    num_val = math.gamma(h2o_data3[5, c])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal gamma values between h2o and" \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.lgamma(h2o_data3[c])[5, 0]
    num_val = math.lgamma(h2o_data3[5, c])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal lgamma values between h2o and " \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.digamma(h2o_data3[c])[5, 0]
    num_val = scipy.special.polygamma(0, h2o_data3[5, c])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal digamma values between h2o and " \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.trigamma(h2o_data3)[5, c]
    num_val = scipy.special.polygamma(1, h2o_data3[5, c])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal trigamma values between h2o and " \
        "math".format(h2o_val,num_val)
def expr_math_ops(ip,port):
    # Connect to h2o
    h2o.init(ip,port)

    sin_cos_tan_atan_sinh_cosh_tanh_asinh_data = [[random.uniform(-10,10) for r in range(10)] for c in range(10)]
    asin_acos_atanh_data = [[random.uniform(-1,1) for r in range(10)] for c in range(10)]
    acosh_data = [[random.uniform(1,10) for r in range(10)] for c in range(10)]
    abs_data = [[random.uniform(-100000,0) for r in range(10)] for c in range(10)]

    h2o_data1 = h2o.H2OFrame(python_obj=sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    h2o_data2 = h2o.H2OFrame(python_obj=asin_acos_atanh_data)
    h2o_data3 = h2o.H2OFrame(python_obj=acosh_data)
    h2o_data4 = h2o.H2OFrame(python_obj=abs_data)

    np_data1 = np.array(sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    np_data2 = np.array(asin_acos_atanh_data)
    np_data3 = np.array(acosh_data)
    np_data4 = np.array(abs_data)

    row, col = h2o_data1.dim()

    def check_values(h2o_data, numpy_data):
        success = True
        for i in range(10):
            r = random.randint(0,row-1)
            c = random.randint(0,col-1)
            h2o_val = h2o.as_list(h2o_data[r,c])[0][0]
            num_val = numpy_data[r,c]
            if not abs(h2o_val - num_val) < 1e-06:
                success = False
                print "check unsuccessful! h2o computed {0} and numpy computed {1}".format(h2o_val,num_val)
        return success

    h2o_data1 = h2o_data1 + 2
    h2o_data2 = h2o_data2 / 1.01
    h2o_data3 = h2o_data3 * 1.5
    h2o_data4 = h2o_data4 - 1.5

    np_data1 = np_data1 + 2
    np_data2 = np_data2 / 1.01
    np_data3 = np_data3 * 1.5
    np_data4 = np_data4 - 1.5

    assert check_values(h2o.cos(h2o_data1), np.cos(np_data1)),           "expected equal cos values between h2o and numpy"
    assert check_values(h2o.sin(h2o_data1), np.sin(np_data1)),           "expected equal sin values between h2o and numpy"
    assert check_values(h2o.tan(h2o_data1), np.tan(np_data1)),           "expected equal tan values between h2o and numpy"
    assert check_values(h2o.acos(h2o_data2), np.arccos(np_data2)),       "expected equal acos values between h2o and numpy"
    assert check_values(h2o.asin(h2o_data2), np.arcsin(np_data2)),       "expected equal asin values between h2o and numpy"
    assert check_values(h2o.atan(h2o_data1), np.arctan(np_data1)),       "expected equal atan values between h2o and numpy"
    assert check_values(h2o.cosh(h2o_data1), np.cosh(np_data1)),         "expected equal cosh values between h2o and numpy"
    assert check_values(h2o.sinh(h2o_data1), np.sinh(np_data1)),         "expected equal sinh values between h2o and numpy"
    assert check_values(h2o.tanh(h2o_data1), np.tanh(np_data1)),         "expected equal tanh values between h2o and numpy"
    assert check_values(h2o.acosh(h2o_data3), np.arccosh(np_data3)),     "expected equal acosh values between h2o and numpy"
    assert check_values(h2o.asinh(h2o_data1), np.arcsinh(np_data1)),     "expected equal asinh values between h2o and numpy"
    assert check_values(h2o.atanh(h2o_data2), np.arctanh(np_data2)),     "expected equal atanh values between h2o and numpy"
    assert check_values(h2o.cospi(h2o_data2/math.pi), np.cos(np_data2)), "expected equal cospi values between h2o and numpy"
    assert check_values(h2o.sinpi(h2o_data2/math.pi), np.sin(np_data2)), "expected equal sinpi values between h2o and numpy"
    assert check_values(h2o.tanpi(h2o_data2/math.pi), np.tan(np_data2)), "expected equal tanpi values between h2o and numpy"
    assert check_values(h2o.abs(h2o_data4), np.fabs(np_data4)),          "expected equal abs values between h2o and numpy"
    assert check_values(h2o.sign(h2o_data2), np.sign(np_data2)),         "expected equal sign values between h2o and numpy"
    assert check_values(h2o.sqrt(h2o_data3), np.sqrt(np_data3)),         "expected equal sqrt values between h2o and numpy"
    assert check_values(h2o.trunc(h2o_data3), np.trunc(np_data3)),       "expected equal trunc values between h2o and numpy"
    assert check_values(h2o.ceil(h2o_data3), np.ceil(np_data3)),         "expected equal ceil values between h2o and numpy"
    assert check_values(h2o.floor(h2o_data3), np.floor(np_data3)),       "expected equal floor values between h2o and numpy"
    assert check_values(h2o.log(h2o_data3), np.log(np_data3)),           "expected equal log values between h2o and numpy"
    assert check_values(h2o.log10(h2o_data3), np.log10(np_data3)),       "expected equal log10 values between h2o and numpy"
    assert check_values(h2o.log1p(h2o_data3), np.log1p(np_data3)),       "expected equal log1p values between h2o and numpy"
    assert check_values(h2o.log2(h2o_data3), np.log2(np_data3)),         "expected equal log2 values between h2o and numpy"
    assert check_values(h2o.exp(h2o_data3), np.exp(np_data3)),           "expected equal exp values between h2o and numpy"
    assert check_values(h2o.expm1(h2o_data3), np.expm1(np_data3)),       "expected equal expm1 values between h2o and numpy"
    h2o_val = h2o.as_list(h2o.gamma(h2o_data3))[5][5]
    num_val = math.gamma(h2o.as_list(h2o_data3)[5][5])
    assert abs(h2o_val - num_val) < max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal gamma values between h2o and math".format(h2o_val,num_val)
    h2o_val = h2o.as_list(h2o.lgamma(h2o_data3))[5][5]
    num_val = math.lgamma(h2o.as_list(h2o_data3)[5][5])
    assert abs(h2o_val - num_val) < max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal lgamma values between h2o and math".format(h2o_val,num_val)
    h2o_val = h2o.as_list(h2o.digamma(h2o_data3))[5][5]
    num_val = scipy.special.polygamma(0,h2o.as_list(h2o_data3)[5][5])
    assert abs(h2o_val - num_val) < max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal digamma values between h2o and math".format(h2o_val,num_val)
    h2o_val = h2o.as_list(h2o.trigamma(h2o_data3))[5][5]
    num_val = scipy.special.polygamma(1,h2o.as_list(h2o_data3)[5][5])
    assert abs(h2o_val - num_val) < max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal trigamma values between h2o and math".format(h2o_val,num_val)
Example #4
0
def expr_math_ops(ip,port):
    # Connect to h2o
    h2o.init(ip,port)

    sin_cos_tan_atan_sinh_cosh_tanh_asinh_data = [[random.uniform(-10,10) for r in range(10)] for c in range(10)]
    asin_acos_atanh_data = [[random.uniform(-1,1) for r in range(10)] for c in range(10)]
    acosh_data = [[random.uniform(1,10) for r in range(10)] for c in range(10)]
    abs_data = [[random.uniform(-100000,0) for r in range(10)] for c in range(10)]

    h2o_data1 = h2o.H2OFrame(python_obj=sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    h2o_data2 = h2o.H2OFrame(python_obj=asin_acos_atanh_data)
    h2o_data3 = h2o.H2OFrame(python_obj=acosh_data)
    h2o_data4 = h2o.H2OFrame(python_obj=abs_data)

    np_data1 = np.array(sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    np_data2 = np.array(asin_acos_atanh_data)
    np_data3 = np.array(acosh_data)
    np_data4 = np.array(abs_data)

    h2o_data1 = h2o_data1 + 2
    h2o_data2 = h2o_data2 / 1.01
    h2o_data3 = h2o_data3 * 1.5
    h2o_data4 = h2o_data4 - 1.5

    np_data1 = np_data1 + 2
    np_data2 = np_data2 / 1.01
    np_data3 = np_data3 * 1.5
    np_data4 = np_data4 - 1.5

    h2o.np_comparison_check(h2o.cos(h2o_data1), np.cos(np_data1), 10)
    h2o.np_comparison_check(h2o.sin(h2o_data1), np.sin(np_data1), 10)
    h2o.np_comparison_check(h2o.tan(h2o_data1), np.tan(np_data1), 10)
    h2o.np_comparison_check(h2o.acos(h2o_data2), np.arccos(np_data2), 10)
    h2o.np_comparison_check(h2o.asin(h2o_data2), np.arcsin(np_data2), 10)
    h2o.np_comparison_check(h2o.atan(h2o_data1), np.arctan(np_data1), 10)
    h2o.np_comparison_check(h2o.cosh(h2o_data1), np.cosh(np_data1), 10)
    h2o.np_comparison_check(h2o.sinh(h2o_data1), np.sinh(np_data1), 10)
    h2o.np_comparison_check(h2o.tanh(h2o_data1), np.tanh(np_data1), 10)
    h2o.np_comparison_check(h2o.acosh(h2o_data3), np.arccosh(np_data3), 10)
    h2o.np_comparison_check(h2o.asinh(h2o_data1), np.arcsinh(np_data1), 10)
    h2o.np_comparison_check(h2o.atanh(h2o_data2), np.arctanh(np_data2), 10)
    h2o.np_comparison_check(h2o.cospi(h2o_data2/math.pi), np.cos(np_data2), 10)
    h2o.np_comparison_check(h2o.sinpi(h2o_data2/math.pi), np.sin(np_data2), 10)
    h2o.np_comparison_check(h2o.tanpi(h2o_data2/math.pi), np.tan(np_data2), 10)
    h2o.np_comparison_check(h2o.abs(h2o_data4), np.fabs(np_data4), 10)
    h2o.np_comparison_check(h2o.sign(h2o_data2), np.sign(np_data2), 10)
    h2o.np_comparison_check(h2o.sqrt(h2o_data3), np.sqrt(np_data3), 10)
    h2o.np_comparison_check(h2o.trunc(h2o_data3), np.trunc(np_data3), 10)
    h2o.np_comparison_check(h2o.ceil(h2o_data3), np.ceil(np_data3), 10)
    h2o.np_comparison_check(h2o.floor(h2o_data3), np.floor(np_data3), 10)
    h2o.np_comparison_check(h2o.log(h2o_data3), np.log(np_data3), 10)
    h2o.np_comparison_check(h2o.log10(h2o_data3), np.log10(np_data3), 10)
    h2o.np_comparison_check(h2o.log1p(h2o_data3), np.log1p(np_data3), 10)
    h2o.np_comparison_check(h2o.log2(h2o_data3), np.log2(np_data3), 10)
    h2o.np_comparison_check(h2o.exp(h2o_data3), np.exp(np_data3), 10)
    h2o.np_comparison_check(h2o.expm1(h2o_data3), np.expm1(np_data3), 10)
    h2o_val = h2o.gamma(h2o_data3)[5,5]
    num_val = math.gamma(h2o_data3[5,5])
    assert abs(h2o_val - num_val) < max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal gamma values between h2o and " \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.lgamma(h2o_data3)[5,5]
    num_val = math.lgamma(h2o_data3[5,5])
    assert abs(h2o_val - num_val) < max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal lgamma values between h2o and " \
        "math".\
            format(h2o_val,num_val)
    h2o_val = h2o.digamma(h2o_data3)[5,5]
    num_val = scipy.special.polygamma(0,h2o_data3[5,5])
    assert abs(h2o_val - num_val) < max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal digamma values between h2o and " \
        "math"\
            .format(h2o_val,num_val)
    h2o_val = h2o.trigamma(h2o_data3)[5,5]
    num_val = scipy.special.polygamma(1,h2o_data3[5,5])
    assert abs(h2o_val - num_val) < max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal trigamma values between h2o and " \
        "math".format(h2o_val,num_val)
Example #5
0
def expr_math_ops(ip, port):
    # Connect to h2o
    h2o.init(ip, port)

    sin_cos_tan_atan_sinh_cosh_tanh_asinh_data = [
        [random.uniform(-10, 10) for r in range(10)] for c in range(10)
    ]
    asin_acos_atanh_data = [[random.uniform(-1, 1) for r in range(10)]
                            for c in range(10)]
    acosh_data = [[random.uniform(1, 10) for r in range(10)]
                  for c in range(10)]
    abs_data = [[random.uniform(-100000, 0) for r in range(10)]
                for c in range(10)]

    h2o_data1_1 = h2o.H2OFrame(
        python_obj=sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    h2o_data2_1 = h2o.H2OFrame(python_obj=asin_acos_atanh_data)
    h2o_data3_1 = h2o.H2OFrame(python_obj=acosh_data)
    h2o_data4_1 = h2o.H2OFrame(python_obj=abs_data)

    np_data1 = np.array(sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    np_data2 = np.array(asin_acos_atanh_data)
    np_data3 = np.array(acosh_data)
    np_data4 = np.array(abs_data)

    h2o_data1 = h2o_data1_1 + 2
    h2o_data2 = h2o_data2_1 / 1.01
    h2o_data3 = h2o_data3_1 * 1.5
    h2o_data4 = h2o_data4_1 - 1.5

    np_data1 = np_data1 + 2
    np_data2 = np_data2 / 1.01
    np_data3 = np_data3 * 1.5
    np_data4 = np_data4 - 1.5

    h2o.np_comparison_check(h2o.cos(h2o_data1), np.cos(np_data1), 10)
    h2o.np_comparison_check(h2o.sin(h2o_data1), np.sin(np_data1), 10)
    h2o.np_comparison_check(h2o.tan(h2o_data1), np.tan(np_data1), 10)
    h2o.np_comparison_check(h2o.acos(h2o_data2), np.arccos(np_data2), 10)
    h2o.np_comparison_check(h2o.asin(h2o_data2), np.arcsin(np_data2), 10)
    h2o.np_comparison_check(h2o.atan(h2o_data1), np.arctan(np_data1), 10)
    h2o.np_comparison_check(h2o.cosh(h2o_data1), np.cosh(np_data1), 10)
    h2o.np_comparison_check(h2o.sinh(h2o_data1), np.sinh(np_data1), 10)
    h2o.np_comparison_check(h2o.tanh(h2o_data1), np.tanh(np_data1), 10)
    h2o.np_comparison_check(h2o.acosh(h2o_data3), np.arccosh(np_data3), 10)
    h2o.np_comparison_check(h2o.asinh(h2o_data1), np.arcsinh(np_data1), 10)
    h2o.np_comparison_check(h2o.atanh(h2o_data2), np.arctanh(np_data2), 10)
    h2o.np_comparison_check(h2o.cospi(h2o_data2 / math.pi), np.cos(np_data2),
                            10)
    h2o.np_comparison_check(h2o.sinpi(h2o_data2 / math.pi), np.sin(np_data2),
                            10)
    h2o.np_comparison_check(h2o.tanpi(h2o_data2 / math.pi), np.tan(np_data2),
                            10)
    h2o.np_comparison_check(h2o.abs(h2o_data4), np.fabs(np_data4), 10)
    h2o.np_comparison_check(h2o.sign(h2o_data2), np.sign(np_data2), 10)
    h2o.np_comparison_check(h2o.sqrt(h2o_data3), np.sqrt(np_data3), 10)
    h2o.np_comparison_check(h2o.trunc(h2o_data3), np.trunc(np_data3), 10)
    h2o.np_comparison_check(h2o.ceil(h2o_data3), np.ceil(np_data3), 10)
    h2o.np_comparison_check(h2o.floor(h2o_data3), np.floor(np_data3), 10)
    h2o.np_comparison_check(h2o.log(h2o_data3), np.log(np_data3), 10)
    h2o.np_comparison_check(h2o.log10(h2o_data3), np.log10(np_data3), 10)
    h2o.np_comparison_check(h2o.log1p(h2o_data3), np.log1p(np_data3), 10)
    h2o.np_comparison_check(h2o.log2(h2o_data3), np.log2(np_data3), 10)
    h2o.np_comparison_check(h2o.exp(h2o_data3), np.exp(np_data3), 10)
    h2o.np_comparison_check(h2o.expm1(h2o_data3), np.expm1(np_data3), 10)
    h2o_val = h2o.gamma(h2o_data3)[5, 5]
    num_val = math.gamma(h2o_data3[5, 5])
    assert abs(h2o_val - num_val) < max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal gamma values between h2o and " \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.lgamma(h2o_data3)[5, 5]
    num_val = math.lgamma(h2o_data3[5, 5])
    assert abs(h2o_val - num_val) < max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal lgamma values between h2o and " \
        "math".\
            format(h2o_val,num_val)
    h2o_val = h2o.digamma(h2o_data3)[5, 5]
    num_val = scipy.special.polygamma(0, h2o_data3[5, 5])
    assert abs(h2o_val - num_val) < max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal digamma values between h2o and " \
        "math"\
            .format(h2o_val,num_val)
    h2o_val = h2o.trigamma(h2o_data3)[5, 5]
    num_val = scipy.special.polygamma(1, h2o_data3[5, 5])
    assert abs(h2o_val - num_val) < max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal trigamma values between h2o and " \
        "math".format(h2o_val,num_val)
Example #6
0
def frame_math_ops(ip, port):
    # Connect to h2o
    h2o.init(ip, port)

    sin_cos_tan_atan_sinh_cosh_tanh_asinh_data = [
        [random.uniform(-10, 10) for r in range(10)] for c in range(10)
    ]
    asin_acos_atanh_data = [[random.uniform(-1, 1) for r in range(10)]
                            for c in range(10)]
    acosh_data = [[random.uniform(1, 10) for r in range(10)]
                  for c in range(10)]
    abs_data = [[random.uniform(-100000, 0) for r in range(10)]
                for c in range(10)]

    h2o_data1 = h2o.H2OFrame(
        python_obj=sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    h2o_data2 = h2o.H2OFrame(python_obj=asin_acos_atanh_data)
    h2o_data3 = h2o.H2OFrame(python_obj=acosh_data)
    h2o_data4 = h2o.H2OFrame(python_obj=abs_data)

    np_data1 = np.array(sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    np_data2 = np.array(asin_acos_atanh_data)
    np_data3 = np.array(acosh_data)
    np_data4 = np.array(abs_data)

    row, col = h2o_data1.dim()

    def check_values(h2o_data, numpy_data):
        success = True
        for i in range(10):
            r = random.randint(0, row - 1)
            c = random.randint(0, col - 1)
            h2o_val = h2o.as_list(h2o_data[r, c])[0][0]
            num_val = numpy_data[r, c]
            if not abs(h2o_val - num_val) < 1e-06:
                success = False
                print "check unsuccessful! h2o computed {0} and numpy computed {1}".format(
                    h2o_val, num_val)
        return success

    assert check_values(
        h2o.cos(h2o_data1),
        np.cos(np_data1)), "expected equal cos values between h2o and numpy"
    assert check_values(
        h2o.sin(h2o_data1),
        np.sin(np_data1)), "expected equal sin values between h2o and numpy"
    assert check_values(
        h2o.tan(h2o_data1),
        np.tan(np_data1)), "expected equal tan values between h2o and numpy"
    assert check_values(h2o.acos(h2o_data2), np.arccos(
        np_data2)), "expected equal acos values between h2o and numpy"
    assert check_values(h2o.asin(h2o_data2), np.arcsin(
        np_data2)), "expected equal asin values between h2o and numpy"
    assert check_values(h2o.atan(h2o_data1), np.arctan(
        np_data1)), "expected equal atan values between h2o and numpy"
    assert check_values(
        h2o.cosh(h2o_data1),
        np.cosh(np_data1)), "expected equal cosh values between h2o and numpy"
    assert check_values(
        h2o.sinh(h2o_data1),
        np.sinh(np_data1)), "expected equal sinh values between h2o and numpy"
    assert check_values(
        h2o.tanh(h2o_data1),
        np.tanh(np_data1)), "expected equal tanh values between h2o and numpy"
    assert check_values(h2o.acosh(h2o_data3), np.arccosh(
        np_data3)), "expected equal acosh values between h2o and numpy"
    assert check_values(h2o.asinh(h2o_data1), np.arcsinh(
        np_data1)), "expected equal asinh values between h2o and numpy"
    assert check_values(h2o.atanh(h2o_data2), np.arctanh(
        np_data2)), "expected equal atanh values between h2o and numpy"
    assert check_values(
        h2o.abs(h2o_data4),
        np.fabs(np_data4)), "expected equal abs values between h2o and numpy"
    assert check_values(
        h2o.sign(h2o_data2),
        np.sign(np_data2)), "expected equal sign values between h2o and numpy"
    assert check_values(
        h2o.sqrt(h2o_data3),
        np.sqrt(np_data3)), "expected equal sqrt values between h2o and numpy"
    assert check_values(h2o.trunc(h2o_data3), np.trunc(
        np_data3)), "expected equal trunc values between h2o and numpy"
    assert check_values(
        h2o.ceil(h2o_data3),
        np.ceil(np_data3)), "expected equal ceil values between h2o and numpy"
    assert check_values(h2o.floor(h2o_data3), np.floor(
        np_data3)), "expected equal floor values between h2o and numpy"
    assert check_values(
        h2o.log(h2o_data3),
        np.log(np_data3)), "expected equal log values between h2o and numpy"
    assert check_values(h2o.log10(h2o_data3), np.log10(
        np_data3)), "expected equal log10 values between h2o and numpy"
    assert check_values(h2o.log1p(h2o_data3), np.log1p(
        np_data3)), "expected equal log1p values between h2o and numpy"
    assert check_values(
        h2o.log2(h2o_data3),
        np.log2(np_data3)), "expected equal log2 values between h2o and numpy"
    assert check_values(
        h2o.exp(h2o_data3),
        np.exp(np_data3)), "expected equal exp values between h2o and numpy"
    assert check_values(h2o.expm1(h2o_data3), np.expm1(
        np_data3)), "expected equal expm1 values between h2o and numpy"
    h2o_val = h2o.as_list(h2o.gamma(h2o_data3))[5][5]
    num_val = math.gamma(h2o.as_list(h2o_data3)[5][5])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal gamma values between h2o and math".format(h2o_val,num_val)
    h2o_val = h2o.as_list(h2o.lgamma(h2o_data3))[5][5]
    num_val = math.lgamma(h2o.as_list(h2o_data3)[5][5])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal lgamma values between h2o and math".format(h2o_val,num_val)
    h2o_val = h2o.as_list(h2o.digamma(h2o_data3))[5][5]
    num_val = scipy.special.polygamma(0, h2o.as_list(h2o_data3)[5][5])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal digamma values between h2o and math".format(h2o_val,num_val)
    h2o_val = h2o.as_list(h2o.trigamma(h2o_data3))[5][5]
    num_val = scipy.special.polygamma(1, h2o.as_list(h2o_data3)[5][5])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal trigamma values between h2o and math".format(h2o_val,num_val)
Example #7
0
def frame_math_ops(ip, port):
    # Connect to h2o
    h2o.init(ip, port)

    sin_cos_tan_atan_sinh_cosh_tanh_asinh_data = [
        [random.uniform(-10, 10) for r in range(10)] for c in range(10)
    ]
    asin_acos_atanh_data = [[random.uniform(-1, 1) for r in range(10)]
                            for c in range(10)]
    acosh_data = [[random.uniform(1, 10) for r in range(10)]
                  for c in range(10)]
    abs_data = [[random.uniform(-100000, 0) for r in range(10)]
                for c in range(10)]
    signif_data = [[0.0000123456, 1], [2, 3]]

    h2o_data1 = h2o.H2OFrame(
        python_obj=sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    h2o_data2 = h2o.H2OFrame(python_obj=asin_acos_atanh_data)
    h2o_data3 = h2o.H2OFrame(python_obj=acosh_data)
    h2o_data4 = h2o.H2OFrame(python_obj=abs_data)
    h2o_data5 = h2o.H2OFrame(python_obj=signif_data)

    np_data1 = np.array(sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    np_data2 = np.array(asin_acos_atanh_data)
    np_data3 = np.array(acosh_data)
    np_data4 = np.array(abs_data)

    for d in range(1, 6):
        h2o_signif = h2o.signif(h2o_data5, digits=d)
        h2o_round = h2o.round(h2o_data5, digits=d + 4)
        s = h2o_signif[0, 0]
        r = h2o_round[0, 0]
        assert s == r, "Expected these to be equal, but signif: {0}, round: {1}".format(
            s, r)
    h2o_transposed = h2o.transpose(h2o_data1[0:5])
    r, c = h2o_transposed.dim()
    assert r == 5 and c == 10, "Expected 5 rows and 10 columns, but got {0} rows and {1} columns".format(
        r, c)
    h2o.np_comparison_check(h2o_transposed, np.transpose(np_data1[:, 0:5]), 10)
    h2o.np_comparison_check(h2o.cos(h2o_data1), np.cos(np_data1), 10)
    h2o.np_comparison_check(h2o.sin(h2o_data1), np.sin(np_data1), 10)
    h2o.np_comparison_check(h2o.tan(h2o_data1), np.tan(np_data1), 10)
    h2o.np_comparison_check(h2o.acos(h2o_data2), np.arccos(np_data2), 10)
    h2o.np_comparison_check(h2o.asin(h2o_data2), np.arcsin(np_data2), 10)
    h2o.np_comparison_check(h2o.atan(h2o_data1), np.arctan(np_data1), 10)
    h2o.np_comparison_check(h2o.cosh(h2o_data1), np.cosh(np_data1), 10)
    h2o.np_comparison_check(h2o.sinh(h2o_data1), np.sinh(np_data1), 10)
    h2o.np_comparison_check(h2o.tanh(h2o_data1), np.tanh(np_data1), 10)
    h2o.np_comparison_check(h2o.acosh(h2o_data3), np.arccosh(np_data3), 10)
    h2o.np_comparison_check(h2o.asinh(h2o_data1), np.arcsinh(np_data1), 10)
    h2o.np_comparison_check(h2o.atanh(h2o_data2), np.arctanh(np_data2), 10)
    h2o.np_comparison_check(h2o.abs(h2o_data4), np.fabs(np_data4), 10)
    h2o.np_comparison_check(h2o.sign(h2o_data2), np.sign(np_data2), 10)
    h2o.np_comparison_check(h2o.sqrt(h2o_data3), np.sqrt(np_data3), 10)
    h2o.np_comparison_check(h2o.trunc(h2o_data3), np.trunc(np_data3), 10)
    h2o.np_comparison_check(h2o.ceil(h2o_data3), np.ceil(np_data3), 10)
    h2o.np_comparison_check(h2o.floor(h2o_data3), np.floor(np_data3), 10)
    h2o.np_comparison_check(h2o.log(h2o_data3), np.log(np_data3), 10)
    h2o.np_comparison_check(h2o.log10(h2o_data3), np.log10(np_data3), 10)
    h2o.np_comparison_check(h2o.log1p(h2o_data3), np.log1p(np_data3), 10)
    h2o.np_comparison_check(h2o.log2(h2o_data3), np.log2(np_data3), 10)
    h2o.np_comparison_check(h2o.exp(h2o_data3), np.exp(np_data3), 10)
    h2o.np_comparison_check(h2o.expm1(h2o_data3), np.expm1(np_data3), 10)
    h2o_val = h2o.gamma(h2o_data3)[5, 5]
    num_val = math.gamma(h2o_data3[5, 5])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal gamma values between h2o and " \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.lgamma(h2o_data3)[5, 5]
    num_val = math.lgamma(h2o_data3[5, 5])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal lgamma values between h2o and " \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.digamma(h2o_data3)[5, 5]
    num_val = scipy.special.polygamma(0, h2o_data3[5, 5])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal digamma values between h2o and " \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.trigamma(h2o_data3)[5, 5]
    num_val = scipy.special.polygamma(1, h2o_data3[5, 5])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal trigamma values between h2o and " \
        "math".format(h2o_val,num_val)
def frame_math_ops(ip,port):
    # Connect to h2o
    h2o.init(ip,port)

    sin_cos_tan_atan_sinh_cosh_tanh_asinh_data = [[random.uniform(-10,10) for r in range(10)] for c in range(10)]
    asin_acos_atanh_data = [[random.uniform(-1,1) for r in range(10)] for c in range(10)]
    acosh_data = [[random.uniform(1,10) for r in range(10)] for c in range(10)]
    abs_data = [[random.uniform(-100000,0) for r in range(10)] for c in range(10)]
    signif_data = [[0.0000123456, 1], [2, 3]]

    h2o_data1 = h2o.H2OFrame(python_obj=sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    h2o_data2 = h2o.H2OFrame(python_obj=asin_acos_atanh_data)
    h2o_data3 = h2o.H2OFrame(python_obj=acosh_data)
    h2o_data4 = h2o.H2OFrame(python_obj=abs_data)
    h2o_data5 = h2o.H2OFrame(python_obj=signif_data)

    np_data1 = np.array(sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    np_data2 = np.array(asin_acos_atanh_data)
    np_data3 = np.array(acosh_data)
    np_data4 = np.array(abs_data)

    for d in range(1,6):
        h2o_signif = h2o.signif(h2o_data5, digits=d)
        h2o_round = h2o.round(h2o_data5, digits=d+4)
        s = h2o_signif[0,0]
        r = h2o_round[0,0]
        assert s == r, "Expected these to be equal, but signif: {0}, round: {1}".format(s, r)
    h2o_transposed = h2o.transpose(h2o_data1[0:5])
    r, c = h2o_transposed.dim()
    assert r == 5 and c == 10, "Expected 5 rows and 10 columns, but got {0} rows and {1} columns".format(r,c)
    h2o.np_comparison_check(h2o_transposed, np.transpose(np_data1[:,0:5]), 10)
    h2o.np_comparison_check(h2o.cos(h2o_data1), np.cos(np_data1), 10)
    h2o.np_comparison_check(h2o.sin(h2o_data1), np.sin(np_data1), 10)
    h2o.np_comparison_check(h2o.tan(h2o_data1), np.tan(np_data1), 10)
    h2o.np_comparison_check(h2o.acos(h2o_data2), np.arccos(np_data2), 10)
    h2o.np_comparison_check(h2o.asin(h2o_data2), np.arcsin(np_data2), 10)
    h2o.np_comparison_check(h2o.atan(h2o_data1), np.arctan(np_data1), 10)
    h2o.np_comparison_check(h2o.cosh(h2o_data1), np.cosh(np_data1), 10)
    h2o.np_comparison_check(h2o.sinh(h2o_data1), np.sinh(np_data1), 10)
    h2o.np_comparison_check(h2o.tanh(h2o_data1), np.tanh(np_data1), 10)
    h2o.np_comparison_check(h2o.acosh(h2o_data3), np.arccosh(np_data3), 10)
    h2o.np_comparison_check(h2o.asinh(h2o_data1), np.arcsinh(np_data1), 10)
    h2o.np_comparison_check(h2o.atanh(h2o_data2), np.arctanh(np_data2), 10)
    h2o.np_comparison_check(h2o.abs(h2o_data4), np.fabs(np_data4), 10)
    h2o.np_comparison_check(h2o.sign(h2o_data2), np.sign(np_data2), 10)
    h2o.np_comparison_check(h2o.sqrt(h2o_data3), np.sqrt(np_data3), 10)
    h2o.np_comparison_check(h2o.trunc(h2o_data3), np.trunc(np_data3), 10)
    h2o.np_comparison_check(h2o.ceil(h2o_data3), np.ceil(np_data3), 10)
    h2o.np_comparison_check(h2o.floor(h2o_data3), np.floor(np_data3), 10)
    h2o.np_comparison_check(h2o.log(h2o_data3), np.log(np_data3), 10)
    h2o.np_comparison_check(h2o.log10(h2o_data3), np.log10(np_data3), 10)
    h2o.np_comparison_check(h2o.log1p(h2o_data3), np.log1p(np_data3), 10)
    h2o.np_comparison_check(h2o.log2(h2o_data3), np.log2(np_data3), 10)
    h2o.np_comparison_check(h2o.exp(h2o_data3), np.exp(np_data3), 10)
    h2o.np_comparison_check(h2o.expm1(h2o_data3), np.expm1(np_data3), 10)
    h2o_val = h2o.gamma(h2o_data3)[5,5]
    num_val = math.gamma(h2o_data3[5,5])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal gamma values between h2o and " \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.lgamma(h2o_data3)[5,5]
    num_val = math.lgamma(h2o_data3[5,5])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal lgamma values between h2o and " \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.digamma(h2o_data3)[5,5]
    num_val = scipy.special.polygamma(0,h2o_data3[5,5])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal digamma values between h2o and " \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.trigamma(h2o_data3)[5,5]
    num_val = scipy.special.polygamma(1,h2o_data3[5,5])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal trigamma values between h2o and " \
        "math".format(h2o_val,num_val)
Example #9
0
def vec_math_ops(ip,port):
    # Connect to h2o
    h2o.init(ip,port)

    sin_cos_tan_atan_sinh_cosh_tanh_asinh_data = [[random.uniform(-10,10) for r in range(10)] for c in range(10)]
    asin_acos_atanh_data = [[random.uniform(-1,1) for r in range(10)] for c in range(10)]
    acosh_data = [[random.uniform(1,10) for r in range(10)] for c in range(10)]
    abs_data = [[random.uniform(-100000,0) for r in range(10)] for c in range(10)]

    h2o_data1 = h2o.H2OFrame(python_obj=sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    h2o_data2 = h2o.H2OFrame(python_obj=asin_acos_atanh_data)
    h2o_data3 = h2o.H2OFrame(python_obj=acosh_data)
    h2o_data4 = h2o.H2OFrame(python_obj=abs_data)

    np_data1 = np.array(sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    np_data2 = np.array(asin_acos_atanh_data)
    np_data3 = np.array(acosh_data)
    np_data4 = np.array(abs_data)

    row, col = h2o_data1.dim()

    def check_values(h2o_data, np_data):
        success = True
        for i in range(10):
            if not abs(h2o.as_list(h2o_data[i,0])[0][0] - np_data[i]) < 1e-06: success = False
        return success


    c = random.randint(0,col-1)
    assert check_values(h2o.cos(h2o_data1[c]), np.cos(np_data1[:,c])),       "expected equal cos values between h2o and numpy"
    assert check_values(h2o.sin(h2o_data1[c]), np.sin(np_data1[:,c])),       "expected equal sin values between h2o and numpy"
    assert check_values(h2o.tan(h2o_data1[c]), np.tan(np_data1[:,c])),       "expected equal tan values between h2o and numpy"
    assert check_values(h2o.acos(h2o_data2[c]), np.arccos(np_data2[:,c])),   "expected equal acos values between h2o and numpy"
    assert check_values(h2o.asin(h2o_data2[c]), np.arcsin(np_data2[:,c])),   "expected equal asin values between h2o and numpy"
    assert check_values(h2o.atan(h2o_data1[c]), np.arctan(np_data1[:,c])),   "expected equal atan values between h2o and numpy"
    assert check_values(h2o.cosh(h2o_data1[c]), np.cosh(np_data1[:,c])),     "expected equal cosh values between h2o and numpy"
    assert check_values(h2o.sinh(h2o_data1[c]), np.sinh(np_data1[:,c])),     "expected equal sinh values between h2o and numpy"
    assert check_values(h2o.tanh(h2o_data1[c]), np.tanh(np_data1[:,c])),     "expected equal tanh values between h2o and numpy"
    assert check_values(h2o.acosh(h2o_data3[c]), np.arccosh(np_data3[:,c])), "expected equal acosh values between h2o and numpy"
    assert check_values(h2o.asinh(h2o_data1[c]), np.arcsinh(np_data1[:,c])), "expected equal asinh values between h2o and numpy"
    assert check_values(h2o.atanh(h2o_data2[c]), np.arctanh(np_data2[:,c])), "expected equal atanh values between h2o and numpy"
    assert check_values(h2o.abs(h2o_data4[c]), np.fabs(np_data4[:,c])),      "expected equal abs values between h2o and numpy"
    assert check_values(h2o.sign(h2o_data2[c]), np.sign(np_data2[:,c])),     "expected equal sign values between h2o and numpy"
    assert check_values(h2o.sqrt(h2o_data3[c]), np.sqrt(np_data3[:,c])),     "expected equal sqrt values between h2o and numpy"
    assert check_values(h2o.trunc(h2o_data3[c]), np.trunc(np_data3[:,c])),   "expected equal trunc values between h2o and numpy"
    assert check_values(h2o.ceil(h2o_data3[c]), np.ceil(np_data3[:,c])),     "expected equal ceil values between h2o and numpy"
    assert check_values(h2o.floor(h2o_data3[c]), np.floor(np_data3[:,c])),   "expected equal floor values between h2o and numpy"
    assert check_values(h2o.log(h2o_data3[c]), np.log(np_data3[:,c])),       "expected equal log values between h2o and numpy"
    assert check_values(h2o.log10(h2o_data3[c]), np.log10(np_data3[:,c])),   "expected equal log10 values between h2o and numpy"
    assert check_values(h2o.log1p(h2o_data3[c]), np.log1p(np_data3[:,c])),   "expected equal log1p values between h2o and numpy"
    assert check_values(h2o.log2(h2o_data3[c]), np.log2(np_data3[:,c])),     "expected equal log2 values between h2o and numpy"
    assert check_values(h2o.exp(h2o_data3[c]), np.exp(np_data3[:,c])),       "expected equal exp values between h2o and numpy"
    assert check_values(h2o.expm1(h2o_data3[c]), np.expm1(np_data3[:,c])),   "expected equal expm1 values between h2o and numpy"
    assert (h2o.as_list(h2o.gamma(h2o_data3[c]))[5][0] - math.gamma(h2o.as_list(h2o_data3[c])[5][0])) < 1e-6, \
        "expected equal gamma values between h2o and math"
    assert (h2o.as_list(h2o.lgamma(h2o_data3[c]))[5][0] - math.lgamma(h2o.as_list(h2o_data3[c])[5][0])) < 1e-6, \
        "expected equal gamma values between h2o and math"
    assert (h2o.as_list(h2o.digamma(h2o_data3[c]))[5][0] - scipy.special.polygamma(0,h2o.as_list(h2o_data3[c])[5][0])) < 1e-6, \
        "expected equal gamma values between h2o and math"
    assert (h2o.as_list(h2o.trigamma(h2o_data3[c]))[5][0] - scipy.special.polygamma(1,h2o.as_list(h2o_data3[c])[5][0])) < 1e-6, \
        "expected equal gamma values between h2o and math"
Example #10
0
def vec_math_ops(ip,port):
    # Connect to h2o
    h2o.init(ip,port)

    sin_cos_tan_atan_sinh_cosh_tanh_asinh_data = [[random.uniform(-10,10) for r in range(10)] for c in range(10)]
    asin_acos_atanh_data = [[random.uniform(-1,1) for r in range(10)] for c in range(10)]
    acosh_data = [[random.uniform(1,10) for r in range(10)] for c in range(10)]
    abs_data = [[random.uniform(-100000,0) for r in range(10)] for c in range(10)]
    zero_one_data = [random.randint(0,1) for c in range(10)]
    zero_one_data = [zero_one_data, zero_one_data]

    h2o_data1 = h2o.H2OFrame(python_obj=sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    h2o_data2 = h2o.H2OFrame(python_obj=asin_acos_atanh_data)
    h2o_data3 = h2o.H2OFrame(python_obj=acosh_data)
    h2o_data4 = h2o.H2OFrame(python_obj=abs_data)
    h2o_data5 = h2o.H2OFrame(python_obj=zero_one_data)

    np_data1 = np.array(sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    np_data2 = np.array(asin_acos_atanh_data)
    np_data3 = np.array(acosh_data)
    np_data4 = np.array(abs_data)
    np_data5 = np.array(zero_one_data)

    row, col = h2o_data1.dim()

    c = random.randint(0,col-1)
    for d in range(1,6):
        h2o_signif = h2o.signif(h2o_data5[c], digits=d)
        h2o_round = h2o.round(h2o_data5[c], digits=d+4)
        s = h2o_signif[0]
        r = h2o_round[0]
        assert s == r, "Expected these to be equal, but signif: {0}, round: {1}".format(s, r)
    h2o_transposed = h2o.transpose(h2o_data1[c])
    x, y = h2o_transposed.dim()
    assert x == 1 and y == 10, "Expected 1 row and 10 columns, but got {0} rows and {1} columns".format(x,y)
    h2o.np_comparison_check(h2o.cos(h2o_data1[c]), np.cos(np_data1[:,c]), 10)
    h2o.np_comparison_check(h2o.sin(h2o_data1[c]), np.sin(np_data1[:,c]), 10)
    h2o.np_comparison_check(h2o.tan(h2o_data1[c]), np.tan(np_data1[:,c]), 10)
    h2o.np_comparison_check(h2o.acos(h2o_data2[c]), np.arccos(np_data2[:,c]), 10)
    h2o.np_comparison_check(h2o.asin(h2o_data2[c]), np.arcsin(np_data2[:,c]), 10)
    h2o.np_comparison_check(h2o.atan(h2o_data1[c]), np.arctan(np_data1[:,c]), 10)
    h2o.np_comparison_check(h2o.cosh(h2o_data1[c]), np.cosh(np_data1[:,c]), 10)
    h2o.np_comparison_check(h2o.sinh(h2o_data1[c]), np.sinh(np_data1[:,c]), 10)
    h2o.np_comparison_check(h2o.tanh(h2o_data1[c]), np.tanh(np_data1[:,c]), 10)
    h2o.np_comparison_check(h2o.acosh(h2o_data3[c]), np.arccosh(np_data3[:,c]), 10)
    h2o.np_comparison_check(h2o.asinh(h2o_data1[c]), np.arcsinh(np_data1[:,c]), 10)
    h2o.np_comparison_check(h2o.atanh(h2o_data2[c]), np.arctanh(np_data2[:,c]), 10)
    h2o.np_comparison_check(h2o.abs(h2o_data4[c]), np.fabs(np_data4[:,c]), 10)
    h2o.np_comparison_check(h2o.sign(h2o_data2[c]), np.sign(np_data2[:,c]), 10)
    h2o.np_comparison_check(h2o.sqrt(h2o_data3[c]), np.sqrt(np_data3[:,c]), 10)
    h2o.np_comparison_check(h2o.trunc(h2o_data3[c]), np.trunc(np_data3[:,c]), 10)
    h2o.np_comparison_check(h2o.ceil(h2o_data3[c]), np.ceil(np_data3[:,c]), 10)
    h2o.np_comparison_check(h2o.floor(h2o_data3[c]), np.floor(np_data3[:,c]), 10)
    h2o.np_comparison_check(h2o.log(h2o_data3[c]), np.log(np_data3[:,c]), 10)
    h2o.np_comparison_check(h2o.log10(h2o_data3[c]), np.log10(np_data3[:,c]), 10)
    h2o.np_comparison_check(h2o.log1p(h2o_data3[c]), np.log1p(np_data3[:,c]), 10)
    h2o.np_comparison_check(h2o.log2(h2o_data3[c]), np.log2(np_data3[:,c]), 10)
    h2o.np_comparison_check(h2o.exp(h2o_data3[c]), np.exp(np_data3[:,c]), 10)
    h2o.np_comparison_check(h2o.expm1(h2o_data3[c]), np.expm1(np_data3[:,c]), 10)
    h2o_val = h2o.gamma(h2o_data3[c])[5]
    num_val = math.gamma(h2o_data3[5,c])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal gamma values between h2o and" \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.lgamma(h2o_data3[c])[5]
    num_val = math.lgamma(h2o_data3[5,c])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal lgamma values between h2o and " \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.digamma(h2o_data3[c])[5]
    num_val = scipy.special.polygamma(0,h2o_data3[5,c])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal digamma values between h2o and " \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.trigamma(h2o_data3[c])[5]
    num_val = scipy.special.polygamma(1,h2o_data3[5,c])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal trigamma values between h2o and " \
        "math".format(h2o_val,num_val)
    for c in range(col):
        h2o_val = h2o.all(h2o_data5[c])
        num_val = True if np.all(np_data5[:,c]) else False
        assert h2o_val == num_val, "check unsuccessful! h2o computed {0} and numpy computed {1}. expected equal " \
                                   "values between h2o and numpy".format(h2o_val,num_val)
Example #11
0
def vec_math_ops(ip, port):
    # Connect to h2o
    h2o.init(ip, port)

    sin_cos_tan_atan_sinh_cosh_tanh_asinh_data = [
        [random.uniform(-10, 10) for r in range(10)] for c in range(10)
    ]
    asin_acos_atanh_data = [[random.uniform(-1, 1) for r in range(10)]
                            for c in range(10)]
    acosh_data = [[random.uniform(1, 10) for r in range(10)]
                  for c in range(10)]
    abs_data = [[random.uniform(-100000, 0) for r in range(10)]
                for c in range(10)]
    zero_one_data = [random.randint(0, 1) for c in range(10)]
    zero_one_data = [zero_one_data, zero_one_data]

    h2o_data1 = h2o.H2OFrame(
        python_obj=sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    h2o_data2 = h2o.H2OFrame(python_obj=asin_acos_atanh_data)
    h2o_data3 = h2o.H2OFrame(python_obj=acosh_data)
    h2o_data4 = h2o.H2OFrame(python_obj=abs_data)
    h2o_data5 = h2o.H2OFrame(python_obj=zero_one_data)

    np_data1 = np.array(sin_cos_tan_atan_sinh_cosh_tanh_asinh_data)
    np_data2 = np.array(asin_acos_atanh_data)
    np_data3 = np.array(acosh_data)
    np_data4 = np.array(abs_data)
    np_data5 = np.array(zero_one_data)

    row, col = h2o_data1.dim()

    c = random.randint(0, col - 1)
    for d in range(1, 6):
        h2o_signif = h2o.signif(h2o_data5[c], digits=d)
        h2o_round = h2o.round(h2o_data5[c], digits=d + 4)
        s = h2o_signif[0]
        r = h2o_round[0]
        assert s == r, "Expected these to be equal, but signif: {0}, round: {1}".format(
            s, r)
    h2o_transposed = h2o.transpose(h2o_data1[c])
    x, y = h2o_transposed.dim()
    assert x == 1 and y == 10, "Expected 1 row and 10 columns, but got {0} rows and {1} columns".format(
        x, y)
    h2o.np_comparison_check(h2o.cos(h2o_data1[c]), np.cos(np_data1[:, c]), 10)
    h2o.np_comparison_check(h2o.sin(h2o_data1[c]), np.sin(np_data1[:, c]), 10)
    h2o.np_comparison_check(h2o.tan(h2o_data1[c]), np.tan(np_data1[:, c]), 10)
    h2o.np_comparison_check(h2o.acos(h2o_data2[c]), np.arccos(np_data2[:, c]),
                            10)
    h2o.np_comparison_check(h2o.asin(h2o_data2[c]), np.arcsin(np_data2[:, c]),
                            10)
    h2o.np_comparison_check(h2o.atan(h2o_data1[c]), np.arctan(np_data1[:, c]),
                            10)
    h2o.np_comparison_check(h2o.cosh(h2o_data1[c]), np.cosh(np_data1[:, c]),
                            10)
    h2o.np_comparison_check(h2o.sinh(h2o_data1[c]), np.sinh(np_data1[:, c]),
                            10)
    h2o.np_comparison_check(h2o.tanh(h2o_data1[c]), np.tanh(np_data1[:, c]),
                            10)
    h2o.np_comparison_check(h2o.acosh(h2o_data3[c]),
                            np.arccosh(np_data3[:, c]), 10)
    h2o.np_comparison_check(h2o.asinh(h2o_data1[c]),
                            np.arcsinh(np_data1[:, c]), 10)
    h2o.np_comparison_check(h2o.atanh(h2o_data2[c]),
                            np.arctanh(np_data2[:, c]), 10)
    h2o.np_comparison_check(h2o.abs(h2o_data4[c]), np.fabs(np_data4[:, c]), 10)
    h2o.np_comparison_check(h2o.sign(h2o_data2[c]), np.sign(np_data2[:, c]),
                            10)
    h2o.np_comparison_check(h2o.sqrt(h2o_data3[c]), np.sqrt(np_data3[:, c]),
                            10)
    h2o.np_comparison_check(h2o.trunc(h2o_data3[c]), np.trunc(np_data3[:, c]),
                            10)
    h2o.np_comparison_check(h2o.ceil(h2o_data3[c]), np.ceil(np_data3[:, c]),
                            10)
    h2o.np_comparison_check(h2o.floor(h2o_data3[c]), np.floor(np_data3[:, c]),
                            10)
    h2o.np_comparison_check(h2o.log(h2o_data3[c]), np.log(np_data3[:, c]), 10)
    h2o.np_comparison_check(h2o.log10(h2o_data3[c]), np.log10(np_data3[:, c]),
                            10)
    h2o.np_comparison_check(h2o.log1p(h2o_data3[c]), np.log1p(np_data3[:, c]),
                            10)
    h2o.np_comparison_check(h2o.log2(h2o_data3[c]), np.log2(np_data3[:, c]),
                            10)
    h2o.np_comparison_check(h2o.exp(h2o_data3[c]), np.exp(np_data3[:, c]), 10)
    h2o.np_comparison_check(h2o.expm1(h2o_data3[c]), np.expm1(np_data3[:, c]),
                            10)
    h2o_val = h2o.gamma(h2o_data3[c])[5]
    num_val = math.gamma(h2o_data3[5, c])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal gamma values between h2o and" \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.lgamma(h2o_data3[c])[5]
    num_val = math.lgamma(h2o_data3[5, c])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal lgamma values between h2o and " \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.digamma(h2o_data3[c])[5]
    num_val = scipy.special.polygamma(0, h2o_data3[5, c])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal digamma values between h2o and " \
        "math".format(h2o_val,num_val)
    h2o_val = h2o.trigamma(h2o_data3[c])[5]
    num_val = scipy.special.polygamma(1, h2o_data3[5, c])
    assert abs(h2o_val - num_val) <  max(abs(h2o_val), abs(num_val)) * 1e-6, \
        "check unsuccessful! h2o computed {0} and math computed {1}. expected equal trigamma values between h2o and " \
        "math".format(h2o_val,num_val)
    for c in range(col):
        h2o_val = h2o.all(h2o_data5[c])
        num_val = True if np.all(np_data5[:, c]) else False
        assert h2o_val == num_val, "check unsuccessful! h2o computed {0} and numpy computed {1}. expected equal " \
                                   "values between h2o and numpy".format(h2o_val,num_val)