public void TestEncodeUnrelatedAreas() { double avgThreshold = 0.3; double maxThreshold = 0.14; CoordinateEncoder.ResetRandomGenerator(); double[] overlaps = OverlapsForUnrelatedAreas(1499, 37, 5, 100, false); double maxOverlaps = ArrayUtils.Max(overlaps); Debug.WriteLine("Max overlaps = " + maxOverlaps); Assert.IsTrue(maxOverlaps < maxThreshold); Assert.IsTrue(ArrayUtils.Average(overlaps) < avgThreshold); maxThreshold = 0.12; overlaps = OverlapsForUnrelatedAreas(1499, 37, 10, 100, false); maxOverlaps = ArrayUtils.Max(overlaps); Debug.WriteLine("Max overlaps = " + maxOverlaps); Assert.IsTrue(maxOverlaps < maxThreshold); Assert.IsTrue(ArrayUtils.Average(overlaps) < avgThreshold); maxThreshold = 0.13; overlaps = OverlapsForUnrelatedAreas(999, 25, 10, 100, false); maxOverlaps = ArrayUtils.Max(overlaps); Debug.WriteLine("Max overlaps = " + maxOverlaps); Assert.IsTrue(maxOverlaps < maxThreshold); Assert.IsTrue(ArrayUtils.Average(overlaps) < avgThreshold); maxThreshold = 0.16; overlaps = OverlapsForUnrelatedAreas(499, 13, 10, 100, false); maxOverlaps = ArrayUtils.Max(overlaps); Debug.WriteLine("Max overlaps = " + maxOverlaps); Assert.IsTrue(maxOverlaps < maxThreshold); Assert.IsTrue(ArrayUtils.Average(overlaps) < avgThreshold); }
private void SetUp() { builder = (CoordinateEncoder.Builder)CoordinateEncoder.GetBuilder() .Name("coordinate") .N(33) .W(3); }
public void TestTopWCoordinates() { int[][] coordinates = new[] { new[] { 1 }, new[] { 2 }, new[] { 3 }, new[] { 4 }, new[] { 5 } }; //ICoordinateOrder mock = new CoordinateOrder() { // @Override public double orderForCoordinate(int[] coordinate) // { // return ArrayUtils.sum(coordinate) / 5.0d; // } //}; var mock = new Mock <ICoordinateOrder>(); mock.Setup(co => co.OrderForCoordinate(It.IsAny <int[]>())) .Returns <int[]>(coordinate => ArrayUtils.Sum(coordinate) / 5.0d); int[][] top = new CoordinateEncoder().TopWCoordinates(mock.Object, coordinates, 2); Assert.AreEqual(2, top.Length); Assert.IsTrue(Arrays.AreEqual(new[] { 4 }, top[0])); Assert.IsTrue(Arrays.AreEqual(new[] { 5 }, top[1])); }
public void TestEncodeRelativePositions() { CoordinateEncoder.ResetRandomGenerator(); // As you get farther from a coordinate, the overlap should decrease double[] overlaps = OverlapsForRelativeAreas(999, 25, new[] { 100, 200 }, 10, new[] { 2, 2 }, 0, 5, false); AssertDecreasingOverlaps(overlaps); }
public void TestNeighbors0Radius() { CoordinateEncoder ce = new CoordinateEncoder(); int[] coordinate = new[] { 100, 200, 300 }; int radius = 0; List <int[]> neighbors = ce.Neighbors(coordinate, radius); Assert.AreEqual(1, neighbors.Count); Assert.IsTrue(ArrayUtils.Contains(new[] { 100, 200, 300 }, neighbors)); }
public void TestNeighbors1D() { CoordinateEncoder ce = new CoordinateEncoder(); int[] coordinate = { 100 }; int radius = 5; List <int[]> neighbors = ce.Neighbors(coordinate, radius); Assert.AreEqual(11, neighbors.Count); Assert.IsTrue(Arrays.AreEqual(new[] { 95 }, neighbors[0])); Assert.IsTrue(Arrays.AreEqual(new[] { 100 }, neighbors[5])); Assert.IsTrue(Arrays.AreEqual(new[] { 105 }, neighbors[10])); }
public void TestEncodeSaturateArea() { SetUp(); builder.N(1999); builder.W(25); builder.Radius(2); InitCe(); CoordinateEncoder.ResetRandomGenerator(); int[] outputA = Encode(ce, new[] { 0, 0 }, 2); int[] outputB = Encode(ce, new[] { 0, 1 }, 2); Assert.AreEqual(0.8, Overlap(outputA, outputB), 0.019); }
public void TestEncodeIntoArray() { SetUp(); builder.N(33); builder.W(3); InitCe(); CoordinateEncoder.ResetRandomGenerator(); int[] coordinate = new[] { 100, 200 }; int[] output1 = Encode(ce, coordinate, 5); Assert.AreEqual(ArrayUtils.Sum(output1), ce.GetW()); int[] output2 = Encode(ce, coordinate, 5); Assert.IsTrue(Arrays.AreEqual(output1, output2)); }
public void TestOrderForCoordinate() { CoordinateEncoder c = new CoordinateEncoder(); double h1 = c.OrderForCoordinate(new[] { 2, 5, 10 }); double h2 = c.OrderForCoordinate(new[] { 2, 5, 11 }); double h3 = c.OrderForCoordinate(new[] { 2497477, -923478 }); Assert.IsTrue(0 <= h1 && h1 < 1); Assert.IsTrue(0 <= h2 && h2 < 1); Assert.IsTrue(0 <= h3 && h3 < 1); Console.WriteLine(h1 + ", " + h2 + ", " + h3); Assert.AreNotEqual(h1, h2); Assert.AreNotEqual(h2, h3); }
public void TestBitForCoordinate() { CoordinateEncoder ce = new CoordinateEncoder(); int n = 1000; double b1 = ce.BitForCoordinate(new[] { 2, 5, 10 }, n); double b2 = ce.BitForCoordinate(new[] { 2, 5, 11 }, n); double b3 = ce.BitForCoordinate(new[] { 2497477, -923478 }, n); Assert.IsTrue(0 <= b1 && b1 < n); Assert.IsTrue(0 <= b2 && b2 < n); Assert.IsTrue(0 <= b3 && b3 < n); Assert.AreNotEqual(b1, b2); Assert.AreNotEqual(b2, b3); // Small n n = 2; double b4 = ce.BitForCoordinate(new[] { 5, 10 }, n); Assert.IsTrue(0 <= b4 && b4 < n); }
/** * Returns the {@link Encoder} matching this field type. * @return */ public IEncoder NewEncoder(FieldMetaType type) { switch (type) { case FieldMetaType.List: case FieldMetaType.String: return(SDRCategoryEncoder.GetBuilder().Build()); case FieldMetaType.DateTime: return(DateEncoder.GetBuilder().Build()); case FieldMetaType.Boolean: return(ScalarEncoder.GetBuilder().Build()); case FieldMetaType.Coord: return(CoordinateEncoder.GetBuilder().Build()); case FieldMetaType.Geo: return(GeospatialCoordinateEncoder.GetGeobuilder().Build()); case FieldMetaType.Integer: case FieldMetaType.Float: return(RandomDistributedScalarEncoder.GetBuilder().Build()); case FieldMetaType.DenseArray: case FieldMetaType.SparseArray: return(SDRPassThroughEncoder.GetSptBuilder().Build()); default: return(null); } }
public int[] Encode(CoordinateEncoder encoder, double[] coordinate, double radius) { int[] output = new int[encoder.GetWidth()]; encoder.EncodeIntoArray(new Tuple(coordinate[0], coordinate[1], radius), output); return(output); }
public void TestTopStrict() { int[][] input = new[] { new[] { 95, 195 }, new[] { 95, 196 }, new[] { 95, 197 }, new[] { 95, 198 }, new[] { 95, 199 }, new[] { 95, 200 }, new[] { 95, 201 }, new[] { 95, 202 }, new[] { 95, 203 }, new[] { 95, 204 }, new[] { 95, 205 }, new[] { 96, 195 }, new[] { 96, 196 }, new[] { 96, 197 }, new[] { 96, 198 }, new[] { 96, 199 }, new[] { 96, 200 }, new[] { 96, 201 }, new[] { 96, 202 }, new[] { 96, 203 }, new[] { 96, 204 }, new[] { 96, 205 }, new[] { 97, 195 }, new[] { 97, 196 }, new[] { 97, 197 }, new[] { 97, 198 }, new[] { 97, 199 }, new[] { 97, 200 }, new[] { 97, 201 }, new[] { 97, 202 }, new[] { 97, 203 }, new[] { 97, 204 }, new[] { 97, 205 }, new[] { 98, 195 }, new[] { 98, 196 }, new[] { 98, 197 }, new[] { 98, 198 }, new[] { 98, 199 }, new[] { 98, 200 }, new[] { 98, 201 }, new[] { 98, 202 }, new[] { 98, 203 }, new[] { 98, 204 }, new[] { 98, 205 }, new[] { 99, 195 }, new[] { 99, 196 }, new[] { 99, 197 }, new[] { 99, 198 }, new[] { 99, 199 }, new[] { 99, 200 }, new[] { 99, 201 }, new[] { 99, 202 }, new[] { 99, 203 }, new[] { 99, 204 }, new[] { 99, 205 }, new[] { 100, 195 }, new[] { 100, 196 }, new[] { 100, 197 }, new[] { 100, 198 }, new[] { 100, 199 }, new[] { 100, 200 }, new[] { 100, 201 }, new[] { 100, 202 }, new[] { 100, 203 }, new[] { 100, 204 }, new[] { 100, 205 }, new[] { 101, 195 }, new[] { 101, 196 }, new[] { 101, 197 }, new[] { 101, 198 }, new[] { 101, 199 }, new[] { 101, 200 }, new[] { 101, 201 }, new[] { 101, 202 }, new[] { 101, 203 }, new[] { 101, 204 }, new[] { 101, 205 }, new[] { 102, 195 }, new[] { 102, 196 }, new[] { 102, 197 }, new[] { 102, 198 }, new[] { 102, 199 }, new[] { 102, 200 }, new[] { 102, 201 }, new[] { 102, 202 }, new[] { 102, 203 }, new[] { 102, 204 }, new[] { 102, 205 }, new[] { 103, 195 }, new[] { 103, 196 }, new[] { 103, 197 }, new[] { 103, 198 }, new[] { 103, 199 }, new[] { 103, 200 }, new[] { 103, 201 }, new[] { 103, 202 }, new[] { 103, 203 }, new[] { 103, 204 }, new[] { 103, 205 }, new[] { 104, 195 }, new[] { 104, 196 }, new[] { 104, 197 }, new[] { 104, 198 }, new[] { 104, 199 }, new[] { 104, 200 }, new[] { 104, 201 }, new[] { 104, 202 }, new[] { 104, 203 }, new[] { 104, 204 }, new[] { 104, 205 }, new[] { 105, 195 }, new[] { 105, 196 }, new[] { 105, 197 }, new[] { 105, 198 }, new[] { 105, 199 }, new[] { 105, 200 }, new[] { 105, 201 }, new[] { 105, 202 }, new[] { 105, 203 }, new[] { 105, 204 }, new[] { 105, 205 } }; CoordinateEncoder.ResetRandomGenerator(); CoordinateEncoder c = new CoordinateEncoder(); int[][] results = c.TopWCoordinates(c, input, 3); int[][] expected = new[] { new[] { 99, 196 }, new[] { 100, 195 }, new[] { 97, 202 } }; for (int i = 0; i < results.Length; i++) { Assert.IsTrue(Arrays.AreEqual(results[i], expected[i]), "Failure on array " + i + " expected: " + Arrays.ToString(expected[i]) + " actual: " + Arrays.ToString(results[i])); } Console.WriteLine("done"); }
private void InitCe() { ce = (CoordinateEncoder)builder.Build(); }