コード例 #1
0
  private void initProcessorIterator(Context context, Iterable<? extends Processor> processors) {
    Log log = Log.instance(context);
    Iterator<? extends Processor> processorIterator;

    if (options.isSet(XPRINT)) {
      try {
        Processor processor = PrintingProcessor.class.newInstance();
        processorIterator = List.of(processor).iterator();
      } catch (Throwable t) {
        AssertionError assertError = new AssertionError("Problem instantiating PrintingProcessor.");
        assertError.initCause(t);
        throw assertError;
      }
    } else if (processors != null) {
      processorIterator = processors.iterator();
    } else {
      String processorNames = options.get(PROCESSOR);
      JavaFileManager fileManager = context.get(JavaFileManager.class);
      try {
        // If processorpath is not explicitly set, use the classpath.
        processorClassLoader =
            fileManager.hasLocation(ANNOTATION_PROCESSOR_PATH)
                ? fileManager.getClassLoader(ANNOTATION_PROCESSOR_PATH)
                : fileManager.getClassLoader(CLASS_PATH);

        /*
         * If the "-processor" option is used, search the appropriate
         * path for the named class.  Otherwise, use a service
         * provider mechanism to create the processor iterator.
         */
        if (processorNames != null) {
          processorIterator = new NameProcessIterator(processorNames, processorClassLoader, log);
        } else {
          processorIterator = new ServiceIterator(processorClassLoader, log);
        }
      } catch (SecurityException e) {
        /*
         * A security exception will occur if we can't create a classloader.
         * Ignore the exception if, with hindsight, we didn't need it anyway
         * (i.e. no processor was specified either explicitly, or implicitly,
         * in service configuration file.) Otherwise, we cannot continue.
         */
        processorIterator = handleServiceLoaderUnavailability("proc.cant.create.loader", e);
      }
    }
    discoveredProcs = new DiscoveredProcessors(processorIterator);
  }
コード例 #2
0
 /**
  * Create a PropertyColumn from a property name, column name, row and column classes, and column
  * width. The render and editor default to null, and updateRow, updateSubsequentRows, and
  * updateTable all default to false.
  *
  * <p>This generates an editable column if a setter exists for this property, and a non-editable
  * property if the setter doesn't exist. For more complex behavior, override {@code
  * isEditable(_RowType)}
  *
  * @param pPropertyName The name of the property of instances of the specified row class
  * @param pColumnName The name of the column
  * @param pRowClass The class of the table row instances
  * @param pValueClass The class of the values of this column
  * @param pPrefWidth the preferred width of this column
  * @throws AssertionError if pRowClass doesn't have a getter for this property name.
  */
 public PropertyColumn(
     String pPropertyName,
     String pColumnName,
     Class pRowClass,
     Class pValueClass,
     int pPrefWidth) {
   super(pColumnName, getWrapper(pValueClass), pPrefWidth);
   try {
     mGetterMethod = generateGetter(pPropertyName, pRowClass, this);
   } catch (NoSuchMethodException e) {
     AssertionError err = new AssertionError(e.getMessage());
     err.initCause(e);
     throw err;
   }
   Method setter = null;
   try {
     setter = generateSetter(pPropertyName, pRowClass, this);
     setEditable(true);
   } catch (NoSuchMethodException nsme) {
     setEditable(false);
   }
   mSetterMethod = setter;
 }
コード例 #3
0
ファイル: OWLQNState.java プロジェクト: rikima/myowlqn
  /** 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();
    }
  }