double MultivariateModel ::ComputeLogLikelihood(const Observations &Obs) { /// It computes the likelihood of the model. For each subject i, it sums its likelihood, namely the distance, /// for each time t_ij, between the observation y_ij and the prediction f(t_ij) = ComputeParallelCurve ScalarType LogLikelihood = 0; /// For each subject for(size_t i = 0; i < m_NumberOfSubjects; ++i) { ScalarType N = Obs.GetNumberOfTimePoints(i); /// For each timepoint for(size_t j = 0; j < N; ++j) { auto& it = Obs.GetSubjectCognitiveScore(i, j); VectorType PC = ComputeParallelCurve(i, j); LogLikelihood += (it - PC).squared_magnitude(); } } LogLikelihood /= -2*m_Noise->GetVariance(); LogLikelihood -= m_NbTotalOfObservations * log(sqrt(2 * m_Noise->GetVariance() * M_PI)); return LogLikelihood; }
AbstractModel::SufficientStatisticsVector MultivariateModel ::GetSufficientStatistics(const Realizations &R, const Observations& Obs) { /// Computation of the suffisient statistics of the model /// Basically, it is a vector (named S1 to S9) of vectors /// S1 <- y_ij * eta_ij & S2 <- eta_ij * eta_ij VectorType S1(m_NbTotalOfObservations), S2(m_NbTotalOfObservations); auto itS1 = S1.begin(), itS2 = S2.begin(); for(size_t i = 0; i < m_NumberOfSubjects; ++i) { for(size_t j = 0; j < Obs.GetNumberOfTimePoints(i); ++j) { VectorType PC = ComputeParallelCurve(i, j); *itS1 = dot_product(PC, Obs.GetSubjectCognitiveScore(i, j)); *itS2 = PC.squared_magnitude(); ++itS1, ++itS2; } } /// S3 <- Ksi_i & S4 <- Ksi_i * Ksi_i VectorType S3 = R.at("Ksi"); VectorType S4 = R.at("Ksi") % R.at("Ksi"); /// S5 <- Tau_i & S6 <- Tau_i * Tau_i VectorType S5 = R.at("Tau"); VectorType S6 = R.at("Tau") % R.at("Tau"); /// S7 <- G VectorType S7(1, R.at("G", 0)); /// S8 <- beta_k VectorType S8((m_ManifoldDimension-1) * m_NbIndependentSources); ScalarType * itS8 = S8.memptr(); for(size_t i = 0; i < S8.size(); ++i) itS8[i] = R.at("Beta#" + std::to_string(i), 0); /// S8 <- delta_k VectorType S9(m_ManifoldDimension - 1); ScalarType * itS9 = S9.memptr(); for(size_t i = 1; i < S9.size(); ++i) itS9[i] = R.at("Delta#" + std::to_string(i), 0); return {S1, S2, S3, S4, S5, S6, S7, S8, S9}; }