fast binomial random numbers

I hate to ask this, because I'm asking someone to do my work for me. Could someone help me write a fast binomial random number generator?
I have written this:
function X = binom(N,p)
X = sum(rand(1,N)<p);
end
which is about 3x faster than the built-in vectorized version.
I would like to write a compiled c version, but I basically know nothing about c.
Thanks

답변 (2개)

Paulo Silva
Paulo Silva 2011년 8월 3일

1 개 추천

Try using the GUI from
deploytool
if you have it installed.
or just
mcc -m binom.m

댓글 수: 5

Ariel Balter
Ariel Balter 2011년 8월 3일
Darn, I don't seem to have any installed compilers :( I'll need to start there.
Thanks for the answer!
Paulo Silva
Paulo Silva 2011년 8월 3일
I think you have to change your code before compiling, change it to this
function binom(N,p)
sum(rand(1,N)<p)
end
Compiled functions can't have outputs besides the ones like you have at MATLAB command line (notice the absence of the ; on the second line) and commands link the disp and fprintf. You must capture the outputs of the functions, unix style (>).
Ariel Balter
Ariel Balter 2011년 8월 3일
I installed lcc win32, but I can't seem to get Matlab to see it. Google hasn't helped much. I'm assuming there is some configuration file somewhere where I put the path.
Paulo Silva
Paulo Silva 2011년 8월 3일
sorry Ariel, I have no experience compiling code with MATLAB
Paulo Silva
Paulo Silva 2011년 8월 3일
The compiler configuration is invoked by
mbuild -setup

댓글을 달려면 로그인하십시오.

Walter Roberson
Walter Roberson 2011년 8월 3일

0 개 추천

If you cannot get MATLAB to see lcc win32, then you may be using the 64 bit version of MATLAB. See here for the 2011a Windows 64 list. Please note that there are two pieces of software to install for Windows 64: be sure to read the notes!

댓글 수: 3

Ariel Balter
Ariel Balter 2011년 8월 3일
Thanks Walter. I tried installing those. But still no luck:
>> mbuild -setup
Please choose your compiler for building standalone MATLAB applications:
Would you like mbuild to locate installed compilers [y]/n? y
Select a compiler:
[1] Microsoft Visual C++ 2008 Express in C:\Program Files (x86)\Microsoft Visual Studio 9.0
[0] None
Compiler: 1
Please verify your choices:
Compiler: Microsoft Visual C++ 2008 Express
Location: C:\Program Files (x86)\Microsoft Visual Studio 9.0
Are these correct [y]/n? y
*****************************************************************************
Error: Could not find the 64-bit compiler. This may indicate that the
"X64 Compilers and Tools" or the Microsoft Windows Software
Development Kit (SDK) is not installed. To build 64-bit binaries,
Microsoft Visual C++ 2008 Express Edition requires that these two
packages be properly installed.
*****************************************************************************
Trying to update options file: C:\Users\abalter\AppData\Roaming\MathWorks\MATLAB\R2010a\compopts.bat
From template: C:\PROGRA~1\MATLAB\R2010a\bin\win64\mbuildopts\msvc90freecompp.bat
Done . . .
>>
Walter Roberson
Walter Roberson 2011년 8월 3일
I did say to read the notes. The link I posted tells you specifically what else you have to install. See in particular notes #1 and #3.
Ariel Balter
Ariel Balter 2011년 8월 3일
I am running x64, so that may explain the lcc problem. Although, there appears to be a x64 version of lcc.
I tried installing Visual C++ 2010 Express and Microsoft Windows SDK for Windows 7 and .NET Framework 4. I never got asked for an option for x64. Seems like maybe I need visual studio, which is not free.
I appreciate all the help. But, this is getting way beyond the scope of compiling my one line program!
Sounds like the problem starts with my Matlab not having the default compiler.
Oh well.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Package MATLAB Functions에 대해 자세히 알아보기

질문:

2011년 8월 3일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by