Saturday, February 6, 2016

I played a bit with population sample sizes to estimate population mean. Even for population=1M and sample size=100 people, mean estimate (SampleMean) is already within 1% from TrueMean. Thus, a run of the following script outputs:
"Population 1000000, Sample size 0.01%, Estimation error: 0.3218%"
TrueMean = 500
TrueSD = 50
PopulationSize <- 1000000
Population <- rnorm(PopulationSize, mean=TrueMean, sd=TrueSD)
 
# SamplePercent <- 0.01
# SampleSize <- PopulationSize * SamplePercent / 100.0
SampleSize <- 100
MySample <- sample(Population, size=SampleSize)
SampleMean <- mean(MySample)
SampleSD <- sd(MySample)
 
 
hist(MySample, breaks=10, prob=TRUE, col="#DDDDDD", ylim=c(0,0.009)) #, xlab="Sample", col="grey")
lines(density(Population), col="blue", lwd=1)
 
SDBounds <- c(SampleMean - SampleSD, SampleMean + SampleSD)
vlines <- c(TrueMean, SampleMean, SDBounds)
style <- c("dashed", "dotted", "solid", "solid")
legend_text <- c("TrueMean", "SampleMean", "SampleMean-SD", "SampleMean+SD")
my_colors = c("red", "blue", "pink")
my_colors[4] = my_colors[3]
 
for(i in 1:length(vlines)){
  abline(v=vlines[i], col=my_colors[i], lty=style[i], lwd=2)  
}
legend(x="topleft", legend=legend_text, col=my_colors, lty=c(1,1))
 
SampleMeanError <- TrueMean - SampleMean
 
printf <- function(...) invisible(print(sprintf(...)))
printf("Population %d, Sample size %.2f%%, Estimation error: %4.4f%%", 
       PopulationSize, SampleSize/PopulationSize * 100, 100.0 * SampleMeanError/TrueMean)

Monday, December 5, 2011

Tuesday, November 15, 2011

gcc assembly output and ndk

I've found a really helpful article on how to get nice assembly output with corresponding C code lines from gcc.
Also, here's a post on how to get gcc assembly output specifically while working with android ndk toolchain.

Tuesday, October 25, 2011

How to launch ndk-build from win32 eclipse

I'm now working on Android making jni shared libraries to speed up some image processing algorithms.

I was wondering how to have all the conveniences of Eclipse IDE running under Windows and normal compilation speed of GCC on Linux machine for building Android shared libraries for jni. Cygwin is just too damn slow, it takes ages to compile even a small-sized shared library.

Here's how to run ndk-build on a Linux build machine from the Eclipse IDE running on Windows. I'm assuming your Putty saved session is "Linux-build".

First, make sure you're able to login to linux machine through Putty without password: google://putty+passwordless. Make sure that you have your plink.exe in your Windows PATH environment variable. I'd recommend a very useful utility Path Editor.

Add a new make target in Eclipse: right-click on your project in Eclipse -> Make targets ->Create...
Enter the following command in the "Build Command" input text box:
plink.exe -load "Linux-build" "cd /home/denis/android/myproject/jni; source env.sh; ndk-build"


plink.exe here opens ssh session named "Linux-build" in Putty and executes several bash commands: goes to the jni directory, reads android ndk configuration variables from env.sh and launches the ndk-build script.
It might be useful to add clean command to Eclipse also:
plink.exe -load "Linux-build" "cd /home/denis/android/myproject/jni; source env.sh; ndk-build clean"


Here "Linux-build" is your Putty session name; myproject is the name of the jni project having jni directory inside. My env.sh looks like this:


# env.sh
export ANDROID=/home/denis/android
export ANDROID_SDK_ROOT=${ANDROID}/android-sdk-linux
export NDK=${ANDROID}/android-ndk-r6
export ANDROID_NDK_ROOT=${NDK}
#export TOOLCHAIN=${NDK}/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
export PATH=$PATH:${NDK}:${NDK}/tools
export ANDROID_API_LEVEL=android-5
export NDK_PROJECT_PATH=$ANDROID/myproject



I intentionally use android-ndk-r6 instead of android-ndk-r6b, because of the compilation problem

...arm-linux-androideabi/bin/ld.exe: crtbegin_so.o: No such file: No such file or directory collect2: ld returned 1 exit status

(see related Stackoverflow question)

Sunday, September 21, 2008

python game

Posted my old small project to google code seabatl. It is a demo game showing usage of wxWindows and xmp-rpc bindings in python. The demo was written in python utilizing Boa python IDE. Hope it would be useful or even fun to somebody!

Saturday, October 27, 2007

projecteuler.net

Project Euler in a web site providing set of interesting programming and math-related tasks.
Example problem looks like

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000

This problem could be easily solved with paper and pencil, but for other some programming skills are required:

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below one million

This web site also provides extended statistics of solved problems. You can check your score and compare it with other player scores. Cool point is that your score is being measure in percent "of genius" :)

Try this web site, I'm sure you'll experience many hours of math delight!