Skip to content

Instantly share code, notes, and snippets.

@milktrader
Created August 25, 2014 01:00
Show Gist options
  • Save milktrader/8919439db67bc5783cbb to your computer and use it in GitHub Desktop.
Save milktrader/8919439db67bc5783cbb to your computer and use it in GitHub Desktop.
Minkowski criterion function
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
@milktrader
Copy link
Author

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

@milktrader
Copy link
Author

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