Sunday, February 14, 2010

Banning the use of the word Sustainable


In a finite world due to be sucked into the sun in only 7.5billion years, nothing is truly sustainable. "Sustainable" has become so meaningless that the local chamber of commerce referred to a "return to a sustainable economy" recently, so would we be lost for words if we banned the use of "Sustainable"?

I'm going to try very hard to remove the word from my vocabulary from now on and use some of these instead:

Resilience - the ability to bounce back, and often the opposite of efficiency. A highly efficient system is designed for the highest gain in the short term. It is tuned to current circumstances and as soon as those circumstances change it is no longer efficient. The more efficient and specialised a system, business or organism becomes the less adaptable and resilient. Resillience is about the boring stuff. The boring banks were more resillient, the boring businesses producing essential goods and services for local markets - funeral directors, tyre sales, food markets are all ticking away. Resillience is about reliability and repairability. Resillience is about having an infrastructure we can trust - energy, transport, broadband, water.

Continuity - the value in keeping some things the same while others change. The loss of a business is not simply a monetary loss for the economy but the loss of intelligence. An established company has an intelligence and learning of it's own which is held by it's staff. While some of that intelligence may be written down, breaking up the people means losing that intelligence. Continuity is about keeping and using that collective intelligence, even if the original purpose has changed.

Balanced Portfolio - In the old days, a couple of decades ago, financial advisors talked about a balanced portfolio. You had your safe (!) bonds and blue chip stocks, your more risky stocks and shares and a few high risk investments. If our economy was a balanced portfolio, the safe investments would be investing in our own elf-sufficiency, making goods and services that are needed in our own economy. The medium risk would be making goods for export markets, attracting multinational FDR and investing in foreign businesses. High risk would be relying on cycles that are likely to be short lived - housing booms have historically been followed by housing busts and there seems to escape from that cycle.

Natural Lifespan - while long term thinking, continuity and resilience have their place, being able to exploit short term opportunities, the high risk element of the balanced portfolio, is also of great benefit and the trick here is to build in the demise as well as the creation and the skill is in knowing when to change.

What all of these words have in common is a longer term view of success than we have become used to, so rather than asking for the speaker's or author's definition of "Sustainable" as I have in the past, I will ask "Do you mean continue indefinitely, or do you have a more realistic timeframe in mind?".

Sunday, February 7, 2010

Installing OpenCV 2 on OSX with Python

Starting with instructions on the Willow Garage site, I fell at the first hurdle because thought I didn't need to install svn. Briefly, this is what I did and the more detailed explanation follows.

The short route:

1. sudo fink install svn-ssl (which takes a long time!)
2. sudo port install cmake
3. svn co https://code.ros.org/svn/opencv/trunk opencv
4. cd opencv
5. mkdir opencv/build
6. cd opencv/build
7. cmake ..
8. ccmake . (option c then option g)
9. make
10. sudo make install

On my osx 10.5 it copied the shared objects file to:

/usr/local/lib/python2.5/site-packages/cv.so

so I needed to move it to the site-packages I was using

11. cp /usr/local/lib/python2.5/site-packages/cv.so /Users/phoebebr/Development/site-packages

Now I can do:

python
>>> import cv

no error

and I can run the tests in my downloaded opencv folder,

cd opencv/opencv/tests/python
python test.py

This did report a few problems but most stuff seemed to run. Tried to run some tests calling opencv from Aptana but this caused the following error: " cp /usr/local/lib/python2.5/site-packages/cv.so /Users/phoebebr/Development/site-packages". Having installed successfully (I hope!) will have a go a writing a few programs next week....




The long route:

Already had svn so did:
svn co https://code.ros.org/svn/opencv/trunk opencv
and got
svn: SSL is not supported
so thought, I don't need https
svn co http://code.ros.org/svn/opencv/trunk opencv

and got

svn: PROPFIND request failed on '/svn/opencv/trunk'
svn: PROPFIND of '/svn/opencv/trunk': 301 Moved Permanently (http://code.ros.org)


So tried the instructions from the top:

The-Black-Book-2:site-packages phoebebr$ sudo port install subversion
Password:
---> Fetching apr
---> Attempting to fetch apr-1.3.5.tar.bz2 from http://www.mirrorservice.org/sites/ftp.apache.org/apr
---> Attempting to fetch apr-1.3.5.tar.bz2 from http://apache.multidist.com/apr
---> Attempting to fetch apr-1.3.5.tar.bz2 from http://apache.mirroring.de/apr
---> Attempting to fetch apr-1.3.5.tar.bz2 from http://archive.apache.org/dist/apr
---> Verifying checksum(s) for apr
---> Extracting apr
---> Configuring apr
---> Building apr
---> Staging apr into destroot
---> Installing apr @1.3.5_0
---> Activating apr @1.3.5_0
Error: Target org.macports.activate returned: Image error: /opt/local/bin/apr-1-config already exists and does not belong to a registered port. Unable to activate port apr.
Error: The following dependencies failed to build: apr apr-util expat libiconv gperf sqlite3 ncurses ncursesw readline cyrus-sasl2 openssl zlib gettext neon serf
Error: Status 1 encountered during processing.

So found this URL:
http://project-tigershark.com/people/rob/blog/2006/08/21/svn-on-os-x-with-fink-part-i-installation/
which explained that I needed the server version of svn and I only had the client version installed.

and did

sudo fink install svn-ssl


and that install svn so could continue with instructions above, missing the first step. Phew....

Thursday, January 28, 2010

I want an iPad


Apple have done it again, leapt ahead of the competition with the new iPad. Now I just have to find a business reason to justify buying one.

I can see a whole new market with the oldies and the computer phobes. This isn't a computer, just a simple of doing the essentials.

Want, want, want...

Wednesday, January 27, 2010

Dr Seuss and Copenhagen

Thanks to Tin Harper who started it http://cientifica.eu/blog/2009/12/cop-15-as-reported-by-dr-seuss/ and Bruce Darrell who forwarded it!

Monday, January 25, 2010

Using Pyparsing to extract dates from text block


This is very much work in progress, but I thought I'd post in case it helps anyone.

I'm currently using two bits of code, one to handle relative dates like "today", "2 days ago" and the other to handle specific dates like "3rd November 2009". These bits of code are building on work already done by others. I've tweeked them and added tests for parsing using parseString - expecting whole text to be a date, eg. "13th December 2009" and scanning using scanString where the date or dates is buried in the text, eg. "projects starts on 12th Nov 09 and finishes 3/2/10".


Relative dates:

Original code is in the Examples - In development on the pyparsing site: http://pyparsing.wikispaces.com/UnderDevelopment

Actual dates:



Sunday, January 24, 2010

Can you read this ok?

A good day for the terrsitros tadoy, wohse gaol atefr all is not to klil ppolee, but to sreapd trroer. The ppear and tv are flul of reotprs of the lteast inrasece in toerrr alret and all the mnay pisbosle rsaoens for it. And all the treisrort had to do was fial to klil a panle laod of peolpe and feed the mdeia. Are tehy vrey sarmt or are we vrey giulblle?

Stumbled across this blog and had to have a go myself http://blog.ggvic.com/2006/12/it-doesnt-matter-what-order-letters.html

Our brains are so smart that we only need the first and last letters in the correct order to be able to make a very accurate guess at the word.

For a bigger challenge, read Iain M Banks, Feersum Endjinn, much of which is written phonetically, for example:

Woak up. Got dresd. Had brekfast. Spoke wif Ergates thi ant who sed itz juss been wurk wurk wurk 4 u lately master Bascule, Y dont u ½ a holiday? & I agr.
Amazon

Have a go jumbling your text:

http://www.stevesachs.com/jumbler.cgi

Saturday, January 23, 2010

Getting started with Pyparsing

Pyparsing is especially useful for those of us who don't use regexp enough to get any good at it! It is a deceptively simple parser for all kinds of text.

Here are a few resources and tutorials I found useful.

And here is my first program. The requirement is to decode an instruction into two chunks. An opening "o" or "-", followed by a mix of "?", "!", "&","^".

from pyparsing import *


def matching(list1, list2):

if len(list1) != len(list2):
return False

for key in list1.keys():
if (not list2.has_key(key)) or (list2.has_key(key) and list2[key] != list1[key]):
return False
return True

tests = [
('o?',{'status':'o', 'stype':'?'}),
('-!',{'status':'-', 'stype':'!'}),
('-!!!',{'status':'-', 'stype':'!'}),
('o?!',{'status':'o', 'stype':'?'}),
]


def handleStuff(string, location, tokens):

print 'string',string
print 'tokens', tokens, tokens[0][0]
return tokens[0][0]


status = Word("-o")
stype = Word("!?&^").setParseAction(handleStuff)


search = ZeroOrMore(status("status"))+ZeroOrMore(stype("stype"))


for (test, result) in tests:
print '---------------'
parsed = search.parseString(test,parseAll=True)
return_value = {'status':parsed.status, 'stype':parsed.stype}
print test, return_value, result, matching(return_value, result)

The bits I had to google a while for:

How to return named tokens.

If you did:

search = ZeroOrMore(status("myvar"))

and this is recommended above using setResultsName I believe.

then to get the return value:

parsed = search.parseString("My test string")
print parsed.myvar


The other question was what does setParseAction return and the answer is an updated token. See example above which returns the first character in the first token.


Results of the program are:

---------------
string o?
tokens ['?'] ?
o? {'status': 'o', 'stype': '?'} {'status': 'o', 'stype': '?'} True
---------------
string -!
tokens ['!'] !
-! {'status': '-', 'stype': '!'} {'status': '-', 'stype': '!'} True
---------------
string -!!!
tokens ['!!!'] !
-!!! {'status': '-', 'stype': '!'} {'status': '-', 'stype': '!'} True
---------------
string o?!
tokens ['?!'] ?
o?! {'status': 'o', 'stype': '?'} {'status': 'o', 'stype': '?'} True