inheritance when extending goog library

2012-10-01 Thread Wei Hsu
I want to add a callback for goog.ui.Popup to call when it's closed.
The latest version of the closure library supports adding callbacks
(http://closure-library.googlecode.com/svn/docs/
closure_goog_disposable_disposable.js.source.html#line209), but the
version that Clojurescript uses doesn't.

Therefore, I'm extending goog.ui.Disposable using Brian Taylor's macro
(http://www.50ply.com/blog/2012/07/08/extending-closure-from-
clojurescript). The problem is, how do I make goog.ui.Popup use my
version of Disposable?

Thanks,
Wei

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


fileseq modifiers - :min-depth, :max-depth ?

2012-10-01 Thread coltnz
Hi,

not sure if this is considered too frivolous somehow but I've thought many 
times how nice it would be to modify a fileseq call by using a min-depth or 
max-depth modifier rather constructing a filter.

Depth would refer to the levels of the underlying treeseq returned.
So min-depth=0,max-depth=0 would return the original file only;  
min-depth=1,max-depth=1 just its children etc..

Does this appeal to anyone else?

cheers
Colin


-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Core.logic performance of looping over a list with tabling

2012-10-01 Thread Reinout Stevens


On Saturday, September 29, 2012 11:10:38 PM UTC+2, David Nolen wrote:
>
> On Wed, Sep 26, 2012 at 9:20 AM, Reinout Stevens 
> 
> > wrote:
>
>> Hi,
>>
>>
>> I'm the author of a DSL that allows reasoning over paths throughout 
>> graphs using core.logic ( https://github.com/ReinoutStevens/damp.qwal ). 
>> We noticed that for larger graphs performance became horribly slow, even 
>> though there is no apparent reason why it should be. First investigations 
>> lead me to believe tabling was the issue. We use tabling to prevent 
>> infinite loops due to cycles in the graph. After writing a small testcase 
>> that exhibits the described problems I've noticed that it is a combination 
>> of tabling and looping over a list.
>>
>> In the test case we construct a linear graph (so: a graph where each node 
>> has a single successor). We want to asser that there exists a path from the 
>> start to the end node. This is done by using the logical rule trans 
>> [graph current next], which given a graph and the current node binds next to 
>> the possible successors. We write this query in three different ways. 
>> First, we try to succeed the goal trans as many times as needed, until we 
>> end up in the end state. Next, we do the same but tabling our loop. This 
>> prevents looping in case our graph would contain a cycle (in this case, 
>> there is no such cycle). Finally, instead of directly proving trans, we 
>> prove a list of goals. This list contains a single goal (trans). This last 
>> scenario runs much slower than the previous two, even though I don't see a 
>> large difference with the first two scenarios.
>>
>> In attachment the code of our test case. There are 3 functions at the 
>> end, each implementing one of the described scenarios. Note the difference 
>> between solve-goal and solve-goals.
>>
>> Any pointers how to solve the issue, or work around it are appreciated
>>
>
> I took some time to look into this. The issue is that your terms are quite 
> complex - the entire graph is the first arg to the tabled goal! In order 
> for tabling to work this argument needs to be reified (completely walked 
> and all logic vars replaced with copies) and this is used as the table 
> cache key. As you can imagine this means given the way you've written your 
> program the entries in the table can get quite large and the comparisons to 
> determine whether a reusable cached answer term exists is quite expensive!
>
> It's important to table at the right "level". Does this make sense and can 
> you formulate a solution so that you're not passing in the entire graph as 
> the first argument to the tabled goal?
>
> David
>
>
Hi,


I quickly changed the code so that the graph structure no longer contains 
the list of nodes, and the same behaviour still persists. For the actual 
implementation I have changed it to a function that returns a list of 
nodes, which can be compared in O(1) instead of looping over the data 
structure, and also here we get the same behaviour. 

Personally, I don't see the difference between calling solve-goal or 
solve-goals, as both should have an equally large table. The recursive step 
of solve-goals shouldn't do anything, as we are only passing a list 
containing a single item. In attachment the updated code (aka: just removed 
the :node key from the graph).


Thanks for taking your time and looking into this,


Reinout

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

tabling.clj
Description: Binary data


Re: Core.logic performance of looping over a list with tabling

2012-10-01 Thread David Nolen
Looking into it.

On Monday, October 1, 2012, Reinout Stevens wrote:

>
>
> On Saturday, September 29, 2012 11:10:38 PM UTC+2, David Nolen wrote:
>>
>> On Wed, Sep 26, 2012 at 9:20 AM, Reinout Stevens wrote:
>>
>>> Hi,
>>>
>>>
>>> I'm the author of a DSL that allows reasoning over paths throughout
>>> graphs using core.logic ( 
>>> https://github.com/**ReinoutStevens/damp.qwal).
>>>  We noticed that for larger graphs performance became horribly slow, even
>>> though there is no apparent reason why it should be. First investigations
>>> lead me to believe tabling was the issue. We use tabling to prevent
>>> infinite loops due to cycles in the graph. After writing a small testcase
>>> that exhibits the described problems I've noticed that it is a combination
>>> of tabling and looping over a list.
>>>
>>> In the test case we construct a linear graph (so: a graph where each
>>> node has a single successor). We want to asser that there exists a path
>>> from the start to the end node. This is done by using the logical rule trans
>>> [graph current next], which given a graph and the current node binds
>>> next to the possible successors. We write this query in three different
>>> ways. First, we try to succeed the goal trans as many times as needed,
>>> until we end up in the end state. Next, we do the same but tabling our
>>> loop. This prevents looping in case our graph would contain a cycle (in
>>> this case, there is no such cycle). Finally, instead of directly proving
>>> trans, we prove a list of goals. This list contains a single goal (trans).
>>> This last scenario runs much slower than the previous two, even though I
>>> don't see a large difference with the first two scenarios.
>>>
>>> In attachment the code of our test case. There are 3 functions at the
>>> end, each implementing one of the described scenarios. Note the difference
>>> between solve-goal and solve-goals.
>>>
>>> Any pointers how to solve the issue, or work around it are appreciated
>>>
>>
>> I took some time to look into this. The issue is that your terms are
>> quite complex - the entire graph is the first arg to the tabled goal! In
>> order for tabling to work this argument needs to be reified (completely
>> walked and all logic vars replaced with copies) and this is used as the
>> table cache key. As you can imagine this means given the way you've written
>> your program the entries in the table can get quite large and the
>> comparisons to determine whether a reusable cached answer term exists is
>> quite expensive!
>>
>> It's important to table at the right "level". Does this make sense and
>> can you formulate a solution so that you're not passing in the entire graph
>> as the first argument to the tabled goal?
>>
>> David
>>
>>
> Hi,
>
>
> I quickly changed the code so that the graph structure no longer contains
> the list of nodes, and the same behaviour still persists. For the actual
> implementation I have changed it to a function that returns a list of
> nodes, which can be compared in O(1) instead of looping over the data
> structure, and also here we get the same behaviour.
>
> Personally, I don't see the difference between calling solve-goal or
> solve-goals, as both should have an equally large table. The recursive step
> of solve-goals shouldn't do anything, as we are only passing a list
> containing a single item. In attachment the updated code (aka: just removed
> the :node key from the graph).
>
>
> Thanks for taking your time and looking into this,
>
>
> Reinout
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to 
> clojure@googlegroups.com 'clojure@googlegroups.com');>
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com  'clojure%2bunsubscr...@googlegroups.com');>
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Is Slick feasible in Clojure?

2012-10-01 Thread Timothy Baldridge
I've thought about this as well. Coming from the .NET world I'm quite
familiar with the Linq.Expression namespace. I too have wondered about
this. For those who are not familiar with how IQueryable works in Linq,
it's something like the following (in clojure):


(def query (q (db :people)
(where #(> (:age %) 21))
:last-name
distinct))

The (db :people) call will return a IQueryable object. The q macro will
then take all the clauses in the query, wrap them up into an AST, and then
create a lazy seq. At this point in the code, nothing has been executed.
Upon calling (first query), the q macro hands the AST to the IQueryable
object, and then calls Execute on the object. Execute does whatever it
pleases with the AST, and then returns a lazy seq of the results.

A C# tutorial on this, is available here (
http://wekeroad.com/2007/07/02/linq-how-to-use-linq-to-query-just-about-anything/
)

I see this fitting into the Clojure ecosystem in a very interesting way:

Seq abstraction -
Lazy evaluation
Must run on the local CPU (for map, reduce, etc.)
Must run in order
Data provider can't influence execution

Reducers -
Data provider can influence execution
Must run on the local CPU
Can run in any order

IQueryable abstraction -
Data provider has full control over execution
Code can be run anywhere
Provider must compile code.


Example providers of IQueryable:

Entity Framework (Linq over SQL)
Linq to XML (Linq over XML)
Linq to GPU (run queries on a graphics processor)
http://brahma.ananthonline.net/
I've also seen index providers for in-memory data structures


So, I guess the original question still remains. Would Clojure benefit from
an AST abstraction? I know we have macros, but is that enough?

I'd love input on this topic.

Timothy Baldridge

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Is Slick feasible in Clojure?

2012-10-01 Thread Yann Schwartz
On Mon, Oct 1, 2012 at 4:45 PM, Timothy Baldridge wrote:

> I've thought about this as well. Coming from the .NET world I'm quite
> familiar with the Linq.Expression namespace. I too have wondered about
> this. For those who are not familiar with how IQueryable works in Linq,
> it's something like the following (in clojure):
>
>
> (def query (q (db :people)
> (where #(> (:age %) 21))
> :last-name
> distinct))
>
> The (db :people) call will return a IQueryable object. The q macro will
> then take all the clauses in the query, wrap them up into an AST, and then
> create a lazy seq. At this point in the code, nothing has been executed.
> Upon calling (first query), the q macro hands the AST to the IQueryable
> object, and then calls Execute on the object. Execute does whatever it
> pleases with the AST, and then returns a lazy seq of the results.
>
> A C# tutorial on this, is available here (
> http://wekeroad.com/2007/07/02/linq-how-to-use-linq-to-query-just-about-anything/
> )
>
> I see this fitting into the Clojure ecosystem in a very interesting way:
>
> Seq abstraction -
> Lazy evaluation
> Must run on the local CPU (for map, reduce, etc.)
> Must run in order
> Data provider can't influence execution
>
> Reducers -
> Data provider can influence execution
> Must run on the local CPU
> Can run in any order
>
> IQueryable abstraction -
> Data provider has full control over execution
> Code can be run anywhere
> Provider must compile code.
>
>
> Example providers of IQueryable:
>
> Entity Framework (Linq over SQL)
> Linq to XML (Linq over XML)
> Linq to GPU (run queries on a graphics processor)
> http://brahma.ananthonline.net/
> I've also seen index providers for in-memory data structures
>
>
Not to nitpick, but Linq to XML is based on Linq to objects entirely (no
IQueryable, juste vanilla IEnumerables). There also used to be a "Linq to
Map reduce" (called DryadLINQ, then Linq to HPC, then "let's forget about
this and hop on the hadoop bandwagon") which looked a lot like Scalding
(Scala over Cascading), only with IQueryable goodies.

To my - naive - knowledge of clojure macros, writing an provider in clojure
would be a lot easier than it is in C# (or even with F# quotations).

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Is Slick feasible in Clojure?

2012-10-01 Thread Timothy Baldridge
> Not to nitpick, but Linq to XML is based on Linq to objects entirely (no
> IQueryable, juste vanilla IEnumerables).
>

You're correct.



> To my - naive - knowledge of clojure macros, writing an provider in
> clojure would be a lot easier than it is in C# (or even with F# quotations).
>
>
I would agree with that, but what is missing with macros is a formalized
specification. With IQueryable we can concat queries, and generalize
algorithms completely separate from the input provider.

For example:

public static IQueryable Over21(this IQueryable q)
{
return q.Where(p => p.age > 21);
}


Now in C# we can do this:

var people = database.Over21().ToList(); // Compiles to SQL WHERE clauses
var people = vector.Over21().ToList(); // Compiles to an in-memory filter

So this is the power of IQueryable. It decouples the query code from the
provider.

Datalog was brought up earlier, I wonder if it could be extended to provide
this sort of interface.

Timothy

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Is Slick feasible in Clojure?

2012-10-01 Thread Alessio Stalla


Il giorno lunedì 1 ottobre 2012 16:45:44 UTC+2, tbc++ ha scritto:
>
> I've thought about this as well. Coming from the .NET world I'm quite 
> familiar with the Linq.Expression namespace. I too have wondered about 
> this. For those who are not familiar with how IQueryable works in Linq, 
> it's something like the following (in clojure):
>
>
> (def query (q (db :people)
> (where #(> (:age %) 21))
> :last-name
> distinct))
>
> The (db :people) call will return a IQueryable object. The q macro will 
> then take all the clauses in the query, wrap them up into an AST, and then 
> create a lazy seq. At this point in the code, nothing has been executed. 
> Upon calling (first query), the q macro hands the AST to the IQueryable 
> object, and then calls Execute on the object. Execute does whatever it 
> pleases with the AST, and then returns a lazy seq of the results. 
>
> A C# tutorial on this, is available here (
> http://wekeroad.com/2007/07/02/linq-how-to-use-linq-to-query-just-about-anything/
> )
>
> I see this fitting into the Clojure ecosystem in a very interesting way:
>
> Seq abstraction - 
> Lazy evaluation
> Must run on the local CPU (for map, reduce, etc.)
> Must run in order
> Data provider can't influence execution
>
> Reducers -
> Data provider can influence execution
> Must run on the local CPU
> Can run in any order
>
> IQueryable abstraction - 
> Data provider has full control over execution
> Code can be run anywhere
> Provider must compile code. 
>
>
> Example providers of IQueryable:
>
> Entity Framework (Linq over SQL)
> Linq to XML (Linq over XML)
> Linq to GPU (run queries on a graphics processor) 
> http://brahma.ananthonline.net/
> I've also seen index providers for in-memory data structures
>
>
> So, I guess the original question still remains. Would Clojure benefit 
> from an AST abstraction? I know we have macros, but is that enough? 
>
> I'd love input on this topic. 
>
>
The missing feature is not AST abstraction, but rather compile-time access 
to an environment with enough meaningful static type information.

An AST abstraction is a representation of (part of) a program's syntax as 
data structures and functions that can operate on them. All Lisps have it; 
most, like Clojure and Common Lisp, have it in the simple form of 
S-Expressions, while others, like some (all?) Scheme dialects, use more 
complex objects that can hold additional information, such as the file name 
and line number they were parsed from.

C# has an AST abstraction too, which, as far as I know, is limited to the 
subset of the language usable in the body of lambda expressions. The C# AST 
implementation is strongly typed, whereas in Lisp the AST is only loosely 
typed, because while each atom is of a well-known type, compound 
expressions are just lists (or sometimes, in Clojure, vector or maps). This 
is an important difference, but it has no impact on the implementation of 
something like LINQ.

In fact, the AST abstraction is only one leg of the support for LINQ in C#; 
the other important aspect is that LINQ is able to generate different code 
depending on the static type of the object being queried. Querying a 
collection will generate code to map, filter etc. that collection, while 
querying a database connection will generate code that submits SQL queries 
to the RDBMS. You cannot generally do that in Lisp because you cannot know 
the static type of the variables that a macro is invoked on; you would have 
to generate code that dispatches at runtime (which might be perfectly 
acceptable, mind you, but is not the same thing as LINQ).

As part of the Common Lisp standardization process, there was a proposal 
for an environment access API that exposed the lexical environment to macro 
writers. The feature did not become part of Common Lisp, but it is 
described in CLtL2, and some CL implementations provide it even if it's not 
in the standard. With that feature and a good type inference engine, it 
would be possible for a macro to generate code depending on the static type 
of one or more of its arguments, because you could query the environment 
for the type of each variable. 

Alessio Stalla

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Playing with clojure-encog, Machine-Learning wrapper

2012-10-01 Thread Timothy Washington
Hey, thanks for responding. See responses inlined.


On Mon, Oct 1, 2012 at 4:24 AM, Jim - FooBar(); wrote:

>  I've always found this page very good :
>
> http://www.doc.ic.ac.uk/~nd/surprise_96/journal/vol4/cs11/report.html
>
> generally, the weight of a connection is adjusted by an amount
> proportional to the product of an error signal δ, on the unit k receiving
> the input and the output of the unit j sending this signal along the
> connection. You use the chain rule to calculate partial derivatives.
>
> also this looks quite detailed with regards to what you're asking:
>
>
> https://docs.google.com/viewer?a=v&q=cache:9ahoWLbap8AJ:www.cedar.buffalo.edu/~srihari/CSE574/Chap5/Chap5.3-BackProp.pdf+the+partial+derivative+of+the+error+neural+nets&hl=en&gl=uk&pid=bl&srcid=ADGEEShVr8tHNIryQDGp0jJ2xv6JM40Ja4UFbcr2-QDgU1tK4Di_4mUTVgWsHdjHphbS7MaHmSn8VwB3dEnAQz-w4J-iyF1VJFklvLoDY5fxJbGaHsU0mio7XQYmGom0_cd7aZkUzhq5&sig=AHIEtbTyaLysuBdK7Bn_-cMzE88tqOzlag
>
>
Looking at page 9 of this document, I take the error derivative calculation
to be:

Thus required derivative *∂En/∂w ji* is obtained by...


   1. Multiplying value of δ ( for the unit at output end of weight )
  2. by value of z ( for unit at input end of weight )


So take this output neuron and it's input weights. Let's say the total
neural network error is *-0.3963277746392987*. I just multiply that total
error by each weight, to get the bolded, green error values. So what you're
saying is that the error derivative *∂En/∂w ji *( or weight change) for
each input is that same error value, below in green. Is this the case?

:output-layer
>
>
>
>  ({:calculated-error -1.1139741279964241,
>
>
>:calculated-value 0.9275622253607013,
>
>
>:inputs
>
>
>({:error *-0.2016795955938916*,
>  :calculated 0.48962608882549025,
>
>
>  :input-id "583c10bfdbd326ba525bda5d13a0a894b947ffb",
>
>
>  :weight 0.5088707087900713,
>
>
>  :bias 0}
>
>
> {:error *-0.15359996014735702*,
>  :calculated 0.3095962076691644,
>
>
>  :input-id "583c10bfdbd326ba525bda5d13a0a894b947ffa",
>
>
>  :weight 0.38755790024342773,
>
>
>  :bias 0}
>
>
> {:error *-0.11659507401745359*
>  :calculated 0.23938733624830652,
>
>
>  :input-id "583c10bfdbd326ba525bda5d13a0a894b947ff9",
>
>
>  :weight 0.2941885012312543,
>
>
>  :bias 0}
>
>
> {:error *-0.2784739949663631*,
>  :calculated 0.6681581686752845,
>
>
>  :input-id "583c10bfdbd326ba525bda5d13a0a894b947ff8",
>
>
>  :weight 0.7026355778870271,
>
>
>  :bias 0}
>
>
> {:error *-0.36362550327135884*,
>  :calculated 0.8430641676611533,
>
>
>  :input-id "583c10bfdbd326ba525bda5d13a0a894b947ff7",
>
>
>  :weight 0.9174868039523537,
>
>
>  :bias 0}),
>
>
>:id "583c10bfdbd326ba525bda5d13a0a894b947ff6"})
>
>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Playing with clojure-encog, Machine-Learning wrapper

2012-10-01 Thread Jim - FooBar();

Hmmm...I am not sure I follow...
the error is simply (- target actual). Then you take the square of that 
difference (2 reasons for that) and there you have the error per neuron 
at the output layer. Then you simply add them up to get the entire 
network's error. so far so good...


the tricky bit comes now when you need to find out how much the error 
depends on the output, inputs and weights so you can feed that in to the 
gradient descent formula via which the weights will be adjusted. 
Basically gradient descent says this:


"the adjustment of each weight will be the negative of a constant theta 
multiplied by the dependence of the previous weight on the error of the 
network, which is the derivative of that error with respect to that weight."


so essentially you're only looking to find the derivative of E (total 
error) with respect to Wij , but in order to find that you will need to know


 * how much the error depends on the output
 * how much the output depends on the activation (which depends on the
   weights)


It is not straight forward to type formulas here but I've put a relevant 
document that describes the procedure exactly and the encog book which i 
cannot guarantee it goes that deep, in my public dropbox for you. the 
link is :https://dl.dropbox.com/u/45723414/for_Tim.tar.gz ...I'll leave 
it up until tomorrow...


hope that helps...

Jim

ps: the encog source did not help you?



On 01/10/12 19:41, Timothy Washington wrote:

Hey, thanks for responding. See responses inlined.


On Mon, Oct 1, 2012 at 4:24 AM, Jim - FooBar(); > wrote:


I've always found this page very good :

http://www.doc.ic.ac.uk/~nd/surprise_96/journal/vol4/cs11/report.html


generally, the weight of a connection is adjusted by an amount
proportional to the product of an error signal δ, on the unit k
receiving the input and the output of the unit j sending this
signal along the connection. You use the chain rule to calculate
partial derivatives.

also this looks quite detailed with regards to what you're asking:


https://docs.google.com/viewer?a=v&q=cache:9ahoWLbap8AJ:www.cedar.buffalo.edu/~srihari/CSE574/Chap5/Chap5.3-BackProp.pdf+the+partial+derivative+of+the+error+neural+nets&hl=en&gl=uk&pid=bl&srcid=ADGEEShVr8tHNIryQDGp0jJ2xv6JM40Ja4UFbcr2-QDgU1tK4Di_4mUTVgWsHdjHphbS7MaHmSn8VwB3dEnAQz-w4J-iyF1VJFklvLoDY5fxJbGaHsU0mio7XQYmGom0_cd7aZkUzhq5&sig=AHIEtbTyaLysuBdK7Bn_-cMzE88tqOzlag




Looking at page 9 of this document, I take the error derivative 
calculation to be:


Thus required derivative */∂En/∂w ji/* is obtained by...

 1. Multiplying value of δ ( for the unit at output end of weight )
 2. by value of z ( for unit at input end of weight )


So take this output neuron and it's input weights. Let's say the total 
neural network error is *-0.3963277746392987*. I just multiply that 
total error by each weight, to get the bolded, green error values. So 
what you're saying is that the error derivative */∂En/∂w ji /*( or 
weight change) for each input is that same error value, below in 
green. Is this the case?



:output-layer
({:calculated-error -1.1139741279964241,
  :calculated-value 0.9275622253607013,
  :inputs
  ({:error */-0.2016795955938916/*,
:calculated 0.48962608882549025,
:input-id "583c10bfdbd326ba525bda5d13a0a894b947ffb",
:weight 0.5088707087900713,
:bias 0}
   {:error */-0.15359996014735702/*,
:calculated 0.3095962076691644,
:input-id "583c10bfdbd326ba525bda5d13a0a894b947ffa",
:weight 0.38755790024342773,
:bias 0}
   {:error */-0.11659507401745359/*
:calculated 0.23938733624830652,
:input-id "583c10bfdbd326ba525bda5d13a0a894b947ff9",
:weight 0.2941885012312543,
:bias 0}
   {:error */-0.2784739949663631/*,
:calculated 0.6681581686752845,
:input-id "583c10bfdbd326ba525bda5d13a0a894b947ff8",
:weight 0.7026355778870271,
:bias 0}
   {:error */-0.36362550327135884/*,
:calculated 0.8430641676611533,
:input-id "583c10bfdbd326ba525bda5d13a0a894b947ff7",
:weight 0.9174868039523537,
:bias 0}),
  :id "583c10bfdbd326ba525bda5d13a0a894b947ff6"})





--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send emai

Regarding Starting Clojure

2012-10-01 Thread aboy021
I decided to quickly compare the website experience of starting Clojure and 
starting Scala.

I do a Google search for Clojure
I decide to try the first link, Clojure.org
There's some basic information. I follow the somewhat obscure link halfway 
down the side, "Getting Started"
Ok, that looks promising, now I can get a REPL to interact with.
I follow the link to the Getting Started Documentation 
(http://dev.clojure.org/display/doc/Getting+Started) (isn't that where I 
already was?) 
Still flailing a bit, I follow the link to Mark Volkmann's Tutorial.
This is the first chance I've had to see what Clojure actually looks like 
and how to program in it.

In stark contrast, I try searching for Scala.
I get presented with an appealing, nicely laid out page with large links to 
an introduction to the language and a page on getting started.
There are links in an easy to navigate menu with Information about the 
language, documentation, code examples, Software, and Developer information.

Now, I'm no Scala developer, but at first glance it seems like I've found a 
great touch stone that I can use to find out what's happening in the 
language, how it looks, what it can do for me, and I can learn how to write 
it.

Another thing that the scala-lang site has is Code Examples. Code examples 
are a really nice way for you to get a taste of how a language can solve 
common problems, and they can give you a real sense of the flavour of the 
language.

A lot of the information for Clojure seems to be there, it's just not laid 
out in an attractive easy to use format. Perhaps we could have a fundraiser 
to pay for a web designer to make a nice modern website that contains the 
information in an easier to digest and more centralised way

The getting started issue is an ongoing problem for Clojure. It's an issue 
that keeps coming up in the surveys and on the mailing list. Other 
languages are doing it really well, Scala is just a convenient example. 
What does the Clojure community need to do to help support the creation of 
something that is on par?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Playing with clojure-encog, Machine-Learning wrapper

2012-10-01 Thread Timothy Washington
Hey, thanks for these. I'll take the evening to read through them. It's the
gradient descent calculation that I find to be convoluted. I understand the
concept. But I haven't seen a clear example of how that's done. That's what
I was trying to nail down with that output neuron example. And reading the
encog-java source code wasn't any clearer either.

Thanks very much for the resources. Perhaps these docs will help.


Tim Washington
Interruptsoftware.ca



On Mon, Oct 1, 2012 at 3:43 PM, Jim - FooBar(); wrote:

>  Hmmm...I am not sure I follow...
> the error is simply (- target actual). Then you take the square of that
> difference (2 reasons for that) and there you have the error per neuron at
> the output layer. Then you simply add them up to get the entire network's
> error. so far so good...
>
> the tricky bit comes now when you need to find out how much the error
> depends on the output, inputs and weights so you can feed that in to the
> gradient descent formula via which the weights will be adjusted. Basically
> gradient descent says this:
>
> "the adjustment of each weight will be the negative of a constant theta
> multiplied by the dependence of the previous weight on the error of the
> network, which is the derivative of that error with respect to that weight."
>
> so essentially you're only looking to find the derivative of E (total
> error) with respect to Wij , but in order to find that you will need to know
>
>
>- how much the error depends on the output
>- how much the output depends on the activation (which depends on the
>weights)
>
>
> It is not straight forward to type formulas here but I've put a relevant
> document that describes the procedure exactly and the encog book which i
> cannot guarantee it goes that deep, in my public dropbox for you. the link
> is :https://dl.dropbox.com/u/45723414/for_Tim.tar.gz ...I'll leave it up
> until tomorrow...
>
> hope that helps...
>
> Jim
>
> ps: the encog source did not help you?
>
>
>
>
> On 01/10/12 19:41, Timothy Washington wrote:
>
> Hey, thanks for responding. See responses inlined.
>
>
>  On Mon, Oct 1, 2012 at 4:24 AM, Jim - FooBar(); wrote:
>
>>  I've always found this page very good :
>>
>> http://www.doc.ic.ac.uk/~nd/surprise_96/journal/vol4/cs11/report.html
>>
>> generally, the weight of a connection is adjusted by an amount
>> proportional to the product of an error signal δ, on the unit k receiving
>> the input and the output of the unit j sending this signal along the
>> connection. You use the chain rule to calculate partial derivatives.
>>
>> also this looks quite detailed with regards to what you're asking:
>>
>>
>> https://docs.google.com/viewer?a=v&q=cache:9ahoWLbap8AJ:www.cedar.buffalo.edu/~srihari/CSE574/Chap5/Chap5.3-BackProp.pdf+the+partial+derivative+of+the+error+neural+nets&hl=en&gl=uk&pid=bl&srcid=ADGEEShVr8tHNIryQDGp0jJ2xv6JM40Ja4UFbcr2-QDgU1tK4Di_4mUTVgWsHdjHphbS7MaHmSn8VwB3dEnAQz-w4J-iyF1VJFklvLoDY5fxJbGaHsU0mio7XQYmGom0_cd7aZkUzhq5&sig=AHIEtbTyaLysuBdK7Bn_-cMzE88tqOzlag
>>
>>
>  Looking at page 9 of this document, I take the error derivative
> calculation to be:
>
>   Thus required derivative *∂En/∂w ji* is obtained by...
>
>
> 1. Multiplying value of δ ( for the unit at output end of weight )
>   2. by value of z ( for unit at input end of weight )
>
>
>  So take this output neuron and it's input weights. Let's say the total
> neural network error is *-0.3963277746392987*. I just multiply that total
> error by each weight, to get the bolded, green error values. So what
> you're saying is that the error derivative *∂En/∂w ji *( or weight
> change) for each input is that same error value, below in green. Is this
> the case?
>
>:output-layer
>>
>>
>>
>>  ({:calculated-error -1.1139741279964241,
>>
>>
>>:calculated-value 0.9275622253607013,
>>
>>
>>:inputs
>>
>>
>>({:error *-0.2016795955938916*,
>>  :calculated 0.48962608882549025,
>>
>>
>>  :input-id "583c10bfdbd326ba525bda5d13a0a894b947ffb",
>>
>>
>>  :weight 0.5088707087900713,
>>
>>
>>  :bias 0}
>>
>>
>> {:error *-0.15359996014735702*,
>>  :calculated 0.3095962076691644,
>>
>>
>>  :input-id "583c10bfdbd326ba525bda5d13a0a894b947ffa",
>>
>>
>>  :weight 0.38755790024342773,
>>
>>
>>  :bias 0}
>>
>>
>> {:error *-0.11659507401745359*
>>   :calculated 0.23938733624830652,
>>
>>
>>  :input-id "583c10bfdbd326ba525bda5d13a0a894b947ff9",
>>
>>
>>  :weight 0.2941885012312543,
>>
>>
>>  :bias 0}
>>
>>
>> {:error *-0.2784739949663631*,
>>  :calculated 0.6681581686752845,
>>
>>
>>  :input-id "583c10bfdbd326b

Re: Transforming an ugly nested loop into clojure code

2012-10-01 Thread arekanderu
I wrote a much better example in order to show what am I trying to do. Of 
course, the following is a simplified version of the actual code in order 
to make things easier for everybody.

(def my-data [{:area "Somewhere" :warehouses
>
>[{:warehouse "W54321" :containers
>
> [{:container "C12345" :boxes
>
>   [{:box "B12345" :items
>
> [{:item "I12345"}]}]}]}]}
>
>   {:area "SomewhereElse" :warehouses
>
>[{:warehouse "W54321" :containers
>
> [{:container "C54321" :boxes
>
>   [{:box "B54321" :items
>
> [{:item "I54321"}]}]}]}]}])
>
>
>> (defn my-func [data]
>
>   (map (fn [area]
>
>  (map (fn [warehouse]
>
> (map (fn [container]
>
>(map (fn [box]
>
>   (if (not (empty? (:items box)))
>
> (map (fn [item]
>
>(doSomething (:box box) (:item 
>> item)))
>
>  (:items box))
>
> (doSomethingElse (:warehouse warehouse) 
>> (:container container) (:box box
>
>   (:boxes container)))
>
>  (:containers warehouse)))
>
>   (:warehouses area)))
>
>data))
>
>
My question is, how can I get rid of the nested loops and replace it with 
something more elegant in clojure.

Thank you for any replies.

On Monday, October 1, 2012 1:16:25 AM UTC+3, arekanderu wrote:
>
> Thank you for your prompt reply Grant.
>
> *> May you share the original code? *
> *
> *
> I will post the original function very soon*
> *
>
> *> Why does my-map have vectors storing maps inside instead of a map with 
> > maps inside? *
> *
> *
> Because each vector will have more than one hash-map and each hash map 
> will have multiple keys. I only posted a simplified version of the map for 
> readability, unless I am missing something here...
> I think of vector as the equivalent of the "array of" and that's why I 
> used it. If i should have done it in some other way please let me know.
>
> *> May you write some tests to demonstrate what you want to accomplish 
> > with the ugly map and share them here? *
> *
> *
> I am basically trying to destruct my deep map with a better way than a 
> 4-nested loop. 
>
> I will post a better code snippet in order to clean things even more.
>
> Thanks again
>
> On Monday, October 1, 2012 12:41:52 AM UTC+3, Grant Rettke wrote:
>>
>> On Sun, Sep 30, 2012 at 2:59 PM, arekanderu  wrote: 
>> > I am trying to port an ugly piece of code from Ruby to clojure. 
>>
>> May you share the original code? 
>>
>> > So far I 
>> > have only ported it to clojure by keeping the same way it was written 
>> in 
>> > Ruby and i am trying to re-write it the clojure way 
>> because...wellits 
>> > very ugly. 
>>
>> Why does my-map have vectors storing maps inside instead of a map with 
>> maps inside? 
>>
>> > I have a complex hash map which it's structure is always the same and 
>> the 
>> > keys always known and by using the values in those keys, i make some 
>> > function calls with those values as parameters. You can find a 
>> simplified 
>> > version of the map and the function which steps into the map below. 
>>
>> May you write some tests to demonstrate what you want to accomplish 
>> with the ugly map and share them here? 
>>
>> > I would really appreciate it if someone could propose an alternative 
>> way 
>> > of writing the above function or at least to point me where can I look 
>> for 
>> > some useful clojure functions that will help me do what I want but in a 
>> > cleaner way. 
>>
>> Once you provide tests then we have a better chance at helping. 
>>
>> -- 
>> ((λ (x) (x x)) (λ (x) (x x))) 
>> http://www.wisdomandwonder.com/ 
>> ACM, AMA, COG, IEEE 
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Transforming an ugly nested loop into clojure code

2012-10-01 Thread gaz jones
You appear to be running over the map purely for side-effects,
therefore off the top of my head something like:

(defn my-func
  [data]
  (doseq [area data
  warehouse (:warehouses area)
  container (:containers warehouse)
  box (:boxes container)]
(if-not (empty? (:items box))
  (doseq [item (:items box)] (do-something (:box box) (:item item)))
  (do-something-else (:warehouse warehouse)
 (:container container)
 (:box box)

Might be more appropriate...


On Mon, Oct 1, 2012 at 5:07 PM, arekanderu  wrote:
>> (def my-data [{:area "Somewhere" :warehouses
>>
>>[{:warehouse "W54321" :containers
>>
>> [{:container "C12345" :boxes
>>
>>   [{:box "B12345" :items
>>
>> [{:item "I12345"}]}]}]}]}
>>
>>   {:area "SomewhereElse" :warehouses
>>
>>[{:warehouse "W54321" :containers
>>
>> [{:container "C54321" :boxes
>>
>>   [{:box "B54321" :items
>>
>> [{:item "I54321"}]}]}]}]}])
>>
>>
>> (defn my-func [data]
>>
>>   (map (fn [area]
>>
>>  (map (fn [warehouse]
>>
>> (map (fn [container]
>>
>>(map (fn [box]
>>
>>   (if (not (empty? (:items box)))
>>
>> (map (fn [item]
>>
>>(doSomething (:box box) (:item
>> item)))
>>
>>  (:items box))
>>
>> (doSomethingElse (:warehouse warehouse)
>> (:container container) (:box box
>>
>>   (:boxes container)))
>>
>>  (:containers warehouse)))
>>
>>   (:warehouses area)))
>>
>>data))

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Regarding Starting Clojure

2012-10-01 Thread Grant Rettke
On Mon, Oct 1, 2012 at 4:13 PM, aboy021  wrote:
> The getting started issue is an ongoing problem for Clojure. It's an issue
> that keeps coming up in the surveys and on the mailing list. Other languages
> are doing it really well, Scala is just a convenient example. What does the
> Clojure community need to do to help support the creation of something that
> is on par?

Surely they wouldn't mind you contributing to the website.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Transforming an ugly nested loop into clojure code

2012-10-01 Thread arekanderu
Thank you Gaz for your reply. You are correct about the side effects.

I will go through your example more carefully and give it a go. It 
definitely looks more promising than what I got :)

On Tuesday, October 2, 2012 1:22:44 AM UTC+3, Gaz wrote:
>
> You appear to be running over the map purely for side-effects, 
> therefore off the top of my head something like: 
>
> (defn my-func 
>   [data] 
>   (doseq [area data 
>   warehouse (:warehouses area) 
>   container (:containers warehouse) 
>   box (:boxes container)] 
> (if-not (empty? (:items box)) 
>   (doseq [item (:items box)] (do-something (:box box) (:item item))) 
>   (do-something-else (:warehouse warehouse) 
>  (:container container) 
>  (:box box) 
>
> Might be more appropriate... 
>
>
> On Mon, Oct 1, 2012 at 5:07 PM, arekanderu > 
> wrote: 
> >> (def my-data [{:area "Somewhere" :warehouses 
> >> 
> >>[{:warehouse "W54321" :containers 
> >> 
> >> [{:container "C12345" :boxes 
> >> 
> >>   [{:box "B12345" :items 
> >> 
> >> [{:item "I12345"}]}]}]}]} 
> >> 
> >>   {:area "SomewhereElse" :warehouses 
> >> 
> >>[{:warehouse "W54321" :containers 
> >> 
> >> [{:container "C54321" :boxes 
> >> 
> >>   [{:box "B54321" :items 
> >> 
> >> [{:item "I54321"}]}]}]}]}]) 
> >> 
> >> 
> >> (defn my-func [data] 
> >> 
> >>   (map (fn [area] 
> >> 
> >>  (map (fn [warehouse] 
> >> 
> >> (map (fn [container] 
> >> 
> >>(map (fn [box] 
> >> 
> >>   (if (not (empty? (:items box))) 
> >> 
> >> (map (fn [item] 
> >> 
> >>(doSomething (:box box) (:item 
> >> item))) 
> >> 
> >>  (:items box)) 
> >> 
> >> (doSomethingElse (:warehouse warehouse) 
> >> (:container container) (:box box 
> >> 
> >>   (:boxes container))) 
> >> 
> >>  (:containers warehouse))) 
> >> 
> >>   (:warehouses area))) 
> >> 
> >>data)) 
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Regarding Starting Clojure

2012-10-01 Thread Andreas Liljeqvist
Probably they wouldn't, but that's not the point.

The clojure community is doing something wrong for providing a coherent
beginner experience.
Maybe we aren't good at encouraging people to contribute documentation.
Or the composability of Clojure leads to small "library islands" without
much community.
Don't really know, but something is clearly wrong when so many complains
about it.

On Tue, Oct 2, 2012 at 12:31 AM, Grant Rettke  wrote:

> On Mon, Oct 1, 2012 at 4:13 PM, aboy021  wrote:
> > The getting started issue is an ongoing problem for Clojure. It's an
> issue
> > that keeps coming up in the surveys and on the mailing list. Other
> languages
> > are doing it really well, Scala is just a convenient example. What does
> the
> > Clojure community need to do to help support the creation of something
> that
> > is on par?
>
> Surely they wouldn't mind you contributing to the website.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Which power function is right for Clojure?

2012-10-01 Thread Grant Rettke
(ns power.examples)

(defn non-acc-pow [base exp]
  (if (zero? exp)
1
(* base (non-acc-pow base (dec exp)

(defn acc-pow [base exp]
  (letfn [(loop [base exp acc]
(if (zero? exp)
  acc
  (recur base (dec exp) (* base acc]
(loop base exp 1)))

(defn lazy-pow [base exp]
  (letfn [(loop [cur]
(cons cur (lazy-seq (loop (* cur base)]
(nth (take exp (loop base)) (dec exp

(defn iter-pow [base exp]
  (nth (take exp (iterate (partial * base) base)) (dec exp)))

(defn apply-pow [base exp]
  (apply * (repeat exp base)))

(= 16
   (non-acc-pow 2 4)
   (acc-pow 2 4)
   (lazy-pow 2 4)
   (iter-pow 2 4)
   (apply-pow 2 4))

Originally posted here:
http://www.wisdomandwonder.com/article/6430/which-power-function-is-right-for-clojure

-- 
((λ (x) (x x)) (λ (x) (x x)))
http://www.wisdomandwonder.com/
ACM, AMA, COG, IEEE

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Which power function is right for Clojure?

2012-10-01 Thread Andy Fingerhut
It depends.

Are you trying to optimize for speed?  Teaching a particular style of 
programming?  Code size?  Range of input values handled correctly?  Time to 
write it?

Something else?

Andy

On Oct 1, 2012, at 4:45 PM, Grant Rettke wrote:

> (ns power.examples)
> 
> (defn non-acc-pow [base exp]
>  (if (zero? exp)
>1
>(* base (non-acc-pow base (dec exp)
> 
> (defn acc-pow [base exp]
>  (letfn [(loop [base exp acc]
>(if (zero? exp)
>  acc
>  (recur base (dec exp) (* base acc]
>(loop base exp 1)))
> 
> (defn lazy-pow [base exp]
>  (letfn [(loop [cur]
>(cons cur (lazy-seq (loop (* cur base)]
>(nth (take exp (loop base)) (dec exp
> 
> (defn iter-pow [base exp]
>  (nth (take exp (iterate (partial * base) base)) (dec exp)))
> 
> (defn apply-pow [base exp]
>  (apply * (repeat exp base)))
> 
> (= 16
>   (non-acc-pow 2 4)
>   (acc-pow 2 4)
>   (lazy-pow 2 4)
>   (iter-pow 2 4)
>   (apply-pow 2 4))
> 
> Originally posted here:
> http://www.wisdomandwonder.com/article/6430/which-power-function-is-right-for-clojure
> 
> -- 
> ((λ (x) (x x)) (λ (x) (x x)))
> http://www.wisdomandwonder.com/
> ACM, AMA, COG, IEEE
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Which power function is right for Clojure?

2012-10-01 Thread Jean Niklas L'orange
Numeric tower has implemented pow (named expt in the library), so you could 
have a look at their implementation:
https://github.com/clojure/math.numeric-tower/blob/master/src/main/clojure/clojure/math/numeric_tower.clj#L64

(It utilizes exponentiation by squaring to get the running time from O(n) 
to O(log n).)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Which power function is right for Clojure?

2012-10-01 Thread Mark Engelberg
On Mon, Oct 1, 2012 at 4:45 PM, Grant Rettke  wrote:

> (ns power.examples)
>
> (defn non-acc-pow [base exp]
>   (if (zero? exp)
> 1
> (* base (non-acc-pow base (dec exp)
>

This is not ideal for Clojure.  The exponent will be limited by the stack
size in Java.


>
> (defn acc-pow [base exp]
>   (letfn [(loop [base exp acc]
> (if (zero? exp)
>   acc
>   (recur base (dec exp) (* base acc]
> (loop base exp 1)))
>

This naming of a helper function to "loop" is non-idiomatic, because there
is a built-in construct "loop", which works somewhat like named let in
Scheme (without the name), allowing you to combine the function definition
and the initial values at once.  Idiomatic version of this would be:

defn acc-pow [base exp]
  (loop [base base,
 exp exp,
 acc 1]
(if (zero? exp)
  acc
  (recur base (dec exp) (* base acc)

There's a subtle concern here though.  Clojure, by default, uses longs.  If
you try to do something large, like (acc-pow 2 500), you'll get an overflow
error.  One easy fix is to change the 1 to 1N, and then you'll get boxed
numerics.  Another option is to change * to *'.

Notice that it is perfectly idiomatic to bind the local "base" to the
function input "base" and so on.  You don't have to do that, though.


>
> (defn lazy-pow [base exp]
>   (letfn [(loop [cur]
> (cons cur (lazy-seq (loop (* cur base)]
> (nth (take exp (loop base)) (dec exp
>

This is just an overly convoluted version of what comes next.


>
> (defn iter-pow [base exp]
>   (nth (take exp (iterate (partial * base) base)) (dec exp)))
>
>
This is an improvement, but the "take exp" is totally unnecessary.  Try:

(defn iter-pow [base exp]
  (nth (iterate (partial * base) base) (dec exp)))


(defn apply-pow [base exp]
>   (apply * (repeat exp base)))
>

This is the most concise, and perfectly reflects what you want to do.  This
is certainly good Clojure, and arguably the best of all of these (again,
think about whether you want * or *')


> (= 16
>(non-acc-pow 2 4)
>(acc-pow 2 4)
>(lazy-pow 2 4)
>(iter-pow 2 4)
>(apply-pow 2 4))
>

Finally, here's an efficient version:

(defn efficient-pow [base pow]
  (loop [n pow, y 1, z base]
(let [t (even? n), n (quot n 2)]
  (cond
   t (recur n y (*' z z))
   (zero? n) (*' z y)
   :else (recur n (*' z y) (*' z z))

This is essentially how I coded it in clojure.math.numeric-tower.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Which power function is right for Clojure?

2012-10-01 Thread Mark Engelberg
On Mon, Oct 1, 2012 at 6:29 PM, Mark Engelberg wrote:

> (defn efficient-pow [base pow]
>   (loop [n pow, y 1, z base]
> (let [t (even? n), n (quot n 2)]
>   (cond
>t (recur n y (*' z z))
>(zero? n) (*' z y)
>:else (recur n (*' z y) (*' z z))
>
> This is essentially how I coded it in clojure.math.numeric-tower.
>

I should clarify that in clojure.math.numeric-tower, this is a helper
function called when the power is known to be positive, so this doesn't
work for a power of 0, for example.

It's written a little oddly because the variable names and branching
structure are meant to reflect the algorithm as presented by Knuth.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Regarding Starting Clojure

2012-10-01 Thread Brent Millare
Sounds like the main beef is with the official website's styling and 
layout. I agree its not necessarily the prettiest but all the information 
is there. On the other hand, there are plenty of great resources that 
provide a great "getting started" experience in my opinion. Just typing 
clojure in google I see tryclojure, which provides a interactive guide with 
a simple click. Then next, the clojure wiki, which has a lot of free 
content as well as places to go. Next is the JoyOfClojure book, which is 
*the* book I'd recommend to any beginning clojure user. Also there is 
learn-clojure.com which looks nice and seems to address a lot of those 
"getting started" points.

Personally, the styling/layout wasn't an issue for me. I found there to be 
a lot of good resources out there, but I couldn't just point to one.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Parallella - The new era of computing?

2012-10-01 Thread René Groß
Hi,

Anyone heard of the project 
"Parallella"
 
yet?

What do you think about it?
Will it be of any interest for the clojure plattform?


Kind regards,

René

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Problems loading Clojure core in Nutch plugin

2012-10-01 Thread Michael Lim
Hi there,

I am trying to implement a Nutch plugin in Clojure 1.3. It works correctly 
in Nutch standalone mode, but not in Nutch distributed (Hadoop) mode. I 
have made the plugin inherit from Nutch's HtmlParser class, as follows. 

---
(ns test_plugin.core)

(gen-class 
  :name test_plugin.core.Parser
  :implements [org.apache.nutch.parse.HtmlParseFilter]
  :prefix "parser-")

;; required by nutch to exist
(defn parser-setConf [this conf])

;; required by nutch to exist
(defn parser-getConf [this])

-

Hadoop was then run with the following command:

hadoop jar apache-nutch-1.5.1.job org.apache.nutch.parse.ParserChecker 
-libjars /home/foobar/test-plugin/test-plugin-standalone.jar 
"http://nutch.apache.org";

* apache-nutch-1.5.1.job is a Hadoop job file created by Nutch that 
consists of the Nutch configuration files, plugins, etc. 
* The libjars option is required by Hadoop so that it can pick up on the 
3rd party jars (eg: Clojure etc)

The error that I get when I run Nutch in distributed mode is as follows:

Exception in thread "main" java.lang.ExceptionInInitializerError
at clojure.core__init.__init0(Unknown Source)
at clojure.core__init.(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at clojure.lang.RT.loadClassForName(RT.java:2030)
at clojure.lang.RT.load(RT.java:417)  
at clojure.lang.RT.load(RT.java:398)  
at clojure.lang.RT.doInit(RT.java:434)
at clojure.lang.RT.(RT.java:316)
at clojure.lang.Namespace.(Namespace.java:34)
at clojure.lang.Namespace.findOrCreate(Namespace.java:176)
at clojure.lang.Var.internPrivate(Var.java:149)
at test_plugin.core.Parser.(Unknown Source)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native 
Method)
at 
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.Class.newInstance0(Class.java:355)
at java.lang.Class.newInstance(Class.java:308)
at 
org.apache.nutch.plugin.Extension.getExtensionInstance(Extension.java:160)
at 
org.apache.nutch.parse.HtmlParseFilters.(HtmlParseFilters.java:59)
at 
org.apache.nutch.parse.html.HtmlParser.setConf(HtmlParser.java:289)
at 
org.apache.nutch.plugin.Extension.getExtensionInstance(Extension.java:162)
at 
org.apache.nutch.parse.ParserFactory.getParsers(ParserFactory.java:132)
at org.apache.nutch.parse.ParseUtil.parse(ParseUtil.java:71)
at org.apache.nutch.parse.ParserChecker.run(ParserChecker.java:101)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:65)
at org.apache.nutch.parse.ParserChecker.main(ParserChecker.java:138)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.hadoop.util.RunJar.main(RunJar.java:156)
Caused by: java.lang.IllegalStateException: Attempting to call unbound fn: 
#'clojure.core/refer
at clojure.lang.Var$Unbound.throwArity(Var.java:43)
at clojure.lang.AFn.invoke(AFn.java:39)
at clojure.lang.Var.invoke(Var.java:401)
at clojure.lang.RT.doInit(RT.java:447)
at clojure.lang.RT.(RT.java:316)
... 33 more

Any ideas why? 

Thanks,
Michael

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Clojure web framework

2012-10-01 Thread James MacAulay
Frameworks have benefits which can't easily be achieved with documentation. 
The most obvious to me is that a framework lets you fire up a complete 
system of carefully curated components in no time. They also let you defer 
choices until you actually need to care about them.

Because Clojure's libraries are so composable, it seems like a good 
approach to fill this gap would be "just" a lein project template with an 
opinionated set of dependencies, a sane and predictable folder hierarchy, 
and a good Getting Started Guide. A quick clojars search reveals many that 
might fit that description, but none have very high visibility.

-James

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Clojure web framework

2012-10-01 Thread Leonardo Borges
On Sun, Sep 30, 2012 at 12:27 PM, James MacAulay wrote:

> Frameworks have benefits which can't easily be achieved with
> documentation. The most obvious to me is that a framework lets you fire up
> a complete system of carefully curated components in no time. They also let
> you defer choices until you actually need to care about them.
>
> Because Clojure's libraries are so composable, it seems like a good
> approach to fill this gap would be "just" a lein project template with an
> opinionated set of dependencies, a sane and predictable folder hierarchy,
> and a good Getting Started Guide. A quick clojars search reveals many that
> might fit that description, but none have very high visibility.
>
>
That's a good point. I put together a repo that I've been using as my main
template for web apps for a while. You can find it on github:
https://github.com/leonardoborges/clj-boilerplate

It tries to bridge that gap. The idea is to clone it, follow the readme and
you should have a new webapp running in a short amount of time.

I would like to turn it into a lein template but haven't had the time to do
so. Still, it could be useful to some.

Cheers,
Leonardo Borges

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Regarding Starting Clojure

2012-10-01 Thread nchurch
I put together the Getting Started confluence page.  I'm sure it could
still be improved, but adding further to it won't really fix the
problems you've noticed, and that many other people have noted.  It's
still on a secondary site, and Confluence doesn't really give you a
lot of design optionsalso ordinary Clojure Contributors don't have
the ability to \delete existing pages, so new material will for now
just add clutter on the sidebar.

At least one respected Clojurian that I know of has offered to write a
new clojure.org site, but replacing or updating it has not been a
priority.

Brent is right that you can find what you need on Clojure.org without
it being "pretty", but the current (and now quite old) site sends new
users some messages we may not necessarily intend:

1. People hoping merely to Get Something Done will be looking to a
streamlined site as evidence that they won't have to waste too much
time getting up and running with their work.  These users will note,
consciously or not, that the information they really need is one among
many choices buried on a link off the bottom of a page linked from the
\sixth subheading on the sidebar of the main site.  (Yes, Getting
Started apparently falls under 'Reference'which is itself
secondary to 'Swag'.)

2. People looking to make a creative contribution will look for
evidence that what they have to offer is valued.  If that contribution
is tools for building well-designed websites, Clojure.org will not
give the impression that anyone in the community would care.  This
impression would be false, but you'd have to look quite a bit harder
to realize this.

Some people may not mind turning away new user #1; but turning away
new user #2 is unfortunate in any possible world.

If I wanted to give someone an elevator pitch for Clojure, I'd admit
that it is new and has some rough edges; but that it offers tremendous
flexibility, power, and concision; and that it is evolving into an
environment where an entire web application, from data all the way up
to presentation, can be written in the same carefully-designed
language and environment.

That's \huge, but it doesn't come across in Clojure.org at all.




On Oct 1, 2:13 pm, aboy021  wrote:
> I decided to quickly compare the website experience of starting Clojure and
> starting Scala.
>
> I do a Google search for Clojure
> I decide to try the first link, Clojure.org
> There's some basic information. I follow the somewhat obscure link halfway
> down the side, "Getting Started"
> Ok, that looks promising, now I can get a REPL to interact with.
> I follow the link to the Getting Started Documentation
> (http://dev.clojure.org/display/doc/Getting+Started) (isn't that where I
> already was?)
> Still flailing a bit, I follow the link to Mark Volkmann's Tutorial.
> This is the first chance I've had to see what Clojure actually looks like
> and how to program in it.
>
> In stark contrast, I try searching for Scala.
> I get presented with an appealing, nicely laid out page with large links to
> an introduction to the language and a page on getting started.
> There are links in an easy to navigate menu with Information about the
> language, documentation, code examples, Software, and Developer information.
>
> Now, I'm no Scala developer, but at first glance it seems like I've found a
> great touch stone that I can use to find out what's happening in the
> language, how it looks, what it can do for me, and I can learn how to write
> it.
>
> Another thing that the scala-lang site has is Code Examples. Code examples
> are a really nice way for you to get a taste of how a language can solve
> common problems, and they can give you a real sense of the flavour of the
> language.
>
> A lot of the information for Clojure seems to be there, it's just not laid
> out in an attractive easy to use format. Perhaps we could have a fundraiser
> to pay for a web designer to make a nice modern website that contains the
> information in an easier to digest and more centralised way
>
> The getting started issue is an ongoing problem for Clojure. It's an issue
> that keeps coming up in the surveys and on the mailing list. Other
> languages are doing it really well, Scala is just a convenient example.
> What does the Clojure community need to do to help support the creation of
> something that is on par?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Regarding Starting Clojure

2012-10-01 Thread nchurch
To cite some concrete examples:

"Datomic"

0 hits on Clojure.org

"Clojurescript"

1 hit

On Oct 1, 11:09 pm, nchurch  wrote:
> I put together the Getting Started confluence page.  I'm sure it could
> still be improved, but adding further to it won't really fix the
> problems you've noticed, and that many other people have noted.  It's
> still on a secondary site, and Confluence doesn't really give you a
> lot of design optionsalso ordinary Clojure Contributors don't have
> the ability to \delete existing pages, so new material will for now
> just add clutter on the sidebar.
>
> At least one respected Clojurian that I know of has offered to write a
> new clojure.org site, but replacing or updating it has not been a
> priority.
>
> Brent is right that you can find what you need on Clojure.org without
> it being "pretty", but the current (and now quite old) site sends new
> users some messages we may not necessarily intend:
>
> 1. People hoping merely to Get Something Done will be looking to a
> streamlined site as evidence that they won't have to waste too much
> time getting up and running with their work.  These users will note,
> consciously or not, that the information they really need is one among
> many choices buried on a link off the bottom of a page linked from the
> \sixth subheading on the sidebar of the main site.  (Yes, Getting
> Started apparently falls under 'Reference'which is itself
> secondary to 'Swag'.)
>
> 2. People looking to make a creative contribution will look for
> evidence that what they have to offer is valued.  If that contribution
> is tools for building well-designed websites, Clojure.org will not
> give the impression that anyone in the community would care.  This
> impression would be false, but you'd have to look quite a bit harder
> to realize this.
>
> Some people may not mind turning away new user #1; but turning away
> new user #2 is unfortunate in any possible world.
>
> If I wanted to give someone an elevator pitch for Clojure, I'd admit
> that it is new and has some rough edges; but that it offers tremendous
> flexibility, power, and concision; and that it is evolving into an
> environment where an entire web application, from data all the way up
> to presentation, can be written in the same carefully-designed
> language and environment.
>
> That's \huge, but it doesn't come across in Clojure.org at all.
>
> On Oct 1, 2:13 pm, aboy021  wrote:
>
>
>
>
>
>
>
> > I decided to quickly compare the website experience of starting Clojure and
> > starting Scala.
>
> > I do a Google search for Clojure
> > I decide to try the first link, Clojure.org
> > There's some basic information. I follow the somewhat obscure link halfway
> > down the side, "Getting Started"
> > Ok, that looks promising, now I can get a REPL to interact with.
> > I follow the link to the Getting Started Documentation
> > (http://dev.clojure.org/display/doc/Getting+Started) (isn't that where I
> > already was?)
> > Still flailing a bit, I follow the link to Mark Volkmann's Tutorial.
> > This is the first chance I've had to see what Clojure actually looks like
> > and how to program in it.
>
> > In stark contrast, I try searching for Scala.
> > I get presented with an appealing, nicely laid out page with large links to
> > an introduction to the language and a page on getting started.
> > There are links in an easy to navigate menu with Information about the
> > language, documentation, code examples, Software, and Developer information.
>
> > Now, I'm no Scala developer, but at first glance it seems like I've found a
> > great touch stone that I can use to find out what's happening in the
> > language, how it looks, what it can do for me, and I can learn how to write
> > it.
>
> > Another thing that the scala-lang site has is Code Examples. Code examples
> > are a really nice way for you to get a taste of how a language can solve
> > common problems, and they can give you a real sense of the flavour of the
> > language.
>
> > A lot of the information for Clojure seems to be there, it's just not laid
> > out in an attractive easy to use format. Perhaps we could have a fundraiser
> > to pay for a web designer to make a nice modern website that contains the
> > information in an easier to digest and more centralised way
>
> > The getting started issue is an ongoing problem for Clojure. It's an issue
> > that keeps coming up in the surveys and on the mailing list. Other
> > languages are doing it really well, Scala is just a convenient example.
> > What does the Clojure community need to do to help support the creation of
> > something that is on par?

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit