Comments (3)
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.
That is nothing short of amazing. Thanks for the pointer!
from sparseregression.jl.
SparseRegression now uses the alias
const LinearRegression = LossFunctions.ScaledDistanceLoss{L2DistLoss,0.5}
from sparseregression.jl.
Related Issues (16)
- Rename package HOT 1
- Does this package work? HOT 2
- SparseRegression doesn't seem to work with large n and p HOT 2
- Better default step size for ProxGrad HOT 1
- error with all betas positive HOT 5
- Add CoordinateDescent <: Algorithm
- SnpArray as input for SModel HOT 6
- run femtocleaner HOT 1
- Methods for finding maximum lambda HOT 1
- Support for typeof(x) == SparseMatrixCSC HOT 1
- Rewrite
- Problem with example HOT 10
- doc images HOT 4
- Line search HOT 4
- ANN: Rewrite
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sparseregression.jl.