Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/capymoa.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CapyMOA Test and Package

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

# TODO: moa tests are sensitive to java versions https://github.com/Waikato/moa/issues/273
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'zulu'
cache: maven

- name: Version
working-directory: ./moa
run: mvn -v

- name: Unit Tests
working-directory: ./moa
# -B: non-interactive (batch) mode
# -q: quiet output
run: mvn -B -q test

- name: Package Jar
working-directory: ./moa
# -B: non-interactive (batch) mode
# -DskipTests: skip tests (they were run earlier)
# -Dmaven.javadoc.skip=true: skip javadoc generation
# -Dlatex.skipBuild=true: skip latex documentation build this needs extra dependencies
run: mvn -B package -DskipTests -Dmaven.javadoc.skip=true -Dlatex.skipBuild=true

# Upload jar file as artifact
- name: Upload Jar
uses: actions/upload-artifact@v4
with:
name: moa-jar
path: ./moa/target/moa-*-jar-with-dependencies.jar
if-no-files-found: error
retention-days: 7
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,31 @@
*.iml
*~
*.bak
.DS_Store
.settings
.project

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
29 changes: 29 additions & 0 deletions CapyMOA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# CapyMOA

CapyMOA is a datastream learning framework that integrates the [Massive Online Analysis
(MOA)](https://moa.cms.waikato.ac.nz/) library with the python ecosystem.

To build MOA for use with CapyMOA run:
```bash
cd moa
mvn package -DskipTests -Dmaven.javadoc.skip=true -Dlatex.skipBuild=true
```
This will create a `target/moa-*-jar-with-dependencies.jar` file that can be used by
CapyMOA. To let CapyMOA know where this file is, set the `CAPYMOA_MOA_JAR` environment
variable to the path of this file.

You can do this temporarily in your terminal session with:
```bash
export CAPYMOA_MOA_JAR=/path/to/moa/target/moa-*-jar-with-dependencies.jar
```
To check that CapyMOA can find MOA, run:
```bash
python -c "import capymoa; capymoa.about()"
# CapyMOA 0.10.0
# CAPYMOA_DATASETS_DIR: .../datasets
# CAPYMOA_MOA_JAR: .../moa/moa/target/moa-2024.07.2-SNAPSHOT-jar-with-dependencies.jar
# CAPYMOA_JVM_ARGS: ['-Xmx8g', '-Xss10M']
# JAVA_HOME: /usr/lib/jvm/java-21-openjdk
# MOA version: aa955ebbcbd99e9e1d19ab16582e3e5a6fca5801ba250e4d164c16a89cf798ea
# JAVA version: 21.0.7
```
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ If you want to refer to MOA in a publication, please cite the following JMLR pap

> Albert Bifet, Geoff Holmes, Richard Kirkby, Bernhard Pfahringer (2010);
> MOA: Massive Online Analysis; Journal of Machine Learning Research 11: 1601-1604


10 changes: 10 additions & 0 deletions moa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>moa.gui.GUI</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>

<plugin>
Expand Down
20 changes: 20 additions & 0 deletions moa/src/main/java/moa/classifiers/AbstractClassifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,26 @@ public double[] getVotesForInstance(Example<Instance> example){
@Override
public abstract double[] getVotesForInstance(Instance inst);

@Override
public double getConfidenceForPrediction(Instance inst, double prediction) {
double[] votes = this.getVotesForInstance(inst);
double predictionValue = votes[(int) prediction];

double sum = 0.0;
for (double vote : votes)
sum += vote;

// Check if the sum is zero
if (sum == 0.0)
return 0.0; // Return 0 if sum is zero to avoid division by zero
return predictionValue / sum;
}

@Override
public double getConfidenceForPrediction(Example<Instance> example, double prediction) {
return getConfidenceForPrediction(example.getData(), prediction);
}

@Override
public Prediction getPredictionForInstance(Example<Instance> example){
return getPredictionForInstance(example.getData());
Expand Down
10 changes: 6 additions & 4 deletions moa/src/main/java/moa/classifiers/Classifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package moa.classifiers;

Expand Down Expand Up @@ -76,7 +76,7 @@ public interface Classifier extends Learner<Example<Instance>> {
* test instance in each class
*/
public double[] getVotesForInstance(Instance inst);

/**
* Sets the reference to the header of the data stream. The header of the
* data stream is extended from WEKA
Expand All @@ -86,7 +86,7 @@ public interface Classifier extends Learner<Example<Instance>> {
* @param ih the reference to the data stream header
*/
//public void setModelContext(InstancesHeader ih);

/**
* Gets the reference to the header of the data stream. The header of the
* data stream is extended from WEKA
Expand All @@ -96,6 +96,8 @@ public interface Classifier extends Learner<Example<Instance>> {
* @return the reference to the data stream header
*/
//public InstancesHeader getModelContext();

public Prediction getPredictionForInstance(Instance inst);

public double getConfidenceForPrediction(Instance inst, double prediction);
}
16 changes: 10 additions & 6 deletions moa/src/main/java/moa/classifiers/SemiSupervisedLearner.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@
*/
package moa.classifiers;

import com.yahoo.labs.samoa.instances.Instance;
import moa.core.Example;
import moa.learners.Learner;

/**
* Learner interface for incremental semi supervised models. It is used only in the GUI Regression Tab.
*
* @author Richard Kirkby (rkirkby@cs.waikato.ac.nz)
* @version $Revision: 7 $
* Updated learner interface for semi-supervised methods.
*/
public interface SemiSupervisedLearner {

public interface SemiSupervisedLearner extends Learner<Example<Instance>> {
// Returns the pseudo-label used. If no pseudo-label was used, then return -1.
int trainOnUnlabeledInstance(Instance instance);

void addInitialWarmupTrainingInstances();
}
Loading