Search in sources :

Example 11 with PropertyException

use of com.oracle.labs.mlrg.olcut.config.PropertyException in project tribuo by oracle.

the class DemoLabelDataSource method postConfig.

/**
 * Configures the class. Should be called in sub-classes' postConfigs
 * after they've validated their parameters.
 */
@Override
public void postConfig() {
    if (numSamples < 1) {
        throw new PropertyException("", "numSamples", "Number of samples must be positive, found " + numSamples);
    }
    this.rng = new Random(seed);
    this.examples = Collections.unmodifiableList(generate());
}
Also used : Random(java.util.Random) PropertyException(com.oracle.labs.mlrg.olcut.config.PropertyException)

Example 12 with PropertyException

use of com.oracle.labs.mlrg.olcut.config.PropertyException in project tribuo by oracle.

the class BinaryResponseProcessor method postConfig.

@Override
public void postConfig() {
    /*
         * Canonically all internal logic is driven by fieldNames and positiveResponses, so this method takes values
         * populated in fieldName and positiveResponse and sets them appropriately.
         */
    boolean bothFieldNamesPopulated = fieldName != null && fieldNames != null;
    boolean neitherFieldNamesPopulated = fieldName == null && fieldNames == null;
    boolean multipleFieldNamesPopulated = fieldNames != null;
    boolean singleFieldNamePopulated = fieldName != null;
    boolean bothPositiveResponsesPopulated = positiveResponses != null && positiveResponse != null;
    boolean neitherPositiveResponsesPopulated = positiveResponse == null && positiveResponses == null;
    boolean multiplePositiveResponsesPopulated = positiveResponses != null;
    boolean singlePositiveResponsePopulated = positiveResponse != null;
    if (bothFieldNamesPopulated || neitherFieldNamesPopulated) {
        throw new PropertyException(configName, "fieldName, FieldNames", "exactly one of fieldName or fieldNames must be populated");
    } else if (bothPositiveResponsesPopulated || neitherPositiveResponsesPopulated) {
        throw new PropertyException(configName, "positiveResponse, positiveResponses", "exactly one of positiveResponse or positiveResponses must be populated");
    } else if (multipleFieldNamesPopulated && multiplePositiveResponsesPopulated && fieldNames.size() != positiveResponses.size()) {
        // sizes don't match
        throw new PropertyException(configName, "positiveResponses", "must match the length of fieldNames");
    } else if (multipleFieldNamesPopulated && singlePositiveResponsePopulated) {
        positiveResponses = Collections.nCopies(fieldNames.size(), positiveResponse);
        positiveResponse = null;
    } else if (singleFieldNamePopulated && multiplePositiveResponsesPopulated) {
        throw new PropertyException(configName, "positiveResponses", "if fieldName is populated, positiveResponses must be blank");
    } else if (singleFieldNamePopulated && singlePositiveResponsePopulated) {
        fieldNames = Collections.singletonList(fieldName);
        fieldName = null;
        positiveResponses = Collections.singletonList(positiveResponse);
        positiveResponse = null;
    }
// the case where both positiveResponses and fieldNames are populated and their sizes match requires no action
}
Also used : PropertyException(com.oracle.labs.mlrg.olcut.config.PropertyException)

Example 13 with PropertyException

use of com.oracle.labs.mlrg.olcut.config.PropertyException in project tribuo by oracle.

the class FieldResponseProcessor method postConfig.

@Override
public void postConfig() {
    /*
         * Canonically all internal logic is driven by
         * fieldNames and defaultValues, so this method takes values populated in fieldName and defaultValue and sets them
         * appropriately.
         */
    boolean bothFieldNamesPopulated = fieldName != null && fieldNames != null;
    boolean neitherFieldNamesPopulated = fieldName == null && fieldNames == null;
    boolean multipleFieldNamesPopulated = fieldNames != null;
    boolean singleFieldNamePopulated = fieldName != null;
    boolean bothDefaultValuesPopulated = defaultValues != null && defaultValue != null;
    boolean neitherDefaultValuesPopulated = defaultValue == null && defaultValues == null;
    boolean multipleDefaultValuesPopulated = defaultValues != null;
    boolean singleDefaultValuePopulated = defaultValue != null;
    if (bothFieldNamesPopulated || neitherFieldNamesPopulated) {
        throw new PropertyException(configName, "fieldName, FieldNames", "exactly one of fieldName or fieldNames must be populated");
    } else if (bothDefaultValuesPopulated || neitherDefaultValuesPopulated) {
        throw new PropertyException(configName, "defaultValue, defaultValues", "exactly one of defaultValue or defaultValues must be populated");
    } else if (multipleFieldNamesPopulated && multipleDefaultValuesPopulated && fieldNames.size() != defaultValues.size()) {
        // sizes don't match
        throw new PropertyException(configName, "defaultValues", "must match the length of fieldNames");
    } else if (multipleFieldNamesPopulated && singleDefaultValuePopulated) {
        defaultValues = Collections.nCopies(fieldNames.size(), defaultValue);
        defaultValue = null;
    } else if (singleFieldNamePopulated && multipleDefaultValuesPopulated) {
        throw new PropertyException(configName, "defaultValues", "if fieldName is populated, defaultValues must be blank");
    } else if (singleFieldNamePopulated && singleDefaultValuePopulated) {
        fieldNames = Collections.singletonList(fieldName);
        fieldName = null;
        defaultValues = Collections.singletonList(defaultValue);
        defaultValue = null;
    }
// the case where both defaultValues and fieldNames are populated and their sizes match requires no action
}
Also used : PropertyException(com.oracle.labs.mlrg.olcut.config.PropertyException)

Example 14 with PropertyException

use of com.oracle.labs.mlrg.olcut.config.PropertyException in project tribuo by oracle.

the class IDXDataSourceTest method testFileNotFound.

@Test
public void testFileNotFound() throws IOException {
    // First check that the configuration system throws out of postConfig
    ConfigurationManager cm = new ConfigurationManager("/org/tribuo/datasource/config.xml");
    try {
        // this config file is in the tests, we know the type
        @SuppressWarnings("unchecked") IDXDataSource<MockOutput> tmp = (IDXDataSource<MockOutput>) cm.lookup("train");
        fail("Should have thrown PropertyException");
    } catch (PropertyException e) {
        if (!e.getMessage().contains("Failed to load from path - ")) {
            fail("Incorrect exception message", e);
        }
    } catch (RuntimeException e) {
        fail("Incorrect exception thrown", e);
    }
    // Next check the constructor throws
    MockOutputFactory factory = new MockOutputFactory();
    try {
        IDXDataSource<MockOutput> tmp = new IDXDataSource<>(Paths.get("these-features-dont-exist"), Paths.get("these-outputs-dont-exist"), factory);
        fail("Should have thrown FileNotFoundException");
    } catch (FileNotFoundException e) {
        if (!e.getMessage().contains("Failed to load from path - ")) {
            fail("Incorrect exception message", e);
        }
    }
}
Also used : MockOutput(org.tribuo.test.MockOutput) PropertyException(com.oracle.labs.mlrg.olcut.config.PropertyException) MockOutputFactory(org.tribuo.test.MockOutputFactory) FileNotFoundException(java.io.FileNotFoundException) ConfigurationManager(com.oracle.labs.mlrg.olcut.config.ConfigurationManager) Test(org.junit.jupiter.api.Test)

Example 15 with PropertyException

use of com.oracle.labs.mlrg.olcut.config.PropertyException in project tribuo by oracle.

the class GaussianDataSource method postConfig.

/**
 * Used by the OLCUT configuration system, and should not be called by external code.
 */
@Override
public void postConfig() {
    // We use java.util.Random here because SplittableRandom doesn't have nextGaussian yet.
    Random rng = new Random(seed);
    List<Example<Regressor>> examples = new ArrayList<>(numSamples);
    if (xMax <= xMin) {
        throw new PropertyException("", "xMax", "xMax must be greater than xMin, found xMax = " + xMax + ", xMin = " + xMin);
    }
    if (variance <= 0.0) {
        throw new PropertyException("", "variance", "Variance must be positive, found variance = " + variance);
    }
    double range = xMax - xMin;
    for (int i = 0; i < numSamples; i++) {
        double input = (rng.nextDouble() * range) + xMin;
        Regressor output = new Regressor("Y", (rng.nextGaussian() * variance) + ((slope * input) + intercept));
        ArrayExample<Regressor> e = new ArrayExample<>(output, new String[] { "X" }, new double[] { input });
        examples.add(e);
    }
    this.examples = Collections.unmodifiableList(examples);
}
Also used : ArrayExample(org.tribuo.impl.ArrayExample) Random(java.util.Random) PropertyException(com.oracle.labs.mlrg.olcut.config.PropertyException) Example(org.tribuo.Example) ArrayExample(org.tribuo.impl.ArrayExample) ArrayList(java.util.ArrayList) Regressor(org.tribuo.regression.Regressor)

Aggregations

PropertyException (com.oracle.labs.mlrg.olcut.config.PropertyException)18 Random (java.util.Random)6 ArrayList (java.util.ArrayList)5 Example (org.tribuo.Example)5 ArrayExample (org.tribuo.impl.ArrayExample)5 Locale (java.util.Locale)2 NeighboursBruteForceFactory (org.tribuo.math.neighbour.bruteforce.NeighboursBruteForceFactory)2 Regressor (org.tribuo.regression.Regressor)2 NodeInfo (ai.onnxruntime.NodeInfo)1 OrtException (ai.onnxruntime.OrtException)1 OrtSession (ai.onnxruntime.OrtSession)1 TensorInfo (ai.onnxruntime.TensorInfo)1 ConfigurationManager (com.oracle.labs.mlrg.olcut.config.ConfigurationManager)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 MessageDigest (java.security.MessageDigest)1 HashSet (java.util.HashSet)1 SplittableRandom (java.util.SplittableRandom)1 MultivariateNormalDistribution (org.apache.commons.math3.distribution.MultivariateNormalDistribution)1