Thursday, December 24, 2009

Wednesday, December 23, 2009

MATLAB gem II: An example

While I was ‘playing’ with the function fdep I decided to write a small M-file to show usage and potential problem.

The code does not produce any useful results but it is not junk either. It calls functions from a few toolboxes. Each function uniquely appears in each toolbox; No ambiguity. Then there is a parameter whose name shadows the name of a MATLAB function.

%% Quick code to test fdep

clear all

% Create 0-mean normal distribution with std = 2
Y = 0 + 2.* randn(1,128);

n = length(Y); % Length of vector n

yy = ceil( max( abs(Y) ) ); % max abs value of data

%% Run sequence plot - MATLAB

subplot(221)
plot(Y, '-')
grid on
axis([1 Inf -yy yy])
title('Run Sequence plot')

%% decimate - Signal Processing Toolbox

YY = decimate(Y,2);

subplot(222)
plot(linspace(1,128,length(YY)), YY, '-')
grid on
axis([1 Inf -yy yy])
title('Decimated Run Sequence plot')

%% Create histogram - MATLAB + Statistics Toolbox

subplot(223)
hist(Y)
hold on
histfit(Y)
hold off
axis([-yy yy 0 Inf])
title('Histogram')

%% Normal probability plot - Statistics Toolbox

subplot(224)
normplot(Y)
title('Normal Probability Plot')

%% Unrelated code: Use parameter named 'step' – MATLAB

lamda = 100;

K = 154;

step = 0;
count = 0;

for id = 1:K+1
   dummy = exp(-lamda) *lamda^(id-1) /factorial(id-1);
   step = step + dummy;
   count = count + 1;
end

The code results in the following plot:

testCode_0912_01

The code is actually 3/4 useful but that is another story.

Now, if you execute fdep from the command line on the M-file shown above the output would look like:

>> P = fdep('testCode_0912_01');
ROOT   : > D:/Documents and Settings/../My Documents/MATLAB/Testing Ground/testCode_0912_01.m
1    1   : | testCode_0912_01      S  0:

-------------  NO USER-DEFINED DEPENDENCIES FOUND
M-FILE       : D:/Documents and Settings/../My Documents/MATLAB/Testing Ground/testCode_0912_01.m
P-FILE       :                                                                                       
MODULE  #   1: testCode_0912_01                                                                      
type         : SCRIPT                                                                                
created      : 23-Dec-2009 12:30:36                                                                  
size         : 1046 bytes                                                                            
lines        : 62                                                                                    
comments     : 9                                                                                     
empty        : 21                                                                                    
recursive    : no                                                                                    
f/eval..     : not used                                                                              
unresolved   : no                                                                                    
calls    TO  :     0  user defined                                                                   
called   FROM:     0  user defined                                                                   
calls in FILE:    20                                                                                 
subfunctions :     0  inside  file                                                                   
nested       :     0                                                                                 
anonymous    :     0                                                                                 
f/eval..     :     0                                                                                 
unresolved   :     0                                                                                 
ML      stock:    13                                                                                 
ML  built-ins:    10                                                                                 
ML    classes:     1                                                                                 
OTHER classes:     0                                                                                 
ML  toolboxes:     4                                                                                 
             :    +1  Control System Toolbox (8.2) [control]                                         
             :    +2  MATLAB (7.7) [matlab]                                                          
             :    +3  Signal Processing Toolbox (6.10) [signal]                                      
             :    +4  Statistics Toolbox (7.0) [stats]                                               
>>

>> P.toolbox

ans =

    'Control System Toolbox (8.2) [control]'
    'MATLAB (7.7) [matlab]'
    'Signal Processing Toolbox (6.10) [signal]'
    'Statistics Toolbox (7.0) [stats]'

>>

Mostly correct; Unfortunately it identifies the presence of the Control Systems Toolbox because of the presence of parameter step. Can’t have everything! Still, a very useful function.

 

Technorati Tags: ,,,,,,

Tuesday, December 22, 2009

MATLAB gem II

Recently I had to figure out which MATLAB toolboxes a massive program is using. The program itself is a smorgasbord of over 5000 (!!) function written by a small army of developers over a number of years. It is a form of spaghetti code based on OOP ideals. Seemingly, no start and no end.
Normally I would not care. I would approach the code as a basic developer and write my new code as needed. I know that applying patches is not a good practice (I really dislike the idea) but my time is a lot more valuable than trying to follow calls forever. However, in this case all that code needs to be installed on more machines. And the installation is temporary. Therefore it makes no sense to buy the full-MATLAB-with-all-toolboxes-plus-Simulink-and-everything-else kind of license we typically buy. Therefore, I had to figure out what exactly that particular program is using.
So I Googled the problem and found exactly what I was looking for in the file exchange of MATLAB Central. The function contributed by us; The contribution is titled fdep: a pedestrian function dependencies finder and it is exactly what I was looking for.
The function (set of functions really) is well written and documented. It very quickly goes through a MATLAB program and displays information about users defined functions, sub-functions, MATLAB functions, toolboxes, calls, etc. Toolboxes!! There is a command line interface and a graphical one. It even comes with an HTML help file. Great work!
One caveat: At least when it comes to the toolboxes the result could be inaccurate. The reason for that is that if a developer is using a parameter name that shadows the name of an existing MATLAB function the the conflict is resolved in favor of MATLAB. For example, if a developer programmed the statement
step = 1;

then fdep will determine that step is the MATLAB function from the Control System Toolbox. That is a problem with namespace littering. And with all the toolboxes available for MATLAB pretty soon all normal dictionary words will shadow some MATLAB function. Anyway…
For my case I used the function fdep in a script that navigated through the mess of code and interrogated each function and printed back the toolbox result. The function worked quickly with few hick-ups and returned reasonable results: A few toolboxes in addition to core MATLAB. It might be that a couple of them seem suspicious but the effort required to uncover details is out of scope!
Technorati Tags: ,,,,

Sunday, December 20, 2009

The first big snowstrom (for a second time!)

I have survived snowstorms in MA before (years ago) but it is always… interesting to wake up surrounded by a foot of snow. Of course it helps to reside in an apartment. The best thing about living in an apartment is the sense of freedom. The second best is that I do not have to clear driveways and sidewalks of all the snow!

The snowfall probably started after 1:00 am and it accumulated very quickly. By 9:00 am Reading was transformed to a winter wonderland. A cold one though; The temperature was around –5C throughout the day.

01Dec.09.Boston_ 02Dec.10.Boston_

The snow was the kind of dry, fluffy snow that you cannot even use for a snowball fight, or to make a snowman (though we tried!) and it kept falling until about 1:00 pm. The maintenance people here were clearing the side walks and the snow ploughs were pushing snow out of the way for most of the day.

Everything was buried pretty deep. The Jeep is very useful during winter in MA!

007 010

Friday, December 18, 2009

FIFA World Ranking Top 20: December 2009

Rank (previous) Team Points Comment
1 (2) Spain 1627  
2 (1) Brazil 1568  
3 (3) Netherlands 1288  
4 (4) Italy 1209  
5 (10) Portugal 1176 That actually is about right.
6 (4) Germany 1173  
7 (9) France 1117 And that is not even close to being right…
8 (6) Argentina 1085  
9 (7) England 1076  
10 (8) Croatia 1042  
11 (14) Cameroon 1035  
12 (12) Russia 1026 Did not even make it to South Africa!
13 (16) Greece 1016 Home tie and away win against Ukraine in November (play-offs for World Cup qualification.)
14 (11) USA 980  
15 (17) Chile 936  
16 (19) Cote d’Ivoire 934  
17 (18) Mexico 931  
18 (13) Switzerland 924  
19 (20) Serbia 916  
20 (19) Uruguay 909  

Full table can be found at FIFA World Ranking.

Thursday, December 17, 2009

Military Could Use iPhones to Track Friends, Enemies in War

Military Could Use iPhones to Track Friends, Enemies in War

That is some pretty cool technology developed by Raytheon. And if ever Raytheon goes into the video game business their developers could develop some great strategy games.

The original article from the New York Times appeared in the Bits Blog.
The press releases from Raytheon can be found here and here.

I would assume that Apple would need to make a more rugged version of the iPod to turn it into a useful tool in the battlefield (No Doubt Mission Assurance and everything.) The biggest struggle might be for Raytheon and the US government to convince the image-conscious Apple to go for something like that!

Sunday, December 6, 2009

Yahoo Issues Takedown Notice for Spying Price List

Yahoo Issues Takedown Notice for Spying Price List

Once upon a time I respected and liked Yahoo! It seems that it has become much like the telecoms: they treat the customer like a commodity. Exploitation rules! And apparently that includes selling the privacy (whatever that might mean today) of their customers to the government (for now) and who knows who else in the future.

A number of 'lawful spying guides' are posted on Cryptome.org including Verizon, Nextel, GTE, etc.

Such pity...

Saturday, December 5, 2009

Jason & Christina Originals

I think they are pretty cool and I want to preserve them.

091206 J&C Originals copy

Friday, December 4, 2009

2010 World Cup Draw

It could have been worse for Greece which was drawn into group B along with Argentina, Nigeria, and South Korea. The ‘Group of Death’ is G with Brazil (FIFA #1), Ivory Coast (FIFA #16), and Portugal (FIFA #5), along with North Korea. The softest group is F with Italy and Paraguay, New Zealand, Slovakia (all 3 ranked 30 or lower; Italy should have a very pleasant group stage.) The US should go through along with England from group C.

The groups are:

Group A
France (7)
Mexico (15)
Uruguay (19)
South Africa (86)
Group B
Argentina (8)
Greece (12)
Nigeria (22)
South Korea (52)
Group C
England (9)
United States (14)
Algeria (28)
Slovenia (33)
Group D
Germany (6)
Serbia (20)
Australia (21)
Ghana (37)
Group E
Netherlands (3)
Cameroon (11)
Denmark (26)
Japan (43)
Group F
Italy (4)
Paraguay (30)
Slovakia (34)
New Zealand (77)
Group G
Brazil (2)
Portugal (5)
Ivory Coast (16)
North Korea (84)
Group H
Spain (1)
Chile (17)
Switzerland (18)
Honduras (38)

Greece will play against:

  • South Korea on June 12;
  • Nigeria on June 17;
  • Argentina on June 22.

History says that a win and a draw will likely get you through the group stage. Therefore, a win over South Korea (they cannot defend set pieces effectively) and a draw with Nigeria (suspect defense) should be sufficient for Greece to advance to the round of 16. All Greece needs to do is play good suffocating defense and score on quick counter attacks and set pieces. And if Maradona cannot keep his nose clean he might screw Argentina up and give us an advantage (though it would be difficult to mess up Lionel Messi and Co.)

If we advance then we will likely advance as a second seed and thus play against the first seed of group A; most likely that would be France.

GOOD LUCK GREECE!

BTW, actress Charlize Theron is magnificent!

Related articles:

GOAL.com: World Cup 2010: Group B Analysis - Argentina, South Korea, Nigeria, Greece

ESPN.com: Team analysis of the draw

FIFA.com: Group B stirs ghosts of '94

Wednesday, December 2, 2009

Ford Fiesta for the US

Finally the Ford Fiesta will be made available to the US market. The car is beautiful, successful, economic, and iconic in Europe. Not to mention that that it was the runner up for Car of the Year 2009 (losing by just one point!)

Fiesta_in_Vision

According to the official press release from Ford, the Fiesta will be available in the summer of 2010. It will have a 1600 cc 4-cylinder engine (that probably used to be an anathema for the average buyer in the US!) that delivers 119 HP. I expect (hope) that the car is going to be available with all the bells and whistles of the European version (Bluetooth with Voice Command, center console multifunctional display, MP3 & USB ready, rain sensing wipers, key free starter, stability and traction assist, parking assist sensor, etc) and definitely hope that is going to be available with a standard (manual) gearbox.

Fiest_Power_Starter_Button Fiesta_steering_wheel_and_controls Fiesta_Zetec-S_in_Vision Fiesta_auto-headlights

She is gorgeous. If it sells for a price similar to the Focus and VW Golf then the MSRP should be around $17000 which is OK for small family cars that appeal to young people.