[julia-users] Re: How do I, as efficiently as possible, iterate over the first and last elements along a given dimension of an array?

2016-03-23 Thread Benjamin Deonovic
Can mapslices help here?


On Wednesday, March 23, 2016 at 6:59:59 PM UTC-5, Tomas Lycken wrote:
>
> Is there an effective pattern to iterate over the “endpoints” of an array 
> along a given dimension?
>
> What I eventually want to accomplish is to apply a function (in this case 
> an equality test) to the two end points along a particular dimension of an 
> array. I think the pattern is easiest explained by considering 1D, 2D and 
> 3D:
>
> # assume the existence of some scalar-valued function f(x,y)
>
> A1 = rand(10)
> f(A1[1], A1[end]) # d == 1 (the only possible value) -> one evaluation
>
> A2 = rand(10, 15)
> map(f, A2[1,:], A2[end,:]) # d == 1 -> 15 evaluations
> map(f, A2[:,1], A2[:,end]) # d == 2 -> 10 evaluations
>
> A3 = rand(10, 15, 8)
> map(f, A3[1,:,:], A3[end,:,:]) # d == 1 -> 15x8 evaluations
> map(f, A3[:,1,:], A3[:,end,:]) # d == 2 -> 10x8 evaluations
> map(f, A3[:,:,1], A3[:,:,end]) # d == 3 -> 10x15 evaluations
>
> I just want to consider one dimension at a time, so given A and d, and in 
> this specific use case I don’t need to collect the results, so a for-loop 
> without an allocated place for the answer instead of a map is just fine 
> (probably preferrable, but it’s easier to go in that direction than in the 
> other). What I’m struggling with, is how to generally formulate the 
> indexing expressions (like [, 1,  instances of :>], but not in pseudo-code…). I assume this can be done 
> somehow using CartesianIndexes and/or CartesianRanges, but I can’t get my 
> mind around to how. Any help is much appreciated.
>
> // T
> ​
>


[julia-users] Re: leaky if semantics

2016-02-08 Thread Benjamin Deonovic
If you keep reading from the link you gave:

The variable relation is declared inside the if block, but used outside. 
However, when depending on this behavior, make sure all possible code paths 
define a value for the variable. The following change to the above function 
results in a runtime error

julia> function test(x,y)
 if x < y
   relation = "less than"
 elseif x == y
   relation = "equal to"
 end
 println("x is ", relation, " y.")
   endtest (generic function with 1 method)
julia> test(1,2)x is less than y.
julia> test(2,1)ERROR: UndefVarError: relation not defined
 in test at none:7

You will see that when i==2 you won't define x and therefore you will get 
the runtime error. 

On Monday, February 8, 2016 at 5:41:40 AM UTC-6, David van Leeuwen wrote:
>
> Hello, 
>
> According to 
> http://docs.julialang.org/en/release-0.4/manual/control-flow/#man-conditional-evaluation
>  variables 
> in if blocks do not introduce lexical scope, and hence are available 
> afterwards.   This makes sense and is what I need. 
>
> However, it seems afterwards relates to position in the encapsulating 
> block, and not to execution time. 
>
> function testif()
> for i in 1:2
> if i==1
> x = 0
> end
> if x==2
> println(x)
> end
> end
> end
>
>
> This code gives me an undefined `x` in the print statement, where I would 
> have expected `x` to be initialized in the first iteration.  It seems I 
> need to define `x` outside the for loop, even though I don't need it there. 
>  
>
> Is this interpretation in Julia intentional?
>
> Cheers, 
>
> ---david
>
>

[julia-users] Re: Hello World.jl

2015-12-04 Thread Benjamin Deonovic
Or from your terminal command line you can type 

julia path/to/hello.jl

and it will execute was is in the file. This is the first topic that is 
discussed in the manual which you should look over): 
http://docs.julialang.org/en/release-0.4/manual/getting-started/

On Thursday, December 3, 2015 at 3:43:12 PM UTC-6, Mark Kugel wrote:
>
>
>
> Hi, I'm just starting to work with JULIA, and I have a couple of questions 
> :
>
> 1) To get in touch with Julia, I have a small "hello.jl" script with only 
> "*println("Hello 
> World.")*". How do I run it through Julia ? Is there somewhere in my mac 
> a misty folder that Julia read and where I should store all my scripts ?
> 2) I want to use some data stored in a excel file. In my program, I use 
> "ExcelReaders". Where do I have to store my Excel file to let Julia read it 
> ?
>
>
> Some info : *Julia Version 0.4.1, installed on my Mac Book Pro in 
> '/Applications/Julia-0.4.1.app'*
>
>
> Thank you
>
>
> MK
>


[julia-users] Re: Hello World.jl

2015-12-04 Thread Benjamin Deonovic
You can store your data wherever you want. In particular for the package 
you noted (ExcelReaders) you can do things like:

using ExcelReaders

f = openxl("/path/to/my/file/Filename.xlsx")





Re: [julia-users] 3D image matrix

2015-12-01 Thread Benjamin Deonovic
So whats the image of? 

On Tuesday, December 1, 2015 at 4:50:51 PM UTC-6, Rivo Sarmento wrote:
>
> Currently the imports, or using package, are in the begining of the code.
> I got it to work only if using is the last step before using `view`.
>
> I can't think of a particular reason for it to happen. Although, in my 
> 0.3.2 Julia importing ImageView returns:
>
> julia> using ImageView
> Warning: could not import Base.Text into Tk
>
> I finally got, as we can see in the attached file, thank you very much.
>
> Em terça-feira, 1 de dezembro de 2015 19:19:03 UTC-3, Tim Holy escreveu:
>>
>> On Tuesday, December 01, 2015 01:36:28 PM Rivo Sarmento wrote: 
>> > But `view` returns: 
>> > 
>> > julia> view(img) 
>> > ERROR: `view` has no method matching 
>> > view(::Image{Float64,3,Array{Float64,3}}) 
>>
>> Are you sure you first said 
>> using ImageView? 
>>
>> julia> methods(view) 
>> # 3 methods for generic function "view": 
>> view{A<:AbstractArray{T,N}}(img::A<:AbstractArray{T,N}) at 
>> /home/tim/.julia/v0.4/ImageView/src/display.jl:233 
>> view{A<:AbstractArray{T,N}}(imgc::ImageView.ImageCanvas, 
>> img::A<:AbstractArray{T,N}) at 
>> /home/tim/.julia/v0.4/ImageView/src/display.jl:344 
>> view{A<:AbstractArray{T,N}}(c::Tk.Canvas, img::A<:AbstractArray{T,N}) at 
>> /home/tim/.julia/v0.4/ImageView/src/display.jl:364 
>>
>> That first method covers any AbstractArray. 
>>
>> --Tim 
>>
>>

[julia-users] Re: Proposal: NoveltyColors.jl

2015-12-01 Thread Benjamin Deonovic
+1 this is a great idea and I think it would make a good contribution to 
NoveltyColors.jl

On Monday, November 30, 2015 at 4:38:10 PM UTC-6, Alex Mellnik wrote:
>
> On a related note, I've been thinking that it would be nice to include the 
> results of the xkcd color survey  in 
> Colors.jl.  Right now it has the CSS/SVG and X11 colors which is great for 
> standardization, but sometimes you want to be able to get a RGB value 
> corresponding to fairly specific and easy-to-remember color names (mocha, 
> cerulean blue, etc).  I was originally going to stick it in a different 
> package, but there might be a nice way to separate these names in Colors.jl
>
> -A
>
> On Tuesday, November 24, 2015 at 2:08:35 PM UTC-8, Randy Zwitch wrote:
>>
>> Since the Julia ecosystem is getting bigger, I figured I'd propose this 
>> here first and see what people think is the right way forward (instead of 
>> wasting people's time at METADATA)
>>
>> In the R community, they've created two packages of novelty color 
>> schemes: Wes Anderson  and 
>> Beyonce . While humorous, these color 
>> palettes are interesting to me and I'd like to make them available in 
>> Vega.jl (and Julia more broadly). Should I:
>>
>> 1) Not do it at allbecause this is a serious, scientific community!
>> 2) Do two separate packages, mimicking R
>> 3) Create a single NoveltyColors.jl package, in case there are other 
>> palettes that come up in the future
>> 4) Make a feature request at Colors.jl (really not my favorite choice, 
>> since there is so much cited research behind the palettes)
>>
>> I neglected to mention ColorBrewer.jl (which Vega.jl uses), since 
>> ColorBrewer is a known entity in the plotting community.
>>
>> What do people think? Note, I'm not looking for anyone to do the work 
>> (I'll do it), just looking for packaging input.
>>
>

Re: [julia-users] Re: More conda troubles

2015-11-20 Thread Benjamin Deonovic
Actually it doesn't seem to have worked:

julia> Pkg.test("NetCDF")
INFO: Testing NetCDF
INFO: NetCDF tests passed


I think the issue is witht he package NetCDF not anything you are doing. 


Re: [julia-users] Re: More conda troubles

2015-11-20 Thread Benjamin Deonovic

I'm guessing the issue isn't NetCDF versus netCDF (capitlization?)
On Friday, November 20, 2015 at 8:25:37 AM UTC-6, J Luis wrote:
>
> Yes, but furthermore you don't seam to be on Windows where further 
> problems exist because the shared library (dll) names differ (libnetcdf.xx 
> on unix and netcdf.dll on Windows)
>
> I actually tried to work-around this with my favorite solution, which is 
> to make the name of the library a veriable, as in
>
> @windows? (const thelib = "netcdf4_w64") : (const thelib = "libnetcdf")  # 
> Name of GMT shared lib.
>
> and than using the 'thelib' in calls to ccall but I get a new error 
>
> julia> using netCDF
> WARNING: requiring "netCDF" in module "Main" did not define a 
> corresponding module.
>
> sexta-feira, 20 de Novembro de 2015 às 14:16:46 UTC, Benjamin Deonovic 
> escreveu:
>>
>> Actually it doesn't seem to have worked:
>>
>> julia> Pkg.test("NetCDF")
>> INFO: Testing NetCDF
>> INFO: NetCDF tests passed
>>
>>
>> I think the issue is witht he package NetCDF not anything you are doing. 
>>
>

Re: [julia-users] Re: More conda troubles

2015-11-20 Thread Benjamin Deonovic
I tried to see if I would have the same problem. I first tried 
Pkg.add("NetCDF") and I got same problem:






























*julia> Pkg.add("NetCDF")INFO: Updating cache of Conda...INFO: Cloning 
cache of Formatting from git://github.com/lindahua/Formatting.jl.gitINFO: 
Cloning cache of NetCDF from git://github.com/JuliaGeo/NetCDF.jl.gitINFO: 
Installing Conda v0.1.8INFO: Installing Formatting v0.1.4INFO: Installing 
NetCDF v0.3.0INFO: Building NetCDFINFO: Recompiling stale cache file 
/home/benjamin/.julia/lib/v0.4/URIParser.ji for module URIParser.INFO: 
Recompiling stale cache file /home/benjamin/.julia/lib/v0.4/SHA.ji for 
module SHA.INFO: Recompiling stale cache file 
/home/benjamin/.julia/lib/v0.4/Conda.ji for module Conda.WARNING: Module 
BinDeps uuid did not match cache file===[ 
ERROR: NetCDF ]LoadError: 
__precompile__(true) but require failed to create a precompiled cache 
filewhile loading /home/benjamin/.julia/v0.4/NetCDF/deps/build.jl, in 
expression starting on line 
6[
 
BUILD ERRORS 
]WARNING:
 
NetCDF had build errors. - packages with build errors remain installed in 
/home/benjamin/.julia/v0.4 - build the package(s) and all dependencies with 
`Pkg.build("NetCDF")` - build a single package by running its 
`deps/build.jl` script*Then I did Pkg.update() followed by 
Pkg.build("NetCDF")

After that it seemed fine:







*julia> Pkg.test("NetCDF")INFO: Testing NetCDFINFO: NetCDF tests passed*

On Friday, November 20, 2015 at 8:02:33 AM UTC-6, J Luis wrote:
>
> Well, some variation of it yes. But I don't even have a deps.jl so test 
> for its existence in netcdf_c.jl always fails.
>
> sexta-feira, 20 de Novembro de 2015 às 11:11:48 UTC, Luthaf escreveu:
>>
>> Is this error the same as https://github.com/JuliaGeo/NetCDF.jl/issues/6
>>  ?
>>
>> -- 
>> Luthaf
>>
>> Le 19 novembre 2015 à 23:12:50, J Luis (jmf...@gmail.com) a écrit:
>>
>> Nope. The trouble is that after installing 295 MB of Condas (I mean a 
>> full python when I already had one and did not ask for another), there was 
>> some problem and libnetcdf was not installed.
>>
>>
>> quinta-feira, 19 de Novembro de 2015 às 21:12:15 UTC, Tony Kelman 
>> escreveu: 
>>>
>>> Looks like that's probably a dlopen failure? Or check the libnetcdf in 
>>> dependency walker? 
>>>
>>>
>>> On Thursday, November 19, 2015 at 12:35:10 PM UTC-8, J Luis wrote: 

 oops, I obviously meant 'cache' not 'cash'

 quinta-feira, 19 de Novembro de 2015 às 20:33:28 UTC, J Luis escreveu: 
>
> It's so annoying that Pkg.rm() does not rm. So I manually cleaned the 
> cash and .trash after Pkg.rm("Conda") but it still doesn't install netCDF.
> I wish I could use what I already have in my computer (netcdf and all 
> of its dependencies) and not duplicating them (if it worked).
>
> julia> Pkg.build("NetCDF")
> INFO: Building NetCDF
> Fetching package metadata: 
> Solving package specifications: 
> # All requested packages already installed.
> # packages in environment at C:\j\.julia\v0.4\Conda\deps\usr:
> #
> libnetcdf 4.3.3.1   vc9_4  [vc9]
> ===[ ERROR: NetCDF 
> ]
>
> LoadError: Provider BinDeps.PackageManager failed to satisfy 
> dependency libnetcdf
> while loading C:\j\.julia\v0.4\NetCDF\deps\build.jl, in expression 
> starting on line 12
>
>
> quinta-feira, 19 de Novembro de 2015 às 20:18:47 UTC, J Luis escreveu: 
>>
>> In fact I had. I always call julia from a bat file that I use to set 
>> paths of interest and calls my WinPython portable installation. Now 
>> changed 
>> that but I'm again in a broken state
>>
>> julia> Pkg.rm("NetCDF")
>> INFO: Installing Conda v0.1.8
>> INFO: Removing Formatting v0.1.4
>> INFO: Removing NetCDF v0.3.0
>> INFO: Package database updated
>>
>> julia> Pkg.add("NetCDF")
>> INFO: Installing Formatting v0.1.4
>> INFO: Installing NetCDF v0.3.0
>> INFO: Building NetCDF
>> Error: This installation of conda is not initialized. Use 'conda 
>> create -n
>> envname' to create a conda environment and 'source activate envname' 
>> to
>> activate it.
>>
>> # Note that pip installing conda is not the recommended way for 
>> setting up your
>> # system.  The recommended way for setting up a conda system is by 
>> installing
>> # Miniconda, see: http://repo.continuum.io/miniconda/index.html
>> ===[ 

Re: [julia-users] Looking for ideas and topics to include in an introductory workshop in Julia

2015-11-20 Thread Benjamin Deonovic
If anyone in your group would be interested in MCMC check out our great 
tutorial on how to use our package 
Mamba: http://mambajl.readthedocs.org/en/latest/


[julia-users] Re: Pkg.update error

2015-11-18 Thread Benjamin Deonovic
No, I think Julia installs its ownAnaconda Python separate from your 
systems python. Looks like BinDeps needs to be recompiled. Try deleting its 
cache, or deleteing the BinDeps folder and reinstalling it. 

On Wednesday, November 18, 2015 at 9:22:19 AM UTC-6, J Luis wrote:
>
> Is this because I don't have (nor want to have) Anaconda Python?
> Win8 here.
>
> INFO: Building PyCall
> INFO: Recompiling stale cache file C:\j\.julia\lib\v0.4\Conda.ji for 
> module Conda.
> WARNING: Module BinDeps uuid did not match cache file
> WARNING: deserialization checks failed while attempting to load cache 
> from C:\j\.julia\lib\v0.4\Conda.ji
> INFO: Precompiling module Conda...
> INFO: Recompiling stale cache file C:\j\.julia\lib\v0.4\Conda.ji for 
> module Conda.
> WARNING: Module BinDeps uuid did not match cache file
> [ ERROR: 
> PyCall ]
>
> LoadError: __precompile__(true) but require failed to create a 
> precompiled cache file
> while loading C:\j\.julia\v0.4\PyCall\deps\build.jl, in expression 
> starting on line 12
>


[julia-users] Re: norm() is faster than maxabs()

2015-11-18 Thread Benjamin Deonovic
Does norm use maxabs? If so this could be due to maxabs getting compiled. 
try running both of the timed statements a second time. 

On Wednesday, November 18, 2015 at 10:41:48 AM UTC-6, Sisyphuss wrote:
>
> Interesting phenomenon: norm() is faster than maxabs()
>
> x = randn(10)
> @time maxabs(x)
> @time norm(x)
>
>
> 0.000108 seconds (5 allocations: 176 bytes) 
> 0.40 seconds (5 allocations: 176 bytes)
>
> I have thought the contrary, for norm() requires N square and 1 square 
> root; maxabs() requires 2N change of sign bit and N comparison.
>


[julia-users] Re: Progress meter for parallel workers

2015-11-17 Thread Benjamin Deonovic
I made progress meters for parllel runners about a year ago in Julia using 
Tk.jl. I've seen stopped using that bit of acode but here is what I have 
unearthed from the depths:

 Progress Types 

type ProgressFrame
  trace::Bool
  widget::Tk_Widget

  function ProgressFrame(title::String, trace::Bool)
if trace
  print(title * "...\n\n")
  new(true)
else
  widget = Frame(Toplevel("Mamba Progress"))
  pack(widget, expand=true, fill="both")
  grid(Label(widget, title), 1, 2)
  new(false, widget)
end
  end
end

type Progress
  frame::ProgressFrame
  chain::Integer
  iters::Integer
  counter::Integer
  t0::Float64

  runin::Integer
  threshold::Float64

  pb::Tk_Widget
  l1::Tk_Widget
  l2::Tk_Widget

  function Progress(f::ProgressFrame, chain::Integer, iters::Integer)
runin = max(1, min(10, iround(0.01 * iters)))
if f.trace
  new(f, chain, iters, 0, time(), runin, 0.0)
else
  pb = Progressbar(f.widget, orient="horizontal")
  l1 = Label(f.widget, "Chain $chain: ")
  l2 = Label(f.widget, @sprintf("[%s of %s remaining]", 0, 0))

  grid(l1, chain+1, 1, sticky="news")
  grid(pb, chain+1, 2, sticky="news")
  grid(l2, chain+1, 3, sticky="news")

  new(f, chain, iters, 0, time(), runin, time(), pb, l1, l2)
end
  end
end


 Progress Methods 

function next!(p::Progress)
  p.counter += 1
  if p.frame.trace
if p.counter / p.iters >= p.threshold && p.counter >= p.runin
  p.threshold += 0.10
  print(STDOUT, p)
end
  else
t = time()
if t > p.threshold + 1.0 || p.counter >= p.iters
  p.threshold = t
  myid() == 1 ? update!(p) : remotecall(1, update!, p)
  sleep(0.01)
end
  end
  p
end

function reset!(p::Progress)
  p.counter = 0
  p.t0 = time()
  p.threshold = p.frame.trace ? 0.0 : time()
  p
end

function terminate!(f::ProgressFrame)
  f.trace || tcl("destroy", parent(f.widget))
  f
end

function update!(p::Progress)
  elapsed = time() - p.t0
  remaining = elapsed * (p.iters / p.counter - 1.0)
  str = @sprintf("[%s of %s remaining]",
 strfsec(remaining),
 strfsec(elapsed + remaining))
  set_value(p.pb, integer(100.0 * p.counter / p.iters))
  set_value(p.l2, str)
  p
end

function Base.print(io::IO, p::Progress)
  elapsed = time() - p.t0
  remaining = elapsed * (p.iters / p.counter - 1.0)
  str = @sprintf("Chain %u: %3u%% [%s of %s remaining]",
 p.chain,
 100.0 * p.counter / p.iters,
 strfsec(remaining),
 strfsec(elapsed + remaining))
  println(io, str)
end

function strfsec(sec::Real)
  hr, sec = divrem(sec, 3600)
  min, sec = divrem(sec, 60)
  @sprintf "%u:%02u:%02u" hr min sec
end




On Sunday, November 15, 2015 at 9:35:24 AM UTC-6, Jason Eckstein wrote:
>
>
>
> I was playing around with the ProgressMeter.jl package by Tim Holy and it 
> works great for a single threaded loop.  I was wondering if there's any way 
> to run several loops on multiple workers and have a set of progress bars 
> update in real time.  When I tried this with Tim's package it just said 
> Progress: 100% Time:  after each was complete but nothing during 
> intermediate progress.  What I had in mind was a display like
> Worker 1:  Progress: X%...
> Worker 2: Progress: Y% 
> that update in real time but have multiple lines to represent the 
> different workers.
>


[julia-users] Re: Progress meter for parallel workers

2015-11-17 Thread Benjamin Deonovic
I made a progress meter for parallel runners once in julia about a year 
ago. I've since stopped using the code but it might inspire you to make 
something similar:

http://pastebin.com/yy1a9RCv

On Monday, November 16, 2015 at 10:06:13 AM UTC-6, Tomas Lycken wrote:
>
> There has been some discussion about this, see 
> https://github.com/timholy/ProgressMeter.jl/issues/9 and 
> https://github.com/timholy/ProgressMeter.jl/issues/32
>
> // T
>
> On Monday, November 16, 2015 at 1:53:22 PM UTC+1, bernhard wrote:
>>
>> related to this I would welcome if it were possible to show the progress 
>> of a pmap() statement.
>> It is easy, to have each worker display the instance number which is 
>> being processed (say if pmap goes over a range 1:n). But I do not know how 
>> to show progress and estimated time left
>>
>> Am Sonntag, 15. November 2015 16:35:24 UTC+1 schrieb Jason Eckstein:
>>>
>>>
>>>
>>> I was playing around with the ProgressMeter.jl package by Tim Holy and 
>>> it works great for a single threaded loop.  I was wondering if there's any 
>>> way to run several loops on multiple workers and have a set of progress 
>>> bars update in real time.  When I tried this with Tim's package it just 
>>> said Progress: 100% Time:  after each was complete but nothing during 
>>> intermediate progress.  What I had in mind was a display like
>>> Worker 1:  Progress: X%...
>>> Worker 2: Progress: Y% 
>>> that update in real time but have multiple lines to represent the 
>>> different workers.
>>>
>>

[julia-users] Re: Best way to return many arrays from function

2015-11-17 Thread Benjamin Deonovic
You can use types:

type myResult
  someArray1::Vector
  someArray2::Vector
end



On Tuesday, November 17, 2015 at 4:06:10 PM UTC-6, Jason McConochie wrote:
>
> In matlab I group arrays into structures such that I can deal with one 
> variable as the output from the function
> e.g. 
> function o=someFunction(in)
> o.someArray1=[0,0,0,0];
> o.someArray2=[1,1,1,1];
> end
>
> What is the Julia equivalent?  Maintaining the efficiency of the 
> contiguous columnar array access in Julia.
>


[julia-users] Re: Chi square test in Julia?

2015-11-10 Thread Benjamin Deonovic
Hey Joshua,

Just saw your post. I will investigate into what the issue is. I wrote this 
quite a while ago when I was just learning Julia!

On Tuesday, November 10, 2015 at 9:10:10 AM UTC-6, Joshua Duncan wrote:
>
> I found your Chi-Square test and am trying to use it.  It appears to work 
> with one array but not with two.  My steps are below:
>
> This works:
> ChisqTest([1,2,3,4])
>
> This doesn't:
> ChisqTest([1,2,3,4],[1,2,2,4])
>
> It errors with the following:
>
> LoadError: MethodError: `ChisqTest` has no method matching 
> ChisqTest(::Array{Int64,1}, ::Array{Int64,1})
> Closest candidates are:
>   ChisqTest{T<:Integer}(::AbstractArray{T<:Integer,1}, 
> ::AbstractArray{T<:Integer,1}, 
> !Matched::Tuple{UnitRange{T<:Integer},UnitRange{T<:Integer}})
>   ChisqTest{T<:Integer}(::AbstractArray{T<:Integer,1}, 
> ::AbstractArray{T<:Integer,1}, !Matched::T<:Integer)
>   ChisqTest{T<:Integer,U<:AbstractFloat}(::AbstractArray{T<:Integer,1}, 
> !Matched::Array{U<:AbstractFloat,1})
>   ...
> while loading In[118], in expression starting on line 1
>
>
>
> I have checked the arrays to make sure they're AbstractArrays and the 
> result is true.
>
> Any advice would be helpful, I might just be implementing wrong.
>
> On Friday, March 6, 2015 at 7:58:20 AM UTC-6, Benjamin Deonovic wrote:
>>
>> My pull has been merged: https://github.com/JuliaStats/HypothesisTests.jl
>>
>> On Thursday, March 5, 2015 at 8:32:32 AM UTC-6, Benjamin Deonovic wrote:
>>>
>>> I implemented the chisquare test in julia. I made a pull request in the 
>>> HypothesisTests package. It hasn't been pulled yet, but probably will be 
>>> soon. 
>>>
>>> On Sunday, February 8, 2015 at 5:32:48 PM UTC-6, Arin Basu wrote:
>>>>
>>>> Hi All,
>>>>
>>>> Please pardon my ignorance, but how does one do chisquare test in 
>>>> Julia. Something like,
>>>>
>>>> ```
>>>>
>>>> chisq.test(x, y = NULL, correct = TRUE,
>>>>p = rep(1/length(x), length(x)), rescale.p = FALSE,
>>>>simulate.p.value = FALSE, B = 2000)
>>>>
>>>> ```
>>>>
>>>> in R
>>>>
>>>>
>>>> I could not find anything in the documentation. I must not have searched 
>>>> enough, what can it be?
>>>>
>>>>
>>>> Best,
>>>>
>>>> Arin
>>>>
>>>>

[julia-users] Re: Chi square test in Julia?

2015-11-10 Thread Benjamin Deonovic
Looks like the state of Julia's "Factors" (PooledDataArrays) is still quite 
a fast evolving monster. Because of this there hasn't been a proper 
implementation of R's "table" function. For now, if you want to run 
ChisqTest in Julia on two vectors do it on the matrix you would obtain in R 
by running table(x,y). 


[julia-users] Re: Chi square test in Julia?

2015-11-10 Thread Benjamin Deonovic
Okay I have figured out the issue. I will fix it so it works the way you 
expected it to work. Before the fix goes live though it should work to do:

ChisqTest([1,2,3,4],[1,2,2,4], 4)

*note the 4

The issue was when I submitted the code to HypothesisTests.jl the only way 
to create a contingency table between two vectors x and y was to also 
provide the levels that the categorical variables could take on. Afterwards 
I submited a version to StatsBase.jl for ``counts`` that had default 
values, but I forgot to update my code at HypothesisTests.jl. Sorry for the 
late response!


**Note the above will give you what is equivalent in R to:

> chisq.test(matrix(c(1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,1),nrow = 4,ncol = 4))

Pearson's Chi-squared test

data:  matrix(c(1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1), nrow = 4, 
ncol = 4)
X-squared = NaN, df = 9, p-value = NA

Warning message:
In chisq.test(matrix(c(1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,  :
  Chi-squared approximation may be incorrect



However you are probably interested in 

> chisq.test(c(1,2,3,4),c(1,2,2,4))

Pearson's Chi-squared test

data:  c(1, 2, 3, 4) and c(1, 2, 2, 4)
X-squared = 8, df = 6, p-value = 0.2381


When I wrote up the function there wasn't a good equivalent of R's 
``table`` function. I will try to flesh out this code so it works closer to 
R. In the meantime the best thing is to work with the full contingency 
table i.e.:

julia> ChisqTest([1 0 0; 0 1 0; 0 1 0; 0 0 1]) 
Pearson's Chi-square Test 
- 
Population details: 
 parameter of interest: Multinomial Probabilities 
 value under h_0: 
[0.0625,0.0625,0.0625,0.0625,0.125,0.125,0.125,0.125,0.0625,0.0625,0.0625,0.0625]
 
 point estimate: [0.25,0.0,0.0,0.0,0.0,0.25,0.25,0.0,0.0,0.0,0.0,0.25] 
 95% confidence interval: 
[(0.0,1.0),(0.0,1.0),(0.0,1.0),(0.0,1.0),(0.0,1.0),(0.0,1.0),(0.0,1.0),(0.0,1.0),(0.0,1.0),(0.0,1.0),(0.0,1.0),(0.0,1.0)]
 
 
Test summary: 
 outcome with 95% confidence: fail to reject h_0 
 two-sided p-value: 0.23810330555354436 (not significant) 
 
Details: 
 Sample size: 4 
 statistic: 8.0 
 degrees of freedom: 6 
 residuals: 
[1.5,-0.5,-0.5,-0.5,-0.7071067811865475,0.7071067811865475,0.7071067811865475,-0.7071067811865475,-0.5,-0.5,-0.5,1.5]
 
 std. residuals: 
[2.0,-0.,-0.,-0.,-1.1547005383792517,1.1547005383792517,1.1547005383792517,-1.1547005383792517,-0.,-0.66
66,-0.,2.0] 
 







Re: [julia-users] Do I have simd?

2015-11-05 Thread Benjamin Deonovic
Did you compile julia from source or just grab a pre-compiled binary? 


On Thursday, November 5, 2015 at 3:22:28 PM UTC-6, DNF wrote:
>
> I see. Do you know if I need to install something to get SIMD support?
>
> According to this 
> 
>  
> review of my computer model: "Haswell chips also include new instructions 
> enhancing SIMD vector processing with Advanced Vector Extensions 2".
>
> So what could be wrong?
>


[julia-users] Re: Command line help documentation

2015-08-26 Thread Benjamin Deonovic
I found my answer. In Julia 0.4 you have access to the doc macro:

help? @doc
 Documentation
≡≡≡

  Functions, methods and types can be documented by placing a string before the
  definition:

  
  # The Foo Function
  `foo(x)`: Foo the living hell out of `x`.
  
  foo(x) = ...

  The @doc macro can be used directly to both set and retrieve documentation /
  metadata. By default, documentation is written as Markdown, but any object 
can be
  placed before the arrow. For example:

  @doc blah -
  function foo() ...

  The - is not required if the object is on the same line, e.g.

  @doc foo foo

 Documenting objects after they are defined


  You can document an object after its definition by

  @doc foo function_to_doc
  @doc bar TypeToDoc

  For macros, the syntax is @doc macro doc :(@Module.macro) or @doc macro 
doc
  :(string_macro) for string macros. Without the quote :() the expansion of 
the macro
  will be documented.

 Retrieving Documentation
==

  You can retrieve docs for functions, macros and other objects as follows:

  @doc foo
  @doc @time
  @doc md

 Functions  Methods
=

  Placing documentation before a method definition (e.g. function foo() ... or 
foo() =
  ...) will cause that specific method to be documented, as opposed to the whole
  function. Method docs are concatenated together in the order they were 
defined to
  provide docs for the function.


On Wednesday, August 26, 2015 at 11:12:54 AM UTC-5, Benjamin Deonovic wrote:

 How can I get documentation for my functions in my package to show up when 
 someone uses the command line help functionality 

 like:


 help? sort 
 INFO: Loading help data...
 Base.sort(v, [alg=algorithm,] [by=transform,] [lt=comparison,] [rev=
 false]) 
  
  Variant of sort! that returns a sorted copy of v leaving 
  v itself unmodified. 
  
 Base.sort(A, dim, [alg=algorithm,] [by=transform,] [lt=comparison,] 
 [rev=false]) 
  
  Sort a multidimensional array A along the given dimension. 
  
 julia 





[julia-users] Re: Julia as scripting language for larger project

2015-08-26 Thread Benjamin Deonovic
Not sure what you mean by julia sandbox, but there 
is https://www.juliabox.org/ if you want to try out julia without having to 
install on your machine. 

On Wednesday, August 26, 2015 at 11:23:29 AM UTC-5, Fengyang Wang wrote:

 Hi,

 I learned Julia recently, and I must say it has been incredible for 
 scientific work. I am in love with the clean, modern syntax. Props to the 
 developers for their tireless efforts to improve this language even further!

 Historically, Lua and Javascript have been the most common choices for 
 scripting languages in larger projects... Lua because it is so easy to 
 integrate with C(++), and Javascript primarily because it is so easy to 
 integrate with Java. I would like Julia to fill this role for one of my 
 current projects, but I have identified some hurdles.

1. For now, security is not important because scripts are assumed to 
be trusted. However, a plan for scripts to eventually be downloaded from 
the Internet is in the works. I could not find a Julia sandbox, however. 
Does such a sandbox exist?
2. My customers may not necessarily be computer-literate, and I can't 
expect them to install Julia. Also, due to the rapid pace of Julia 
development, it may be advantageous to install a portable Julia entirely 
for this project only. My project currently targets Windows, Linux, and 
 Mac 
OSX. Is there a portable way to install a portable Julia, or will I have 
 to 
create separate installation code for each OS?
3. My current understanding is that I should write the public API in 
Julia, and use ccall internally to call back into my project. Is this the 
correct method?

 Thanks in advance!



[julia-users] Command line help documentation

2015-08-26 Thread Benjamin Deonovic
How can I get documentation for my functions in my package to show up when 
someone uses the command line help functionality 

like:


help? sort 
INFO: Loading help data...
Base.sort(v, [alg=algorithm,] [by=transform,] [lt=comparison,] [rev=
false]) 
 
 Variant of sort! that returns a sorted copy of v leaving 
 v itself unmodified. 
 
Base.sort(A, dim, [alg=algorithm,] [by=transform,] [lt=comparison,] [
rev=false]) 
 
 Sort a multidimensional array A along the given dimension. 
 
julia 





[julia-users] Iterating over Dicts

2015-07-21 Thread Benjamin Deonovic
A few clarifying questions. I believe that when you iterate over julia 
Dicts, the iteration is not necessarily in any particular order (i.e. if 
keys are alpha-numeric it is not necessarily in sorted order, or it is not 
necessarily in order the keys were inserted). Is that correct? 

If I set the seed though am I guaranteed the same order each time and 
between Julia sessions? 

Thanks
Benjamin


[julia-users] Mutate dict

2015-06-22 Thread Benjamin Deonovic
I have a Dict constructed lets call it d. I want to pass it to a function 
that will change some entries in d. What is the appropriate way to do this 
so that I end up with an updated dictionary? 


[julia-users] Finding mode(s) of density estimate

2015-03-30 Thread Benjamin Deonovic
I have some data for which I want to find the mode(s) of the kernel density 
estimate of the data. Is there anything that already does this? If not what 
is the best approach? 


[julia-users] Creating custom distribution

2015-03-10 Thread Benjamin Deonovic
I'm trying to create a custom distribution. I define:

immutable myDist : DiscreteMultivariateDistribution
  #code
end




function _logpdf{T:Real}(d::myDist, X::AbstractVector{T})
  # code
end


_pdf(d::myDist, X::AbstractVector) = exp(_logpdf(d, X))



I can succesfully create a distribution (i.e. d = myDist(...)) and I can 
directly call _logpdf(d,x) on some data x. However, if I try to call 
logpdf(d,x) (which is defined by the Distributions package) I get 

ERROR: `_logpdf` has no method matching _logpdf(::myDist, ::Array{Int64,1})
 in logpdf at 
/Users/bdeonovic/.julia/v0.3/Distributions/src/multivariates.jl:66

why is this??


Re: [julia-users] Re: Confused about parametrization type

2015-03-06 Thread Benjamin Deonovic
That was the perfect resource, thank you Tim Holy!

Here's a question about a specific situation:

Suppose I have a type that has two String variables, but at construction, 
these might not be the same type of Strings (e.g. one might be ASCIIString, 
the other SubString{ASCIIString}). Which parametrization is better:

type Foo{T : String, U : String}
   a::T
   b::U
end

or 

type Foo{T : String}
   a::T
   b::String
end

On Thursday, March 5, 2015 at 2:59:40 PM UTC-6, Tim Holy wrote:

 Extensive discussion here: 

 http://docs.julialang.org/en/release-0.3/manual/faq/#how-do-abstract-or-ambiguous-fields-in-types-interact-with-the-compiler
  

 --Tim 

 On Thursday, March 05, 2015 12:50:59 PM Benjamin Deonovic wrote: 
  This has been very helpful 
  
  @Ivar Nesje 
  
  Can you explain the difference between your two examples of type A? I 
 think 
  that is where most of my confusion comes from. 
  
  On Thursday, March 5, 2015 at 12:24:12 PM UTC-6, Ivar Nesje wrote: 
  1. Make sure that your code is correct for the inputs you allow. 
 There 
  is no need to accept BigFloat (nor Float16) if you end up 
 converting to 
  Float64 for the calculation anyway (the user of your code can do 
 that 
  himself). If you don't care enough about different precisions to 
 even 
  think 
  about  how it will affect your program, I think it is better to add 
 a 
  TODO 
  comment in the code/documentation, so that others that care might 
  submit 
  the required changes in a PR. 
  2. Testing your algorithm with random Float16 and BigInt will 
  sometimes raise new issues that affects Float64, but is much harder 
 to 
  find 
  there. There is definitely value in thinking about how different 
 makes 
  a 
  difference (or why it doesn't). 
   
   Usually you shouldn't use abstract types in a type definition, but 
 rather 
   make a parametric type. This is for performance, because the current 
 Julia 
   runtime is very slow if it can't statically infer the types of the 
 members 
   of a type. See that 
   
   type A{T:FloatingPoint} 
   
 member::T 
   
   end 
   
   is usually much better than 
   
   type A 
   
   member::FloatingPoint 
   
   end 
   
   Regards 
   Ivar 
   
   torsdag 5. mars 2015 18.27.38 UTC+1 skrev Simon Danisch følgende: 
   I think it's a good idea to have things parametric and type stable. 
 So 
   I'd vote for T : FloatingPoint. 
   Like this, the type you call a function with can be propagated down 
 to 
   all other functions and no conversions are needed. 
   As you said, this gets difficult as some people have Float64 hard 
 coded 
   all over the place. It's understandable as John pointed out. 
   But for someone like me who works with GPU's which depending on the 
   graphics card perform up to 30 times faster with Float32, this is 
 quite 
   annoying as I always need to convertcopy. 
   
   Am Donnerstag, 5. März 2015 17:55:40 UTC+1 schrieb Benjamin Deonovic: 
   Moving a post from julia issues to here since it is more 
 appropriate: 
   https://github.com/JuliaLang/julia/issues/10408 
   
   If I am making a function or composite type that involves floating 
 point 
   numbers, should I enforce those numbers to be Float64 or 
 FloatingPoint? 
   I thought it should be FloatingPoint so that the function/type will 
   work with any kind of floating point number. However, several julia 
   packages enforce Float64 (e.g. Distributions package Multinomial 
   distribution) and so I run into problems and have to put in a lot of 
   converts in my code to Float64. Am I doing this wrong? I'm quite new 
 to 
   julia 
   
   
   I don't have any intention to use non Float64 floatingpoints 
 numbers, 
   I'm just trying to write good code. I saw a lot of examples where 
   people recommended to to use Integer rather than Int64 or String 
 rather 
   than ASCIIString, etc. I'm just trying to be consistent. I'm fine 
 just 
   using Float64 if that is the appropriate approach here. 



[julia-users] Re: Chi square test in Julia?

2015-03-06 Thread Benjamin Deonovic
My pull has been merged: https://github.com/JuliaStats/HypothesisTests.jl

On Thursday, March 5, 2015 at 8:32:32 AM UTC-6, Benjamin Deonovic wrote:

 I implemented the chisquare test in julia. I made a pull request in the 
 HypothesisTests package. It hasn't been pulled yet, but probably will be 
 soon. 

 On Sunday, February 8, 2015 at 5:32:48 PM UTC-6, Arin Basu wrote:

 Hi All,

 Please pardon my ignorance, but how does one do chisquare test in Julia. 
 Something like,

 ```

 chisq.test(x, y = NULL, correct = TRUE,
p = rep(1/length(x), length(x)), rescale.p = FALSE,
simulate.p.value = FALSE, B = 2000)

 ```

 in R


 I could not find anything in the documentation. I must not have searched 
 enough, what can it be?


 Best,

 Arin



[julia-users] Re: Confused about parametrization type

2015-03-05 Thread Benjamin Deonovic
This has been very helpful

@Ivar Nesje

Can you explain the difference between your two examples of type A? I think 
that is where most of my confusion comes from. 

On Thursday, March 5, 2015 at 12:24:12 PM UTC-6, Ivar Nesje wrote:


1. Make sure that your code is correct for the inputs you allow. There 
is no need to accept BigFloat (nor Float16) if you end up converting to 
Float64 for the calculation anyway (the user of your code can do that 
himself). If you don't care enough about different precisions to even 
 think 
about  how it will affect your program, I think it is better to add a TODO 
comment in the code/documentation, so that others that care might submit 
the required changes in a PR.
2. Testing your algorithm with random Float16 and BigInt will 
sometimes raise new issues that affects Float64, but is much harder to 
 find 
there. There is definitely value in thinking about how different makes a 
difference (or why it doesn't).


 Usually you shouldn't use abstract types in a type definition, but rather 
 make a parametric type. This is for performance, because the current Julia 
 runtime is very slow if it can't statically infer the types of the members 
 of a type. See that

 type A{T:FloatingPoint}
   member::T
 end

 is usually much better than

 type A
 member::FloatingPoint
 end

 Regards
 Ivar

 torsdag 5. mars 2015 18.27.38 UTC+1 skrev Simon Danisch følgende:

 I think it's a good idea to have things parametric and type stable. So 
 I'd vote for T : FloatingPoint.
 Like this, the type you call a function with can be propagated down to 
 all other functions and no conversions are needed.
 As you said, this gets difficult as some people have Float64 hard coded 
 all over the place. It's understandable as John pointed out. 
 But for someone like me who works with GPU's which depending on the 
 graphics card perform up to 30 times faster with Float32, this is quite 
 annoying as I always need to convertcopy.

 Am Donnerstag, 5. März 2015 17:55:40 UTC+1 schrieb Benjamin Deonovic:

 Moving a post from julia issues to here since it is more appropriate: 
 https://github.com/JuliaLang/julia/issues/10408

 If I am making a function or composite type that involves floating point 
 numbers, should I enforce those numbers to be Float64 or FloatingPoint? I 
 thought 
 it should be FloatingPoint so that the function/type will work with any 
 kind of floating point number. However, several julia packages enforce 
 Float64 (e.g. Distributions package Multinomial distribution) and so I run 
 into problems and have to put in a lot of converts in my code to Float64. 
 Am 
 I doing this wrong? I'm quite new to julia


 I don't have any intention to use non Float64 floatingpoints numbers, 
 I'm just trying to write good code. I saw a lot of examples where 
 people recommended to to use Integer rather than Int64 or String rather 
 than ASCIIString, etc. I'm just trying to be consistent. I'm fine just 
 using Float64 if that is the appropriate approach here.



[julia-users] Confused about parametrization type

2015-03-05 Thread Benjamin Deonovic
Moving a post from julia issues to here since it is more 
appropriate: https://github.com/JuliaLang/julia/issues/10408

If I am making a function or composite type that involves floating point 
numbers, should I enforce those numbers to be Float64 or FloatingPoint? I 
thought 
it should be FloatingPoint so that the function/type will work with any 
kind of floating point number. However, several julia packages enforce 
Float64 (e.g. Distributions package Multinomial distribution) and so I run 
into problems and have to put in a lot of converts in my code to Float64. Am 
I doing this wrong? I'm quite new to julia


I don't have any intention to use non Float64 floatingpoints numbers, I'm 
just trying to write good code. I saw a lot of examples where people 
recommended to to use Integer rather than Int64 or String rather than 
ASCIIString, etc. I'm just trying to be consistent. I'm fine just using 
Float64 if that is the appropriate approach here.


[julia-users] Re: Chi square test in Julia?

2015-03-05 Thread Benjamin Deonovic
I implemented the chisquare test in julia. I made a pull request in the 
HypothesisTests package. It hasn't been pulled yet, but probably will be 
soon. 

On Sunday, February 8, 2015 at 5:32:48 PM UTC-6, Arin Basu wrote:

 Hi All,

 Please pardon my ignorance, but how does one do chisquare test in Julia. 
 Something like,

 ```

 chisq.test(x, y = NULL, correct = TRUE,
p = rep(1/length(x), length(x)), rescale.p = FALSE,
simulate.p.value = FALSE, B = 2000)

 ```

 in R


 I could not find anything in the documentation. I must not have searched 
 enough, what can it be?


 Best,

 Arin