Gaussian Mixture Regression is basically Multivariate normal distribution with Conditional distribution. The more about the theory could be found at [1], [2], [3], [4]. For this work, I have added the functionality of adding Gaussian Mixture Regression to this project on the GitHub by forking the main project, my forked project can be download at here Github
The main changes are:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
float computeNormalDistributionPDF(Eigen::VectorXf X, Eigen::VectorXf mean, Eigen::MatrixXf covariance) { float nominator, denominator,tmp; Eigen::MatrixXf tmp_nominator_matrixXf; tmp_nominator_matrixXf=( X.transpose()-mean.transpose() ) * covariance.inverse() * (X-mean) ; tmp=-0.5*tmp_nominator_matrixXf(0,0); nominator=std::exp (tmp); int k=X.rows(); tmp=std::pow(2*M_PI,k) *covariance.determinant(); denominator=std::pow( tmp, 0.5 ); return (nominator/denominator); } //Xi is 2xn matrix, the first column is t and the second column is s //means is a c++ vector of size k which contains eigen vector of size 2 void doRegression(Eigen::MatrixXf xi, const std::vector<Eigen::VectorXf> means, const std::vector<float> weights , const std::vector<Eigen::MatrixXf> covariances) { Eigen::VectorXf X; Eigen::VectorXf mean; Eigen::MatrixXf covariance; Eigen::MatrixXf out_xi; out_xi.resize(xi.rows() ,xi.cols()); out_xi=Eigen::MatrixXf::Zero(xi.rows(), xi.cols()); //equation 10 float xi_hat_s_k, mu_s_k,mu_t_k,sigma_st_k,inv_sigma_t_k,sigma_hat_s_k, sigma_s_k, sigma_t_k,sigma_ts_k, xi_t, beta_k,xi_hat_s,beta_k_sum, beta_k_xi_hat_s_k_sum; for(std::size_t i=0;i<xi.rows();i++) { beta_k_sum=0; beta_k_xi_hat_s_k_sum=0; for(std::size_t k=0;k<means.size();k++) { mu_t_k=means.at(k)(0); mu_s_k=means.at(k)(1); sigma_st_k=covariances.at(k)(1,0); sigma_t_k=covariances.at(k)(0,0); inv_sigma_t_k=1/sigma_t_k; sigma_s_k=covariances.at(k)(1,1); sigma_ts_k=covariances.at(k)(0,1); xi_t=xi(i,0); xi_hat_s_k=mu_s_k+ sigma_st_k*inv_sigma_t_k*(xi_t -mu_t_k); sigma_hat_s_k=sigma_s_k -sigma_st_k*inv_sigma_t_k*sigma_ts_k; //equation 11 X.resize(1,1); mean.resize(1,1); covariance.resize(1,1); X<<xi_t; mean<<mu_t_k; covariance<<sigma_t_k; beta_k=weights.at(k) * computeNormalDistributionPDF(X, mean,covariance); beta_k_sum=beta_k_sum+beta_k; xi_hat_s=beta_k*xi_hat_s_k; beta_k_xi_hat_s_k_sum=beta_k_xi_hat_s_k_sum+xi_hat_s; } out_xi(i,1)=beta_k_xi_hat_s_k_sum/beta_k_sum; } std::cout<< "-------------------------------------" <<std::endl; // std::cout<< "out_xi:" <<out_xi <<std::endl; // std::cout<< "out_xi.rows():" <<out_xi.rows() <<std::endl; // std::cout<< "out_xi.cols():" <<out_xi.cols() <<std::endl; std::cout<< "out_xi:" <<std::endl; for(std::size_t i=0;i<out_xi.rows()/6;i++) { std::cout<< out_xi(i,1) <<" , "; } } |