[GitHub] [ignite] zaleslaw commented on a change in pull request #6964: IGNITE-12279: [ML] Added support for using H2O MOJO for model inference

2019-10-30 Thread GitBox
zaleslaw commented on a change in pull request #6964: IGNITE-12279: [ML] Added 
support for using H2O MOJO for model inference
URL: https://github.com/apache/ignite/pull/6964#discussion_r340514389
 
 

 ##
 File path: 
modules/ml/h2o-model-parser/src/main/java/org/apache/ignite/ml/h2o/H2OMojoModelParser.java
 ##
 @@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.ignite.ml.h2o;
+
+import java.io.*;
+
+import hex.genmodel.CategoricalEncoding;
+import hex.genmodel.MojoModel;
+import hex.genmodel.MojoReaderBackend;
+import hex.genmodel.MojoReaderBackendFactory;
+import hex.genmodel.easy.EasyPredictModelWrapper;
+import org.apache.ignite.ml.inference.parser.ModelParser;
+import org.apache.ignite.ml.math.primitives.vector.NamedVector;
+
+/**
+ * H2O MOJO model parser.
+ */
+public class H2OMojoModelParser implements ModelParser {
+/** */
+private static final long serialVersionUID = -170352744966205716L;
+
+
+/** {@inheritDoc} */
+@Override public H2OMojoModel parse(byte[] mojoBytes) {
+try (InputStream mojoInputStream = new 
ByteArrayInputStream(mojoBytes)) {
+MojoReaderBackend readerBackend = 
MojoReaderBackendFactory.createReaderBackend(mojoInputStream,
+MojoReaderBackendFactory.CachingStrategy.MEMORY);
+MojoModel mojoModel = MojoModel.load(readerBackend);
+validateMojoModel(mojoModel);
+// we expect categorical values to be already encoded
+EasyPredictModelWrapper.Config config = new 
EasyPredictModelWrapper.Config()
+.setUseExternalEncoding(true)
+.setConvertInvalidNumbersToNa(true)
+.setConvertUnknownCategoricalLevelsToNa(true)
+.setModel(mojoModel);
+EasyPredictModelWrapper easyPredict = new 
EasyPredictModelWrapper(config);
+return new H2OMojoModel(easyPredict);
+} catch (IOException e) {
+throw new RuntimeException("Failed to parse MOJO", e);
+}
+}
+
+private void validateMojoModel(MojoModel mojoModel) {
+switch (mojoModel.getModelCategory()) {
+case Binomial:
+case Multinomial:
+case Ordinal:
+case Regression:
+case Clustering:
+break; // ok - supported
+default:
+throw new UnsupportedOperationException("Model Category " + 
mojoModel.getModelCategory() + " is not supported yet.");
+}
+if (mojoModel.getCategoricalEncoding() == 
CategoricalEncoding.OneHotExplicit) {
+return;
+}
+for (int i = 0; i < mojoModel.nfeatures(); i++) {
+if (mojoModel.getDomainValues(i) != null) {
+String columnName = mojoModel.getNames()[i];
+throw new UnsupportedOperationException("Unsupported MOJO 
model: only models using trained using " +
+"OneHotExplicit categorical encoding and models 
without categorical features are currently supported. " +
+"Column `" + columnName + "` is categorical.");
+}
+}
+}
+
 
 Review comment:
   Remove empty line


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [ignite] zaleslaw commented on a change in pull request #6964: IGNITE-12279: [ML] Added support for using H2O MOJO for model inference

2019-10-30 Thread GitBox
zaleslaw commented on a change in pull request #6964: IGNITE-12279: [ML] Added 
support for using H2O MOJO for model inference
URL: https://github.com/apache/ignite/pull/6964#discussion_r340514279
 
 

 ##
 File path: 
modules/ml/h2o-model-parser/src/main/java/org/apache/ignite/ml/h2o/H2OMojoModelParser.java
 ##
 @@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.ignite.ml.h2o;
+
+import java.io.*;
+
+import hex.genmodel.CategoricalEncoding;
+import hex.genmodel.MojoModel;
+import hex.genmodel.MojoReaderBackend;
+import hex.genmodel.MojoReaderBackendFactory;
+import hex.genmodel.easy.EasyPredictModelWrapper;
+import org.apache.ignite.ml.inference.parser.ModelParser;
+import org.apache.ignite.ml.math.primitives.vector.NamedVector;
+
+/**
+ * H2O MOJO model parser.
+ */
+public class H2OMojoModelParser implements ModelParser {
+/** */
+private static final long serialVersionUID = -170352744966205716L;
+
 
 Review comment:
   Remove empty line


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [ignite] zaleslaw commented on a change in pull request #6964: IGNITE-12279: [ML] Added support for using H2O MOJO for model inference

2019-10-30 Thread GitBox
zaleslaw commented on a change in pull request #6964: IGNITE-12279: [ML] Added 
support for using H2O MOJO for model inference
URL: https://github.com/apache/ignite/pull/6964#discussion_r340514645
 
 

 ##
 File path: 
examples/src/main/java/org/apache/ignite/examples/ml/inference/h2o/H2OMojoModelParserExample.java
 ##
 @@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.ignite.examples.ml.inference.h2o;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.ml.inference.Model;
+import org.apache.ignite.ml.inference.builder.AsyncModelBuilder;
+import org.apache.ignite.ml.inference.builder.IgniteDistributedModelBuilder;
+import org.apache.ignite.ml.inference.reader.FileSystemModelReader;
+import org.apache.ignite.ml.inference.reader.ModelReader;
+import org.apache.ignite.ml.math.primitives.vector.NamedVector;
+import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
+import org.apache.ignite.ml.h2o.H2OMojoModelParser;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.HashMap;
+import java.util.Scanner;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+/**
+ * This example demonstrates how to import H2O MOJO model and use imported 
model for distributed inference in Apache
+ * Ignite.
+ */
+public class H2OMojoModelParserExample {
+/**
+ * Test model resource name.
+ */
+private static final String MODEL_RES = 
"examples/src/main/resources/models/h2o/agaricus-gbm-mojo.zip";
+
+/**
+ * Test data.
+ */
+private static final String DATA_RES = 
"examples/src/main/resources/datasets/agaricus-test-data.txt";
+
 
 Review comment:
   Remove empty line


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [ignite] zaleslaw commented on a change in pull request #6964: IGNITE-12279: [ML] Added support for using H2O MOJO for model inference

2019-10-30 Thread GitBox
zaleslaw commented on a change in pull request #6964: IGNITE-12279: [ML] Added 
support for using H2O MOJO for model inference
URL: https://github.com/apache/ignite/pull/6964#discussion_r340515612
 
 

 ##
 File path: 
examples/src/main/java/org/apache/ignite/examples/ml/inference/h2o/H2OMojoModelParserExample.java
 ##
 @@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.ignite.examples.ml.inference.h2o;
+
+import org.apache.ignite.Ignite;
 
 Review comment:
   Reorder imports, please, java imports should be first, after that should be 
added ignite imports like below, for exxample, also all unused imports should 
be removed
   
   import java.io.IOException;
   import java.io.ObjectInput;
   import java.io.ObjectOutput;
   import java.util.Arrays;
   import java.util.HashMap;
   import java.util.Map;
   import java.util.Random;
   import java.util.Spliterator;
   import java.util.function.Consumer;
   import org.apache.ignite.lang.IgniteUuid;
   import org.apache.ignite.ml.math.Blas;
   import org.apache.ignite.ml.math.exceptions.math.CardinalityException;
   import org.apache.ignite.ml.math.exceptions.math.ColumnIndexException;
   import org.apache.ignite.ml.math.exceptions.math.RowIndexException;
   import org.apache.ignite.ml.math.functions.Functions;
   import org.apache.ignite.ml.math.functions.IgniteBiFunction;
   import org.apache.ignite.ml.math.functions.IgniteDoubleFunction;
   import org.apache.ignite.ml.math.functions.IgniteFunction;
   import org.apache.ignite.ml.math.functions.IgniteTriFunction;
   import org.apache.ignite.ml.math.functions.IntIntToDoubleFunction;
   import org.apache.ignite.ml.math.primitives.vector.Vector;
   import org.apache.ignite.ml.math.primitives.vector.impl.DenseVector;
   import org.apache.ignite.ml.math.primitives.vector.impl.VectorizedViewMatrix;


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [ignite] zaleslaw commented on a change in pull request #6964: IGNITE-12279: [ML] Added support for using H2O MOJO for model inference

2019-10-17 Thread GitBox
zaleslaw commented on a change in pull request #6964: IGNITE-12279: [ML] Added 
support for using H2O MOJO for model inference
URL: https://github.com/apache/ignite/pull/6964#discussion_r335930534
 
 

 ##
 File path: modules/ml/h2o-model-parser/pom.xml
 ##
 @@ -0,0 +1,75 @@
+
+
+
+
+http://maven.apache.org/POM/4.0.0;
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd;>
+4.0.0
+
+
+ignite-parent
+org.apache.ignite
+1
+../../../parent
+
+
+ignite-ml-h2o-model-parser
+2.8.0-SNAPSHOT
+http://ignite.apache.org
+
+
+
+
+maven-dependency-plugin
+
+
+copy-libs
+package
+
+copy-dependencies
+
+
+false
+
+
fastutil,h2,ignite-shmem,annotations,arpack_combined_all,
+
cache-api,commons-math3,commons-rng-client-api,commons-rng-core,
+commons-rng-simple,core,ignite-ml
+
+
+
+
+
+
+
+
+
+
+org.apache.ignite
+ignite-ml
+${project.version}
+
+
+ai.h2o
+h2o-genmodel
+3.26.0.6
 
 Review comment:
   Please, define as separate property at the start of the file.
   have a look at the ignite-ml-tensorflow-ml-parser with 
   
   
   1.12.0
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [ignite] zaleslaw commented on a change in pull request #6964: IGNITE-12279: [ML] Added support for using H2O MOJO for model inference

2019-10-17 Thread GitBox
zaleslaw commented on a change in pull request #6964: IGNITE-12279: [ML] Added 
support for using H2O MOJO for model inference
URL: https://github.com/apache/ignite/pull/6964#discussion_r335927864
 
 

 ##
 File path: 
examples/src/main/java/org/apache/ignite/examples/ml/h2o/H2OMojoModelParserExample.java
 ##
 @@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.ignite.examples.ml.h2o;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.ml.inference.Model;
+import org.apache.ignite.ml.inference.builder.AsyncModelBuilder;
+import org.apache.ignite.ml.inference.builder.IgniteDistributedModelBuilder;
+import org.apache.ignite.ml.inference.reader.FileSystemModelReader;
+import org.apache.ignite.ml.inference.reader.ModelReader;
+import org.apache.ignite.ml.math.primitives.vector.NamedVector;
+import org.apache.ignite.ml.math.primitives.vector.VectorUtils;
+import org.apache.ignite.ml.h2o.H2OMojoModelParser;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.HashMap;
+import java.util.Scanner;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+
+/**
+ * This example demonstrates how to import H2O MOJO model and use imported 
model for distributed inference in Apache
+ * Ignite.
+ */
+public class H2OMojoModelParserExample {
 
 Review comment:
   Please, move this to the ml/inference/h2o folder


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services