def runMultTest(transaction_list, trans4lcm, threshold, set_method, lcm_path, max_comb, outlog, alternative): max_lambda = maxLambda(transaction_list) lam_star = 1; func_f = None; try: if set_method == "fisher": func_f = functions4fisher.FunctionOfX(transaction_list, max_lambda, abs(alternative)) elif set_method == "u_test": func_f = functions4u_test.FunctionOfX(transaction_list, alternative) elif set_method == "chi": func_f = functions4chi.FunctionOfX(transaction_list, max_lambda, abs( alternative)) else: sys.stderr.write("Error: choose \"fisher\", \"chi\" or \"u_test\" by using -p option.\n") outlog.close() sys.exit() lam = max_lambda # check a MASL of max_lambda if set_method in BINARY_METHODS: n1 = func_f.sumValue(transaction_list) if (n1 < max_lambda): max_lambda = int( n1 ) lam = int( n1 ) fre_pattern = frequentPatterns.LCM(lcm_path, max_lambda, outlog) fre_pattern.makeFile4Lem(transaction_list, trans4lcm) # make itemset file for lcm # If Fisher's exact test or chi-square test is used for computing P-value, # LCM-LAMP is run to find optimal lambda. if set_method == "fisher": neg_size = func_f.getAllSize() - func_f.getN1() n1 = min( n1, neg_size ) # # of positives == # of negatives, and two.sided hypothesis test. if ( func_f.getN1() == neg_size ) and (alternative == 0): fre_pattern, lam_star = depthFirst( trans4lcm, fre_pattern, max_comb, n1, 0.5*threshold, 1 ) else: fre_pattern, lam_star = depthFirst( trans4lcm, fre_pattern, max_comb, n1, threshold, 1 ) elif set_method == "chi": neg_size = func_f.getAllSize() - func_f.getN1() n1 = min( n1, neg_size ) # two-sided hypothesis test if alternative == 0: fre_pattern, lam_star = depthFirst( trans4lcm, fre_pattern, max_comb, n1, 0.5*threshold, 2 ) # one-sided else: fre_pattern, lam_star = depthFirst( trans4lcm, fre_pattern, max_comb, n1, threshold, 2 ) # If Mann-Whitney U test of Chi-square test is used, # LAMP ver 1. is run for computing the optimal lambda. else: # two-sided hypothesis test if alternative == 0: fre_pattern, lam_star = breadthFirst( trans4lcm, fre_pattern, func_f, max_comb, 0.5*threshold, lam, outlog ) # one-sided hypothesis test else: fre_pattern, lam_star = breadthFirst( trans4lcm, fre_pattern, func_f, max_comb, threshold, lam, outlog ) except fs.TestMethodError, e: sys.exit()
sys.exit except fs.TestMethodError, e: sys.exit() try: lam = max_lambda # check a MASL of max_lambda if (set_method == 'fisher') or (set_method == 'chi'): n1 = func_f.sumValue(transaction_list) if (n1 < max_lambda): max_lambda = int(n1) lam = int(n1) fre_pattern = frequentPatterns.LCM(lcm_path, max_lambda, outlog) fre_pattern.makeFile4Lem(transaction_list, trans4lcm) # make itemset file for lcm # If file for Lcm exist, comfiem that overwrite the file. # solve K and lambda while lam > 1: outlog.write("--- lambda: " + str(lam) + " ---\n") # if lambda == 1, all tests which support >= 1 are tested. if lam == 1: lam_star = lam fre_pattern.frequentPatterns(trans4lcm, lam, max_comb) # line 3 of Algorithm k = fre_pattern.getTotal(lam) break fre_pattern.frequentPatterns(trans4lcm, lam,
def runMultTest(transaction_list, trans4lcm, threshold, set_method, lcm_path, max_comb, outlog, alternative): max_lambda = maxLambda(transaction_list) lam_star = 1 func_f = None try: if set_method == "fisher": func_f = functions4fisher.FunctionOfX(transaction_list, max_lambda, abs(alternative)) elif set_method == "u_test": func_f = functions4u_test.FunctionOfX(transaction_list, alternative) elif set_method == "chi": func_f = functions4chi.FunctionOfX(transaction_list, max_lambda, abs(alternative)) else: sys.stderr.write( "Error: choose \"fisher\", \"chi\" or \"u_test\" by using -p option.\n" ) outlog.close() sys.exit() lam = max_lambda # check a MASL of max_lambda if set_method in BINARY_METHODS: n1 = func_f.sumValue(transaction_list) if (n1 < max_lambda): max_lambda = int(n1) lam = int(n1) fre_pattern = frequentPatterns.LCM(lcm_path, max_lambda, outlog) fre_pattern.makeFile4Lem(transaction_list, trans4lcm) # make itemset file for lcm # If Fisher's exact test or chi-square test is used for computing P-value, # LCM-LAMP is run to find optimal lambda. if set_method == "fisher": neg_size = func_f.getAllSize() - func_f.getN1() n1 = min(n1, neg_size) # # of positives == # of negatives, and two.sided hypothesis test. if (func_f.getN1() == neg_size) and (alternative == 0): fre_pattern, lam_star = depthFirst(trans4lcm, fre_pattern, max_comb, n1, 0.5 * threshold, 1) else: fre_pattern, lam_star = depthFirst(trans4lcm, fre_pattern, max_comb, n1, threshold, 1) elif set_method == "chi": neg_size = func_f.getAllSize() - func_f.getN1() n1 = min(n1, neg_size) # two-sided hypothesis test if alternative == 0: fre_pattern, lam_star = depthFirst(trans4lcm, fre_pattern, max_comb, n1, 0.5 * threshold, 2) # one-sided else: fre_pattern, lam_star = depthFirst(trans4lcm, fre_pattern, max_comb, n1, threshold, 2) # If Mann-Whitney U test of Chi-square test is used, # LAMP ver 1. is run for computing the optimal lambda. else: # two-sided hypothesis test if alternative == 0: fre_pattern, lam_star = breadthFirst(trans4lcm, fre_pattern, func_f, max_comb, 0.5 * threshold, lam, outlog) # one-sided hypothesis test else: fre_pattern, lam_star = breadthFirst(trans4lcm, fre_pattern, func_f, max_comb, threshold, lam, outlog) except fs.TestMethodError as e: sys.exit() except frequentPatterns.LCMError as e: sys.exit() try: fre_pattern.frequentPatterns(trans4lcm, lam_star, max_comb) # P_lambda* at line 13 k = fre_pattern.getTotal(lam_star) except frequentPatterns.LCMError as e: sys.exit() # multiple test by using k and lambda_star outlog.write("finish calculation of K: %s\n" % k) # If lam_star > max_lambda, m_lambda set to max_lambda. # This case cause when optimal solution is found at first step. outlog.write("%s\n" % lam_star) if (lam_star > max_lambda): lam_star = max_lambda correction_term_time = time.time() return (fre_pattern, lam_star, max_lambda, correction_term_time, func_f)