[Report] machine learning ---- experiment Experiment two parameter estimation (maximum likelihood estimation)

Disclaimer: This article is a blogger original article, reproduced, please indicate the source https://blog.csdn.net/C2681595858/article/details/84191828

First, the theoretical knowledge

  • Maximum Likelihood Estimate: making the maximum probability sample appears parameter estimation.
  • For the normal distribution, the sample mean is its parameters m \ mu maximum likelihood estimation. 1 / n k = 1 n ( x k μ ) ( x k μ ) T 1/n*\sum_{k=1}^n(x_k - \mu)(x_k-\mu)^T his parameter σ 2 \sigma^2 maximum likelihood estimate

Second, the experimental environment

  • linux system

  • g ++ compiler, you need 6.3.0 or later

  • c ++ language

  • Can be compiled, you need to use the windows system command line vs2017, nmake command compiler, g ++ compiler version 6.3.0 or higher, but you need to modify the Makefile in the win, rm will delete command to be replaced by del, while the executable file main modification is main.exe,

  • Using experimental data in English textbooks
    Here Insert Picture Description

Second, the experimental process

  • The first experiment conducted on the basis of the above, it has been Matrix Storage category and class, and the class of Bayes many functions can be used directly after slightly modified, so it is relatively simple to do. The job description for the following:
  1. The main functionPETest.cpp
	PE pe;
	pe.setSampleFile("a.txt");
	pe.setClassSize(3);
	pe.setSampleSize(10);
	pe.setVectorLen(1);

	pe.estimate();
	cout<<"ch3_1_a:\n";
	for(int counter = 1; counter <= 3; counter++)
	{
		cout<<"clo "<<counter<<" means :"<<pe.getMean(counter).matrixToFloat()
		<<" variance :"<<pe.getSigma(counter).matrixToFloat()<<endl;
	}

①. The above process is part of the process of a small problem, new objects, where the sample data set file pe.setSampleFile("a.txt");, is provided to estimate parameters of several groups pe.setClassSize(3);, each provided with a number of samples pe.setSampleSize(10);, each sample set dimension pe.setVectorLen(1);of these parameters is provided before each calculation must be set, unless he and the last set is the same as
②. estimate pe.estimate();, obtain estimation results pe.getMean(counter).matrixToFloat();getMean () retrieves μ \ mu estimated value, counter obtaining an estimated value which represents the group. matrixToFloat () will be converted to a floating matrix, due to the one-dimensional sample, the final estimate of his value is one-dimensional, but it exists in the form of a matrix, so we can convert him into a float. Of course, you can not convert directly printMatrix () will print it out.
③. B and c small problem small problem approach is the same, just different sample dimensions, not to get into a float after the estimated results, and to use printMatrix () to print out.

pe.setSampleFile("b.txt");
	pe.setClassSize(3);
	pe.setSampleSize(10);
	pe.setVectorLen(2);

	pe.estimate();
	cout<<"\nch3_1_b:\n";
	for(int counter = 1; counter <= 3; counter++)
	{
		cout<<"pair "<<counter<<"\nmeans :";
		pe.getMean(counter).printMatrix();
		cout<<"variance :";
		pe.getSigma(counter).printMatrix();
	}

	pe.setSampleFile("c.txt");
	pe.setClassSize(1);
	pe.setSampleSize(10);
	pe.setVectorLen(3);

	pe.estimate();
	cout<<"\nch3_1_c:\n";
	cout<<"means :";
	pe.getMean(1).printMatrix();
	cout<<"variance :";
	pe.getSigma(1).printMatrix();

④. D small problems,

Third, the experimental results

a small problem results

Here Insert Picture Description

b small problem results

Here Insert Picture Description

c small problem results

Here Insert Picture Description

d small problem results

Here Insert Picture Description

e small problem

  • The above four questions, the same arguments as long as they sample data μ \ mu estimated value is the same, because no matter which one, they are calculated on the average of each dimension, a dimension not only they, like the other are the same.

f small problem

  • For the estimated covariance, using the first three questions 1 / n k = 1 n ( x k μ ) ( x k μ ) T 1/n*\sum_{k=1}^n(x_k - \mu)(x_k-\mu)^T , and the fourth question, because it is a diagonal matrix, indicating that his estimate is 1 / n k = 1 n ( x k μ ) 2 1/n*\sum_{k=1}^n(x_k - \mu)^2 , that is, the variance of each dimension are seeking, you can. Such results immediately find out the foregoing method is a non-diagonal elements of the result set to zero.

Fourth, the difficulties encountered

  • Is working on the basis of the last to do so is relatively simple. Did not encounter too much difficulty, the most important is the last job in the vs2017 do this go on linux, linux done before on the subject compiled up to three files, and the files are more and for linux the Makefile written not very familiar with, resulting in learning to write Makefile spent more time on it. Learn to write Makefile after a very short summary.

Guess you like

Origin blog.csdn.net/C2681595858/article/details/84191828