/** * {@inheritDoc} */ @Override public double[] toArray() { return dataRow.toDoubleArray(); } }
/** * {@inheritDoc} */ @Override public double[] toArray() { return dataRow.toDoubleArray(); } }
/** * GetxfromInstances - Extract attributes as a double x[] from an Instance. */ public static double[] getxfromInstance(Instance xy) { int L = xy.classIndex(); double xy_[] = xy.toDoubleArray(); return Arrays.copyOfRange(xy_,L,xy_.length); }
/** * GetxfromInstances - Extract attributes as a double x[] from an Instance. */ public static double[] getxfromInstance(Instance xy) { int L = xy.classIndex(); double xy_[] = xy.toDoubleArray(); return Arrays.copyOfRange(xy_,L,xy_.length); }
/** * returns the data minus the class column as matrix * * @param instance the instance to work on * @return the data without the class attribute */ protected Matrix getX(Instance instance) { double[][] x; double[] values; Matrix result; x = new double[1][]; values = instance.toDoubleArray(); x[0] = new double[values.length - 1]; System.arraycopy(values, 0, x[0], 0, values.length - 1); result = new Matrix(x); return result; }
/** * Constructor that copies the attribute values and the weight from the given * instance. It does NOT perform a deep copy of the attribute values if the * instance provided is also of type DenseInstance (it simply copies the * reference to the array of values), otherwise it does. Reference to the * dataset is set to null. (ie. the instance doesn't have access to * information about the attribute types) * * @param instance the instance from which the attribute values and the weight * are to be copied */ // @ ensures m_Dataset == null; public DenseInstance(/* @non_null@ */Instance instance) { if (instance instanceof DenseInstance) { m_AttValues = ((DenseInstance) instance).m_AttValues; } else { m_AttValues = instance.toDoubleArray(); } m_Weight = instance.weight(); m_Dataset = null; }
/** * Constructor that copies the attribute values and the weight from the given * instance. It does NOT perform a deep copy of the attribute values if the * instance provided is also of type DenseInstance (it simply copies the * reference to the array of values), otherwise it does. Reference to the * dataset is set to null. (ie. the instance doesn't have access to * information about the attribute types) * * @param instance the instance from which the attribute values and the weight * are to be copied */ // @ ensures m_Dataset == null; public DenseInstance(/* @non_null@ */Instance instance) { if (instance instanceof DenseInstance) { m_AttValues = ((DenseInstance) instance).m_AttValues; } else { m_AttValues = instance.toDoubleArray(); } m_Weight = instance.weight(); m_Dataset = null; }
/** * * @param instance * @param labelIndices * @return tranformed instance */ public static Instance transformInstance(Instance instance, int[] labelIndices) { double[] oldValues = instance.toDoubleArray(); double[] newValues = new double[oldValues.length - labelIndices.length]; int counter1 = 0; int counter2 = 0; for (int i = 0; i < oldValues.length; i++) { if (counter1 < labelIndices.length) if (i == labelIndices[counter1]) { counter1++; continue; } newValues[counter2] = oldValues[i]; counter2++; } return DataUtils.createInstance(instance, instance.weight(), newValues); } }
double[] values = instance.toDoubleArray(); double[] transformedValues = new double[values.length - labelIndices.length + 1];
@Override public Instance extract(Edit edit) { Instance instance = newDenseInstance(); int index = 0; for (FeatureExtractor fe: features) { for (Double value: fe.extract(edit).toDoubleArray()) { instance.setValue(index, value); index++; } } instance.setDataset(_instances); return instance; }
protected MultiLabelOutput makePredictionInternal(Instance instance) throws Exception { Instance transformed = DataUtils.createInstance(instance, instance.weight(), instance.toDoubleArray()); for (int i = 0; i < numMetaLabels; i++) { transformed.insertAttributeAt(transformed.numAttributes()); } transformed.setDataset(header); MultiLabelOutput mlo = hmc.makePrediction(transformed); boolean[] oldBipartition = mlo.getBipartition(); //System.out.println("old:" + Arrays.toString(oldBipartition)); boolean[] newBipartition = new boolean[numLabels]; System.arraycopy(oldBipartition, 0, newBipartition, 0, numLabels); //System.out.println("new:" + Arrays.toString(newBipartition)); double[] oldConfidences = mlo.getConfidences(); double[] newConfidences = new double[numLabels]; System.arraycopy(oldConfidences, 0, newConfidences, 0, numLabels); MultiLabelOutput newMLO = new MultiLabelOutput(newBipartition, newConfidences); return newMLO; }
protected MultiLabelOutput makePredictionInternal(Instance instance) throws Exception { boolean[] bipartition = new boolean[numLabels]; double[] confidences = new double[numLabels]; Instance tempInstance = DataUtils.createInstance(instance, instance.weight(), instance.toDoubleArray()); for (int counter = 0; counter < numLabels; counter++) { double distribution[]; try { distribution = ensemble[counter].distributionForInstance(tempInstance); } catch (Exception e) { System.out.println(e); return null; } int maxIndex = (distribution[0] > distribution[1]) ? 0 : 1; // Ensure correct predictions both for class values {0,1} and {1,0} Attribute classAttribute = ensemble[counter].getFilter().getOutputFormat().classAttribute(); bipartition[chain[counter]] = (classAttribute.value(maxIndex).equals("1")) ? true : false; // The confidence of the label being equal to 1 confidences[chain[counter]] = distribution[classAttribute.indexOfValue("1")]; tempInstance.setValue(labelIndices[chain[counter]], maxIndex); } MultiLabelOutput mlo = new MultiLabelOutput(bipartition, confidences); return mlo; } }
/** * Input an instance for filtering. Ordinarily the instance is processed * and made available for output immediately. Some filters require all * instances be read before producing output. * * @param instance the input instance * @return true if the filtered instance may now be * collected with output(). * @throws IllegalStateException if no input structure has been defined */ public boolean input(Instance instance) { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (m_NewBatch) { resetQueue(); m_NewBatch = false; } Instance inst = null; if (instance instanceof SparseInstance) { inst = new DenseInstance(instance.weight(), instance.toDoubleArray()); inst.setDataset(instance.dataset()); } else { inst = (Instance)instance.copy(); } push(inst, false); // No need to copy instance return true; }
/** * Input an instance for filtering. Ordinarily the instance is processed * and made available for output immediately. Some filters require all * instances be read before producing output. * * @param instance the input instance * @return true if the filtered instance may now be * collected with output(). * @throws IllegalStateException if no input structure has been defined */ public boolean input(Instance instance) { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (m_NewBatch) { resetQueue(); m_NewBatch = false; } Instance inst = null; if (instance instanceof SparseInstance) { inst = new DenseInstance(instance.weight(), instance.toDoubleArray()); inst.setDataset(instance.dataset()); } else { inst = (Instance)instance.copy(); } push(inst, false); // No need to copy instance return true; }
values = instance.toDoubleArray(); if (!instance.isMissing(m_AttIndex.getIndex())) { values[m_AttIndex.getIndex()] = m_SortedIndices[(int) values[m_AttIndex
System.arraycopy(instance.toDoubleArray(), 0, vals, 0, instance.numAttributes());
System.arraycopy(instance.toDoubleArray(), 0, vals, 0, instance.numAttributes());
double[] values = inst.toDoubleArray(); for (int i = 0; i < values.length; i++) { if (m_Cols.isInRange(i) && (i != instances.classIndex() || getIgnoreClass())) {
@Override public void add(Instance instance) { double[] values = instance.toDoubleArray(); Object[] obvValues = new Object[table.getSchema().getColumnCount()]; for (int i = 0; i < table.getSchema().getColumnCount(); i++) { Attribute att = instance.attribute(i); Class<?> c = table.getSchema().getColumnType(i); if(att.isString() && ObviousWekaUtils.isString(c)) { obvValues[i] = instance.attribute(i).value(i); } else if (att.isNumeric() && ObviousWekaUtils.isNumeric(c)) { obvValues[i] = instance.value(att); } else if (att.isDate() && ObviousWekaUtils.isDate(c)) { obvValues[i] = new Date((long) values[i]); } else { obvValues[i] = null; } } Tuple tuple = new TupleImpl(table.getSchema(), obvValues); m_Instances.addElement(new ObviousWekaInstance(tuple, this)); table.addRow(tuple); }
/** * Samoa instance from weka instance. * * @param inst the inst * @return the instance */ public Instance samoaInstance(weka.core.Instance inst) { Instance samoaInstance; if (inst instanceof weka.core.SparseInstance) { double[] attributeValues = new double[inst.numValues()]; int[] indexValues = new int[inst.numValues()]; for (int i = 0; i < inst.numValues(); i++) { if (inst.index(i) != inst.classIndex()) { attributeValues[i] = inst.valueSparse(i); indexValues[i] = inst.index(i); } } samoaInstance = new SparseInstance(inst.weight(), attributeValues, indexValues, inst.numAttributes()); } else { samoaInstance = new DenseInstance(inst.weight(), inst.toDoubleArray()); //samoaInstance.deleteAttributeAt(inst.classIndex()); } if (this.samoaInstanceInformation == null) { this.samoaInstanceInformation = this.samoaInstancesInformation(inst.dataset()); } samoaInstance.setDataset(samoaInstanceInformation); samoaInstance.setClassValue(inst.classValue()); return samoaInstance; }