public double[] getInstanceValues(Instance inst) { int length = inst.numValues()-1; double[] values = new double[length]; // last attribute is the class for (int i = 0; i < length; i++) { values[i] = inst.value(i); } return values; }
/** * Checks if there is any missing value in the given * instance. * @param ins The instance to check missing values in. * @throws Exception If there is a missing value in the * instance. */ protected void checkMissing(Instance ins) throws Exception { for (int j = 0; j < ins.numValues(); j++) { if (ins.index(j) != ins.classIndex()) if (ins.isMissingSparse(j)) { throw new Exception("ERROR: KDTree can not deal with missing " + "values. Please run ReplaceMissingValues filter " + "on the dataset before passing it on to the KDTree."); } } }
private void drawOutliers(JPanel layer, Vector<Outlier> outliers, Color color){ layer.removeAll(); for (Outlier outlier : outliers) { int length = outlier.inst.numValues() - 1; // -1 double[] center = new double[length]; // last value is the class for (int i = 0; i < length; i++) { center[i] = outlier.inst.value(i); } SphereCluster cluster = new SphereCluster(center, 0); OutlierPanel outlierpanel = new OutlierPanel(m_outlierDetector, outlier, cluster, color, this); layer.add(outlierpanel); outlierpanel.updateLocation(); } layer.repaint(); }
public void insert( Instance instance, long timestamp ) { N++; LST += timestamp; SST += timestamp*timestamp; for ( int i = 0; i < instance.numValues(); i++ ) { LS[i] += instance.value(i); SS[i] += instance.value(i)*instance.value(i); } }
public void insert( Instance instance, long timestamp ) { N++; LST += timestamp; SST += timestamp*timestamp; for ( int i = 0; i < instance.numValues(); i++ ) { LS[i] += instance.value(i); SS[i] += instance.value(i)*instance.value(i); } }
@Override public Clustering getClusteringResult(){ myClusters = new Clustering(); for (Outlier o : outliersFound) { if (IsNodeIdInWin(o.id)) { double[] center = new double[o.inst.numValues() - 1]; for (int i = 0; i < o.inst.numValues() - 1; i++) { center[i] = o.inst.value(i); } Cluster c = new SphereCluster(center, 0); myClusters.add(c); } } return myClusters; }
public void insert( Instance instance, long timestamp ) { N++; LST += timestamp; SST += timestamp*timestamp; for ( int i = 0; i < instance.numValues(); i++ ) { LS[i] += instance.value(i); SS[i] += instance.value(i)*instance.value(i); } }
protected static double dotProd(Instance inst1, double[] weights, int classIndex) { double result = 0; int n1 = inst1.numValues(); int n2 = weights.length - 1; for (int p1 = 0, p2 = 0; p1 < n1 && p2 < n2;) { int ind1 = inst1.index(p1); int ind2 = p2; if (ind1 == ind2) { if (ind1 != classIndex && !inst1.isMissingSparse(p1)) { result += inst1.valueSparse(p1) * weights[p2]; } p1++; p2++; } else if (ind1 > ind2) { p2++; } else { p1++; } } return (result); }
/** * Checks if there is any instance with missing values. Throws an exception if * there is, as KDTree does not handle missing values. * * @param instances the instances to check * @throws Exception if missing values are encountered */ protected void checkMissing(Instances instances) throws Exception { for (int i = 0; i < instances.numInstances(); i++) { Instance ins = instances.instance(i); for (int j = 0; j < ins.numValues(); j++) { if (ins.index(j) != ins.classIndex()) if (ins.isMissingSparse(j)) { throw new Exception("ERROR: KDTree can not deal with missing " + "values. Please run ReplaceMissingValues filter " + "on the dataset before passing it on to the KDTree."); } } } }
public void PrintInstance(Instance inst) { Print("instance: [ "); for (int i = 0; i < inst.numValues()-1; i++) { // -1 last value is the class Printf("%.2f ", inst.value(i)); } Print("] "); Println(""); }
public void insert(Instance instance, long timestamp) { N++; super.setWeight(super.getWeight() + 1); this.lastEditT = timestamp; for (int i = 0; i < instance.numValues(); i++) { LS[i] += instance.value(i); SS[i] += instance.value(i) * instance.value(i); } }
public double totalSize(Instance instance) { int classIndex = instance.classIndex(); double total = 0.0; for (int i = 0; i < instance.numValues(); i++) { int index = instance.index(i); if (index == classIndex || instance.isMissing(i)) { continue; } double count = instance.valueSparse(i); if (count >= 0) { total += count; } else { //throw new Exception("Numeric attribute value is not >= 0. " + i + " " + index + " " + // instance.valueSparse(i) + " " + " " + instance); } } return total; }
/** * Calculates the class membership probabilities for the given test * instance. * * @param instance the instance to be classified * @return predicted class probability distribution */ @Override public double[] getVotesForInstance(Instance instance) { if (this.reset == true) { return new double[2]; } double[] probOfClassGivenDoc = new double[m_numClasses]; double totalSize = totalSize(instance); for (int i = 0; i < m_numClasses; i++) { probOfClassGivenDoc[i] = Math.log(m_probOfClass[i]) - totalSize * Math.log(m_classTotals[i]); } for (int i = 0; i < instance.numValues(); i++) { int index = instance.index(i); if (index == instance.classIndex() || instance.isMissing(i)) { continue; } double wordCount = instance.valueSparse(i); for (int c = 0; c < m_numClasses; c++) { double value = m_wordTotalForClass[c].getValue(index); probOfClassGivenDoc[c] += wordCount * Math.log(value == 0 ? this.laplaceCorrectionOption.getValue() : value ); } } return Utils.logs2probs(probOfClassGivenDoc); }
protected static double dotProd(Instance inst1, DoubleVector weights, int classIndex) { double result = 0; int n1 = inst1.numValues(); int n2 = weights.numValues(); for (int p1 = 0, p2 = 0; p1 < n1 && p2 < n2;) { int ind1 = inst1.index(p1); int ind2 = p2; if (ind1 == ind2) { if (ind1 != classIndex && !inst1.isMissingSparse(p1)) { result += inst1.valueSparse(p1) * weights.getValue(p2); } p1++; p2++; } else if (ind1 > ind2) { p2++; } else { p1++; } } return (result); }
protected static double dotProd(Instance inst1, DoubleVector weights, int classIndex) { double result = 0; int n1 = inst1.numValues(); int n2 = weights.numValues(); for (int p1 = 0, p2 = 0; p1 < n1 && p2 < n2;) { int ind1 = inst1.index(p1); int ind2 = p2; if (ind1 == ind2) { if (ind1 != classIndex && !inst1.isMissingSparse(p1)) { result += inst1.valueSparse(p1) * weights.getValue(p2); } p1++; p2++; } else if (ind1 > ind2) { p2++; } else { p1++; } } return (result); }
int n1 = instance.numValues(); for (int p1 = 0; p1 < n1; p1++) { int indS = instance.index(p1);
double total = m_classTotals[classValue]; for (int i = 0; i < inst.numValues(); i++) { int index = inst.index(i); if (index != classIndex && !inst.isMissing(i)) {
int n = instance.numValues();
int n1 = instance.numValues(); for (int p1 = 0; p1 < n1; p1++) { int indS = instance.index(p1);
int n1 = instance.numValues(); for (int p1 = 0; p1 < n1; p1++) { int indS = instance.index(p1);