Esempio n. 1
0
from Conf.Settings import ASD_PATH, ASD_DW_PATH, ASD_DW_RESULTS_PATH, MIN_D_N, MAX_LAG, CUT_OFF, TYPICAL_PATH, \
    TYPICAL_DW_PATH, TYPICAL_DW_RESULTS_PATH, AVG_WIN_SIZE, FREQ_GAZE, AREA_FIX_TH
from Utils.Lib import filterFixation
import matplotlib.pyplot as plt
from nolds import sampen
from sklearn.neighbors import KernelDensity
import warnings

# set the processing
# ASD or TYPICAL
game_paths = [TYPICAL_PATH, ASD_PATH]
gaze_paths = [TYPICAL_DW_PATH, ASD_DW_PATH]
result_paths = [TYPICAL_DW_RESULTS_PATH, ASD_DW_RESULTS_PATH]

# Reader and removal
reader = DataReader()
removal = OutliersRemoval(cutoff=CUT_OFF)

# edges
xedges, yedges = np.arange(0, 101, 1), np.arange(0, 101, 1)
# x_grid, y_grid = np.mgrid[0:1:100j, 0:1:100j]
# positions = np.vstack([x_grid.ravel(), y_grid.ravel()])
for path in zip(game_paths, gaze_paths, result_paths):
    game_path = path[0]
    gaze_path = path[1]
    result_path = path[2]

    # read game data

    data_game, game_f_names = reader.readGameResults(game_path)
    data_game = removal.transformGameResult(
################################## IMPORTS ##################################

from Utils.SearchAbstractClass import SearchInputRecommenderArgs
from Utils.SearchBayesianSkopt import SearchBayesianSkopt
from skopt.space import Real, Integer, Categorical
from Utils.Evaluator import EvaluatorHoldout
from Utils.DataSplitter import DataSplitter
from Utils.DataReader import DataReader
import os

# Model to be tuned
from hybrid import Hybrid

################################# READ DATA #################################

reader = DataReader()
splitter = DataSplitter()

urm = reader.load_urm()
ICM = reader.load_icm()
URM_train, URM_val, URM_test = splitter.split(urm, validation=0.2, testing=0.1)

################################ EVALUATORS ##################################

evaluator_validation = EvaluatorHoldout(URM_val, [10])
evaluator_test = EvaluatorHoldout(URM_test, [10])

############################### OPTIMIZER SETUP ###############################

recommender_class = Hybrid
parameterSearch = SearchBayesianSkopt(
 def test_dataReader(self):
     reader = DataReader()
     removal = OutliersRemoval(cutoff=150)
     data_game, _ = reader.readGameResults(ASD_PATH)
     data_gaze, _, _ = reader.readGazeData(ASD_PATH)
     self.assertEqual(len(data_game), len(data_gaze))
    def fit(self,
            topK=50,
            shrink=100,
            similarity='cosine',
            normalization="none",
            feature_weighting="none",
            **similarity_args):

        self.topK = topK
        self.shrink = shrink

        reader = DataReader()
        icm = reader.load_icm()

        if normalization == "bm25":
            self.URM_train = similaripy.normalization.bm25(self.URM_train,
                                                           axis=1)
        if normalization == "tfidf":
            self.URM_train = similaripy.normalization.tfidf(self.URM_train,
                                                            axis=1)
        if normalization == "bm25plus":
            self.URM_train = similaripy.normalization.bm25plus(self.URM_train,
                                                               axis=1)

        if feature_weighting == "bm25":
            icm = similaripy.normalization.bm25(icm, axis=1)
        if feature_weighting == "tfidf":
            icm = similaripy.normalization.tfidf(icm, axis=1)
        if feature_weighting == "bm25plus":
            icm = similaripy.normalization.bm25plus(icm, axis=1)

        matrix = sps.hstack((self.URM_train.transpose().tocsr(), icm))

        if similarity == "cosine":
            similarity_matrix = similaripy.cosine(matrix,
                                                  k=self.topK,
                                                  shrink=self.shrink,
                                                  binary=False,
                                                  threshold=0)
        if similarity == "dice":
            similarity_matrix = similaripy.dice(matrix,
                                                k=self.topK,
                                                shrink=self.shrink,
                                                binary=False,
                                                threshold=0)
        if similarity == "jaccard":
            similarity_matrix = similaripy.jaccard(matrix,
                                                   k=self.topK,
                                                   shrink=self.shrink,
                                                   binary=False,
                                                   threshold=0)
        if similarity == "asym":
            similarity_matrix = similaripy.asymmetric_cosine(
                matrix,
                k=self.topK,
                shrink=self.shrink,
                binary=False,
                threshold=0)
        if similarity == "rp3beta":
            similarity_matrix = similaripy.rp3beta(matrix,
                                                   k=self.topK,
                                                   shrink=self.shrink,
                                                   binary=False,
                                                   threshold=0,
                                                   alpha=0.3,
                                                   beta=0.61)

        self.W_sparse = similarity_matrix
        self.W_sparse = check_matrix(self.W_sparse, format='csr')
Esempio n. 5
0
################################## IMPORTS ##################################

from Utils.Evaluator import EvaluatorHoldout
from Utils.DataSplitter import DataSplitter
from Utils.DataReader import DataReader
from hybrid import Hybrid
from tqdm import tqdm

################################# READ DATA #################################
reader = DataReader()
splitter = DataSplitter()
urm = reader.load_urm()
ICM = reader.load_icm()
targets = reader.load_target()

URM_train, URM_val, URM_test = splitter.split(urm, validation=0, testing=0)

####################### ISTANTIATE AND FIT THE HYBRID #######################

recommender = Hybrid(URM_train, ICM)
recommender.fit()

################################ PRODUCE CSV ################################

f = open("submission.csv", "w+")
f.write("user_id,item_list\n")
for t in tqdm(targets):
    recommended_items = recommender.recommend(t, cutoff=10, remove_seen_flag=True)
    well_formatted = " ".join([str(x) for x in recommended_items])
    f.write(f"{t}, {well_formatted}\n")
Esempio n. 6
0
import glob
import numpy as np
from Utils.DataReader import DataReader
from Utils.Lib import arParams, createDir
from Utils.OutliersRemoval import OutliersRemoval
from Conf.Settings import ASD_PATH, ASD_DW_PATH, MIN_D_N, CUT_OFF, TYPICAL_PATH, TYPICAL_DW_PATH
from scipy import interpolate
from statsmodels.tsa.ar_model import AR

max_lag = np.zeros(20)
max_llf = np.zeros(20)
aic_lag = np.zeros(20)
bic_lag = np.zeros(20)

# read game data
reader = DataReader()
removal = OutliersRemoval(cutoff=CUT_OFF)
# read typical data
typical_game, _ = reader.readGameResults(TYPICAL_PATH)
typical_game = removal.transformGameResult(typical_game)
_, typical_gaze_obj, _ = reader.readGazeData(TYPICAL_DW_PATH, downsample=True)

# read asd data
asd_game, _ = reader.readGameResults(ASD_PATH)
asd_game = removal.transformGameResult(asd_game)
_, asd_gaze_obj, _ = reader.readGazeData(ASD_DW_PATH, downsample=True)

data_game = typical_game + asd_game
data_gaze = typical_gaze_obj + asd_gaze_obj

for d in zip(data_game, data_gaze):
Esempio n. 7
0
"""
Created on 06/05/2018
@author Stefan
"""

from Domain.Network import Network
from Utils.DataReader import DataReader

if __name__ == '__main__':
    dr = DataReader()

    net = Network(21, 3, 2, 10)

    net.learning(dr.learningData)
    net.testing(dr.testData)