Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6676055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:56:21+00:00 2026-05-26T03:56:21+00:00

I need to code a Maximum Likelihood Estimator to estimate the mean and variance

  • 0

I need to code a Maximum Likelihood Estimator to estimate the mean and variance of some toy data. I have a vector with 100 samples, created with numpy.random.randn(100). The data should have zero mean and unit variance Gaussian distribution.

I checked Wikipedia and some extra sources, but I am a little bit confused since I don’t have a statistics background.

Is there any pseudo code for a maximum likelihood estimator? I get the intuition of MLE but I cannot figure out where to start coding.

Wiki says taking argmax of log-likelihood. What I understand is: I need to calculate log-likelihood by using different parameters and then I’ll take the parameters which gave the maximum probability. What I don’t get is: where will I find the parameters in the first place? If I randomly try different mean & variance to get a high probability, when should I stop trying?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:56:21+00:00Added an answer on May 26, 2026 at 3:56 am

    If you do maximum likelihood calculations, the first step you need to take is the following: Assume a distribution that depends on some parameters. Since you generate your data (you even know your parameters), you “tell” your program to assume Gaussian distribution. However, you don’t tell your program your parameters (0 and 1), but you leave them unknown a priori and compute them afterwards.

    Now, you have your sample vector (let’s call it x, its elements are x[0] to x[100]) and you have to process it. To do so, you have to compute the following (f denotes the probability density function of the Gaussian distribution):

    f(x[0]) * ... * f(x[100])
    

    As you can see in my given link, f employs two parameters (the greek letters µ and σ). You now have to calculate the values for µ and σ in a way such that f(x[0]) * ... * f(x[100]) takes the maximum possible value.

    When you’ve done that, µ is your maximum likelihood value for the mean, and σ is the maximum likelihood value for standard deviation.

    Note that I don’t explicitly tell you how to compute the values for µ and σ, since this is a quite mathematical procedure I don’t have at hand (and probably I would not understand it); I just tell you the technique to get the values, which can be applied to any other distributions as well.

    Since you want to maximize the original term, you can “simply” maximize the logarithm of the original term – this saves you from dealing with all these products, and transforms the original term into a sum with some summands.

    If you really want to calculate it, you can do some simplifications that lead to the following term (hope I didn’t mess up anything):

    enter image description here

    Now, you have to find values for µ and σ such that the above beast is maximal. Doing that is a very nontrivial task called nonlinear optimization.

    One simplification you could try is the following: Fix one parameter and try to calculate the other. This saves you from dealing with two variables at the same time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some code to download a pdf file. what i mean is normaly
I need some code to zoom an image when i mouse over that image,
I have the following code, which I'm trying to only allow a maximum of
I have multiple sets of code I need to run in Access 2007 and
I need help in troubleshooting my code. I have 3 classes. Class 1 is
Right now in Spring security I have this code: <session-management> <concurrency-control max-sessions=1 error-if-maximum-exceeded=true />
i need some perl code for the following problem. thanks in advance for your
Please forgive my attempts at necromancy, but I actually need to write some code
I have written some matlab code for image analysis that searches for clusters in
I'm in need of some pointing in the right direction here... I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.