diff --git a/src/dist/PrecalculatedDistribution.java b/src/dist/PrecalculatedDistribution.java index caf81160..288f08f9 100644 --- a/src/dist/PrecalculatedDistribution.java +++ b/src/dist/PrecalculatedDistribution.java @@ -42,7 +42,7 @@ public Instance mode(Instance input) { * @see hmm.distribution.OutputDistribution#probabilityOfObservation(hmm.observation.Observation) */ public double p(Instance inst) { - return inst.getContinuous(i); + return inst.get(i); } diff --git a/src/func/inst/HyperRectangle.java b/src/func/inst/HyperRectangle.java index ebdb886b..caea42f2 100644 --- a/src/func/inst/HyperRectangle.java +++ b/src/func/inst/HyperRectangle.java @@ -108,12 +108,12 @@ public HyperRectangle splitRight(double value, int dimension) { public Instance pointNearestTo(Instance target) { double[] nearest = new double[target.size()]; for (int i = 0; i < nearest.length; i++) { - if (target.getContinuous(i) <= min.get(i)) { + if (target.get(i) <= min.get(i)) { nearest[i] = min.get(i); - } else if (target.getContinuous(i) >= max.get(i)) { + } else if (target.get(i) >= max.get(i)) { nearest[i] = max.get(i); } else { - nearest[i] = target.getContinuous(i); + nearest[i] = target.get(i); } } return new Instance(new DenseVector(nearest)); diff --git a/src/func/inst/KDTree.java b/src/func/inst/KDTree.java index 45caef76..105ebd67 100644 --- a/src/func/inst/KDTree.java +++ b/src/func/inst/KDTree.java @@ -156,8 +156,8 @@ private int chooseSplitterSmart(KDTreeNode[] nodes, int start, int end) { for (int i = start; i < end; i++) { Instance key = nodes[i].getInstance(); for (int j = 0; j < dimensions; j++) { - min[j] = Math.min(min[j], key.getContinuous(j)); - max[j] = Math.max(max[j], key.getContinuous(j)); + min[j] = Math.min(min[j], key.get(j)); + max[j] = Math.max(max[j], key.get(j)); } } // find the widest dimension @@ -176,11 +176,11 @@ private int chooseSplitterSmart(KDTreeNode[] nodes, int start, int end) { int splitterIndex = -1; for (int i = start; i < end; i++) { KDTreeNode node = nodes[i]; - if (Math.abs(node.getInstance().getContinuous(widestDimension) - median) + if (Math.abs(node.getInstance().get(widestDimension) - median) < bestDifference) { splitterIndex = i; bestDifference = - Math.abs(node.getInstance().getContinuous(widestDimension) - median); + Math.abs(node.getInstance().get(widestDimension) - median); } } nodes[splitterIndex].setDimension(widestDimension); @@ -253,7 +253,7 @@ private void knn(KDTreeNode node, Instance target, HyperRectangle hr, node.getSplitValue(), node.getDimension()); HyperRectangle nearHR, farHR; KDTreeNode nearNode, farNode; - if (target.getContinuous(node.getDimension()) < node.getSplitValue()) { + if (target.get(node.getDimension()) < node.getSplitValue()) { nearHR = leftHR; nearNode = node.getLeft(); farHR = rightHR; farNode = node.getRight(); } else { diff --git a/src/func/inst/KDTreeNode.java b/src/func/inst/KDTreeNode.java index 7d76bd5d..0cb0498e 100644 --- a/src/func/inst/KDTreeNode.java +++ b/src/func/inst/KDTreeNode.java @@ -41,7 +41,7 @@ public KDTreeNode(Instance key) { * @return the value */ public double getSplitValue() { - return instance.getContinuous(dimension); + return instance.get(dimension); } /** @@ -105,7 +105,7 @@ public void setRight(KDTreeNode node) { */ public int compareTo(Object o) { double value = getSplitValue(); - double otherValue = ((KDTreeNode) o).getInstance().getContinuous(dimension); + double otherValue = ((KDTreeNode) o).getInstance().get(dimension); if (value < otherValue) { return -1; } else if (value > otherValue) { diff --git a/src/opt/ContinuousAddOneNeighbor.java b/src/opt/ContinuousAddOneNeighbor.java index bfc221c3..f238bdac 100644 --- a/src/opt/ContinuousAddOneNeighbor.java +++ b/src/opt/ContinuousAddOneNeighbor.java @@ -36,7 +36,7 @@ public ContinuousAddOneNeighbor() { public Instance neighbor(Instance d) { int i = Distribution.random.nextInt(d.size()); Instance cod = (Instance) d.copy(); - cod.getData().set(i, cod.getContinuous(i)+ Distribution.random.nextDouble() * amount - amount / 2); + cod.getData().set(i, cod.get(i)+ Distribution.random.nextDouble() * amount - amount / 2); return cod; } } diff --git a/src/opt/SwapNeighbor.java b/src/opt/SwapNeighbor.java index e8085dac..4a6fa71f 100644 --- a/src/opt/SwapNeighbor.java +++ b/src/opt/SwapNeighbor.java @@ -18,8 +18,8 @@ public Instance neighbor(Instance d) { Instance cod = (Instance) d.copy(); int i = Distribution.random.nextInt(cod.getData().size()); int j = Distribution.random.nextInt(cod.getData().size()); - double temp = cod.getContinuous(i); - cod.getData().set(i, cod.getContinuous(j)); + double temp = cod.get(i); + cod.getData().set(i, cod.get(j)); cod.getData().set(j, temp); return cod; } diff --git a/src/opt/example/TravelingSalesmanSortEvaluationFunction.java b/src/opt/example/TravelingSalesmanSortEvaluationFunction.java index c0b80ef3..789f496f 100644 --- a/src/opt/example/TravelingSalesmanSortEvaluationFunction.java +++ b/src/opt/example/TravelingSalesmanSortEvaluationFunction.java @@ -26,7 +26,7 @@ public TravelingSalesmanSortEvaluationFunction(double[][] points) { public double value(Instance d) { double[] ddata = new double[d.size()]; for (int i = 0; i < ddata.length; i++) { - ddata[i] = d.getContinuous(i); + ddata[i] = d.get(i); } int[] order = ABAGAILArrays.indices(d.size()); ABAGAILArrays.quicksort(ddata, order); diff --git a/src/opt/ga/ContinuousAddOneMutation.java b/src/opt/ga/ContinuousAddOneMutation.java index e78585fb..e43de1e6 100644 --- a/src/opt/ga/ContinuousAddOneMutation.java +++ b/src/opt/ga/ContinuousAddOneMutation.java @@ -35,6 +35,6 @@ public ContinuousAddOneMutation() { */ public void mutate(Instance cod) { int i = Distribution.random.nextInt(cod.size()); - cod.getData().set(i, cod.getContinuous(i)+ Distribution.random.nextDouble() * amount - amount / 2); + cod.getData().set(i, cod.get(i)+ Distribution.random.nextDouble() * amount - amount / 2); } } diff --git a/src/opt/ga/SingleCrossOver.java b/src/opt/ga/SingleCrossOver.java index 110bba5c..57f7a66e 100644 --- a/src/opt/ga/SingleCrossOver.java +++ b/src/opt/ga/SingleCrossOver.java @@ -19,9 +19,9 @@ public Instance mate(Instance a, Instance b) { int point = Distribution.random.nextInt(newData.length + 1); for (int i = 0; i < newData.length; i++) { if (i >= point) { - newData[i] = a.getContinuous(i); + newData[i] = a.get(i); } else { - newData[i] = b.getContinuous(i); + newData[i] = b.get(i); } } return new Instance(newData); diff --git a/src/opt/ga/SwapMutation.java b/src/opt/ga/SwapMutation.java index 8690151a..a8723d7c 100644 --- a/src/opt/ga/SwapMutation.java +++ b/src/opt/ga/SwapMutation.java @@ -16,8 +16,8 @@ public class SwapMutation implements MutationFunction { public void mutate(Instance d) { int i = Distribution.random.nextInt(d.size()); int j = Distribution.random.nextInt(d.size()); - double temp = d.getContinuous(i); - d.getData().set(i, d.getContinuous(j)); + double temp = d.get(i); + d.getData().set(i, d.get(j)); d.getData().set(j, temp); } } diff --git a/src/opt/ga/UniformCrossOver.java b/src/opt/ga/UniformCrossOver.java index 3ef69889..703176df 100644 --- a/src/opt/ga/UniformCrossOver.java +++ b/src/opt/ga/UniformCrossOver.java @@ -18,9 +18,9 @@ public Instance mate(Instance a, Instance b) { double[] newData = new double[a.size()]; for (int i = 0; i < newData.length; i++) { if (Distribution.random.nextBoolean()) { - newData[i] = a.getContinuous(i); + newData[i] = a.get(i); } else { - newData[i] = b.getContinuous(i); + newData[i] = b.get(i); } } return new Instance(newData); diff --git a/src/shared/DataSetDescription.java b/src/shared/DataSetDescription.java index c9acf9a6..024ff6f7 100644 --- a/src/shared/DataSetDescription.java +++ b/src/shared/DataSetDescription.java @@ -271,12 +271,12 @@ public void induceFrom(DataSet data) { min.minEquals(cur.getData()); for (int j = 0; j < types.length; j++) { if (types[j] == AttributeType.BINARY - && cur.getContinuous(j) != 1 && cur.getContinuous(j) != 0) { + && cur.get(j) != 1 && cur.get(j) != 0) { types[j] = AttributeType.DISCRETE; } if (types[j] == AttributeType.DISCRETE - && cur.getDiscrete(j) != cur.getContinuous(j)) { + && cur.getDiscrete(j) != cur.get(j)) { types[j] = AttributeType.CONTINUOUS; } } diff --git a/src/shared/DataSetWriter.java b/src/shared/DataSetWriter.java index 1f629975..c6c661bd 100644 --- a/src/shared/DataSetWriter.java +++ b/src/shared/DataSetWriter.java @@ -84,7 +84,7 @@ public void write() throws IOException { } } else { for (int j = 0; j < data.size(); j++) { - pw.print(data.getContinuous(j)); + pw.print(data.get(j)); if (j + 1 < data.size() || data.getLabel() != null) { pw.print(", "); } diff --git a/src/shared/EuclideanDistance.java b/src/shared/EuclideanDistance.java index 0fe38a3a..17c8cda7 100644 --- a/src/shared/EuclideanDistance.java +++ b/src/shared/EuclideanDistance.java @@ -14,8 +14,8 @@ public class EuclideanDistance extends AbstractDistanceMeasure { public double value(Instance va, Instance vb) { double sum = 0; for (int i = 0; i < va.size(); i++) { - sum += (va.getContinuous(i) - vb.getContinuous(i)) - * (va.getContinuous(i) - vb.getContinuous(i)); + sum += (va.get(i) - vb.get(i)) + * (va.get(i) - vb.get(i)); } return sum; } diff --git a/src/shared/Instance.java b/src/shared/Instance.java index 37f0b8f9..56093a40 100644 --- a/src/shared/Instance.java +++ b/src/shared/Instance.java @@ -137,11 +137,11 @@ public int size() { } /** - * Get the ith continuous value - * @param i the value to get + * Get the ith value + * @param i the index of the value to get * @return the value */ - public double getContinuous(int i) { + public double get(int i) { return data.get(i); } @@ -159,7 +159,7 @@ public int getDiscrete(int i) { * @return the value */ public double getContinuous() { - return getContinuous(0); + return get(0); } /** diff --git a/src/shared/MixedDistanceMeasure.java b/src/shared/MixedDistanceMeasure.java index 95ee89d7..7e842090 100644 --- a/src/shared/MixedDistanceMeasure.java +++ b/src/shared/MixedDistanceMeasure.java @@ -29,8 +29,8 @@ public double value(Instance va, Instance vb) { double distance = 0; for (int i = 0; i < va.size(); i++) { if (types[i] == AttributeType.CONTINUOUS) { - distance += (va.getContinuous(i) - vb.getContinuous(i)) - * (va.getContinuous(i) - vb.getContinuous(i)); + distance += (va.get(i) - vb.get(i)) + * (va.get(i) - vb.get(i)); } else { if (va.getDiscrete(i) != vb.getDiscrete(i)) { distance += 1; diff --git a/src/shared/SumOfSquaresError.java b/src/shared/SumOfSquaresError.java index 23e0e907..53ad9196 100644 --- a/src/shared/SumOfSquaresError.java +++ b/src/shared/SumOfSquaresError.java @@ -20,8 +20,8 @@ public double value(Instance output, Instance example) { double sum = 0; Instance label = example.getLabel(); for (int i = 0; i < output.size(); i++) { - sum += (output.getContinuous(i) - label.getContinuous(i)) - * (output.getContinuous(i) - label.getContinuous(i)) + sum += (output.get(i) - label.get(i)) + * (output.get(i) - label.get(i)) * example.getWeight(); } return .5 * sum; @@ -34,7 +34,7 @@ public double[] gradient(Instance output, Instance example) { double[] errorArray = new double[output.size()]; Instance label = example.getLabel(); for (int i = 0; i < output.size(); i++) { - errorArray[i] = (output.getContinuous(i) - label.getContinuous(i)) + errorArray[i] = (output.get(i) - label.get(i)) * example.getWeight(); } return errorArray; diff --git a/src/shared/filt/ContinuousToDiscreteFilter.java b/src/shared/filt/ContinuousToDiscreteFilter.java index c794d9eb..86dc96b8 100644 --- a/src/shared/filt/ContinuousToDiscreteFilter.java +++ b/src/shared/filt/ContinuousToDiscreteFilter.java @@ -37,16 +37,16 @@ public void filter(DataSet dataSet) { Instance instance = dataSet.get(i); for (int j = 0; j < oldDescription.getAttributeCount(); j++) { if (oldDescription.getAttributeTypes()[j] == AttributeType.CONTINUOUS) { - double cv = instance.getContinuous(j); + double cv = instance.get(j); int dv = (int) ((cv - oldDescription.getMin(j)) * numberOfBins / oldDescription.getRange(j)); instance.getData().set(j, dv); } } } - - // the description is no longer valid so generate a new one - dataSet.setDescription(new DataSetDescription(dataSet)); - dataSet.getDescription().setLabelDescription(new DataSetDescription(dataSet.getLabelDataSet())); + + // the description is no longer valid so generate a new one + dataSet.setDescription(new DataSetDescription(dataSet)); + dataSet.getDescription().setLabelDescription(new DataSetDescription(dataSet.getLabelDataSet())); } } diff --git a/src/shared/filt/DiscreteToBinaryFilter.java b/src/shared/filt/DiscreteToBinaryFilter.java index 3acd8c70..586cf920 100644 --- a/src/shared/filt/DiscreteToBinaryFilter.java +++ b/src/shared/filt/DiscreteToBinaryFilter.java @@ -43,7 +43,7 @@ public void filter(DataSet dataSet) { data[k + instance.getDiscrete(j)] = 1; k += oldDescription.getDiscreteRange(j); } else { - data[k] = instance.getContinuous(j); + data[k] = instance.get(j); k++; } } diff --git a/src/shared/reader/DataSetLabelBinarySeperator.java b/src/shared/reader/DataSetLabelBinarySeperator.java index 52839ad3..7b6d59c5 100644 --- a/src/shared/reader/DataSetLabelBinarySeperator.java +++ b/src/shared/reader/DataSetLabelBinarySeperator.java @@ -5,7 +5,6 @@ import shared.DataSet; import shared.Instance; -import shared.tester.Comparison; /** * Separates Discrete Labels into Binary representation for better use in Neural Networks @@ -61,7 +60,7 @@ public static Instance combineLabels(Instance instance) { int maxInx = -1; double max = 0; for (int ii = 0; ii < instance.size(); ii++) { - double inst = instance.getContinuous(ii); + double inst = instance.get(ii); if (inst > max) { maxInx = ii; max = inst; diff --git a/src/shared/runner/Experiment.java b/src/shared/runner/Experiment.java new file mode 100644 index 00000000..ff6bd6c1 --- /dev/null +++ b/src/shared/runner/Experiment.java @@ -0,0 +1,24 @@ +package shared.runner; + +import shared.DataSet; +import shared.reader.DataSetReader; + +/** + * Created by zooky on 10/11/14. + */ +public interface Experiment { + /** + * Set type of DataSetReader according to type of datafile + */ + public void setDataSetReader(); + /** + * + * @return A DataSet + */ + public DataSet getDataSet(); + + + + + +} diff --git a/src/shared/tester/Comparison.java b/src/shared/tester/Comparison.java index a56cbe84..9ece0992 100644 --- a/src/shared/tester/Comparison.java +++ b/src/shared/tester/Comparison.java @@ -1,7 +1,6 @@ package shared.tester; import shared.Instance; -import util.linalg.Vector; /** * An generic utility for comparing values in Instance objects @@ -55,7 +54,7 @@ public boolean isAllCorrect() { public boolean isCorrect(int index) { //compare the continuous values, down to 1e-6. This accounts for any weird floating point issues, and some // issues when classifying discrete or boolean functions. - return Math.abs(expected.getContinuous(index) - actual.getContinuous(index)) < epsilon; + return Math.abs(expected.get(index) - actual.get(index)) < epsilon; } /** diff --git a/src/shared/tester/ConfusionMatrixTestMetric.java b/src/shared/tester/ConfusionMatrixTestMetric.java index 8f5c07e1..a0a34063 100644 --- a/src/shared/tester/ConfusionMatrixTestMetric.java +++ b/src/shared/tester/ConfusionMatrixTestMetric.java @@ -6,7 +6,6 @@ import shared.AttributeType; import shared.DataSetDescription; import shared.Instance; -import shared.reader.DataSetLabelBinarySeperator; /** * A test metric to generate a confusion matrix. This metric expects the true labels @@ -57,8 +56,8 @@ public int hashCode() { for (int ii = 0; ii < expected.size(); ii++) { //scale the expected value, to provide separation between corresponding pairs // (e.g. a, b should be different from b, a) - hashCode += 0x10000 * expected.getContinuous(ii); - hashCode += actual.getContinuous(ii); + hashCode += 0x10000 * expected.get(ii); + hashCode += actual.get(ii); } return hashCode; } diff --git a/src/shared/tester/RawOutputTestMetric.java b/src/shared/tester/RawOutputTestMetric.java index d8a81122..57af34f5 100644 --- a/src/shared/tester/RawOutputTestMetric.java +++ b/src/shared/tester/RawOutputTestMetric.java @@ -13,7 +13,7 @@ public void addResult(Instance expected, Instance actual) { if (addComma) { builder.append(","); } - builder.append(expected.getContinuous(ii)); + builder.append(expected.get(ii)); addComma = true; } builder.append(", Actual: "); @@ -22,7 +22,7 @@ public void addResult(Instance expected, Instance actual) { if (addComma) { builder.append(","); } - builder.append(actual.getContinuous(ii)); + builder.append(actual.get(ii)); addComma = true; }