def frame_math_ops(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_data5.signif(digits=d) h2o_round = h2o_data5.round(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_data1[0:5].transpose() 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) tests.np_comparison_check(h2o_transposed, np.transpose(np_data1[:, 0:5]), 10) tests.np_comparison_check(h2o_data1.cos(), np.cos(np_data1), 10) tests.np_comparison_check(h2o_data1.sin(), np.sin(np_data1), 10) tests.np_comparison_check(h2o_data1.tan(), np.tan(np_data1), 10)
def expr_reducers(): data = [[random.uniform(-10000,10000) for r in range(10)] for c in range(10)] h2o_data_1 = h2o.H2OFrame(python_obj=data) np_data = np.array(data) row, col = h2o_data_1.dim h2o_data = h2o_data_1 + 2 np_data = np_data + 2 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_data[r,c] 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_val = h2o_data.min() num_val = np.min(np_data) assert abs(h2o_val - num_val) < 1e-06, \ "check unsuccessful! h2o computed {0} and numpy computed {1}. expected equal min values between h2o and " \ "numpy".format(h2o_val,num_val) h2o_val = h2o_data.max() num_val = np.max(np_data) assert abs(h2o_val - num_val) < 1e-06, \ "check unsuccessful! h2o computed {0} and numpy computed {1}. expected equal max values between h2o and " \ "numpy".format(h2o_val,num_val) h2o_val = h2o_data.sum() num_val = np.sum(np_data) assert abs(h2o_val - num_val) < 1e-06, \ "check unsuccessful! h2o computed {0} and numpy computed {1}. expected equal sum values between h2o and " \ "numpy".format(h2o_val,num_val) tests.np_comparison_check(h2o_data.var(), np.cov(np_data, rowvar=0, ddof=1), 10), \ "expected equal var values between h2o and numpy"
def expr_reducers(): data = [[random.uniform(-10000, 10000) for r in range(10)] for c in range(10)] h2o_data_1 = h2o.H2OFrame(python_obj=data) np_data = np.array(data) row, col = h2o_data_1.dim h2o_data = h2o_data_1 + 2 np_data = np_data + 2 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_data[r, c] 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_val = h2o_data.min() num_val = np.min(np_data) assert abs(h2o_val - num_val) < 1e-06, \ "check unsuccessful! h2o computed {0} and numpy computed {1}. expected equal min values between h2o and " \ "numpy".format(h2o_val,num_val) h2o_val = h2o_data.max() num_val = np.max(np_data) assert abs(h2o_val - num_val) < 1e-06, \ "check unsuccessful! h2o computed {0} and numpy computed {1}. expected equal max values between h2o and " \ "numpy".format(h2o_val,num_val) h2o_val = h2o_data.sum() num_val = np.sum(np_data) assert abs(h2o_val - num_val) < 1e-06, \ "check unsuccessful! h2o computed {0} and numpy computed {1}. expected equal sum values between h2o and " \ "numpy".format(h2o_val,num_val) tests.np_comparison_check(h2o_data.var(), np.cov(np_data, rowvar=0, ddof=1), 10), \ "expected equal var values between h2o and numpy"
def frame_math_ops(): 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_data5.signif(digits=d) h2o_round = h2o_data5.round(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_data1[0:5].transpose() 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) tests.np_comparison_check(h2o_transposed, np.transpose(np_data1[:, 0:5]), 10) tests.np_comparison_check(h2o_data1.cos(), np.cos(np_data1), 10) tests.np_comparison_check(h2o_data1.sin(), np.sin(np_data1), 10) tests.np_comparison_check(h2o_data1.tan(), np.tan(np_data1), 10)
def expr_math_ops(): 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 tests.np_comparison_check(h2o_data1.cos(), np.cos(np_data1), 10) tests.np_comparison_check(h2o_data1.sin(), np.sin(np_data1), 10) tests.np_comparison_check(h2o_data1.tan(), np.tan(np_data1), 10) tests.np_comparison_check(h2o_data2.acos(), np.arccos(np_data2), 10) tests.np_comparison_check(h2o_data2.asin(), np.arcsin(np_data2), 10) tests.np_comparison_check(h2o_data1.atan(), np.arctan(np_data1), 10) tests.np_comparison_check(h2o_data1.cosh(), np.cosh(np_data1), 10) tests.np_comparison_check(h2o_data1.sinh(), np.sinh(np_data1), 10) tests.np_comparison_check(h2o_data1.tanh(), np.tanh(np_data1), 10) tests.np_comparison_check(h2o_data3.acosh(), np.arccosh(np_data3), 10) tests.np_comparison_check(h2o_data1.asinh(), np.arcsinh(np_data1), 10) tests.np_comparison_check(h2o_data2.atanh(), np.arctanh(np_data2), 10) tests.np_comparison_check((h2o_data2/math.pi).cospi(), np.cos(np_data2), 10) tests.np_comparison_check((h2o_data2/math.pi).sinpi(), np.sin(np_data2), 10) tests.np_comparison_check((h2o_data2/math.pi).tanpi(), np.tan(np_data2), 10) tests.np_comparison_check(h2o_data4.abs(), np.fabs(np_data4), 10) tests.np_comparison_check(h2o_data2.sign(), np.sign(np_data2), 10) tests.np_comparison_check(h2o_data3.sqrt(), np.sqrt(np_data3), 10) tests.np_comparison_check(h2o_data3.trunc(), np.trunc(np_data3), 10) tests.np_comparison_check(h2o_data3.ceil(), np.ceil(np_data3), 10) tests.np_comparison_check(h2o_data3.floor(), np.floor(np_data3), 10) tests.np_comparison_check(h2o_data3.log(), np.log(np_data3), 10) tests.np_comparison_check(h2o_data3.log10(), np.log10(np_data3), 10) tests.np_comparison_check(h2o_data3.log1p(), np.log1p(np_data3), 10) tests.np_comparison_check(h2o_data3.log2(), np.log2(np_data3), 10) tests.np_comparison_check(h2o_data3.exp(), np.exp(np_data3), 10) tests.np_comparison_check(h2o_data3.expm1(), np.expm1(np_data3), 10) h2o_val = h2o_data3.gamma()[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_data3.lgamma()[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_data3.digamma()[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_data3.trigamma()[5,5] num_val = float(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 expr_math_ops(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 tests.np_comparison_check(h2o_data1.cos(), np.cos(np_data1), 10) tests.np_comparison_check(h2o_data1.sin(), np.sin(np_data1), 10) tests.np_comparison_check(h2o_data1.tan(), np.tan(np_data1), 10) tests.np_comparison_check(h2o_data2.acos(), np.arccos(np_data2), 10) tests.np_comparison_check(h2o_data2.asin(), np.arcsin(np_data2), 10) tests.np_comparison_check(h2o_data1.atan(), np.arctan(np_data1), 10) tests.np_comparison_check(h2o_data1.cosh(), np.cosh(np_data1), 10) tests.np_comparison_check(h2o_data1.sinh(), np.sinh(np_data1), 10) tests.np_comparison_check(h2o_data1.tanh(), np.tanh(np_data1), 10) tests.np_comparison_check(h2o_data3.acosh(), np.arccosh(np_data3), 10) tests.np_comparison_check(h2o_data1.asinh(), np.arcsinh(np_data1), 10) tests.np_comparison_check(h2o_data2.atanh(), np.arctanh(np_data2), 10) tests.np_comparison_check((h2o_data2/math.pi).cospi(), np.cos(np_data2), 10) tests.np_comparison_check((h2o_data2/math.pi).sinpi(), np.sin(np_data2), 10) tests.np_comparison_check((h2o_data2/math.pi).tanpi(), np.tan(np_data2), 10) tests.np_comparison_check(h2o_data4.abs(), np.fabs(np_data4), 10) tests.np_comparison_check(h2o_data2.sign(), np.sign(np_data2), 10) tests.np_comparison_check(h2o_data3.sqrt(), np.sqrt(np_data3), 10) tests.np_comparison_check(h2o_data3.trunc(), np.trunc(np_data3), 10) tests.np_comparison_check(h2o_data3.ceil(), np.ceil(np_data3), 10) tests.np_comparison_check(h2o_data3.floor(), np.floor(np_data3), 10) tests.np_comparison_check(h2o_data3.log(), np.log(np_data3), 10) tests.np_comparison_check(h2o_data3.log10(), np.log10(np_data3), 10) tests.np_comparison_check(h2o_data3.log1p(), np.log1p(np_data3), 10) tests.np_comparison_check(h2o_data3.log2(), np.log2(np_data3), 10) tests.np_comparison_check(h2o_data3.exp(), np.exp(np_data3), 10) tests.np_comparison_check(h2o_data3.expm1(), np.expm1(np_data3), 10) h2o_val = h2o_data3.gamma()[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_data3.lgamma()[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_data3.digamma()[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_data3.trigamma()[5,5] num_val = float(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 vec_math_ops(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_data5[c].signif(digits=d) h2o_round = h2o_data5[c].round(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_data1[c].transpose() 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) tests.np_comparison_check(h2o_data1[:,c].cos(), np.cos(np_data1[:,c]), 10) tests.np_comparison_check(h2o_data1[:,c].sin(), np.sin(np_data1[:,c]), 10) tests.np_comparison_check(h2o_data1[:,c].tan(), np.tan(np_data1[:,c]), 10) tests.np_comparison_check(h2o_data2[:,c].acos(), np.arccos(np_data2[:,c]), 10) tests.np_comparison_check(h2o_data2[:,c].asin(), np.arcsin(np_data2[:,c]), 10) tests.np_comparison_check(h2o_data1[:,c].atan(), np.arctan(np_data1[:,c]), 10) tests.np_comparison_check(h2o_data1[:,c].cosh(), np.cosh(np_data1[:,c]), 10) tests.np_comparison_check(h2o_data1[c].sinh(), np.sinh(np_data1[:,c]), 10) tests.np_comparison_check(h2o_data1[c].tanh(), np.tanh(np_data1[:,c]), 10) tests.np_comparison_check(h2o_data3[c].acosh(), np.arccosh(np_data3[:,c]), 10) tests.np_comparison_check(h2o_data1[c].asinh(), np.arcsinh(np_data1[:,c]), 10) h2o_val = h2o_data3[c].gamma()[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_data3[c].lgamma()[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_data3[c].digamma()[5,:]._scalar() 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_data3[c].trigamma()[5,:] num_val = scipy.special.polygamma(1,h2o_data3[5,c]) assert abs(h2o_val - float(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 op_precedence(ip,port): # Connect to a pre-existing cluster a = [[random.uniform(-100,100) for r in range(10)] for c in range(10)] b = [[random.uniform(-100,100) for r in range(10)] for c in range(10)] c = [[random.uniform(-100,100) for r in range(10)] for c in range(10)] A = h2o.H2OFrame(python_obj=a) B = h2o.H2OFrame(python_obj=b) C = h2o.H2OFrame(python_obj=c) np_A = np.array(a) np_B = np.array(b) np_C = np.array(c) s1 = np_A + np_B * np_C s2 = np_A - np_B - np_C s3 = np_A ** 1 ** 2 s4 = np.logical_and(np_A == np_B, np_C) s5 = np_A == np_B + np_C s6 = np.logical_and(np.logical_or(np_A, np_B), np_C) print "Check A + B * C" S1 = A + B * C tests.np_comparison_check(S1, s1, 10) print "Check A - B - C" S2 = A - B - C tests.np_comparison_check(S2, s2, 10) print "Check A ^ 2 ^ 3" S3 = A ** 1 ** 2 tests.np_comparison_check(S3, s3, 10) print "Check A == B & C" S4 = A == B & C tests.np_comparison_check(S4, s4, 10) print "Check A == B + C" S5 = A == B + C tests.np_comparison_check(S5, s5, 10) print "Check A | B & C" S6 = A | B & C tests.np_comparison_check(S6, s6, 10)