[Tutor] Programming Collective Intelligence Study Group (Mark Lybrand)

tommy at enkelthed.dk tommy at enkelthed.dk
Tue Nov 29 11:51:56 CET 2011


Excellent, Ill take a look at those.

If you start up a G+ og Facebook group, Id like to participate, would give
me a kick in the back with regards to actually starting on this, instead of
just having it on my massive to-do list.

I've dabble in programming for a while, done some java, c#, php, python,
perl and some various unknown scripting languages developed by the
companies i've worked with, but not enough to be fluent in any of the large
established languages. 



On Tue, 29 Nov 2011 02:04:04 -0800, Mark Lybrand <mlybrand at gmail.com>
wrote:
> Sorry about that. The book is called Programming Collective
Intelligence.
>  It is from O'Reilly Press.  It is written by Toby Segaran. ISBN-13:
> 978-0596529321.
>  There is a PDF on the web, if you google around, but it doesn't seem
that
> kosher to me, so you are on your own if you decide to go that route.
> 
> The other book that we are considering afterwards is Natural Language
> Processing with Python. Also from O'Reilly.  Written by Steven Bird, et
al.
> The book is legally freely available on the web. See here:
> http://www.nltk.org/book
> 
> I hope that helps.  I will try to make my postings specific enough to be
> able to participate without the book.  And will try to point people to
> information that might help.  But I am also a noob (to all of it,
Python,
> NLP, ML).  Man I miss my curly braces (although not as much as I thought
I
> would, since Python is making it real easy to love it)
> 
> 
> On Tue, Nov 29, 2011 at 1:44 AM, <tommy at enkelthed.dk> wrote:
> 
>> Hey Mark
>>
>> Id be very much interested in this. While I mostly lurk on the python
>> mailing list and have only dabbled in a few quick scripts. Then I
wouldnt
>> mind getting deeper into via a collective group.
>>
>> This is the first I've heard of this, Im not sure if you've posted
before
>> but which book are you using?
>>
>> /Regards
>> Tommy
>> On Tue, 29 Nov 2011 10:18:25 +0100, tutor-request at python.org wrote:
>> > Send Tutor mailing list submissions to
>> >       tutor at python.org
>> >
>> > To subscribe or unsubscribe via the World Wide Web, visit
>> >       http://mail.python.org/mailman/listinfo/tutor
>> > or, via email, send a message with subject or body 'help' to
>> >       tutor-request at python.org
>> >
>> > You can reach the person managing the list at
>> >       tutor-owner at python.org
>> >
>> > When replying, please edit your Subject line so it is more specific
>> > than "Re: Contents of Tutor digest..."
>> >
>> >
>> > Today's Topics:
>> >
>> >    1. Re: How to handle try and except in this case (Mic)
>> >    2. Re: useful function or reinventing the wheel?? (Mark Lybrand)
>> >    3. Programming Collective Intelligence Study Group (Mark Lybrand)
>> >    4. Re: Do loop in Python (stm atoc)
>> >    5. Re: How to handle try and except in this case (Dave Angel)
>> >
>> >
>> >
----------------------------------------------------------------------
>> >
>> > Message: 1
>> > Date: Tue, 29 Nov 2011 09:37:28 +0100
>> > From: "Mic" <o0MB0o at hotmail.se>
>> > To: <tutor at python.org>
>> > Subject: Re: [Tutor] How to handle try and except in this case
>> > Message-ID: <COL124-DS7AC3D458B3F5FA994A929B7B30 at phx.gbl>
>> > Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>> >       reply-type=original
>> >
>> >
>> > On 2011-11-27 17:58, Mic wrote:
>> >>> Say that I want to try and open 10 files. If none of these exists,
I
>> >>> want
>> >>> an
>> >>> error
>> >>> message to appear. But only if NONE of these files exists.
>> >
>> >>> I know how to handle this with one file. But I don't know how to do
>> that
>> >>> with more than one.
>> >>> So the program should try and open all 10 files and if, and only
if,
>> >>> none
>> >>> of the files exists I want en error message to appear.
>> >
>> >
>> > [Andreas wrote]:
>> >>Use a counter which increments with every existing file. After
opening
>> >>all files check if the counter is bigger than 0.
>> >
>> >>Or, if you need to know which files exist, use a list, append
existing
>> >>files to it and check at the end if it's not empty.
>> >
>> >>Do you need more help?
>> >
>> > Andreas,
>> >
>> >
>> > Thanks for your answer. I am afraid I don't understand this:
>> > "Use a counter which increments with every existing file. After
opening
>> > all files check if the counter is bigger than 0."
>> >
>> >
>> > I thought I could co along those lines earlier
>> >
>> > try:
>> >     text_file=open("Hey","r") and text_file1=open("Hey","r")
>> > except:
>> >     print("hi")
>> >
>> >
>> > So that hi is printed only and only if both files aren't existing.
>> >
>> >
>> > Thank you!
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > ------------------------------
>> >
>> > Message: 2
>> > Date: Tue, 29 Nov 2011 00:37:40 -0800
>> > From: Mark Lybrand <mlybrand at gmail.com>
>> > To: d at davea.name
>> > Cc: tutor at python.org
>> > Subject: Re: [Tutor] useful function or reinventing the wheel??
>> > Message-ID:
>> >       <CALsUBtzEvCyynA=PPip3OVDM=
>> BW5H3W3pcUr0DCtpRBg--2saA at mail.gmail.com>
>> > Content-Type: text/plain; charset="utf-8"
>> >
>> >>
>> >>
>> >> You're welcome.  I'd look forward to seeing your rewrite, and
whether
>> >> it's
>> >> really shorter and more straightforward.
>> >>
>> >> Another advantage is doing less disk I/O if you start by trying the
>> >> requested directory directly, and only recursing to parents if you
>> can't
>> >> make the requested directory.
>> >>
>> >> I took a quick stab at it  (ask me later for mark.py)  and it wasn't
>> >> as
>> >> straightforward as I expected.  The main problem comes down to how
to
>> >> define the base case.  I think you might have the same problem also.
>> You
>> >> assume that you can safely go back to the mount point.  But if the
>> >> path
>> >> given is relative, you have to allow for that as well. Perhaps a
call
>> to
>> >> os.path.abspath is in order.  I also think that ismount() might not
be
>> >> legal on Windows, if you care about that.
>> >>
>> >> Also, we have to worry about what happens when one of the
directories
>> >> cannot be made for reasons unrelated to the syntax of the string. 
For
>> >> example, the user might not have write permissions for one or more
of
>> the
>> >> directories.  In fact, the user might not have read permissions
>> >> either.
>> >>
>> >>
>> > I am actually passing in the path already os.path.abspath-ed.  So, I
>> should
>> > probably move that into the function for better encapsulation.  I am
on
>> > Windows, so ismount is behaving correctly (I tested it in Idle before
>> going
>> > with that as my base case).  Since this will end up being a
throw-away,
>> I
>> > will probably not worry too much about permissions and failures, but
I
>> can
>> > appreciate the need for such checks, should I decide to keep this for
>> more
>> > widespread use.
>> >
>> > Thanks again.  I will send my solution when I get a chance to get
back
>> to
>> > it (gotta get myself ahead in machine learning before the weekend
gets
>> too
>> > close :)
>> >
>> > Mark
>> > -------------- next part --------------
>> > An HTML attachment was scrubbed...
>> > URL:
>> >
>> <
>>
http://mail.python.org/pipermail/tutor/attachments/20111129/991cc3a9/attachment-0001.html
>> >
>> >
>> > ------------------------------
>> >
>> > Message: 3
>> > Date: Tue, 29 Nov 2011 00:42:01 -0800
>> > From: Mark Lybrand <mlybrand at gmail.com>
>> > To: tutor at python.org
>> > Subject: [Tutor] Programming Collective Intelligence Study Group
>> > Message-ID:
>> >       <
>> CALsUBtzSqtJh4MX2ixuVO-J5zTn5xqLT+O4ZdyeVSe1VJknLzg at mail.gmail.com>
>> > Content-Type: text/plain; charset="utf-8"
>> >
>> > Over on the Machine Learning Class, I mentioned the idea of setting
up
>> some
>> > online resources to go through the Programming Collective
Intelligence
>> book
>> > as a group. This would include a group or discussion board of some
>> > type,
>> > maybe a Google+ or Facebook page, and a wiki.  Then we would set a
pace
>> and
>> > work through the book.  Since it is in Python, I thought this group
>> would
>> > be interested.  Am I wrong?  If it works out pretty good, we will
>> probably
>> > continue with Natural Language Processing (also Python) after we
>> > finish.
>> >
>> > So, what is the interest like here?  Let me know and I will give you
>> guys a
>> > heads up when I get everything all set up.
>> >
>> > --
>> > Mark :)
>> > -------------- next part --------------
>> > An HTML attachment was scrubbed...
>> > URL:
>> >
>> <
>>
http://mail.python.org/pipermail/tutor/attachments/20111129/82dcebaf/attachment-0001.html
>> >
>> >
>> > ------------------------------
>> >
>> > Message: 4
>> > Date: Tue, 29 Nov 2011 09:51:45 +0100
>> > From: stm atoc <stm.at.oc at googlemail.com>
>> > To: Andreas Perstinger <andreas.perstinger at gmx.net>
>> > Cc: tutor at python.org
>> > Subject: Re: [Tutor] Do loop in Python
>> > Message-ID:
>> >       <
>> CAHNhTs68PqEQ5XVk4Tn3C6hQYMENRBY1O7xnqn-fxjmdki4ftg at mail.gmail.com>
>> > Content-Type: text/plain; charset=ISO-8859-1
>> >
>> > Thank you so much. This script and all information was totally
helpful
>> > and actually helped me for the next step of my work as well.
>> >
>> > Have a great time.....
>> > Sue
>> >
>> > On Fri, Nov 25, 2011 at 10:44 PM, Andreas Perstinger
>> > <andreas.perstinger at gmx.net> wrote:
>> >> On 2011-11-25 14:46, stm atoc wrote:
>> >>>
>> >>> Here is the new version of the program:
>> >>>
>> >>> zvalues = [-200] ?# starting value
>> >>> hvalues = [10] ?# starting value
>> >>> increments = [1, 1, 1, 1, 1, 1, 1, 1]
>> >>> for N in increments:
>> >>> ? ? ? ?h = hvalues[-1] - N
>> >>> ? ? ? ?hvalues.append(h)
>> >>> ? ? ? ?z = zvalues[-1] + h
>> >>> ? ? ? ?zvalues.append(z)
>> >>> ? ? ? ?height = arange((z)*dz,0,dz)
>> >>
>> >>
>> >> There is no "arange" in python. Could it be that you use numpy and
>> >> import it
>> >> with "from numpy import *"?
>> >>
>> >>> ? ? ? ?for z,when in enumerate(height):
>> >>
>> >>
>> >> I'm pretty sure this line doesn't do what you expect it to do. You
>> >> have
>> a
>> >> sequence (a numpy array) named "height" and after calling
"enumerate"
>> you
>> >> get a list of tuples in the form of [(0, height[0]), (1, height[1]),
>> >> ...].
>> >> Now the for-loop iterates over this list and assigns "z" to the
first
>> >> value
>> >> of the tuple (the index-values) and "when" to the second (the values
>> from
>> >> "height"). You later never use "when" but just use "z". If you
really
>> >> want
>> >> that, the "enumerate" is completly unnecessary and you could just
use
>> >> "for z
>> >> in range(len(height))". But I'm not sure if numpy arrays work with
>> >> "len()".
>> >>
>> >>
>> >>> ? ? ? ? ? ?nuh.append(0.001 * exp(-0.005*(z+200.0))*dz) #turbulence
>> >>> diffusivity m**2/s
>> >>> ? ? ? ? ? ?nu.append(num + nuh[z])
>> >>>
>> >>> The story is like this:
>> >>> I should define layers and thickness and see how the diffusion
>> >>> profile
>> >>> changes over the z.
>> >>> height (or depth) of the total thickness or 'z'.
>> >>> I basically, define 'z' in 10 layers and each layer is called ?' N'
.
>> >>> Difference between each layer is 'h', which is equal 10 micrometer.
>> >>> Now, what I like to do is the modification of nu based on each
zvalue
>> >>> In fact, for each 'zvalue' o'z' step, I need to calculate a
different
>> >>> value for 'nu' based on the available equation in the program.
>> >>>
>> >>> BUT, I am not sure, exactly, how to add the new do loop of z inside
>> >>> another loop of nu.
>> >>
>> >>
>> >> For me your explanations are still too confusing. Could it be that
you
>> >> are
>> >> thinking way too complicated?
>> >>
>> >> My guess is you want to have a range of material thicknesses (from 1
>> >> to
>> >> 200
>> >> micrometers in 10 micrometer-steps) and then you want from each
>> >> thickness 10
>> >> different layers, right?
>> >>
>> >> import math # you should always tell us which modules you import
>> >> num = 0.05 # some constant
>> >> nu = [] # list of resulting values
>> >> h = 10.0 # height of one layer
>> >> thickness = range(0, 210, 10) # a list from 0 to 200 with step 10
(0,
>> 10,
>> >> 20, ..., 190, 200)
>> >> layers = range(1,11) # a list from 1 to 10
>> >> for t in thickness:
>> >> ?for l in layers:
>> >> ? ?z = t + h * l # I'm not sure if you want to add or subtract the
>> layer
>> >> thickness
>> >> ? ?nu = num + (0.01 * math.exp(-0.05 * (z + 200.0)))
>> >>
>> >> This will result in a big one-dimensional list where you calculate
for
>> >> each
>> >> thickness the nu-value for 10 layers. Am I close?
>> >> I'm still not sure about the steps and the height of the layers. I
>> >> also
>> >> wonder if it wouldn't be better to use a two-dimensional list.
>> >>
>> >>
>> >>> I have done this way as well (the other way around):
>> >>>
>> >>> height = arange((z)*dz,0,dz)
>> >>> for z,when in enumerate(height):
>> >>> ? ? for N in increments:
>> >>> ? ? ? ?h = hvalues[-1] - N
>> >>> ? ? ? ?hvalues.append(h)
>> >>> ? ? ? ?z = zvalues[-1] + h
>> >>> ? ? ? ?zvalues.append(z)
>> >>> ? ? ? ?nuh.append(0.001 * exp(-0.005*(z+200.0))*dz) #turbulence
>> >>> diffusivity m**2/s
>> >>> ? ? ? ?nu.append(num + nuh[z])
>> >>>
>> >>> but still no sign of 'nu changes' over 'z'!
>> >>
>> >>
>> >> As Charles has already mentioned, the values for "nu" are very
similar
>> >> (they
>> >> start beginning to differ just at the seventh digit after the
comma).
>> >> How do
>> >> you further process this values? If you plot them what's your scale?
>> >>
>> >> Bye, Andreas
>> >>
>> >> _______________________________________________
>> >> Tutor maillist ?- ?Tutor at python.org
>> >> To unsubscribe or change subscription options:
>> >> http://mail.python.org/mailman/listinfo/tutor
>> >
>> >
>> > ------------------------------
>> >
>> > Message: 5
>> > Date: Tue, 29 Nov 2011 04:17:55 -0500
>> > From: Dave Angel <d at davea.name>
>> > To: Mic <o0MB0o at hotmail.se>
>> > Cc: tutor at python.org
>> > Subject: Re: [Tutor] How to handle try and except in this case
>> > Message-ID: <4ED4A343.1020406 at davea.name>
>> > Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>> >
>> > On 11/29/2011 03:37 AM, Mic wrote:
>> >>
>> >> On 2011-11-27 17:58, Mic wrote:
>> >>>> Say that I want to try and open 10 files. If none of these exists,
I
>> >>>> want an
>> >>>> error
>> >>>> message to appear. But only if NONE of these files exists.
>> >>
>> >>>> I know how to handle this with one file. But I don't know how to
do
>> >>>> that
>> >>>> with more than one.
>> >>>> So the program should try and open all 10 files and if, and only
if,
>> >>>> none
>> >>>> of the files exists I want en error message to appear.
>> >>
>> >>
>> >> [Andreas wrote]:
>> >>> Use a counter which increments with every existing file. After
>> >>> opening
>> >>> all files check if the counter is bigger than 0.
>> >>
>> >>> Or, if you need to know which files exist, use a list, append
>> >>> existing
>> >>> files to it and check at the end if it's not empty.
>> >>
>> >>> Do you need more help?
>> >>
>> >> Andreas,
>> >>
>> >>
>> >> Thanks for your answer. I am afraid I don't understand this:
>> >> "Use a counter which increments with every existing file. After
>> >> opening
>> >> all files check if the counter is bigger than 0."
>> >>
>> > Could you explain what's unclear about it?  Andreas couldn't get more
>> > specific, since you didn't say how these 10 names are provided.  If
>> > they're in a list called filenames, you could do something like:
>> >
>> > fileobjects = []
>> > for fname in filenames:
>> >      try:
>> >          fileobj = open(fname, "r")
>> >          fileobjects.append(fileobj)
>> >      catch SomeExceptionType as e:
>> >          pass
>> >
>> > and when you're done, use something like:
>> >
>> > if len(fileobjects) == 0:
>> >       print "no files could be opened"
>> >
>> >>
>> >> I thought I could co along those lines earlier
>> >>
>> >> try:
>> >>    text_file=open("Hey","r") and text_file1=open("Hey","r")
>> >
>> > Unfortunately this isn't valid Python syntax.  The equal sign has a
>> > specific statement syntax, and the only time you can have more than
one
>> > of them in one statement, is the chained assignments, where they all
>> > get
>>
>> > bound to the same object.  You wouldn't want to do this anyway, since
>> > it
>>
>> > would leave all those open files in an unspecified state.
>> >
>> > To go one step further, if it could work, it would give an exception
if
>> > any ONE of the files couldn't be open, and you want the message to
>> > appear if none of the files could be opened.
>> >
>> >> except:
>> >>    print("hi")
>> >>
>> >>
>> >> So that hi is printed only and only if both files aren't existing.
>> > If you didn't need to open them, but just to make sure they exist,
you
>> > could use if  os.exist(filename)  much more easily.
>> _______________________________________________
>> Tutor maillist  -  Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>


More information about the Tutor mailing list