[julia-users] Re: Julia Summer of Code

2015-05-23 Thread Scott Jones
Your link is to a local address on your machine...

On Sunday, May 24, 2015 at 12:42:27 AM UTC-4, Miles Lubin wrote:
>
> We've put up a blog post (http://localhost:4000/blog/2015/05/jsoc-cfp/) 
> with some more details on Julia Summer of Code. There are still a number of 
> unfilled slots open; submission deadline is June 1st!
>
> On Friday, May 15, 2015 at 1:57:24 PM UTC-4, Viral Shah wrote:
>>
>> Folks,
>>
>> The Moore Foundation is generously funding us to allow for 6-8 Julia 
>> Summer of Code projects. Details will be published soon, but if you are 
>> interested, please mark your calendars and plan your projects.
>>
>> -viral
>>
>

[julia-users] Re: Julia Summer of Code

2015-05-23 Thread Miles Lubin
Sorry about that, here's the real 
link: http://julialang.org/blog/2015/05/jsoc-cfp/

On Sunday, May 24, 2015 at 12:42:27 AM UTC-4, Miles Lubin wrote:
>
> We've put up a blog post (http://localhost:4000/blog/2015/05/jsoc-cfp/) 
> with some more details on Julia Summer of Code. There are still a number of 
> unfilled slots open; submission deadline is June 1st!
>
> On Friday, May 15, 2015 at 1:57:24 PM UTC-4, Viral Shah wrote:
>>
>> Folks,
>>
>> The Moore Foundation is generously funding us to allow for 6-8 Julia 
>> Summer of Code projects. Details will be published soon, but if you are 
>> interested, please mark your calendars and plan your projects.
>>
>> -viral
>>
>

[julia-users] Re: Julia Summer of Code

2015-05-23 Thread Miles Lubin
We've put up a blog post (http://localhost:4000/blog/2015/05/jsoc-cfp/) 
with some more details on Julia Summer of Code. There are still a number of 
unfilled slots open; submission deadline is June 1st!

On Friday, May 15, 2015 at 1:57:24 PM UTC-4, Viral Shah wrote:
>
> Folks,
>
> The Moore Foundation is generously funding us to allow for 6-8 Julia 
> Summer of Code projects. Details will be published soon, but if you are 
> interested, please mark your calendars and plan your projects.
>
> -viral
>


[julia-users] Avoid memory allocations when reading from matrices

2015-05-23 Thread Dom Luna
Reposting this from Gitter chat since it seems this is more active.

I'm writing a GloVe module to learn Julia.

How can I avoid memory allocations? My main function deals with a lot of 
random indexing in Matrices.

A[i,  :] = 0.5 * B[i, :]

In this case* i* isn't from a linear sequence. I'm not sure that matters. 
Anyway, I've done analysis and I know B[i, :]  is the issue here since it's 
creating a copy. 

https://github.com/JuliaLang/julia/blob/master/base/array.jl#L309 makes the 
copy


I tried to do it via loop but it looks like that doesn't help either. In 
fact, it seems to allocate slight more memory which seems really odd.

Here's some of the code, it's a little messy since I'm commenting different 
approaches I'm trying out.

type Model{T}
W_main::Matrix{T}
W_ctx::Matrix{T}
b_main::Vector{T}
b_ctx::Vector{T}
W_main_grad::Matrix{T}
W_ctx_grad::Matrix{T}
b_main_grad::Vector{T}
b_ctx_grad::Vector{T}
covec::Vector{Cooccurence}
end

# Each vocab word in associated with a main vector and a context vector.
# The paper initializes the to values [-0.5, 0.5] / vecsize+1 and
# the gradients to 1.0.
#
# The +1 term is for the bias.
function Model(comatrix; vecsize=100)
vs = size(comatrix, 1)
Model(
(rand(vecsize, vs) - 0.5) / (vecsize + 1),
(rand(vecsize, vs) - 0.5) / (vecsize + 1),
(rand(vs) - 0.5) / (vecsize + 1),
(rand(vs) - 0.5) / (vecsize + 1),
ones(vecsize, vs),
ones(vecsize, vs),
ones(vs),
ones(vs),
CoVector(comatrix), # not required in 0.4
)
end

# TODO: figure out memory issue
# the memory comments are from 500 loop test with vecsize=100
function train!(m::Model, s::Adagrad; xmax=100, alpha=0.75)
J = 0.0
shuffle!(m.covec)

vecsize = size(m.W_main, 1)
eltype = typeof(m.b_main[1])
vm = zeros(eltype, vecsize)
vc = zeros(eltype, vecsize)
grad_main = zeros(eltype, vecsize)
grad_ctx = zeros(eltype, vecsize)

for n=1:s.niter
# shuffle indices
for i = 1:length(m.covec)
@inbounds l1 = m.covec[i].i # main index
@inbounds l2 = m.covec[i].j # context index
@inbounds v = m.covec[i].v

vm[:] = m.W_main[:, l1]
vc[:] = m.W_ctx[:, l2]

diff = dot(vec(vm), vec(vc)) + m.b_main[l1] + m.b_ctx[l2] - 
log(v)
fdiff = ifelse(v < xmax, (v / xmax) ^ alpha, 1.0) * diff
J += 0.5 * fdiff * diff

fdiff *= s.lrate
# inc memory by ~200 MB && running time by 2x
grad_main[:] = fdiff * m.W_ctx[:, l2]
grad_ctx[:] = fdiff * m.W_main[:, l1]

# Adaptive learning
# inc ~ 600MB + 0.75s
#= @inbounds for ii = 1:vecsize =#
#= m.W_main[ii, l1] -= grad_main[ii] / 
sqrt(m.W_main_grad[ii, l1]) =#
#= m.W_ctx[ii, l2] -= grad_ctx[ii] / sqrt(m.W_ctx_grad[ii, 
l2]) =#
#= m.b_main[l1] -= fdiff ./ sqrt(m.b_main_grad[l1]) =#
#= m.b_ctx[l2] -= fdiff ./ sqrt(m.b_ctx_grad[l2]) =#
#= end =#

m.W_main[:, l1] -= grad_main ./ sqrt(m.W_main_grad[:, l1])
m.W_ctx[:, l2] -= grad_ctx ./ sqrt(m.W_ctx_grad[:, l2])
m.b_main[l1] -= fdiff ./ sqrt(m.b_main_grad[l1])
m.b_ctx[l2] -= fdiff ./ sqrt(m.b_ctx_grad[l2])

# Gradients
fdiff *= fdiff
m.W_main_grad[:, l1] += grad_main .^ 2
m.W_ctx_grad[:, l2] += grad_ctx .^ 2
m.b_main_grad[l1] += fdiff
m.b_ctx_grad[l2] += fdiff
end

#= if n % 10 == 0 =#
#= println("iteration $n, cost $J") =#
#= end =#
end
end


Here's the entire repo https://github.com/domluna/GloVe.jl. Might be 
helpful.

I tried doing some loops but it allocates more memory (oddly enough) and 
gets slower.

You'll notice the word vectors are indexed by column, I changed the 
representation to that
seeing if it would make a difference during the loop. It didn't seem to.

The memory analysis showed

Julia Version 0.4.0-dev+4893
Commit eb5da26* (2015-05-19 11:51 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin14.4.0)
  CPU: Intel(R) Core(TM) i5-2557M CPU @ 1.70GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

Here model consists of 100x19 Matrices and 100 element vectors, 19 words in 
the vocab, 100 element word vector.

@time GloVe.train!(model, GloVe.Adagrad(500))
   1.990 seconds  (6383 k allocations: 1162 MB, 10.82% gc time)

0.3 has is a bit slower due to worse gc but same memory.

Any help would be greatly appreciated!


[julia-users] Re: What wrong in read(STDIN,Int) ?

2015-05-23 Thread elextr
`read` reads binary, not text.  939577809079766321 = d0a0d0a0d0a0d31 in 
hex, notice the last two digits (31) is the ASCII code for '1'  0d is 
carriage return and 0a is line feed.  Those are the binary values of what 
you typed.

you should use text IO to read the line, eg `readline()` and then convert 
to int, eg `x=int(readline())`

Cheers
Lex

On Sunday, May 24, 2015 at 3:35:03 AM UTC+10, paul analyst wrote:
>
> What wrong ? after typing "1" var = 939577809079766321
> (one ENTER is to small )
>
> julia> println("type any digit and ENTER");x=read(STDIN,Int)
> type any digit and ENTER
> 1
>
> 939577809079766321
> julia>
>
> julia> x
> 939577809079766321
>
> julia> println("type any digit and ENTER");x=read(STDIN,Int64)
> type any digit and ENTER
> 1
>


[julia-users] performance problem with factor

2015-05-23 Thread Steven G. Johnson
See https://github.com/JuliaLang/julia/pull/11189

[julia-users] Re: Question about modules and overloaded functions

2015-05-23 Thread Gabriel Goh
Thanks for the help guys! The pointer to the discussion helped! 

It seems the most "Juilesque" way to do this is to drop the modules 
altogether. All the solutions suggested didn't feel very appealing.

Gabe


Re: [julia-users] Re: How to stop the program and enter the value of the variable from the keyboard (by user)?

2015-05-23 Thread Jameson Nash
You are asking for a return value of type "Int", but have typed in the
character "1". Try instead:
x=chomp(readline(STDIN))
On Sat, May 23, 2015 at 7:31 PM paul analyst  wrote:

> What wrong ? after typing "1" var = 939577809079766321
> (one ENTER is to small )
>
> julia> println("type any digit and ENTER");x=read(STDIN,Int)
> type any digit and ENTER
> 1
>
> 939577809079766321
> julia>
>
> julia> x
> 939577809079766321
>
> julia> println("type any digit and ENTER");x=read(STDIN,Int64)
> type any digit and ENTER
> 1
>
>
>
> 939577809079766321
>
>
> Paul
>
>
> W dniu sobota, 23 maja 2015 13:02:54 UTC+2 użytkownik paul analyst napisał:
>>
>> How to stop the program and enter the value of the variable from the
>> keyboard (by user)?
>> in other words:
>> How to choose variants of the program with the keyboard?
>>
>> for example:
>>
>> a=zeros(10);
>> for i=1:10
>> x=rand(1);y=rand(1)
>> if x[].>y[] a[i]=x[]
>> else a[i]=SOMTHIG FROM KEYBOARD (USER DECISION)
>> end
>>
>> Paul
>>
>


[julia-users] Best practice in julia for sorting an array of UInt64 or byte strings, by frequency

2015-05-23 Thread Scott Jones
I know *how* to write this myself, as I would in C, but I'd like to know if 
one of the built-in datatypes (or a package) in Julia would handle this for 
me without me having to write much code...
I will be building up an array or dict or whatever with a key, where need 
to keep track of number of occurrences and a flag that indicates whether it 
is
present in group 1, group 2, or both...
I then need to sort it first by the group (group 1 first, then present in 
both, then group 2), and within the groups by frequency...

I am curious both about which approach in Julia would be the easiest and 
simplest to write (for when performance is not important, where I build
these tables just once), and which approach would perform the best (on 0.4, 
I'm not interested in 0.3.x). [Maybe it is the same approach... that would 
be nice!]

Thanks for any advice on this!


[julia-users] What wrong in read(STDIN,Int) ?

2015-05-23 Thread paul analyst
What wrong ? after typing "1" var = 939577809079766321
(one ENTER is to small )

julia> println("type any digit and ENTER");x=read(STDIN,Int)
type any digit and ENTER
1

939577809079766321
julia>

julia> x
939577809079766321

julia> println("type any digit and ENTER");x=read(STDIN,Int64)
type any digit and ENTER
1


[julia-users] What wrong in read(STDIN,Int) ??? Re: How to stop the program and enter the value of the variable from the keyboard (by user)?

2015-05-23 Thread paul analyst
What wrong   in read(STDIN,Int) ??? 

W dniu sobota, 23 maja 2015 19:31:47 UTC+2 użytkownik paul analyst napisał:
>
> What wrong ? after typing "1" var = 939577809079766321
> (one ENTER is to small )
>
> julia> println("type any digit and ENTER");x=read(STDIN,Int)
> type any digit and ENTER
> 1
>
> 939577809079766321
> julia>
>
> julia> x
> 939577809079766321
>
> julia> println("type any digit and ENTER");x=read(STDIN,Int64)
> type any digit and ENTER
> 1
>
>
>
> 939577809079766321
>
> Paul
>
> W dniu sobota, 23 maja 2015 13:02:54 UTC+2 użytkownik paul analyst napisał:
>>
>> How to stop the program and enter the value of the variable from the 
>> keyboard (by user)?
>> in other words:
>> How to choose variants of the program with the keyboard?
>>
>> for example:
>>
>> a=zeros(10);
>> for i=1:10
>> x=rand(1);y=rand(1)
>> if x[].>y[] a[i]=x[]
>> else a[i]=SOMTHIG FROM KEYBOARD (USER DECISION)
>> end
>>
>> Paul
>>
>

[julia-users] Re: How to stop the program and enter the value of the variable from the keyboard (by user)?

2015-05-23 Thread paul analyst
What wrong ? after typing "1" var = 939577809079766321
(one ENTER is to small )

julia> println("type any digit and ENTER");x=read(STDIN,Int)
type any digit and ENTER
1

939577809079766321
julia>

julia> x
939577809079766321

julia> println("type any digit and ENTER");x=read(STDIN,Int64)
type any digit and ENTER
1



939577809079766321

Paul

W dniu sobota, 23 maja 2015 13:02:54 UTC+2 użytkownik paul analyst napisał:
>
> How to stop the program and enter the value of the variable from the 
> keyboard (by user)?
> in other words:
> How to choose variants of the program with the keyboard?
>
> for example:
>
> a=zeros(10);
> for i=1:10
> x=rand(1);y=rand(1)
> if x[].>y[] a[i]=x[]
> else a[i]=SOMTHIG FROM KEYBOARD (USER DECISION)
> end
>
> Paul
>


[julia-users] performance problem with factor

2015-05-23 Thread harven
The factor function seems to be slow.

julia> @time factor(147573952589676412927)   # 2^67-1;  Cole
  elapsed time: 4.955545116 seconds (6 MB allocated, 6.82% gc time in 1 
pauses with 0 full sweep)
  Dict{Int128,Int64} with 2 entries:
761838257287 => 1
193707721=> 1

This is even worse if a bigint is taken as argument (e.g. big(2)^67-1).
In contrast, here is the timing for the unix factor utility (instant)

  $ time factor 147573952589676412927
  147573952589676412927: 193707721 761838257287

  real0m0.043s
  user0m0.000s
  sys 0m0.004s

Is there a way to speed up the factorisation with julia?


[julia-users] Re: seaching on multiple columns

2015-05-23 Thread David Gold
I'm also going to plug for DataFramesMeta, especially 
https://github.com/JuliaStats/DataFramesMeta.jl#where. For your example, 
you could use

@where df (:donor .== "Patient") & (:pregnant .== "yes")

See also this related issue: 
https://github.com/JuliaStats/DataFramesMeta.jl/issues/13

On Saturday, May 23, 2015 at 11:09:21 AM UTC-4, Martin Somers wrote:
>
> Was trying something like this earlier
>
> df[df[:donor] .== "Patient" & df[:pregnant] .== "yes", :]
>
> but doesnt seem to work is this even possible or am I going to have sub 
> divid the operations
> what the what most efficient syntax
>
> M
>


Re: [julia-users] seaching on multiple columns

2015-05-23 Thread Milan Bouchet-Valat
Le samedi 23 mai 2015 à 08:09 -0700, Martin Somers a écrit :
> Was trying something like this earlier
> 
> 
> df[df[:donor] .== "Patient" & df[:pregnant] .== "yes", :]
> 
> 
> 
> but doesnt seem to work is this even possible or am I going to have
> sub divid the operations
> what the what most efficient syntax
You just need to add parentheses like this:
df[(df[:donor] .== "Patient") & (df[:pregnant] .== "yes"), :]

By the way, DataFramesMeta offers convenience macros that you may find
useful for this kind of operations:
https://github.com/JuliaStats/DataFramesMeta.jl


Regards



[julia-users] Re: Question about modules and overloaded functions

2015-05-23 Thread David Gold
One such recent, long discussion can be found at 
https://groups.google.com/forum/?hl=en#!topic/julia-users/sk8Gxq7ws3w.

I will also take this opportunity to plug shamelessly for my "package" 
https://github.com/davidagold/MetaMerge.jl that allows you to merge 
functions. For your example, so long as you have a function f defined in 
the module from which you call fmerge!, you can do

fmerge!(f, (A, f), (B, f))

and now the function f (as defined in the module in which fmerge! is 
called) will have both methods. 

On Saturday, May 23, 2015 at 10:56:56 AM UTC-4, Gabriel Goh wrote:
>
> Hey all,
>
> I'm wondering if you guys could educate me on the correct way to overload 
> functions in modules. The code here doesn't work:
>
> # **
>
> module A
>
> type apple
> end
>
> export apple,f
>
> f(x::A.apple) = println("I am apple");
>
> end
>
> # **
>
> module B
>
> type orange
> end
>
> export orange, f
>
> f(x::B.orange) = println("I am orange");
>
> end
>
> using A
> using B
>
> f(apple())
> f(orange())
>
> I expect julia to print "I am apple" and "I am orange", but instead I get
>
> ERROR: `f` has no method matching f(::apple)
>
> Any clues?
>


[julia-users] seaching on multiple columns

2015-05-23 Thread Martin Somers
Was trying something like this earlier

df[df[:donor] .== "Patient" & df[:pregnant] .== "yes", :]

but doesnt seem to work is this even possible or am I going to have sub 
divid the operations
what the what most efficient syntax

M


Re: [julia-users] Question about modules and overloaded functions

2015-05-23 Thread Mauro
Inside B you have to do:

B.f(x::B.orange) = println("I am orange")

If you can be bothered you can read through some recent, long
discussions on the merits of this approach.

(BTW, I think in Julia 0.4, your example should give a better error.)

On Sat, 2015-05-23 at 06:43, Gabriel Goh  wrote:
> Hey all,
>
> I'm wondering if you guys could educate me on the correct way to overload 
> functions in modules. The code here doesn't work:
>
> # **
>
> module A
>
> type apple
> end
>
> export apple,f
>
> f(x::A.apple) = println("I am apple");
>
> end
>
> # **
>
> module B
>
> type orange
> end
>
> export orange, f
>
> f(x::B.orange) = println("I am orange");
>
> end
>
> using A
> using B
>
> f(apple())
> f(orange())
>
> I expect julia to print "I am apple" and "I am orange", but instead I get
>
> ERROR: `f` has no method matching f(::apple)
>
> Any clues?



[julia-users] Question about modules and overloaded functions

2015-05-23 Thread Gabriel Goh
Hey all,

I'm wondering if you guys could educate me on the correct way to overload 
functions in modules. The code here doesn't work:

# **

module A

type apple
end

export apple,f

f(x::A.apple) = println("I am apple");

end

# **

module B

type orange
end

export orange, f

f(x::B.orange) = println("I am orange");

end

using A
using B

f(apple())
f(orange())

I expect julia to print "I am apple" and "I am orange", but instead I get

ERROR: `f` has no method matching f(::apple)

Any clues?


Re: [julia-users] Using macroexpand for non-debugging

2015-05-23 Thread Mauro
For @nref there is actually the function _nref which makes the
expression, so no need to use macroexpand.  I would suspect that is the
preferred way.

On Sat, 2015-05-23 at 00:33, Peter Brady  wrote:
> I've noticed that a common pattern in my code is to use macroexpand inside 
> functions/macros to generate expressions which are then further manipulated 
> into what I need.  As an example, here's a short function I wrote to unroll 
> a finite difference stencil at a wall (which is then spliced into a larger 
> function to compute the requested derivatives)
>
> julia> function unroll_left(st, idx, N=3)
>pd = quote end
>for j=1:size(st,2)
>ex = Expr(:call, :+)
>for i=1:size(st,1)
>solref = macroexpand(:(@nref $N sol 
> d->(d==$idx?$i:i_{d})))
>push!(ex.args, :($solref*$(st[i,j])))
>end
>derref = macroexpand(:(@nref $N der d->(d==$idx?$j:i_{d})))
>push!(pd.args, :($derref = $ex))
>end
>pd
>end
>
> julia> a = rand(4,2)
> 4x2 Array{Float64,2}:
>  0.0352328  0.342554 
>  0.898077   0.489546 
>  0.933981   0.558188 
>  0.721357   0.0678564
>
> julia> unroll_left(a, 1)
> quote 
> der[1,i_2,i_3] = sol[1,i_2,i_3] * 0.035232761679327096 + sol[2,i_2,i_3] 
> * 0.8980770465285655 + sol[3,i_2,i_3] * 0.9339813198913125 + sol[4,i_2,i_3] 
> * 0.7213570230346098
> der[2,i_2,i_3] = sol[1,i_2,i_3] * 0.34255367557827077 + sol[2,i_2,i_3] 
> * 0.4895461571970048 + sol[3,i_2,i_3] * 0.5581879223691961 + sol[4,i_2,i_3] 
> * 0.06785635982311189
> end
>
> julia> unroll_left(a, 2)
> quote 
> der[i_1,1,i_3] = sol[i_1,1,i_3] * 0.035232761679327096 + sol[i_1,2,i_3] 
> * 0.8980770465285655 + sol[i_1,3,i_3] * 0.9339813198913125 + sol[i_1,4,i_3] 
> * 0.7213570230346098
> der[i_1,2,i_3] = sol[i_1,1,i_3] * 0.34255367557827077 + sol[i_1,2,i_3] 
> * 0.4895461571970048 + sol[i_1,3,i_3] * 0.5581879223691961 + sol[i_1,4,i_3] 
> * 0.06785635982311189
> end
>
>
> This works perfectly but using macroexpand in this way feels a bit hackish. 
>  Is there a better way?



[julia-users] How to stop the program and enter the value of the variable from the keyboard (by user)?

2015-05-23 Thread paul analyst
 How to stop the program and enter the value of the variable from the 
keyboard (by user)?
in other words:
How to choose variants of the program with the keyboard?

for example:

a=zeros(10);
for i=1:10
x=rand(1);y=rand(1)
if x[].>y[] a[i]=x[]
else a[i]=SOMTHIG FROM KEYBOARD (USER DECISION)
end

Paul