本文整理汇总了Java中com.feedzai.fos.api.FOSException类的典型用法代码示例。如果您正苦于以下问题:Java FOSException类的具体用法?Java FOSException怎么用?Java FOSException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FOSException类属于com.feedzai.fos.api包,在下文中一共展示了FOSException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMultipleModels
import com.feedzai.fos.api.FOSException; //导入依赖的package包/类
@Test
public void testMultipleModels() throws FOSException {
ModelConfig modelConfig = new ModelConfig();
modelConfig.setProperty(WekaModelConfig.CLASSIFIER_IMPL, Vote.class.getName());
modelConfig.setProperty(WekaModelConfig.CLASSIFIER_CONFIG, "-R MAX -B \""+J48.class.getName()+"\" -B \"" + NaiveBayes.class.getName() + "\"");
MultipleClassifiersCombiner classifier = (MultipleClassifiersCombiner)WekaClassifierFactory.create(modelConfig);
Assert.assertEquals(2,classifier.getClassifiers().length);
Assert.assertEquals(J48.class,classifier.getClassifiers()[0].getClass());
Assert.assertEquals(NaiveBayes.class,classifier.getClassifiers()[1].getClass());
}
示例2: removeModel
import com.feedzai.fos.api.FOSException; //导入依赖的package包/类
@Override
public synchronized void removeModel(UUID modelId) throws FOSException {
WekaModelConfig wekaModelConfig = modelConfigs.remove(modelId);
if (wekaModelConfig == null) {
logger.warn("Could not remove model with id {} because it does not exists", modelId);
return;
}
wekaScorer.removeModel(modelId);
if (wekaModelConfig.getModelConfig().isStoreModel()) {
// delete the header & model file (or else it will be picked up on the next restart)
wekaModelConfig.getHeader().delete();
// only delete if is in our header location
if (!wekaManagerConfig.getHeaderLocation().toURI().relativize(wekaModelConfig.getModel().toURI()).isAbsolute()) {
wekaModelConfig.getModel().delete();
}
}
logger.debug("Model {} removed", modelId);
}
示例3: reconfigureModel
import com.feedzai.fos.api.FOSException; //导入依赖的package包/类
@Override
public synchronized void reconfigureModel(UUID modelId, ModelConfig modelConfig, Model model) throws FOSException {
try {
File modelFile = createModelFile(wekaManagerConfig.getHeaderLocation(), modelId, model);
WekaModelConfig wekaModelConfig = this.modelConfigs.get(modelId);
wekaModelConfig.update(modelConfig);
ModelDescriptor descriptor = getModelDescriptor(model, modelFile);
wekaModelConfig.setModelDescriptor(descriptor);
wekaScorer.addOrUpdate(wekaModelConfig);
saveConfiguration();
logger.debug("Model {} reconfigured", modelId);
} catch (IOException e) {
throw new FOSException(e);
}
}
示例4: train
import com.feedzai.fos.api.FOSException; //导入依赖的package包/类
@Override
public Model train(ModelConfig config, List<Object[]> instances) throws FOSException {
checkNotNull(instances, "Instances must be supplied");
checkNotNull(config, "Config must be supplied");
long time = System.currentTimeMillis();
WekaModelConfig wekaModelConfig = new WekaModelConfig(config, wekaManagerConfig);
Classifier classifier = WekaClassifierFactory.create(config);
FastVector attributes = WekaUtils.instanceFields2Attributes(wekaModelConfig.getClassIndex(), config.getAttributes());
InstanceSetter[] instanceSetters = WekaUtils.instanceFields2ValueSetters(config.getAttributes(), InstanceType.TRAINING);
Instances wekaInstances = new Instances(config.getProperty(WekaModelConfig.CLASSIFIER_IMPL), attributes, instances.size());
for (Object[] objects : instances) {
wekaInstances.add(WekaUtils.objectArray2Instance(objects, instanceSetters, attributes));
}
trainClassifier(wekaModelConfig.getClassIndex(), classifier, wekaInstances);
final byte[] bytes = SerializationUtils.serialize(classifier);
logger.debug("Trained model with {} instances in {}ms", instances.size(), (System.currentTimeMillis() - time));
return new ModelBinary(bytes);
}
示例5: create
import com.feedzai.fos.api.FOSException; //导入依赖的package包/类
/**
* @param modelConfig model config should contain the wanted classifier
* @return instantiated classifier
* @throws FOSException if it has failed to create a classifier
*/
public static Classifier create(ModelConfig modelConfig) throws FOSException {
checkNotNull(modelConfig, "Model config cannot be null");
String classifierNames = modelConfig.getProperty(WekaModelConfig.CLASSIFIER_IMPL);
try {
Classifier classifier = (Classifier) Class.forName(modelConfig.getProperty(WekaModelConfig.CLASSIFIER_IMPL)).newInstance();
classifier.setOptions(weka.core.Utils.splitOptions(StringUtils.defaultString(modelConfig.getProperty(WekaModelConfig.CLASSIFIER_CONFIG))));
return classifier;
} catch (Exception e) {
throw new FOSException(e);
}
}
示例6: score
import com.feedzai.fos.api.FOSException; //导入依赖的package包/类
/**
* Score a single <code>scorable</code> with the given <code>modelId</code>.
*
* @param modelId the id of the model
* @param scorable the instance to score
* @return a list of scores with the same order as the scorable array
* @throws FOSException when classification was not possible
*/
@Override
@NotNull
public double[] score(UUID modelId, Object[] scorable) throws FOSException {
checkNotNull(scorable, "The scorable cannot be null");
try {
reloadModelsLock.readLock().lock();
WekaThreadSafeScorer wekaThreadSafeScorer = getScorer(modelId);
return wekaThreadSafeScorer.score(scorable);
} finally {
reloadModelsLock.readLock().unlock();
}
}
示例7: WekaThreadSafeScorerPool
import com.feedzai.fos.api.FOSException; //导入依赖的package包/类
/**
* Creates a new thread safe scorer from the given configuration parameters.
*
* @param wekaModelConfig the configuration of the model
* @param wekaManagerConfig the global configurations
* @throws FOSException when the underlying classifier could not be instantiated
*/
public WekaThreadSafeScorerPool(WekaModelConfig wekaModelConfig,WekaManagerConfig wekaManagerConfig) throws FOSException {
checkNotNull(wekaModelConfig, "Model config cannot be null");
checkNotNull(wekaManagerConfig, "Manager config cannot be null");
checkNotNull(wekaModelConfig.getAttributess(), "Model instances fields cannot be null");
checkArgument(wekaModelConfig.getAttributess().size() > 0, "Model must have at least one field");
this.poolConfig = new GenericObjectPoolConfig();
this.wekaManagerConfig = wekaManagerConfig;
this.wekaModelConfig = wekaModelConfig;
this.attributes = WekaUtils.instanceFields2Attributes(wekaModelConfig.getClassIndex(), wekaModelConfig.getAttributess());
this.instanceSetters = WekaUtils.instanceFields2ValueSetters(wekaModelConfig.getAttributess(), InstanceType.SCORING);
this.instances = new Instances(Integer.toString(this.wekaModelConfig.hashCode()), attributes, 0 /*this set is for scoring only*/);
this.instances.setClassIndex(wekaModelConfig.getClassIndex());
try {
BeanUtils.populate(poolConfig, this.wekaModelConfig.getPoolConfiguration());
this.pool = new AutoPopulateGenericObjectPool<>(new ClassifierFactory(wekaModelConfig.getModelDescriptor()), poolConfig);
} catch (Exception e) {
throw new FOSException(e);
}
}
示例8: score
import com.feedzai.fos.api.FOSException; //导入依赖的package包/类
/**
* The the given <code>Object[]</code> with this scorer (thread safe!).
* <p/>
* The score in bound by the configuration <code>minScore</code> and <code>maxScore</code>.
*
*
* @param scorable the scorable data to score
* @return the score value already bound the configuration range
* @throws FOSException when classification was not possible
*/
@Override
public double[] score(Object[] scorable) throws FOSException {
/* the pool can change while this is processing (reload) so assign a local variable */
final ObjectPool<Classifier> localPool = pool;
Classifier classifier = null;
try {
classifier = localPool.borrowObject();
return WekaUtils.score(classifier, scorable, instanceSetters, instances, attributes);
} catch (Exception e) {
throw new FOSException(e);
} finally {
returnObject(localPool, classifier);
}
}
示例9: Cloner
import com.feedzai.fos.api.FOSException; //导入依赖的package包/类
/**
* Creates a clonner by reading a serialized object from file.
*
* @param descriptor A {@link com.feedzai.fos.api.ModelDescriptor} with the information about the classifier.
* @throws IOException when there were problems reading the file
*/
public Cloner(ModelDescriptor descriptor) throws IOException {
checkNotNull(descriptor.getModelFilePath(), "Source file cannot be null");
File file = new File(descriptor.getModelFilePath());
checkArgument(file.exists(), "Source file '"+ file.getAbsolutePath() + "' must exist");
switch (descriptor.getFormat()) {
case BINARY:
this.serializedObject = FileUtils.readFileToByteArray(file);
break;
case PMML:
try {
this.serializedObject = SerializationUtils.serialize(PMMLConsumers.consume(file));
} catch (FOSException e) {
throw new RuntimeException("Failed to consume PMML file.", e);
}
break;
}
}
示例10: WekaThreadSafeScorerPassthrough
import com.feedzai.fos.api.FOSException; //导入依赖的package包/类
/**
* Creates a new thread safe scorer from the given configuration parameters.
*
* @param wekaModelConfig the configuration of the model
* @param wekaManagerConfig the global configurations
* @throws FOSException when the underlying classifier could not be instantiated
*/
public WekaThreadSafeScorerPassthrough(WekaModelConfig wekaModelConfig,WekaManagerConfig wekaManagerConfig) throws FOSException {
checkNotNull(wekaModelConfig, "Model config cannot be null");
checkNotNull(wekaManagerConfig, "Manager config cannot be null");
checkNotNull(wekaModelConfig.getAttributess(), "Model instances fields cannot be null");
checkArgument(wekaModelConfig.getAttributess().size() > 0, "Model must have at least one field");
this.wekaManagerConfig = wekaManagerConfig;
this.wekaModelConfig = wekaModelConfig;
this.attributes = WekaUtils.instanceFields2Attributes(wekaModelConfig.getClassIndex(), this.wekaModelConfig.getAttributess());
this.instanceSetters = WekaUtils.instanceFields2ValueSetters(wekaModelConfig.getAttributess(), InstanceType.SCORING);
this.instances = new Instances(Integer.toString(this.wekaModelConfig.hashCode()), attributes, 0 /*this set is for scoring only*/);
this.instances.setClassIndex(this.wekaModelConfig.getClassIndex());
try {
this.classifier = new Cloner<Classifier>(wekaModelConfig.getModelDescriptor()).get();
} catch (Exception e) {
throw new FOSException(e);
}
}
示例11: instanceField2AttributesTest
import com.feedzai.fos.api.FOSException; //导入依赖的package包/类
@Test
public void instanceField2AttributesTest() throws FOSException {
FastVector attributes = WekaUtils.instanceFields2Attributes(5, this.attributes);
Assert.assertEquals(this.attributes.size(), attributes.size());
Assert.assertNotNull(attributes.elementAt(0));
Assert.assertNotNull(attributes.elementAt(1));
Assert.assertNotNull(attributes.elementAt(2));
Assert.assertNotNull(attributes.elementAt(3));
Assert.assertNotNull(attributes.elementAt(4));
Assert.assertNotNull(attributes.elementAt(5));
Assert.assertNotNull(attributes.elementAt(6));
Assert.assertNotNull(attributes.elementAt(7));
Assert.assertTrue(((weka.core.Attribute) attributes.elementAt(0)).isNumeric());
Assert.assertTrue(((weka.core.Attribute) attributes.elementAt(1)).isNumeric());
Assert.assertTrue(((weka.core.Attribute) attributes.elementAt(2)).isNumeric());
Assert.assertTrue(((weka.core.Attribute) attributes.elementAt(3)).isNumeric());
Assert.assertTrue(((weka.core.Attribute) attributes.elementAt(4)).isNominal());
Assert.assertTrue(((weka.core.Attribute) attributes.elementAt(5)).isNominal());
Assert.assertTrue(((weka.core.Attribute) attributes.elementAt(6)).isString());
Assert.assertTrue(((weka.core.Attribute) attributes.elementAt(7)).isDate());
}
示例12: poolCreationTest
import com.feedzai.fos.api.FOSException; //导入依赖的package包/类
public void poolCreationTest() throws FOSException {
BaseConfiguration configuration = new BaseConfiguration();
configuration.setProperty(GenericObjectPoolConfig.class.getName() + ".minIdle", 10);
configuration.setProperty(GenericObjectPoolConfig.class.getName() + ".maxActive", 10);
configuration.setProperty(FosConfig.HEADER_LOCATION, "target/test-classes/models/threadsafe");
configuration.setProperty(FosConfig.FACTORY_NAME, WekaManagerFactory.class.getName());
WekaManagerConfig wekaManagerConfig = new WekaManagerConfig(new FosConfig(configuration));
WekaManager wekaManager = new WekaManager(wekaManagerConfig);
WekaScorer wekaScorer = wekaManager.getScorer();
double[] score = wekaScorer.score(Lists.newArrayList(testUUID), new Object[]{1.5, 0, "gray", "positive"}).get(0);
assertEquals(2, score.length);
assertEquals(1.0, score[0] + score[1], 0.001);
Assert.assertTrue(((Map<Integer, WekaThreadSafeScorer>) Whitebox.getInternalState(wekaScorer, "wekaThreadSafeScorers")).get(testUUID) instanceof WekaThreadSafeScorerPool);
wekaManager.close();
}
示例13: load
import com.feedzai.fos.api.FOSException; //导入依赖的package包/类
@Override
public void load(String script) throws FOSException {
try {
File file = new File(script);
if (!file.exists()) {
throw new FOSException("Error loading script '" + script + "' into R (script not found).");
}
if (!file.isFile()) {
throw new FOSException("Error loading script '" + script + "' into R (unsupported file type).");
}
// read file
String contents = Files.toString(new File(script), Charsets.UTF_8);
// strip all CR because R in Windows does not like them
contents = contents.replaceAll("\r\n", "\n");
// evaluate script
eval(contents);
} catch (IOException e) {
throw new FOSException("Error loading script '" + script + "' into R.", e);
}
}
示例14: assignStringList
import com.feedzai.fos.api.FOSException; //导入依赖的package包/类
@Override
public void assignStringList(String varname, String rEnvironment, List<String> values) throws FOSException {
StringBuilder sb = new StringBuilder();
sb.append(rEnvironment)
.append('$')
.append(RScorer.rVariableName(varname))
.append(" <- c(\n");
int i = 0;
while(i < values.size() - 1) {
sb.append(" '").append(values.get(i++)).append("',\n");
}
sb.append(" '").append(values.get(i)).append("')");
eval(sb.toString());
}
示例15: assignIntList
import com.feedzai.fos.api.FOSException; //导入依赖的package包/类
@Override
public void assignIntList(String varname, String rEnvironment, List<Integer> values) throws FOSException {
StringBuilder sb = new StringBuilder();
sb.append(rEnvironment)
.append('$')
.append(varname)
.append(" <- c(\n");
int i = 0;
while(i < values.size() - 1) {
sb.append(" ").append(values.get(i++)).append(",\n");
}
sb.append(" ").append(values.get(i)).append(")");
eval(sb.toString());
}