/** * Returns natural logarithm of density estimate for given value based on * given instance. * * @param inst the instance to make the prediction for. * @param value the value to make the prediction for. * @return the natural logarithm of the density estimate * @exception Exception if the density cannot be computed */ @Override public double logDensity(Instance inst, double value) throws Exception { inst = filterInstance(inst); // Build K vector (and Kappa) Vector k = new DenseVector(m_NumTrain); for (int i = 0; i < m_NumTrain; i++) { k.set(i, m_weights[i] * m_actualKernel.eval(-1, i, inst)); } double estimate = k.dot(m_t) + m_avg_target; double sigma = computeStdDev(inst, k); // transform to GP space value = value * m_Alin + m_Blin; // center around estimate value = value - estimate; double z = -Math.log(sigma * Math.sqrt(2 * Math.PI)) - value * value / (2.0 * sigma * sigma); return z + Math.log(m_Alin); }
/** * Returns natural logarithm of density estimate for given value based on * given instance. * * @param inst the instance to make the prediction for. * @param value the value to make the prediction for. * @return the natural logarithm of the density estimate * @exception Exception if the density cannot be computed */ @Override public double logDensity(Instance inst, double value) throws Exception { inst = filterInstance(inst); // Build K vector (and Kappa) Vector k = new DenseVector(m_NumTrain); for (int i = 0; i < m_NumTrain; i++) { k.set(i, m_weights[i] * m_actualKernel.eval(-1, i, inst)); } double estimate = k.dot(m_t) + m_avg_target; double sigma = computeStdDev(inst, k); // transform to GP space value = value * m_Alin + m_Blin; // center around estimate value = value - estimate; double z = -Math.log(sigma * Math.sqrt(2 * Math.PI)) - value * value / (2.0 * sigma * sigma); return z + Math.log(m_Alin); }
/** * Gives standard deviation of the prediction at the given instance. * * @param inst the instance to get the standard deviation for * @return the standard deviation * @throws Exception if computation fails */ public double getStandardDeviation(Instance inst) throws Exception { inst = filterInstance(inst); // Build K vector (and Kappa) Vector k = new DenseVector(m_NumTrain); for (int i = 0; i < m_NumTrain; i++) { k.set(i, m_weights[i] * m_actualKernel.eval(-1, i, inst)); } return computeStdDev(inst, k) / m_Alin; }
/** * Gives standard deviation of the prediction at the given instance. * * @param inst the instance to get the standard deviation for * @return the standard deviation * @throws Exception if computation fails */ public double getStandardDeviation(Instance inst) throws Exception { inst = filterInstance(inst); // Build K vector (and Kappa) Vector k = new DenseVector(m_NumTrain); for (int i = 0; i < m_NumTrain; i++) { k.set(i, m_weights[i] * m_actualKernel.eval(-1, i, inst)); } return computeStdDev(inst, k) / m_Alin; }
/** * Computes a prediction interval for the given instance and confidence level. * * @param inst the instance to make the prediction for * @param confidenceLevel the percentage of cases the interval should cover * @return a 1*2 array that contains the boundaries of the interval * @throws Exception if interval could not be estimated successfully */ @Override public double[][] predictIntervals(Instance inst, double confidenceLevel) throws Exception { inst = filterInstance(inst); // Build K vector (and Kappa) Vector k = new DenseVector(m_NumTrain); for (int i = 0; i < m_NumTrain; i++) { k.set(i, m_weights[i] * m_actualKernel.eval(-1, i, inst)); } double estimate = k.dot(m_t) + m_avg_target; double sigma = computeStdDev(inst, k); confidenceLevel = 1.0 - ((1.0 - confidenceLevel) / 2.0); double z = Statistics.normalInverse(confidenceLevel); double[][] interval = new double[1][2]; interval[0][0] = estimate - z * sigma; interval[0][1] = estimate + z * sigma; interval[0][0] = (interval[0][0] - m_Blin) / m_Alin; interval[0][1] = (interval[0][1] - m_Blin) / m_Alin; return interval; }
/** * Computes a prediction interval for the given instance and confidence level. * * @param inst the instance to make the prediction for * @param confidenceLevel the percentage of cases the interval should cover * @return a 1*2 array that contains the boundaries of the interval * @throws Exception if interval could not be estimated successfully */ @Override public double[][] predictIntervals(Instance inst, double confidenceLevel) throws Exception { inst = filterInstance(inst); // Build K vector (and Kappa) Vector k = new DenseVector(m_NumTrain); for (int i = 0; i < m_NumTrain; i++) { k.set(i, m_weights[i] * m_actualKernel.eval(-1, i, inst)); } double estimate = k.dot(m_t) + m_avg_target; double sigma = computeStdDev(inst, k); confidenceLevel = 1.0 - ((1.0 - confidenceLevel) / 2.0); double z = Statistics.normalInverse(confidenceLevel); double[][] interval = new double[1][2]; interval[0][0] = estimate - z * sigma; interval[0][1] = estimate + z * sigma; interval[0][0] = (interval[0][0] - m_Blin) / m_Alin; interval[0][1] = (interval[0][1] - m_Blin) / m_Alin; return interval; }