Created
August 25, 2014 01:00
-
-
Save milktrader/8919439db67bc5783cbb to your computer and use it in GitHub Desktop.
Minkowski criterion function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
julia> function L(c) | |
sum([abs(xs-c)^2 for xs in x])/length(x) | |
end | |
L (generic function with 2 methods) | |
julia> x=[1,2,3,4,5,6,9,12] | |
8-element Array{Int64,1}: | |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
9 | |
12 | |
julia> mean(x) | |
5.25 |
Here is a method that brute forces it
julia> function optimizeL(x; p=2, start=minimum(x), stop=maximum(x), step=0.1)
rng = [start:step:stop]
res = [L(x,p,r) for r in rng]
best = minimum(res)
idx = findfirst(res, best)
rng[idx]
end
First though L
needs to be defined better
julia> function L(x,p,c)
sum([abs(xs-c)^p for xs in x])/length(x)
end
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can see that the smallest error is in the 5.25 slot here