40 if (fMatrix(0, fMatrix.ColumnSize() - 1) > 0.0)
42 nbStates = fMatrix.ColumnSize();
46 nbStates = fMatrix.ColumnSize() - 1;
49 for (
s = 0;
s < nbStates;
s++)
51 model.States[
s].Prio = fMatrix(0,
s);
55 nbDim = fMatrix.RowSize();
56 model.nbStates = nbStates;
60 for (
s = 0;
s < nbStates;
s++)
62 model.States[
s].Mu.Resize(nbDim);
63 model.States[
s].Sigma.Resize(nbDim, nbDim);
66 for (
s = 0;
s < nbStates;
s++)
68 model.States[
s].Mu = fMatrix.GetColumn(
s);
71 fMatrix.Load(f_sigma);
73 for (
s = 0;
s < nbStates;
s++)
75 for (i = 0; i < nbDim; i++)
77 model.States[
s].Sigma.SetRow(fMatrix.GetRow(j), i);
92 model.nbStates = nbStates;
95 for (
s = 0;
s < nbStates;
s++)
97 model.States[
s].Mu.Resize(nbDim);
98 model.States[
s].Sigma.Resize(nbDim, nbDim);
103 for (
s = 0;
s < nbStates;
s++)
105 model.States[
s].Mu = fMatrix.GetColumn(
s);
108 fMatrix.Resize(nbStates * nbDim, nbDim);
109 fMatrix.Load(f_sigma);
111 for (
s = 0;
s < nbStates;
s++)
113 for (i = 0; i < nbDim; i++)
115 model.States[
s].Sigma.SetRow(fMatrix.GetRow(j), i);
120 fMatrix.Resize(1, nbStates);
121 fMatrix.Load(f_prio);
123 for (
s = 0;
s < nbStates;
s++)
125 model.States[
s].Prio = fMatrix(0,
s);
131 const vector<double> pri_vec,
132 const vector<double> mu_vec,
133 const vector<double> sig_vec)
136 model.nbStates = nbStates;
139 for (
int s = 0;
s < nbStates;
s++)
141 model.States[
s].Mu.Resize(nbDim);
142 model.States[
s].Sigma.Resize(nbDim, nbDim);
145 for (
int s = 0;
s < nbStates;
s++)
147 model.States[
s].Prio = pri_vec[
s];
156 for (
int s = 0;
s < nbStates;
s++)
158 for (
int d = 0; d < nbDim; d++)
160 model.States[
s].Mu[d] = mu_vec[
s * nbDim + d];
173 for (
int s = 0;
s < nbStates;
s++)
175 for (
int row = 0; row < nbDim; row++)
177 for (
int col = 0; col < nbDim; col++)
179 int ind =
s * nbDim * nbDim + row * nbDim + col;
180 model.States[
s].Sigma(row, col) = sig_vec[ind];
215 int nbIN = last_inindex - first_inindex + 1;
217 for (
unsigned int s = 0;
s < model.nbStates;
s++)
219 gmmpinv[
s].MuI.Resize(nbIN);
220 gmmpinv[
s].SigmaII.Resize(nbIN, nbIN);
221 gmmpinv[
s].SigmaIIInv.Resize(nbIN, nbIN);
224 for (
unsigned int s = 0;
s < model.nbStates;
s++)
226 for (
int i = first_inindex; i <= last_inindex; i++)
228 gmmpinv[
s].MuI(i - first_inindex) = model.States[
s].Mu(i);
230 for (
int i = first_inindex; i <= last_inindex; i++)
231 for (
int j = first_inindex; j <= last_inindex; j++)
233 gmmpinv[
s].SigmaII(i - first_inindex, j - first_inindex) =
234 model.States[
s].Sigma(i, j);
237 gmmpinv[
s].SigmaII.Inverse(gmmpinv[
s].SigmaIIInv, &det);
244 gmmpinv[
s].detSigmaII = det;
247 nbDimI = last_inindex - first_inindex + 1;
248 gfDiff.Resize(nbDimI);
249 gfDiffp.Resize(nbDimI);
257 gfDiff = x - gmmpinv[state].MuI;
258 gfDiffp = gmmpinv[state].SigmaIIInv * gfDiff;
260 p = exp(-0.5 * gfDiff.Dot(gfDiffp)) /
261 sqrt(pow(2.0 *
PI, nbDimI) * (gmmpinv[state].detSigmaII + 1e-30));
270 for (
unsigned int s = 0;
s < model.nbStates;
s++)
272 totalP += model.States[
s].Prio * GaussianPDFFast(
s, x);
281 for (
unsigned int s = 0;
s < model.nbStates;
s++)
283 gDer += (gmmpinv[
s].SigmaIIInv * (x - gmmpinv[
s].MuI)) * model.States[
s].Prio *
284 GaussianPDFFast(
s, x);
293 int nbIN = last_inindex - first_inindex + 1;
294 int nbOUT = last_outindex - first_outindex + 1;
296 gPdf.Resize(model.nbStates);
298 for (
unsigned int s = 0;
s < model.nbStates;
s++)
300 gmmpinv[
s].MuI.Resize(nbIN);
301 gmmpinv[
s].SigmaII.Resize(nbIN, nbIN);
302 gmmpinv[
s].SigmaIIInv.Resize(nbIN, nbIN);
304 gmmpinv[
s].muO.Resize(nbOUT);
305 gmmpinv[
s].SigmaIO.Resize(nbIN, nbOUT);
306 gmmpinv[
s].SigmaIOInv.Resize(nbOUT, nbOUT);
309 for (
unsigned int s = 0;
s < model.nbStates;
s++)
311 for (
int i = first_inindex; i <= last_inindex; i++)
313 gmmpinv[
s].MuI(i - first_inindex) = model.States[
s].Mu(i);
315 for (
int j = first_inindex; j <= last_inindex; j++)
317 gmmpinv[
s].SigmaII(i - first_inindex, j - first_inindex) =
318 model.States[
s].Sigma(i, j);
320 for (
int j = first_outindex; j <= last_outindex; j++)
322 gmmpinv[
s].SigmaIO(i - first_inindex, j - first_outindex) =
323 model.States[
s].Sigma(i, j);
327 for (
int i = first_outindex; i <= last_outindex; i++)
329 gmmpinv[
s].muO(i - first_outindex) = model.States[
s].Mu(i);
332 gmmpinv[
s].SigmaII.Inverse(gmmpinv[
s].SigmaIIInv, &det);
337 gmmpinv[
s].detSigmaII = det;
338 (gmmpinv[
s].SigmaIO).Transpose().Inverse(gmmpinv[
s].SigmaIOInv, &det);
341 nbDimI = last_inindex - first_inindex + 1;
342 gfDiff.Resize(nbDimI);
343 gfDiffp.Resize(nbDimI);
352 Regression(indata, outdata);
353 cout <<
"derivative is not implemented yet " << endl;
363 for (
unsigned int s = 0;
s < model.nbStates;
s++)
365 gPdf(
s) = model.States[
s].Prio * GaussianPDFFast(
s, indata);
370 for (
unsigned int s = 0;
s < model.nbStates;
s++)
373 h(
s) = gPdf(
s) / (pdfall);
374 r_diff = gmmpinv[
s].SigmaIO.Transpose() * gmmpinv[
s].SigmaIIInv * (indata - gmmpinv[
s].MuI);
376 for (
unsigned int i = 0; i < r_diff.Size(); i++)
378 outdata(i) += h(
s) * (r_diff(i) + gmmpinv[
s].muO(i));
387 Regression(indata, outdata);