Wednesday, January 28, 2009

VirtualBox: discard snapshot

I have always been confused by naming of commands available for snapshots in VirtualBox. Especially, what is the difference between discard snapshot and discard current snapshot and state. For that reason, I made small experiment. I made new virtual machine (without any snapshots) and I performed the following operations:
  1. Make folder named made_before_a
  2. Take snapshot named a
  3. Make folder made_before_b
  4. Take snapshot named b
  5. Make folder made_before_c
  6. Take snapshot named c
  7. Remove all dirs and save state of machine
As a result, the my snapshots were as follows:At this point, I had three possibilities:I wanted to see what would happen if I had performed 'discard current snapshot and state' or 'revert to current snapshot'. Remember that in point 7 above, I removed all my folders, therefore Current State (changed) refers to the guest OS without the folders (i.e. without made_before_a, made_before_b and made_before_c).

Discard current snapshot and state

This option removed snapshot c and the Current State (changed). After starting my guest OA I had only folders made_before_a and made_before_b!

Revert to current snapshot

After this my guest os was in a state at which snapshot c had been taken (i.e. folders made_before_a, made_before_b and made_before_c were restored)

Discard snapshot

Final option is discard snapshot.This option removes the snapshots but not the current state. In other words, I could remove all my snapshots (named a,b, and c) and I was left only with my current state (i.e. no folders)!

Conclusions

  • Revert to current snapshot - it moves guest os to the state it was when the snapshot was made. All changes made since the snapshot creation time will be lost.
  • Discard current snapshot and state - it moves guest os to the state of the previous snapshot. Current snapshot and all changes are lost. In my example, performing operation 'discard current snapshot and state' on snapshot c, moved my systems to state of snapshot b.
  • Discard snapshot- it removes a snapshot, but not the changes made since the creation of the snapshot.

Hope it will be useful and hope I did not make any mistake (apart from my English :-)).

Alternative source of info

This topic was previously discussed. Also, VirtualBox documentation might be handy.

Tuesday, January 27, 2009

Vim: setting background color

:highlight Normal ctermbg=black ctermfg=whiteTab size to 4:set tabstop=4
:set ts=4
Specify syntaxset syntax=html

Matlab: Working with text data files using Perl

Previously I wrote two posts about this:
Although, these posts were written a while ago, for Matlab 2007a, they might be still useful.

Matlab: hash tables

Unfortunately, Matlab does not have hash table functionality by itself. However, Matlab is based on Java, and provides programing interface to java classes. Consequently, it is possible to use Hash tables from Java!

Previously, I described one possible solution to that problem using Java hash tables. Although, it was written a while ago, for Matlab 2007a, it still should be useful.

Matlab: making Bland and Altman plots

To do the Bland and Altman plot, we have to compute the differences between the instruments and the mean of both instruments for all the paired values.

For instanceA=[749 583 740 235 735 971 867 86 366 369]
B=[685 598 789 368 206 87 772 206 388 552]
blandAltmanPlot(A,B);



function blandAltmanPlot(A,B)
%reference: Y H Chan, Biostatistics 104:
%Correlational Analysis,
%Singapore Med J 2003 Vol 44(12) : 614-619

meanAB=(A+B)./2;
difff=A-B;
meanDiff=mean(difff);
stdDiff=std(difff);

meanp2D=meanDiff+2*stdDiff;
meanm2D=meanDiff-2*stdDiff;
n=length(difff);
minD=min(meanAB)-0.1;
maxD=max(meanAB)+0.1;

figure;
plot(meanAB,difff,'.k')
hold on;
plot([minD; maxD],ones(1,2)*meanp2D,'--k');
text(minD+0.01,meanp2D+0.01,'Mean + 2*SD');
hold on;
plot([minD; maxD],ones(1,2)*meanm2D,'--k');
text(minD+0.01,meanm2D+0.01,'Mean - 2*SD');
hold on;
plot([minD; maxD],ones(1,2)*meanDiff,'--k');
xlim([minD maxD]);
xlabel('(A+B)/2');
ylabel('A-B');

The excel spreadsheet with the example of Bland and Altman plots is here. These two programs calculated the same statistics.

Excel: Confidence interval

You can use both t and z distribution to create confidence interval around sample mean. You use t when the sample size is less than 30 (n<30).
or

Hence with 0.05 (95%) level of confidence our interval is: mean±interval i.e. 182.4±20.719 and 45±4.6924, respectively.
For illustration only there is also z statistic interval shown (19.4 and 4.39 respectively). As can be seen, using z instead of t makes the interval to be smaller.

If one wants to use for example, 0.01 (99%) level of confidence one must use TINV(0.01,n-1) for t distribution and CONFIDENCE(0.01,STDEV,n) for z distribution.
In our case if we use 0.01 we get interval for t distribution equal to 28.3207 for the first example and 6.4141 for the second example. Interval for z is 25.50 and 5.77 respectively.

Briefly:Interval using z distribution is narrower
than for t distribution

The same but in R:
>X1 <- scan()
1: 205 179 185 210 128 145 177 117 221 159 205 128 165 180 198 158 132 283 269 204
> a <- mean(X1)
> s <- sd(X1)
> n <- length(X1)
> errZ <- qnorm(0.975)*s/sqrt(n)
> errT <- qt(0.975,df=n-1)*s/sqrt(n)

Excel: Paired t-test

I always forget what must be the value of P must be to reject or not to reject the null hypothesis in paired t-test. So lets explain by the example.H0 - null hypothesis - there is no
significant difference
between method A and B
H1 - alternative hypothesis - there is difference
(two tail test)
For example [with 5% (a=0.05) level of significance ]:

Based on the above results I can say that: "since P=0.009103483 and this is lover than a=0.05 (P<0.05), I can claim that":I'm 95% (a=0.05) sure that there is significant
difference between A and B, because (P<0.05).
On the other hand, we can have:

In this case P=0.649507752, and I can claim that:I'm 95% (a=0.05) sure that there is no significant
difference between A and B, because (P>0.05).
Above paired t-test was performed in Excel.

Matlab: Coefficient of correlation and determination

Both coefficients are used to measure the relationship between two variables. For example lets assume that we want to check whether there is a correlation between the size of the store (in thousands of square feet) (X variable) and annual sales (in million dollars) (Y variable):

X=[1.7 1.6 2.8 5.6 1.3 2.2 1.3 1.1 3.2 1.5 5.2 4.6 5.8 3.0]
Y=[3.7 3.9 6.7 9.5 3.4 5.6 3.7 2.7 5.5 2.9 10.7 7.6 11.8 4.1]

Using Matlab/Octave we can calculate Coefficient of correlation (r) and Coefficient of determination (r2) in a following way:

c=corrcoef([X' Y']);
r=c(1,2);
r2=r^2;

In our example we get r=0.95088 and r2=0.90418.
Now what does it mean? Coefficient of determination measures the proportion of variation in Y that is explained by the X. In other words, we can say that 90.4% of the change in Y can be explained by the change in X. In our case we can conclude that 90.4% of change in annual sales is explained by the change in store size. The rest (9.6%) depends on the other factors like localization, staff, management, etc.

Bellow scatter plot of X and Y:



The above scatter plot can be generated in Matlab/Octave by:
figure;
plot(X,Y,'+r');
title('Scatter plot');

Monday, January 26, 2009

VirtualBox: port forwarding

My host: windows XP
My guest: ubuntu 8.04.1

To redirect all connections from port 80 (www server) of the host machine to port 80 of theguest operating system being I used the following commands in windows xp console: VBoxManage setextradata "ubuntu-server" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/Apache/Protocol" TCP
VBoxManage setextradata "ubuntu-server" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/Apache/GuestPort" 80
VBoxManage setextradata "ubuntu-server" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/Apache/HostPort" 80

"Apache" is an arbitrary name, and "ubuntu-server" is the name of my virtual machine with Ubuntu.

Ports can be redirected only when VirtualBox is turned off.

Matlab: Compile m file in Matlab 7.4 on Mac X

I tried to compile one simple m file - get_pad_load.m (see previous post).
First, when I tried to use mcc -m test.m I got error dyld: Library not loaded: ../../bin/maci/libmwcompiler.dylib
Referenced from: /Applications/MATLAB74/bin/maci/mcc
Reason: image not found
Trace/BPT trap


To repair it I indicated paths to missing libraries export DYLD_LIBRARY_PATH="/Applications/MATLAB74/bin/maci:/Applications/MATLAB74/sys/os/maci"
This worked. I was able to compile my file, and run it from console as an executable.