Commit 19aa5133 authored by Chris Coughlin's avatar Chris Coughlin

Minor API cleanup and added README

parent 140fe7ce
Myriad Data Reduction Framework
==
Myriad is a library written in Java that provides tools for image / signal processing, machine learning, and fault-tolerant distributed computing. Its primary purpose is to assist with the development of large-scale Region Of Interest (ROI) detection applications by providing the parts required to train a model to detect ROI in large datasets.
Example applications include face detection, pedestrian tracking, and anomalous signal identification. Myriad’s [original application for NASA](http://sbir.nasa.gov/SBIR/abstracts/16/sbir/phase1/SBIR-16-1-H13.01-8360.html) was to detect indications of structural damage in nondestructive evaluation data.
For more details on Myriad, visit our [Myriad page](https://emphysic.com/myriad/) to get [code samples](https://emphysic.com/myriad/sample-code/), [video demonstrations](https://emphysic.com/myriad/downloads/), and [tutorials](http://myrdocs.azurewebsites.net/).
License
==
[Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0)
Sister Projects
==
* [Myriad Trainer](https://gitlab.com/ccoughlin/MyriadTrainer) is a cross-platform GUI for training and testing machine learning models
* [Myriad Desktop](https://gitlab.com/ccoughlin/MyriadDesktop) is a cross-platform GUI for constructing and running ROI processing pipelines
Links
==
* [Installation](http://myrdocs.azurewebsites.net/install/)
* [Frequently Asked Questions](https://emphysic.com/myriad/faq/)
* [API Documentation](http://myrdocs.azurewebsites.net/api/)
* [About Emphysic](https://emphysic.com/about/)
Contact Information
==
Questions? Comments? Suggestions? [Drop us a line.](https://emphysic.com/contact-us/)
\ No newline at end of file
......@@ -118,7 +118,7 @@ public class AdaptiveSGDROIFinder extends MLROIConfFinder {
@Override
public Vector classify(DenseVector d) {
return model.getBest().getPayload().getLearner().classify(d);
return model.getBest().getPayload().getLearner().classifyFull(d);
}
/**
......
......@@ -20,9 +20,8 @@ package com.emphysic.myriad.core.data.roi;
import com.emphysic.myriad.core.data.io.Dataset;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import java.util.stream.DoubleStream;
import org.apache.mahout.math.DenseVector;
import org.apache.mahout.math.Vector;
/**
* A Region of Interest (ROI) finder based on machine learning that provides both probabilities of its
......@@ -65,17 +64,18 @@ public abstract class MLROIConfFinder implements MLROIFinder, ROIProbability {
*/
@Override
public double predict(double[] data) {
double[] labelProbs = predict_proba(data);
double maxConf = DoubleStream.of(labelProbs).max().getAsDouble();
int idx = ArrayUtils.indexOf(labelProbs, maxConf);
DenseVector d = new DenseVector(data);
Vector scores = classify(d);
int idx = scores.maxValueIndex();
double maxConf = scores.maxValue();
if (idx > 0) {
StringBuilder sb = new StringBuilder("Predicted ROI class " + idx + " with probability " + maxConf);
if (maxConf < confThr) {
// Only report ROI if the model's confidence > threshold
sb.append(": below " + confThr + ", setting to " + negativeClass());
sb.append(": below ").append(confThr).append(", setting to ").append(negativeClass());
return negativeClass();
} else {
sb.append(": above " + confThr + ", no changes made");
sb.append(": above ").append(confThr).append(", no changes made");
}
log.info(sb.toString());
}
......
......@@ -224,6 +224,6 @@ public class PassiveAggressiveROIFinder extends MLROIConfFinder {
@Override
public Vector classify(DenseVector d) {
return model.classify(d);
return model.classifyFull(d);
}
}
......@@ -39,10 +39,8 @@ public interface ROIProbability {
DenseVector d = new DenseVector(data);
Vector scores = classify(d);
double[] probabilities = new double[1 + scores.size()];
// Mahout doesn't return the probability of the first class (class 0) - need to calculate
probabilities[0] = 1 - scores.zSum();
for (int i = 0; i < scores.size(); i++) {
probabilities[i + 1] = scores.get(i);
probabilities[0] = scores.get(i);
}
return probabilities;
}
......
......@@ -202,7 +202,7 @@ public class GradMachineROIFinder extends MLROIConfFinder {
}
public Vector classify(DenseVector d) {
return model.classify(d);
return model.classifyFull(d);
}
public GradientMachine getModel() {
......
......@@ -19,15 +19,15 @@
package com.emphysic.myriad.core.data.roi;
import com.emphysic.myriad.core.data.io.Dataset;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.mahout.classifier.sgd.UniformPrior;
import org.apache.mahout.math.DenseVector;
import org.apache.mahout.math.Vector;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.util.Random;
import java.util.stream.DoubleStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
......@@ -120,9 +120,9 @@ public class AdaptiveSGDROIFinderTest {
model.setConfidenceThreshold(t);
assertEquals(t, model.getConfidenceThreshold(), 0.05 * t);
for (double[] aX : X) {
double[] probs = model.predict_proba(aX);
double maxConf = DoubleStream.of(probs).max().getAsDouble();
int idx = ArrayUtils.indexOf(probs, maxConf);
Vector scores = model.classify(new DenseVector(aX));
double maxConf = scores.maxValue();
int idx = scores.maxValueIndex();
if (idx > 0 && maxConf < t) {
idx = 0;
}
......
......@@ -19,14 +19,14 @@
package com.emphysic.myriad.core.data.roi;
import com.emphysic.myriad.core.data.io.Dataset;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.mahout.math.DenseVector;
import org.apache.mahout.math.Vector;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.util.Random;
import java.util.stream.DoubleStream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
......@@ -106,9 +106,9 @@ public class PassiveAggressiveROIFinderTest {
model.setConfidenceThreshold(t);
assertEquals(t, model.getConfidenceThreshold(), 0.05 * t);
for (double[] aX : X) {
double[] probs = model.predict_proba(aX);
double maxConf = DoubleStream.of(probs).max().getAsDouble();
int idx = ArrayUtils.indexOf(probs, maxConf);
Vector scores = model.classify(new DenseVector(aX));
double maxConf = scores.maxValue();
int idx = scores.maxValueIndex();
if (idx > 0 && maxConf < t) {
idx = 0;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment