@Override public double[] call() { double[] llk = new double[2]; double loglk = 0.0, sOW = 0.0; try { for (int i = m_lowNum; i < m_highNum; i++) { Instance in = m_eData.instance(i); loglk += in.weight() * EM.this.logDensityForInstance(in); sOW += in.weight(); if (m_changeWeights) { m_weights[i] = distributionForInstance(in); } } // completedETask(loglk, sOW, true); } catch (Exception ex) { // completedETask(0, 0, false); } llk[0] = loglk; llk[1] = sOW; return llk; } }
@Override public double[] call() { double[] llk = new double[2]; double loglk = 0.0, sOW = 0.0; try { for (int i = m_lowNum; i < m_highNum; i++) { Instance in = m_eData.instance(i); loglk += in.weight() * EM.this.logDensityForInstance(in); sOW += in.weight(); if (m_changeWeights) { m_weights[i] = distributionForInstance(in); } } // completedETask(loglk, sOW, true); } catch (Exception ex) { // completedETask(0, 0, false); } llk[0] = loglk; llk[1] = sOW; return llk; } }
/** * The E step of the EM algorithm. Estimate cluster membership probabilities. * * @param inst the training instances * @param change_weights whether to change the weights * @return the average log likelihood * @throws Exception if computation fails */ private double E(Instances inst, boolean change_weights) throws Exception { double loglk = 0.0, sOW = 0.0; for (int l = 0; l < inst.numInstances(); l++) { Instance in = inst.instance(l); loglk += in.weight() * logDensityForInstance(in); sOW += in.weight(); if (change_weights) { m_weights[l] = distributionForInstance(in); } } if (sOW <= 0) { // In case all weights are zero return 0; } // reestimate priors /* * if (change_weights) { estimate_priors(inst); } */ return loglk / sOW; }
/** * The E step of the EM algorithm. Estimate cluster membership probabilities. * * @param inst the training instances * @param change_weights whether to change the weights * @return the average log likelihood * @throws Exception if computation fails */ private double E(Instances inst, boolean change_weights) throws Exception { double loglk = 0.0, sOW = 0.0; for (int l = 0; l < inst.numInstances(); l++) { Instance in = inst.instance(l); loglk += in.weight() * logDensityForInstance(in); sOW += in.weight(); if (change_weights) { m_weights[l] = distributionForInstance(in); } } if (sOW <= 0) { // In case all weights are zero return 0; } // reestimate priors /* * if (change_weights) { estimate_priors(inst); } */ return loglk / sOW; }