Skip to content

Commit

Permalink
fixed device and added models
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdiz5 committed Dec 14, 2024
1 parent d99c8d8 commit 268faef
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cornac/models/globallocalkernel/recom_globallocalkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def __init__(
self.verbose = verbose

# Device
if torch.cuda.is_available() and (self.device != 'cpu'):
if torch.cuda.is_available():
self.device = torch.device("cuda")
else:
self.device = torch.device("cpu")
Expand Down
86 changes: 86 additions & 0 deletions experiment_log_1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@

========================================
Experiment conducted on: 2024-12-14 22:16:07.572951

Hyperparameters:
name: GlobalLocalKernel
trainable: True
verbose: False
is_fitted: False
ignored_attrs: ['train_set', 'val_set', 'test_set']
num_users: None
num_items: 1656
uid_map: None
iid_map: None
max_rating: 4.0
min_rating: 1.0
global_mean: None
_Recommender__user_ids: None
_Recommender__item_ids: None
n_hid: 10
n_dim: 2
n_layers: 2
lambda_s: 0.006
lambda_2: 0.001
gk_size: 3
dot_scale: 1
max_epoch_p: 500
max_epoch_f: 500
tol_p: 0.0001
tol_f: 1e-05
patience_p: 10
patience_f: 10
lr_p: 0.1
lr_f: 0.01
device: cuda
model: CompleteNet(
(local_kernel_net): KernelNet(
(layers): ModuleList(
(0-1): 2 x KernelLayer(
(activation): Sigmoid()
)
(2): KernelLayer(
(activation): Identity()
)
)
(dropout): Dropout(p=0.33, inplace=False)
)
)
train_r_local: [[4.18834 3.834389 4.190889 ... 3.719673 4.9786563 4.025386 ]
[4.1866603 3.833935 4.1901083 ... 3.7193959 4.9786563 4.0248137]
[3.643859 3.643947 3.9684842 ... 3.4783204 4.9786563 3.7472897]
...
[3.0270095 3.4925659 3.7013142 ... 3.32962 4.9786563 3.496717 ]
[3.030718 3.493905 3.7029653 ... 3.3311675 4.9786563 3.4985132]
[3.030718 3.493905 3.7029653 ... 3.3311675 4.9786563 3.4985132]]
_train_r: [[4. 0. 0. ... 0. 0. 0.]
[0. 5. 0. ... 0. 0. 0.]
[0. 0. 5. ... 0. 0. 0.]
...
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]]
_train_mask: [[1. 0. 0. ... 0. 0. 0.]
[0. 1. 0. ... 0. 0. 0.]
[0. 0. 1. ... 0. 0. 0.]
...
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]]

Test Results:
Early stopping fine-tuning at epoch: 380
Early stopping fine-tuning at epoch: 381
Early stopping fine-tuning at epoch: 391
Early stopping fine-tuning at epoch: 401
Early stopping fine-tuning at epoch: 411
Early stopping fine-tuning at epoch: 432

TEST:
...
| MAE | RMSE | AUC | MAP | NDCG@10 | Precision@10 | Recall@10 | Train (s) | Test (s)
----------------- + ------ + ------ + ------ + ------ + ------- + ------------ + --------- + --------- + --------
GlobalLocalKernel | 0.8034 | 0.9727 | 0.5107 | 0.0189 | 0.0217 | 0.0192 | 0.0133 | 28.9218 | 190.2286


========================================
83 changes: 83 additions & 0 deletions experiment_log_2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

========================================
Experiment conducted on: 2024-12-14 22:22:56.926776

Hyperparameters:
name: GlobalLocalKernel
trainable: True
verbose: False
is_fitted: False
ignored_attrs: ['train_set', 'val_set', 'test_set']
num_users: None
num_items: 1656
uid_map: None
iid_map: None
max_rating: 4.0
min_rating: 1.0
global_mean: None
_Recommender__user_ids: None
_Recommender__item_ids: None
n_hid: 10
n_dim: 2
n_layers: 2
lambda_s: 0.006
lambda_2: 0.001
gk_size: 3
dot_scale: 1
max_epoch_p: 500
max_epoch_f: 500
tol_p: 0.0001
tol_f: 1e-05
patience_p: 10
patience_f: 10
lr_p: 0.1
lr_f: 0.01
device: cuda
model: CompleteNet(
(local_kernel_net): KernelNet(
(layers): ModuleList(
(0-1): 2 x KernelLayer(
(activation): Sigmoid()
)
(2): KernelLayer(
(activation): Identity()
)
)
(dropout): Dropout(p=0.33, inplace=False)
)
)
train_r_local: [[4.074561 3.7919703 4.1602736 ... 3.5502026 4.9746857 3.943836 ]
[4.0745606 3.79197 4.1602736 ... 3.5502021 4.9746857 3.9438357]
[3.7859447 3.7108083 4.024741 ... 3.356383 4.9746857 3.8038127]
...
[3.1270785 3.4874184 3.683483 ... 3.1386068 4.9746857 3.4953837]
[3.1272159 3.4874575 3.6835485 ... 3.1387024 4.9746857 3.4954498]
[3.1272159 3.4874575 3.6835485 ... 3.1387024 4.9746857 3.4954498]]
_train_r: [[4. 0. 0. ... 0. 0. 0.]
[0. 5. 0. ... 0. 0. 0.]
[0. 0. 5. ... 0. 0. 0.]
...
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]]
_train_mask: [[1. 0. 0. ... 0. 0. 0.]
[0. 1. 0. ... 0. 0. 0.]
[0. 0. 1. ... 0. 0. 0.]
...
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]
[0. 0. 0. ... 0. 0. 0.]]

Test Results:

TEST:
...
| MAE | RMSE | AUC | MAP | NDCG@10 | Precision@10 | Recall@10 | Train (s) | Test (s)
----------------- + ------ + ------ + ------ + ------ + ------- + ------------ + --------- + --------- + --------
GlobalLocalKernel | 0.8051 | 0.9771 | 0.5428 | 0.0232 | 0.0261 | 0.0254 | 0.0169 | 30.8466 | 191.1777
MF | 0.7430 | 0.8998 | 0.7445 | 0.0548 | 0.0761 | 0.0675 | 0.0463 | 0.0290 | 0.7707
PMF | 0.7534 | 0.9138 | 0.7744 | 0.0671 | 0.0969 | 0.0813 | 0.0639 | 1.4337 | 1.1157
BPR | 2.0143 | 2.2267 | 0.8695 | 0.1042 | 0.1500 | 0.1110 | 0.1195 | 1.2896 | 0.7294


========================================
11 changes: 8 additions & 3 deletions try.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from cornac.models import GlobalLocalKernel
from cornac.eval_methods import RatioSplit
from cornac.metrics import MAE, RMSE, Precision, Recall, NDCG, AUC, MAP
from cornac.models import MF, PMF, BPR

# Function to find the next available log file name
def get_next_log_file(base_name="experiment_log", ext=".txt"):
Expand Down Expand Up @@ -49,13 +50,17 @@ def log_results(log_file, test_results, model_instance):
# Example hyperparameters
n_hid=10,
n_dim=2,
max_epoch_p=30,
max_epoch_f=100,
max_epoch_p=500,
max_epoch_f=500,
lr_p=0.1,
lr_f=0.01,
verbose=False
)

mf = MF(k=10, max_iter=25, learning_rate=0.01, lambda_reg=0.02, use_bias=True, seed=123)
pmf = PMF(k=10, max_iter=100, learning_rate=0.001, lambda_reg=0.001, seed=123)
bpr = BPR(k=10, max_iter=200, learning_rate=0.001, lambda_reg=0.01, seed=123)

# Define some basic metrics
metrics = [MAE(), RMSE(), Precision(k=10), Recall(k=10), NDCG(k=10), AUC(), MAP()]

Expand All @@ -68,7 +73,7 @@ def log_results(log_file, test_results, model_instance):
sys.stdout = StringIO() # Redirect stdout to capture results

# Run the experiment on the smaller subset
cornac.Experiment(eval_method=rs, models=[my_model], metrics=metrics, user_based=True).run()
cornac.Experiment(eval_method=rs, models=[my_model, mf, pmf, bpr], metrics=metrics, user_based=True).run()

# Retrieve experiment results
experiment_results = sys.stdout.getvalue()
Expand Down

0 comments on commit 268faef

Please sign in to comment.