@Override public void initialize(Parameters params) throws ResourceInitializationException { if (params.contains(Constants.LABELS)) { labels = loadLabels(((ResourceReader) params.get(Constants.LABELS)).getReader()); } else { throw new ResourceInitializationException("No labels provided."); } if (params.contains(Constants.THRESHOLD)) { threshold = params.getDouble(Constants.THRESHOLD); } }
@Override public void initialize(Parameters params) throws ResourceInitializationException { super.initialize(params); try { model = Model.load(((ResourceReader) params.get(Constants.MODEL)).getReader()); } catch (IOException e) { throw new ResourceInitializationException("Failed to load SVM model.", e); } labelIndeces = new int[labels.size()]; labelIndeces = model.getLabels(); representer = (TextRepresenter) params.get(Constants.REPRESENTER); }
@Override public void initialize(Parameters params) throws ResourceInitializationException { super.initialize(params); if (params.contains(Constants.REPRESENTER)) { representer = (TextRepresenter) params.get(Constants.REPRESENTER); } else { throw new ResourceInitializationException("No text representer specified."); } if (params.contains(Constants.FIND_BEST_PARAMETERS)) { findBestParameters = params.getBoolean(Constants.FIND_BEST_PARAMETERS); } else { gamma = 1.0 / (double) representer.getFeatures().size(); } if (params.contains(Constants.C)) { if (findBestParameters) { logger.warn("Finding best parameters. The specified C value will be ignored."); } else { c = params.getDouble(Constants.C); } } if (params.contains(Constants.WEIGHTS)) { // Parse weight specs weights = new TreeMap<Integer, Double>(); for (String piece : params.getString(Constants.WEIGHTS).split(",\\s*")) { String[] pair = piece.split(":"); if (pair.length != 2) { throw new ResourceInitializationException( "Invalid weight specs in " + params.getString(Constants.WEIGHTS)); } try { int i = Integer.parseInt(pair[0]); double w = Double.parseDouble(pair[1]); weights.put(i, w); } catch (Exception e) { throw new ResourceInitializationException( "Invalid weight specs in " + params.getString(Constants.WEIGHTS), e); } } } if (params.contains(Constants.GAMMA)) { if (findBestParameters) { logger.warn("Finding best parameters. The specified gamma value will be ignored."); } else { gamma = params.getDouble(Constants.GAMMA); } } if (params.contains(Constants.SAMPLE)) { if (findBestParameters) { sample = params.getDouble(Constants.SAMPLE); if (sample <= 0 || sample > 1) { throw new ResourceInitializationException("Invalid sample value " + sample); } } else { logger.warn( "Sample value valid for parameter optimization only. Provided sample value will be ignored."); } } if (params.contains(Constants.NUMBER_OF_THREADS)) { numberOfThreads = params.getInt(Constants.NUMBER_OF_THREADS); if (numberOfThreads < 1) { throw new ResourceInitializationException(Constants.NUMBER_OF_THREADS + " must be >= 1"); } } if (params.contains(Constants.TARGET_CLASS)) { targetClass = params.getString(Constants.TARGET_CLASS); logger.debug("Target Class: " + targetClass); } }