Esempio n. 1
0
def main(web_driver):
    nvidia_results, ldlc_results, materiel_results, top_achat_results, pc_componentes_results = ([], [], [], [], [])

    if(web_driver != None):
        print("- Checking nvidia.com")
        nvidia_results = bot.check_nvidia(util.nvidia_founders, web_driver)

        print("- Checking material.net")
        materiel_results = bot.check_materiel(util.materiel_urls, web_driver)

        web_driver.quit()
    else:
        print(" -- Skipping Javascript based sites")

    print("- Checking ldlc.com")
    ldlc_results = bot.check_ldlc(util.ldlc_urls) 

    print("- Checking topachat.com")
    top_achat_results = bot.check_top_achat(util.top_achat_url)

    print("- Checking pccomponentes.com")
    pc_componentes_results = bot.check_pc_componentes(util.pc_componentes_urls)

    full_list = ldlc_results + materiel_results + nvidia_results + top_achat_results + pc_componentes_results
    full_list = util.filter_results(full_list)
    util.print_results(full_list)
Esempio n. 2
0
def run(p_method, p_normalise = True, p_reverse_results = True):

    all_dirs = current.train + [current.test]

    for d in all_dirs:
        vectors[d] = {}
        util.read_files(util.get_files(dataset.DATA_DIRECTORY + d), d, vectors)

    if p_normalise:
        util.normalise(vectors)
    
    if p_method == Method.DOT_PRODUCT:
        dot.compute_dot_product(current, vectors, results)
    elif p_method == Method.DIRICHLET:
        bayes.calculate(current, vectors, results)
    elif p_method == Method.DIFFERENCE:
        dot.compute_difference(current, vectors, results)
    elif p_method == Method.PEARSON:
        pearson.compute(current, vectors, results)

    #bayes.cal(current, vectors, results)

    util.print_results(results, p_reverse_results, decimal_numbers)
Esempio n. 3
0
def run(p_method, p_normalise=True, p_reverse_results=True):

    all_dirs = current.train + [current.test]

    for d in all_dirs:
        vectors[d] = {}
        util.read_files(util.get_files(dataset.DATA_DIRECTORY + d), d, vectors)

    if p_normalise:
        util.normalise(vectors)

    if p_method == Method.DOT_PRODUCT:
        dot.compute_dot_product(current, vectors, results)
    elif p_method == Method.DIRICHLET:
        bayes.calculate(current, vectors, results)
    elif p_method == Method.DIFFERENCE:
        dot.compute_difference(current, vectors, results)
    elif p_method == Method.PEARSON:
        pearson.compute(current, vectors, results)

    #bayes.cal(current, vectors, results)

    util.print_results(results, p_reverse_results, decimal_numbers)
Esempio n. 4
0
    ticker = 'SPY'

    data = pd.read_csv(stock_io.format_data.format(ticker), header=0).tail(1500).reset_index(drop=True)
    
    low_vol_prediction = pd.read_csv(stock_io.file_pred_low.format(ticker), header=None)
    high_vol_prediction = pd.read_csv(stock_io.file_pred_high.format(ticker), header=None)
    
    final_prediction = pd.Series(low_vol_prediction[0]) + pd.Series(high_vol_prediction[0])

    mse = mean_squared_error(final_prediction.values, data['close'].tail(252).values)
    rmse = mse ** 0.5
    mape = util.mean_absolute_percentage_error(data['close'].tail(252).reset_index(drop=True), final_prediction)
    
    accuracy_act, accuracy_pred = util.get_sim_accuracy(data, final_prediction)
    
    util.print_results(accuracy_act, accuracy_pred,
                       mse, rmse, mape)
    
    


#
#        simulation[ma] = {'low_vol': {'prediction': low_vol_prediction, 'mse': low_vol_mse,
#                                      'rmse': low_vol_rmse, 'mape': low_vol_mape},
#                          'high_vol': {'prediction': high_vol_prediction, 'mse': high_vol_mse,
#                                       'rmse': high_vol_rmse},
#                          'final': {'prediction': final_prediction.values.tolist(), 'mse': mse,
#                                    'rmse': rmse, 'mape': mape},
#                          'accuracy': {'prediction vs close': accuracy_1, 'prediction vs prediction': accuracy_2}}
#
#        # save simulation data here as checkpoint
#        with open('simulation_data.json', 'w') as fp:
        train_x = train_data[emo_id, :, :-1]
        train_y = train_data[emo_id, :, -1:]
        test_x = test_data[emo_id, :, :-1]
        test_y = test_data[emo_id, :, -1:]

        k = GPy.kern.RBF(train_data[emo_id].shape[1] - 1)
        m = GPy.models.GPRegression(train_x, train_y, kernel=k)
        m.optimize_restarts(verbose=True, robust=True)
        preds = m.predict(test_x)[0]
        maes[emo] = MAE(preds, test_y)
        rmses[emo] = math.sqrt(MSE(preds, test_y))
        pearsons[emo] = pearsonr(preds, test_y)[0]
        all_labels = np.concatenate((all_labels, test_y.flatten()))
        all_preds = np.concatenate((all_preds, preds.flatten()))
    all_pearson = pearsonr(all_preds, all_labels)[0]
    return maes, rmses, pearsons, all_pearson, all_preds


if __name__ == "__main__":
    TRAIN_DATA = sys.argv[1]
    TEST_DATA = sys.argv[2]
    RESULTS_DIR = sys.argv[3]
    PREDS_DIR = sys.argv[4]
    train_data = scipy.io.loadmat(TRAIN_DATA)['out']
    test_data = scipy.io.loadmat(TEST_DATA)['out']
    maes, rmses, pearsons, all_pearson, all_preds = single_gp_experiment(
        train_data, test_data)
    np.savetxt(os.path.join(PREDS_DIR, 'single_gp.tsv'), all_preds)
    save_results(maes, rmses, pearsons, all_pearson, RESULTS_DIR)
    print_results(maes, rmses, pearsons, all_pearson)
Esempio n. 6
0
    for userID in FM_user_item_score:
        if user_kl_score[userID] <= threshold:
            continue
        NFM_item_scores = NFM_user_item_score[userID]
        DecFM_scores = []
        for i in range(len(NFM_item_scores)):
            itemID = user_candidates[userID][i]
            score = NFM_item_scores[i]
            DecFM_scores.append([itemID, score])
        DecFM_scores.sort(reverse=True, key=util.sort_function)

        user_item_gt.append(test_dict[userID])
        user_item_pred.append([x[0] for x in DecFM_scores[:1000]])
    print(f'user num {len(user_item_gt)}')
    test_result = util.computeTopNAccuracy(user_item_gt, user_item_pred, topN)
    util.print_results(None, None, test_result, None)

# print("DecNFM FM")
# threshold_list = [0, 0.5, 1, 2, 3, 4]
# alpha_list = [1]
# # alpha_list = [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]
# for threshold in threshold_list:
#     print(f'threshold {threshold}')
#     for alpha in alpha_list:
#         print(f'alpha {alpha}')
#         user_item_pred = []
#         user_item_gt = []
#         for userID in FM_user_item_score:
#             if user_kl_score[userID]<=threshold:
#                 continue
#             FM_item_scores = np.array(FM_user_item_score[userID])
Esempio n. 7
0
 def result(self):
   print_results(self.results)
Esempio n. 8
0
if __name__ == "__main__":
    TRAIN_DATA = sys.argv[1]
    TEST_DATA = sys.argv[2]
    RESULTS_DIR = sys.argv[3]
    PREDS_DIR = sys.argv[4]
    PLOTS_DIR = sys.argv[5]
    MODEL = sys.argv[6]
    if MODEL == "rank":
        RANK = int(sys.argv[7])
    else:
        RANK = 1
    train_data = scipy.io.loadmat(TRAIN_DATA)['out']
    test_data = scipy.io.loadmat(TEST_DATA)['out']
    maes, rmses, pearsons, all_pearson, all_preds, B = icm_gp_experiment(train_data,
                                                                         test_data,
                                                                         MODEL, RANK)
    if MODEL == "rank":
        preds_name = '_'.join([MODEL, str(RANK) + '.tsv'])
        plot_name = '_'.join([MODEL, str(RANK), 'matrix.png'])
    else:
        preds_name = MODEL + '.tsv'
        plot_name = '_'.join([MODEL, 'matrix.png'])
    np.savetxt(os.path.join(PREDS_DIR, preds_name), all_preds)
    print_results(maes, rmses, pearsons, all_pearson)
    save_results(maes, rmses, pearsons, all_pearson, RESULTS_DIR)

    plot_coreg_matrix(B, os.path.join(PLOTS_DIR, plot_name))
    
    
Esempio n. 9
0
def walktrap(G, t):

    N = G.number_of_nodes()

    if DEBUG:
        print("===== Graph Edges =====")
        print(G.edges)

    # Adjacency Matrix with self-loops
    A = nx.to_numpy_matrix(G, dtype=int)

    if DEBUG:
        print("===== Adjacency Matrix =====")
        print(A)

    # Diagonal Matrix
    D = nx.laplacian_matrix(G) + A

    # D^(-1/2). For distance calculation
    Dtemp = np.diagonal(D)
    if DEBUG:
        print("===== Diagonal Matrix's Diagonals =====")
        print(Dtemp)

    Dd = np.diag(np.power(Dtemp, (-0.5)))

    # Transition Matrix P
    P = inv(D) @ A

    # Transition Matrix P^t
    P_t = util.transition_matrix_after_t(P, t)

    # Initialize Partition 1, its modularity, and community
    part = []
    for n in G.nodes:
        community[n] = [n]
        part.append([n])
    partition[1] = part
    compute_modularity(1, G)
    #compute_optimal_modularity(1, G, A)

    # Populate initial comm dictionary
    for C in part:
        comm[str(C)] = util.community_to_adj(P_t, C)

    # Populate initial variance
    for (s, d) in G.edges:
        if s != d:
            variance[util.sort_communities_str([s], [d])] = \
             compute_variance_linear(N, Dd, [s], [d])

    # Start algorithm
    for step in range(1, N):

        if DEBUG:
            print("Step " + str(step))

        # Choose two communities based on variance
        (C1, C2) = choose_communities()

        # Sorted communities
        C3 = util.sort_communities(C1, C2)

        # Insert new partition and its modularity
        part = list(partition.get(step))

        part.remove(C1)
        part.remove(C2)
        part.append(C3)
        partition[step + 1] = part
        compute_modularity(step + 1, G)
        #compute_optimal_modularity(step+1, G, A)
        if DEBUG:
            print("Partition " + str(step + 1))
            print(part)

        # Update comm dict by removing C1 and C2
        # and adding C3
        update_comm(C1, C2, C3)

        # Update new community for each node and
        # find all adjacent vertices in C3
        adj_vertices = set()
        for v in C3:
            community[v] = sorted(C3)
            adj_vertices |= set(G.adj[v])

        # Remove duplicates and vertices already in C3
        adj_vertices = list(adj_vertices - set(C3))

        # Find existing communities for each vertice
        adj_communities = []
        for C in adj_vertices:
            adj_communities.append(community[C])

        # Remove duplicates from adj_communities
        adj_communities = \
         list(dict((x[0], x) for x in adj_communities).values())
        # Update distance between C3 and its adjacent communities
        for C in adj_communities:
            var = 0
            if check_compute_variance(C1, C2, C):
                var = compute_variance_constant(C1, C2, C)
            else:
                var = compute_variance_linear(N, Dd, C3, C)
            update_variance(C1, C2, C3, C, var)

        if DEBUG:
            print("Variance: ")
            print(variance)

    if DEBUG:
        print("===== Partitions =====")
        print(partition)
        print("===== Modularities =====")
        print(Q)

    util.print_results(partition, Q)

    bp = partition[max(Q, key=Q.get)]

    # Uncomment for Graph Plot
    # util.graph_plot(G, bp)

    # Return best partition
    return bp