473,320 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Expected Value

How would I get the expected value out of this information. I have
tried many times to understand this but am unable to.

The function expectP(z) computes E(X) for the random variable
representing a sample over the probability generated by "pf" for the
set of discrete items [1,100000]. The constant c is needed so that the
probability sum to 1.0, as required by the definition of probability.
The function pf(r,c,x) returns the probability that item x will be
equal to a randomly chosen variable, denoted by P(x) or P(X=x) in
mathematical texts, where c is the constant mentioned above and r is
needed because we are considering a power law distribution.

The function expectP(z) computes E(X) with r=z, using pf(r,c,x) where x
ranges over the set of discrete items in [1,100000]

The program:

def norm(r):
"calculate normalization factor for a given exponent"
# the function for this distribution is P(x) = c*(x**-r)
# and the job of this norm function is to calculate c based
# on the range [1,10**5]
sum = 0.0
for i in range(1,1+10**5):
# final sum would be more accurate by summing from small values
# to large ones, but this is just a homework, so sum 1,2,..10**5
sum += float(i)**-r
return 1.0/sum

def pf(r,c,x):
"return a power-law probability for a given value"
# the function for this distribution is P(x) = c*(x**-r)
# where the constant c is such that it normalizes the distribution
return c*(float(x)**-r)

#--------- between these lines, define expectP() function
-----------------
#--------- end of expectP() definition
------------------------------------

def showExpectP(limit):
"display ExpectP(limit) by rounding down to nearest integer"
k = expectP(limit)
return int(k)

if __name__ == '__main__':
import doctest, sys
doctest.testmod(sys.modules[__name__])

Sep 11 '05 #1
1 5126
On Sat, 10 Sep 2005 17:50:06 -0700, George wrote:
How would I get the expected value out of this information. I have
tried many times to understand this but am unable to.


Do you have a specific Python problem here, or do you need help with the
maths? If Python, please tell us what your problem is. If your problem is
with the maths, then a statistics and/or probability forum is probably
going to be more useful to you.

If you are having a problem with the code, not the maths, I frequently
find that it helps to reduce the problem. Instead of calculating the
expectation of a discrete pdf with one hundred thousand values, start with
a toy problem: write code that calculates the expectation of a pdf with
only five values. That is small enough that you can experiment using the
interactive Python interpreter, and if need be calculate the correct
answer with paper and pencil.

You might also find it useful to read this:

http://www.catb.org/~esr/faqs/smart-questions.html
--
Steven.

Sep 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bill | last post by:
I call a function in my .js file like this: onClick="location.href='blank.html' + generateSearchStringFromForm('section')" where section is the name of my form. The function is defined as...
1
by: TAM | last post by:
Hi, I have a simple JavaScript code that ensures that all the form fields are filled and there is also a function that checks if the email is a valid address. For some reason IE is giving...
10
by: Steve Benson | last post by:
Our regular programmer moved on. I'm almost clueless in Javascript/ASP and got the job of adapting existing code. In the page below, everything works until I added the function checkIt() to...
3
by: undercups | last post by:
When I run page I immediatley get "Object expected" message and the tag <body onload="setfocus()" is highlighted. The error occurs in this snippet from within the script file function...
5
by: andy.herrera | last post by:
I'm getting this Error Message. Expected ';' Please Select One: <form name="form1"> <<------------ Error is here. <select name="selectTrans" onChange="If (this.value == 'checkout')...
1
by: Dean R. Henderson | last post by:
I setup FormsAuthentication on a couple websites where it has been working as expected for a long time. I used this code to setup the same type of authentication on a new website I am working on...
14
by: Tom.PesterDELETETHISSS | last post by:
Hi, I think this question requires an in depth understanding of how a browser cache works. I hope I can reach an expert here. I may have found a quirk in the asp.net documentation or I don't...
4
by: javatopia | last post by:
Hello, I am trying to show a Crystal Reports 10 Enterprise report in an ASP.NET page (C#). I can run the report via the admin console just fine. When I try to show the report, after setting up...
4
by: Kiyomi | last post by:
Hello, I am trying to replace my alert message box with a popup page. In my page behind,
9
by: Rohit | last post by:
I am trying to initialize an array whose initializers depend on value of Enums. I take enum and then decide the initializer value, so that even if enum value changes because of addition to list...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.