diff --git a/.classpath b/.classpath index 49737c980..ca2b79c8a 100644 --- a/.classpath +++ b/.classpath @@ -5,18 +5,15 @@ - - - @@ -63,8 +60,6 @@ - - @@ -74,7 +69,61 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Run.jar b/Run.jar new file mode 100644 index 000000000..1aa320ec3 Binary files /dev/null and b/Run.jar differ diff --git a/lib/dl4j/commons-codec-1.10.jar b/lib/dl4j/commons-codec-1.10.jar new file mode 100644 index 000000000..1d7417c40 Binary files /dev/null and b/lib/dl4j/commons-codec-1.10.jar differ diff --git a/lib/dl4j/commons-compress-1.18.jar b/lib/dl4j/commons-compress-1.18.jar new file mode 100644 index 000000000..e401046b5 Binary files /dev/null and b/lib/dl4j/commons-compress-1.18.jar differ diff --git a/lib/dl4j/commons-io-2.5.jar b/lib/dl4j/commons-io-2.5.jar new file mode 100644 index 000000000..107b061f5 Binary files /dev/null and b/lib/dl4j/commons-io-2.5.jar differ diff --git a/lib/dl4j/commons-lang-2.6.jar b/lib/dl4j/commons-lang-2.6.jar new file mode 100644 index 000000000..98467d3a6 Binary files /dev/null and b/lib/dl4j/commons-lang-2.6.jar differ diff --git a/lib/dl4j/commons-lang3-3.6.jar b/lib/dl4j/commons-lang3-3.6.jar new file mode 100644 index 000000000..c25fd4d32 Binary files /dev/null and b/lib/dl4j/commons-lang3-3.6.jar differ diff --git a/lib/dl4j/commons-math3-3.5.jar b/lib/dl4j/commons-math3-3.5.jar new file mode 100644 index 000000000..db99f8c28 Binary files /dev/null and b/lib/dl4j/commons-math3-3.5.jar differ diff --git a/lib/dl4j/deeplearning4j-common-1.0.0-beta7.jar b/lib/dl4j/deeplearning4j-common-1.0.0-beta7.jar new file mode 100644 index 000000000..32c5952d4 Binary files /dev/null and b/lib/dl4j/deeplearning4j-common-1.0.0-beta7.jar differ diff --git a/lib/dl4j/deeplearning4j-core-1.0.0-beta7.jar b/lib/dl4j/deeplearning4j-core-1.0.0-beta7.jar new file mode 100644 index 000000000..e9bb98df3 Binary files /dev/null and b/lib/dl4j/deeplearning4j-core-1.0.0-beta7.jar differ diff --git a/lib/dl4j/deeplearning4j-nlp-1.0.0-beta7.jar b/lib/dl4j/deeplearning4j-nlp-1.0.0-beta7.jar new file mode 100644 index 000000000..19e38097e Binary files /dev/null and b/lib/dl4j/deeplearning4j-nlp-1.0.0-beta7.jar differ diff --git a/lib/dl4j/deeplearning4j-nn-1.0.0-beta7.jar b/lib/dl4j/deeplearning4j-nn-1.0.0-beta7.jar new file mode 100644 index 000000000..eb7f5d1db Binary files /dev/null and b/lib/dl4j/deeplearning4j-nn-1.0.0-beta7.jar differ diff --git a/lib/dl4j/deeplearning4j-tsne-1.0.0-beta7.jar b/lib/dl4j/deeplearning4j-tsne-1.0.0-beta7.jar new file mode 100644 index 000000000..32aa92c35 Binary files /dev/null and b/lib/dl4j/deeplearning4j-tsne-1.0.0-beta7.jar differ diff --git a/lib/dl4j/flatbuffers-java-1.10.0.jar b/lib/dl4j/flatbuffers-java-1.10.0.jar new file mode 100644 index 000000000..4b57c4099 Binary files /dev/null and b/lib/dl4j/flatbuffers-java-1.10.0.jar differ diff --git a/lib/dl4j/gson-2.8.0.jar b/lib/dl4j/gson-2.8.0.jar new file mode 100644 index 000000000..1235f6381 Binary files /dev/null and b/lib/dl4j/gson-2.8.0.jar differ diff --git a/lib/dl4j/guava-1.0.0-beta7.jar b/lib/dl4j/guava-1.0.0-beta7.jar new file mode 100644 index 000000000..d3765c652 Binary files /dev/null and b/lib/dl4j/guava-1.0.0-beta7.jar differ diff --git a/lib/dl4j/jackson-1.0.0-beta7.jar b/lib/dl4j/jackson-1.0.0-beta7.jar new file mode 100644 index 000000000..0c8980533 Binary files /dev/null and b/lib/dl4j/jackson-1.0.0-beta7.jar differ diff --git a/lib/dl4j/javacpp-1.5.3-linux-arm64.jar b/lib/dl4j/javacpp-1.5.3-linux-arm64.jar new file mode 100644 index 000000000..f1cbbaa91 Binary files /dev/null and b/lib/dl4j/javacpp-1.5.3-linux-arm64.jar differ diff --git a/lib/dl4j/javacpp-1.5.3-linux-armhf.jar b/lib/dl4j/javacpp-1.5.3-linux-armhf.jar new file mode 100644 index 000000000..70e85ba38 Binary files /dev/null and b/lib/dl4j/javacpp-1.5.3-linux-armhf.jar differ diff --git a/lib/dl4j/javacpp-1.5.3-linux-ppc64le.jar b/lib/dl4j/javacpp-1.5.3-linux-ppc64le.jar new file mode 100644 index 000000000..93d4a159a Binary files /dev/null and b/lib/dl4j/javacpp-1.5.3-linux-ppc64le.jar differ diff --git a/lib/dl4j/javacpp-1.5.3-linux-x86.jar b/lib/dl4j/javacpp-1.5.3-linux-x86.jar new file mode 100644 index 000000000..7b2992ef0 Binary files /dev/null and b/lib/dl4j/javacpp-1.5.3-linux-x86.jar differ diff --git a/lib/dl4j/javacpp-1.5.3-linux-x86_64.jar b/lib/dl4j/javacpp-1.5.3-linux-x86_64.jar new file mode 100644 index 000000000..78cdc2c20 Binary files /dev/null and b/lib/dl4j/javacpp-1.5.3-linux-x86_64.jar differ diff --git a/lib/dl4j/javacpp-1.5.3-macosx-x86_64.jar b/lib/dl4j/javacpp-1.5.3-macosx-x86_64.jar new file mode 100644 index 000000000..aefbd179f Binary files /dev/null and b/lib/dl4j/javacpp-1.5.3-macosx-x86_64.jar differ diff --git a/lib/dl4j/javacpp-1.5.3.jar b/lib/dl4j/javacpp-1.5.3.jar new file mode 100644 index 000000000..b38757d66 Binary files /dev/null and b/lib/dl4j/javacpp-1.5.3.jar differ diff --git a/lib/dl4j/javacpp-platform-1.5.3.jar b/lib/dl4j/javacpp-platform-1.5.3.jar new file mode 100644 index 000000000..f935c1f64 Binary files /dev/null and b/lib/dl4j/javacpp-platform-1.5.3.jar differ diff --git a/lib/dl4j/javacv-1.5.3.jar b/lib/dl4j/javacv-1.5.3.jar new file mode 100644 index 000000000..4607dc980 Binary files /dev/null and b/lib/dl4j/javacv-1.5.3.jar differ diff --git a/lib/dl4j/jna-4.3.0.jar b/lib/dl4j/jna-4.3.0.jar new file mode 100644 index 000000000..713354e59 Binary files /dev/null and b/lib/dl4j/jna-4.3.0.jar differ diff --git a/lib/dl4j/jna-platform-4.3.0.jar b/lib/dl4j/jna-platform-4.3.0.jar new file mode 100644 index 000000000..16d3ae6fc Binary files /dev/null and b/lib/dl4j/jna-platform-4.3.0.jar differ diff --git a/lib/dl4j/nd4j-api-1.0.0-beta7.jar b/lib/dl4j/nd4j-api-1.0.0-beta7.jar new file mode 100644 index 000000000..8ddf00f4c Binary files /dev/null and b/lib/dl4j/nd4j-api-1.0.0-beta7.jar differ diff --git a/lib/dl4j/nd4j-common-1.0.0-beta7.jar b/lib/dl4j/nd4j-common-1.0.0-beta7.jar new file mode 100644 index 000000000..6c7aef2d0 Binary files /dev/null and b/lib/dl4j/nd4j-common-1.0.0-beta7.jar differ diff --git a/lib/dl4j/nd4j-native-1.0.0-beta7-linux-armhf.jar b/lib/dl4j/nd4j-native-1.0.0-beta7-linux-armhf.jar new file mode 100644 index 000000000..edc09d6cb Binary files /dev/null and b/lib/dl4j/nd4j-native-1.0.0-beta7-linux-armhf.jar differ diff --git a/lib/dl4j/nd4j-native-1.0.0-beta7-linux-ppc64le.jar b/lib/dl4j/nd4j-native-1.0.0-beta7-linux-ppc64le.jar new file mode 100644 index 000000000..793a7f5eb Binary files /dev/null and b/lib/dl4j/nd4j-native-1.0.0-beta7-linux-ppc64le.jar differ diff --git a/lib/dl4j/nd4j-native-1.0.0-beta7-linux-x86_64.jar b/lib/dl4j/nd4j-native-1.0.0-beta7-linux-x86_64.jar new file mode 100644 index 000000000..5d23158e3 Binary files /dev/null and b/lib/dl4j/nd4j-native-1.0.0-beta7-linux-x86_64.jar differ diff --git a/lib/dl4j/nd4j-native-1.0.0-beta7-macosx-x86_64.jar b/lib/dl4j/nd4j-native-1.0.0-beta7-macosx-x86_64.jar new file mode 100644 index 000000000..8753cba03 Binary files /dev/null and b/lib/dl4j/nd4j-native-1.0.0-beta7-macosx-x86_64.jar differ diff --git a/lib/dl4j/nd4j-native-1.0.0-beta7.jar b/lib/dl4j/nd4j-native-1.0.0-beta7.jar new file mode 100644 index 000000000..7cbd208dd Binary files /dev/null and b/lib/dl4j/nd4j-native-1.0.0-beta7.jar differ diff --git a/lib/dl4j/nd4j-native-api-1.0.0-beta7.jar b/lib/dl4j/nd4j-native-api-1.0.0-beta7.jar new file mode 100644 index 000000000..cb345b659 Binary files /dev/null and b/lib/dl4j/nd4j-native-api-1.0.0-beta7.jar differ diff --git a/lib/dl4j/nd4j-native-platform-1.0.0-beta7.jar b/lib/dl4j/nd4j-native-platform-1.0.0-beta7.jar new file mode 100644 index 000000000..bc0f9594a Binary files /dev/null and b/lib/dl4j/nd4j-native-platform-1.0.0-beta7.jar differ diff --git a/lib/dl4j/nearestneighbor-core-1.0.0-beta7.jar b/lib/dl4j/nearestneighbor-core-1.0.0-beta7.jar new file mode 100644 index 000000000..561d6dfaf Binary files /dev/null and b/lib/dl4j/nearestneighbor-core-1.0.0-beta7.jar differ diff --git a/lib/dl4j/neoitertools-1.0.0.jar b/lib/dl4j/neoitertools-1.0.0.jar new file mode 100644 index 000000000..4e43b26c7 Binary files /dev/null and b/lib/dl4j/neoitertools-1.0.0.jar differ diff --git a/lib/dl4j/openblas-0.3.9-1.5.3-linux-arm64.jar b/lib/dl4j/openblas-0.3.9-1.5.3-linux-arm64.jar new file mode 100644 index 000000000..054352b30 Binary files /dev/null and b/lib/dl4j/openblas-0.3.9-1.5.3-linux-arm64.jar differ diff --git a/lib/dl4j/openblas-0.3.9-1.5.3-linux-armhf.jar b/lib/dl4j/openblas-0.3.9-1.5.3-linux-armhf.jar new file mode 100644 index 000000000..3c83d32f0 Binary files /dev/null and b/lib/dl4j/openblas-0.3.9-1.5.3-linux-armhf.jar differ diff --git a/lib/dl4j/openblas-0.3.9-1.5.3-linux-ppc64le.jar b/lib/dl4j/openblas-0.3.9-1.5.3-linux-ppc64le.jar new file mode 100644 index 000000000..667b67894 Binary files /dev/null and b/lib/dl4j/openblas-0.3.9-1.5.3-linux-ppc64le.jar differ diff --git a/lib/dl4j/openblas-0.3.9-1.5.3-linux-x86.jar b/lib/dl4j/openblas-0.3.9-1.5.3-linux-x86.jar new file mode 100644 index 000000000..5c6c8f118 Binary files /dev/null and b/lib/dl4j/openblas-0.3.9-1.5.3-linux-x86.jar differ diff --git a/lib/dl4j/openblas-0.3.9-1.5.3-linux-x86_64.jar b/lib/dl4j/openblas-0.3.9-1.5.3-linux-x86_64.jar new file mode 100644 index 000000000..3bf0dfb3b Binary files /dev/null and b/lib/dl4j/openblas-0.3.9-1.5.3-linux-x86_64.jar differ diff --git a/lib/dl4j/openblas-0.3.9-1.5.3-macosx-x86_64.jar b/lib/dl4j/openblas-0.3.9-1.5.3-macosx-x86_64.jar new file mode 100644 index 000000000..51008bd1b Binary files /dev/null and b/lib/dl4j/openblas-0.3.9-1.5.3-macosx-x86_64.jar differ diff --git a/lib/dl4j/openblas-0.3.9-1.5.3.jar b/lib/dl4j/openblas-0.3.9-1.5.3.jar new file mode 100644 index 000000000..db79d5d61 Binary files /dev/null and b/lib/dl4j/openblas-0.3.9-1.5.3.jar differ diff --git a/lib/dl4j/openblas-platform-0.3.9-1.5.3.jar b/lib/dl4j/openblas-platform-0.3.9-1.5.3.jar new file mode 100644 index 000000000..699d14f26 Binary files /dev/null and b/lib/dl4j/openblas-platform-0.3.9-1.5.3.jar differ diff --git a/lib/dl4j/opencsv-2.3.jar b/lib/dl4j/opencsv-2.3.jar new file mode 100644 index 000000000..01f82ca73 Binary files /dev/null and b/lib/dl4j/opencsv-2.3.jar differ diff --git a/lib/dl4j/opencv-platform-4.3.0-1.5.3.jar b/lib/dl4j/opencv-platform-4.3.0-1.5.3.jar new file mode 100644 index 000000000..6bb27966a Binary files /dev/null and b/lib/dl4j/opencv-platform-4.3.0-1.5.3.jar differ diff --git a/lib/dl4j/protobuf-1.0.0-beta7.jar b/lib/dl4j/protobuf-1.0.0-beta7.jar new file mode 100644 index 000000000..c07a1a3e7 Binary files /dev/null and b/lib/dl4j/protobuf-1.0.0-beta7.jar differ diff --git a/lib/dl4j/slf4j-api-1.7.21.jar b/lib/dl4j/slf4j-api-1.7.21.jar new file mode 100644 index 000000000..2a5c33ec5 Binary files /dev/null and b/lib/dl4j/slf4j-api-1.7.21.jar differ diff --git a/lib/dl4j/slf4j-simple-1.7.21.jar b/lib/dl4j/slf4j-simple-1.7.21.jar new file mode 100644 index 000000000..a4086de0b Binary files /dev/null and b/lib/dl4j/slf4j-simple-1.7.21.jar differ diff --git a/lib/dl4j/threadly-4.10.0.jar b/lib/dl4j/threadly-4.10.0.jar new file mode 100644 index 000000000..4fa7ffd0d Binary files /dev/null and b/lib/dl4j/threadly-4.10.0.jar differ diff --git a/lib/weka/arpack_combined.jar b/lib/weka/arpack_combined.jar new file mode 100644 index 000000000..7444ccc27 Binary files /dev/null and b/lib/weka/arpack_combined.jar differ diff --git a/lib/weka/core.jar b/lib/weka/core.jar new file mode 100644 index 000000000..cf4584fdb Binary files /dev/null and b/lib/weka/core.jar differ diff --git a/lib/weka/mtj.jar b/lib/weka/mtj.jar new file mode 100644 index 000000000..e6ec6048e Binary files /dev/null and b/lib/weka/mtj.jar differ diff --git a/lib/weka/weka.jar b/lib/weka/weka.jar new file mode 100644 index 000000000..41b2b9436 Binary files /dev/null and b/lib/weka/weka.jar differ diff --git a/src/antlr/Boa.g b/src/antlr/Boa.g index 236d34fba..df995c28e 100644 --- a/src/antlr/Boa.g +++ b/src/antlr/Boa.g @@ -112,6 +112,7 @@ type returns [AbstractType ast] | q=queueType { $ast = $q.ast; } | set=setType { $ast = $set.ast; } | e=enumType { $ast = $e.ast; } + | model=modelType { $ast = $model.ast; } | id=identifier { $ast = $id.ast; } ; @@ -202,7 +203,12 @@ outputType returns [OutputType ast] @after { $ast.setPositions($l, $c, getEndLine(), getEndColumn()); } : OUTPUT (tk=SET { $ast = new OutputType((Identifier)new Identifier($tk.text).setPositions(getStartLine($tk), getStartColumn($tk), getEndLine($tk), getEndColumn($tk))); } | id=identifier { $ast = new OutputType($id.ast); }) (LPAREN el=expressionList RPAREN { $ast.setArgs($el.list); })? (LBRACKET m=component RBRACKET { $ast.addIndice($m.ast); })* OF m=component { $ast.setType($m.ast); } (WEIGHT m=component { $ast.setWeight($m.ast); })? (FORMAT LPAREN el=expressionList RPAREN)? ; - +modelType returns [ModelType ast] + locals [int l, int c] + @init { $l = getStartLine(); $c = getStartColumn(); } + @after { $ast.setPositions($l, $c, getEndLine(), getEndColumn()); } + : MODEL OF id=identifier { $ast = new ModelType($id.ast); } OF m=component { $ast.setType($m.ast); } + ; functionType returns [FunctionType ast] locals [int l, int c] @init { @@ -610,6 +616,7 @@ identifier returns [Identifier ast] | lit=MAP { notifyErrorListeners("keyword '" + $lit.text + "' can not be used as an identifier"); } | lit=STACK { notifyErrorListeners("keyword '" + $lit.text + "' can not be used as an identifier"); } | lit=QUEUE { notifyErrorListeners("keyword '" + $lit.text + "' can not be used as an identifier"); } + | lit=MODEL { notifyErrorListeners("keyword '" + $lit.text + "' can not be used as an identifier"); } | lit=SET { notifyErrorListeners("keyword '" + $lit.text + "' can not be used as an identifier"); } | lit=FOR { notifyErrorListeners("keyword '" + $lit.text + "' can not be used as an identifier"); } | lit=FOREACH { notifyErrorListeners("keyword '" + $lit.text + "' can not be used as an identifier"); } @@ -690,6 +697,7 @@ DO : 'do'; MAP : 'map'; STACK : 'stack'; QUEUE : 'queue'; +MODEL : 'model'; SET : 'set'; FOR : 'for'; FOREACH : 'foreach'; diff --git a/src/antlr/BoaNoActions.g b/src/antlr/BoaNoActions.g index 2b80b6f93..f65af23e1 100644 --- a/src/antlr/BoaNoActions.g +++ b/src/antlr/BoaNoActions.g @@ -55,6 +55,7 @@ type | queueType | setType | enumType + | modelType | identifier ; @@ -103,6 +104,10 @@ setType outputType : OUTPUT (SET | identifier) (LPAREN expressionList RPAREN)? (LBRACKET component RBRACKET)* OF component (WEIGHT component)? (FORMAT LPAREN expressionList RPAREN)? ; + +modelType + : MODEL of identifier OF component + ; functionType : FUNCTION LPAREN (identifier COLON type (COMMA identifier COLON type)*)? RPAREN (COLON type)? @@ -352,6 +357,7 @@ identifier | lit=MAP { notifyErrorListeners("keyword '" + $lit.text + "' can not be used as an identifier"); } | lit=STACK { notifyErrorListeners("keyword '" + $lit.text + "' can not be used as an identifier"); } | lit=QUEUE { notifyErrorListeners("keyword '" + $lit.text + "' can not be used as an identifier"); } + | lit=MODEL { notifyErrorListeners("keyword '" + $lit.text + "' can not be used as an identifier"); } | lit=SET { notifyErrorListeners("keyword '" + $lit.text + "' can not be used as an identifier"); } | lit=FOR { notifyErrorListeners("keyword '" + $lit.text + "' can not be used as an identifier"); } | lit=FOREACH { notifyErrorListeners("keyword '" + $lit.text + "' can not be used as an identifier"); } @@ -417,6 +423,7 @@ DO : 'do'; MAP : 'map'; STACK : 'stack'; QUEUE : 'queue'; +MODEL : 'model'; SET : 'set'; FOR : 'for'; FOREACH : 'foreach'; diff --git a/src/java/boa/aggregators/Aggregator.java b/src/java/boa/aggregators/Aggregator.java index 619aa1070..4d508f9ca 100644 --- a/src/java/boa/aggregators/Aggregator.java +++ b/src/java/boa/aggregators/Aggregator.java @@ -25,6 +25,7 @@ import boa.functions.BoaCasts; import boa.io.EmitKey; import boa.io.EmitValue; +import boa.runtime.Tuple; /** * The base class for all Boa aggregators. diff --git a/src/java/boa/aggregators/ml/AdaBoostM1Aggregator.java b/src/java/boa/aggregators/ml/AdaBoostM1Aggregator.java new file mode 100644 index 000000000..78fe5af1d --- /dev/null +++ b/src/java/boa/aggregators/ml/AdaBoostM1Aggregator.java @@ -0,0 +1,70 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.runtime.Tuple; +import boa.aggregators.AggregatorSpec; +import weka.classifiers.meta.AdaBoostM1; +import java.io.IOException; + +/** + * A Boa aggregator for training the model using AdaBoostM1. + * + * @author ankuraga + * @author nmtiwari + */ +@AggregatorSpec(name = "adaboost", formalParameters = { "string" }) +public class AdaBoostM1Aggregator extends MLAggregator { + private AdaBoostM1 model; + + public AdaBoostM1Aggregator() { + } + + public AdaBoostM1Aggregator(final String s) { + super(s); + } + + @Override + public void aggregate(final String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "AdaBoostM1"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "AdaBoostM1"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new AdaBoostM1(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/AdditiveRegressionAggregator.java b/src/java/boa/aggregators/ml/AdditiveRegressionAggregator.java new file mode 100644 index 000000000..351a08b54 --- /dev/null +++ b/src/java/boa/aggregators/ml/AdditiveRegressionAggregator.java @@ -0,0 +1,70 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.runtime.Tuple; +import boa.aggregators.AggregatorSpec; +import weka.classifiers.meta.AdditiveRegression; +import java.io.IOException; + +/** + * A Boa aggregator for training the model using AdditiveRegression. + * + * @author ankuraga/ + * @author nmtiwari + */ +@AggregatorSpec(name = "additiveregression", formalParameters = { "string" }) +public class AdditiveRegressionAggregator extends MLAggregator { + private AdditiveRegression model; + + public AdditiveRegressionAggregator() { + } + + public AdditiveRegressionAggregator(final String s) { + super(s); + } + + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "AdditiveRegression"); + } + + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "AdditiveRegression"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new AdditiveRegression(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } +} diff --git a/src/java/boa/aggregators/ml/AttributeSelectedClassifierAggregator.java b/src/java/boa/aggregators/ml/AttributeSelectedClassifierAggregator.java new file mode 100644 index 000000000..9080fe931 --- /dev/null +++ b/src/java/boa/aggregators/ml/AttributeSelectedClassifierAggregator.java @@ -0,0 +1,70 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.runtime.Tuple; +import boa.aggregators.AggregatorSpec; +import weka.classifiers.meta.AttributeSelectedClassifier; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using AttributeSelectedClassifier. + * + * @author ankuraga + */ +@AggregatorSpec(name = "attributeselectedclassifier", formalParameters = { "string" }) +public class AttributeSelectedClassifierAggregator extends MLAggregator { + private AttributeSelectedClassifier model; + + public AttributeSelectedClassifierAggregator() { + } + + public AttributeSelectedClassifierAggregator(final String s) { + super(s); + } + + public void aggregate(String[] data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "AttributeSelectedClassifier"); + } + + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "AttributeSelectedClassifier"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new AttributeSelectedClassifier(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } +} diff --git a/src/java/boa/aggregators/ml/BaggingAggregator.java b/src/java/boa/aggregators/ml/BaggingAggregator.java new file mode 100644 index 000000000..1470436ea --- /dev/null +++ b/src/java/boa/aggregators/ml/BaggingAggregator.java @@ -0,0 +1,72 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.runtime.Tuple; +import boa.aggregators.AggregatorSpec; +import boa.aggregators.FinishedException; +import weka.classifiers.meta.Bagging; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using Bagging. + * + * @author ankuraga + */ +@AggregatorSpec(name = "bagging", formalParameters = { "string" }) +public class BaggingAggregator extends MLAggregator { + private Bagging model; + + public BaggingAggregator() { + } + + public BaggingAggregator(final String s) { + super(s); + } + + public void aggregate(String[] data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "Bagging"); + } + + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "Bagging"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException, FinishedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new Bagging(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} diff --git a/src/java/boa/aggregators/ml/BayesNetAggregator.java b/src/java/boa/aggregators/ml/BayesNetAggregator.java new file mode 100644 index 000000000..417276e3d --- /dev/null +++ b/src/java/boa/aggregators/ml/BayesNetAggregator.java @@ -0,0 +1,72 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.runtime.Tuple; +import boa.aggregators.AggregatorSpec; +import boa.aggregators.FinishedException; +import weka.classifiers.bayes.BayesNet; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using BayesNet. + * + * @author ankuraga + */ +@AggregatorSpec(name = "bayesnet", formalParameters = { "string" }) +public class BayesNetAggregator extends MLAggregator { + private BayesNet model; + + public BayesNetAggregator() { + } + + public BayesNetAggregator(final String s) { + super(s); + } + + public void aggregate(String[] data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "BayesNet"); + } + + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "BayesNet"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException, FinishedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new BayesNet(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} diff --git a/src/java/boa/aggregators/ml/CVParameterSelectionAggregator.java b/src/java/boa/aggregators/ml/CVParameterSelectionAggregator.java new file mode 100644 index 000000000..07cb0f8ba --- /dev/null +++ b/src/java/boa/aggregators/ml/CVParameterSelectionAggregator.java @@ -0,0 +1,71 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.runtime.Tuple; +import boa.aggregators.AggregatorSpec; +import boa.aggregators.FinishedException; +import weka.classifiers.meta.CVParameterSelection; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using CVParameterSelection. + * + * @author ankuraga + */ +@AggregatorSpec(name = "cvparameterselection", formalParameters = { "string" }) +public class CVParameterSelectionAggregator extends MLAggregator { + private CVParameterSelection model; + + public CVParameterSelectionAggregator() { + } + + public CVParameterSelectionAggregator(final String s) { + super(s); + } + + public void aggregate(String[] data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "CVParameterSelection"); + } + + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "CVParameterSelection"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException, FinishedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new CVParameterSelection(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } +} diff --git a/src/java/boa/aggregators/ml/ClassificationViaRegressionAggregator.java b/src/java/boa/aggregators/ml/ClassificationViaRegressionAggregator.java new file mode 100644 index 000000000..1b7c83d71 --- /dev/null +++ b/src/java/boa/aggregators/ml/ClassificationViaRegressionAggregator.java @@ -0,0 +1,71 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.runtime.Tuple; +import boa.aggregators.AggregatorSpec; +import weka.classifiers.meta.ClassificationViaRegression; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using ClassificationViaRegression. + * + * @author ankuraga + */ +@AggregatorSpec(name = "classificationviaregression", formalParameters = { "string" }) +public class ClassificationViaRegressionAggregator extends MLAggregator { + private ClassificationViaRegression model; + + public ClassificationViaRegressionAggregator() { + } + + public ClassificationViaRegressionAggregator(final String s) { + super(s); + } + + public void aggregate(String[] data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "ClassificationViaRegression"); + } + + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "ClassificationViaRegression"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new ClassificationViaRegression(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} diff --git a/src/java/boa/aggregators/ml/DecisionStumpAggregator.java b/src/java/boa/aggregators/ml/DecisionStumpAggregator.java new file mode 100644 index 000000000..b454cbc6f --- /dev/null +++ b/src/java/boa/aggregators/ml/DecisionStumpAggregator.java @@ -0,0 +1,72 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.runtime.Tuple; +import boa.aggregators.AggregatorSpec; +import boa.aggregators.FinishedException; +import weka.classifiers.trees.DecisionStump; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using DecisionStump. + * + * @author ankuraga + */ +@AggregatorSpec(name = "decisionstump", formalParameters = { "string" }) +public class DecisionStumpAggregator extends MLAggregator { + private DecisionStump model; + + public DecisionStumpAggregator() { + } + + public DecisionStumpAggregator(final String s) { + super(s); + } + + public void aggregate(String[] data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "DecisionStump"); + } + + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "DecisionStump"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException, FinishedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new DecisionStump(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} diff --git a/src/java/boa/aggregators/ml/DecisionTableAggregator.java b/src/java/boa/aggregators/ml/DecisionTableAggregator.java new file mode 100644 index 000000000..c80348cb9 --- /dev/null +++ b/src/java/boa/aggregators/ml/DecisionTableAggregator.java @@ -0,0 +1,71 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.runtime.Tuple; +import boa.aggregators.AggregatorSpec; +import boa.aggregators.FinishedException; +import weka.classifiers.rules.DecisionTable; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using DecisionTable. + * + * @author ankuraga + */ +@AggregatorSpec(name = "decisiontable", formalParameters = { "string" }) +public class DecisionTableAggregator extends MLAggregator { + private DecisionTable model; + + public DecisionTableAggregator() { + } + + public DecisionTableAggregator(final String s) { + super(s); + } + + public void aggregate(String[] data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "DecisionTable"); + } + + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "DecisionTable"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException, FinishedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new DecisionTable(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } +} diff --git a/src/java/boa/aggregators/ml/FilteredClassifierAggregator.java b/src/java/boa/aggregators/ml/FilteredClassifierAggregator.java new file mode 100644 index 000000000..ea9b75645 --- /dev/null +++ b/src/java/boa/aggregators/ml/FilteredClassifierAggregator.java @@ -0,0 +1,71 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.runtime.Tuple; +import boa.aggregators.AggregatorSpec; +import boa.aggregators.FinishedException; +import weka.classifiers.meta.FilteredClassifier; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using FilteredClassifier. + * + * @author ankuraga + */ +@AggregatorSpec(name = "filteredclassifier", formalParameters = { "string" }) +public class FilteredClassifierAggregator extends MLAggregator { + private FilteredClassifier model; + + public FilteredClassifierAggregator() { + } + + public FilteredClassifierAggregator(final String s) { + super(s); + } + + public void aggregate(String[] data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "FilteredClassifier"); + } + + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "FilteredClassifier"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException, FinishedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new FilteredClassifier(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } +} diff --git a/src/java/boa/aggregators/ml/GaussianProcessesAggregator.java b/src/java/boa/aggregators/ml/GaussianProcessesAggregator.java new file mode 100644 index 000000000..dde3a9f68 --- /dev/null +++ b/src/java/boa/aggregators/ml/GaussianProcessesAggregator.java @@ -0,0 +1,72 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.runtime.Tuple; +import boa.aggregators.AggregatorSpec; +import boa.aggregators.FinishedException; +import weka.classifiers.functions.GaussianProcesses; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using GaussianProcesses. + * + * @author ankuraga + */ +@AggregatorSpec(name = "gaussianprocesses", formalParameters = {"string"}) +public class GaussianProcessesAggregator extends MLAggregator { + private GaussianProcesses model; + + + public GaussianProcessesAggregator() { + } + + public GaussianProcessesAggregator(final String s) { + super(s); + } + + public void aggregate(String[] data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "GaussianProcesses"); + } + + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "GaussianProcesses"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException, FinishedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new GaussianProcesses(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } +} diff --git a/src/java/boa/aggregators/ml/InputMappedClassifierAggregator.java b/src/java/boa/aggregators/ml/InputMappedClassifierAggregator.java new file mode 100644 index 000000000..93bc1797a --- /dev/null +++ b/src/java/boa/aggregators/ml/InputMappedClassifierAggregator.java @@ -0,0 +1,72 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.runtime.Tuple; +import boa.aggregators.AggregatorSpec; +import boa.aggregators.FinishedException; +import weka.classifiers.misc.InputMappedClassifier; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using InputMappedClassifier. + * + * @author ankuraga + * @author nmtiwari + */ +@AggregatorSpec(name = "inputmappedclassifier", formalParameters = {"string"}) +public class InputMappedClassifierAggregator extends MLAggregator { + private InputMappedClassifier model; + + public InputMappedClassifierAggregator() { + } + + public InputMappedClassifierAggregator(final String s) { + super(s); + } + + public void aggregate(String[] data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "InputMappedClassifier"); + } + + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "InputMappedClassifier"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException, FinishedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new InputMappedClassifier(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } +} diff --git a/src/java/boa/aggregators/ml/J48Aggregator.java b/src/java/boa/aggregators/ml/J48Aggregator.java new file mode 100644 index 000000000..fbcf70625 --- /dev/null +++ b/src/java/boa/aggregators/ml/J48Aggregator.java @@ -0,0 +1,73 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.classifiers.trees.J48; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using J48. + * + * @author ankuraga + */ +@AggregatorSpec(name = "j48", formalParameters = { "string" }) +public class J48Aggregator extends MLAggregator { + private J48 model; + + public J48Aggregator() { + } + + public J48Aggregator(final String s) { + super(s); + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "J48"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "J48"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new J48(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/JRipAggregator.java b/src/java/boa/aggregators/ml/JRipAggregator.java new file mode 100644 index 000000000..fcb856dce --- /dev/null +++ b/src/java/boa/aggregators/ml/JRipAggregator.java @@ -0,0 +1,72 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.classifiers.rules.JRip; +import java.io.IOException; + +/** + * A Boa aggregator for training the model using JRip. + * + * @author ankuraga + */ +@AggregatorSpec(name = "jrip", formalParameters = { "string" }) +public class JRipAggregator extends MLAggregator { + private JRip model; + + public JRipAggregator() { + } + + public JRipAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "JRip"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "JRip"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new JRip(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/KStarAggregator.java b/src/java/boa/aggregators/ml/KStarAggregator.java new file mode 100644 index 000000000..df01bf0bc --- /dev/null +++ b/src/java/boa/aggregators/ml/KStarAggregator.java @@ -0,0 +1,72 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.classifiers.lazy.KStar; +import java.io.IOException; + +/** + * A Boa aggregator for training the model using KStar. + * + * @author ankuraga + */ +@AggregatorSpec(name = "kstar", formalParameters = { "string" }) +public class KStarAggregator extends MLAggregator { + private KStar model; + + public KStarAggregator() { + } + + public KStarAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "KStar"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "KStar"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new KStar(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/LMTAggregator.java b/src/java/boa/aggregators/ml/LMTAggregator.java new file mode 100644 index 000000000..e61816233 --- /dev/null +++ b/src/java/boa/aggregators/ml/LMTAggregator.java @@ -0,0 +1,73 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.classifiers.trees.LMT; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using Logistic. + * + * @author ankuraga + */ +@AggregatorSpec(name = "lmt", formalParameters = { "string" }) +public class LMTAggregator extends MLAggregator { + private LMT model; + + public LMTAggregator() { + } + + public LMTAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "LMT"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "LMT"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new LMT(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/LWLAggregator.java b/src/java/boa/aggregators/ml/LWLAggregator.java new file mode 100644 index 000000000..4912f342c --- /dev/null +++ b/src/java/boa/aggregators/ml/LWLAggregator.java @@ -0,0 +1,73 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.classifiers.lazy.LWL; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using LWL. + * + * @author ankuraga + */ +@AggregatorSpec(name = "lwl", formalParameters = { "string" }) +public class LWLAggregator extends MLAggregator { + private LWL model; + + public LWLAggregator() { + } + + public LWLAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "LWL"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "LWL"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new LWL(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/LinearRegressionAggregator.java b/src/java/boa/aggregators/ml/LinearRegressionAggregator.java new file mode 100644 index 000000000..d542d07b1 --- /dev/null +++ b/src/java/boa/aggregators/ml/LinearRegressionAggregator.java @@ -0,0 +1,73 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.classifiers.functions.LinearRegression; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using LinearRegression. + * + * @author ankuraga + */ +@AggregatorSpec(name = "linearregression", formalParameters = { "string" }) +public class LinearRegressionAggregator extends MLAggregator { + private LinearRegression model; + + public LinearRegressionAggregator() { + } + + public LinearRegressionAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "LinearRegression"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "LinearRegression"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new LinearRegression(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/LogisticRegressionAggregator.java b/src/java/boa/aggregators/ml/LogisticRegressionAggregator.java new file mode 100644 index 000000000..6c796cd46 --- /dev/null +++ b/src/java/boa/aggregators/ml/LogisticRegressionAggregator.java @@ -0,0 +1,73 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.classifiers.functions.Logistic; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using Logistic. + * + * @author ankuraga + */ +@AggregatorSpec(name = "logistic", formalParameters = { "string" }) +public class LogisticRegressionAggregator extends MLAggregator { + private Logistic model; + + public LogisticRegressionAggregator() { + } + + public LogisticRegressionAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "Logistic"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "Logistic"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new Logistic(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/LogitBoostAggregator.java b/src/java/boa/aggregators/ml/LogitBoostAggregator.java new file mode 100644 index 000000000..0430a1380 --- /dev/null +++ b/src/java/boa/aggregators/ml/LogitBoostAggregator.java @@ -0,0 +1,73 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.classifiers.meta.LogitBoost; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using LogitBoost. + * + * @author ankuraga + */ +@AggregatorSpec(name = "logitboost", formalParameters = { "string" }) +public class LogitBoostAggregator extends MLAggregator { + private LogitBoost model; + + public LogitBoostAggregator() { + } + + public LogitBoostAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "LogitBoost"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "LogitBoost"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new LogitBoost(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/MLAggregator.java b/src/java/boa/aggregators/ml/MLAggregator.java new file mode 100644 index 000000000..121a8073e --- /dev/null +++ b/src/java/boa/aggregators/ml/MLAggregator.java @@ -0,0 +1,362 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.Aggregator; +import boa.datagen.DefaultProperties; +import boa.runtime.Tuple; + +import org.apache.commons.lang.math.NumberUtils; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FSDataOutputStream; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.mapred.FileOutputFormat; +import org.apache.hadoop.mapred.JobConf; +import org.apache.hadoop.mapreduce.JobContext; +import weka.classifiers.Classifier; +import weka.classifiers.Evaluation; +import weka.clusterers.ClusterEvaluation; +import weka.clusterers.Clusterer; +import weka.core.*; +import weka.filters.Filter; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.List; + +/** + * A Boa ML aggregator to train models. + * + * @author ankuraga + */ +public abstract class MLAggregator extends Aggregator { + protected ArrayList fvAttributes; + protected Instances unFilteredInstances; + protected int trainingPerc; + protected Instances trainingSet; + protected Instances testingSet; + protected int NumOfAttributes; + protected String[] options; + protected boolean flag; + protected boolean isClusterer; + protected ArrayList nominalAttr; + + public MLAggregator() { + fvAttributes = new ArrayList(); + nominalAttr = new ArrayList(); + trainingPerc = 100; + } + + public MLAggregator(final String s) { + this(); + try { + options = handleNonWekaOptions(Utils.splitOptions(s)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + // this function is used to handle non-weka options (-s: split) + private String[] handleNonWekaOptions(String[] opts) { + List others = new ArrayList<>(); + for (int i = 0; i < opts.length; i++) { + String cur = opts[i]; + if (cur.equals("-s")) + trainingPerc = Integer.parseInt(opts[++i]); + else + others.add(opts[i]); + } + return others.toArray(new String[0]); + } + + public void evaluate(Classifier model, Instances set) { + try { + Evaluation eval = new Evaluation(set); + eval.evaluateModel(model, set); + String setName = set == trainingSet ? "Training" : "Testing"; + collect(eval.toSummaryString("\n" + setName + "Set Evaluation:\n", false)); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void evaluate(Clusterer clusterer, Instances set) { + try { + ClusterEvaluation eval = new ClusterEvaluation(); + eval.setClusterer(clusterer); + set.setClassIndex(set.numAttributes() - 1); + eval.evaluateClusterer(set); + String setName = set == trainingSet ? "Training" : "Testing"; + collect("\n" + setName + "Set Evaluation:\n" + eval.clusterResultsToString()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + // TODO: this is not fixed + public void saveTrainingSet(Object set) { + FSDataOutputStream out = null; + FileSystem fileSystem = null; + Path filePath = null; + ObjectOutputStream objectOut = null; + + try { + JobContext context = (JobContext) getContext(); + Configuration configuration = context.getConfiguration(); + int boaJobId = configuration.getInt("boa.hadoop.jobid", 0); + JobConf job = new JobConf(configuration); + Path outputPath = FileOutputFormat.getOutputPath(job); + fileSystem = outputPath.getFileSystem(context.getConfiguration()); + String output = null; + String subpath = "_" + trainingSet.attribute(0).name() + "_"; + if (DefaultProperties.localOutput != null) + output = DefaultProperties.localOutput; + else + output = configuration.get("fs.default.name", "hdfs://boa-njt/"); + for (int i = 1; i < NumOfAttributes; i++) { + // System.out.println(trainingSet.attribute(0).name()); + subpath += "_" + trainingSet.attribute(i).name() + "_"; + } + fileSystem.mkdirs(new Path(output, new Path("/model" + boaJobId))); + filePath = new Path(output, + new Path("/model" + boaJobId, new Path(("" + getKey()).split("\\[")[0] + subpath + "data"))); + + if (fileSystem.exists(filePath)) + return; + + out = fileSystem.create(filePath); + + ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); + objectOut = new ObjectOutputStream(byteOutStream); + objectOut.writeObject(set); + byte[] serializedObject = byteOutStream.toByteArray(); + out.write(serializedObject); + + collect(filePath.toString()); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (out != null) + out.close(); + if (objectOut != null) + objectOut.close(); + } catch (final Exception e) { + e.printStackTrace(); + } + } + } + + public void saveModel(Object model) { + FSDataOutputStream out = null; + FileSystem fileSystem = null; + Path filePath = null; + ObjectOutputStream objectOut = null; + + try { + JobContext context = (JobContext) getContext(); + Configuration conf = context.getConfiguration(); + int boaJobId = conf.getInt("boa.hadoop.jobid", 0); + JobConf job = new JobConf(conf); + Path outputPath = FileOutputFormat.getOutputPath(job); + fileSystem = outputPath.getFileSystem(context.getConfiguration()); + String output = DefaultProperties.localOutput != null + ? new Path(DefaultProperties.localOutput).toString() + "/../" + : conf.get("fs.default.name", "hdfs://boa-njt/"); + fileSystem.mkdirs(getModelDirPath(output, boaJobId)); + filePath = getModelFilePath(output, boaJobId, getKey().getName()); + + // delete previous model + if (fileSystem.exists(filePath)) { + fileSystem.delete(filePath, true); + System.out.println("deleted previous model"); + } + + // serialize the model and write to the path + out = fileSystem.create(filePath); + ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); + objectOut = new ObjectOutputStream(byteOutStream); + objectOut.writeObject(model); + out.write(byteOutStream.toByteArray()); + + collect("Model is saved to: " + filePath.toString()); + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (out != null) + out.close(); + if (objectOut != null) + objectOut.close(); + } catch (final Exception e) { + e.printStackTrace(); + } + } + } + + public static Path getModelDirPath(String output, int boaJobId) { + return new Path(output, new Path("model/job_" + boaJobId)); + } + + public static Path getModelFilePath(String output, int boaJobId, String modelVar) { + return new Path(getModelDirPath(output, boaJobId), new Path(modelVar + ".model")); + } + + protected void applyFilterToUnfilteredInstances(Filter filter) throws Exception { + unFilteredInstances = Filter.useFilter(unFilteredInstances, filter); + } + + protected void applyFilterToUnfilteredInstances(Filter filter, Instances filteredInstances) throws Exception { + unFilteredInstances = Filter.useFilter(unFilteredInstances, filter); + moveFromUnFilteredToFiltered(filteredInstances); + } + + protected void moveFromUnFilteredToFiltered(Instances filteredInstances) { + int totalUnfilteredInstances = unFilteredInstances.numInstances(); + filteredInstances.addAll(unFilteredInstances.subList(0, totalUnfilteredInstances)); + unFilteredInstances.delete(); + } + + // create attributes with tuple input data + protected void attributeCreation(Tuple data, final String name) { + if (flag == true) + return; + fvAttributes.clear(); + try { + String[] fieldNames = data.getFieldNames(); + int count = 0; + for (int i = 0; i < fieldNames.length; i++) { + if (data.getValue(fieldNames[i]).getClass().isEnum()) { + ArrayList fvNominalVal = new ArrayList(); + for (Object obj : data.getValue(fieldNames[i]).getClass().getEnumConstants()) + fvNominalVal.add(obj.toString()); + fvAttributes.add(new Attribute("Nominal" + count, fvNominalVal)); + count++; + } else if (data.getValue(fieldNames[i]).getClass().isArray()) { + int l = Array.getLength(data.getValue(fieldNames[i])) - 1; + for (int j = 0; j <= l; j++) { + fvAttributes.add(new Attribute("Attribute" + count)); + count++; + } + } else { + fvAttributes.add(new Attribute("Attribute" + count)); + count++; + } + } + NumOfAttributes = count; // use NumOfAttributes for tuple data + flag = true; + trainingSet = new Instances(name, fvAttributes, 1); + testingSet = new Instances(name, fvAttributes, 1); + if (!isClusterer) { + trainingSet.setClassIndex(NumOfAttributes - 1); + testingSet.setClassIndex(NumOfAttributes - 1); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + // create instance this tuple input data + private void instanceCreation(Tuple data, Instances set) { + try { + int count = 0; + Instance instance = new DenseInstance(NumOfAttributes); + String[] fieldNames = data.getFieldNames(); + for (int i = 0; i < fieldNames.length; i++) { + if (data.getValue(fieldNames[i]).getClass().isEnum()) { + instance.setValue(fvAttributes.get(count), String.valueOf(data.getValue(fieldNames[i]))); + count++; + } else if (data.getValue(fieldNames[i]).getClass().isArray()) { + int x = Array.getLength(data.getValue(fieldNames[i])) - 1; + Object o = data.getValue(fieldNames[i]); + for (int j = 0; j <= x; j++) { + instance.setValue(fvAttributes.get(count), Double.parseDouble(String.valueOf(Array.get(o, j)))); + count++; + } + } else { + if (NumberUtils.isNumber(String.valueOf(data.getValue(fieldNames[i])))) + instance.setValue(fvAttributes.get(count), + Double.parseDouble(String.valueOf(data.getValue(fieldNames[i])))); + else + instance.setValue(fvAttributes.get(count), String.valueOf(data.getValue(fieldNames[i]))); + count++; + } + } + set.add(instance); + } catch (Exception e) { + e.printStackTrace(); + } + } + + // create attributes with string[] input data + private void attributeCreation(String[] data, String name) { + if (flag == true) + return; + fvAttributes.clear(); + try { + for (int i = 0; i < data.length; i++) + fvAttributes.add(new Attribute("Attribute" + i)); + trainingSet = new Instances(name, fvAttributes, 1); + testingSet = new Instances(name, fvAttributes, 1); + if (!isClusterer) { + trainingSet.setClassIndex(data.length - 1); // use data length for String[] data + testingSet.setClassIndex(data.length - 1); + } + flag = true; + } catch (Exception e) { + e.printStackTrace(); + } + } + + // create instance this string[] input data + private void instanceCreation(String[] data, Instances set) { + try { + Instance instance = new DenseInstance(data.length); + for (int i = 0; i < data.length; i++) + instance.setValue(fvAttributes.get(i), Double.parseDouble(data[i])); + set.add(instance); + } catch (Exception e) { + e.printStackTrace(); + } + } + + protected void aggregate(final String[] data, final String metadata, String name) + throws IOException, InterruptedException { + attributeCreation(data, name); + instanceCreation(data, isTrainData() ? trainingSet : testingSet); + } + + protected void aggregate(final Tuple data, final String metadata, String name) + throws IOException, InterruptedException { + attributeCreation(data, name); + instanceCreation(data, isTrainData() ? trainingSet : testingSet); + } + + private boolean isTrainData() { + return Math.random() > (1 - trainingPerc / 100.0); + } + + public abstract void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException; + + public abstract void aggregate(final String[] data, final String metadata) throws IOException, InterruptedException; + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/MultiClassClassifierAggregator.java b/src/java/boa/aggregators/ml/MultiClassClassifierAggregator.java new file mode 100644 index 000000000..812182d18 --- /dev/null +++ b/src/java/boa/aggregators/ml/MultiClassClassifierAggregator.java @@ -0,0 +1,73 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.classifiers.meta.MultiClassClassifier; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using MultiClassClassifier. + * + * @author ankuraga + */ +@AggregatorSpec(name = "multiclassclassifier", formalParameters = { "string" }) +public class MultiClassClassifierAggregator extends MLAggregator { + private MultiClassClassifier model; + + public MultiClassClassifierAggregator() { + } + + public MultiClassClassifierAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "MultiClassClassifier"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "MultiClassClassifier"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new MultiClassClassifier(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/MultiSchemeAggregator.java b/src/java/boa/aggregators/ml/MultiSchemeAggregator.java new file mode 100644 index 000000000..380d4d952 --- /dev/null +++ b/src/java/boa/aggregators/ml/MultiSchemeAggregator.java @@ -0,0 +1,73 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.classifiers.meta.MultiScheme; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using LinearRegression. + * + * @author ankuraga + */ +@AggregatorSpec(name = "multischeme", formalParameters = { "string" }) +public class MultiSchemeAggregator extends MLAggregator { + private MultiScheme model; + + public MultiSchemeAggregator() { + } + + public MultiSchemeAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "MultiScheme"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "MultiScheme"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new MultiScheme(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/MultilayerPerceptronAggregator.java b/src/java/boa/aggregators/ml/MultilayerPerceptronAggregator.java new file mode 100644 index 000000000..05841832f --- /dev/null +++ b/src/java/boa/aggregators/ml/MultilayerPerceptronAggregator.java @@ -0,0 +1,72 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.classifiers.functions.MultilayerPerceptron; +import java.io.IOException; + +/** + * A Boa aggregator for training the model using MultilayerPerceptron. + * + * @author ankuraga + */ +@AggregatorSpec(name = "multilayerperceptron", formalParameters = { "string" }) +public class MultilayerPerceptronAggregator extends MLAggregator { + private MultilayerPerceptron model; + + public MultilayerPerceptronAggregator() { + } + + public MultilayerPerceptronAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "MultiClassClassifier"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "MultiClassClassifier"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new MultilayerPerceptron(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/NaiveBayesAggregator.java b/src/java/boa/aggregators/ml/NaiveBayesAggregator.java new file mode 100644 index 000000000..594488f0c --- /dev/null +++ b/src/java/boa/aggregators/ml/NaiveBayesAggregator.java @@ -0,0 +1,72 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.classifiers.bayes.NaiveBayes; +import java.io.IOException; + +/** + * A Boa aggregator for training the model using LinearRegression. + * + * @author ankuraga + */ +@AggregatorSpec(name = "naivebayes", formalParameters = { "string" }) +public class NaiveBayesAggregator extends MLAggregator { + private NaiveBayes model; + + public NaiveBayesAggregator() { + } + + public NaiveBayesAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "NaiveBayes"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "NaiveBayes"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new NaiveBayes(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/NaiveBayesMultinomialUpdateableAggregator.java b/src/java/boa/aggregators/ml/NaiveBayesMultinomialUpdateableAggregator.java new file mode 100644 index 000000000..84ec544a4 --- /dev/null +++ b/src/java/boa/aggregators/ml/NaiveBayesMultinomialUpdateableAggregator.java @@ -0,0 +1,70 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.runtime.Tuple; +import boa.aggregators.AggregatorSpec; +import weka.classifiers.bayes.NaiveBayesMultinomialUpdateable; +import java.io.IOException; + +/** + * A Boa aggregator for training the model using AdaBoostM1. + * + * @author ankuraga + * @author nmtiwari + */ +@AggregatorSpec(name = "naivebayesmultinomialupdateable", formalParameters = { "string" }) +public class NaiveBayesMultinomialUpdateableAggregator extends MLAggregator { + private NaiveBayesMultinomialUpdateable model; + + public NaiveBayesMultinomialUpdateableAggregator() { + } + + public NaiveBayesMultinomialUpdateableAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(final String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "NaiveBayesMultinomialUpdateable"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "NaiveBayesMultinomialUpdateable"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new NaiveBayesMultinomialUpdateable(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/OneRAggregator.java b/src/java/boa/aggregators/ml/OneRAggregator.java new file mode 100644 index 000000000..3850b480d --- /dev/null +++ b/src/java/boa/aggregators/ml/OneRAggregator.java @@ -0,0 +1,70 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.runtime.Tuple; +import boa.aggregators.AggregatorSpec; +import weka.classifiers.rules.OneR; +import java.io.IOException; + +/** + * A Boa aggregator for training the model using AdaBoostM1. + * + * @author ankuraga + * @author nmtiwari + */ +@AggregatorSpec(name = "oner", formalParameters = { "string" }) +public class OneRAggregator extends MLAggregator { + private OneR model; + + public OneRAggregator() { + } + + public OneRAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(final String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "OneR"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "OneR"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new OneR(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/PARTAggregator.java b/src/java/boa/aggregators/ml/PARTAggregator.java new file mode 100644 index 000000000..acf4d1c26 --- /dev/null +++ b/src/java/boa/aggregators/ml/PARTAggregator.java @@ -0,0 +1,71 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.runtime.Tuple; +import boa.aggregators.AggregatorSpec; +import weka.classifiers.rules.PART; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using AdaBoostM1. + * + * @author ankuraga + * @author nmtiwari + */ +@AggregatorSpec(name = "part", formalParameters = { "string" }) +public class PARTAggregator extends MLAggregator { + private PART model; + + public PARTAggregator() { + } + + public PARTAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(final String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "PART"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "PART"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new PART(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/RandomForestAggregator.java b/src/java/boa/aggregators/ml/RandomForestAggregator.java new file mode 100644 index 000000000..c39945088 --- /dev/null +++ b/src/java/boa/aggregators/ml/RandomForestAggregator.java @@ -0,0 +1,73 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.classifiers.trees.RandomForest; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using LinearRegression. + * + * @author ankuraga + */ +@AggregatorSpec(name = "randomforest", formalParameters = { "string" }) +public class RandomForestAggregator extends MLAggregator { + private RandomForest model; + + public RandomForestAggregator() { + } + + public RandomForestAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "RandomForest"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "RandomForest"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new RandomForest(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/SMOAggregator.java b/src/java/boa/aggregators/ml/SMOAggregator.java new file mode 100644 index 000000000..0c4c4c83a --- /dev/null +++ b/src/java/boa/aggregators/ml/SMOAggregator.java @@ -0,0 +1,71 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.classifiers.functions.SMO; +import java.io.IOException; + +/** + * A Boa aggregator for training the model using LinearRegression. + * + * @author ankuraga + */ +@AggregatorSpec(name = "smo", formalParameters = { "string" }) +public class SMOAggregator extends MLAggregator { + private SMO model; + + public SMOAggregator() { + } + + public SMOAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "SMO"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "SMO"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new SMO(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } +} diff --git a/src/java/boa/aggregators/ml/Sequence2VectorAggregator.java b/src/java/boa/aggregators/ml/Sequence2VectorAggregator.java new file mode 100644 index 000000000..5885a770d --- /dev/null +++ b/src/java/boa/aggregators/ml/Sequence2VectorAggregator.java @@ -0,0 +1,106 @@ +package boa.aggregators.ml; + +import java.io.IOException; +import java.util.LinkedList; + +import org.deeplearning4j.models.embeddings.loader.VectorsConfiguration; +import org.deeplearning4j.models.sequencevectors.SequenceVectors; +import org.deeplearning4j.models.sequencevectors.iterators.AbstractSequenceIterator; +import org.deeplearning4j.models.sequencevectors.transformers.impl.SentenceTransformer; +import org.deeplearning4j.models.word2vec.VocabWord; +import org.deeplearning4j.text.sentenceiterator.CollectionSentenceIterator; +import org.deeplearning4j.text.sentenceiterator.SentenceIterator; +import org.deeplearning4j.text.stopwords.StopWords; +import org.deeplearning4j.text.tokenization.tokenizer.preprocessor.CommonPreprocessor; +import org.deeplearning4j.text.tokenization.tokenizerfactory.DefaultTokenizerFactory; +import org.deeplearning4j.text.tokenization.tokenizerfactory.TokenizerFactory; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.core.Utils; + +@AggregatorSpec(name = "seq2vec", formalParameters = { "string" }) +public class Sequence2VectorAggregator extends MLAggregator { + LinkedList train; + + public Sequence2VectorAggregator() { + train = new LinkedList(); + } + + public Sequence2VectorAggregator(final String s) { + this(); + try { + options = Utils.splitOptions(s); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + for (String s : data) + train.add(s); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + train.add(data); + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + // load train dataset + SentenceIterator iter = new CollectionSentenceIterator(train); + + // tokenization and preprocess + TokenizerFactory t = new DefaultTokenizerFactory(); + t.setTokenPreProcessor(new CommonPreprocessor()); + + SentenceTransformer transformer = new SentenceTransformer.Builder().iterator(iter).tokenizerFactory(t) + .build(); + AbstractSequenceIterator itr = new AbstractSequenceIterator.Builder(transformer) + .build(); + + // train model + SequenceVectors.Builder sb = new SequenceVectors.Builder(new VectorsConfiguration()); + updateOptions(sb); + SequenceVectors sv = sb.iterate(itr).build(); + sv.fit(); + + // save model + saveModel(sv); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void updateOptions(SequenceVectors.Builder sb) { + for (int i = 0; i < options.length; i++) { + String cur = options[i]; + if (cur.equals("-s")) + trainingPerc = Integer.parseInt(options[++i]); + else if (cur.equals("-f")) + sb.minWordFrequency(Integer.parseInt(options[++i])); + else if (cur.equals("-lr")) + sb.minLearningRate(Integer.parseInt(options[++i])); + else if (cur.equals("-ls")) + sb.layerSize(Integer.parseInt(options[++i])); + else if (cur.equals("-ws")) + sb.windowSize(Integer.parseInt(options[++i])); + else if (cur.equals("-i")) + sb.iterations(Integer.parseInt(options[++i])); + else if (cur.equals("-b")) + sb.batchSize(Integer.parseInt(options[++i])); + else if (cur.equals("-stop")) + sb.stopWords(StopWords.getStopWords()); + } + } +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/SimpleKMeansAggregator.java b/src/java/boa/aggregators/ml/SimpleKMeansAggregator.java new file mode 100644 index 000000000..c4830ae09 --- /dev/null +++ b/src/java/boa/aggregators/ml/SimpleKMeansAggregator.java @@ -0,0 +1,75 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.clusterers.SimpleKMeans; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using SimpleKMeans. + * + * @author ankuraga + */ +@AggregatorSpec(name = "simplekmeans", formalParameters = { "string" }) +public class SimpleKMeansAggregator extends MLAggregator { + private SimpleKMeans model; + + public SimpleKMeansAggregator() { + this.isClusterer = true; + } + + public SimpleKMeansAggregator(final String s) { + super(s); + this.isClusterer = true; + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "SimpleKMeans"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "SimpleKMeans"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new SimpleKMeans(); + this.model.setOptions(options); + this.model.buildClusterer(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/VoteAggregator.java b/src/java/boa/aggregators/ml/VoteAggregator.java new file mode 100644 index 000000000..64daac67d --- /dev/null +++ b/src/java/boa/aggregators/ml/VoteAggregator.java @@ -0,0 +1,72 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.classifiers.meta.Vote; + +import java.io.IOException; + +/** + * A Boa aggregator for training the model using LinearRegression. + * + * @author ankuraga + */ +@AggregatorSpec(name = "vote", formalParameters = { "string" }) +public class VoteAggregator extends MLAggregator { + private Vote model; + + public VoteAggregator() { + } + + public VoteAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "Vote"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "Vote"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new Vote(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } +} \ No newline at end of file diff --git a/src/java/boa/aggregators/ml/Word2VectorAggregator.java b/src/java/boa/aggregators/ml/Word2VectorAggregator.java new file mode 100644 index 000000000..803b36035 --- /dev/null +++ b/src/java/boa/aggregators/ml/Word2VectorAggregator.java @@ -0,0 +1,104 @@ +package boa.aggregators.ml; + +import java.io.IOException; +import java.util.LinkedList; + +import org.deeplearning4j.models.word2vec.Word2Vec; +import org.deeplearning4j.models.word2vec.Word2Vec.Builder; +import org.deeplearning4j.text.sentenceiterator.CollectionSentenceIterator; +import org.deeplearning4j.text.sentenceiterator.SentenceIterator; +import org.deeplearning4j.text.sentenceiterator.SentencePreProcessor; +import org.deeplearning4j.text.stopwords.StopWords; +import org.deeplearning4j.text.tokenization.tokenizer.preprocessor.CommonPreprocessor; +import org.deeplearning4j.text.tokenization.tokenizerfactory.DefaultTokenizerFactory; +import org.deeplearning4j.text.tokenization.tokenizerfactory.TokenizerFactory; + +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.core.Utils; + +@AggregatorSpec(name = "word2vec", formalParameters = { "string" }) +public class Word2VectorAggregator extends MLAggregator { + LinkedList train; + + public Word2VectorAggregator() { + train = new LinkedList(); + } + + public Word2VectorAggregator(final String s) { + this(); + try { + options = Utils.splitOptions(s); + } catch (Exception e) { + e.printStackTrace(); + } + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + for (String s : data) + train.add(s); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + train.add(data); + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + // load train dataset + SentenceIterator iter = new CollectionSentenceIterator(train); + iter.setPreProcessor(new SentencePreProcessor() { + private static final long serialVersionUID = 1L; + + @Override + public String preProcess(String sentence) { + return sentence.toLowerCase(); + } + }); + + // tokenization and preprocess + TokenizerFactory t = new DefaultTokenizerFactory(); + t.setTokenPreProcessor(new CommonPreprocessor()); + + // train model + Word2Vec.Builder wb = new Word2Vec.Builder(); + updateOptions(wb); + Word2Vec vec = wb.iterate(iter).tokenizerFactory(t).build(); + vec.fit(); + + // save model + saveModel(vec); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void updateOptions(Builder wb) { + for (int i = 0; i < options.length; i++) { + String cur = options[i]; + if (cur.equals("-s")) + trainingPerc = Integer.parseInt(options[++i]); + else if (cur.equals("-f")) + wb.minWordFrequency(Integer.parseInt(options[++i])); + else if (cur.equals("-lr")) + wb.minLearningRate(Integer.parseInt(options[++i])); + else if (cur.equals("-ls")) + wb.layerSize(Integer.parseInt(options[++i])); + else if (cur.equals("-ws")) + wb.windowSize(Integer.parseInt(options[++i])); + else if (cur.equals("-stop")) + wb.stopWords(StopWords.getStopWords()); + } + } + +} diff --git a/src/java/boa/aggregators/ml/ZeroRAggregator.java b/src/java/boa/aggregators/ml/ZeroRAggregator.java new file mode 100644 index 000000000..eead6b00b --- /dev/null +++ b/src/java/boa/aggregators/ml/ZeroRAggregator.java @@ -0,0 +1,72 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.aggregators.ml; + +import java.io.IOException; +import boa.aggregators.AggregatorSpec; +import boa.runtime.Tuple; +import weka.classifiers.rules.ZeroR; + +/** + * A Boa aggregator for training the model using ZeroR. + * + * @author ankuraga + */ +@AggregatorSpec(name = "zeror", formalParameters = {"string"}) +public class ZeroRAggregator extends MLAggregator { + private ZeroR model; + + public ZeroRAggregator() { + } + + public ZeroRAggregator(final String s) { + super(s); + } + + @Override + public void aggregate(String[] data, String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "ZeroR"); + } + + @Override + public void aggregate(final Tuple data, final String metadata) throws IOException, InterruptedException { + aggregate(data, metadata, "ZeroR"); + } + + @Override + public void aggregate(String data, String metadata) throws IOException, InterruptedException { + } + + /** + * {@inheritDoc} + */ + @Override + public void finish() throws IOException, InterruptedException { + try { + this.model = new ZeroR(); + this.model.setOptions(options); + this.model.buildClassifier(this.trainingSet); + } catch (Exception e) { + e.printStackTrace(); + } + this.saveModel(this.model); + this.evaluate(this.model, this.trainingSet); + this.evaluate(this.model, this.testingSet); + this.collect(this.model.toString()); + } + +} \ No newline at end of file diff --git a/src/java/boa/compiler/SymbolTable.java b/src/java/boa/compiler/SymbolTable.java index ea182ba05..0a7b80a1d 100644 --- a/src/java/boa/compiler/SymbolTable.java +++ b/src/java/boa/compiler/SymbolTable.java @@ -28,9 +28,9 @@ import boa.aggregators.AggregatorSpec; import boa.functions.FunctionSpec; import boa.types.*; +import boa.types.ml.*; import boa.types.proto.*; import boa.types.proto.enums.*; - import boa.compiler.ast.Operand; import boa.compiler.ast.statements.VisitStatement; @@ -379,6 +379,45 @@ public static void resetTypeMap() { types.put("float", new BoaFloat()); types.put("time", new BoaTime()); types.put("string", new BoaString()); + types.put("model", new BoaModel()); + types.put("tuple", new BoaTuple()); + + types.put("LinearRegression", new BoaLinearRegression()); + types.put("AdaBoostM1", new BoaAdaBoostM1()); + types.put("ZeroR", new BoaZeroR()); + types.put("Vote", new BoaVote()); + types.put("SMO", new BoaSMO()); + types.put("SimpleKMeans", new BoaSimpleKMeans()); + types.put("RandomForest", new BoaRandomForest()); + types.put("AdditiveRegression", new BoaAdditiveRegression()); + types.put("AttributeSelectedClassifier", new BoaAttributeSelectedClassifier()); + types.put("PART", new BoaPART()); + types.put("OneR", new BoaOneR()); + types.put("NaiveBayesMultinomialUpdateable", new BoaNaiveBayesMultinomialUpdateable()); + types.put("NaiveBayes", new BoaNaiveBayes()); + types.put("MultiScheme", new BoaMultiScheme()); + types.put("MultilayerPerceptron", new BoaMultilayerPerceptron()); + types.put("MultiScheme", new BoaMultiScheme()); + types.put("MultiClassClassifier", new BoaMultiClassClassifier()); + types.put("MultilayerPerceptron", new BoaMultilayerPerceptron()); + types.put("Bagging", new BoaBagging()); + types.put("BayesNet", new BoaBayesNet()); + types.put("ClassificationViaRegression", new BoaClassificationViaRegression()); + types.put("LWL", new BoaLWL()); + types.put("LogitBoost", new BoaLogitBoost()); + types.put("LMT", new BoaLMT()); + types.put("LogisticRegression", new BoaLogisticRegression()); + types.put("J48", new BoaJ48()); + types.put("JRip", new BoaJRip()); + types.put("KStar", new BoaKStar()); + types.put("CVParameterSelection", new BoaCVParameterSelection()); + types.put("DecisionStump", new BoaDecisionStump()); + types.put("DecisionTable", new BoaDecisionTable()); + types.put("FilteredClassifier", new BoaFilteredClassifier()); + types.put("GaussianProcesses", new BoaGaussianProcesses()); + types.put("InputMappedClassifier", new BoaInputMappedClassifier()); + types.put("Word2Vec", new BoaWord2Vec()); + types.put("Seq2Vec", new BoaSequence2Vec()); for (final BoaType t : dslTupleTypes) types.put(t.toString(), t); @@ -554,6 +593,7 @@ private static void importLibs(final List urls) throws IOException { boa.functions.BoaAstIntrinsics.class, boa.functions.BoaGraphIntrinsics.class, boa.functions.BoaIntrinsics.class, + boa.functions.BoaMLIntrinsics.class, boa.functions.BoaMetricIntrinsics.class, boa.functions.BoaNormalFormIntrinsics.class, boa.functions.BoaModifierIntrinsics.class, @@ -596,7 +636,42 @@ private static void importLibs(final List urls) throws IOException { boa.aggregators.UniqueAggregator.class, boa.aggregators.VarianceAggregator.class, boa.aggregators.PreconditionAggregator.class, + boa.aggregators.ml.LinearRegressionAggregator.class, + boa.aggregators.ml.AdaBoostM1Aggregator.class, + boa.aggregators.ml.ZeroRAggregator.class, + boa.aggregators.ml.VoteAggregator.class, + boa.aggregators.ml.SMOAggregator.class, + boa.aggregators.ml.SimpleKMeansAggregator.class, + boa.aggregators.ml.RandomForestAggregator.class, + boa.aggregators.ml.AdditiveRegressionAggregator.class, + boa.aggregators.ml.AttributeSelectedClassifierAggregator.class, + boa.aggregators.ml.PARTAggregator.class, + boa.aggregators.ml.OneRAggregator.class, + boa.aggregators.ml.NaiveBayesMultinomialUpdateableAggregator.class, + boa.aggregators.ml.NaiveBayesAggregator.class, + boa.aggregators.ml.MultiSchemeAggregator.class, + boa.aggregators.ml.MultiClassClassifierAggregator.class, + boa.aggregators.ml.MultilayerPerceptronAggregator.class, + boa.aggregators.ml.BaggingAggregator.class, + boa.aggregators.ml.BayesNetAggregator.class, + boa.aggregators.ml.ClassificationViaRegressionAggregator.class, + boa.aggregators.ml.LWLAggregator.class, + boa.aggregators.ml.LogitBoostAggregator.class, + boa.aggregators.ml.LMTAggregator.class, + boa.aggregators.ml.LogisticRegressionAggregator.class, + boa.aggregators.ml.J48Aggregator.class, + boa.aggregators.ml.KStarAggregator.class, + boa.aggregators.ml.JRipAggregator.class, + boa.aggregators.ml.CVParameterSelectionAggregator.class, + boa.aggregators.ml.DecisionStumpAggregator.class, + boa.aggregators.ml.DecisionTableAggregator.class, + boa.aggregators.ml.FilteredClassifierAggregator.class, + boa.aggregators.ml.GaussianProcessesAggregator.class, + boa.aggregators.ml.InputMappedClassifierAggregator.class, + boa.aggregators.ml.Word2VectorAggregator.class, + boa.aggregators.ml.Sequence2VectorAggregator.class }; + for (final Class c : builtinAggs) importAggregator(c); @@ -755,4 +830,13 @@ public String toString() { return r.toString(); } + + public static BoaType getMLAggregatorType(String aggregtorName) { + for (Entry e : types.entrySet()) { + if (e.getKey().equalsIgnoreCase(aggregtorName)) { + return e.getValue(); + } + } + return null; + } } diff --git a/src/java/boa/compiler/ast/types/ModelType.java b/src/java/boa/compiler/ast/types/ModelType.java new file mode 100644 index 000000000..4b5e8566e --- /dev/null +++ b/src/java/boa/compiler/ast/types/ModelType.java @@ -0,0 +1,91 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.compiler.ast.types; + +import java.util.ArrayList; +import java.util.List; + +import boa.compiler.ast.Component; +import boa.compiler.ast.Identifier; +import boa.compiler.visitors.AbstractVisitor; +import boa.compiler.visitors.AbstractVisitorNoArgNoRet; +import boa.compiler.visitors.AbstractVisitorNoReturn; + +/** + * + * @author ankuraga + */ +public class ModelType extends AbstractType { + protected Identifier id; + protected Component t; + + public Identifier getId() { + return id; + } + + public void setId(final Identifier id) { + id.setParent(this); + this.id = id; + } + + public Component getType() { + return t; + } + + public void setType(final Component t) { + t.setParent(this); + this.t = t; + } + + public ModelType (final Identifier id) { + this(id, null); + } + + public ModelType (final Identifier id, final Component t) { + if (id != null) + id.setParent(this); + if (t != null) + t.setParent(this); + this.id = id; + this.t = t; + } + + /** {@inheritDoc} */ + @Override + public T accept(final AbstractVisitor v, A arg) { + return v.visit(this, arg); + } + + /** {@inheritDoc} */ + @Override + public void accept(final AbstractVisitorNoReturn v, A arg) { + v.visit(this, arg); + } + + /** {@inheritDoc} */ + @Override + public void accept(final AbstractVisitorNoArgNoRet v) { + v.visit(this); + } + + public ModelType clone() { + final ModelType m; + m = new ModelType(id.clone(), t.clone()); + copyFieldsTo(m); + return m; + } +} diff --git a/src/java/boa/compiler/visitors/AbstractVisitor.java b/src/java/boa/compiler/visitors/AbstractVisitor.java index 85c992b38..8c768e765 100644 --- a/src/java/boa/compiler/visitors/AbstractVisitor.java +++ b/src/java/boa/compiler/visitors/AbstractVisitor.java @@ -468,4 +468,10 @@ public ReturnTypeT visit(final TraversalType n, final ArgTypeT arg) { public ReturnTypeT visit(final FixPType n, final ArgTypeT arg) { return null; } + + public ReturnTypeT visit(final ModelType n, final ArgTypeT arg) { + n.getId().accept(this, arg); + n.getType().accept(this, arg); + return null; + } } diff --git a/src/java/boa/compiler/visitors/AbstractVisitorNoArgNoRet.java b/src/java/boa/compiler/visitors/AbstractVisitorNoArgNoRet.java index a022a0f3a..e538fe0a7 100644 --- a/src/java/boa/compiler/visitors/AbstractVisitorNoArgNoRet.java +++ b/src/java/boa/compiler/visitors/AbstractVisitorNoArgNoRet.java @@ -414,4 +414,9 @@ public void visit(final TraversalType n) { public void visit(final FixPType n) { } + + public void visit(final ModelType n) { + n.getId().accept(this); + n.getType().accept(this); + } } diff --git a/src/java/boa/compiler/visitors/AbstractVisitorNoReturn.java b/src/java/boa/compiler/visitors/AbstractVisitorNoReturn.java index bed42124e..26c3345be 100644 --- a/src/java/boa/compiler/visitors/AbstractVisitorNoReturn.java +++ b/src/java/boa/compiler/visitors/AbstractVisitorNoReturn.java @@ -406,4 +406,9 @@ public void visit(final TraversalType n, final ArgTypeT arg) { public void visit(final FixPType n, final ArgTypeT arg) { } + + public void visit(final ModelType n, final ArgTypeT arg) { + n.getId().accept(this, arg); + n.getType().accept(this, arg); + } } diff --git a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java index 16bb1b469..490186ffb 100644 --- a/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java +++ b/src/java/boa/compiler/visitors/CodeGeneratingVisitor.java @@ -37,6 +37,7 @@ import boa.compiler.ast.types.*; import boa.compiler.visitors.analysis.*; import boa.types.*; +import boa.types.ml.BoaModel; /** * @@ -277,17 +278,24 @@ public void visit(final Composite n) { final List fields = new ArrayList(); final List types = new ArrayList(); + final List protos = new ArrayList(); + final List enums = new ArrayList(); int counter = 0; for (final Expression e : n.getExprs()) { fields.add("f" + counter); - types.add(e.type.toBoxedJavaType()); + BoaType type = e.type; counter++; + types.add(type.toBoxedJavaType()); + protos.add(type instanceof BoaProtoTuple); + enums.add(type instanceof BoaEnum); } st.add("name", name); st.add("fields", fields); st.add("types", types); + st.add("protos", protos); + st.add("enums", enums); code.add(st.render()); } @@ -312,6 +320,7 @@ public void visit(final TupleType n) { final List fields = new ArrayList(); final List types = new ArrayList(); final List protos = new ArrayList(); + final List enums = new ArrayList(); int fieldCount = 0; for (final Component c : members) { @@ -323,6 +332,7 @@ public void visit(final TupleType n) { fieldCount++; BoaType type = c.getType().type; protos.add(type instanceof BoaProtoTuple); + enums.add(type instanceof BoaEnum); types.add(type.toBoxedJavaType()); } @@ -330,6 +340,7 @@ public void visit(final TupleType n) { st.add("fields", fields); st.add("types", types); st.add("protos", protos); + st.add("enums", enums); code.add(st.render()); } @@ -1004,6 +1015,16 @@ else if (lhs.charAt(idx) == ')') return; } + if (rhs.contains(".load(")) { + Operand o = n.getLhs().getOperand(); + if (o instanceof Identifier) { + String token = ((Identifier) o).getToken(); + token = token.substring(0, token.lastIndexOf('_')); + rhs = rhs.substring(0,rhs.length()-1) + ", \"" + token + "\"" + ", \"" + n.getLhs().type.toJavaType() + "\"" + ", new " + ((BoaModel)n.getLhs().type).getType().toJavaType() + "())"; + } + rhs = "(" + (n.getLhs().type + "").split("\\/")[0] + ")" + rhs; + } + st.add("lhs", lhs); st.add("operator", n.getOp()); st.add("rhs", rhs); @@ -1874,6 +1895,12 @@ public void visit(final OutputType n) { code.add(""); } + + /** {@inheritDoc} */ + @Override + public void visit(final ModelType n) { + visit(n.getType()); + } /** {@inheritDoc} */ @Override @@ -1923,7 +1950,32 @@ public void visit(final SetType n) { /** {@inheritDoc} */ @Override public void visit(final TupleType n) { - throw new RuntimeException("unexpected error"); + final ST st = stg.getInstanceOf("TupleType"); + + if (!(n.type instanceof BoaTuple)) + throw new TypeCheckException(n ,"type " + n.type + " is not a tuple type"); + + final BoaTuple tupType = ((BoaTuple) n.type); + + final List members = n.getMembers(); + final List fields = new ArrayList(); + final List types = new ArrayList(); + + int fieldCount = 0; + for (final Component c : members) { + if(c.hasIdentifier()){ + fields.add(c.getIdentifier().getToken()); + } else { + fields.add("id" + fieldCount++); + } + types.add(c.getType().type.toJavaType()); + } + + st.add("name", tupType.toJavaType()); + st.add("fields", fields); + st.add("types", types); + + code.add(st.render()); } /** {@inheritDoc} */ diff --git a/src/java/boa/compiler/visitors/TypeCheckingVisitor.java b/src/java/boa/compiler/visitors/TypeCheckingVisitor.java index 7d9f38100..eebb37f64 100644 --- a/src/java/boa/compiler/visitors/TypeCheckingVisitor.java +++ b/src/java/boa/compiler/visitors/TypeCheckingVisitor.java @@ -30,6 +30,7 @@ import boa.compiler.ast.types.*; import boa.compiler.transforms.VisitorDesugar; import boa.types.*; +import boa.types.ml.*; import boa.types.proto.CodeRepositoryProtoTuple; /** @@ -77,16 +78,18 @@ public void visit(final VisitStatement n) { final Set s = n.isBefore() ? befores : afters; if (n.hasComponent()) { - final Identifier id = (Identifier)n.getComponent().getType(); + final Identifier id = (Identifier) n.getComponent().getType(); final String token = id.getToken(); if (s.contains(token)) - throw new TypeCheckException(id, "The type '" + token + "' already has a '" + (n.isBefore() ? "before" : "after") + "' visit statement"); + throw new TypeCheckException(id, "The type '" + token + "' already has a '" + + (n.isBefore() ? "before" : "after") + "' visit statement"); s.add(token); } else if (n.getIdListSize() > 0) { for (final Identifier id : n.getIdList()) { final String token = id.getToken(); if (s.contains(token)) - throw new TypeCheckException(id, "The type '" + token + "' already has a '" + (n.isBefore() ? "before" : "after") + "' visit statement"); + throw new TypeCheckException(id, "The type '" + token + "' already has a '" + + (n.isBefore() ? "before" : "after") + "' visit statement"); s.add(token); } } @@ -118,7 +121,7 @@ public void visit(final TraversalExpression n) { @Override public void visit(final TraverseStatement n) { if (n.hasComponent()) { - final Identifier id = (Identifier)n.getComponent().getType(); + final Identifier id = (Identifier) n.getComponent().getType(); final String token = id.getToken(); if (befores.contains(token)) throw new TypeCheckException(id, "The type '" + token + "' already has a traverse statement"); @@ -159,11 +162,11 @@ public void visit(final FixPExpression n) { /** {@inheritDoc} */ @Override public void visit(final FixPStatement n) { - final Identifier id = (Identifier)n.getParam1().getType(); + final Identifier id = (Identifier) n.getParam1().getType(); final String token = id.getToken(); befores.add(token); - final Identifier id1 = (Identifier)n.getParam2().getType(); + final Identifier id1 = (Identifier) n.getParam2().getType(); final String token1 = id1.getToken(); befores.add(token1); } @@ -171,8 +174,8 @@ public void visit(final FixPStatement n) { } /** - * This does type checking of function bodies to ensure the - * returns are the correct type. + * This does type checking of function bodies to ensure the returns are the + * correct type. * * @author rdyer */ @@ -216,7 +219,8 @@ public void visit(final ReturnStatement n) { if (!(retType instanceof BoaAny) && !n.hasExpr()) throw new TypeCheckException(n, "must return a value of type '" + retType + "'"); if (!(retType instanceof BoaAny) && !retType.assigns(n.getExpr().type)) - throw new TypeCheckException(n.getExpr(), "incompatible types: required '" + retType + "', found '" + n.getExpr().type + "'"); + throw new TypeCheckException(n.getExpr(), + "incompatible types: required '" + retType + "', found '" + n.getExpr().type + "'"); } } @@ -259,7 +263,24 @@ public void visit(final Program n, final SymbolTable env) { @Override public void visit(final Call n, final SymbolTable env) { n.env = env; - + List expr = this.check(n.getArgs(), env); + if (expr.size() > 1) { + if (expr.get(0) instanceof BoaModel && expr.get(1) instanceof BoaTuple) { + final BoaType t = ((BoaModel) expr.get(0)).getType(); + if (t instanceof BoaTuple) { + final List mtypes = ((BoaTuple) t).getTypes(); + final List vtypes = ((BoaTuple) expr.get(1)).getTypes(); + if (mtypes.size() - 1 == vtypes.size()) { + for (int i = 0; i < mtypes.size() - 1; i++) + if (!(mtypes.get(i).toString().equals(vtypes.get(i).toString()))) + throw new TypeCheckException(n, "incompatible types for model:" + " required '" + + mtypes.get(i) + "', found '" + vtypes.get(i) + "'"); + } else + throw new TypeCheckException(n, "'incorrect number of types for model classification '" + + "': required " + (mtypes.size() - 1) + ", found " + vtypes.size()); + } + } + } if (n.getArgsSize() > 0) n.type = new BoaTuple(this.check(n.getArgs(), env)); else @@ -278,11 +299,14 @@ public void visit(final Comparison n, final SymbolTable env) { n.getRhs().accept(this, env); if (!n.getRhs().type.compares(n.type)) - throw new TypeCheckException(n.getRhs(), "incompatible types for comparison: required '" + n.type + "', found '" + n.getRhs().type + "'"); + throw new TypeCheckException(n.getRhs(), "incompatible types for comparison: required '" + n.type + + "', found '" + n.getRhs().type + "'"); - if (n.type instanceof BoaString || n.type instanceof BoaMap || n.type instanceof BoaSet || n.type instanceof BoaStack || !(n.type instanceof BoaScalar)) + if (n.type instanceof BoaString || n.type instanceof BoaMap || n.type instanceof BoaSet + || n.type instanceof BoaStack || !(n.type instanceof BoaScalar)) if (!n.getOp().equals("==") && !n.getOp().equals("!=")) - throw new TypeCheckException(n.getLhs(), "invalid comparison operator '" + n.getOp() + "' for type '" + n.type + "'"); + throw new TypeCheckException(n.getLhs(), + "invalid comparison operator '" + n.getOp() + "' for type '" + n.type + "'"); n.type = new BoaBool(); } @@ -300,9 +324,11 @@ public void visit(final Component n, final SymbolTable env) { if (!env.getShadowing()) { if (env.hasGlobal(id)) - throw new TypeCheckException(n.getIdentifier(), "name conflict: constant '" + id + "' already exists"); + throw new TypeCheckException(n.getIdentifier(), + "name conflict: constant '" + id + "' already exists"); if (env.hasLocal(id)) - throw new TypeCheckException(n.getIdentifier(), "variable '" + id + "' already declared as '" + env.get(id) + "'"); + throw new TypeCheckException(n.getIdentifier(), + "variable '" + id + "' already declared as '" + env.get(id) + "'"); } n.type = new BoaName(n.getType().type, n.getIdentifier().getToken()); @@ -348,12 +374,14 @@ public void visit(final Conjunction n, final SymbolTable env) { if (n.getRhsSize() > 0) { if (!(ltype instanceof BoaBool)) - throw new TypeCheckException(n.getLhs(), "incompatible types for conjunction: required 'bool', found '" + ltype + "'"); + throw new TypeCheckException(n.getLhs(), + "incompatible types for conjunction: required 'bool', found '" + ltype + "'"); for (final Comparison c : n.getRhs()) { c.accept(this, env); if (!(c.type instanceof BoaBool)) - throw new TypeCheckException(c, "incompatible types for conjunction: required 'bool', found '" + c.type + "'"); + throw new TypeCheckException(c, + "incompatible types for conjunction: required 'bool', found '" + c.type + "'"); } n.type = new BoaBool(); @@ -392,20 +420,27 @@ public void visit(final Factor n, final SymbolTable env) { if (type instanceof BoaArray) { if (!(index instanceof BoaInt)) - throw new TypeCheckException(node, "invalid index type '" + index + "' for indexing into '" + type + "'"); + throw new TypeCheckException(node, + "invalid index type '" + index + "' for indexing into '" + type + "'"); type = ((BoaArray) type).getType(); } else if (type instanceof BoaProtoList) { if (!(index instanceof BoaInt)) - throw new TypeCheckException(node, "invalid index type '" + index + "' for indexing into '" + type + "'"); + throw new TypeCheckException(node, + "invalid index type '" + index + "' for indexing into '" + type + "'"); type = ((BoaProtoList) type).getType(); } else if (type instanceof BoaMap) { if (!((BoaMap) type).getIndexType().assigns(index)) - throw new TypeCheckException(node, "invalid index type '" + index + "' for indexing into '" + type + "'"); + throw new TypeCheckException(node, + "invalid index type '" + index + "' for indexing into '" + type + "'"); if (!n.env.getIsLhs()) - warn(node, "directly indexing maps can lead to runtime crashes - replace with lookup(" + n.getOperand() + ", " + new PrettyPrintVisitor().startAndReturn(((Index)node).getStart()) + ", )"); + warn(node, + "directly indexing maps can lead to runtime crashes - replace with lookup(" + + n.getOperand() + ", " + + new PrettyPrintVisitor().startAndReturn(((Index) node).getStart()) + + ", )"); type = ((BoaMap) type).getType(); } else { throw new TypeCheckException(node, "type '" + type + "' does not allow index operations"); @@ -417,14 +452,17 @@ public void visit(final Factor n, final SymbolTable env) { final List formalParameters = this.check((Call) node, env); try { - type = env.getFunction(((Identifier)n.getOperand()).getToken(), formalParameters).erase(formalParameters); + type = env.getFunction(((Identifier) n.getOperand()).getToken(), formalParameters) + .erase(formalParameters); } catch (final ClassCastException e) { - throw new TypeCheckException(n.getOperand(), "Function declarations must be assigned to a variable and can not be used anonymously", e); + throw new TypeCheckException(n.getOperand(), + "Function declarations must be assigned to a variable and can not be used anonymously", + e); } catch (final RuntimeException e) { throw new TypeCheckException(n.getOperand(), e.getMessage(), e); } - if (formalParameters.size() == 1 && ((Identifier)n.getOperand()).getToken().equals("getvalue")) { + if (formalParameters.size() == 1 && ((Identifier) n.getOperand()).getToken().equals("getvalue")) { type = lastRetType; } } @@ -468,7 +506,8 @@ public void visit(final Index n, final SymbolTable env) { if (n.hasEnd()) { if (!(n.getStart().type instanceof BoaInt)) - throw new TypeCheckException(n.getStart(), "invalid type '" + n.getStart().type + "' for slice expression"); + throw new TypeCheckException(n.getStart(), + "invalid type '" + n.getStart().type + "' for slice expression"); n.getEnd().accept(this, env); if (!(n.getEnd().type instanceof BoaInt)) @@ -501,7 +540,8 @@ public void visit(final Selector n, final SymbolTable env) { throw new TypeCheckException(n.getId(), "'" + type + "' has no member named '" + selector + "'"); if (type instanceof CodeRepositoryProtoTuple && selector.equals("revisions")) { - throw new TypeCheckException(n.getId(), "Accessing " + "'" + selector + "' of '" + type + "' is prohibited! " + throw new TypeCheckException(n.getId(), "Accessing " + "'" + selector + "' of '" + type + + "' is prohibited! " + "Use functions 'getrevisionscount(CodeRepository)' and 'getrevision(CodeRepository, int)' instead! " + "E.g., revision := getrevision(cr, 0); or for (i := 0; i < getrevisionscount(cr); i++) revision := getrevision(cr, i);"); } @@ -513,8 +553,7 @@ public void visit(final Selector n, final SymbolTable env) { if (!((BoaEnum) type).hasMember(selector)) throw new TypeCheckException(n.getId(), "'" + type + "' has no member named '" + selector + "'"); type = ((BoaEnum) type).getMember(selector); - } - else { + } else { throw new TypeCheckException(n, "invalid operand type '" + type + "' for member selection"); } @@ -539,7 +578,8 @@ public void visit(final Term n, final SymbolTable env) { try { type = type.arithmetics(f.type); } catch (final Exception e) { - throw new TypeCheckException(f, "type '" + f.type + "' does not support the '" + n.getOp(i) + "' operator", e); + throw new TypeCheckException(f, + "type '" + f.type + "' does not support the '" + n.getOp(i) + "' operator", e); } } @@ -564,9 +604,9 @@ public void visit(final AssignmentStatement n, final SymbolTable env) { n.env = env; try { - n.env.setIsLhs(true); + n.env.setIsLhs(true); n.getLhs().accept(this, env); - n.env.setIsLhs(false); + n.env.setIsLhs(false); } catch (final TypeCheckException e) { if (!e.getMessage().startsWith("expected a call to function")) throw e; @@ -576,14 +616,18 @@ public void visit(final AssignmentStatement n, final SymbolTable env) { if (!(n.getLhs().type instanceof BoaArray && n.getRhs().type instanceof BoaTuple)) if (!n.getLhs().type.assigns(n.getRhs().type)) - throw new TypeCheckException(n.getRhs(), "incompatible types for assignment: required '" + n.getLhs().type + "', found '" + n.getRhs().type + "'"); + throw new TypeCheckException(n.getRhs(), "incompatible types for assignment: required '" + + n.getLhs().type + "', found '" + n.getRhs().type + "'"); if (n.getLhs().getOperand().type instanceof BoaProtoTuple && n.getLhs().getOpsSize() > 0) - throw new TypeCheckException(n.getLhs(), "assignment not allowed to input-derived type '" + n.getLhs().getOperand().type + "'"); + throw new TypeCheckException(n.getLhs(), + "assignment not allowed to input-derived type '" + n.getLhs().getOperand().type + "'"); final Factor f = n.getRhs().getLhs().getLhs().getLhs().getLhs().getLhs(); - if (f.getOperand() instanceof Identifier && f.getOpsSize() == 0 && env.hasType(((Identifier)f.getOperand()).getToken())) - throw new TypeCheckException(n.getRhs(), "type '" + f.getOperand().type + "' is not a value and can not be assigned"); + if (f.getOperand() instanceof Identifier && f.getOpsSize() == 0 + && env.hasType(((Identifier) f.getOperand()).getToken())) + throw new TypeCheckException(n.getRhs(), + "type '" + f.getOperand().type + "' is not a value and can not be assigned"); n.type = n.getLhs().type; } @@ -652,37 +696,46 @@ public void visit(final EmitStatement n, final SymbolTable env) { Class aggregator = null; try { - aggregator = env.getAggregator(id, ((BoaTable)type).getType()); + aggregator = env.getAggregator(id, ((BoaTable) type).getType()); } catch (final RuntimeException e) { // do nothing } if (aggregator != null) - throw new TypeCheckException(n.getId(), "'" + id + "' is an aggregator function - you must declare an output variable that uses this function, then emit to it"); + throw new TypeCheckException(n.getId(), "'" + id + + "' is an aggregator function - you must declare an output variable that uses this function, then emit to it"); final BoaTable t = (BoaTable) type; if (n.getIndicesSize() != t.countIndices()) - throw new TypeCheckException(n.getId(), "output variable '" + id + "': incorrect number of indices for '" + id + "': required " + t.countIndices() + ", found " + n.getIndicesSize()); + throw new TypeCheckException(n.getId(), "output variable '" + id + "': incorrect number of indices for '" + + id + "': required " + t.countIndices() + ", found " + n.getIndicesSize()); if (n.getIndicesSize() > 0) for (int i = 0; i < n.getIndicesSize() && i < t.countIndices(); i++) { n.getIndice(i).accept(this, env); if (!t.getIndex(i).assigns(n.getIndice(i).type)) - throw new TypeCheckException(n.getIndice(i), "output variable '" + id + "': incompatible types for index '" + i + "': required '" + t.getIndex(i) + "', found '" + n.getIndice(i).type + "'"); + throw new TypeCheckException(n.getIndice(i), + "output variable '" + id + "': incompatible types for index '" + i + "': required '" + + t.getIndex(i) + "', found '" + n.getIndice(i).type + "'"); } n.getValue().accept(this, env); if (!t.accepts(n.getValue().type)) - throw new TypeCheckException(n.getValue(), "output variable '" + id + "': incompatible emit value types: required '" + t.getType() + "', found '" + n.getValue().type + "'"); + throw new TypeCheckException(n.getValue(), + "output variable '" + id + "': incompatible emit value types: required '" + t.getType() + + "', found '" + n.getValue().type + "'"); if (n.hasWeight()) { if (t.getWeightType() == null) - throw new TypeCheckException(n.getWeight(), "output variable '" + id + "': emit contains a weight, but variable not declared with a weight"); + throw new TypeCheckException(n.getWeight(), "output variable '" + id + + "': emit contains a weight, but variable not declared with a weight"); n.getWeight().accept(this, env); if (!t.acceptsWeight(n.getWeight().type)) - throw new TypeCheckException(n.getWeight(), "output variable '" + id + "': incompatible types for weight: required '" + t.getWeightType() + "', found '" + n.getWeight().type + "'"); + throw new TypeCheckException(n.getWeight(), + "output variable '" + id + "': incompatible types for weight: required '" + t.getWeightType() + + "', found '" + n.getWeight().type + "'"); } else if (t.getWeightType() != null && !t.canOmitWeight()) throw new TypeCheckException(n, "output variable '" + id + "': emit must specify a weight"); } @@ -720,7 +773,8 @@ public void visit(final IfAllStatement n, final SymbolTable env) { n.setCondition(e); } - protected Expression checkQuantifier(final Node n, final Component c, Expression e, final Block b, final String kind, final SymbolTable env) { + protected Expression checkQuantifier(final Node n, final Component c, Expression e, final Block b, + final String kind, final SymbolTable env) { SymbolTable st; try { st = env.cloneNonLocals(); @@ -735,19 +789,8 @@ protected Expression checkQuantifier(final Node n, final Component c, Expression e.accept(this, st); if (!(e.type instanceof BoaBool)) { - e = new Expression( - new Conjunction( - new Comparison( - new SimpleExpr( - new Term( - new Factor( - new Identifier("def") - ).addOp(new Call().addArg(e.clone())) - ) - ) - ) - ) - ); + e = new Expression(new Conjunction(new Comparison( + new SimpleExpr(new Term(new Factor(new Identifier("def")).addOp(new Call().addArg(e.clone()))))))); e.accept(this, st); } @@ -792,7 +835,8 @@ public void visit(final IfStatement n, final SymbolTable env) { n.getCondition().accept(this, env); if (!(n.getCondition().type instanceof BoaBool)) - throw new TypeCheckException(n.getCondition(), "incompatible types for if condition: required 'boolean', found '" + n.getCondition().type + "'"); + throw new TypeCheckException(n.getCondition(), + "incompatible types for if condition: required 'boolean', found '" + n.getCondition().type + "'"); n.getBody().accept(this, env); @@ -807,7 +851,8 @@ public void visit(final PostfixStatement n, final SymbolTable env) { n.getExpr().accept(this, env); if (!(n.getExpr().type instanceof BoaInt)) - throw new TypeCheckException(n.getExpr(), "incompatible types for operator '" + n.getOp() + "': required 'int', found '" + n.getExpr().type + "'"); + throw new TypeCheckException(n.getExpr(), "incompatible types for operator '" + n.getOp() + + "': required 'int', found '" + n.getExpr().type + "'"); n.type = n.getExpr().type; } @@ -865,13 +910,15 @@ public void visit(final SwitchStatement n, final SymbolTable env) { n.getCondition().accept(this, st); final BoaType expr = n.getCondition().type; if (!(expr instanceof BoaInt) && !(expr instanceof BoaProtoMap) && !(expr instanceof BoaEnum)) - throw new TypeCheckException(n.getCondition(), "incompatible types for switch expression: required 'int' or 'enum', found: " + expr); + throw new TypeCheckException(n.getCondition(), + "incompatible types for switch expression: required 'int' or 'enum', found: " + expr); for (final SwitchCase sc : n.getCases()) { sc.accept(this, st); for (final Expression e : sc.getCases()) if (!expr.assigns(e.type)) - throw new TypeCheckException(e, "incompatible types for case expression: required '" + expr + "', found '" + e.type + "'"); + throw new TypeCheckException(e, + "incompatible types for case expression: required '" + expr + "', found '" + e.type + "'"); } n.getDefault().accept(this, st); @@ -901,12 +948,12 @@ public void visit(final VarDeclStatement n, final SymbolTable env) { throw new RuntimeException(e.getClass().getSimpleName() + " caught", e); } - ((FunctionExpression)f.getOperand()).getType().accept(this, st); + ((FunctionExpression) f.getOperand()).getType().accept(this, st); if (env.hasGlobalFunction(id) || env.hasLocalFunction(id)) throw new TypeCheckException(n.getId(), "name conflict: a function '" + id + "' already exists"); - env.set(id, ((FunctionExpression)f.getOperand()).getType().type); + env.set(id, ((FunctionExpression) f.getOperand()).getType().type); } n.getInitializer().accept(this, env); @@ -918,25 +965,412 @@ public void visit(final VarDeclStatement n, final SymbolTable env) { } if (rhs instanceof BoaAny) - throw new TypeCheckException(n.getInitializer(), "functions without a return type can not be used as initializers"); + throw new TypeCheckException(n.getInitializer(), + "functions without a return type can not be used as initializers"); - if (f.getOperand() instanceof Identifier && f.getOpsSize() == 0 && env.hasType(((Identifier)f.getOperand()).getToken())) - throw new TypeCheckException(n.getInitializer(), "type '" + f.getOperand().type + "' is not a value and can not be assigned"); + if (f.getOperand() instanceof Identifier && f.getOpsSize() == 0 + && env.hasType(((Identifier) f.getOperand()).getToken())) + throw new TypeCheckException(n.getInitializer(), + "type '" + f.getOperand().type + "' is not a value and can not be assigned"); } BoaType lhs; if (n.hasType()) { - if (n.getType() instanceof Identifier && !env.hasType(((Identifier)n.getType()).getToken())) - throw new TypeCheckException(n.getType(), "type '" + ((Identifier)n.getType()).getToken() + "' undefined"); + if (n.getType() instanceof Identifier && !env.hasType(((Identifier) n.getType()).getToken())) + throw new TypeCheckException(n.getType(), + "type '" + ((Identifier) n.getType()).getToken() + "' undefined"); n.getType().accept(this, env); lhs = n.getType().type; if (lhs instanceof BoaArray && rhs instanceof BoaTuple) - rhs = new BoaArray(((BoaTuple)rhs).getMember(0)); + rhs = new BoaArray(((BoaTuple) rhs).getMember(0)); + + if (lhs instanceof BoaModel) { + final BoaType t = ((BoaModel) lhs).getType(); + List types = new ArrayList(); + + if (t instanceof BoaTuple) + types = ((BoaTuple) t).getTypes(); + else if (t instanceof BoaArray) + types.add(((BoaArray) t).getType()); + + if (lhs instanceof BoaAdaBoostM1) { + if (!(types.get(types.size() - 1) instanceof BoaEnum)) + throw new TypeCheckException(n, "AdaBoostM1 required class to be nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "AdaBoostM1 required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaLinearRegression) { + if (!(types.get(types.size() - 1) instanceof BoaInt + || types.get(types.size() - 1) instanceof BoaFloat + || types.get(types.size() - 1) instanceof BoaTime)) + throw new TypeCheckException(n, "LinearRegression required class to be numeric or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "LinearRegression required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaZeroR) { + if (!(types.get(types.size() - 1) instanceof BoaEnum + || types.get(types.size() - 1) instanceof BoaInt + || types.get(types.size() - 1) instanceof BoaFloat + || types.get(types.size() - 1) instanceof BoaTime)) + throw new TypeCheckException(n, "ZeroR required class to be numeric, nominal or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaString || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "ZeroR required attributes to be numeric, nominal, date or string"); + } + } else if (lhs instanceof BoaVote) { + if (!(types.get(types.size() - 1) instanceof BoaEnum + || types.get(types.size() - 1) instanceof BoaInt + || types.get(types.size() - 1) instanceof BoaFloat + || types.get(types.size() - 1) instanceof BoaTime)) + throw new TypeCheckException(n, "Vote required class to be numeric, nominal or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaString || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "Vote required attributes to be numeric, nominal, date or string"); + } + } else if (lhs instanceof BoaSMO) { + if (!(types.get(types.size() - 1) instanceof BoaEnum)) + throw new TypeCheckException(n, "SMO required class to be nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, "SMO required attributes to be numeric or nominal"); + } + } else if (lhs instanceof BoaSimpleKMeans) { + for (int i = 0; i < types.size(); i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "SimpleKMeans required attributes to be numeric or nominal"); + } + } else if (lhs instanceof BoaRandomForest) { + if (!(types.get(types.size() - 1) instanceof BoaEnum + || types.get(types.size() - 1) instanceof BoaInt + || types.get(types.size() - 1) instanceof BoaFloat)) + throw new TypeCheckException(n, "RandomForest required class to be numeric or nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "RandomForest required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaAdditiveRegression) { + if (!(types.get(types.size() - 1) instanceof BoaInt + || types.get(types.size() - 1) instanceof BoaFloat + || types.get(types.size() - 1) instanceof BoaTime)) + throw new TypeCheckException(n, "AdditiveRegression required class to be numeric or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "AdditiveRegression required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaAttributeSelectedClassifier) { + if (!(types.get(types.size() - 1) instanceof BoaEnum + || types.get(types.size() - 1) instanceof BoaInt + || types.get(types.size() - 1) instanceof BoaFloat + || types.get(types.size() - 1) instanceof BoaTime)) + throw new TypeCheckException(n, + "AttributeSelectedClassifier required class to be numeric, nominal or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "AttributeSelectedClassifier required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaPART) { + if (!(types.get(types.size() - 1) instanceof BoaEnum)) + throw new TypeCheckException(n, "PART required class to be nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, "PART required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaOneR) { + if (!(types.get(types.size() - 1) instanceof BoaEnum)) + throw new TypeCheckException(n, "OneR required class to be nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, "OneR required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaNaiveBayesMultinomialUpdateable) { + if (!(types.get(types.size() - 1) instanceof BoaEnum)) + throw new TypeCheckException(n, "NaiveBayesMultinomialUpdateable required class to be nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaFloat || types.get(i) instanceof BoaInt + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "NaiveBayesMultinomialUpdateable required attributes to be numeric"); + } + } else if (lhs instanceof BoaNaiveBayes) { + if (!(types.get(types.size() - 1) instanceof BoaEnum)) + throw new TypeCheckException(n, "NaiveBayes required class to be nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, "NaiveBayes required attributes to be numeric or nominal"); + } + } else if (lhs instanceof BoaMultiScheme) { + if (!(types.get(types.size() - 1) instanceof BoaEnum + || types.get(types.size() - 1) instanceof BoaInt + || types.get(types.size() - 1) instanceof BoaFloat + || types.get(types.size() - 1) instanceof BoaTime)) + throw new TypeCheckException(n, "MultiScheme required class to be numeric, nominal or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaString || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "MultiScheme required attributes to be numeric, nominal, date or string"); + } + } else if (lhs instanceof BoaMultilayerPerceptron) { + if (!(types.get(types.size() - 1) instanceof BoaEnum + || types.get(types.size() - 1) instanceof BoaInt + || types.get(types.size() - 1) instanceof BoaFloat + || types.get(types.size() - 1) instanceof BoaTime)) + throw new TypeCheckException(n, + "MultilayerPerceptron required class to be numeric, nominal or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "MultilayerPerceptron required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaMultiClassClassifier) { + if (!(types.get(types.size() - 1) instanceof BoaEnum)) + throw new TypeCheckException(n, "MultiClassClassifier required class to be nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "MultiClassClassifier required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaBagging) { + if (!(types.get(types.size() - 1) instanceof BoaEnum + || types.get(types.size() - 1) instanceof BoaInt + || types.get(types.size() - 1) instanceof BoaFloat + || types.get(types.size() - 1) instanceof BoaTime)) + throw new TypeCheckException(n, "Bagging required class to be numeric, nominal or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "Bagging required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaBayesNet) { + if (!(types.get(types.size() - 1) instanceof BoaEnum)) + throw new TypeCheckException(n, "BayesNet required class to be nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, "BayesNet required attributes to be numeric or nominal"); + } + } else if (lhs instanceof BoaClassificationViaRegression) { + if (!(types.get(types.size() - 1) instanceof BoaEnum)) + throw new TypeCheckException(n, "ClassificationViaRegression required class to be nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "ClassificationViaRegression required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaLWL) { + if (!(types.get(types.size() - 1) instanceof BoaEnum + || types.get(types.size() - 1) instanceof BoaInt + || types.get(types.size() - 1) instanceof BoaFloat + || types.get(types.size() - 1) instanceof BoaTime)) + throw new TypeCheckException(n, "LWL required class to be numeric, nominal or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, "LWL required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaLogitBoost) { + if (!(types.get(types.size() - 1) instanceof BoaEnum)) + throw new TypeCheckException(n, "LogitBoost required class to be nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "LogitBoost required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaLogisticRegression) { + if (!(types.get(types.size() - 1) instanceof BoaEnum)) + throw new TypeCheckException(n, "LogisticRegression required class to be nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "LogisticRegression required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaLogitBoost) { + if (!(types.get(types.size() - 1) instanceof BoaEnum)) + throw new TypeCheckException(n, "LogitBoost required class to be nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "LogitBoost required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaLMT) { + if (!(types.get(types.size() - 1) instanceof BoaEnum)) + throw new TypeCheckException(n, "LMT required class to be nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, "LMT required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaJ48) { + if (!(types.get(types.size() - 1) instanceof BoaEnum)) + throw new TypeCheckException(n, "J48 required class to be nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, "J48 required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaJRip) { + if (!(types.get(types.size() - 1) instanceof BoaEnum)) + throw new TypeCheckException(n, "JRip required class to be nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, "JRip required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaKStar) { + if (!(types.get(types.size() - 1) instanceof BoaEnum + || types.get(types.size() - 1) instanceof BoaInt + || types.get(types.size() - 1) instanceof BoaFloat + || types.get(types.size() - 1) instanceof BoaTime)) + throw new TypeCheckException(n, "KStar required class to be numeric, nominal or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, "KStar required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaCVParameterSelection) { + if (!(types.get(types.size() - 1) instanceof BoaEnum + || types.get(types.size() - 1) instanceof BoaInt + || types.get(types.size() - 1) instanceof BoaFloat + || types.get(types.size() - 1) instanceof BoaTime)) + throw new TypeCheckException(n, + "CVParameterSelection required class to be numeric, nominal or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaString || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "CVParameterSelection required attributes to be numeric, nominal, date or string"); + } + } else if (lhs instanceof BoaDecisionStump) { + if (!(types.get(types.size() - 1) instanceof BoaEnum + || types.get(types.size() - 1) instanceof BoaInt + || types.get(types.size() - 1) instanceof BoaFloat + || types.get(types.size() - 1) instanceof BoaTime)) + throw new TypeCheckException(n, "DecisionStump required class to be numeric, nominal or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "DecisionStump required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaDecisionTable) { + if (!(types.get(types.size() - 1) instanceof BoaEnum + || types.get(types.size() - 1) instanceof BoaInt + || types.get(types.size() - 1) instanceof BoaFloat + || types.get(types.size() - 1) instanceof BoaTime)) + throw new TypeCheckException(n, "DecisionTable required class to be numeric, nominal or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "DecisionTable required attributes to be numeric, nominal or date"); + } + } else if (lhs instanceof BoaFilteredClassifier) { + if (!(types.get(types.size() - 1) instanceof BoaEnum)) + throw new TypeCheckException(n, "FilteredClassifier required class to be nominal"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaString || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "FilteredClassifier required attributes to be numeric, nominal, date or string"); + } + } else if (lhs instanceof BoaGaussianProcesses) { + if (!(types.get(types.size() - 1) instanceof BoaInt + || types.get(types.size() - 1) instanceof BoaTime + || types.get(types.size() - 1) instanceof BoaFloat)) + throw new TypeCheckException(n, "GaussianProcesses required class to be numeric or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaFloat || types.get(i) instanceof BoaInt + || types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "GaussianProcesses required attributes to be nominal or numeric"); + } + } else if (lhs instanceof BoaInputMappedClassifier) { + if (!(types.get(types.size() - 1) instanceof BoaEnum + || types.get(types.size() - 1) instanceof BoaInt + || types.get(types.size() - 1) instanceof BoaFloat + || types.get(types.size() - 1) instanceof BoaTime)) + throw new TypeCheckException(n, + "InputMappedClassifier required class to be numeric, nominal or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaString || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "InputMappedClassifier required attributes to be numeric, nominal, date or string"); + } + } else if (lhs instanceof BoaWord2Vec) { + for (int i = 0; i < types.size(); i++) { + if (!(types.get(i) instanceof BoaString)) + throw new TypeCheckException(n, "BoaWord2Vec required attributes to be string"); + } + } else if (lhs instanceof BoaSequence2Vec) { + for (int i = 0; i < types.size(); i++) { + if (!(types.get(i) instanceof BoaString)) + throw new TypeCheckException(n, "BoaSequence2Vec required attributes to be string"); + } + } + } if (rhs != null && !lhs.assigns(rhs) && !env.hasCast(rhs, lhs)) - throw new TypeCheckException(n.getInitializer(), "incorrect type '" + rhs + "' for assignment to '" + id + ": " + lhs + "'"); + throw new TypeCheckException(n.getInitializer(), + "incorrect type '" + rhs + "' for assignment to '" + id + ": " + lhs + "'"); } else { if (rhs == null) throw new TypeCheckException(n, "variable declaration requires an explicit type or an initializer"); @@ -968,8 +1402,7 @@ public void visit(final VisitStatement n, final SymbolTable env) { if (n.getComponent().type instanceof BoaName) n.getComponent().type = n.getComponent().getType().type; st.setShadowing(false); - } - else if (!n.hasWildcard()) + } else if (!n.hasWildcard()) for (final Identifier id : n.getIdList()) { if (SymbolTable.getType(id.getToken()) == null) throw new TypeCheckException(id, "Invalid type '" + id.getToken() + "'"); @@ -996,11 +1429,11 @@ public void visit(final TraverseStatement n, final SymbolTable env) { st.setIsTraverse(true); BoaType ret = new BoaAny(); - if (n.getReturnType()!=null) { + if (n.getReturnType() != null) { n.getReturnType().accept(this, env); ret = n.getReturnType().type; } - n.type = new BoaFunction(ret, new BoaType[]{}); + n.type = new BoaFunction(ret, new BoaType[] {}); lastRetType = ret; n.env = st; @@ -1040,11 +1473,11 @@ public void visit(final FixPStatement n, final SymbolTable env) { } BoaType ret = new BoaAny(); - if (n.getReturnType()!=null) { + if (n.getReturnType() != null) { n.getReturnType().accept(this, env); ret = n.getReturnType().type; } - n.type = new BoaFunction(ret, new BoaType[]{}); + n.type = new BoaFunction(ret, new BoaType[] {}); n.env = st; @@ -1097,12 +1530,14 @@ public void visit(final Expression n, final SymbolTable env) { if (n.getRhsSize() > 0) { if (!(ltype instanceof BoaBool)) - throw new TypeCheckException(n.getLhs(), "incompatible types for disjunction: required 'bool', found '" + ltype + "'"); + throw new TypeCheckException(n.getLhs(), + "incompatible types for disjunction: required 'bool', found '" + ltype + "'"); for (final Conjunction c : n.getRhs()) { c.accept(this, env); if (!(c.type instanceof BoaBool)) - throw new TypeCheckException(c, "incompatible types for disjunction: required 'bool', found '" + c.type + "'"); + throw new TypeCheckException(c, + "incompatible types for disjunction: required 'bool', found '" + c.type + "'"); } n.type = new BoaBool(); @@ -1124,7 +1559,7 @@ public void visit(final FunctionExpression n, final SymbolTable env) { n.getType().accept(this, st); if (!(n.getType().type instanceof BoaFunction)) throw new TypeCheckException(n.getType(), "the identifier '" + n.getType() + "' must be a function type"); - final BoaFunction t = (BoaFunction)n.getType().type; + final BoaFunction t = (BoaFunction) n.getType().type; n.type = t; st.setIsVisitor(false); @@ -1133,8 +1568,8 @@ public void visit(final FunctionExpression n, final SymbolTable env) { returnFinder.initialize(t.getType()); returnFinder.start(n.getBody()); - if (!(t.getType() instanceof BoaAny) - && (n.getBody().getStatementsSize() == 0 || !(n.getBody().getStatement(n.getBody().getStatementsSize() - 1) instanceof ReturnStatement))) + if (!(t.getType() instanceof BoaAny) && (n.getBody().getStatementsSize() == 0 + || !(n.getBody().getStatement(n.getBody().getStatementsSize() - 1) instanceof ReturnStatement))) throw new TypeCheckException(n.getBody(), "missing return statement"); } @@ -1158,24 +1593,28 @@ public void visit(final SimpleExpr n, final SymbolTable env) { if (type instanceof BoaArray) { for (final String s : n.getOps()) if (!s.equals("+")) - throw new TypeCheckException(n, "arrays do not support the '" + s + "' arithmetic operator, perhaps you meant '+'?"); + throw new TypeCheckException(n, + "arrays do not support the '" + s + "' arithmetic operator, perhaps you meant '+'?"); - final BoaType valType = ((BoaArray)type).getType(); + final BoaType valType = ((BoaArray) type).getType(); for (final Term t : n.getRhs()) { t.accept(this, env); - if (!(t.type instanceof BoaArray) || !valType.assigns(((BoaArray)t.type).getType())) - throw new TypeCheckException(t, "invalid array concatenation, found: " + t.type + " expected: " + type); + if (!(t.type instanceof BoaArray) || !valType.assigns(((BoaArray) t.type).getType())) + throw new TypeCheckException(t, + "invalid array concatenation, found: " + t.type + " expected: " + type); } - // only allow '+' (concat) on strings + // only allow '+' (concat) on strings } else if (type instanceof BoaString) { for (final String s : n.getOps()) if (!s.equals("+")) - throw new TypeCheckException(n, "strings do not support the '" + s + "' arithmetic operator, perhaps you meant '+'?"); + throw new TypeCheckException(n, + "strings do not support the '" + s + "' arithmetic operator, perhaps you meant '+'?"); for (final Term t : n.getRhs()) { t.accept(this, env); if (!(t.type instanceof BoaString)) - throw new TypeCheckException(t, "invalid string concatenation, found: " + t.type + " expected: string"); + throw new TypeCheckException(t, + "invalid string concatenation, found: " + t.type + " expected: string"); } } else for (int i = 0; i < n.getRhsSize(); i++) { @@ -1184,7 +1623,8 @@ public void visit(final SimpleExpr n, final SymbolTable env) { try { type = type.arithmetics(t.type); } catch (final Exception e) { - throw new TypeCheckException(t, "type '" + t.type + "' does not support the '" + n.getOp(i) + "' operator", e); + throw new TypeCheckException(t, + "type '" + t.type + "' does not support the '" + n.getOp(i) + "' operator", e); } } @@ -1198,7 +1638,8 @@ public void visit(final VisitorExpression n, final SymbolTable env) { n.getType().accept(this, env); for (final Statement s : n.getBody().getStatements()) if (!(s instanceof VisitStatement)) - throw new TypeCheckException(s, "only 'before' or 'after' visit statements are allowed inside visitor bodies"); + throw new TypeCheckException(s, + "only 'before' or 'after' visit statements are allowed inside visitor bodies"); visitorChecker.start(n); n.getBody().accept(this, env); n.type = n.getType().type; @@ -1211,7 +1652,7 @@ public void visit(final VisitorExpression n, final SymbolTable env) { public void visit(final TraversalExpression n, final SymbolTable env) { n.env = env; n.getType().accept(this, env); - //n.getBody.addStatement(,0); + // n.getBody.addStatement(,0); for (final Statement s : n.getBody().getStatements()) if (!(s instanceof TraverseStatement)) throw new TypeCheckException(s, "only traverse statements are allowed inside traversal bodies"); @@ -1379,25 +1820,159 @@ public void visit(final OutputType n, final SymbolTable env) { BoaScalar tweight = null; if (n.hasWeight()) { if (annotation.weightType().equals("none")) - throw new TypeCheckException(n.getWeight(), "output aggregator '" + n.getId().getToken() + "' does not expect a weight"); + throw new TypeCheckException(n.getWeight(), + "output aggregator '" + n.getId().getToken() + "' does not expect a weight"); final BoaType aweight = SymbolTable.getType(annotation.weightType()); n.getWeight().accept(this, st); tweight = (BoaScalar) n.getWeight().type; if (!aweight.assigns(tweight)) - throw new TypeCheckException(n.getWeight(), "invalid weight type, found: " + tweight + " expected: " + aweight); + throw new TypeCheckException(n.getWeight(), + "invalid weight type, found: " + tweight + " expected: " + aweight); } else if (!annotation.weightType().equals("none") && !annotation.weightType().equals("any")) throw new TypeCheckException(n, "output aggregator expects a weight type"); if (n.getArgsSize() > 0 && annotation.formalParameters().length == 0) - throw new TypeCheckException(n.getArgs(), "output aggregator '" + n.getId().getToken() + "' takes no arguments"); + throw new TypeCheckException(n.getArgs(), + "output aggregator '" + n.getId().getToken() + "' takes no arguments"); n.type = new BoaTable(type, indexTypes, tweight, annotation.canOmitWeight()); n.env = env; env.set(n.getId().getToken(), n.type); n.getId().accept(this, env); + + // TODO: What's the purpose of this? + BoaModel model = (BoaModel) SymbolTable.getMLAggregatorType(n.getId().getToken()); + + if (model != null) { + BoaType t = (n.getType()).type; + List types = new ArrayList(); + + if (t instanceof BoaTable) + t = ((BoaTable) t).getType(); + if (t instanceof BoaTuple) + types = ((BoaTuple) t).getTypes(); + else if (t instanceof BoaArray) + types.add(((BoaArray) t).getType()); + else + types.add(t); + + if (model instanceof BoaLinearRegression) { + if (!(types.get(types.size() - 1) instanceof BoaInt || types.get(types.size() - 1) instanceof BoaFloat + || types.get(types.size() - 1) instanceof BoaTime)) + throw new TypeCheckException(n, "LinearRegression required class to be numeric or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "LinearRegression required attributes to be numeric, nominal or date"); + } + } + + if (model instanceof BoaAdaBoostM1) { + if (!(types.get(types.size() - 1) instanceof BoaInt || types.get(types.size() - 1) instanceof BoaFloat + || types.get(types.size() - 1) instanceof BoaTime)) + throw new TypeCheckException(n, "AdaBoostM1 required class to be numeric or date"); + for (int i = 0; i < types.size() - 1; i++) { + if (!(types.get(i) instanceof BoaEnum || types.get(i) instanceof BoaFloat + || types.get(i) instanceof BoaInt || types.get(i) instanceof BoaTime + || types.get(i) instanceof BoaArray)) + throw new TypeCheckException(n, + "AdaBoostM1 required attributes to be numeric, nominal or date"); + } + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public void visit(final ModelType n, final SymbolTable env) { + n.env = env; + n.getType().accept(this, env); + if (env.hasType(n.getId().getToken())) + n.type = SymbolTable.getType(n.getId().getToken()); + else + try { + n.type = env.get(n.getId().getToken()); + } catch (final RuntimeException e) { + throw new TypeCheckException(n, "invalid identifier '" + n.getId().getToken() + "'", e); + } + + if (n.type instanceof BoaLinearRegression) + n.type = new BoaLinearRegression(n.getType().type); + else if (n.type instanceof BoaAdaBoostM1) + n.type = new BoaAdaBoostM1(n.getType().type); + else if (n.type instanceof BoaZeroR) + n.type = new BoaZeroR(n.getType().type); + else if (n.type instanceof BoaVote) + n.type = new BoaVote(n.getType().type); + else if (n.type instanceof BoaSMO) + n.type = new BoaSMO(n.getType().type); + else if (n.type instanceof BoaSimpleKMeans) + n.type = new BoaSimpleKMeans(n.getType().type); + else if (n.type instanceof BoaRandomForest) + n.type = new BoaRandomForest(n.getType().type); + else if (n.type instanceof BoaAdditiveRegression) + n.type = new BoaAdditiveRegression(n.getType().type); + else if (n.type instanceof BoaAttributeSelectedClassifier) + n.type = new BoaAttributeSelectedClassifier(n.getType().type); + else if (n.type instanceof BoaPART) + n.type = new BoaPART(n.getType().type); + else if (n.type instanceof BoaOneR) + n.type = new BoaOneR(n.getType().type); + else if (n.type instanceof BoaNaiveBayesMultinomialUpdateable) + n.type = new BoaNaiveBayesMultinomialUpdateable(n.getType().type); + else if (n.type instanceof BoaNaiveBayes) + n.type = new BoaNaiveBayes(n.getType().type); + else if (n.type instanceof BoaMultiScheme) + n.type = new BoaMultiScheme(n.getType().type); + else if (n.type instanceof BoaMultilayerPerceptron) + n.type = new BoaMultilayerPerceptron(n.getType().type); + else if (n.type instanceof BoaMultiClassClassifier) + n.type = new BoaMultiClassClassifier(n.getType().type); + else if (n.type instanceof BoaBagging) + n.type = new BoaBagging(n.getType().type); + else if (n.type instanceof BoaBayesNet) + n.type = new BoaBayesNet(n.getType().type); + else if (n.type instanceof BoaClassificationViaRegression) + n.type = new BoaClassificationViaRegression(n.getType().type); + else if (n.type instanceof BoaLogitBoost) + n.type = new BoaLogitBoost(n.getType().type); + else if (n.type instanceof BoaLWL) + n.type = new BoaLWL(n.getType().type); + else if (n.type instanceof BoaLMT) + n.type = new BoaLMT(n.getType().type); + else if (n.type instanceof BoaLogisticRegression) + n.type = new BoaLogisticRegression(n.getType().type); + else if (n.type instanceof BoaJ48) + n.type = new BoaJ48(n.getType().type); + else if (n.type instanceof BoaJRip) + n.type = new BoaJRip(n.getType().type); + else if (n.type instanceof BoaKStar) + n.type = new BoaKStar(n.getType().type); + else if (n.type instanceof BoaCVParameterSelection) + n.type = new BoaCVParameterSelection(n.getType().type); + else if (n.type instanceof BoaDecisionStump) + n.type = new BoaDecisionStump(n.getType().type); + else if (n.type instanceof BoaDecisionTable) + n.type = new BoaDecisionTable(n.getType().type); + else if (n.type instanceof BoaFilteredClassifier) + n.type = new BoaFilteredClassifier(n.getType().type); + else if (n.type instanceof BoaGaussianProcesses) + n.type = new BoaGaussianProcesses(n.getType().type); + else if (n.type instanceof BoaInputMappedClassifier) + n.type = new BoaInputMappedClassifier(n.getType().type); + else if (n.type instanceof BoaWord2Vec) + n.type = new BoaWord2Vec(n.getType().type); + else if (n.type instanceof BoaSequence2Vec) + n.type = new BoaSequence2Vec(n.getType().type); + else + throw new TypeCheckException(n, "Model required attributes to be model type"); } /** {@inheritDoc} */ @@ -1487,8 +2062,9 @@ else if (f.getOperand() instanceof FloatLiteral) fieldType = new BoaFloat(); else if (f.getOperand() instanceof TimeLiteral) fieldType = new BoaTime(); - values.add(((ILiteral)(f.getOperand())).getLiteral()); - types.add(new BoaEnum(c.getIdentifier().getToken(),((ILiteral)(f.getOperand())).getLiteral(),fieldType)); + values.add(((ILiteral) (f.getOperand())).getLiteral()); + types.add(new BoaEnum(c.getIdentifier().getToken(), ((ILiteral) (f.getOperand())).getLiteral(), + fieldType)); } } @@ -1559,13 +2135,15 @@ protected BoaType checkPairs(final List pl, final SymbolTable env) { for (final Pair p : pl) { p.accept(this, env); if (!boaMap.assigns(p.type)) - throw new TypeCheckException(p, "incompatible types: required '" + boaMap + "', found '" + p.type + "'"); + throw new TypeCheckException(p, + "incompatible types: required '" + boaMap + "', found '" + p.type + "'"); } return boaMap; } protected void warn(final Node node, final String msg) { - System.err.println("WARNING at line " + node.beginLine + ", columns " + node.beginColumn + "-" + node.endColumn + ": " + msg); + System.err.println("WARNING at line " + node.beginLine + ", columns " + node.beginColumn + "-" + node.endColumn + + ": " + msg); } } diff --git a/src/java/boa/datagen/DefaultProperties.java b/src/java/boa/datagen/DefaultProperties.java index ae9c65eb6..baf5b7a1c 100644 --- a/src/java/boa/datagen/DefaultProperties.java +++ b/src/java/boa/datagen/DefaultProperties.java @@ -74,6 +74,8 @@ public class DefaultProperties { public static String localDataPath = null; + public static String localOutput = null; + @SuppressWarnings("unused") private static String getRoot() { File dir = new File(System.getProperty("user.dir")); diff --git a/src/java/boa/evaluator/BoaEvaluator.java b/src/java/boa/evaluator/BoaEvaluator.java index 7b2e66ad1..0a81247e6 100644 --- a/src/java/boa/evaluator/BoaEvaluator.java +++ b/src/java/boa/evaluator/BoaEvaluator.java @@ -214,5 +214,6 @@ private void setup() throws IOException { // set localData path in Defaultproperties DefaultProperties.localDataPath = this.DATA_PATH; + DefaultProperties.localOutput = this.OUTPUT_DIR; } } diff --git a/src/java/boa/functions/BoaMLIntrinsics.java b/src/java/boa/functions/BoaMLIntrinsics.java new file mode 100644 index 000000000..33935afe9 --- /dev/null +++ b/src/java/boa/functions/BoaMLIntrinsics.java @@ -0,0 +1,408 @@ +package boa.functions; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.LinkedList; +import java.util.List; + +import org.apache.commons.lang.math.NumberUtils; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FSDataInputStream; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.deeplearning4j.models.embeddings.reader.impl.BasicModelUtils; +import org.deeplearning4j.models.sequencevectors.SequenceVectors; +import org.deeplearning4j.models.word2vec.VocabWord; +import org.deeplearning4j.models.word2vec.Word2Vec; + +import boa.datagen.DefaultProperties; +import boa.runtime.Tuple; +import boa.types.ml.*; +import weka.classifiers.Classifier; +import weka.clusterers.Clusterer; +import weka.core.Attribute; +import weka.core.DenseInstance; +import weka.core.Instance; +import weka.core.Instances; + +import static boa.aggregators.ml.MLAggregator.getModelFilePath; + +public class BoaMLIntrinsics { + + /** + * Given the model URL, deserialize the model and return Model type + * + * @param Take URL for the model + * @return Model type after deserializing + */ + @FunctionSpec(name = "load", returnType = "model", formalParameters = { "int", "model" }) + public static BoaModel load(final long jobId, BoaModel m, final String identifier, final String type, + final Object o) throws Exception { + Object object = null; + FSDataInputStream in = null; + ObjectInputStream dataIn = null; + ByteArrayOutputStream bo = null; + ByteArrayInputStream bin = null; + try { + final Configuration conf = BoaAstIntrinsics.context.getConfiguration(); + final FileSystem fs; + final Path p; + String output = DefaultProperties.localOutput != null + ? new Path(DefaultProperties.localOutput).toString() + "/../" + : conf.get("fs.default.name", "hdfs://boa-njt/"); + p = getModelFilePath(output, (int) jobId, identifier); + + // deserialize the model from the path + fs = FileSystem.get(conf); + in = fs.open(p); + final byte[] b = new byte[(int) fs.getFileStatus(p).getLen() + 1]; + int c = 0; + bo = new ByteArrayOutputStream(); + while ((c = in.read(b)) != -1) + bo.write(b, 0, c); + bin = new ByteArrayInputStream(bo.toByteArray()); + object = new ObjectInputStream(bin).readObject(); + + } catch (Exception e) { + e.printStackTrace(); + } finally { + try { + if (in != null) + in.close(); + if (dataIn != null) + dataIn.close(); + if (bo != null) + bo.close(); + } catch (final Exception e) { + e.printStackTrace(); + } + } + + if (object instanceof Word2Vec) { + Word2Vec word2Vec = (Word2Vec) object; + word2Vec.setModelUtils(new BasicModelUtils<>()); + return new BoaWord2Vec(word2Vec, o); + } else if (object instanceof SequenceVectors) { + @SuppressWarnings("unchecked") + SequenceVectors seq2vec = (SequenceVectors) object; + seq2vec.setModelUtils(new BasicModelUtils<>()); + return new BoaSequence2Vec(seq2vec, o); + } else if (object instanceof Classifier) { + // classifier + Classifier clr = (Classifier) object; + String className = clr.getClass().toString(); + if (className.contains("LinearRegression")) { + m = new BoaLinearRegression(clr, o); + } else if (className.contains("AdaBoostM1")) { + m = new BoaAdaBoostM1(clr, o); + } else if (className.contains("ZeroR")) { + m = new BoaZeroR(clr, o); + } else if (className.contains("Vote")) { + m = new BoaVote(clr, o); + } else if (className.contains("SMO")) { + m = new BoaSMO(clr, o); + } else if (className.contains("RandomForest")) { + m = new BoaRandomForest(clr, o); + } else if (className.contains("AdditiveRegression")) { + m = new BoaAdditiveRegression(clr, o); + } else if (className.contains("AttributeSelectedClassifier")) { + m = new BoaAttributeSelectedClassifier(clr, o); + } else if (className.contains("PART")) { + m = new BoaPART(clr, o); + } else if (className.contains("OneR")) { + m = new BoaOneR(clr, o); + } else if (className.contains("NaiveBayesMultinomialUpdateable")) { + m = new BoaNaiveBayesMultinomialUpdateable(clr, o); + } else if (className.contains("BoaNaiveBayesMultinomial")) { + // TODO BoaNaiveBayesMultinomial + m = new BoaNaiveBayesMultinomial(clr, o); + } else if (className.contains("NaiveBayes")) { + m = new BoaNaiveBayes(clr, o); + } else if (className.contains("MultiScheme")) { + m = new BoaMultiScheme(clr, o); + } else if (className.contains("MultiClassClassifier")) { + m = new BoaMultiClassClassifier(clr, o); + } else if (className.contains("MultilayerPerceptron")) { + m = new BoaMultilayerPerceptron(clr, o); + } else if (className.contains("Bagging")) { + m = new BoaBagging(clr, o); + } else if (className.contains("BayesNet")) { + m = new BoaBayesNet(clr, o); + } else if (className.contains("ClassificationViaRegression")) { + m = new BoaClassificationViaRegression(clr, o); + } else if (className.contains("LWL")) { + m = new BoaLWL(clr, o); + } else if (className.contains("LogitBoost")) { + m = new BoaLogitBoost(clr, o); + } else if (className.contains("LMT")) { + m = new BoaLMT(clr, o); + } else if (className.contains("Logistic")) { + m = new BoaLogisticRegression(clr, o); + } else if (className.contains("J48")) { + m = new BoaJ48(clr, o); + } else if (className.contains("JRip")) { + m = new BoaJRip(clr, o); + } else if (className.contains("KStar")) { + m = new BoaKStar(clr, o); + } else if (className.contains("CVParameterSelection")) { + m = new BoaCVParameterSelection(clr, o); + } else if (className.contains("DecisionStump")) { + m = new BoaDecisionStump(clr, o); + } else if (className.contains("DecisionTable")) { + m = new BoaDecisionTable(clr, o); + } else if (className.contains("FilteredClassifier")) { + m = new BoaFilteredClassifier(clr, o); + } else if (className.contains("GaussianProcesses")) { + m = new BoaGaussianProcesses(clr, o); + } else if (className.contains("InputMappedClassifier")) { + m = new BoaInputMappedClassifier(clr, o); + } + } else if (object instanceof Clusterer) { + // Clusterer + Clusterer clu = (Clusterer) object; + String className = clu.getClass().toString(); + if (className.contains("SimpleKMeans")) { + m = new BoaSimpleKMeans(clu, o); + } + } + + // TODO attribute selection: + // TODO PrincipalComponents + // TODO LSA + return m; + } + + @FunctionSpec(name = "classify", returnType = "string", formalParameters = { "model", "array of int" }) + public static String classify(final BoaModel model, final long[] vector) throws Exception { + int NumOfAttributes = vector.length + 1; + ArrayList fvAttributes = getAttributes(model, vector); + + Instances testingSet = new Instances("Classifier", fvAttributes, 1); + testingSet.setClassIndex(NumOfAttributes - 1); + + Instance instance = new DenseInstance(NumOfAttributes); + for (int i = 0; i < NumOfAttributes - 1; i++) + instance.setValue((Attribute) fvAttributes.get(i), vector[i]); + testingSet.add(instance); + + Classifier classifier = (Classifier) model.getClassifier(); + double predval = classifier.classifyInstance(testingSet.instance(0)); + + return testingSet.classAttribute().isNominal() ? testingSet.classAttribute().value((int) predval) + : String.valueOf(predval); + } + + @FunctionSpec(name = "cluster", returnType = "string", formalParameters = { "model", "array of int" }) + public static String cluster(final BoaModel model, final long[] vector) throws Exception { + int NumOfAttributes = vector.length + 1; + ArrayList fvAttributes = getAttributes(model, vector); + + Instances testingSet = new Instances("Clusterer", fvAttributes, 1); + testingSet.setClassIndex(NumOfAttributes - 1); + + Instance instance = new DenseInstance(NumOfAttributes); + for (int i = 0; i < NumOfAttributes - 1; i++) + instance.setValue((Attribute) fvAttributes.get(i), vector[i]); + testingSet.add(instance); + + Clusterer clusterer = (Clusterer) model.getClusterer(); + double predval = clusterer.clusterInstance(testingSet.instance(0)); + + return testingSet.classAttribute().isNominal() ? testingSet.classAttribute().value((int) predval) + : String.valueOf(predval); + } + + private static ArrayList getAttributes(BoaModel model, long[] vector) { + int NumOfAttributes = vector.length + 1; + ArrayList fvAttributes = new ArrayList(); + for (int i = 0; i < NumOfAttributes - 1; i++) + fvAttributes.add(new Attribute("Attribute" + i)); + + try { + Field[] fields = ((Tuple) model.getObject()).getClass().getDeclaredFields(); + Field lastfield = fields[fields.length - 1]; + if (lastfield.getType().isEnum()) { + ArrayList fvNominalVal = new ArrayList(); + for (Object obj : lastfield.getType().getEnumConstants()) + fvNominalVal.add(obj.toString()); + fvAttributes.add(new Attribute("Nominal" + (NumOfAttributes - 1), fvNominalVal)); + } else { + fvAttributes.add(new Attribute("Attribute" + (NumOfAttributes - 1))); + } + } catch (Exception e) { + e.printStackTrace(); + } + return fvAttributes; + } + + @FunctionSpec(name = "classify", returnType = "string", formalParameters = { "model", "tuple" }) + public static String classify(final BoaModel model, final Tuple vector) throws Exception { + ArrayList fvAttributes = getAttributes(model, vector); + int NumOfAttributes = fvAttributes.size(); + + Instances testingSet = new Instances("Classifier", fvAttributes, 1); + testingSet.setClassIndex(NumOfAttributes - 1); + + Instance instance = new DenseInstance(NumOfAttributes); + + for (int i = 0; i < NumOfAttributes - 1; i++) + if (NumberUtils.isNumber(vector.getValues()[i])) + instance.setValue((Attribute) fvAttributes.get(i), Double.parseDouble(vector.getValues()[i])); + else + instance.setValue((Attribute) fvAttributes.get(i), vector.getValues()[i]); + testingSet.add(instance); + + Classifier classifier = (Classifier) model.getClassifier(); + double predval = classifier.classifyInstance(testingSet.instance(0)); + + return testingSet.classAttribute().isNominal() ? testingSet.classAttribute().value((int) predval) + : String.valueOf(predval); + } + + @FunctionSpec(name = "cluster", returnType = "string", formalParameters = { "model", "tuple" }) + public static String cluster(final BoaModel model, final Tuple vector) throws Exception { + ArrayList fvAttributes = getAttributes(model, vector); + int NumOfAttributes = fvAttributes.size(); + + Instances testingSet = new Instances("Classifier", fvAttributes, 1); + testingSet.setClassIndex(NumOfAttributes - 1); + + Instance instance = new DenseInstance(NumOfAttributes); + + for (int i = 0; i < NumOfAttributes - 1; i++) + if (NumberUtils.isNumber(vector.getValues()[i])) + instance.setValue((Attribute) fvAttributes.get(i), Double.parseDouble(vector.getValues()[i])); + else + instance.setValue((Attribute) fvAttributes.get(i), vector.getValues()[i]); + testingSet.add(instance); + + Clusterer clusterer = (Clusterer) model.getClusterer(); + double predval = clusterer.clusterInstance(testingSet.instance(0)); + + return testingSet.classAttribute().isNominal() ? testingSet.classAttribute().value((int) predval) + : String.valueOf(predval); + } + + private static ArrayList getAttributes(BoaModel model, Tuple vector) { + ArrayList fvAttributes = new ArrayList(); + try { + String[] fieldNames = vector.getFieldNames(); + int count = 0; + for (int i = 0; i < fieldNames.length; i++) { + if (vector.getValue(fieldNames[i]).getClass().isEnum()) { + ArrayList fvNominalVal = new ArrayList(); + for (Object obj : vector.getValue(fieldNames[i]).getClass().getEnumConstants()) + fvNominalVal.add(obj.toString()); + fvAttributes.add(new Attribute("Nominal" + count, fvNominalVal)); + count++; + } else if (vector.getValue(fieldNames[i]).getClass().isArray()) { + int l = Array.getLength(vector.getValue(fieldNames[i])) - 1; + for (int j = 0; j <= l; j++) { + fvAttributes.add(new Attribute("Attribute" + count)); + count++; + } + } else { + fvAttributes.add(new Attribute("Attribute" + count)); + count++; + } + } + + Field[] fields = ((Tuple) model.getObject()).getClass().getDeclaredFields(); + Field lastfield = fields[fields.length - 1]; + if (lastfield.getType().isEnum()) { + ArrayList fvNominalVal = new ArrayList(); + for (Object obj : lastfield.getType().getEnumConstants()) + fvNominalVal.add(obj.toString()); + fvAttributes.add(new Attribute("Nominal" + count, fvNominalVal)); + count++; + } else { + fvAttributes.add(new Attribute("Attribute" + count)); + count++; + } + } catch (Exception e) { + e.printStackTrace(); + } + return fvAttributes; + } + + /* ------------------------------- Word2Vec ------------------------------- */ + // for more methods please check: + // https://github.com/eclipse/deeplearning4j/blob/43fd64358cd96413063a06e63b7d34402555a3ec/deeplearning4j/deeplearning4j-nlp-parent/deeplearning4j-nlp/src/main/java/org/deeplearning4j/models/embeddings/wordvectors/WordVectorsImpl.java + // https://github.com/eclipse/deeplearning4j/blob/43fd64358cd96413063a06e63b7d34402555a3ec/deeplearning4j/deeplearning4j-nlp-parent/deeplearning4j-nlp/src/main/java/org/deeplearning4j/models/embeddings/reader/impl/BasicModelUtils.java + + @FunctionSpec(name = "sim", returnType = "float", formalParameters = { "Word2Vec", "string", "string" }) + public static double sim(final BoaWord2Vec m, final String w1, final String w2) { + return m.getW2v().similarity(w1, w2); + } + + @FunctionSpec(name = "nearest", returnType = "array of string", formalParameters = { "Word2Vec", "string", "int" }) + public static String[] nearest(final BoaWord2Vec m, final String w, final long num) { + return m.getW2v().wordsNearest(w, (int) num).toArray(new String[0]); + } + + @FunctionSpec(name = "vector", returnType = "array of float", formalParameters = { "Word2Vec", "string" }) + public static double[] vector(final BoaWord2Vec m, final String w) { + return m.getW2v().getWordVector(w); + } + + @FunctionSpec(name = "arith", returnType = "array of string", formalParameters = { "Word2Vec", "string", "int" }) + public static String[] arith(final BoaWord2Vec m, final String exp, final long num) { + List plus = new LinkedList(); + List minus = new LinkedList(); + String[] tokens = exp.split("\\s+"); + for (int i = 0; i < tokens.length; i++) { + String token = tokens[i]; + if (i == 0 && !token.equals("-") && !token.equals("+")) + plus.add(token); + else if (token.equals("+")) + plus.add(tokens[++i]); + else if (token.equals("-")) + minus.add(tokens[++i]); + } + return m.getW2v().wordsNearest(plus, minus, (int) num).toArray(new String[0]); + } + + /* ------------------------------- Seq2Vec ------------------------------- */ + + @FunctionSpec(name = "sim", returnType = "float", formalParameters = { "Seq2Vec", "string", "string" }) + public static double sim(final BoaSequence2Vec m, final String w1, final String w2) { + return m.getSeq2Vec().similarity(w1, w2); + } + + @FunctionSpec(name = "nearest", returnType = "array of string", formalParameters = { "Seq2Vec", "string", "int" }) + public static String[] nearest(final BoaSequence2Vec m, final String w, final long num) { + return m.getSeq2Vec().wordsNearest(w, (int) num).toArray(new String[0]); + } + + @FunctionSpec(name = "vector", returnType = "array of float", formalParameters = { "Seq2Vec", "string" }) + public static double[] vector(final BoaSequence2Vec m, final String w) { + return m.getSeq2Vec().getWordVector(w); + } + + @FunctionSpec(name = "vector", returnType = "array of float", formalParameters = { "Seq2Vec", "array of string" }) + public static double[] vector(final BoaSequence2Vec m, final String[] sequence) { + return m.getSeq2Vec().getWordVectorsMean(Arrays.asList(sequence)).toDoubleVector(); + } + + @FunctionSpec(name = "arith", returnType = "array of string", formalParameters = { "Seq2Vec", "string", "int" }) + public static String[] arith(final BoaSequence2Vec m, final String exp, final long num) { + List plus = new LinkedList(); + List minus = new LinkedList(); + String[] tokens = exp.split("\\s+"); + for (int i = 0; i < tokens.length; i++) { + String token = tokens[i]; + if (i == 0 && !token.equals("-") && !token.equals("+")) + plus.add(token); + else if (token.equals("+")) + plus.add(tokens[++i]); + else if (token.equals("-")) + minus.add(tokens[++i]); + } + return m.getSeq2Vec().wordsNearest(plus, minus, (int) num).toArray(new String[0]); + } +} \ No newline at end of file diff --git a/src/java/boa/io/EmitValue.java b/src/java/boa/io/EmitValue.java index 61f03c2a9..c51754b20 100644 --- a/src/java/boa/io/EmitValue.java +++ b/src/java/boa/io/EmitValue.java @@ -17,15 +17,18 @@ */ package boa.io; +import java.io.ByteArrayInputStream; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; +import java.io.ObjectInputStream; import java.util.Arrays; import org.apache.hadoop.io.Text; import org.apache.hadoop.io.Writable; import boa.functions.BoaCasts; +import boa.runtime.Tuple; /** * A {@link Writable} that contains a datum and an optional metadatum to be @@ -37,6 +40,7 @@ public class EmitValue implements Writable { private String[] data; private String metadata; + private Tuple tdata; /** * Construct an EmitValue. @@ -48,10 +52,8 @@ public EmitValue() { /** * Construct an EmitValue. * - * @param data - * An array of {@link String} containing the data to be emitted - * @param metadata - * A {@link String} containing the metadata to be emitted + * @param data An array of {@link String} containing the data to be emitted + * @param metadata A {@link String} containing the metadata to be emitted */ public EmitValue(final String[] data, final String metadata) { this.data = data; @@ -61,8 +63,7 @@ public EmitValue(final String[] data, final String metadata) { /** * Construct an EmitValue. * - * @param data - * An array of {@link String} containing the data to be emitted + * @param data An array of {@link String} containing the data to be emitted */ public EmitValue(final String[] data) { this(data, null); @@ -71,10 +72,8 @@ public EmitValue(final String[] data) { /** * Construct an EmitValue. * - * @param data - * An array of {@link Object} containing the data to be emitted - * @param metadata - * A {@link String} containing the metadata to be emitted + * @param data An array of {@link Object} containing the data to be emitted + * @param metadata A {@link String} containing the metadata to be emitted */ public EmitValue(final Object[] data, final String metadata) { final String[] strings = new String[data.length]; @@ -89,8 +88,7 @@ public EmitValue(final Object[] data, final String metadata) { /** * Construct an EmitValue. * - * @param data - * An array of {@link String} containing the data to be emitted + * @param data An array of {@link String} containing the data to be emitted */ public EmitValue(final Object[] data) { this(data, null); @@ -99,8 +97,7 @@ public EmitValue(final Object[] data) { /** * Construct an EmitValue. * - * @param data - * A {@link String} containing the data to be emitted + * @param data A {@link String} containing the data to be emitted */ public EmitValue(final String data) { this(new String[] { data }, null); @@ -109,10 +106,8 @@ public EmitValue(final String data) { /** * Construct an EmitValue. * - * @param data - * A {@link String} containing the data to be emitted - * @param metadata - * A {@link String} containing the metadata to be emitted + * @param data A {@link String} containing the data to be emitted + * @param metadata A {@link String} containing the metadata to be emitted */ public EmitValue(final String data, final String metadata) { this(new String[] { data }, metadata); @@ -121,10 +116,8 @@ public EmitValue(final String data, final String metadata) { /** * Construct an EmitValue. * - * @param data - * A {@link String} containing the data to be emitted - * @param metadata - * A long representing the metadata to be emitted + * @param data A {@link String} containing the data to be emitted + * @param metadata A long representing the metadata to be emitted */ public EmitValue(final String data, final long metadata) { this(new String[] { data }, BoaCasts.longToString(metadata)); @@ -133,10 +126,8 @@ public EmitValue(final String data, final long metadata) { /** * Construct an EmitValue. * - * @param data - * A {@link String} containing the data to be emitted - * @param metadata - * A double representing the metadata to be emitted + * @param data A {@link String} containing the data to be emitted + * @param metadata A double representing the metadata to be emitted */ public EmitValue(final String data, final double metadata) { this(new String[] { data }, BoaCasts.doubleToString(metadata)); @@ -145,8 +136,7 @@ public EmitValue(final String data, final double metadata) { /** * Construct an EmitValue. * - * @param data - * A long representing the data to be emitted + * @param data A long representing the data to be emitted */ public EmitValue(final long data) { this(new String[] { BoaCasts.longToString(data) }, null); @@ -155,10 +145,8 @@ public EmitValue(final long data) { /** * Construct an EmitValue. * - * @param data - * A long representing the data to be emitted - * @param metadata - * A {@link String} containing the metadata to be emitted + * @param data A long representing the data to be emitted + * @param metadata A {@link String} containing the metadata to be emitted */ public EmitValue(final long data, final String metadata) { this(new String[] { BoaCasts.longToString(data) }, metadata); @@ -167,10 +155,8 @@ public EmitValue(final long data, final String metadata) { /** * Construct an EmitValue. * - * @param data - * A long representing the data to be emitted - * @param metadata - * A long representing the metadata to be emitted + * @param data A long representing the data to be emitted + * @param metadata A long representing the metadata to be emitted */ public EmitValue(final long data, final long metadata) { this(new String[] { BoaCasts.longToString(data) }, BoaCasts.longToString(metadata)); @@ -179,10 +165,8 @@ public EmitValue(final long data, final long metadata) { /** * Construct an EmitValue. * - * @param data - * A long representing the data to be emitted - * @param metadata - * A double representing the metadata to be emitted + * @param data A long representing the data to be emitted + * @param metadata A double representing the metadata to be emitted */ public EmitValue(final long data, final double metadata) { this(new String[] { BoaCasts.longToString(data) }, BoaCasts.doubleToString(metadata)); @@ -191,8 +175,7 @@ public EmitValue(final long data, final double metadata) { /** * Construct an EmitValue. * - * @param data - * A double representing the data to be emitted + * @param data A double representing the data to be emitted */ public EmitValue(final double data) { this(new String[] { BoaCasts.doubleToString(data) }, null); @@ -201,10 +184,8 @@ public EmitValue(final double data) { /** * Construct an EmitValue. * - * @param data - * A double representing the data to be emitted - * @param metadata - * A {@link String} containing the metadata to be emitted + * @param data A double representing the data to be emitted + * @param metadata A {@link String} containing the metadata to be emitted */ public EmitValue(final double data, final String metadata) { this(new String[] { BoaCasts.doubleToString(data) }, metadata); @@ -213,10 +194,8 @@ public EmitValue(final double data, final String metadata) { /** * Construct an EmitValue. * - * @param data - * A double representing the data to be emitted - * @param metadata - * A long representing the metadata to be emitted + * @param data A double representing the data to be emitted + * @param metadata A long representing the metadata to be emitted */ public EmitValue(final double data, final long metadata) { this(new String[] { BoaCasts.doubleToString(data) }, BoaCasts.longToString(metadata)); @@ -225,10 +204,8 @@ public EmitValue(final double data, final long metadata) { /** * Construct an EmitValue. * - * @param data - * A double representing the data to be emitted - * @param metadata - * A double representing the metadata to be emitted + * @param data A double representing the data to be emitted + * @param metadata A double representing the metadata to be emitted */ public EmitValue(final double data, final double metadata) { this(new String[] { BoaCasts.doubleToString(data) }, BoaCasts.doubleToString(metadata)); @@ -237,8 +214,7 @@ public EmitValue(final double data, final double metadata) { /** * Construct an EmitValue. * - * @param data - * A boolean representing the data to be emitted + * @param data A boolean representing the data to be emitted */ public EmitValue(final boolean data) { this(new String[] { BoaCasts.booleanToString(data) }, null); @@ -247,10 +223,8 @@ public EmitValue(final boolean data) { /** * Construct an EmitValue. * - * @param data - * A boolean representing the data to be emitted - * @param metadata - * A {@link String} containing the metadata to be emitted + * @param data A boolean representing the data to be emitted + * @param metadata A {@link String} containing the metadata to be emitted */ public EmitValue(final boolean data, final String metadata) { this(new String[] { BoaCasts.booleanToString(data) }, metadata); @@ -259,10 +233,8 @@ public EmitValue(final boolean data, final String metadata) { /** * Construct an EmitValue. * - * @param data - * A boolean representing the data to be emitted - * @param metadata - * A long representing the metadata to be emitted + * @param data A boolean representing the data to be emitted + * @param metadata A long representing the metadata to be emitted */ public EmitValue(final boolean data, final long metadata) { this(new String[] { BoaCasts.booleanToString(data) }, BoaCasts.longToString(metadata)); @@ -271,24 +243,108 @@ public EmitValue(final boolean data, final long metadata) { /** * Construct an EmitValue. * - * @param data - * A boolean representing the data to be emitted - * @param metadata - * A double representing the metadata to be emitted + * @param data A boolean representing the data to be emitted + * @param metadata A double representing the metadata to be emitted */ public EmitValue(final boolean data, final double metadata) { this(new String[] { BoaCasts.booleanToString(data) }, BoaCasts.doubleToString(metadata)); } + /** + * Construct an EmitValue. + * + * @param data A {@link Tuple} containing the data to be emitted + * @param metadata A {@link String} containing the metadata to be emitted + */ + public EmitValue(final Tuple data, final String metadata) { + this.tdata = data; + } + + /** + * Construct an EmitValue. + * + * @param data A {@link Tuple} containing the data to be emitted + */ + public EmitValue(final Tuple data) { + this(data, null); + } + + /** + * Construct an EmitValue. + * + * @param data An array of {@link double} containing the data to be emitted + * @param metadata A {@link String} containing the metadata to be emitted + */ + public EmitValue(final double[] data, final String metadata) { + final String[] strings = new String[data.length]; + + for (int i = 0; i < data.length; i++) + strings[i] = String.valueOf(data[i]); + + this.data = strings; + this.metadata = metadata; + } + + /** + * Construct an EmitValue. + * + * @param data An array of {@link double} containing the data to be emitted + */ + public EmitValue(final double[] data) { + this(data, null); + } + + /** + * Construct an EmitValue. + * + * @param data An array of {@link long} containing the data to be emitted + * @param metadata A {@link String} containing the metadata to be emitted + */ + public EmitValue(final long[] data, final String metadata) { + final String[] strings = new String[data.length]; + for (int i = 0; i < data.length; i++) + strings[i] = String.valueOf(data[i]); + this.data = strings; + this.metadata = metadata; + } + + /** + * Construct an EmitValue. + * + * @param data An array of {@link long} containing the data to be emitted + */ + public EmitValue(final long[] data) { + this(data, null); + } + /** {@inheritDoc} */ @Override public void readFields(final DataInput in) throws IOException { - final int count = in.readInt(); - - this.data = new String[count]; - for (int i = 0; i < count; i++) - this.data[i] = Text.readString(in); + final char type = in.readChar(); + if (type == 'S') { + final int count = in.readInt(); + this.data = new String[count]; + for (int i = 0; i < count; i++) + this.data[i] = Text.readString(in); + } else { + final int length = in.readInt(); + if (length > 0) { + byte[] bytes = new byte[length]; + in.readFully(bytes, 0, length); + ByteArrayInputStream bin = new ByteArrayInputStream(bytes); + ObjectInputStream dataIn = new ObjectInputStream(bin); + Object o = null; + try { + o = dataIn.readObject(); + } catch (Exception e) { + e.printStackTrace(); + } + this.tdata = (Tuple) o; + } + } + + // read metadata final String metadata = Text.readString(in); if (metadata.equals("")) this.metadata = null; @@ -299,11 +355,23 @@ public void readFields(final DataInput in) throws IOException { /** {@inheritDoc} */ @Override public void write(final DataOutput out) throws IOException { - out.writeInt(this.data.length); - - for (final String d : this.data) - Text.writeString(out, d); - + // write string[] data + if (this.data != null) { + out.writeChar('S'); // set date type S + out.writeInt(this.data.length); + for (final String d : this.data) + Text.writeString(out, d); + } + + // write tuple data + if (this.tdata != null) { + out.writeChar('T'); // set date type T + byte[] serializedObject = this.tdata.serialize(this.tdata); + out.writeInt(serializedObject.length); + out.write(serializedObject); + } + + // write metadata if (this.metadata == null) Text.writeString(out, ""); else @@ -318,8 +386,7 @@ public String[] getData() { } /** - * @param data - * the data to set + * @param data the data to set */ public void setData(final String[] data) { this.data = data; @@ -333,13 +400,16 @@ public String getMetadata() { } /** - * @param metadata - * the metadatum to set + * @param metadata the metadatum to set */ public void setMetadata(final String metadata) { this.metadata = metadata; } + public Tuple getTuple() { + return this.tdata; + } + @Override public int hashCode() { final int prime = 31; @@ -373,4 +443,4 @@ public boolean equals(final Object obj) { public String toString() { return Arrays.toString(this.data) + ":" + this.metadata; } -} +} \ No newline at end of file diff --git a/src/java/boa/runtime/BoaMapper.java b/src/java/boa/runtime/BoaMapper.java index c65e3c554..5585c1b7b 100644 --- a/src/java/boa/runtime/BoaMapper.java +++ b/src/java/boa/runtime/BoaMapper.java @@ -55,7 +55,6 @@ public void setConf(final Configuration conf) { @Override protected void setup(final Mapper.Context context) throws IOException, InterruptedException { super.setup(context); - this.context = context; } } diff --git a/src/java/boa/runtime/BoaPartitioner.java b/src/java/boa/runtime/BoaPartitioner.java index 695a689ab..8c250c440 100644 --- a/src/java/boa/runtime/BoaPartitioner.java +++ b/src/java/boa/runtime/BoaPartitioner.java @@ -32,7 +32,7 @@ public class BoaPartitioner extends Partitioner { private static String[] outputVariableNames = new String[0]; public int getPartition(final EmitKey key, final EmitValue value, final int num) { - return getPartitionForVariable(key.getName()); + return getPartitionForVariable(key.getName()) % num; } public static void setVariableNames(final String[] names) { diff --git a/src/java/boa/runtime/BoaReducer.java b/src/java/boa/runtime/BoaReducer.java index a1f75e034..70b5bec6a 100644 --- a/src/java/boa/runtime/BoaReducer.java +++ b/src/java/boa/runtime/BoaReducer.java @@ -29,6 +29,7 @@ import boa.aggregators.Aggregator; import boa.aggregators.FinishedException; +import boa.aggregators.ml.MLAggregator; import boa.io.EmitKey; import boa.io.EmitValue; @@ -76,17 +77,29 @@ public void setConf(final Configuration conf) { /** {@inheritDoc} */ @Override protected void reduce(final EmitKey key, final Iterable values, final Context context) throws IOException, InterruptedException { + // get the aggregator named by the emit key final Aggregator a = this.aggregators.get(key.getName()); - + a.setCombining(false); a.start(key); a.setContext(context); for (final EmitValue value : values) try { - for (final String s : value.getData()) - a.aggregate(s, value.getMetadata()); + if (a instanceof MLAggregator) { + MLAggregator mla = (MLAggregator) a; + if (value.getTuple() != null) { +// System.out.println("emit value is string[] "); + mla.aggregate(value.getTuple(), value.getMetadata()); + } else { +// System.out.println("emit value is tuple "); + mla.aggregate(value.getData(), value.getMetadata()); + } + } else { + for (final String s : value.getData()) + a.aggregate(s, value.getMetadata()); + } } catch (final FinishedException e) { // we are done return; diff --git a/src/java/boa/runtime/Tuple.java b/src/java/boa/runtime/Tuple.java new file mode 100644 index 000000000..7882e88fb --- /dev/null +++ b/src/java/boa/runtime/Tuple.java @@ -0,0 +1,26 @@ +/* + * Copyright 2020, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.runtime; + +import java.io.IOException; + +public interface Tuple { + public String[] getValues(); + public String[] getFieldNames(); + public byte[] serialize(Object o) throws IOException; + public Object getValue(String f); +} diff --git a/src/java/boa/types/BoaQueue.java b/src/java/boa/types/BoaQueue.java index ec03bbacc..cf05abb49 100644 --- a/src/java/boa/types/BoaQueue.java +++ b/src/java/boa/types/BoaQueue.java @@ -34,9 +34,8 @@ public BoaQueue() { /** * Construct a {@link BoaQueue}. * - * @param boaType - * A {@link BoaType} representing the type of the values in - * this queue + * @param boaType A {@link BoaType} representing the type of the values in this + * queue */ public BoaQueue(final BoaType boaType) { this.type = boaType; @@ -108,8 +107,7 @@ public boolean hasTypeVar() { /** * Get the type of the values of this queue. * - * @return A {@link BoaType} representing the type of the values of this - * queue + * @return A {@link BoaType} representing the type of the values of this queue */ public BoaType getType() { return this.type; diff --git a/src/java/boa/types/ml/BoaAdaBoostM1.java b/src/java/boa/types/ml/BoaAdaBoostM1.java new file mode 100644 index 000000000..08d540917 --- /dev/null +++ b/src/java/boa/types/ml/BoaAdaBoostM1.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of AdaBoostM1 with attached types. + * + * @author ankuraga + */ +public class BoaAdaBoostM1 extends BoaModel { + + /** + * Default BoaAdaBoostM1 Constructor. + * + */ + public BoaAdaBoostM1() { + } + + /** + * Construct a BoaAdaBoostM1. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaAdaBoostM1(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaAdaBoostM1. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaAdaBoostM1(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaAdaBoostM1"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaAdaBoostM1" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaAdditiveRegression.java b/src/java/boa/types/ml/BoaAdditiveRegression.java new file mode 100644 index 000000000..ffd083c93 --- /dev/null +++ b/src/java/boa/types/ml/BoaAdditiveRegression.java @@ -0,0 +1,92 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of AdditiveRegression with attached + * types. + * + * @author ankuraga + */ +public class BoaAdditiveRegression extends BoaModel { + public BoaAdditiveRegression() { + } + + /** + * Construct a BoaAdditiveRegression. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaAdditiveRegression(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaAdditiveRegression. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaAdditiveRegression(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** + * Get the type object of this model. + * + * @return A {@link Object} representing type object + * + */ + public Object getObject() { + return this.o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaAdditiveRegression"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaAdditiveRegression" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaAttributeSelectedClassifier.java b/src/java/boa/types/ml/BoaAttributeSelectedClassifier.java new file mode 100644 index 000000000..eb4faa09d --- /dev/null +++ b/src/java/boa/types/ml/BoaAttributeSelectedClassifier.java @@ -0,0 +1,96 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of AttributeSelectedClassifier with + * attached types. + * + * @author ankuraga + */ +public class BoaAttributeSelectedClassifier extends BoaModel { + /** + * Default BoaAttributeSelectedClassifier Constructor. + * + */ + public BoaAttributeSelectedClassifier() { + } + + /** + * Construct a BoaAttributeSelectedClassifier. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaAttributeSelectedClassifier(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaAttributeSelectedClassifier. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaAttributeSelectedClassifier(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** + * Get the type object of this model. + * + * @return A {@link Object} representing type object + * + */ + public Object getObject() { + return this.o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaAttributeSelectedClassifier"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaAttributeSelectedClassifier" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaBagging.java b/src/java/boa/types/ml/BoaBagging.java new file mode 100644 index 000000000..10a571ebd --- /dev/null +++ b/src/java/boa/types/ml/BoaBagging.java @@ -0,0 +1,97 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; +/** + * A {@link BoaType} representing ML model of Bagging with attached types. + * + * @author ankuraga + */ +public class BoaBagging extends BoaModel{ + /** + * Default BoaBagging Constructor. + * + */ + public BoaBagging(){ + } + + /** + * Construct a BoaBagging. + * + * @param t + * A {@link BoaType} containing the types attached with this model + * + */ + public BoaBagging(BoaType t){ + this.t = t; + } + + /** + * Construct a BoaBagging. + * + * @param clr + * A {@link Classifier} containing ML model + * + * @param o + * A {@link Object} containing type object + * + */ + public BoaBagging(Classifier clr, Object o){ + this.clr = clr; + this.o = o; + } + + /** + * Get the type object of this model. + * + * @return A {@link Object} representing type object + * + */ + public Object getObject() { + return this.o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaBagging"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaBagging" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaBayesNet.java b/src/java/boa/types/ml/BoaBayesNet.java new file mode 100644 index 000000000..9174e71ea --- /dev/null +++ b/src/java/boa/types/ml/BoaBayesNet.java @@ -0,0 +1,97 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; +/** + * A {@link BoaType} representing ML model of BayesNet with attached types. + * + * @author ankuraga + */ +public class BoaBayesNet extends BoaModel{ + /** + * Default BoaBayesNet Constructor. + * + */ + public BoaBayesNet(){ + } + + /** + * Construct a BoaBayesNet. + * + * @param t + * A {@link BoaType} containing the types attached with this model + * + */ + public BoaBayesNet(BoaType t){ + this.t = t; + } + + /** + * Construct a BoaBayesNet. + * + * @param clr + * A {@link Classifier} containing ML model + * + * @param o + * A {@link Object} containing type object + * + */ + public BoaBayesNet(Classifier clr, Object o){ + this.clr = clr; + this.o = o; + } + + /** + * Get the type object of this model. + * + * @return A {@link Object} representing type object + * + */ + public Object getObject() { + return this.o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaBayesNet"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaBayesNet" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaCVParameterSelection.java b/src/java/boa/types/ml/BoaCVParameterSelection.java new file mode 100644 index 000000000..3ae7b7e57 --- /dev/null +++ b/src/java/boa/types/ml/BoaCVParameterSelection.java @@ -0,0 +1,98 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + + +import boa.types.BoaType; +import weka.classifiers.Classifier; +/** + * A {@link BoaType} representing ML model of CVParameterSelection with attached types. + * + * @author ankuraga + */ +public class BoaCVParameterSelection extends BoaModel{ + /** + * Default BoaCVParameterSelection Constructor. + * + */ + public BoaCVParameterSelection(){ + } + + /** + * Construct a BoaCVParameterSelection. + * + * @param t + * A {@link BoaType} containing the types attached with this model + * + */ + public BoaCVParameterSelection(BoaType t){ + this.t = t; + } + + /** + * Construct a BoaCVParameterSelection. + * + * @param clr + * A {@link Classifier} containing ML model + * + * @param o + * A {@link Object} containing type object + * + */ + public BoaCVParameterSelection(Classifier clr, Object o){ + this.clr = clr; + this.o = o; + } + + /** + * Get the type object of this model. + * + * @return A {@link Object} representing type object + * + */ + public Object getObject() { + return this.o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaCVParameterSelection"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaCVParameterSelection" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaClassificationViaRegression.java b/src/java/boa/types/ml/BoaClassificationViaRegression.java new file mode 100644 index 000000000..b65b8c13d --- /dev/null +++ b/src/java/boa/types/ml/BoaClassificationViaRegression.java @@ -0,0 +1,97 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; +/** + * A {@link BoaType} representing ML model of ClassificationViaRegression with attached types. + * + * @author ankuraga + */ +public class BoaClassificationViaRegression extends BoaModel{ + /** + * Default BoaClassificationViaRegression Constructor. + * + */ + public BoaClassificationViaRegression(){ + } + + /** + * Construct a BoaClassificationViaRegression. + * + * @param t + * A {@link BoaType} containing the types attached with this model + * + */ + public BoaClassificationViaRegression(BoaType t){ + this.t = t; + } + + /** + * Construct a BoaClassificationViaRegression. + * + * @param clr + * A {@link Classifier} containing ML model + * + * @param o + * A {@link Object} containing type object + * + */ + public BoaClassificationViaRegression(Classifier clr, Object o){ + this.clr = clr; + this.o = o; + } + + /** + * Get the type object of this model. + * + * @return A {@link Object} representing type object + * + */ + public Object getObject() { + return this.o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaClassificationViaRegression"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaClassificationViaRegression" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaDecisionStump.java b/src/java/boa/types/ml/BoaDecisionStump.java new file mode 100644 index 000000000..fda325177 --- /dev/null +++ b/src/java/boa/types/ml/BoaDecisionStump.java @@ -0,0 +1,97 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; +/** + * A {@link BoaType} representing ML model of DecisionStump with attached types. + * + * @author ankuraga + */ +public class BoaDecisionStump extends BoaModel{ + /** + * Default BoaDecisionStump Constructor. + * + */ + public BoaDecisionStump(){ + } + + /** + * Construct a BoaDecisionStump. + * + * @param t + * A {@link BoaType} containing the types attached with this model + * + */ + public BoaDecisionStump(BoaType t){ + this.t = t; + } + + /** + * Construct a BoaDecisionStump. + * + * @param clr + * A {@link Classifier} containing ML model + * + * @param o + * A {@link Object} containing type object + * + */ + public BoaDecisionStump(Classifier clr, Object o){ + this.clr = clr; + this.o = o; + } + + /** + * Get the type object of this model. + * + * @return A {@link Object} representing type object + * + */ + public Object getObject() { + return this.o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaDecisionStump"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaDecisionStump" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaDecisionTable.java b/src/java/boa/types/ml/BoaDecisionTable.java new file mode 100644 index 000000000..a481d56fb --- /dev/null +++ b/src/java/boa/types/ml/BoaDecisionTable.java @@ -0,0 +1,97 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; +/** + * A {@link BoaType} representing ML model of DecisionTable with attached types. + * + * @author ankuraga + */ +public class BoaDecisionTable extends BoaModel{ + /** + * Default BoaDecisionTable Constructor. + * + */ + public BoaDecisionTable(){ + } + + /** + * Construct a BoaDecisionTable. + * + * @param t + * A {@link BoaType} containing the types attached with this model + * + */ + public BoaDecisionTable(BoaType t){ + this.t = t; + } + + /** + * Construct a BoaDecisionTable. + * + * @param clr + * A {@link Classifier} containing ML model + * + * @param o + * A {@link Object} containing type object + * + */ + public BoaDecisionTable(Classifier clr, Object o){ + this.clr = clr; + this.o = o; + } + + /** + * Get the type object of this model. + * + * @return A {@link Object} representing type object + * + */ + public Object getObject() { + return this.o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaDecisionTable"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaDecisionTable" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaFilteredClassifier.java b/src/java/boa/types/ml/BoaFilteredClassifier.java new file mode 100644 index 000000000..dc37d670c --- /dev/null +++ b/src/java/boa/types/ml/BoaFilteredClassifier.java @@ -0,0 +1,97 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; +/** + * A {@link BoaType} representing ML model of FilteredClassifier with attached types. + * + * @author ankuraga + */ +public class BoaFilteredClassifier extends BoaModel{ + /** + * Default BoaFilteredClassifier Constructor. + * + */ + public BoaFilteredClassifier(){ + } + + /** + * Construct a BoaFilteredClassifier. + * + * @param t + * A {@link BoaType} containing the types attached with this model + * + */ + public BoaFilteredClassifier(BoaType t){ + this.t = t; + } + + /** + * Construct a BoaFilteredClassifier. + * + * @param clr + * A {@link Classifier} containing ML model + * + * @param o + * A {@link Object} containing type object + * + */ + public BoaFilteredClassifier(Classifier clr, Object o){ + this.clr = clr; + this.o = o; + } + + /** + * Get the type object of this model. + * + * @return A {@link Object} representing type object + * + */ + public Object getObject() { + return this.o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaFilteredClassifier"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaFilteredClassifier" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaGaussianProcesses.java b/src/java/boa/types/ml/BoaGaussianProcesses.java new file mode 100644 index 000000000..dac6f4262 --- /dev/null +++ b/src/java/boa/types/ml/BoaGaussianProcesses.java @@ -0,0 +1,97 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; +import boa.types.BoaType; + +import weka.classifiers.Classifier; +/** + * A {@link BoaType} representing ML model of GaussianProcesses with attached types. + * + * @author ankuraga + */ +public class BoaGaussianProcesses extends BoaModel{ + /** + * Default BoaGaussianProcesses Constructor. + * + */ + public BoaGaussianProcesses(){ + } + + /** + * Construct a BoaGaussianProcesses. + * + * @param t + * A {@link BoaType} containing the types attached with this model + * + */ + public BoaGaussianProcesses(BoaType t){ + this.t = t; + } + + /** + * Construct a BoaGaussianProcesses. + * + * @param clr + * A {@link Classifier} containing ML model + * + * @param o + * A {@link Object} containing type object + * + */ + public BoaGaussianProcesses(Classifier clr, Object o){ + this.clr = clr; + this.o = o; + } + + /** + * Get the type object of this model. + * + * @return A {@link Object} representing type object + * + */ + public Object getObject() { + return this.o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaGaussianProcesses"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaGaussianProcesses" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaInputMappedClassifier.java b/src/java/boa/types/ml/BoaInputMappedClassifier.java new file mode 100644 index 000000000..a95a77dad --- /dev/null +++ b/src/java/boa/types/ml/BoaInputMappedClassifier.java @@ -0,0 +1,97 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; +/** + * A {@link BoaType} representing ML model of InputMappedClassifier with attached types. + * + * @author ankuraga + */ +public class BoaInputMappedClassifier extends BoaModel{ + /** + * Default BoaInputMappedClassifier Constructor. + * + */ + public BoaInputMappedClassifier(){ + } + + /** + * Construct a BoaInputMappedClassifier. + * + * @param t + * A {@link BoaType} containing the types attached with this model + * + */ + public BoaInputMappedClassifier(BoaType t){ + this.t = t; + } + + /** + * Construct a BoaInputMappedClassifier. + * + * @param clr + * A {@link Classifier} containing ML model + * + * @param o + * A {@link Object} containing type object + * + */ + public BoaInputMappedClassifier(Classifier clr, Object o){ + this.clr = clr; + this.o = o; + } + + /** + * Get the type object of this model. + * + * @return A {@link Object} representing type object + * + */ + public Object getObject() { + return this.o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaInputMappedClassifier"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaInputMappedClassifier" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaJ48.java b/src/java/boa/types/ml/BoaJ48.java new file mode 100644 index 000000000..4e37a4b5f --- /dev/null +++ b/src/java/boa/types/ml/BoaJ48.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of J48 with attached types. + * + * @author ankuraga + */ +public class BoaJ48 extends BoaModel { + + /** + * Default BoaJ48 Constructor. + * + */ + public BoaJ48() { + } + + /** + * Construct a BoaJ48. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaJ48(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaJ48. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaJ48(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaJ48"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaJ48" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaJRip.java b/src/java/boa/types/ml/BoaJRip.java new file mode 100644 index 000000000..eb42f3721 --- /dev/null +++ b/src/java/boa/types/ml/BoaJRip.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of JRip with attached types. + * + * @author ankuraga + */ +public class BoaJRip extends BoaModel { + + /** + * Default BoaJRip Constructor. + * + */ + public BoaJRip() { + } + + /** + * Construct a BoaJRip. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaJRip(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaJRip. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaJRip(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaJRip"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaJRip" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaKStar.java b/src/java/boa/types/ml/BoaKStar.java new file mode 100644 index 000000000..6e7955758 --- /dev/null +++ b/src/java/boa/types/ml/BoaKStar.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of KStar with attached types. + * + * @author ankuraga + */ +public class BoaKStar extends BoaModel { + + /** + * Default BoaJ48 Constructor. + * + */ + public BoaKStar() { + } + + /** + * Construct a BoaKStar. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaKStar(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaKStar. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaKStar(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaKStar"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaKStar" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaLMT.java b/src/java/boa/types/ml/BoaLMT.java new file mode 100644 index 000000000..93bf698f3 --- /dev/null +++ b/src/java/boa/types/ml/BoaLMT.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of LMT with attached types. + * + * @author ankuraga + */ +public class BoaLMT extends BoaModel { + + /** + * Default BoaLMT Constructor. + * + */ + public BoaLMT() { + } + + /** + * Construct a BoaLMT. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaLMT(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaLMT. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaLMT(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaLMT"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaLMT" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaLWL.java b/src/java/boa/types/ml/BoaLWL.java new file mode 100644 index 000000000..b92ca3f53 --- /dev/null +++ b/src/java/boa/types/ml/BoaLWL.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of LWL with attached types. + * + * @author ankuraga + */ +public class BoaLWL extends BoaModel { + + /** + * Default BoaLWL Constructor. + * + */ + public BoaLWL() { + } + + /** + * Construct a BoaLWL. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaLWL(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaLWL. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaLWL(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaLWL"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaLWL" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaLinearRegression.java b/src/java/boa/types/ml/BoaLinearRegression.java new file mode 100644 index 000000000..f1f694b82 --- /dev/null +++ b/src/java/boa/types/ml/BoaLinearRegression.java @@ -0,0 +1,91 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of LinearRegression with attached + * types. + * + * @author ankuraga + */ +public class BoaLinearRegression extends BoaModel { + + /** + * Default BoaLinearRegression Constructor. + * + */ + public BoaLinearRegression() { + } + + /** + * Construct a BoaLinearRegression. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaLinearRegression(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaLinearRegression. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaLinearRegression(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaLinearRegression"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaLinearRegression" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaLogisticRegression.java b/src/java/boa/types/ml/BoaLogisticRegression.java new file mode 100644 index 000000000..2ef3f66b8 --- /dev/null +++ b/src/java/boa/types/ml/BoaLogisticRegression.java @@ -0,0 +1,91 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of LogisticRegression with attached + * types. + * + * @author ankuraga + */ +public class BoaLogisticRegression extends BoaModel { + + /** + * Default BoaLogisticRegression Constructor. + * + */ + public BoaLogisticRegression() { + } + + /** + * Construct a BoaLogisticRegression. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaLogisticRegression(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaLogisticRegression. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaLogisticRegression(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaLogisticRegression"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaLogisticRegression" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaLogitBoost.java b/src/java/boa/types/ml/BoaLogitBoost.java new file mode 100644 index 000000000..4456bb894 --- /dev/null +++ b/src/java/boa/types/ml/BoaLogitBoost.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of LogitBoost with attached types. + * + * @author ankuraga + */ +public class BoaLogitBoost extends BoaModel { + + /** + * Default BoaLogitBoost Constructor. + * + */ + public BoaLogitBoost() { + } + + /** + * Construct a BoaLogitBoost. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaLogitBoost(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaLogitBoost. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaLogitBoost(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaLogitBoost"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaLogitBoost" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaModel.java b/src/java/boa/types/ml/BoaModel.java new file mode 100644 index 000000000..7fe4ac374 --- /dev/null +++ b/src/java/boa/types/ml/BoaModel.java @@ -0,0 +1,164 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaFunction; +import boa.types.BoaName; +import boa.types.BoaType; +import weka.classifiers.Classifier; +import weka.clusterers.Clusterer; + +/** + * A {@link BoaType} representing model of any ML type. + * + * @author ankuraga + */ +public class BoaModel extends BoaType { + protected Classifier clr; + protected Clusterer clu; + protected BoaType t; + protected Object o; + + /** + * Default BoaModel Constructor. + * + */ + public BoaModel() { + } + + /** + * Construct a BoaModel. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaModel(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaModel. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaModel(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** + * Get the classifier of this model. + * + * @return A {@link Classifier} representing ML model + * + */ + public Classifier getClassifier() { + return this.clr; + } + + /** + * Construct a BoaModel. + * + * @param clu A {@link Clusterer} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaModel(Clusterer clu, Object o) { + this.clu = clu; + this.o = o; + } + + /** + * Get the classifier of this model. + * + * @return A {@link Clusterer} representing ML model + * + */ + public Clusterer getClusterer() { + return this.clu; + } + + /** + * Get the type attached with this model. + * + * @return A {@link BoaType} representing type attached with ML model + * + */ + public BoaType getType() { + return this.t; + } + + /** + * Get the type object of this model. + * + * @return A {@link Object} representing type object + * + */ + public Object getObject() { + return this.o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + // if that is a function, check the return type + if (that instanceof BoaFunction) + return this.assigns(((BoaFunction) that).getType()); + + // if that is a component, check the type + if (that instanceof BoaName) + return this.assigns(((BoaName) that).getType()); + + // otherwise, if it's not an model, forget it + if (!(that instanceof BoaModel)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + // if that is a function, check the return value + if (that instanceof BoaFunction) + return this.assigns(((BoaFunction) that).getType()); + + // otherwise, if it's not an model, forget it + if (!(that instanceof BoaModel)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaModel"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "model"; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaMultiClassClassifier.java b/src/java/boa/types/ml/BoaMultiClassClassifier.java new file mode 100644 index 000000000..5db3362d2 --- /dev/null +++ b/src/java/boa/types/ml/BoaMultiClassClassifier.java @@ -0,0 +1,91 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of MultiClassClassifier with attached + * types. + * + * @author ankuraga + */ +public class BoaMultiClassClassifier extends BoaModel { + + /** + * Default BoaMultiClassClassifier Constructor. + * + */ + public BoaMultiClassClassifier() { + } + + /** + * Construct a BoaMultiClassClassifier. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaMultiClassClassifier(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaMultiClassClassifier. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaMultiClassClassifier(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaMultiClassClassifier"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaMultiClassClassifier" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaMultiScheme.java b/src/java/boa/types/ml/BoaMultiScheme.java new file mode 100644 index 000000000..afdd5fc6c --- /dev/null +++ b/src/java/boa/types/ml/BoaMultiScheme.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of MultiScheme with attached types. + * + * @author ankuraga + */ +public class BoaMultiScheme extends BoaModel { + + /** + * Default BoaMultiScheme Constructor. + * + */ + public BoaMultiScheme() { + } + + /** + * Construct a BoaMultiScheme. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaMultiScheme(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaMultiScheme. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaMultiScheme(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaMultiScheme"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaMultiScheme" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaMultilayerPerceptron.java b/src/java/boa/types/ml/BoaMultilayerPerceptron.java new file mode 100644 index 000000000..3b303c28c --- /dev/null +++ b/src/java/boa/types/ml/BoaMultilayerPerceptron.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of MultilayerPerceptron with attached + * types. + * + * @author ankuraga + */ +public class BoaMultilayerPerceptron extends BoaModel { + /** + * Default BoaMultilayerPerceptron Constructor. + * + */ + public BoaMultilayerPerceptron() { + } + + /** + * Construct a BoaMultilayerPerceptron. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaMultilayerPerceptron(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaMultilayerPerceptron. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaMultilayerPerceptron(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaMultilayerPerceptron"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaMultilayerPerceptron" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaNaiveBayes.java b/src/java/boa/types/ml/BoaNaiveBayes.java new file mode 100644 index 000000000..47e6d3e27 --- /dev/null +++ b/src/java/boa/types/ml/BoaNaiveBayes.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of NaiveBayes with attached types. + * + * @author ankuraga + */ +public class BoaNaiveBayes extends BoaModel { + + /** + * Default BoaNaiveBayes Constructor. + * + */ + public BoaNaiveBayes() { + } + + /** + * Construct a BoaNaiveBayes. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaNaiveBayes(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaNaiveBayes. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaNaiveBayes(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaNaiveBayes"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaNaiveBayes" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaNaiveBayesMultinomial.java b/src/java/boa/types/ml/BoaNaiveBayesMultinomial.java new file mode 100644 index 000000000..782b72281 --- /dev/null +++ b/src/java/boa/types/ml/BoaNaiveBayesMultinomial.java @@ -0,0 +1,91 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of NaiveBayesMultinomial with + * attached types. + * + * @author ankuraga + */ +public class BoaNaiveBayesMultinomial extends BoaModel { + + /** + * Default BoaNaiveBayesMultinomial Constructor. + * + */ + public BoaNaiveBayesMultinomial() { + } + + /** + * Construct a BoaNaiveBayesMultinomial. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaNaiveBayesMultinomial(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaNaiveBayesMultinomial. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaNaiveBayesMultinomial(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaNaiveBayesMultinomial"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaNaiveBayesMultinomial" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaNaiveBayesMultinomialUpdateable.java b/src/java/boa/types/ml/BoaNaiveBayesMultinomialUpdateable.java new file mode 100644 index 000000000..b2be6f17a --- /dev/null +++ b/src/java/boa/types/ml/BoaNaiveBayesMultinomialUpdateable.java @@ -0,0 +1,91 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of NaiveBayesMultinomialUpdateable + * with attached types. + * + * @author ankuraga + */ +public class BoaNaiveBayesMultinomialUpdateable extends BoaModel { + + /** + * Default BoaNaiveBayesMultinomialUpdateable Constructor. + * + */ + public BoaNaiveBayesMultinomialUpdateable() { + } + + /** + * Construct a BoaNaiveBayesMultinomialUpdateable. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaNaiveBayesMultinomialUpdateable(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaNaiveBayesMultinomialUpdateable. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaNaiveBayesMultinomialUpdateable(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaNaiveBayesMultinomialUpdateable"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaNaiveBayesMultinomialUpdateable" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaOneR.java b/src/java/boa/types/ml/BoaOneR.java new file mode 100644 index 000000000..4030c54f4 --- /dev/null +++ b/src/java/boa/types/ml/BoaOneR.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of OneR with attached types. + * + * @author ankuraga + */ +public class BoaOneR extends BoaModel { + + /** + * Default BoaOneR Constructor. + * + */ + public BoaOneR() { + } + + /** + * Construct a BoaOneR. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaOneR(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaOneR. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaOneR(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaOneR"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaOneR" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaPART.java b/src/java/boa/types/ml/BoaPART.java new file mode 100644 index 000000000..4ce51c505 --- /dev/null +++ b/src/java/boa/types/ml/BoaPART.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of PART with attached types. + * + * @author ankuraga + */ +public class BoaPART extends BoaModel { + + /** + * Default BoaPART Constructor. + * + */ + public BoaPART() { + } + + /** + * Construct a BoaPART. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaPART(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaPART. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaPART(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaPART"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaPART" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaRandomForest.java b/src/java/boa/types/ml/BoaRandomForest.java new file mode 100644 index 000000000..eadb4ebff --- /dev/null +++ b/src/java/boa/types/ml/BoaRandomForest.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of RandomForest with attached types. + * + * @author ankuraga + */ +public class BoaRandomForest extends BoaModel { + + /** + * Default BoaRandomForest Constructor. + * + */ + public BoaRandomForest() { + } + + /** + * Construct a BoaRandomForest. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaRandomForest(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaRandomForest. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaRandomForest(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaRandomForest"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaRandomForest" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaSMO.java b/src/java/boa/types/ml/BoaSMO.java new file mode 100644 index 000000000..2bcc60643 --- /dev/null +++ b/src/java/boa/types/ml/BoaSMO.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of SMO with attached types. + * + * @author ankuraga + */ +public class BoaSMO extends BoaModel { + + /** + * Default BoaSMO Constructor. + * + */ + public BoaSMO() { + } + + /** + * Construct a BoaSMO. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaSMO(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaSMO. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaSMO(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaSMO"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaSMO" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaSequence2Vec.java b/src/java/boa/types/ml/BoaSequence2Vec.java new file mode 100644 index 000000000..71a47bbd4 --- /dev/null +++ b/src/java/boa/types/ml/BoaSequence2Vec.java @@ -0,0 +1,98 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import org.deeplearning4j.models.sequencevectors.SequenceVectors; +import org.deeplearning4j.models.word2vec.VocabWord; + +import boa.types.BoaType; + +/** + * A {@link BoaType} representing ML model of Word2Vec with attached types. + * + * @author hyj + */ +public class BoaSequence2Vec extends BoaModel { + + private SequenceVectors seq2vec; + + /** + * Default BoaVote Constructor. + * + */ + public BoaSequence2Vec() { + } + + /** + * Construct a BoaVote. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaSequence2Vec(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaVote. + * + * @param w2v A {@link SequenceVectors} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaSequence2Vec(SequenceVectors seq2vec, Object o) { + this.seq2vec = seq2vec; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaSequence2Vec"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaSequence2Vec" + "/" + this.t; + } + + public SequenceVectors getSeq2Vec() { + return seq2vec; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaSimpleKMeans.java b/src/java/boa/types/ml/BoaSimpleKMeans.java new file mode 100644 index 000000000..0b63ed1e7 --- /dev/null +++ b/src/java/boa/types/ml/BoaSimpleKMeans.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.clusterers.Clusterer; + +/** + * A {@link BoaType} representing ML model of SimpleKMeans with attached types. + * + * @author ankuraga + */ +public class BoaSimpleKMeans extends BoaModel { + + /** + * Default BoaSimpleKMeans Constructor. + * + */ + public BoaSimpleKMeans() { + } + + /** + * Construct a BoaSimpleKMeans. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaSimpleKMeans(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaSimpleKMeans. + * + * @param clu A {@link Clusterer} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaSimpleKMeans(Clusterer clu, Object o) { + this.clu = clu; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaSimpleKMeans"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaSimpleKMeans" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaVote.java b/src/java/boa/types/ml/BoaVote.java new file mode 100644 index 000000000..9fb19e085 --- /dev/null +++ b/src/java/boa/types/ml/BoaVote.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of Vote with attached types. + * + * @author ankuraga + */ +public class BoaVote extends BoaModel { + + /** + * Default BoaVote Constructor. + * + */ + public BoaVote() { + } + + /** + * Construct a BoaVote. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaVote(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaVote. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaVote(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaVote"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaVote" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaWord2Vec.java b/src/java/boa/types/ml/BoaWord2Vec.java new file mode 100644 index 000000000..1b29b4b36 --- /dev/null +++ b/src/java/boa/types/ml/BoaWord2Vec.java @@ -0,0 +1,97 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import org.deeplearning4j.models.word2vec.Word2Vec; + +import boa.types.BoaType; + +/** + * A {@link BoaType} representing ML model of Word2Vec with attached types. + * + * @author hyj + */ +public class BoaWord2Vec extends BoaModel { + + private Word2Vec w2v; + + /** + * Default BoaVote Constructor. + * + */ + public BoaWord2Vec() { + } + + /** + * Construct a BoaVote. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaWord2Vec(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaVote. + * + * @param w2v A {@link Word2Vec} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaWord2Vec(Word2Vec w2v, Object o) { + this.w2v = w2v; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaWord2Vec"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaWord2Vec" + "/" + this.t; + } + + public Word2Vec getW2v() { + return w2v; + } +} \ No newline at end of file diff --git a/src/java/boa/types/ml/BoaZeroR.java b/src/java/boa/types/ml/BoaZeroR.java new file mode 100644 index 000000000..84fcc3890 --- /dev/null +++ b/src/java/boa/types/ml/BoaZeroR.java @@ -0,0 +1,90 @@ +/* + * Copyright 2014, Hridesh Rajan, Robert Dyer, + * and Iowa State University of Science and Technology + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package boa.types.ml; + +import boa.types.BoaType; +import weka.classifiers.Classifier; + +/** + * A {@link BoaType} representing ML model of ZeroR with attached types. + * + * @author ankuraga + */ +public class BoaZeroR extends BoaModel { + + /** + * Default BoaZeroR Constructor. + * + */ + public BoaZeroR() { + } + + /** + * Construct a BoaZeroR. + * + * @param t A {@link BoaType} containing the types attached with this model + * + */ + public BoaZeroR(BoaType t) { + this.t = t; + } + + /** + * Construct a BoaZeroR. + * + * @param clr A {@link Classifier} containing ML model + * + * @param o A {@link Object} containing type object + * + */ + public BoaZeroR(Classifier clr, Object o) { + this.clr = clr; + this.o = o; + } + + /** {@inheritDoc} */ + @Override + public boolean assigns(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean accepts(final BoaType that) { + if (!super.assigns(that)) + return false; + + // ok + return true; + } + + /** {@inheritDoc} */ + @Override + public String toJavaType() { + return "boa.types.ml.BoaZeroR"; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return "boa.types.ml.BoaZeroR" + "/" + this.t; + } +} \ No newline at end of file diff --git a/src/test/boa/test/compiler/TestMLGood.java b/src/test/boa/test/compiler/TestMLGood.java new file mode 100644 index 000000000..09427ab77 --- /dev/null +++ b/src/test/boa/test/compiler/TestMLGood.java @@ -0,0 +1,42 @@ +package boa.test.compiler; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + +/** + * @author hyj + */ +@RunWith(Parameterized.class) +public class TestMLGood extends BaseTest { + final private static String rootDir = "test/ml/"; + + @Parameters(name = "{0}") + public static List data() { + final List files = new ArrayList(); + for (final File f : new File(rootDir).listFiles()) + if (f.isDirectory()) + for (final File f1 : f.listFiles()) + if (!f1.isDirectory() && f1.getName().endsWith(".boa")) + files.add(new String[] { f1.getPath(), null }); + return files; + } + + private String fileName; + public TestMLGood(final String fileName, final String ignored) { + this.fileName = fileName; + } + + + // test a bunch of known good files + @Test + public void knownGood() throws IOException { + codegen(load(fileName)); + } +} diff --git a/src/test/boa/test/compiler/TestParserBad.java b/src/test/boa/test/compiler/TestParserBad.java index 5d062a711..32dd93f46 100644 --- a/src/test/boa/test/compiler/TestParserBad.java +++ b/src/test/boa/test/compiler/TestParserBad.java @@ -53,11 +53,11 @@ public void badEmitWithWeight() throws IOException { public void badIdentifiers() throws IOException { parse(load(badDir + "bad-identifiers.boa"), new String[] { - "2,0: extraneous input '_' expecting {'of', 'if', 'do', 'map', 'stack', 'queue', 'set', 'for', 'foreach', 'ifall', 'exists', 'not', 'type', 'else', 'case', 'output', 'format', 'while', 'break', 'array', 'static', 'switch', 'return', 'weight', 'default', 'continue', 'function', 'fixp', 'visitor', 'traversal', 'before', 'after', 'stop', ';', '{', '(', '+', '-', '~', '!', '$', IntegerLiteral, FloatingPointLiteral, CharacterLiteral, RegexLiteral, MultilineStringLiteral, StringLiteral, TimeLiteral, Identifier}", + "2,0: extraneous input '_' expecting {'of', 'if', 'do', 'map', 'stack', 'queue', 'model', 'set', 'for', 'foreach', 'ifall', 'exists', 'not', 'type', 'else', 'case', 'output', 'format', 'while', 'break', 'array', 'static', 'switch', 'return', 'weight', 'default', 'continue', 'function', 'fixp', 'visitor', 'traversal', 'before', 'after', 'stop', ';', '{', '(', '+', '-', '~', '!', '$', IntegerLiteral, FloatingPointLiteral, CharacterLiteral, RegexLiteral, MultilineStringLiteral, StringLiteral, TimeLiteral, Identifier}", "3,1: error: ';' expected", "4,9: no viable alternative at input '+id:'", "4,5: error: ';' expected", - "4,9: mismatched input ':' expecting {, 'of', 'if', 'do', 'map', 'stack', 'queue', 'set', 'for', 'foreach', 'ifall', 'exists', 'not', 'type', 'else', 'case', 'output', 'format', 'while', 'break', 'array', 'static', 'switch', 'return', 'weight', 'default', 'continue', 'function', 'fixp', 'visitor', 'traversal', 'before', 'after', 'stop', ';', '.', '{', '(', '[', 'or', '|', '||', 'and', '&', '&&', '+', '-', '^', '*', '/', '%', '>>', '~', '!', '$', '<<', IntegerLiteral, FloatingPointLiteral, CharacterLiteral, RegexLiteral, MultilineStringLiteral, StringLiteral, TimeLiteral, Identifier}", + "4,9: mismatched input ':' expecting {, 'of', 'if', 'do', 'map', 'stack', 'queue', 'model', 'set', 'for', 'foreach', 'ifall', 'exists', 'not', 'type', 'else', 'case', 'output', 'format', 'while', 'break', 'array', 'static', 'switch', 'return', 'weight', 'default', 'continue', 'function', 'fixp', 'visitor', 'traversal', 'before', 'after', 'stop', ';', '.', '{', '(', '[', 'or', '|', '||', 'and', '&', '&&', '+', '-', '^', '*', '/', '%', '>>', '~', '!', '$', '<<', IntegerLiteral, FloatingPointLiteral, CharacterLiteral, RegexLiteral, MultilineStringLiteral, StringLiteral, TimeLiteral, Identifier}", "4,12: error: ';' expected" }); } @@ -71,7 +71,7 @@ public void outputVarEquals() throws IOException { @Test public void assignToMap() throws IOException { parse(load(badDir + "assign-to-map.boa"), - new String[] { "2,9: extraneous input ':' expecting {, 'of', 'if', 'do', 'map', 'stack', 'queue', 'set', 'for', 'foreach', 'ifall', 'exists', 'not', 'type', 'else', 'case', 'output', 'format', 'while', 'break', 'array', 'static', 'switch', 'return', 'weight', 'default', 'continue', 'function', 'fixp', 'visitor', 'traversal', 'before', 'after', 'stop', ';', '.', '{', '(', '[', 'or', '|', '||', 'and', '&', '&&', '+', '-', '^', '*', '/', '%', '>>', '~', '!', '$', '<<', IntegerLiteral, FloatingPointLiteral, CharacterLiteral, RegexLiteral, MultilineStringLiteral, StringLiteral, TimeLiteral, Identifier}", + new String[] { "2,9: extraneous input ':' expecting {, 'of', 'if', 'do', 'map', 'stack', 'queue', 'model', 'set', 'for', 'foreach', 'ifall', 'exists', 'not', 'type', 'else', 'case', 'output', 'format', 'while', 'break', 'array', 'static', 'switch', 'return', 'weight', 'default', 'continue', 'function', 'fixp', 'visitor', 'traversal', 'before', 'after', 'stop', ';', '.', '{', '(', '[', 'or', '|', '||', 'and', '&', '&&', '+', '-', '^', '*', '/', '%', '>>', '~', '!', '$', '<<', IntegerLiteral, FloatingPointLiteral, CharacterLiteral, RegexLiteral, MultilineStringLiteral, StringLiteral, TimeLiteral, Identifier}", "2,12: error: ';' expected" }); } @@ -89,7 +89,7 @@ public void enumExtracomma() throws IOException { parse(load(badDir + "enum-extra-comma.boa"), new String[] { "2,38: no viable alternative at input ',,'", "2,39: error: ';' expected", - "2,51: extraneous input '}' expecting {, 'of', 'if', 'do', 'map', 'stack', 'queue', 'set', 'for', 'foreach', 'ifall', 'exists', 'not', 'type', 'else', 'case', 'output', 'format', 'while', 'break', 'array', 'static', 'switch', 'return', 'weight', 'default', 'continue', 'function', 'fixp', 'visitor', 'traversal', 'before', 'after', 'stop', ';', '.', '{', '(', '[', 'or', '|', '||', 'and', '&', '&&', '+', '-', '^', '*', '/', '%', '>>', '~', '!', '$', '<<', IntegerLiteral, FloatingPointLiteral, CharacterLiteral, RegexLiteral, MultilineStringLiteral, StringLiteral, TimeLiteral, Identifier}" + "2,51: extraneous input '}' expecting {, 'of', 'if', 'do', 'map', 'stack', 'queue', 'model', 'set', 'for', 'foreach', 'ifall', 'exists', 'not', 'type', 'else', 'case', 'output', 'format', 'while', 'break', 'array', 'static', 'switch', 'return', 'weight', 'default', 'continue', 'function', 'fixp', 'visitor', 'traversal', 'before', 'after', 'stop', ';', '.', '{', '(', '[', 'or', '|', '||', 'and', '&', '&&', '+', '-', '^', '*', '/', '%', '>>', '~', '!', '$', '<<', IntegerLiteral, FloatingPointLiteral, CharacterLiteral, RegexLiteral, MultilineStringLiteral, StringLiteral, TimeLiteral, Identifier}" }); } } diff --git a/templates/BoaJava.stg b/templates/BoaJava.stg index e1776dd92..8ea86486d 100644 --- a/templates/BoaJava.stg +++ b/templates/BoaJava.stg @@ -125,16 +125,19 @@ new () } >> -TupleType(name, fields, types, protos) ::= << -private class -{ +TupleType(name, fields, types, protos, enums) ::= << +public static class implements boa.runtime.Tuple, java.io.Serializable +{ + (){} + ___;}; separator="\n"> ( ___}; separator=", ">) { - this.___ = ___;this.___ = new (___);}; separator="\n"> + this.___ = ___;this.___ = ___;this.___ = new (___);}; separator="\n"> } + ( tmp) { - this.___ = tmp.___; this.___ = new (tmp.___);}; separator="\n"> + this.___ = tmp.___; this.___ = tmp.___; this.___ = new (tmp.___);}; separator="\n"> } public clone() { @@ -149,6 +152,30 @@ s += " = " + this.___;}; separator="\n"> s += " }"; return s; } + + public byte[] serialize(Object o) throws java.io.IOException { + java.io.ByteArrayOutputStream byteOutStream = new java.io.ByteArrayOutputStream(); + java.io.ObjectOutputStream objectOut = new java.io.ObjectOutputStream(byteOutStream); + objectOut.writeObject(o); + objectOut.close(); + return byteOutStream.toByteArray(); + } + + public String[] getValues() { + return new String[] {)}; separator=", "> }; + } + + public String[] getFieldNames() { + return new String[] {"}; separator=", "> }; + } + + public Object getValue(String f) { + ")) + return ___; + }; separator=" "> + return "empty"; + } }<\n> >> diff --git a/test/ml/SMO/test.boa b/test/ml/SMO/test.boa new file mode 100644 index 000000000..823bf82df --- /dev/null +++ b/test/ml/SMO/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +s: model of SMO of {int, T, int, T}; +s = load(0, s); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << classify(s, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/SMO/train.boa b/test/ml/SMO/train.boa new file mode 100644 index 000000000..f90c04a56 --- /dev/null +++ b/test/ml/SMO/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +s: output smo("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + s << {x1, x2, x3, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/adaboost/test.boa b/test/ml/adaboost/test.boa new file mode 100644 index 000000000..21d40acca --- /dev/null +++ b/test/ml/adaboost/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +ada: model of AdaBoostM1 of {int, T, int, T}; +ada = load(0, ada); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << classify(ada, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/adaboost/train.boa b/test/ml/adaboost/train.boa new file mode 100644 index 000000000..92dde83f4 --- /dev/null +++ b/test/ml/adaboost/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +ada : output adaboost("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + ada << {x1, x2, x3, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/additive-regression/test.boa b/test/ml/additive-regression/test.boa new file mode 100644 index 000000000..47203e0ea --- /dev/null +++ b/test/ml/additive-regression/test.boa @@ -0,0 +1,9 @@ +p: Project = input; +predict: output collection of string; + +additive: model of AdditiveRegression of {int, int, int}; +additive = load(0, additive); + +x1 := 1; +x2 := 2; +predict << classify(additive, {x1, x2}); \ No newline at end of file diff --git a/test/ml/additive-regression/train.boa b/test/ml/additive-regression/train.boa new file mode 100644 index 000000000..2c158bc96 --- /dev/null +++ b/test/ml/additive-regression/train.boa @@ -0,0 +1,12 @@ +p: Project = input; + +additive: output additiveregression("-s 75") of {int, int, int}; +i := 0; +while(i < 100){ + x1 := 2 + 6 * i; + x2 := 3 + 5 * i; + y := 4 + 2 * i; + additive << { x1, x2, y }; + + i++; +} \ No newline at end of file diff --git a/test/ml/attribute-selected-classifier/test.boa b/test/ml/attribute-selected-classifier/test.boa new file mode 100644 index 000000000..1e52e7847 --- /dev/null +++ b/test/ml/attribute-selected-classifier/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +asc: model of AttributeSelectedClassifier of {int, T, int, T}; +asc = load(0, asc); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << classify(asc, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/attribute-selected-classifier/train.boa b/test/ml/attribute-selected-classifier/train.boa new file mode 100644 index 000000000..f709cb810 --- /dev/null +++ b/test/ml/attribute-selected-classifier/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; +p: Project = input; + +asc : output attributeselectedclassifier("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + asc << {x1, x2, x3, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/bagging/test.boa b/test/ml/bagging/test.boa new file mode 100644 index 000000000..3f30468c6 --- /dev/null +++ b/test/ml/bagging/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +bg: model of Bagging of {int, T, int, T}; +bg = load(0, bg); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << classify(bg, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/bagging/train.boa b/test/ml/bagging/train.boa new file mode 100644 index 000000000..32389635e --- /dev/null +++ b/test/ml/bagging/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; +p: Project = input; + +bg : output bagging("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + bg << {x1, x2, x3, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/bayes-net/test.boa b/test/ml/bayes-net/test.boa new file mode 100644 index 000000000..fc77d46a7 --- /dev/null +++ b/test/ml/bayes-net/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +bn: model of BayesNet of {int, T, int, T}; +bn = load(0, bn); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << classify(bn, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/bayes-net/train.boa b/test/ml/bayes-net/train.boa new file mode 100644 index 000000000..d67ef7252 --- /dev/null +++ b/test/ml/bayes-net/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; +p: Project = input; + +bn : output bayesnet("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + bn << {x1, x2, x3, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/classification-via-regression/test.boa b/test/ml/classification-via-regression/test.boa new file mode 100644 index 000000000..bd5e7c61a --- /dev/null +++ b/test/ml/classification-via-regression/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +cvr: model of ClassificationViaRegression of {int, T, int, T}; +cvr = load(0, cvr); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << classify(cvr, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/classification-via-regression/train.boa b/test/ml/classification-via-regression/train.boa new file mode 100644 index 000000000..ab5f645d5 --- /dev/null +++ b/test/ml/classification-via-regression/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; +p: Project = input; + +cvr : output classificationviaregression("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + cvr << {x1, x2, x3, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/cv-parameter-selection/test.boa b/test/ml/cv-parameter-selection/test.boa new file mode 100644 index 000000000..83b29d873 --- /dev/null +++ b/test/ml/cv-parameter-selection/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +cvps: model of CVParameterSelection of {int, T, int, T}; +cvps = load(0, cvps); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << classify(cvps, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/cv-parameter-selection/train.boa b/test/ml/cv-parameter-selection/train.boa new file mode 100644 index 000000000..765090864 --- /dev/null +++ b/test/ml/cv-parameter-selection/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; +p: Project = input; + +cvps : output cvparameterselection("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + cvps << {x1, x2, x3, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/decision-stump/test.boa b/test/ml/decision-stump/test.boa new file mode 100644 index 000000000..79a07a9ba --- /dev/null +++ b/test/ml/decision-stump/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +ds: model of DecisionStump of {int, T, int, T}; +ds = load(0, ds); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << classify(ds, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/decision-stump/train.boa b/test/ml/decision-stump/train.boa new file mode 100644 index 000000000..e779b36cd --- /dev/null +++ b/test/ml/decision-stump/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; +p: Project = input; + +ds : output decisionstump("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + ds << {x1, x2, x3, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/decision-table/test.boa b/test/ml/decision-table/test.boa new file mode 100644 index 000000000..a5890772c --- /dev/null +++ b/test/ml/decision-table/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +dt: model of DecisionTable of {int, T, int, T}; +dt = load(0, dt); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << classify(dt, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/decision-table/train.boa b/test/ml/decision-table/train.boa new file mode 100644 index 000000000..c1e77eef1 --- /dev/null +++ b/test/ml/decision-table/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; +p: Project = input; + +dt : output decisiontable("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + dt << {x1, x2, x3, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/filtered-classifier/test.boa b/test/ml/filtered-classifier/test.boa new file mode 100644 index 000000000..fc35e82de --- /dev/null +++ b/test/ml/filtered-classifier/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +fc: model of DecisionTable of {int, T, int, T}; +fc = load(0, fc); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << classify(fc, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/filtered-classifier/train.boa b/test/ml/filtered-classifier/train.boa new file mode 100644 index 000000000..5339ba81b --- /dev/null +++ b/test/ml/filtered-classifier/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; +p: Project = input; + +fc : output filteredclassifier("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + fc << {x1, x2, x3, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/gaussian-processes/test.boa b/test/ml/gaussian-processes/test.boa new file mode 100644 index 000000000..ef13731ec --- /dev/null +++ b/test/ml/gaussian-processes/test.boa @@ -0,0 +1,9 @@ +p: Project = input; +predict: output collection of string; + +gp: model of GaussianProcesses of {int, int, int}; +gp = load(0, gp); + +x1 := 1; +x2 := 2; +predict << classify(gp, {x1, x2}); \ No newline at end of file diff --git a/test/ml/gaussian-processes/train.boa b/test/ml/gaussian-processes/train.boa new file mode 100644 index 000000000..acacc4991 --- /dev/null +++ b/test/ml/gaussian-processes/train.boa @@ -0,0 +1,12 @@ +p: Project = input; + +gp : output gaussianprocesses("-s 75") of {int, int, int}; +i := 0; +while(i < 100){ + x1 := 2 + 6 * i; + x2 := 3 + 5 * i; + y := 4 + 2 * i; + gp << { x1, x2, y }; + + i++; +} \ No newline at end of file diff --git a/test/ml/input-mapped-classifier/test.boa b/test/ml/input-mapped-classifier/test.boa new file mode 100644 index 000000000..4d3079760 --- /dev/null +++ b/test/ml/input-mapped-classifier/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +imc: model of InputMappedClassifier of {int, T, int, T}; +imc = load(0, imc); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << classify(imc, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/input-mapped-classifier/train.boa b/test/ml/input-mapped-classifier/train.boa new file mode 100644 index 000000000..449e233a1 --- /dev/null +++ b/test/ml/input-mapped-classifier/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; +p: Project = input; + +imc : output inputmappedclassifier("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + imc << {x1, x2, x3, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/j48/test.boa b/test/ml/j48/test.boa new file mode 100644 index 000000000..943a003c3 --- /dev/null +++ b/test/ml/j48/test.boa @@ -0,0 +1,8 @@ +type T = enum {y = "true", n = "false"}; +p: Project = input; +predict: output collection of string; +jm: model of J48 of {int, int, T}; +jm = load(0, jm); +x1 := 1; +x2 := 2; +predict << classify(jm, {x1, x2}); \ No newline at end of file diff --git a/test/ml/j48/train.boa b/test/ml/j48/train.boa new file mode 100644 index 000000000..a58ec0234 --- /dev/null +++ b/test/ml/j48/train.boa @@ -0,0 +1,19 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +jm: output j48("-s 75") of {int, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := 2 + 6 * i; + x2 := 3 + 5 * i; + + jm << {x1, x2, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/jrip/test.boa b/test/ml/jrip/test.boa new file mode 100644 index 000000000..20ccc0c9a --- /dev/null +++ b/test/ml/jrip/test.boa @@ -0,0 +1,8 @@ +type T = enum {y = "true", n = "false"}; +p: Project = input; +predict: output collection of string; +jr: model of JRip of {int, int, T}; +jr = load(0, jr); +x1 := 1; +x2 := 2; +predict << classify(jr, {x1, x2}); diff --git a/test/ml/jrip/train.boa b/test/ml/jrip/train.boa new file mode 100644 index 000000000..2723c3ee9 --- /dev/null +++ b/test/ml/jrip/train.boa @@ -0,0 +1,19 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +jr: output jrip("-s 75") of {int, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := 2 + 6 * i; + x2 := 3 + 5 * i; + + jr << {x1, x2, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/kmeans/test.boa b/test/ml/kmeans/test.boa new file mode 100644 index 000000000..8e4c135e5 --- /dev/null +++ b/test/ml/kmeans/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +kmeans: model of SimpleKMeans of {int, T, int, T}; +kmeans = load(0, kmeans); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << cluster(kmeans, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/kmeans/train.boa b/test/ml/kmeans/train.boa new file mode 100644 index 000000000..418e975cb --- /dev/null +++ b/test/ml/kmeans/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +kmeans: output simplekmeans("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + kmeans << {x1, x2, x3, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/kstar/test.boa b/test/ml/kstar/test.boa new file mode 100644 index 000000000..35acab7ef --- /dev/null +++ b/test/ml/kstar/test.boa @@ -0,0 +1,8 @@ +type T = enum {y = "true", n = "false"}; +p: Project = input; +predict: output collection of string; +ks: model of KStar of {int, int, T}; +ks = load(0, ks); +x1 := 1; +x2 := 2; +predict << classify(ks, {x1, x2}); \ No newline at end of file diff --git a/test/ml/kstar/train.boa b/test/ml/kstar/train.boa new file mode 100644 index 000000000..720214c83 --- /dev/null +++ b/test/ml/kstar/train.boa @@ -0,0 +1,19 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +ks: output kstar("-s 75") of {int, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := 2 + 6 * i; + x2 := 3 + 5 * i; + + ks << {x1, x2, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/linear-regression/test.boa b/test/ml/linear-regression/test.boa new file mode 100644 index 000000000..3f0cee8c9 --- /dev/null +++ b/test/ml/linear-regression/test.boa @@ -0,0 +1,9 @@ +p: Project = input; +predict: output collection of string; + +linear: model of LinearRegression of {int, int, int}; +linear = load(0, linear); + +x1 := 1; +x2 := 2; +predict << classify(linear, {x1, x2}); \ No newline at end of file diff --git a/test/ml/linear-regression/train.boa b/test/ml/linear-regression/train.boa new file mode 100644 index 000000000..1350ced2f --- /dev/null +++ b/test/ml/linear-regression/train.boa @@ -0,0 +1,12 @@ +p: Project = input; + +linear : output linearregression("-s 75") of {int, int, int}; +i := 0; +while(i < 100){ + x1 := 2 + 6 * i; + x2 := 3 + 5 * i; + y := 4 + 2 * i; + linear << { x1, x2, y }; + + i++; +} \ No newline at end of file diff --git a/test/ml/lmt/test.boa b/test/ml/lmt/test.boa new file mode 100644 index 000000000..d65f42e7f --- /dev/null +++ b/test/ml/lmt/test.boa @@ -0,0 +1,8 @@ +type T = enum {y = "true", n = "false"}; +p: Project = input; +predict: output collection of string; +lmtm: model of LMT of {int, int, T}; +lmtm = load(0, lmtm); +x1 := 1; +x2 := 2; +predict << classify(lmtm, {x1, x2}); \ No newline at end of file diff --git a/test/ml/lmt/train.boa b/test/ml/lmt/train.boa new file mode 100644 index 000000000..34f4e1e9b --- /dev/null +++ b/test/ml/lmt/train.boa @@ -0,0 +1,19 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +lmtm: output lmt("-s 75") of {int, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := 2 + 6 * i; + x2 := 3 + 5 * i; + + lmtm << {x1, x2, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/logistic/test.boa b/test/ml/logistic/test.boa new file mode 100644 index 000000000..744e39252 --- /dev/null +++ b/test/ml/logistic/test.boa @@ -0,0 +1,8 @@ +type T = enum {y = "true", n = "false"}; +p: Project = input; +predict: output collection of string; +lg: model of LogisticRegression of {int, int, T}; +lg = load(0, lg); +x1 := 1; +x2 := 2; +predict << classify(lg, {x1, x2}); \ No newline at end of file diff --git a/test/ml/logistic/train.boa b/test/ml/logistic/train.boa new file mode 100644 index 000000000..203ac543d --- /dev/null +++ b/test/ml/logistic/train.boa @@ -0,0 +1,19 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +lg: output logistic("-s 75") of {int, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := 2 + 6 * i; + x2 := 3 + 5 * i; + + lg << {x1, x2, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/logit-boost/test.boa b/test/ml/logit-boost/test.boa new file mode 100644 index 000000000..706f0b2a7 --- /dev/null +++ b/test/ml/logit-boost/test.boa @@ -0,0 +1,8 @@ +type T = enum {y = "true", n = "false"}; +p: Project = input; +predict: output collection of string; +lb: model of LogitBoost of {int, int, T}; +lb = load(0, lb); +x1 := 1; +x2 := 2; +predict << classify(lb, {x1, x2}); \ No newline at end of file diff --git a/test/ml/logit-boost/train.boa b/test/ml/logit-boost/train.boa new file mode 100644 index 000000000..6939e7cbf --- /dev/null +++ b/test/ml/logit-boost/train.boa @@ -0,0 +1,19 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +lb: output logitboost("-s 75") of {int, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := 2 + 6 * i; + x2 := 3 + 5 * i; + + lb << {x1, x2, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/lwl/test.boa b/test/ml/lwl/test.boa new file mode 100644 index 000000000..98dac2f26 --- /dev/null +++ b/test/ml/lwl/test.boa @@ -0,0 +1,8 @@ +type T = enum {y = "true", n = "false"}; +p: Project = input; +predict: output collection of string; +la: model of LWL of {int, int, T}; +la = load(0, la); +x1 := 1; +x2 := 2; +predict << classify(la, {x1, x2}); \ No newline at end of file diff --git a/test/ml/lwl/train.boa b/test/ml/lwl/train.boa new file mode 100644 index 000000000..78993b6c8 --- /dev/null +++ b/test/ml/lwl/train.boa @@ -0,0 +1,19 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +la: output lwl("-s 75") of {int, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := 2 + 6 * i; + x2 := 3 + 5 * i; + + la << {x1, x2, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/multi-class/test.boa b/test/ml/multi-class/test.boa new file mode 100644 index 000000000..55f41f643 --- /dev/null +++ b/test/ml/multi-class/test.boa @@ -0,0 +1,8 @@ +type T = enum {y = "true", n = "false"}; +p: Project = input; +predict: output collection of string; +mc: model of MultiClassClassifier of {int, int, T}; +mc = load(0, mc); +x1 := 1; +x2 := 2; +predict << classify(mc, {x1, x2}); \ No newline at end of file diff --git a/test/ml/multi-class/train.boa b/test/ml/multi-class/train.boa new file mode 100644 index 000000000..d730601f1 --- /dev/null +++ b/test/ml/multi-class/train.boa @@ -0,0 +1,19 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +mc: output multiclassclassifier("-s 75") of {int, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := 2 + 6 * i; + x2 := 3 + 5 * i; + + mc << {x1, x2, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/multi-scheme/test.boa b/test/ml/multi-scheme/test.boa new file mode 100644 index 000000000..539c8b092 --- /dev/null +++ b/test/ml/multi-scheme/test.boa @@ -0,0 +1,8 @@ +type T = enum {y = "true", n = "false"}; +p: Project = input; +predict: output collection of string; +ms: model of MultiScheme of {int, int, T}; +ms = load(0, ms); +x1 := 1; +x2 := 2; +predict << classify(ms, {x1, x2}); \ No newline at end of file diff --git a/test/ml/multi-scheme/train.boa b/test/ml/multi-scheme/train.boa new file mode 100644 index 000000000..cfa818ac0 --- /dev/null +++ b/test/ml/multi-scheme/train.boa @@ -0,0 +1,19 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +ms: output multischeme("-s 75") of {int, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := 2 + 6 * i; + x2 := 3 + 5 * i; + + ms << {x1, x2, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/multilayer-perceptron/test.boa b/test/ml/multilayer-perceptron/test.boa new file mode 100644 index 000000000..46ac9c939 --- /dev/null +++ b/test/ml/multilayer-perceptron/test.boa @@ -0,0 +1,8 @@ +type T = enum {y = "true", n = "false"}; +p: Project = input; +predict: output collection of string; +mp: model of MultilayerPerceptron of {int, int, T}; +mp = load(0, mp); +x1 := 1; +x2 := 2; +predict << classify(mp, {x1, x2}); \ No newline at end of file diff --git a/test/ml/multilayer-perceptron/train.boa b/test/ml/multilayer-perceptron/train.boa new file mode 100644 index 000000000..f408cca47 --- /dev/null +++ b/test/ml/multilayer-perceptron/train.boa @@ -0,0 +1,19 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +mp: output multilayerperceptron("-s 75") of {int, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := 2 + 6 * i; + x2 := 3 + 5 * i; + + mp << {x1, x2, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/naive-bayes-multinomial-updateable/test.boa b/test/ml/naive-bayes-multinomial-updateable/test.boa new file mode 100644 index 000000000..d6536cdc8 --- /dev/null +++ b/test/ml/naive-bayes-multinomial-updateable/test.boa @@ -0,0 +1,8 @@ +type T = enum {y = "true", n = "false"}; +p: Project = input; +predict: output collection of string; +nbmu: model of NaiveBayesMultinomialUpdateable of {int, int, T}; +nbmu = load(0, nbmu); +x1 := 1; +x2 := 2; +predict << classify(nbmu, {x1, x2}); \ No newline at end of file diff --git a/test/ml/naive-bayes-multinomial-updateable/train.boa b/test/ml/naive-bayes-multinomial-updateable/train.boa new file mode 100644 index 000000000..7484d5ad6 --- /dev/null +++ b/test/ml/naive-bayes-multinomial-updateable/train.boa @@ -0,0 +1,19 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +nbmu: output naivebayesmultinomialupdateable("-s 75") of {int, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := 2 + 6 * i; + x2 := 3 + 5 * i; + + nbmu << {x1, x2, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/naive-bayes/test.boa b/test/ml/naive-bayes/test.boa new file mode 100644 index 000000000..ebdfd08fb --- /dev/null +++ b/test/ml/naive-bayes/test.boa @@ -0,0 +1,8 @@ +type T = enum {y = "true", n = "false"}; +p: Project = input; +predict: output collection of string; +nb: model of NaiveBayes of {int, int, T}; +nb = load(0, nb); +x1 := 1; +x2 := 2; +predict << classify(nb, {x1, x2}); \ No newline at end of file diff --git a/test/ml/naive-bayes/train.boa b/test/ml/naive-bayes/train.boa new file mode 100644 index 000000000..d99cfe04a --- /dev/null +++ b/test/ml/naive-bayes/train.boa @@ -0,0 +1,19 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +nb: output naivebayes("-s 75") of {int, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := 2 + 6 * i; + x2 := 3 + 5 * i; + + nb << {x1, x2, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/oner/test.boa b/test/ml/oner/test.boa new file mode 100644 index 000000000..0c2262853 --- /dev/null +++ b/test/ml/oner/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +oa: model of OneR of {int, T, int, T}; +oa = load(0, oa); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << classify(oa, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/oner/train.boa b/test/ml/oner/train.boa new file mode 100644 index 000000000..64c70beb7 --- /dev/null +++ b/test/ml/oner/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +oa: output oner("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + oa << {x1, x2, x3, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/part/test.boa b/test/ml/part/test.boa new file mode 100644 index 000000000..d484c1b69 --- /dev/null +++ b/test/ml/part/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +prt: model of PART of {int, T, int, T}; +prt = load(0, prt); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << classify(prt, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/part/train.boa b/test/ml/part/train.boa new file mode 100644 index 000000000..69c94ef78 --- /dev/null +++ b/test/ml/part/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +prt: output part("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + prt << {x1, x2, x3, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/random-forest/test.boa b/test/ml/random-forest/test.boa new file mode 100644 index 000000000..50f6e845b --- /dev/null +++ b/test/ml/random-forest/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +rf: model of RandomForest of {int, T, int, T}; +rf = load(0, rf); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << classify(rf, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/random-forest/train.boa b/test/ml/random-forest/train.boa new file mode 100644 index 000000000..12efb93d0 --- /dev/null +++ b/test/ml/random-forest/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +rf: output randomforest("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + rf << {x1, x2, x3, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/seq2vec/test.boa b/test/ml/seq2vec/test.boa new file mode 100644 index 000000000..bc44d89ba --- /dev/null +++ b/test/ml/seq2vec/test.boa @@ -0,0 +1,22 @@ +p: Project = input; +predict: output collection of string; +s2v: model of Seq2Vec of { string }; +s2v = load(0, s2v); + +# nearest words +words1: array of string = nearest(s2v, "king", 10); + +# cosine similarity +val: float = sim(s2v, "c", "c"); + +# arithmetic of words: king - queen + woman = man +words2: array of string = arith(s2v, "king - queen + woman", 10); + +# word vector +vec1: array of float = vector(s2v, "king"); + +# sequence vector +seq := {"c", "c", "c", "c"}; +vec2: array of float = vector(s2v, seq); + +predict << string(val); \ No newline at end of file diff --git a/test/ml/seq2vec/train.boa b/test/ml/seq2vec/train.boa new file mode 100644 index 000000000..e679752b2 --- /dev/null +++ b/test/ml/seq2vec/train.boa @@ -0,0 +1,8 @@ +p: Project = input; +s2v: output seq2vec("-f 2") of {string}; + +visit(p, visitor { + before r : Revision -> { + s2v << { r.log }; + } +}); diff --git a/test/ml/vote/test.boa b/test/ml/vote/test.boa new file mode 100644 index 000000000..110543c8a --- /dev/null +++ b/test/ml/vote/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +v: model of Vote of {int, T, int, T}; +v = load(0, v); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << classify(v, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/vote/train.boa b/test/ml/vote/train.boa new file mode 100644 index 000000000..ae6c53f43 --- /dev/null +++ b/test/ml/vote/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +v: output vote("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + v << {x1, x2, x3, label}; + i++; +} \ No newline at end of file diff --git a/test/ml/word2vec/test.boa b/test/ml/word2vec/test.boa new file mode 100644 index 000000000..0db7ae3f8 --- /dev/null +++ b/test/ml/word2vec/test.boa @@ -0,0 +1,18 @@ +p: Project = input; +predict: output collection of string; +w2v: model of Word2Vec of { string }; +w2v = load(0, w2v); + +# nearest words +words1: array of string = nearest(w2v, "king", 10); + +# cosine similarity +val: float = sim(w2v, "c", "c"); + +# arithmetic of words: king - queen + woman = man +words2: array of string = arith(w2v, "king - queen + woman", 10); + +# word vector +vec: array of float = vector(w2v, "king"); + +predict << string(val); \ No newline at end of file diff --git a/test/ml/word2vec/train.boa b/test/ml/word2vec/train.boa new file mode 100644 index 000000000..0492da760 --- /dev/null +++ b/test/ml/word2vec/train.boa @@ -0,0 +1,8 @@ +p: Project = input; +w2v: output word2vec("-f 2 -ls 100 -ws 5 -stop") of {string}; + +visit(p, visitor { + before r : Revision -> { + w2v << { r.log }; + } +}); \ No newline at end of file diff --git a/test/ml/zeror/test.boa b/test/ml/zeror/test.boa new file mode 100644 index 000000000..e5fef5c25 --- /dev/null +++ b/test/ml/zeror/test.boa @@ -0,0 +1,13 @@ +type T = enum {y = "true", n = "false"}; + +p: Project = input; +predict: output collection of string; + +zr: model of ZeroR of {int, T, int, T}; +zr = load(0, zr); + +x1 := 1; +x2: T = T.n; +x3 := 2; + +predict << classify(zr, {x1, x2, x3}); \ No newline at end of file diff --git a/test/ml/zeror/train.boa b/test/ml/zeror/train.boa new file mode 100644 index 000000000..153afee04 --- /dev/null +++ b/test/ml/zeror/train.boa @@ -0,0 +1,20 @@ +type T = enum {y = "true", n = "false"}; +label: T; + +p: Project = input; +zr: output zeror("-s 75") of {int, T, int, T}; + +i := 0; +while(i < 100){ + + label = T.y; + if (i % 2 == 0) + label = T.n; + + x1 := i + 7; + x2: T = T.n; + x3 := i; + + zr << {x1, x2, x3, label}; + i++; +} \ No newline at end of file