<?xml version="1.0"?>
<!-- name="generator" content="blosxom/2.0" -->
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">

<rss version="0.91">
  <channel>
    <title>Patrick Roberts's Blog   </title>
    <link>http://egofile.com/blog</link>
    <description>Formalizing Intelligence in Code</description>
    <language>en</language>

  <item>
    <title>Speech Interface over Cordless Phones</title>
    <link>http://egofile.com/blog/2008/05/12#phoneadapter</link>
    <description>
&lt;p&gt;This circuit, connected to my sound card and a set of cordless phones, seems to be the cheapest way to talk with my computer wirelessly around the house.

&lt;p align=center&gt;&lt;img src=&quot;/phoneadapter.png&quot; alt=&quot;sound-card to phone adapter&quot;&gt;&lt;/p&gt;

&lt;p&gt;The design is mostly from &lt;a href=&quot;http://www.grynx.com/projects/build-your-own-chat-cord/&quot;&gt;http://www.grynx.com/projects/build-your-own-chat-cord/&lt;/a&gt; Improvements are welcome. The parts, especially the line isolation transformer, can be scavenged from a cordless phone. My local Goodwill sells them for $5. The microphone and speaker connections, at the right, are to those jacks in a sound card.

&lt;p&gt;The 9V can come from a battery. That worked for me until I experimented with leaving a muted speakerphone on for hours. Now I use a 9V power supply. It caused a hum on the phones, but the capacitor and the resistor (the left one) filter it well enough.

&lt;p&gt;I'm using a digital cordless phone but there's still noise. What are the likely causes? Wires too long? Lack of shielding?

&lt;p&gt;Have you tried alternatives?
&lt;ul&gt;
&lt;li&gt;Bluetooth: Seems inconvenient to screw the ear piece into my ear every time I want to talk. Phones have speakerphone modes. Range? (I gather there are two classes of Bluetooth devices with different ranges.)
&lt;li&gt;Walkie-talkies: I imagine these would have great range. Is there a common model that can be easily connected to a sound card? Would the computer have to press a button when it wants to talk?
&lt;li&gt;Skype phones: More expensive. Is there a standard API?
&lt;li&gt;Wired microphones &amp; speakers in each room: Nice but expensive. Still would want a phone for the yard.
&lt;li&gt;Robot that follows you around: Ideal, since it can carry sensors to know when to interrupt you, but very expensive. Phones would still be a good redundancy.
&lt;li&gt;Any option missing?
&lt;/ul&gt;

&lt;p&gt;Unfortunately, phones give the computer no easy way to indicate that it wants to talk. It could ring the phone, but that's a more complicated circuit - and annoying. Instead, when my computer has something it wants me to hear, it shows messages on the TVs.</description>
  </item>
  <item>
    <title>Assembly Line Syntax</title>
    <link>http://egofile.com/blog/2008/04/10#pipes</link>
    <description>
&lt;p&gt;It's often convenient to imagine a process as a tree-shaped (or graph-shaped) assembly line. Inputs flow in through the leaves and are transformed, filtered or reduced where branches join. This well represents lazy-functional programming. Say one wants the words from a line-delimited file, excluding acronyms, then converted to lower case and stored in a set for quick lookup. Compare syntaxes...

&lt;h3&gt;English:&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Get every line in file &lt;i&gt;words&lt;/i&gt;.
&lt;li&gt;Skip empty lines.
&lt;li&gt;Strip white space.
&lt;li&gt;Filter out words that have every letter capitalized.
&lt;li&gt;Covert each word to lowercase.
&lt;li&gt;Add to the set.
&lt;/ol&gt;

&lt;h3&gt;Procedural:&lt;/h3&gt;
&lt;pre&gt;
words = set()
for line in file('words'):
    line = line.strip()
    if line and not line.isupper():
        words.add(line.lower())
&lt;/pre&gt;
Variables describe edges in a graph, connecting parts of code, but without being obvious to the eye. Names are boring to create and are often misspelled.

&lt;h3&gt;Lazy-functional using standard Python:&lt;/h3&gt;
&lt;pre&gt;set(imap(str.lower, ifilterfalse(lambda w: w.isupper(), ifilter(None, imap(str.strip, file('words'))))))&lt;/pre&gt;

&lt;h3&gt;Lazy using a Python iterator comprehension:&lt;/h3&gt;
&lt;pre&gt;set(line.strip().lower() for line in file('words') if line.strip() and not line.isupper())&lt;/pre&gt;
This wastes time on a second strip() call.

&lt;h3&gt;Lazy-functional mixed with a Python iterator comprehension:&lt;/h3&gt;
&lt;pre&gt;set(line.lower() for line in ifilter(None, imap(str.strip, file('words'))) if not line.isupper())&lt;/pre&gt;
This eliminates the second strip() call but has a confusing mix of syntaxes. The data flow repeatedly changes direction.

&lt;p&gt;Prefix syntax - that of Lisp, Python, C, etc. - is backwards: the functions called later must precede those called earlier. One has to say what comes last first, like saying: &quot;Eat a sandwich; make a sandwich; buy groceries.&quot; The words are spelled left to right but the sentence is right to left.

&lt;p&gt;Consider this Python syntax hack to write lazy-functional code like an assembly line.

&lt;h3&gt;Lazy-functional using &lt;a href='/open/pipes.py'&gt;pipes.py&lt;/a&gt;:&lt;/h3&gt;
&lt;pre&gt;file('words') | pmethod('strip') | pfilter | pnfilter(methodcaller('isupper')) | pmethod('lower') | pset&lt;/pre&gt;

&lt;p&gt;This isn't shorter, but allows sequences of operations to be written naturally from left to right, without nested and distant parenthesis.

&lt;p&gt;pmethod() eases mapping using a method of the objects to be mapped, making this version more general because it works if the strings are a mix of str and unicode instances. methodcaller() similarly eases filtering.

&lt;p&gt;Presumably, this would be better in Lisp, using its read macros, but this abuse of __ror__ hasn't caused problems yet.

&lt;!--
Also much more convenient in the CLI because you needn't leap back &amp; forth to add pairs of brackets.
&lt;p&gt;Notice that functional programming spares the programmer from naming variables.
Most callables here expect an iterable on the LHS &amp; result in an iterator.
Pipe names starting with 't' (for 'terminate') result in something not iterable, or nothing.
| is bitwise OR for numbers &amp; union for sets, but is otherwise hardly used &amp; recalls UNIX pipes
--&gt;

&lt;p&gt;Related: &lt;a href='http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/276960'&gt;ASPN Cookbook Python recipe&lt;/a&gt;, &lt;a href='http://en.wikipedia.org/wiki/Dataflow_programming'&gt;Dataflow programming&lt;/a&gt;.

&lt;p&gt;Does anyone know of a practical language that takes this idea seriously?</description>
  </item>
  <item>
    <title>Objects are Exclusive Types &lt;!-- /Patterns --&gt;</title>
    <link>http://egofile.com/blog/2008/04/10#types</link>
    <description>
&lt;p&gt;There is a common dichotomy between objects and types.

&lt;blockquote&gt;&lt;b&gt;Object:&lt;/b&gt; Unique, objective, existing thing.&lt;br&gt;Examples: Socrates, the Sun, one's self.&lt;/blockquote&gt;

&lt;blockquote&gt;&lt;b&gt;Type:&lt;/b&gt; A bundle of attributes that may match zero or more objects.&lt;br&gt;Examples: man, star, yellow.&lt;/blockquote&gt;
&lt;!-- bundle is intentionally fuzzy; explore later --&gt;

&lt;p&gt;Similar distinctions appear in the assumptions &lt;!-- axioms --&gt; of major systems of philosophy, logic, and computer programming.

&lt;p&gt;An object is only a type that one expects to have no more than one &lt;!-- extrinsic --&gt; match at once. That is why minds believe objects exist. For example, if one believes in the Sun, &lt;!-- &amp; that its position is inessential to it as an object --&gt; and he believes the Sun is in the eastern sky, then he assumes the Sun is not in the western sky. &lt;!-- could use a better example --&gt; That seems trivial only because this type of inference is constantly relied on.

&lt;p&gt;Objects are unprovable. There could be a duplicate of any object. One would believe there is only one thing in the Universe with all those attributes, &lt;!--(except position, but that's inessential to the thing, or it would stop being that thing to you when it moved),--&gt; but his mistaken idea of an object is really a type. One can be certain that a type is a type but not that an object is an object. Beliefs in objects are routinely wrong and must be revised; beliefs in types are useless at worst.

&lt;p&gt;Axioms are to formal systems as rules are to a game. It seems unwise to afford an axiom to the idea of objects when the Universe may contain none or when beliefs in them may be useless.

&lt;p&gt;Natural languages, containing nouns and definite articles, encourage the useful presumption of objects.

&lt;p&gt;It is immensely beneficial to minimize axioms. Those remaining represent deeper patterns, giving greater leverage. For example, in a computer program, reducing axioms eases increasing reliability and speed. Also, fewer axioms with the same power are likely to be more expressive: simpler parts can form more combinations.
&lt;!-- want some mathematical precision here --&gt;

&lt;p&gt;In first-order logic, the similar distinction between things and predicates limits expressiveness. In it, statements about predicates, such as, &quot;yellow is a color&quot;, cannot be made without resorting to a trick like reification. When objects are eliminated, saying &quot;yellow is a color&quot; is no different than saying &quot;the Sun is yellow&quot;.

&lt;p&gt;Objects should not be axiomatic. They should be the fluctuating implications of a web of learned types and inferences. The goal is an algorithm for the creation and destruction of object beliefs. Presumably, a system to represent all the knowledge of a general intelligence must contain beliefs and beliefs about associations between beliefs. It's likely that the function of objects can be expressed in terms of negative associations between types.

&lt;!--
may want to reverse the order, starting with the goal of formalizing intelligence, explaining the value of minimizing axioms, then trying to remove the object axiom
&lt;p&gt;Types permit inferences. Without them one could not apply a belief that &quot;All men are mortal.&quot; You would individually judge each man before assuming he is mortal – absurdly time consuming.
&lt;p&gt;Nothing has functional existence beyond its description.
&lt;p&gt;If a type is similar to a tree, then a supertype would be a pruned type. It's important not to think of a type as the set of all things it matches; matching types is a process.
&lt;p&gt;There is no real distinction between types and objects, only a continuum of detail from more specific types to more abstract ones, from types matching only 1 believed object to the thing type that matches any belief.
&lt;p&gt;I want a system that can well represent all knowledge needed by a machine intelligence; having a lie in an axiom would be detrimental; why?
--&gt;

&lt;p&gt;&lt;i&gt;Thoughts?&lt;/i&gt;
</description>
  </item>
  <item>
    <title>Fancy wxPython Exception Handler</title>
    <link>http://egofile.com/blog/2004/09/12#support</link>
    <description>
&lt;p&gt;My &lt;a href=&quot;http://egofile.com/open/wxsupportwiz.py&quot;&gt;wxsupportwiz.py&lt;/a&gt; module has made it easy to solve most of the bugs that users have found in &lt;a href=&quot;http://egofile.com/egoclip/&quot;&gt;egoClip&lt;/a&gt;. I guess it resembles Mozilla's &lt;a href='http://www.mozilla.org/quality/qfa.html'&gt;Quality Feedback Agent&lt;/a&gt;, except it doesn't catch crashes in Python extensions, but those are rare.

&lt;p&gt;When an exception goes uncaught, it pops up a little window asking the user if it's okay to send error information to your website. Then it POSTs to your CGI script almost anything you could want about the error:

&lt;ul&gt;
&lt;li&gt;exception type
&lt;li&gt;traceback
&lt;li&gt;program version
&lt;li&gt;Windows version
&lt;li&gt;date
&lt;li&gt;current directory
&lt;li&gt;local variables
&lt;li&gt;and it's easy to add more.
&lt;/ul&gt;

&lt;p&gt;In egoClip's case, the CGI presently just e-mails me everything. The CGI could also match the error details to a set of solutions and output the URL to a page of instructions that the module will popup in the user's webbrowser.

&lt;p&gt;To hook it up, just:

&lt;pre&gt;
import wxsupportwiz
wxsupportwiz.wxAddExceptHook('http://egofile.com/naughty_users.php')
&lt;/pre&gt;

&lt;p&gt;As usual, let me know if you find this useful or if you have suggestions.</description>
  </item>
  <item>
    <title>Responsive User Interfaces II</title>
    <link>http://egofile.com/blog/2004/09/03#wxtimers2</link>
    <description>
&lt;p&gt;In my previous entry, I devised a cheap trick for improving the overall responsiveness of &lt;a href=&quot;http://egofile.com/egoclip/&quot;&gt;egoClip&lt;/a&gt;. I've since noticed the irony of trying to accelerate a program by inserting a delay. I also noticed that it doesn't make for a perfectly live search field, but it's at least wickedly easy to use and beats the typical behavior of always blocking the UI thread until the work's done.

&lt;p&gt;One conspicuous flaw is the requirement of a magic number: the length of the delay. Mainly this means it will fail when your computer's gummy.

&lt;p&gt;I think the deep solution is not to write the program in this style:

&lt;blockquote&gt;Oh, the user wants me to do X, then I'll do that right now and ignore everything until I'm finished.&lt;/blockquote&gt;

But instead to write it entirely this way:

&lt;blockquote&gt;Oh, the user wants me to do X, then I'll make a note to later do X after I've done all more urgent work and if the user hasn't since asked me to do something that would erase all of X's effects.&lt;/blockquote&gt;

&lt;p&gt;So in egoClip, if I want to show a news item when the user double clicks on a headline, I might hook it up using:

&lt;pre&gt;
headline_list_ctrl.Bind(wx.EVT_LIST_ITEM_ACTIVATED,
                        lambda e: queue.put(lambda i=e.GetIndex(): show_item(i),
                                            priority='high',
                                            affects=['shown item']))
&lt;/pre&gt;

&lt;p&gt;The priority is high because the user is sitting there waiting for it. The affects list gives the queue the information it needs to remove overridden pending jobs.

&lt;p&gt;This is a complex kind of queue, and it has to be thread-safe. Is there Python code for one of these? If not, I'll soon write it myself. Either way, stay tuned for code.</description>
  </item>
  <item>
    <title>Responsive User Interfaces</title>
    <link>http://egofile.com/blog/2004/08/23#wxtimers</link>
    <description>
&lt;p&gt;For the &lt;a href=&quot;http://egofile.com/egoclip/&quot;&gt;egoClip&lt;/a&gt; project, I aim to make the UI completely responsive. (By responsive, I mean that the UI never locks up and provides at least partial results ASAP, not that every operation is completed instantaneously.) I've used what I imagine is the standard/obvious approach:

&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;One big background thread that handles all slow tasks (mainly database work).
&lt;li&gt;Fed by a prioritized queue of jobs to do.
&lt;li&gt;And an idle event handler that gently does whatever work has to be done from the UI thread.
&lt;/ul&gt;

&lt;p&gt;Yesterday, a customer pointed out that in egoClip, when focused on the news item list control, if you hold down an arrow key to swiftly step through the items, it just leaps to an item when you release the key. The problem seemed to be that the time to show an item's text was greater than the key repeat rate. You could have a similar problem with a live search field.

&lt;p&gt;So I wrote a little wxPython function that makes it easy to delay responding to the user's actions until they finish or pause.
Here's the open-sourced code from egoClip: &lt;a href=&quot;http://egofile.com/open/wxtimers.py&quot;&gt;wxtimers.py&lt;/a&gt;. Example usage:

&lt;pre&gt;
from wxtimers import wxDoLater

def event_handler(what_the_user_wants):
    wxDoLater(0.5, lambda: show(what_the_user_wants))
&lt;/pre&gt;

&lt;p&gt;So if within half a second, the user asks you to show something else, the original do-later will be cancelled and the new one will start.

&lt;p&gt;The module also contains my trivial convenience subclass of wxTimer.</description>
  </item>
  <item>
    <title>wxSetting Python Module</title>
    <link>http://egofile.com/blog/2004/08/15#wxsetting</link>
    <description>
&lt;p&gt;I might be qualified to say something useful about Python because I seem to be one of the few who has built a consumer Windows application with it and has started selling some copies.

&lt;p&gt;The program's named &lt;a href=&quot;http://egofile.com/egoclip/&quot;&gt;egoClip&lt;/a&gt; (was less imaginatively named the NewsRanker until I noticed that Topix trademarked NewsRank; presumably they're playing on Google's PageRank and don't simply have it in for me). It's an RSS aggregator that learns to sort your news by how interesting it thinks you'll find them. Think Bayes meets RSS. Many others have had this idea, but hardly anyone seems to have done anything about it.

&lt;p&gt;Anyway, since code beats prose, here's some open-sourced code from egoClip: &lt;a href=&quot;http://egofile.com/open/wxsetting.py&quot;&gt;wxsetting.py&lt;/a&gt;. Example usage:

&lt;pre&gt;
from wxsetting import *

def font_change(new_value):
    [use the new font size]

app.settings = wxSettings(
    first_use = wxSetting(default=True),
    font_size = wxSetting(default=12, handler=font_change),
    )

# and then from your prefs code, you could go ...
font_size_ctrl.Bind(wx.EVT_SLIDER, lambda e: setattr(settings, 'font_size', e.GetInt()))
&lt;/pre&gt;

&lt;p&gt;Mainly, the point is that when you initialize your application, you define this bag of settings with defaults and optional functions to be called when the setting is changed. Then you can, e.g., pass this to your preferences dialog code and it can change settings without having to know what has to be done as a result. No doubt it's messy and there's much room for improvement, but if you find it useful or have suggestions, let me know.

&lt;p&gt;Now that I've reviewed the module, I'm reminded that I originally wanted to use &lt;a href=&quot;http://users.rcn.com/python/download/Descriptor.htm&quot;&gt;descriptors&lt;/a&gt; so I wouldn't have to put all the settings in a wxSettings bag to handle assignment, but couldn't because before wxPython 2.5, the frame and app classes weren't derived from object. I can change that now, though it's not so bad having all settings alone inside one object.</description>
  </item>
  </channel>
</rss>