You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by to...@apache.org on 2012/07/30 14:59:41 UTC

svn commit: r1367074 - /labs/yay/trunk/core/src/main/java/org/apache/yay/utils/ExamplesFactory.java

Author: tommaso
Date: Mon Jul 30 12:59:41 2012
New Revision: 1367074

URL: http://svn.apache.org/viewvc?rev=1367074&view=rev
Log:
adding ExamplesFactory

Added:
    labs/yay/trunk/core/src/main/java/org/apache/yay/utils/ExamplesFactory.java

Added: labs/yay/trunk/core/src/main/java/org/apache/yay/utils/ExamplesFactory.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/utils/ExamplesFactory.java?rev=1367074&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/utils/ExamplesFactory.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/utils/ExamplesFactory.java Mon Jul 30 12:59:41 2012
@@ -0,0 +1,69 @@
+/*
+ * 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.yay.utils;
+
+import java.util.Vector;
+
+import org.apache.yay.Example;
+import org.apache.yay.Feature;
+import org.apache.yay.TrainingExample;
+
+/**
+ * Factory class for {@link Example}s
+ */
+public class ExamplesFactory {
+
+    public static TrainingExample<Double, Double> createDoubleTrainingExample(final Double output, final Double... featuresValues) {
+        return new TrainingExample<Double, Double>() {
+            @Override
+            public Vector<Feature<Double>> getFeatureVector() {
+                return doublesToFeatureVector(featuresValues);
+            }
+
+            @Override
+            public Double getOutput() {
+                return output;
+            }
+        };
+    }
+
+    public static Example<Double> createDoubleExample(final Double... featuresValues) {
+        return new Example<Double>() {
+            @Override
+            public Vector<Feature<Double>> getFeatureVector() {
+                return doublesToFeatureVector(featuresValues);
+            }
+        };
+    }
+
+    private static Vector<Feature<Double>> doublesToFeatureVector(Double[] featuresValues) {
+        Vector<Feature<Double>> features = new Vector<Feature<Double>>();
+        Feature<Double> byasFeature = new Feature<Double>();
+        byasFeature.setValue(1d);
+        features.add(byasFeature);
+        for (Double d : featuresValues) {
+            Feature<Double> feature = new Feature<Double>();
+            feature.setValue(d);
+            features.add(feature);
+        }
+        return features;
+    }
+
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org