If a problem must be solved in deterministic time, what exactly does it mean.
I am beginning to learn more in depth ML and came across this problem
Write a function sample_x( ) to draw independent samples of a random variable with probability density function
p(x) = 6(1/4 - (x - 1/2)^2) for 0 <= x <= 1 OR 0 otherwise
Assume you have a function RNG( ) that returns independent floats uniformly distributed in [0,1]. Can you find a way of doing this that runs in a deterministic amount of time?
What does it mean to run it in a deterministic amount of time??
To understand what deterministic time is helps to understand what both deterministic time and stochastic time are.
stochastic time and deterministic time are two polar opposites.
EXAMPLE OF STOCHASTIC TIME
A program runs in "stochastic" time if how-long-the-program takes-to-run is probabilistic. For example:
An example of a stochastic algorithm would be trying to sell 10 bottles of wonder window cleaner by going door to door.
The number of homes you must ring the doorbell at before all 10 bottles of wonder window cleaner are sold is stochastic
The phrase "stochastic time" can almost always be replaced by the phrase "an uncertain amount of time".
EXAMPLE OF DETERMINISTIC TIME
A program runs in deterministic time if how much time the program requires is predictable and certain, and does not change so long as different inputs are all the same size as other inputs.
Suppose that I write a function which takes a list of people's names and my function capitalizes the first letter of each person's name.
The
capitalize_names()function runs in deterministic time.Thus, the
capitalize_names()function is NOT stochasticAdditional Notes
If you are expected to know what the phrases "stochastic time" and "deterministic time" mean then you will also be expected to understand what the following symbols and words mean:
O(n)O(n^p)O(2^n)What is "Linear Time"
Suppose again that you simply want to capitalize people names.
If the number of people's names to be capitalize is
n, and names are all less than 100 characters long, then the amount of time it takes our program ist*nwheretis the average number seconds per name.We do not know exactly how much time it is (maybe we require
t == 0.832nanoseconds per name).When talking about "linear time" it does not matter exactly how many nanoseconds are required per name.
Capitalizing names executes in "linear time"
"linear time" is also written as
O(n)O(n)and "linear time" mean the same thing, it is just that some people like mathematical looking symbols instead of Minglish (mathy-English).If we have to capitalize
npeoples names it will take us time equal to some number timesn.Suppose that you write two
for-loops:What does
to_piglatindo?Well...
That's what it does.
You might thing that the program runs on the order of
2*nWell... sort of yes and no.
For "linear time" constant coefficients do not matter.
nis O(n)2*nis O(n)4*nis O(n)5*nis O(n)500*nis O(n)9083389475838495848 * nis O(n)Also,
7*n + 36is on the order ofn"on the order of
n" is written asO(n).Simply delete constant terms like
5or971.10Note that if a computer program took a billion years to finish executing, then a billion and one years would not be much different.
That is, for very large values of
n,n + 1is basically the same asn.100,000,000 ≈ 100,000,001
What is "polynomial time"?
Sometimes, if we have
npeople to process, a computer will require0.686 nanosecondstimes9*n^5 + 5*n^2 + 82.For very large values of
n,+ 82does not matter.9*n^5 + 5*n^2 + 82becomes9*n^5 + 5*n^2For very large values of
n,n^5is like 99.999% ofn^5 + n^2.In the end,
9*n^5 + 5*n^2 + 82is "on the order ofn^5" which is also written asO(n^5)If the amount of time your code takes to finish is
O(n^5)andnis the number of peoples names you are processing, then your algorithm runs in polynomial timenis polynomialn^2is polynomialn^3is polynomialn^4is polynomialn^9002181028is polynomialnraised to any constant power greater than1is polynomialWhat about your question
It is a trick question.
IF I hand you a number
xcan you calculatep(x) = 6(1/4 - (x - 1/2)^2)in deterministic time?I sure hope so.
PYTHON!
That does not take much time to calculate. Not much time at all.
Technically,
x - 1/2might take more time to calculate ifx == 0.9374923than ifx == 0.2If
xis output from a random number generator, then how much timeprequires to execute might be stochastic instead of deterministicHowever, it is silly to say that
p()is stochastic.Whoever wrote that question probably lives in an ivory tower and will never write a self-documenting variable name in their entire life. Instead of "
surface_area" they will write "a".Also, they will use all global variables inside of one massive function which is more than 3,000 lines long.
LATEX!
Boy, wouldn't it be nice if you could write "
1/4" instead of "\frac{1}{4}"?