Skip to content

Commit

Permalink
ComputeLoss -> ComputeObjective
Browse files Browse the repository at this point in the history
  • Loading branch information
zenogantner committed Feb 4, 2012
1 parent 6e8ee09 commit 4a2d15c
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion doc/Changes
Expand Up @@ -9,7 +9,7 @@
- move PredictItems from ItemRecommendation.Extensions to Extensions,
add method ScoreItems
- add interface IFoldInRatingPredictor with extension methods
- IIterativeModel.ComputeLoss(): return float instead of double
- IIterativeModel: double ComputeLoss() => float ComputeObjective()
recommenders
- #157: matrix factorization recommenders use float to store the
latent factors
Expand Down
8 changes: 4 additions & 4 deletions src/MyMediaLite/IIterativeModel.cs
@@ -1,4 +1,4 @@
// Copyright (C) 2010, 2011 Zeno Gantner
// Copyright (C) 2010, 2011, 2012 Zeno Gantner
//
// This file is part of MyMediaLite.
//
Expand Down Expand Up @@ -26,9 +26,9 @@ public interface IIterativeModel
/// <summary>Run one iteration (= pass over the training data)</summary>
void Iterate();

/// <summary>Compute the current loss of the model</summary>
/// <returns>the current loss; -1 if not implemented</returns>
float ComputeLoss();
/// <summary>Compute the current optimization objective (usually loss plus regularization term) of the model</summary>
/// <returns>the current objective; -1 if not implemented</returns>
float ComputeObjective();
}
}

2 changes: 1 addition & 1 deletion src/MyMediaLite/ItemRecommendation/BPRLinear.cs
Expand Up @@ -254,7 +254,7 @@ public override void LoadModel(string filename)
}

///
public float ComputeLoss()
public float ComputeObjective()
{
return -1;
}
Expand Down
6 changes: 3 additions & 3 deletions src/MyMediaLite/ItemRecommendation/BPRMF.cs
Expand Up @@ -171,7 +171,7 @@ public override void Train()
loss_sample_j[c] = j;
}

last_loss = ComputeLoss();
last_loss = ComputeObjective();
}

for (int i = 0; i < NumIter; i++)
Expand Down Expand Up @@ -250,7 +250,7 @@ public override void Iterate()

if (BoldDriver)
{
double loss = ComputeLoss();
double loss = ComputeObjective();

if (loss > last_loss)
LearnRate *= 0.5f;
Expand Down Expand Up @@ -534,7 +534,7 @@ protected virtual void RetrainItem(int item_id)
}

///
public override float ComputeLoss()
public override float ComputeObjective()
{
double ranking_loss = 0;
for (int c = 0; c < loss_sample_u.Length; c++)
Expand Down
2 changes: 1 addition & 1 deletion src/MyMediaLite/ItemRecommendation/MF.cs
Expand Up @@ -77,7 +77,7 @@ public override void Train()
public abstract void Iterate();

///
public abstract float ComputeLoss();
public abstract float ComputeObjective();

/// <summary>Predict the weight for a given user-item combination</summary>
/// <remarks>
Expand Down
2 changes: 1 addition & 1 deletion src/MyMediaLite/ItemRecommendation/MultiCoreBPRMF.cs
Expand Up @@ -96,7 +96,7 @@ public override void Iterate()

if (BoldDriver)
{
double loss = ComputeLoss();
double loss = ComputeObjective();

if (loss > last_loss)
LearnRate *= 0.5f;
Expand Down
2 changes: 1 addition & 1 deletion src/MyMediaLite/ItemRecommendation/SoftMarginRankingMF.cs
Expand Up @@ -111,7 +111,7 @@ protected override void UpdateFactors(int u, int i, int j, bool update_u, bool u

/// <summary>Compute approximate loss</summary>
/// <returns>the approximate loss</returns>
public override float ComputeLoss()
public override float ComputeObjective()
{
throw new NotImplementedException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/MyMediaLite/ItemRecommendation/WRMF.cs
Expand Up @@ -143,7 +143,7 @@ protected virtual void Optimize(IBooleanMatrix data, Matrix<float> W, Matrix<flo
}

///
public override float ComputeLoss()
public override float ComputeObjective()
{
return -1;
}
Expand Down
6 changes: 3 additions & 3 deletions src/MyMediaLite/RatingPrediction/BiasedMatrixFactorization.cs
Expand Up @@ -160,7 +160,7 @@ protected override void InitModel()
item_bias[i] = 0;

if (BoldDriver)
last_loss = ComputeLoss();
last_loss = ComputeObjective();
}

///
Expand Down Expand Up @@ -212,7 +212,7 @@ public override void Iterate()

if (BoldDriver)
{
double loss = ComputeLoss();
double loss = ComputeObjective();

if (loss > last_loss)
LearnRate *= 0.5f;
Expand Down Expand Up @@ -435,7 +435,7 @@ protected override IList<float> FoldIn(IList<Pair<int, float>> rated_items)
}

///
public override float ComputeLoss()
public override float ComputeObjective()
{
double loss = 0;
switch (Loss)
Expand Down
2 changes: 1 addition & 1 deletion src/MyMediaLite/RatingPrediction/CoClustering.cs
Expand Up @@ -357,7 +357,7 @@ public override void LoadModel(string filename)
}

///
public float ComputeLoss()
public float ComputeObjective()
{
return this.Evaluate(ratings)["RMSE"];
}
Expand Down
Expand Up @@ -267,7 +267,7 @@ public override void LoadModel(string filename)
}

///
public float ComputeLoss()
public float ComputeObjective()
{
return -1;
}
Expand Down
Expand Up @@ -98,7 +98,7 @@ protected override void Iterate(IList<int> rating_indices, bool update_user, boo
}

///
public override float ComputeLoss()
public override float ComputeObjective()
{
double rating_range_size = MaxRating - MinRating;

Expand Down
2 changes: 1 addition & 1 deletion src/MyMediaLite/RatingPrediction/MatrixFactorization.cs
Expand Up @@ -374,7 +374,7 @@ public override void LoadModel(string filename)

/// <summary>Compute the regularized loss</summary>
/// <returns>the regularized loss</returns>
public virtual float ComputeLoss()
public virtual float ComputeObjective()
{
double loss = 0;
for (int i = 0; i < ratings.Count; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/MyMediaLite/RatingPrediction/SocialMF.cs
Expand Up @@ -221,7 +221,7 @@ private void IterateBatch()
}

///
public override float ComputeLoss()
public override float ComputeObjective()
{
double loss = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/MyMediaLite/RatingPrediction/TimeAwareBaseline.cs
Expand Up @@ -289,7 +289,7 @@ public override float Predict(int user_id, int item_id, DateTime time)
}

///
public virtual float ComputeLoss()
public virtual float ComputeObjective()
{
double loss =
this.Evaluate(ratings)["RMSE"]
Expand Down
Expand Up @@ -150,9 +150,9 @@ public override float Predict(int user_id, int item_id, DateTime time)
}

///
public override float ComputeLoss()
public override float ComputeObjective()
{
return (float) (base.ComputeLoss() + RegItemBiasAtFrequency * Math.Pow(item_bias_at_frequency.FrobeniusNorm(), 2));
return (float) (base.ComputeObjective() + RegItemBiasAtFrequency * Math.Pow(item_bias_at_frequency.FrobeniusNorm(), 2));
}

///
Expand Down
2 changes: 1 addition & 1 deletion src/MyMediaLite/RatingPrediction/UserItemBaseline.cs
Expand Up @@ -239,7 +239,7 @@ public override void LoadModel(string filename)
}

///
public float ComputeLoss()
public float ComputeObjective()
{
return (float) (
this.Evaluate(ratings)["RMSE"]
Expand Down
Expand Up @@ -95,7 +95,7 @@ protected override void InitModel()
similarity_constraint_matrix = new Matrix<float>(NumFactors, MaxItemID + 1);

//if (BoldDriver)
// last_loss = ComputeLoss();
// last_loss = ComputeObjective();
}

///
Expand All @@ -118,7 +118,7 @@ public override void Iterate()
/*
if (BoldDriver)
{
double loss = ComputeLoss();
double loss = ComputeObjective();
if (loss > last_loss)
LearnRate *= 0.5;
Expand Down Expand Up @@ -227,7 +227,7 @@ public override void RemoveItem(int item_id)
}

///
public override float ComputeLoss()
public override float ComputeObjective()
{
// TODO
return -1;
Expand Down

0 comments on commit 4a2d15c

Please sign in to comment.