Re: How is AI implemented

2008-01-03 Thread montyphyton
On Jan 3, 6:49 pm, Martin Marcher [EMAIL PROTECTED] wrote:
 Hi,

 I know it's not a trivial field but I had some readings about
 artificial intelligence lately and my personal conclusion is that it's
 mostly just statistics.

 Naively explained:

 continiously gather and store information and apply a default rating

 1) answer questions with gathered information according to rating
 2) store/calculate rating based upon input (be it an interface or user input)
 3) goto 1 (sorry for the goto)

really naively :)


 So I think that in general there hasn't yet been any artificial
 intelligence programmed (Note: I believe I'm aware of the difference
 between artificial intelligence and artificial conscusiness where the
 second would be able to answer things like: How are you today and
 the first can answer factual knowledge)


What you want to do is look up the difference between weak AI and
strong AI.
Everything we have to this day is weak AI, and there is still a debate
between
various scientists as to whether strong AI is even possible.  Be sure
to look
at Chinese room argument to see if strong AI is really what you need.
(http://en.wikipedia.org/wiki/Chinese_room)

 Am I thinking right here or is there some (preferrably) web reading
 available on that or in depth links about the topic?

 thanks and sorry for OT posting
 martin

 --http://noneisyours.marcher.namehttp://feeds.feedburner.com/NoneIsYours

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list in a tuple

2007-12-27 Thread montyphyton
After some tought I must agree that this is a wart more than
a bug and that it will probably be best not to mess with it.
However, what do you guys think about the print wart in Py3k
described at 
http://filoxus.blogspot.com/2007/12/python-3000-how-mutable-is-immutable.html#links
(im not trying to advertise my blog, I just don't feel like
typing the whole problem all over again)?

On 26 pro, 19:11, Arnaud Delobelle [EMAIL PROTECTED] wrote:
 On Dec 26, 1:08 am, Steven D'Aprano [EMAIL PROTECTED]

 cybersource.com.au wrote:
  On Mon, 24 Dec 2007 18:01:53 -0800, Raymond Hettinger wrote:
 [...]
   The first succeeds and the second fails.

  And this is a good idea?

  Shouldn't the tuple assignment raise the exception BEFORE calling
  __iadd__ on the item, instead of after?

 If you look at the bytecode generated, this doesn't seem possible:

  def f():

 ...     a = ([1],)
 ...     a[0] += [2]
 ... import dis
  dis.dis(f)

   2           0 LOAD_CONST               1 (1)
               3 BUILD_LIST               1
               6 BUILD_TUPLE              1
               9 STORE_FAST               0 (a)

   3          12 LOAD_FAST                0 (a)
              15 LOAD_CONST               2 (0)
              18 DUP_TOPX                 2
              21 BINARY_SUBSCR
              22 LOAD_CONST               3 (2)
              25 BUILD_LIST               1
              28 INPLACE_ADD
              29 ROT_THREE
              30 STORE_SUBSCR
              31 LOAD_CONST               0 (None)
              34 RETURN_VALUE

 BINARY_SUBSCR puts a[0] on the stack, it has no way to know that a[0]
 will be changed in place.  To allow an exception to be thrown before
 the in-place modification of a[0], there should be a new bytecode
 instruction, say BINARY_SUBSCR_WITH_A_VIEW_TO_CHANGE_IN_PLACE, which
 checks that the subscriptable object supports STORE_SUBSCR (;-).

 [...]

  I was never a big fan of augmented assignments. I think it goes against
  the Python grain: it's an implied operation, using punctuation, for the
  sole (?) benefit of saving a keystroke or three.

  But I think this behaviour counts as a wart on the language, rather than
  a bug.

 Yes.  I didn't realise this before you mentioned it, but the culprit
 here seems to be the augmented assignment which acts differently on
 mutable and immutable objects:

 b = a  # say a is immutable
 a += c # equivalent to a = a + c
 b is a # - False

 b = a  # Now say a is mutable
 a += c # equivalent to a.__iadd__(c)
 b is a # - True

 OTOH augmented assignent are a slight optimisation:

 a[i] += 1

 will look for the value of a and i only once and duplicate them on the
 stack, whereas

 a[i] = a[i] + 1

 will need to resolve a and i twice (which can be costly if a and i are
 globals)

 --
 Arnaud

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list in a tuple

2007-12-27 Thread montyphyton


On Dec 27, 8:20 pm, Wildemar Wildenburger
[EMAIL PROTECTED] wrote:
  

  From that post:
   Ok, I do admit that doing
  
   a = ([1], 2)
   a[0].append(2)
  
   also doesn't throw an error, but this only confuses me more.
  
 Why? You mutate thelist, but thetupledoes not change. It is still atupleof 
 alistand an int. At least that's how I think about it, and I
 seem to recall reading that beavior justified like this (don't ask me
 where though (might have been Dive Into Python, but maybe not)).

That part is ok, I mean it doesn't confuse me I just wanted to say
that this is somewhat confusing behavior.
I agree that its not best put... But I was thinking about the last
part of the post, the part
that talks about trying to print a tuple and getting an error.


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list in a tuple

2007-12-27 Thread montyphyton
Carl Banks wrote:
 On Dec 27, 12:38 pm, [EMAIL PROTECTED] wrote:
 After some tought I must agree that this is a wart more than
 a bug and that it will probably be best not to mess with it.
 However, what do you guys think about the print wart in Py3k
 described 
 athttp://filoxus.blogspot.com/2007/12/python-3000-how-mutable-is-immuta...
 (im not trying to advertise my blog, I just don't feel like
 typing the whole problem all over again)?


 1. Tuples are immutable.  None of the tuples in your example were
 modified.

 The behavior you want (which is not immutability of tuples, which
 Python already has, but *recursive* immutability of all objects
 contained within the tuple) is not an unreasonable thing to ask for,
 but the design of Python and common usage of tuples makes it all but
 impossible at this point.

 There is no general way to determine whether an object is mutable or
 not.  (Python would have to add this capability, an extremely
 substantial change, to grant your wish.  It won't happen.)

like I said, I don't think that this behavior should be changed...
therefore, no wish-granting is needed, thank you :)



 Tuples are used internally to represent the arguments of a function,
 which are often mutable.

 Tuples are sometimes used to return multiple values from a function,
 which could include mutable values.

 Tuples are used to specify multiple arguments to a format string, some
 of which could be mutable, though I guess this is going away in Python
 3.


 2. The issue with print in your example is a bug, not a wart.  It'll
 be fixed.

 (This is just a guess, but I think it might have something to do with
 the flux of the new bytes type.  The behavior manifested itself when
 trying to print a self-referencing structure probably only because
 that section of code was lagging behind.)


 3. You're still top posting, which goes against this group's
 conventions and annoys quite a few people.  When you reply to a
 message, please move your cursor to below the quoted message before
 you begin typing.  Thank you

sorry for top posting...
-- 
http://mail.python.org/mailman/listinfo/python-list


list in a tuple

2007-12-24 Thread montyphyton
Recently, I got into a debate on programming.reddit.com about
what should happen in the following case:

 a = ([1], 2)
 a[0] += [3]

Currently, Python raises an error *and* changes the first element of
the tuple. Now, this seems like something one would want to
change - why raise an error *and* execute the thing it
was complaining about? The discussion seems to have no end, and
that is why I'm posting here. I would like to know what is the opinion
of the people on this group... Am I really mistaking for thinking that
this is strange and unwanted behavior? Btw I understand *why* is this
happening, I just think it should change...
And here is the post that started this discussion:
http://filoxus.blogspot.com/2007/12/python-3000-how-mutable-is-immutable.html#links

Thanks for your replies
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: list in a tuple

2007-12-24 Thread montyphyton
Like I said, it is clear *why* this happens, what I
am concerned is if this what we *want* to happen, i.e.,
if the current situation is satisfying. Your mytuple class
would be something that resembles a solution, my question
is what the people on this group think about it.

On Dec 24, 5:08 pm, Arnaud Delobelle [EMAIL PROTECTED] wrote:
 On Dec 24, 3:22 pm, [EMAIL PROTECTED] wrote:



  Recently, I got into a debate on programming.reddit.com about
  what should happen in the following case:

   a = ([1], 2)
   a[0] += [3]

  Currently, Python raises an error *and* changes the first element of
  the tuple. Now, this seems like something one would want to
  change - why raise an error *and* execute the thing it
  was complaining about? The discussion seems to have no end, and
  that is why I'm posting here. I would like to know what is the opinion
  of the people on this group... Am I really mistaking for thinking that
  this is strange and unwanted behavior? Btw I understand *why* is this
  happening, I just think it should change...
  And here is the post that started this 
  discussion:http://filoxus.blogspot.com/2007/12/python-3000-how-mutable-is-immuta...

  Thanks for your replies

 For the sake of clarity, say you have typed:

  L = [1]
  a = (L, 2)
  a[0] += [3]

 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: 'tuple' object does not support item assignment a

 ([1, 3], 2)

 I think that this is what happens when a[0] += [3] is executed:

 1. list.__iadd__(L, [3]) is called, modifying L in place and returning
 L.
 2. tuple.__setitem__(a, L) is tried, raising the TypeError.

 Notice that this problem doesn't arise when replacing lists with
 tuples:

  a = ( (1,), 2)
  a[0] += (3, )

 Traceback (most recent call last):
   File stdin, line 1, in module
 TypeError: 'tuple' object does not support item assignment a

 ((1,), 2)

 This is because tuple object don't have an __iadd__ method so a new
 object tuple.__add__((1,),(3,)) is created and returned.

 AFAICS, the only way to avoid the error message would be to check if
 the new object is the same as the old one before raising the
 TypeError:

 class mytuple(tuple):
 It's ok to do t[i] = obj as long as t[i] was already obj
 def __setitem__(self, i, val):
 if self[i] is not val:
 raise TypeError('mytuple' object is immutable)

 So:

  a = mytuple(([1], 2))
  a[0] += [3] # This now works
  a[1] += 4   # This won't work as ints are immutable

 Traceback (most recent call last):
   File stdin, line 1, in module
   File tuple.py, line 4, in __setitem__
 raise TypeError('mytuple' object is immutable)
 TypeError: 'mytuple' object is immutable a

 ([1, 3], 2)

 It wouldn't slow anything down I suppose, just make some currently
 failing code succeed.

 --
 Arnaud

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting dict keys

2007-07-21 Thread montyphyton
On 21 srp, 02:31, Steven D'Aprano
[EMAIL PROTECTED] wrote:
 On Fri, 20 Jul 2007 15:27:51 -0700, montyphyton wrote:
  b = a.keys()
  b.sort()
  [1, 2, 3]

  Works fine, but I would really like it if I could somehow do it in one
  line.

 Why? Is the Enter key on your keyboard broken? Is there a global shortage
 of newline characters that I haven't been told about? Does your employer
 pay you less if you write more lines?

 --
 Steven.

I'd like to do it in one line because what I am trying to do is, after
all, a single, simple enough action. I find the suggested
b = sorted(a.keys()) much more readable than breaking it up in two
lines. In the long run, I guess it's a matter of personal taste...
Do I get payed less for more source code? Since I'm a student, I don't
get payed at all, regardless of number of lines :)

-- 
http://mail.python.org/mailman/listinfo/python-list


Sorting dict keys

2007-07-20 Thread montyphyton
Consider the following:
 a = {1:2, 3:4, 2:5}

Say that i want to get the keys of a, sorted. First thing I  tried:

 b = a.keys().sort()
 print b
None

Doesn't work. Probably because I am actually trying to sort the keys
of the dictionary without copying them first. If that is the case,
fine. Next thing I do:

 b = a.keys()
 b.sort()
[1, 2, 3]

Works fine, but I would really like it if I could somehow do it in one
line. As the problem seems to be copying the object, i try the
following:

 import copy
 b = copy.copy(a.keys()).sort()
 print b
None

Hmmm, why doesn't it work? Also,

 b = copy.deepcopy(a.keys()).sort()
 print b
None

(not that I thought that deepcopy will work since shallow didn't, I
understand the difference :) )
Obviously, I am missing something here. What am I thinking wrong? Why
doesn't copying the object work?
Thanks for all the help

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Sorting dict keys

2007-07-20 Thread montyphyton
On 21 srp, 00:47, Duncan Smith [EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] wrote:
  Consider the following:

 a = {1:2, 3:4, 2:5}

  Say that i want to get the keys of a, sorted. First thing I  tried:

 b = a.keys().sort()
 print b

  None

  Doesn't work. Probably because I am actually trying to sort the keys
  of the dictionary without copying them first. If that is the case,
  fine. Next thing I do:

 b = a.keys()
 b.sort()

  [1, 2, 3]

  Works fine, but I would really like it if I could somehow do it in one
  line. As the problem seems to be copying the object, i try the
  following:

 import copy
 b = copy.copy(a.keys()).sort()
 print b

  None

  Hmmm, why doesn't it work? Also,

 b = copy.deepcopy(a.keys()).sort()
 print b

  None

  (not that I thought that deepcopy will work since shallow didn't, I
  understand the difference :) )
  Obviously, I am missing something here. What am I thinking wrong? Why
  doesn't copying the object work?
  Thanks for all the help

 sort() sorts a list in place and returns None.  For a one-liner:

  a = {1:2, 3:4, 2:5}
  b = sorted(a.keys())
  b

 [1, 2, 3]

 Duncan

Thanks, this is what I was looking for. I know that .sort() sorts the
list in-place (the snippet I posted was written in a hurry, not pasted
-- I apologise for that). In fact, this is exactly what puzzles me.
copy.copy returns a new object:

 copy.copy(a.keys())
[1,2,3]

Then why doesn't copy.copy(a.keys()).sort() work??
Thanks to everyone who replied!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which GUI module you suggest me to use?

2007-06-06 Thread montyphyton
 This completely loses me; what do you mean by draw its own icon,
 and what does that have to do with rendering Web pages?

maybe draw its own icons wasn't the best (or the most accurate way)
of putting it. what i meant by that is this (from wikipedia):

Qt uses its own paint engine and controls. This makes the work of
porting to other platforms easier because very few classes in Qt
depended on the target platform. Qt used to emulate the native look of
its intended platforms, which occasionally led to slight discrepancies
where that emulation wasn't perfect. This, however, no longer applies
because the latest versions of Qt use the native styles API of the
different platforms to draw the Qt controls.

what does that have to do with rendering web pages? have no idea. i
just wanted to point out the main difference between qt and wx that he
should be aware of.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Determinant of Large Matrix

2007-06-06 Thread montyphyton

James Stroud je napisao/la:
 Hello All,

 I'm using numpy to calculate determinants of matrices that look like
 this (13x13):

 [[ 0.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]
   [ 1.  0.  1.  4.  1.  9.  4.  4.  1.  1.  4.  9.  4.  9.]
   [ 1.  1.  0.  1.  4.  4.  9.  9.  4.  4.  1.  4.  1.  4.]
   [ 1.  4.  1.  0.  9.  1.  4.  4.  9.  1.  4.  1.  4.  1.]
   [ 1.  1.  4.  9.  0.  4.  4.  4.  1.  4.  1.  9.  4.  9.]
   [ 1.  9.  4.  1.  4.  0.  4.  4.  9.  4.  1.  1.  4.  1.]
   [ 1.  4.  9.  4.  4.  4.  0.  1.  1.  1.  9.  1.  9.  4.]
   [ 1.  4.  9.  4.  4.  4.  1.  0.  4.  1.  9.  4.  4.  1.]
   [ 1.  1.  4.  9.  1.  9.  1.  4.  0.  4.  4.  4.  4.  9.]
   [ 1.  1.  4.  1.  4.  4.  1.  1.  4.  0.  9.  4.  9.  4.]
   [ 1.  4.  1.  4.  1.  1.  9.  9.  4.  9.  0.  4.  1.  4.]
   [ 1.  9.  4.  1.  9.  1.  1.  4.  4.  4.  4.  0.  4.  1.]
   [ 1.  4.  1.  4.  4.  4.  9.  4.  4.  9.  1.  4.  0.  1.]
   [ 1.  9.  4.  1.  9.  1.  4.  1.  9.  4.  4.  1.  1.  0.]]

 For this matrix, I'm getting this with numpy:

   2774532095.971

 But I have a feeling I'm exceeding the capacity of floats here. Does
 anyone have an idea for how to treat this? Is it absurd to think I could
 get a determinant of this matrix? Is there a python package that could
 help me?

 Many thanks for any answers.

 James

have you tried using matlab to verify the result? matlab is very fast
and can work with large matrices, so this should be no problem for
it...

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Who uses Python?

2007-06-05 Thread montyphyton
i use it for text mining, processing large text corpora for scientific
purposes. i'm also working on some neat data mining tools written in
python (called orange, in case someone's interested)

walterbyrd je napisao/la:
 I mean other than sysadmins, programmers, and web-site developers?

 I have heard of some DBAs who use a lot of python.

 I suppose some scientists. I think python is used in bioinformatics. I
 think some math and physics people use python.

 I suppose some people use python to learn programming in general.
 Python would do well as a teaching language.

 I would think that python would be a good language for data analysis.

 Anything else? Finance? Web-analytics? SEO? Digital art?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which GUI module you suggest me to use?

2007-06-05 Thread montyphyton

ZioMiP je napisao/la:
 Hi to all...

 I'm actually using Tkinter for my GUI... but I need to put a piece of a
 web-page in a widget how can I do?

 which GUI module do you suggest me to use for do that?

 or which GUI module do you suggest me to use at all?

 I'm acutally using Windows Xp but I also use Linux...

 I know that WxPython work only under Windows and PyGTK work only under
 Linux... there's some other modules?

have you considered using qt, i.e., pyqt, pyqwt? unlike wx, qt draws
its own icons...

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python, Dutch, English, Chinese, Japanese, etc.

2007-06-04 Thread montyphyton

Steve Howell je napisao/la:
 some European alphabets:

Spanish -- accented, includes digraphs ch and ll
German -- accented
French -- accented
Italian -- accented, no J/K/W/X/Y


what about slavic languages?
in croatian you have five accented letters plus three letters for
digrahps. russian, bulgarian, serbian, macedonian, ukranian etc. use
cyrilic alphabet (lets not forget that russia isn't that small -
around 150 million people), polish also has some of its own
characters...
all in all, it is estimated that some 400 million people speak slavic
languages...

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python, Dutch, English, Chinese, Japanese, etc.

2007-06-04 Thread montyphyton
 Agreed, but FWIW, if you compared Slavic-writing
 people to Chinese-writing people, I would think that a
 higher percentage of Slavic-writing people would be
 bilingual in terms of their ability to write code in
 non-Slavic alphabets, due to various
 cultural/geographical factors.

of course. but maybe it would be a nice effort to enable writing code
in cyrillic, since it is a whole new alphabet. for the accented
letters from slavic (or other) languages, i agree that one wouldn't
gain much from enabling their use in source code.
but my point being, if we are going to add chinese and japanese, why
not do everything right and add all languages/alphabets? after all,
after adding chinese, how hard can it be to add a few accedented
letters :)


 I don't predict a huge upswing in Slavic-writing
 Python programmers after PEP 3131, even among
 children.


you are probably right.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python, Dutch, English, Chinese, Japanese, etc.

2007-06-04 Thread montyphyton

Méta-MCI je napisao/la:
 Et le klingon ?

 Please, don't forget klingons
 SVP, n'oubliez pas les klingons

 ;o)

je pense que le klingon utilise les mems lettres comme l'anglais

-- 
http://mail.python.org/mailman/listinfo/python-list

Re: how can I get the name of a method inside it?

2007-06-03 Thread montyphyton
 I would like to know if it's possible to retrieve the name of a method when
 you're inside it. For example, in the following script, I would like to
 assign _s so that it prints you are in method1.


 ***
 class Obj1:
 def __init__(self):
 ...

 def method1(self):
 _s = ???
 print you are in %s % _s

 x = Obj1()
 x.method1()

i'm no expert on the subject, but AFAIK, there's no way to do this.
why not just print you are in method1?
what are you exactly trying to do?

-- 
http://mail.python.org/mailman/listinfo/python-list


PEP 8 style enforcing program

2007-05-31 Thread montyphyton
Some recent posts about Python programming style got me thinking.
Since we have the PEP 8 which gives some guidelines about the style to
be used, do we have any program that can check for violations of these
guidelines within the source code? I understand that there are a lot
of code beautifiers out there, but i haven't seen one specially
tailored for Python... Is there even a desire in Python community for
a program like this (by Python community I mean the people in this
group:) ) ? I think it would be a nice little project for practice and
I'd like to do it, but if there is already something like this then I
can probably spend my time on something more productive. So, I'd like
to hear your opinion on this...
There is one thing that I don't understand about PEP 8 - why is using
spaces considered more desirable than using tabs for indentation?

-- 
http://mail.python.org/mailman/listinfo/python-list


writing to a file

2007-05-30 Thread montyphyton
as i understand there are two ways to write data to a file: using
f.write(foo) and print f, foo.
what i want to know is which one is faster (if there is any difference
in speed) since i'm working with very large files. of course, if there
is any other way to write data to a file, i'd love to hear about it

-- 
http://mail.python.org/mailman/listinfo/python-list