Beispiel #1
0
  /** line search */
  private void backtrackingLineSearch() throws AssertionError {
    double origDirDeriv = dirDeriv();
    // if a non-descent direction is chosen, the line search will break anyway, so throw here
    // The most likely reason for this is a bug in your function's gradient computation

    try {
      assert origDirDeriv < 0;
    } catch (AssertionError ae) {
      ae.printStackTrace();
      stderr.println("!! L-BFGS chose a non-descent direction: check your gradient!");
      // System.exit(1);

      throw new AssertionError(ae.toString());
    }

    double alpha = 1.0;
    double backoff = 0.5;
    if (iter == 1) {
      double normDir = Math.sqrt(ArrayUtils.dot(dir, dir));
      alpha = (1 / normDir);
      backoff = 0.1;

      if (DEBUG || verbose) {
        stderr.println("alpha:" + alpha);
        stderr.println("normDir:" + normDir);
      }
    }

    double oldValue = value;
    boolean first = true;
    while (true) {

      getNextPoint(alpha);
      value = evalL1();

      if (DEBUG || verbose) {
        stderr.println("alpha:" + alpha);
        stderr.println("value:" + value);

        stderr.println("oldValue:" + oldValue);
        stderr.println("C1:" + C1);
        stderr.println("origDirDeriv:" + origDirDeriv);

        stderr.println("alpha:" + alpha);

        assert !Double.isNaN(value);
        assert !Double.isNaN(origDirDeriv);
      }

      if (!first && value <= (oldValue + C1 * origDirDeriv * alpha)) {
        break;
      }

      first = false;

      if (!quiet) {
        stderr.print(".");
      }

      alpha *= backoff;
    }

    if (!quiet) {
      stderr.println();
    }
  }
  BARControl(String[] args) {
    try {
      // load settings
      Settings.load();

      // parse arguments
      parseArguments(args);

      // init display
      display = new Display();

      // connect to server
      LoginData loginData = new LoginData(serverName, serverPort, serverTLSPort);
      boolean connectOkFlag = false;
      if ((loginData.serverName != null)
          && !loginData.serverName.equals("")
          && (loginData.password != null)
          && !loginData.password.equals("")
          && !loginDialogFlag) {
        // connect to server with preset data
        try {
          BARServer.connect(
              loginData.serverName,
              loginData.port,
              loginData.tlsPort,
              loginData.password,
              serverKeyFileName);
          connectOkFlag = true;
        } catch (ConnectionError error) {
        }
      }
      while (!connectOkFlag) {
        // get login data
        if (!getLoginData(loginData)) {
          System.exit(0);
        }
        if ((loginData.port == 0) && (loginData.tlsPort == 0)) {
          throw new Error("Cannot connect to server. No server ports specified!");
        }
        /// ??? host name scheck

        // connect to server
        try {
          BARServer.connect(
              loginData.serverName,
              loginData.port,
              loginData.tlsPort,
              loginData.password,
              serverKeyFileName);
          connectOkFlag = true;
        } catch (ConnectionError error) {
          if (!Dialogs.confirmError(
              new Shell(),
              "Connection fail",
              "Error: " + error.getMessage(),
              "Try again",
              "Cancel")) {
            System.exit(1);
          }
        }
      }

      // open main window
      createWindow();
      createTabs();
      createMenu();

      // run
      run();

      // disconnect
      BARServer.disconnect();

      // save settings
      Settings.save();
    } catch (org.eclipse.swt.SWTException exception) {
      System.err.println("ERROR graphics: " + exception.getCause());
      if (debug) {
        for (StackTraceElement stackTraceElement : exception.getStackTrace()) {
          System.err.println("  " + stackTraceElement);
        }
      }
    } catch (CommunicationError communicationError) {
      System.err.println("ERROR communication: " + communicationError.getMessage());
    } catch (AssertionError assertionError) {
      System.err.println("INTERNAL ERROR: " + assertionError.toString());
      for (StackTraceElement stackTraceElement : assertionError.getStackTrace()) {
        System.err.println("  " + stackTraceElement);
      }
      System.err.println("");
      System.err.println("Please report this assertion error to [email protected].");
    } catch (InternalError error) {
      System.err.println("INTERNAL ERROR: " + error.getMessage());
    } catch (Error error) {
      System.err.println("ERROR: " + error.getMessage());
      if (debug) {
        for (StackTraceElement stackTraceElement : error.getStackTrace()) {
          System.err.println("  " + stackTraceElement);
        }
      }
    }
  }
Beispiel #3
0
  @Test
  public void testSizeOf() throws Exception {
    Assume.assumeThat(
        CURRENT_JVM_INFORMATION.getMinimumObjectSize(),
        is(CURRENT_JVM_INFORMATION.getObjectAlignment()));

    SizeOf sizeOf = new CrossCheckingSizeOf();
    Assert.assertThat(deepSizeOf(sizeOf, TimeUnit.SECONDS), is(0L));
    Assert.assertThat(deepSizeOf(sizeOf, Object.class), is(0L));
    Assert.assertThat(deepSizeOf(sizeOf, 1), is(0L));
    Assert.assertThat(deepSizeOf(sizeOf, BigInteger.ZERO), is(0L));
    Assert.assertThat(deepSizeOf(sizeOf, BigDecimal.ZERO), is(0L));
    Assert.assertThat(deepSizeOf(sizeOf, MathContext.UNLIMITED), is(0L));
    Assert.assertThat(deepSizeOf(sizeOf, Locale.ENGLISH), is(0L));
    Assert.assertThat(deepSizeOf(sizeOf, Logger.global), is(0L));
    Assert.assertThat(deepSizeOf(sizeOf, Collections.EMPTY_SET), is(0L));
    Assert.assertThat(deepSizeOf(sizeOf, Collections.EMPTY_LIST), is(0L));
    Assert.assertThat(deepSizeOf(sizeOf, Collections.EMPTY_MAP), is(0L));
    Assert.assertThat(deepSizeOf(sizeOf, String.CASE_INSENSITIVE_ORDER), is(0L));
    Assert.assertThat(deepSizeOf(sizeOf, System.err), is(0L));
    Assert.assertThat(deepSizeOf(sizeOf, Proxy.NO_PROXY), is(0L));
    Assert.assertThat(deepSizeOf(sizeOf, CodingErrorAction.REPORT), is(0L));
    Assert.assertThat(deepSizeOf(sizeOf, DatatypeConstants.DAYS), is(0L));
    Assert.assertThat(deepSizeOf(sizeOf, DatatypeConstants.TIME), is(0L));

    assertThat(sizeOf.sizeOf(new Object()), "sizeOf(new Object())");
    assertThat(sizeOf.sizeOf(new Integer(1)), "sizeOf(new Integer(1))");
    assertThat(sizeOf.sizeOf(1000), "sizeOf(1000)");
    assertThat(deepSizeOf(sizeOf, new SomeClass(false)), "deepSizeOf(new SomeClass(false))");
    assertThat(deepSizeOf(sizeOf, new SomeClass(true)), "deepSizeOf(new SomeClass(true))");
    assertThat(sizeOf.sizeOf(new Object[] {}), "sizeOf(new Object[] { })");
    assertThat(
        sizeOf.sizeOf(new Object[] {new Object(), new Object(), new Object(), new Object()}),
        "sizeOf(new Object[] { new Object(), new Object(), new Object(), new Object() })");
    assertThat(sizeOf.sizeOf(new int[] {}), "sizeOf(new int[] { })");
    assertThat(
        sizeOf.sizeOf(new int[] {987654, 876543, 765432, 654321}),
        "sizeOf(new int[] { 987654, 876543, 765432, 654321 })");
    assertThat(deepSizeOf(sizeOf, new Pair(null, null)), "deepSizeOf(new Pair(null, null))");
    assertThat(
        deepSizeOf(sizeOf, new Pair(new Object(), null)),
        "deepSizeOf(new Pair(new Object(), null))");
    assertThat(
        deepSizeOf(sizeOf, new Pair(new Object(), new Object())),
        "deepSizeOf(new Pair(new Object(), new Object()))");
    assertThat(
        deepSizeOf(sizeOf, new ReentrantReadWriteLock()),
        "deepSizeOf(new ReentrantReadWriteLock())");

    if (!sizeOfFailures.isEmpty()) {
      StringBuilder sb = new StringBuilder();
      for (AssertionError e : sizeOfFailures) {
        sb.append(e.toString()).append('\n');
      }
      Assert.fail(sb.toString());
    }

    List<Object> list1 = new ArrayList<Object>();
    List<Object> list2 = new ArrayList<Object>();

    Object someInstance = new Object();
    list1.add(someInstance);
    list2.add(someInstance);

    Assert.assertThat(deepSizeOf(sizeOf, list1), is(deepSizeOf(sizeOf, list2)));
    Assert.assertThat(
        deepSizeOf(sizeOf, list1, list2) < (deepSizeOf(sizeOf, list1) + deepSizeOf(sizeOf, list2)),
        is(true));
    list2.add(new Object());
    Assert.assertThat(deepSizeOf(sizeOf, list2) > deepSizeOf(sizeOf, list1), is(true));
  }