Wednesday, August 22, 2012
Monday, May 14, 2012
Finding intersection of two regression lines using R
Suppose m1 and m2 are 2 regression models created using lm() in R, then try
cm <- rbind(coef(m1),coef(m2)) # Coefficient matrix
c(-solve(cbind(cm[,2],-1)) %*% cm[,1])
which would give you the point of intersection.
Tuesday, March 6, 2012
protect(): protection stack overflow
Monday, March 5, 2012
Securing Mac's Single User Mode
Monday, February 27, 2012
Backup failed hard disk data on Mac
I recently encountered a Mac that would not boot properly. However, it did boot into single-user mode and allowed access to the file system via the command line interface. Since I had recently purchased an external, portable USB drive, I wanted to offload my important files to the USB drive before reformatting and reinstalling a fresh system. Here are the steps I took:
- Connect USB drive to Mac and boot into single-user mode (cmd-s)
- At prompt type:
/sbin/mount -uw /
then hit return
- At prompt type:
/sbin/fsck -fy
then hit return
- At prompt type:
ls /Volumes
then hit return. This should provide a list of mounted volumes. It’s likely that your USB drive will not show. If this is true, then you will need to create a sharepoint in the /Volumes directory. You do this by using this command (in this case, we are creating a directory called “usb”):
mkdir /Volumes/usb
then hit return
- Next we need to identify the disk number of the USB drive. This is done with this command:
ls /dev/disk*
then hit return. The system will list the disks like this:
In most cases, the USB drive will be the last disk number listed (in this case: disk0s3).
- Now, to mount this disk to your sharepoint, type the following command:
/sbin/mount_msdos /dev/disk0s3 /Volumes/usb
then hit return. NOTE: In this case, we are using disk0s3 since it is the last listed. Yours will likely be different. Also note that my Western Digital USB drive uses the msdos format. Yours may not.
- If this is mounted properly, you will be able to see the contents of your USB drive by using this command:
ls /Volumes/usb
then hit return
- If you have successfully mounted the USB drive, you may now copy files using thecpcommand. (In this example, I will copy a file named “testfile” and assume the Mac has a volume named MacHardDrive.) For example:
cp /Volumes/MacHardDrive/testfile /Volumes/usb/
then hit return.
You can use this method to copy entire directories from your ailing Mac to the USB drive. In my case, I copied the entire user account directory over to the USB drive so I would keep settings, mail, music, pictures, and files in my Documents directory.
Monday, August 22, 2011
Rapid Miner and R extension problem on Mac solved
Enter the following in either /etc/profile or ~/.bash_profile
PATH=$PATH:/Library/Frameworks/R.framework/Versions/2.12/Resources/bin:/Library/Frameworks/R.framework/Versions/2.12/Resources/library/rJava/jri
R_HOME=/Library/Frameworks/R.framework/Versions/2.12/Resources
export R_HOME
In the /Library/Frameworks/R.framework/Versions/2.12/Resources/library/rJava/jri/ folder, do the following:
1) Rename the JRI.jar to JRI.jar.original
2) make a copy of the libjri.jnilib and rename this copy to JRI.jar
This is because, by default it looks for JRI.jar
Once rapidminer is started, in the R preferences, change the rapid.miner.r.native lib file back to /Library/Frameworks/R.framework/Versions/2.12/Resources/library/rJava/jri/libjri.jnilib
Delete the JRI.jar (copied from libjri.jnilib)
Rename back JRI.jar.original to JRI.jar.
Wednesday, August 3, 2011
Download file from terminal MAC OSX versus Linux
curl -O ftp://abc.tar.gz &
On Linux, use:
wget ftp://abc.tar.gz &
Wednesday, June 15, 2011
Tuesday, June 7, 2011
receiver operating characteristic (roc) and area under the curve (AUC) in matlab
function auc=areaundercurve(FPR,TPR);
% given true positive rate and false positive rate calculates the area under the curve
% true positive are on the y-axis and false positives on the x-axis
% sum rectangular area between all points
% example: auc=areaundercurve(FPR,TPR);
[x2,inds]=sort(FPR);
x2=[x2,1]; % the trick is in inventing a last point 1,1
y2=TPR(inds);
y2=[y2,1];
xdiff=diff(x2);
xdiff=[x2(1),xdiff];
auc1=sum(y2.*xdiff); % upper point area
auc2=sum([0,y2([1:end-1])].*xdiff); % lower point area
auc=mean([auc1,auc2]);
function [TP,FP]=getfptp(T,Y)
Y(Y>=0)=1;Y(Y<0)=-1; % target class (positive) is 1
TP=sum( ( (Y==1) + (T==1) )==2 );
FN=sum( ( (Y==-1) + (T==1) )==2 );
FP=sum( ( (Y==1) + (T==-1) )==2 );
TN=sum( ( (Y==-1) + (T==-1) )==2 );
TP=TP/(TP+FN);
FP=FP/(FP+TN);
end
Saturday, June 4, 2011
How to read external drives in both Mac and Windows
Tuesday, May 31, 2011
R mean and std plot
First create the following function:
error.bar <- function(x, y, upper, lower=upper, length=0.1,...){
if(length(x) != length(y) | length(y) !=length(lower) | length(lower) != length(upper))
stop("vectors must be same length")
arrows(x,y+upper, x, y-lower, angle=90, code=3, length=length, ...)
}
Then try the example below:
y <- rnorm(500, mean=1)
y <- matrix(y,100,5)
y.means <- apply(y,2,mean)
y.sd <- apply(y,2,sd)
barx <- barplot(y.means, names.arg=1:5,ylim=c(0,1.5), col="blue", axis.lty=1, xlab="Replicates", ylab="Value (arbitrary units)")
error.bar(barx,y.means, 1.96*y.sd/10)
Sunday, May 8, 2011
Solving R error using kfilter matrix(NA, ss$n, ss$p) : non-numeric matrix extent
example
the following works:
m2=NULL
m2 <- SS( t(t(ts(runif(100, 5.0, 7.5)))))
m2.n=1;
m2.p=1;
m2.f <- kfilter(m2)
plot(m2$y)
lines(m2$y,lty=2,col="green")
lines(m2.f$m,lty=2,col="red")
but dont forget to first install the sspir package using
install.packages("sspir")
and loading the library using
library(sspir)
Thursday, May 5, 2011
Solving R error "tar: Failed to set default locale" in Mac OS X
defaults write org.R-project.R force.LANG en_US.UTF-8
and restart R
Tuesday, May 3, 2011
Virtual Box Notes
Installing Octave and Gnuplot in Mac OS X
There are some possibilities to install Gnuplot on Mac OS X, none of them is “official”, since the Gnuplot project doesn’t provide binaries for Mac OS X. It’s actually quite easy to configure and compile Gnuplot (i.e. ./configure; make; make install), but some terminals are not built due to missing dependencies and this makes Gnuplot less powerful.
There is some information on the web about running Gnuplot on Mac OS X already (http://lee-phillips.org/info/Macintosh/gnuplot.html , http://maba.wordpress.com/2006/08/02/scientific-plotting-on-mac-os-x-using-gnuplot-and-plot/ ) and there is also http://www.finkproject.org/ and http://www.macports.org/ but there is IMO an easier way (though it still needs some work): there is a Gnuplot installer provided by Octave! Here are the instructions:
Download Octave for Mac OS X from the Octaveforge homepage (latest version at time of writing was 3.2.2).
Open the downloaded dmg file and browse to the Extras folder
Open gnuplot-4.2.5-i386.dmg and copy Gnuplot.app to your Applications folder (or anywhere else).
Alternatively you could directly download the gnuplot-4.2.5-i386.dmg from here.
That’s about it. Or at least it should be. Usually you just open Gnuplot.app and start plotting. But unfortunately the default aquaterm terminal doesn’t work for me always (on one Mac it did, on another it didn’t – maybe Aquaterm shouldn’t be installed before). So we need to hack Gnuplot.app so that X11 (which is also more powerful) becomes the default terminal.
Right click on Gnuplot.app and choose “Show Package Contents”.
Browse to Contents/Resources and edit “script” with your favorite text editor
Replace both lines do script (“exec ‘${ROOT}/bin/gnuplot’”) with do script (“GNUTERM=x11 exec ‘${ROOT}/bin/gnuplot’”) . X11 will then be the default terminal.
You might also want to have gnuplot available in your usual terminal session. This is also no problem. Just run the following command in your terminal
ln -s /Applications/Gnuplot.app/Contents/Resources/bin/gnuplot /Users/username/bin/gnuplot
where username is your user name. /Users/username/bin must be added to the path, so that Gnuplot works form everywhere, e.g. you could add the following to the /Users/username/.profile file
# add binary directory of .localexport PATH=$HOME/.local/bin:$PATH
# add bin directory of home directory
export PATH=$HOME/bin:$PATH
If you run gnuplot from the Terminal.app again the Aquaterm terminal is the default. This can be changed by adding
# use x11 as the default Gnuplot terminal
export GNUTERM=x11
to your .profile file.
Tuesday, December 28, 2010
Monday, October 18, 2010
Linux memory and 64bit useful commands
ulimit
if get error like Program received signal SIGSEGV, Segmentation fault.
0x000000380ee62184 in fwrite () from /lib64/libc.so.6
using gdb for non root user but works fine for root user on
RHEL 5.4
try
export MALLOC_CHECK_=3
and recompile the program with gcc
That should solve the problem
Sunday, September 6, 2009
Use GMail SMTP to send mail in PHP
<?php include("class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPAuth = true; // enable SMTP authentication $mail->SMTPSecure = "ssl"; // use ssl $mail->Host = "smtp.gmail.com"; // GMAIL's SMTP server $mail->Port = 465; // SMTP port used by GMAIL server $mail->Username = "your_gmail_account@gmail.com"; // GMAIL username $mail->Password = "password"; // GMAIL password $mail->AddReplyTo("other_email@hotmail.com","FirstName LastName"); // Reply email address $mail->From = "your_gmail_account@gmail.com"; $mail->FromName = "FirstName LastName"; // Name to appear once the email is sent $mail->Subject = "Subject of the email"; // Email's subject //$mail->Body = "Hello World,<br />This is the HTML BODY<br />"; //HTML Body $mail->AltBody = "This is a test email"; // optional, comment out and test $mail->WordWrap = 50; // set word wrap $mail->MsgHTML($body); // [optional] Send body email as HTML $mail->AddAddress("abc@email.com", "Test email"); // email address of recipient //$mail->AddAttachment("files/files.zip"); // [optional] attachment $mail->IsHTML(true); // [optional] send as HTML if(!$mail->Send()) echo "Mailer Error: " . $mail->ErrorInfo; else echo "Message sent!"; ?>
Friday, August 14, 2009
Modify PMapper Map File from url
Documentation on PHP MapScript
Use the following to get capabilities on a WMS
http://SERVICE-ENDPOINT/?request=GetCapabilities&service=WMS&version=DESIRED-VERSION
Friday, July 24, 2009
Printing Google Visualization
The other way is to use the following:
Website Thumb Generator can be used to create website thumbnails for your needs, or start your own website thumbnail generation service.
Requirements:
Windows hosting
PHP GD library (installed on most hostings)
Permissions to execute third-party applications (i.e. exe files)
Permissions to execute Internet Explorer
How it works:
Website Thumbnail Generator checks if it already has website image in the cache, and shows it in the browser.
If no cached image then IECapt would be run from the script.
IECapt would run Internet Explorer, grab full sized website screenshot from it, and save image into the folder you specified in script settings.
Then Website Thumbnail Generator would resize image, and show it in the browser.
Installation:
Download IECapt from http://iecapt.sourceforge.net Place it in some folder on your server.
Download Website Thumbnail Generator using link below, and unzip it to the same folder.
Update webthumb.php with your settings for thumbnails folder, cache time, default thumbnail size, etc.
Sample usage:
webthumb.php?url=http://www.microsoft.com
webthumb.php?url=http://www.thumbnails.com&x=150&y=150
Website Thumbnail Generator
