[julia-users] Re: Has anyone successfully performed probit or logit regression in Julia?

2014-08-31 Thread Adam Kapor
This works for me:

```

*julia **fit(GeneralizedLinearModel,Y~X,data,Binomial(),ProbitLink())*

*DataFrameRegressionModel{GeneralizedLinearModel,Float64}:*

*Coefficients:*

*Estimate Std.Error z value Pr(|z|)*

*(Intercept) 0.430727   1.980190.217518   0.8278*

*X2.37745e-17   0.91665 2.59362e-17   1.*

*julia **fit(GeneralizedLinearModel,Y~X,data,Binomial(),LogitLink())*

*DataFrameRegressionModel{GeneralizedLinearModel,Float64}:*

*Coefficients:*

* Estimate Std.Error  z value Pr(|z|)*

*(Intercept)  0.693147   3.24037  0.21391   0.8306*

*X-7.44332e-17   1.5 -4.96221e-17   1.*

*```*

On Sunday, August 31, 2014 1:27:15 PM UTC-4, Bradley Setzler wrote:

 Has anyone successfully performed probit or logit regression in Julia? The 
 GLM 
 documentation https://github.com/JuliaStats/GLM.jl does not provide a 
 generalizable example of how to use glm(). It gives a Poisson example 
 without any suggestion of how to switch from Poisson to some other type.

 *Using the Poisson example from GLM documentation works:*

 julia X = [1;2;3.]
 julia Y = [1;0;1.]
 julia data = DataFrame(X=X,Y=Y)
 julia fit(GeneralizedLinearModel, Y ~ X,data, Poisson())
 DataFrameRegressionModel{GeneralizedLinearModel,Float64}: 
 Coefficients: 
 Estimate Std.Error z value Pr(|z|) 
 (Intercept) -0.405465 1.87034 -0.216787 0.8284 
 X -3.91448e-17 0.8658 -4.52123e-17 1. 

 *But does not generalize:*

 julia fit(GeneralizedLinearModel, Y ~ X ,data, Logit()) 
 ERROR: Logit not defined

 julia fit(GeneralizedLinearModel, Y ~ X, data, link=:ProbitLink) 
 ERROR: `fit` has no method matching fit(::Type{GeneralizedLinearModel}, 
 ::Array{Float64,2}, ::Array{Float64,1})

 julia fit(GeneralizedLinearModel, Y ~ X, data, 
 family=binomial,link=probit) 
 ERROR: `fit` has no method matching fit(::Type{GeneralizedLinearModel}, 
 ::Array{Float64,2}, ::Array{Float64,1})

 and a dozen other similar attempts fail. 


 Thanks,
 Bradley



[julia-users] trouble building julia on mac

2014-08-13 Thread Adam Kapor
 

I just tried building the latest master on my mac; I get the following 
error.  Any ideas on what to do -- I'm pretty new to this.  Googling tells 
me that this is an issue with clang in Xcode 5.1 but what can I do to fix 
this?

Thanks,

Adam


adams-air:julia adamkapor$ make

Making install in support

Making install in kernel

libtool: compile:  clang -stdlib=libc++ -mmacosx-version-min=10.7 
-DHAVE_CONFIG_H -I. -I.. -I../simd -O3 -fomit-frame-pointer -mtune=native 
-malign-double -fstrict-aliasing -fno-schedule-insns -ffast-math -MT 
align.lo -MD -MP -MF .deps/align.Tpo -c align.c  -fno-common -DPIC -o 
.libs/align.o

clang: error: unknown argument: '-malign-double' 
[-Wunused-command-line-argument-hard-error-in-future]

clang: note: this will be a hard error (cannot be downgraded to a warning) 
in the future

make[5]: *** [align.lo] Error 1

make[4]: *** [install-recursive] Error 1

make[3]: *** [/Applications/julia/usr/lib/libfftw3f.dylib] Error 2

make[2]: *** [install-fftw] Error 2

make[1]: *** [julia-release] Error 2

make: *** [release] Error 2


Re: [julia-users] trouble building julia on mac

2014-08-13 Thread Adam Kapor
Thank you Elliot and Jameson.  I indeed recently upgraded Xcode and clang,
and `make -C deps distclean-fftw` did the trick.


On Wed, Aug 13, 2014 at 2:39 PM, Jameson Nash vtjn...@gmail.com wrote:

 Especially true if you just upgraded you OS / compiler, you should start
 again with a fresh clone


 On Wednesday, August 13, 2014, Elliot Saba staticfl...@gmail.com wrote:

 Adam, is this julia codebase a fresh clone, or have you been building out
 of this directory for a while?  If it's not 100% fresh, you might want to
 try running `make -C deps distclean-fftw` and then trying again.  It's
 possible that we fixed this issue a while back, and the cached configure
 state of your fftw is behind a bit and needs to be reconfigured.
 -E


 On Wed, Aug 13, 2014 at 2:29 PM, Jeff Waller truth...@gmail.com wrote:

 Likewise no problems compiling using an older version of clang (Xcode
 5.0.2), but I do see that flag

 bizarro% clang --version

 Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)

 Target: x86_64-apple-darwin13.3.0

 Thread model: posix

 It looks like it's in there.  There is a test to check (see below) but
 the compiler doesn't fail, it just warns so the test is perhaps concluding
 that yep, supported which is technically true.

 bizarro% find . -type f -exec grep malign-double {} /dev/null \;

 ...

 ./deps/fftw-3.3.3-double/config.log:clang: warning: argument unused
 during compilation: '-malign-double'

 ./deps/fftw-3.3.3-double/config.log:configure:14242: clang
 -stdlib=libc++ -mmacosx-version-min=10.7 -m64 -c -O3 -fomit-frame-pointer
 -mtune=native -malign-double -fstrict-aliasing -fno-schedule-insns
 -ffast-math


 ...


 ./deps/fftw-3.3.3-single/configure:$as_echo_n checking whether C
 compiler accepts -malign-double...  6; }

 ./deps/fftw-3.3.3-single/configure:  CFLAGS=-malign-double

 ./deps/fftw-3.3.3-single/configure: CFLAGS=$CFLAGS -malign-double

 ./deps/fftw-3.3.3-single/configure: # -malign-double for x86 systems

 ./deps/fftw-3.3.3-single/configure:  { $as_echo
 $as_me:${as_lineno-$LINENO}: checking whether C compiler accepts
 -malign-double 5

 ./deps/fftw-3.3.3-single/configure:$as_echo_n checking whether C
 compiler accepts -malign-double...  6; }

 ./deps/fftw-3.3.3-single/configure:  CFLAGS=-malign-double

 ./deps/fftw-3.3.3-single/configure: CFLAGS=$CFLAGS -malign-double

 ./deps/fftw-3.3.3-single/configure: { $as_echo
 $as_me:${as_lineno-$LINENO}: checking whether C compiler accepts
 -malign-double 5

 ./deps/fftw-3.3.3-single/configure:$as_echo_n checking whether C
 compiler accepts -malign-double...  6; }

 ./deps/fftw-3.3.3-single/configure:  CFLAGS=-malign-double

 ./deps/fftw-3.3.3-single/configure: CFLAGS=$CFLAGS -malign-double

 ...

 Binary file ./usr/lib/libfftw3.3.dylib matches

 Binary file ./usr/lib/libfftw3.a matches

 Binary file ./usr/lib/libfftw3f.3.dylib matches

 Binary file ./usr/lib/libfftw3f.a matches





[julia-users] Re: parallel for loop suggestions?

2014-07-07 Thread Adam Kapor
I had a similar issue (former Matlab user, big likelihood computation that 
needs a giant read-only matrix for each observation.)  I haven't dealt with 
preallocating outputs, but for the read-only matrices can you do something 
like:
  
 mybigmatrix = ... #
 @everywhere const mybigmatrix = @fetchfrom(1,mybigmatrix)
 @everywhere function likelihood(params,data_i,mybigmatrix)
 ... #
 end
@everywhere obj(params,data_i) = likelihood(params,data_i,mybigmatrix)

@parallel (+) for ii in observations  #or use pmap
obj(params,ii)
end
```

I didn't know the answer beforehand, so I worked out an example.  
https://gist.github.com/adamkapor/52ee025b243bf3f5f990
I may be doing this badly but as far as I can tell, you can do fine with 
@parallel or pmap, but naive @parallel copies everything each call.

Adam

On Monday, July 7, 2014 2:22:56 PM UTC-4, Thomas Covert wrote:

 I was indeed planning on using parallel map, but I'm still not clear on 
 whether it will allocate copies of arrays for each worker.

 On Monday, July 7, 2014 1:21:13 PM UTC-5, Sid wrote:

 For (1), perhaps something like the parallel map mentioned here (
 http://julia.readthedocs.org/en/latest/manual/parallel-computing/) would 
 work?

 On Monday, July 7, 2014 2:00:43 PM UTC-4, Thomas Covert wrote:

 Any suggestions about how to do this?  Thanks in advance.

 -Thom

 On Friday, July 4, 2014 9:15:27 AM UTC-5, Thomas Covert wrote:

 Hi Julia-Users,

 I'm trying to parallelize a likelihood calculation in which each step 
 requires read-only access to several large matrices (10,000 by 3000 in one 
 case, 3,000 square in another case, etc).  

 1) If I do a @parallel for, is Julia going to create copies of each of 
 these matrices?  If so, would specifying them as DArray or SharedArray 
 prevent this memory allocation?  There are enough of these matrices (and 
 they are big enough) that copying them for parallel programming purposes 
 pretty much defeats the benefits of parallel execution in my setting, I 
 think.  I'd really like to avoid that if possible.
 2) Each step of the for loop also generates medium sized matrices (with 
 no gradients, its a few 100x1 vectors per loop iteration, with gradients 
 I'd also add some 100x20 matrices).  Should I be writing these outputs to 
 a 
 SharedArray or a DArray?

 I think my head is still stuck in the MATLAB parfor/sliced-array 
 mindset, so any advice from previous MATLAB users would be especially 
 helpful.

 Thanks.

 -Thom




[julia-users] typeassert when assigning to elements of array

2014-05-28 Thread Adam Kapor
I'm not sure what :(::) is supposed to do below, but not giving an error at 
top level suggests to me that x[1] is an expression computing a value. In 
any case, I was surprised that += runs but doesn't `setindex!` x


julia x=zeros(2)
2-element Array{Float64,1}:
 0.0
 0.0
julia x[1]::Float64 += 1.
1.0
julia x
2-element Array{Float64,1}:
 0.0
 0.0
julia x[1]::Float64 = 1.
ERROR: syntax: invalid assignment location x[1]

julia myf(x) = x[1]::Float64+=1
myf (generic function with 1 method)
julia code_lowered(myf,(Array,))
1-element Array{Any,1}:
 :($(Expr(:lambda, {:x}, 
{{:#s36,:#s40},{{:x,:Any,0},{:#s36,:Any,18},{:#s40,:Float64,2}},{}}, 
:(begin  # none, line 1:
#s40 = top(typeassert)(top(convert)(Float64,getindex(x,1)),Float64)
#s36 = top(typeassert)(#s40,Float64) + 1
#s40 = top(typeassert)(top(convert)(Float64,#s36),Float64)
return #s36
end
julia myf_noassert(x) = x[1]+=1
myf_noassert (generic function with 1 method)
julia code_lowered(myf_noassert, (Array,))
1-element Array{Any,1}:
 :($(Expr(:lambda, {:x}, {{:#s30},{{:x,:Any,0},{:#s30,:Any,18}},{}}, 
:(begin  # none, line 1:
#s30 = getindex(x,1) + 1
setindex!(x,#s30,1)
return #s30
end



[julia-users] get is more eager than I thought

2014-04-06 Thread Adam Kapor
Is get supposed to evaluate the fallback argument?  I was surprised by this:

julia dict1 = {1=1} 
{1=1} 
julia dict2 = Dict() 
Dict{Any,Any}() 
julia get(dict1,1,get!(dict2,1,2)) 
1 
julia dict2 
{1=2}

The other method is more what I'd have expected
julia get(dict1,1) do
   ()-get!(dict2,1,2) 
   end 
1 
julia dict2 
Dict{Any,Any}()