예제 #1
0
  /** Test a column matrix. */
  @Test
  public void testSmallDeviations() {
    System.out.println("testSmallDeviations");

    // run nearest point test by making small deviations (del) to lattice points.
    int iters = 10;
    Random r = new Random();
    double del = 0.0001;
    for (int t = 0; t < iters; t++) {
      int n = r.nextInt(10) + 5;
      LatticeAndNearestPointAlgorithm lattice = new AnstarSorted(n - 1);
      Matrix G = lattice.getGeneratorMatrix();

      Babai babai = new Babai();
      babai.setLattice(lattice);

      // System.out.println("G is " + G.getRowDimension() + " by " + G.getColumnDimension());
      double[] x = new double[G.getRowDimension()];
      double[] xdel = new double[G.getRowDimension()];
      double[] u = VectorFunctions.randomIntegerVector(n, 1000);

      // System.out.println("u is length " + u.length + ", x is length"  + x.length);

      VectorFunctions.matrixMultVector(G, u, x);
      for (int i = 0; i < x.length; i++) {
        xdel[i] = x[i] + r.nextGaussian() * del;
      }

      babai.nearestPoint(xdel);
      double dist = VectorFunctions.distance_between(babai.getLatticePoint(), x);
      System.out.println(dist);
      assertEquals(true, dist < 0.00001);
    }
  }
예제 #2
0
파일: MbestTest.java 프로젝트: ivlc/pubsim
  /** Test a column matrix. */
  @Test
  public void testBeatsOrEqualsBabai() {
    System.out.println("testBeatsOrEqualsBabai");

    // run nearest point test by making small deviations (del) to lattice points.
    int iters = 100;
    Random r = new Random();
    double del = 1000.0;
    for (int t = 0; t < iters; t++) {
      int n = r.nextInt(100) + 5;
      Lattice lattice = new GeneralLattice(Matrix.random(n, n));
      Matrix G = lattice.getGeneratorMatrix();

      Mbest instance = new Mbest(lattice, n);
      Babai babai = new Babai(lattice);

      // System.out.println("G is " + G.getRowDimension() + " by " + G.getColumnDimension());
      double[] x = new double[G.getRowDimension()];
      double[] xdel = new double[G.getRowDimension()];
      double[] u = new double[n];
      for (int i = 0; i < n; i++) {
        u[i] = r.nextDouble();
      }
      VectorFunctions.matrixMultVector(G, u, xdel);

      instance.nearestPoint(xdel);
      babai.nearestPoint(xdel);
      double instdist = VectorFunctions.distance_between2(instance.getLatticePoint(), xdel);
      double babaidist = VectorFunctions.distance_between2(babai.getLatticePoint(), xdel);

      System.out.println(babaidist + ", " + instdist);
      // System.out.println(VectorFunctions.print(babai.getIndex()));
      assertTrue(instdist <= babaidist);
    }
  }
  @Test
  public void testDisambiguate() {
    System.out.println("testDisambiguate");
    double[] p1 = {1.3, -2.1};
    int m = p1.length - 1;
    AmbiguityRemover instance = new AmbiguityRemover(m);
    p1 = instance.disambiguate(p1);
    double[] y1 = {0.3, -0.1};
    assertTrue(VectorFunctions.distance_between2(p1, y1) < 0.000001);

    double[] p2 = {1.3, -2.1, 2.6};
    m = p2.length - 1;
    instance = new AmbiguityRemover(m);
    p2 = instance.disambiguate(p2);
    double[] y2 = {0.3, 0.4, 0.1};
    assertTrue(VectorFunctions.distance_between2(p2, y2) < 0.000001);
  }
  @Override
  public final double[] closestPoint(double[] y) {
    if (n != y.length - 1) throw new RuntimeException("y is the wrong length");

    Anstar.project(y, y);

    VectorFunctions.round(y, u);
    double m = VectorFunctions.sum(u);
    for (int i = 0; i < n + 1; i++) {
      z[i].value = Math.signum(m) * (y[i] - u[i]);
      z[i].index = i;
    }

    Arrays.sort(z);
    for (int i = 0; i < Math.abs(m); i++) u[z[i].index] -= Math.signum(m);

    return u;
  }
예제 #5
0
  /** Test of FloydRivestSelect method, of class FastSelection. */
  @Test
  public void FloydRivestSelect() {
    System.out.println("FloydRivestSelect");

    int iters = 100;
    Random r = new Random();

    for (int j = 1; j < iters; j++) {

      double[] A = VectorFunctions.randomGaussian(iters * 10);
      int L = 0;
      int R = A.length - 1;
      int K = r.nextInt(A.length);
      double result = FastSelection.FloydRivestSelect(L, R, K, A);
      // assertEquals(expResult, result);
      for (int i = 0; i < K; i++) {
        assertTrue(A[i] <= A[K]);
      }
      for (int i = K + 1; i < A.length; i++) {
        assertTrue(A[i] >= A[K]);
      }
    }

    for (int j = 1; j < iters; j++) {

      double[] A = VectorFunctions.randomGaussian(iters * 10);
      Double[] Ac = new Double[A.length];
      for (int i = 0; i < A.length; i++) Ac[i] = new Double(A[i]);

      int L = 0;
      int R = A.length - 1;
      int K = r.nextInt(A.length);
      FastSelection.FloydRivestSelect(L, R, K, Ac);
      // assertEquals(expResult, result);
      for (int i = 0; i < K; i++) {
        assertTrue(Ac[i].compareTo(Ac[K]) <= 0);
      }
      for (int i = K + 1; i < A.length; i++) {
        assertTrue(Ac[i].compareTo(Ac[K]) >= 0);
      }
    }
  }
  /** Test of setSize method, of class AmbiguityRemover. */
  @Test
  public void testNextColumn() {
    System.out.println("testNextColumn");
    double[] c = VectorFunctions.eVector(0, 1);
    // System.out.println("c = " + VectorFunctions.print(c));
    c = AmbiguityRemover.getNextColumn(c);
    // System.out.println("c = " + VectorFunctions.print(c));
    double[] y1 = {0, 1};
    assertTrue(VectorFunctions.distance_between2(c, y1) < 0.000001);

    c = AmbiguityRemover.getNextColumn(c);
    // System.out.println("c = " + VectorFunctions.print(c));
    double[] y2 = {0, 1.0 / 2.0, 1.0 / 2.0};
    assertTrue(VectorFunctions.distance_between2(c, y2) < 0.000001);

    c = AmbiguityRemover.getNextColumn(c);
    // System.out.println("c = " + VectorFunctions.print(c));
    double[] y3 = {0, 1.0 / 3.0, 1.0 / 2.0, 1.0 / 6};
    assertTrue(VectorFunctions.distance_between2(c, y3) < 0.000001);
  }
예제 #7
0
 public double getCRB() {
   double p = h / var;
   AllPAMSymbolGenerator gen = new AllPAMSymbolGenerator();
   double bestcrb = Double.NEGATIVE_INFINITY;
   double[] d = new double[T];
   for (int i = 0; i < Math.pow(M, T); i++) {
     double[] nextsym = gen.getNext();
     // System.out.println(nextsym.length);
     for (int j = 0; j < T; j++) {
       d[j] = x[j] - nextsym[j];
     }
     double magd2 = VectorFunctions.sum2(d);
     if (magd2 > 0.5) {
       double std = VectorFunctions.dot(x, d);
       double crb = var / (magx2 - p * std * std / Math.expm1(p * magd2));
       if (crb > bestcrb) bestcrb = crb;
     }
   }
   return bestcrb;
 }
예제 #8
0
  /** Babai's algorithm should work perfectly for Zn. This tests that it does. */
  @Test
  public void returnsCorrectForZn() {
    System.out.println("returnsCorrectForZn");
    double[] y = {1.1, 2.2, 3.9, -4.1, -100.49};
    Babai babai = new Babai();
    // construc the integer lattice
    Zn lattice = new Zn(y.length);

    babai.setLattice(lattice);

    lattice.nearestPoint(y);
    double[] xtrue = lattice.getLatticePoint();
    double[] utrue = lattice.getIndex();

    babai.nearestPoint(y);
    double[] xtest = babai.getLatticePoint();
    double[] utest = babai.getIndex();

    System.out.println(VectorFunctions.print(xtrue));
    System.out.println(VectorFunctions.print(xtest));

    assertTrue(VectorFunctions.distance_between(utest, utrue) < 0.00001);
    assertTrue(VectorFunctions.distance_between(xtest, xtrue) < 0.00001);
    assertTrue(VectorFunctions.distance_between(utest, xtrue) < 0.00001);
    assertTrue(VectorFunctions.distance_between(xtest, utrue) < 0.00001);
  }
예제 #9
0
  @Before
  public void setUp() {
    int length = 1500;

    double[] A = VectorFunctions.randomGaussian(length);
    Vector<Double> Ac = new Vector<Double>();
    for (int i = 0; i < A.length; i++) Ac.add(A[i]);

    Random r = new Random();
    k = r.nextInt(A.length);
    elem = (Double) instance.select(k, Ac);

    System.out.println("k = " + k + ", elem = " + elem);
  }
  /** Test of generateReceivedSignal method, of class simulator.qam.FadingNoisyQAM. */
  public void testGenerateReceivedSignal() {
    System.out.println("generateReceivedSignal");

    FadingNoisyQAM instance = new FadingNoisyQAM();
    double[] xr = {1.0, 2.0, -2.0};
    double[] xi = {1.0, -3.0, 1.0};
    instance.setChannel(-0.4326, -1.6656);

    RealRandomVariable noise = new pubsim.distributions.UniformNoise(0.0, 0.0);
    instance.setNoiseGenerator(noise);

    instance.setTransmittedSignal(xr, xi);

    double[] expr = {1.2330, -5.8620, 2.5308};
    double[] expi = {-2.0982, -2.0334, 2.8986};
    instance.generateReceivedSignal();

    System.out.println(VectorFunctions.print(instance.getInphase()));
    System.out.println(VectorFunctions.print(instance.getQuadrature()));

    assertEquals(true, VectorFunctions.distance_between(expr, instance.getInphase()) < 0.00001);
    assertEquals(true, VectorFunctions.distance_between(expi, instance.getQuadrature()) < 0.00001);
  }