Skip to content
This repository was archived by the owner on May 21, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
language: julia
os:
- linux
- osx
julia:
- 0.5
- 0.6
- nightly
notifications:
email: false
Expand Down
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ julia 0.5-

Reexport
LearnBase
Compat 0.17 # for new type syntax
13 changes: 7 additions & 6 deletions src/ObjectiveFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ __precompile__(true)

module ObjectiveFunctions

using Compat: @compat
using Reexport
@reexport using LearnBase
@reexport using LossFunctions
Expand All @@ -19,7 +20,7 @@ export
RegularizedObjective,
objective

abstract AbstractLossTransform{T} <: Transformation
@compat abstract type AbstractLossTransform{T} <: Transformation end

immutable NoLoss <: AbstractLossTransform{Void} end

Expand All @@ -41,20 +42,20 @@ immutable LossTransform{T,L<:Loss} <: AbstractLossTransform{T}
target::SumNode{T,1}
output::OutputNode{T,1}

function LossTransform(loss::Loss, nin::Int)
function (::Type{LossTransform{T, L}}){T, L <: Loss}(loss::Loss, nin::Int)
input = InputNode(T, nin)
target = InputNode(T, nin)
output = OutputNode(T, 1)
grad(output)[1] = one(T) # ∂L/∂L == 1
new(loss, nin, input, target, output)
new{T, L}(loss, nin, input, target, output)
end
end

LossTransform{L<:Loss}(loss::L, nin::Int) = LossTransform{Float64, L}(loss, nin)

# input and target are pre-populated... compute the output value as: ∑ loss(targetᵢ, inputᵢ)
function transform!(lt::LossTransform)
lt.output.val[1] = sumvalue(lt.loss, value(lt.target), input_value(lt))
lt.output.val[1] = value(lt.loss, value(lt.target), input_value(lt), AvgMode.Sum())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lt
end

Expand All @@ -76,12 +77,12 @@ immutable CrossEntropy{T} <: AbstractLossTransform{T}
target::SumNode{T,1}
output::OutputNode{T,1}

function CrossEntropy(n::Int)
function (::Type{CrossEntropy{T}}){T}(n::Int)
input = InputNode(T, n)
target = InputNode(T, n)
output = OutputNode(T, 1)
grad(output)[:] = one(T) # ∂L/∂L == 1
new(n, input, target, output)
new{T}(n, input, target, output)
end
end
CrossEntropy(n::Int) = CrossEntropy{Float64}(n)
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using Base.Test
t = Affine(nin, nout)
l = L2DistLoss()
λ = 1e-3
p = L2Penalty(λ)
p = scaled(L2Penalty(), λ)
obj = objective(t, l, p)
@show obj typeof(obj)

Expand Down