public void addSparseValues(int[] indexValues, double[] attributeValues, int numberAttributes) { this.instanceData = new SparseInstanceData(attributeValues, indexValues, numberAttributes); // ??? }
@Override public double[] toDoubleArray() { double[] array = new double[numAttributes()]; for (int i=0; i<numValues() ; i++) { array[index(i)] = valueSparse(i); } return array; }
@Override public void setValue(int attributeIndex, double d) { int index = locateIndex(attributeIndex); if (index(index) == attributeIndex) { this.attributeValues[index] = d; } else { // We need to add the value } }
@Override public void insertAttributeAt(int position) { if ((position< 0) || (position > numAttributes())) { throw new IllegalArgumentException("Can't insert attribute: index out " + "of range"); int index = locateIndex(position);
@Override public double value(int indexAttribute) { int location = locateIndex(indexAttribute); //return location == -1 ? 0 : this.attributeValues[location]; // int index = locateIndex(attIndex); if ((location >= 0) && (indexValues[location] == indexAttribute)) { return attributeValues[location]; } else { return 0.0; } }
InstanceImpl instance = (InstanceImpl) inst; SparseInstanceData sparseInstanceData = (SparseInstanceData) instance.instanceData; wekaInstance = new weka.core.SparseInstance(instance.weight(), sparseInstanceData.getAttributeValues(), sparseInstanceData.getIndexValues(), sparseInstanceData.getNumberAttributes());
@Override public boolean isMissingSparse(int indexAttribute) { return Double.isNaN(this.valueSparse(indexAttribute)); }
@Override public boolean isMissing(int indexAttribute) { return Double.isNaN(this.value(indexAttribute)); }
/** * Value. * * @param indexAttribute the index attribute * @return the double */ @Override public double value(int indexAttribute) { int location = locateIndex(indexAttribute); //return location == -1 ? 0 : this.attributeValues[location]; // int index = locateIndex(attIndex); if ((location >= 0) && (indexValues[location] == indexAttribute)) { return attributeValues[location]; } else { return 0.0; } }
/** * Checks if is missing sparse. * * @param indexAttribute the index attribute * @return true, if is missing sparse */ @Override public boolean isMissingSparse(int indexAttribute) { return Double.isNaN(this.valueSparse(indexAttribute)); }
/** * Checks if is missing. * * @param indexAttribute the index attribute * @return true, if is missing */ @Override public boolean isMissing(int indexAttribute) { return Double.isNaN(this.value(indexAttribute)); }
/** * To double array. * * @return the double[] */ @Override public double[] toDoubleArray() { double[] array = new double[numAttributes()]; for (int i = 0; i < numValues(); i++) { array[index(i)] = valueSparse(i); } return array; }
/** * Sets the value. * * @param attributeIndex the attribute index * @param d the d */ @Override public void setValue(int attributeIndex, double d) { int index = locateIndex(attributeIndex); if (index(index) == attributeIndex) { this.attributeValues[index] = d; } else { // We need to add the value } }
/** * Instantiates a new instance. * * @param weight the weight * @param attributeValues the attribute values * @param indexValues the index values * @param numberAttributes the number attributes */ public InstanceImpl(double weight, double[] attributeValues, int[] indexValues, int numberAttributes) { this.weight = weight; this.instanceData = new SparseInstanceData(attributeValues, indexValues, numberAttributes); }
public void deleteAttributeAt(int position) { int index = locateIndex(position);
/** * Adds the sparse values. * * @param indexValues the index values * @param attributeValues the attribute values * @param numberAttributes the number attributes */ @Override public void addSparseValues(int[] indexValues, double[] attributeValues, int numberAttributes) { this.instanceData = new SparseInstanceData(attributeValues, indexValues, numberAttributes); //??? }
public SingleLabelInstance(double weight, double[] attributeValues, int[] indexValues, int numberAttributes) { this.weight = weight; this.instanceData = new SparseInstanceData(attributeValues, indexValues, numberAttributes); // ??? this.classData = new SingleClassInstanceData(); // this.classValue = Double.NaN; //this.instanceInformation = new InstancesHeader(); }
@Override public InstanceData copy() { return new SparseInstanceData(this.attributeValues.clone(),this.indexValues.clone(),this.numberAttributes); }