Sunday, January 27, 2013

MCMC

Doing MCMC is fun! Thanks to KnuthClass
aa
% probability step
if x(n) < 0
    px = 3/5;
else
    px = 2/5;
end


% Metropolis Hastings MCMC

p = min([1, p(y)/p(x(n))]);
r = rand;

n = n+1;
if r < p 
    x(n) = y;
else
    x(n) = x(n-1);
end


%%

% do this 100 times

x(1) = 1;   % start in the low prob region
px(1) = 2/5;

for n = 1:10000
    
    % take a step
    y = (-1)*x(n);
    
    % probability step
    if y < 0
        py = 3/5;
    else
     py = 2/5;
    end
    
    % Metropolis Hastings MCMC
    p = min([1, py/px(n)]);
    r = rand;

    %n = n+1;
    if r < p 
        x(n+1) = y;
        px(n+1) = py;
    else
        x(n+1) = x(n);
        px(n+1) = px(n);
    end
    
    x(n)
    
end
    

%%
clear

% Gaussian probability density with zero mean and unit variance
prob = @(z)((sqrt(2*pi))^(-1)*exp(-z^2/2));

x(1) = 5*(2*rand-1);
px(1) = prob(x);

for n = 1:100000
    step = 0.01*randn;
    y = x(n)+step;
    
    py = prob(y);
    
    p = min([1,py/px(n)]);
    r = rand;

    if r < p 
        x(n+1) = y;
        px(n+1) = py;
    else
        x(n+1) = x(n);
        px(n+1) = px(n);
    end
end

 aa

Wednesday, January 23, 2013

Blogger Trick hide the post/widget in main page

Well, I wanted to replace some of the widgets to invisible mode in nabinkm.com. Actually, wanted for long time...
<b:if cond='data:blog.pageType != "index"'>

the widget goes here...

</b:if>

Another trick is: replacing
]]></b:skin>


 by


]]></b:skin>
<b:if cond="data:blog.url == data:blog.homepageUrl">
<style type="text/css">
.post,   #blog-pager {display:none;}
</style>
</b:if>
<b:if cond="data:blog.url == data:blog.homepageUrl">
<style type="text/css">
body#layout .sidebar {display:inline;margin-top:200px;}
</style>
</b:if>
-->

Friday, August 31, 2012

The bus resistance of your #code

What is the bus resistance of your code? Read more here... http://www.nabinkm.com/2010/08/bus-resistance-of-code-or-program.html
% Long story short: comment your code!

Tuesday, May 1, 2012

Basic unix shell scripting tutorial revision

I wanted to revise shell scripting to my friend. Here are the list of commands that we used.

The kernel: agent
The shell: interface between the user and the kernel,
command line interpreter
bash
tcsh
etc
http://unixhelp.ed.ac.uk/shell/oview2.html

(show terminal)
You can scroll up and down with arrow key...

Tuesday, April 3, 2012

Assigning shortcut keys in Keynote: Mac

I needed to make a picture of neural network. The picture is too much work as it has a lot of connected blocks to be constructed.
So, in order to reduce the pain, I looked for shortcuts.

I wanted to assign shortcut keys to connect the blocks. So, I went to :

  • System preferences
  • Keyboard
  • Keyboard Shortcuts
  • Application Shortcuts
  • From there I had to browse the keynote and put the exact word. In this case "Connection Line", and assign the shortcut.
  • This method is true in general. So, if I wanted to assign any set of keyboard shortcut to any task, it should work. 
  • Profit!! :)



In order to connect the blocks, I would need to select two blocks, then press the shortcut key.
I wonder if there is a way to make connection between all selected blocks. (There seems to be none...)

Currently, If I have to connect two blocks, it is set to:
CMD+SHIFT+K

Tuesday, February 14, 2012

Screen Capture in Mac using Terminal

I figured, there should be some kind of terminal script out there which enables us to take the screen capture of the desktop. This will become real handy when we need to produce consistent screenshots for the Google Earth Images for my results. Furthermore, in order to crop it nicely, there is a code too!
http://usefulcodes.blogspot.com/2011/11/using-imagemagick-shell-command-to-crop.html
screencapture ~/Desktop/test.png