Question

Consider the following function that generates k Monte Carlo estimatives for an Integral with size n:

def MCExponencial(k, n):

sample=[]
values=[]
estimative=[]
for j in range(k):
    sample = [geradorExponencial(L, e1, e2) for i in range(n)] 
    values=[(math.exp(-L*e1) - math.exp(-L*e2)) * f(sample[i], a1, a2, a3, b1, b2,  b3, c)/func_exponencial(sample[i], L) for i in range(n)]
    estimative.append(mean(values))

return mean(estimativa), estimative

In my program, I do

n=10

mean, estimative = MCExponencial(100, n)

while p < 1/math.sqrt(100) * standardDeviation(estimative, mean):

    n = n+10
    mean, estimative = MCExponencial(100, n)

but I am getting the following error:

Traceback (most recent call last): File "C:\Users\MM\Desktop\Python\MonteCarlo.py", line 110, in mean, estimative = MCExponencial(100, n) File "C:\Users\MM\Desktop\Python\MonteCarlo.py", line 60, in MCExponencial estimative.append(mean(values)) TypeError: 'float' object is not callable

I don't know what I am doing wrong.

Ps: The error occurs at the 'while' iteration.

Thanks in advance!

Was it helpful?

Solution

You reused the name mean for the result of a computation, replacing the mean function you also needed. Name one of these things something else, or move the second code snippet into a function so its mean doesn't hide the global, or do something else to resolve the name conflict.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top