# -*- coding: utf-8 -*-
"""
Created on Wed Apr  6 18:14:46 2016

@author: Balázs Hidasi
"""

import sys
sys.path.append('../..')

import numpy as np
import pandas as pd
from tqdm import tqdm
import gru4rec
import evaluation

PATH_TO_TRAIN = 'reddit_train_full.txt'
PATH_TO_TEST = 'reddit_test.txt'

if __name__ == '__main__':
    data = pd.read_csv(PATH_TO_TRAIN, sep='\t', dtype={'ItemId':np.int64})
    valid = pd.read_csv(PATH_TO_TEST, sep='\t', dtype={'ItemId':np.int64})
    
    #Reproducing results from "Session-based Recommendations with Recurrent Neural Networks" on RSC15 (http://arxiv.org/abs/1511.06939)
    for x in tqdm(range(10,100)):
        print('Training GRU4Rec with '+str(x)+' hidden units')
        for y in range(1,50):
            gru = gru4rec.GRU4Rec(loss='top1', final_act='tanh', hidden_act='tanh', 
                                  layers=[x], batch_size=y, dropout_p_hidden=0.5, learning_rate=0.01, momentum=0.0,
                                  time_sort=False)
            gru.fit(data)
            print('---------------------')
            print()
            print('Training params')
            print('Layers: '+str(x))
            print('Batch size: '+str(y))
            print('Final act: tanh')
            print('Hidden act: tanh')
            print('Learning rate: 0.01')
            print('dropout p: 0.5')
            print('Time sort: False')
            print('---Evaluation Phase---')
            res = evaluation.evaluate_sessions_batch(gru, valid, None)
            print()
            print('Results')
            print('Recall@20: {}'.format(res[0]))
            print()
            print('MRR@20: {}'.format(res[1]))
    
    
    #Reproducing results from "Recurrent Neural Networks with Top-k Gains for Session-based Recommendations" on RSC15 (http://arxiv.org/abs/1706.03847)
    
   # print('Training GRU4Rec with 100 hidden units')

    #gru = gru4rec.GRU4Rec(loss='bpr-max-0.5', final_act='linear', hidden_act='tanh', layers=[100], batch_size=32, dropout_p_hidden=0.0, learning_rate=0.2, momentum=0.5, n_sample=2048, sample_alpha=0, time_sort=True)
    #gru.fit(data)
    
    #res = evaluation.evaluate_sessions_batch(gru, valid, None)
    #print('Recall@20: {}'.format(res[0]))
    #print('MRR@20: {}'.format(res[1]))