Skip to content

Commit

Permalink
Remove commended code + new test case
Browse files Browse the repository at this point in the history
  • Loading branch information
btwardow committed Aug 21, 2015
1 parent f371f4b commit 9550ce8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 38 deletions.
39 changes: 5 additions & 34 deletions src/fm.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,3 @@
#function fmPredictInstance(fm::FMModel, x::FMVector)
# result = 0.0
# fSum = zeros(fm.num_factor)
# sum_sqr = zeros(fm.num_factor)
# if(fm.k0)
# result += fm.w0
# end
# if(fm.k1)
# for i in 1:length(x)
# if x[i] != 0.0
# result += fm.w[i] * x[i]
# end
# end
# end
# for f in 1:fm.num_factor
# for i in 1:length(x)
# if x[i] != 0.0
# d = fm.V[f,i] * x[i]
# fSum[f] += d
# sum_sqr[f] += d*d
# end
# end
# result += 0.5 * (fSum[f]*fSum[f] - sum_sqr[f])
# end
# #scale prediction
# result = min(result, fm.targetMax)
# result = max(result, fm.targetMin)
# (result, fSum, sum_sqr)
#end


function fmPredictInstance!(fm::FMModel, idx::Array{Int64,1}, x::Array{FMFloat,1}, fSum::Array{FMFloat}, sum_sqr::Array{FMFloat})
fill!(fSum, .0)
fill!(sum_sqr, .0)
Expand Down Expand Up @@ -141,9 +110,11 @@ function fmTrain(
if method == :sgd
fmTrainSGD!(fm, X, y, iterationNum, alpha)
else
error("FM Model learning method: $method not implemented!")
error("If You think it should be, create appropriate Pull Request")
error("or contact me - bartlomiej.twardowski@gmail.com")
error("""
FM Model learning method: $method not implemented!
If You think it should be, create appropriate Pull Request
or contact me - bartlomiej.twardowski@gmail.com
""")
end

fm
Expand Down
8 changes: 4 additions & 4 deletions test/ml100k.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ using FactorizationMachines
using Base.Test

info("Running tests on ml-100k dataset...")
(ml100kTrain, ml100kTrainRatings) = @time fmReadLibSVM("test/data/ml-100k.train.libfm")
(ml100kTrain, ml100kTrainRatings) = @time fmReadLibSVM("data/ml-100k.train.libfm")
info("Train dim: $(size(ml100kTrain))")
(ml100kTest, ml100kTestRatings) = @time fmReadLibSVM("test/data/ml-100k.test.libfm")
(ml100kTest, ml100kTestRatings) = @time fmReadLibSVM("data/ml-100k.test.libfm")
info("Test dim: $(size(ml100kTest))")

info("Test ML-100K - Training model...")
Expand All @@ -20,9 +20,9 @@ p = @time fmPredict(fmMl100k, ml100kTest)
rmse = sqrt(sum((p-ml100kTestRatings).^2)/length(p))
info("RMSE on test data: $rmse")

if isfile("test/data/ml-100k.output.libfm")
if isfile("data/ml-100k.output.libfm")
info("File with output from libfm exists. Bencharking to its result...")
libfmOutput = readcsv("test/data/ml-100k.output.libfm")
libfmOutput = readcsv("data/ml-100k.output.libfm")
rmseWithLibfm = sqrt(sum((p-libfmOutput).^2)/length(p))
info("RMSE with Libfm output: $rmseWithLibfm")
end
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ using FactorizationMachines
using Base.Test

include("test_fm_readlibsvm.jl")
include("test_fm.jl")
include("test_reco.jl")
10 changes: 10 additions & 0 deletions test/test_fm.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module TestFactorizationMachines

using Base.Test

info("Testing - unknow learning method should throw an exception")
X = sparse(randn(10, 5))
y = randn(5)
@test_throws(Exception, fmTrain(X,y,:unknowMethod))

end

0 comments on commit 9550ce8

Please sign in to comment.