getCapabilities().testWithFail(data); double factor = getInstancesFromClass(data, attrIndex, classIndex, classValue, workData); addValues(data, attrIndex, min, max, factor);
/** * Gets the current settings of the Estimator. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { String[] options; if (getDebug()) { options = new String[1]; options[0] = "-D"; } else { options = new String[0]; } return options; }
/** * get particular probability of the conditional probability distribtion of a * node given its parents. * * @param iNode index of the node * @param iParent index of the parent set, 0 <= iParent <= * getParentCardinality(iNode) * @param iValue index of the value, 0 <= iValue <= getCardinality(iNode) * @return probability */ public double getProbability(int iNode, int iParent, int iValue) { return m_Distributions[iNode][iParent].getProbability(iValue); }
/** * Initialize the estimator with a new dataset. Finds min and max first. * * @param data the dataset used to build this estimator * @param attrIndex attribute the estimator is for * @exception Exception if building of estimator goes wrong */ public void addValues(Instances data, int attrIndex) throws Exception { // can estimator handle the data? getCapabilities().testWithFail(data); double[] minMax = new double[2]; try { EstimatorUtils.getMinMax(data, attrIndex, minMax); } catch (Exception ex) { ex.printStackTrace(); System.out.println(ex.getMessage()); } double min = minMax[0]; double max = minMax[1]; // factor is 1.0, data set has not been reduced addValues(data, attrIndex, min, max, 1.0); }
/** * Initialize the estimator using only the instance of one class. It is using * the values of one attribute only. * * @param data the dataset used to build this estimator * @param attrIndex attribute the estimator is for * @param classIndex index of the class attribute * @param classValue the class value * @param min minimal value of this attribute * @param max maximal value of this attribute * @exception Exception if building of estimator goes wrong */ public void addValues(Instances data, int attrIndex, int classIndex, int classValue, double min, double max) throws Exception { // extract the instances with the given class value Instances workData = new Instances(data, 0); double factor = getInstancesFromClass(data, attrIndex, classIndex, classValue, workData); // if no data return if (workData.numInstances() == 0) { return; } addValues(data, attrIndex, min, max, factor); }
estimator = Estimator.makeCopies(getEstimator(), 1)[0]; } catch (Exception ex) { throw new Error("Error setting up for tests: " + ex.getMessage()); estimator.addValues(train1, attrIndex1); built = true; estimator1 = Estimator.makeCopies(getEstimator(), 1)[0]; estimator.addValues(train2, attrIndex2); built = true; estimator.addValues(train1, attrIndex1); built = true; if (!estimator.equals(estimator1)) { if (m_Debug) { println("\n=== Full report ===\n" + "\nFirst build estimator\n"
estimator = Estimator.makeCopies(getEstimator(), 1)[0]; } catch (Exception ex) { ex.printStackTrace(); estimator.addValues(train, attrIndex, classType, classIndex); built = true;
/** * Get a probability estimator for a value * * @param given the new value that data is conditional upon * @return the estimator for the supplied value given the condition */ public Estimator getEstimator(double given) { Estimator result = new DiscreteEstimator(m_Estimators.length,false); for(int i = 0; i < m_Estimators.length; i++) { result.addValue(i,m_Weights.getProbability(i) *m_Estimators[i].getProbability(given)); } return result; }
/** * Test if the estimator can handle the data. * * @param data the dataset the estimator takes an attribute from * @param attrIndex the index of the attribute * @see Capabilities */ public void testCapabilities(Instances data, int attrIndex) throws Exception { getCapabilities().testWithFail(data); getCapabilities().testWithFail(data.attribute(attrIndex)); } }
setGeneralOptions(build, est, options); buildEstimator(est, build.m_instances, build.m_attrIndex, build.m_classIndex, build.m_classValueIndex, isIncremental); } catch (Exception ex) {
public static void buildEstimator(Estimator est, Instances instances, int attrIndex, int classIndex, int classValueIndex, boolean isIncremental) throws Exception { // DBO.pln("buildEstimator 2 " + classValueIndex); // non-incremental estimator add all instances at once if (!isIncremental) { if (classValueIndex == -1) { // DBO.pln("before addValues -- Estimator"); est.addValues(instances, attrIndex); } else { // DBO.pln("before addValues with classvalue -- Estimator"); est.addValues(instances, attrIndex, classIndex, classValueIndex); } } else { // incremental estimator, read one value at a time Enumeration<Instance> enumInsts = (instances).enumerateInstances(); while (enumInsts.hasMoreElements()) { Instance instance = enumInsts.nextElement(); ((IncrementalEstimator) est).addValue(instance.value(attrIndex), instance.weight()); } } }
/** * Add arc between two nodes Distributions are updated by duplication for * every value of the parent node. * * @param nParent index of the parent node * @param nChild index of the child node * @throws Exception */ public void addArc(int nParent, int nChild) throws Exception { // update undo stack if (m_bNeedsUndoAction) { addUndoAction(new AddArcAction(nParent, nChild)); } int nOldCard = m_ParentSets[nChild].getCardinalityOfParents(); // update parentsets m_ParentSets[nChild].addParent(nParent, m_Instances); // update distributions int nNewCard = m_ParentSets[nChild].getCardinalityOfParents(); Estimator[] ds = new Estimator[nNewCard]; for (int iParent = 0; iParent < nNewCard; iParent++) { ds[iParent] = Estimator .clone(m_Distributions[nChild][iParent % nOldCard]); } m_Distributions[nChild] = ds; } // addArc
throw new Exception("A estimator must be specified with the -W option."); setEstimator(Estimator.forName(tmpStr, Utils.partitionOptions(options)));
estimator = Estimator.makeCopies(getEstimator(), 1)[0]; } catch (Exception ex) { throw new Error("Error setting up for tests: " + ex.getMessage()); estimator.addValues(train1, attrIndex1); built = true; estimator1 = Estimator.makeCopies(getEstimator(), 1)[0]; estimator.addValues(train2, attrIndex2); built = true; estimator.addValues(train1, attrIndex1); built = true; if (!estimator.equals(estimator1)) { if (m_Debug) { println("\n=== Full report ===\n" + "\nFirst build estimator\n"
estimator = Estimator.makeCopies(getEstimator(), 1)[0]; } catch (Exception ex) { ex.printStackTrace(); estimator.addValues(train, attrIndex, classType, classIndex); built = true;
/** * Get a probability estimator for a value * * @param given the new value that data is conditional upon * @return the estimator for the supplied value given the condition */ public Estimator getEstimator(double given) { Estimator result = new DiscreteEstimator(m_Estimators.length,false); for(int i = 0; i < m_Estimators.length; i++) { result.addValue(i,m_Weights.getProbability(i) *m_Estimators[i].getProbability(given)); } return result; }
/** * Test if the estimator can handle the data. * * @param data the dataset the estimator takes an attribute from * @param attrIndex the index of the attribute * @see Capabilities */ public void testCapabilities(Instances data, int attrIndex) throws Exception { getCapabilities().testWithFail(data); getCapabilities().testWithFail(data.attribute(attrIndex)); } }
/** * Initialize the estimator with a new dataset. Finds min and max first. * * @param data the dataset used to build this estimator * @param attrIndex attribute the estimator is for * @exception Exception if building of estimator goes wrong */ public void addValues(Instances data, int attrIndex) throws Exception { // can estimator handle the data? getCapabilities().testWithFail(data); double[] minMax = new double[2]; try { EstimatorUtils.getMinMax(data, attrIndex, minMax); } catch (Exception ex) { ex.printStackTrace(); System.out.println(ex.getMessage()); } double min = minMax[0]; double max = minMax[1]; // factor is 1.0, data set has not been reduced addValues(data, attrIndex, min, max, 1.0); }
/** * Initialize the estimator using only the instance of one class. It is using * the values of one attribute only. * * @param data the dataset used to build this estimator * @param attrIndex attribute the estimator is for * @param classIndex index of the class attribute * @param classValue the class value * @param min minimal value of this attribute * @param max maximal value of this attribute * @exception Exception if building of estimator goes wrong */ public void addValues(Instances data, int attrIndex, int classIndex, int classValue, double min, double max) throws Exception { // extract the instances with the given class value Instances workData = new Instances(data, 0); double factor = getInstancesFromClass(data, attrIndex, classIndex, classValue, workData); // if no data return if (workData.numInstances() == 0) { return; } addValues(data, attrIndex, min, max, factor); }
setGeneralOptions(build, est, options); buildEstimator(est, build.m_instances, build.m_attrIndex, build.m_classIndex, build.m_classValueIndex, isIncremental); } catch (Exception ex) {