Git Product home page Git Product logo

Comments (3)

Evizero avatar Evizero commented on May 27, 2024 1

The overhead in the first example comes from the fact that I made the scalefactor a type parameter instead of a member variable. So runtime decisions are now heavily penalized.

The big upside is that this is possible:

julia> typealias LeastSquaresLoss LossFunctions.ScaledDistanceLoss{L2DistLoss,0.5}
LossFunctions.ScaledDistanceLoss{LossFunctions.LPDistLoss{2},0.5}

julia> value(LeastSquaresLoss(), -1., 3.)
8.0

julia> @code_llvm value(LeastSquaresLoss(), -1., 3.)

define double @julia_value_70896(double, double) #0 {
top:
  %2 = fsub double %1, %0
  %3 = fmul double %2, %2
  %4 = fmul double %3, 5.000000e-01
  ret double %4
}

and thus scaling a loss at compile time is a zero cost abstraction.

To really drive the point home about being zero cost, behold the derivative where the compiler gets rid of 0.5 * 2.0 with the magic of @fastmath:

julia> @code_llvm deriv(L2DistLoss(),-1.,3.)

define double @julia_deriv_70946(double, double) #0 {
top:
  %2 = fsub double %1, %0
  %3 = fmul double %2, 2.000000e+00
  ret double %3
}
julia> @code_llvm deriv(LeastSquaresLoss(),-1.,3.)

define double @julia_deriv_70944(double, double) #0 {
top:
  %2 = fsub double %1, %0
  ret double %2
}

from sparseregression.jl.

joshday avatar joshday commented on May 27, 2024

That is nothing short of amazing. Thanks for the pointer!

from sparseregression.jl.

joshday avatar joshday commented on May 27, 2024

SparseRegression now uses the alias

const LinearRegression      = LossFunctions.ScaledDistanceLoss{L2DistLoss,0.5}

from sparseregression.jl.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.