<NME> SDRClassifierSerializer.java
<BEF> ADDFILE
<MSG> Added SDRClassifierSerializer class

<DFF> @@ -0,0 +1,87 @@
+/* ---------------------------------------------------------------------
+ * Numenta Platform for Intelligent Computing (NuPIC)
+ * Copyright (C) 2014, Numenta, Inc.  Unless you have an agreement
+ * with Numenta, Inc., for a separate license for this software code, the
+ * following terms and conditions apply:
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU Affero Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero Public License
+ * along with this program.  If not, see http://www.gnu.org/licenses.
+ *
+ * http://numenta.org/licenses/
+ * ---------------------------------------------------------------------
+ */
+
+package org.numenta.nupic.algorithms;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import no.uib.cipr.matrix.Matrices;
+import no.uib.cipr.matrix.sparse.FlexCompRowMatrix;
+import org.numenta.nupic.util.Tuple;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Map;
+
+public class SDRClassifierSerializer extends JsonSerializer<SDRClassifier> {
+
+    @Override
+    public void serialize(SDRClassifier sdrc, JsonGenerator jgen, SerializerProvider serializerProvider)
+            throws IOException, JsonProcessingException {
+
+        jgen.writeStartObject();
+        jgen.writeNumberField("alpha", sdrc.alpha);
+        jgen.writeNumberField("actValueAlpha", sdrc.actValueAlpha);
+        jgen.writeNumberField("learnIteration", sdrc.learnIteration);
+        jgen.writeNumberField("recordNumMinusLearnIteration", sdrc.recordNumMinusLearnIteration);
+        jgen.writeNumberField("maxInputIdx", sdrc.maxInputIdx);
+        jgen.writeNumberField("maxBucketIdx", sdrc.maxBucketIdx);
+
+        StringBuilder sb = new StringBuilder();
+        for(int i : sdrc.steps.toArray()) {
+            sb.append(i).append(",");
+        }
+        sb.setLength(sb.length() - 1);
+        jgen.writeStringField("steps", sb.toString());
+
+        sb = new StringBuilder();
+        for(Tuple t : sdrc.patternNZHistory) {
+            sb.append(t.get(0)).append("-").append(Arrays.toString((int[])t.get(1))).append(";");
+        }
+        sb.setLength(sb.length() - 1);
+        jgen.writeStringField("patternNZHistory", sb.toString());
+
+        sb = new StringBuilder();
+        for(Map.Entry<Integer, FlexCompRowMatrix> entry : sdrc.weightMatrix.entrySet()) {
+            sb.append(entry.getKey()).append("-");
+            double[][] matrix = Matrices.getArray(entry.getValue());
+            jgen.writeStartArray();
+            for(int row = 0; row < matrix.length; row++) {
+                sb.append(Arrays.toString(matrix[row])).append(", ");
+            }
+            sb.setLength(sb.length() - 2);
+            jgen.writeEndArray();
+            sb.append(";");
+        }
+        sb.setLength(sb.length() - 1);
+        jgen.writeStringField("weightMatrix", sb.toString());
+
+        jgen.writeArrayFieldStart("actualValues");
+        for(Object o : sdrc.actualValues) {
+            jgen.writeObject(o);
+        }
+        jgen.writeEndArray();
+        jgen.writeEndObject();
+    }
+}

{'commit': 'diff --git a/src/main/java/org/numenta/nupic/algorithms/SDRClassifierSerializer.java b/src/main/java/org/numenta/nupic/algorithms/SDRClassifierSerializer.java\nnew file mode 100644\nindex 00000000..06b4c564\n--- /dev/null\n+++ b/src/main/java/org/numenta/nupic/algorithms/SDRClassifierSerializer.java\n@@ -0,0 +1,87 @@\n+/* ---------------------------------------------------------------------\n+ * Numenta Platform for Intelligent Computing (NuPIC)\n+ * Copyright (C) 2014, Numenta, Inc.  Unless you have an agreement\n+ * with Numenta, Inc., for a separate license for this software code, the\n+ * following terms and conditions apply:\n+ *\n+ * This program is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU Affero Public License version 3 as\n+ * published by the Free Software Foundation.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n+ * See the GNU Affero Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Affero Public License\n+ * along with this program.  If not, see http://www.gnu.org/licenses.\n+ *\n+ * http://numenta.org/licenses/\n+ * ---------------------------------------------------------------------\n+ */\n+\n+package org.numenta.nupic.algorithms;\n+\n+import com.fasterxml.jackson.core.JsonGenerator;\n+import com.fasterxml.jackson.core.JsonProcessingException;\n+import com.fasterxml.jackson.databind.JsonSerializer;\n+import com.fasterxml.jackson.databind.SerializerProvider;\n+import no.uib.cipr.matrix.Matrices;\n+import no.uib.cipr.matrix.sparse.FlexCompRowMatrix;\n+import org.numenta.nupic.util.Tuple;\n+\n+import java.io.IOException;\n+import java.util.Arrays;\n+import java.util.Map;\n+\n+public class SDRClassifierSerializer extends JsonSerializer<SDRClassifier> {\n+\n+    @Override\n+    public void serialize(SDRClassifier sdrc, JsonGenerator jgen, SerializerProvider serializerProvider)\n+            throws IOException, JsonProcessingException {\n+\n+        jgen.writeStartObject();\n+        jgen.writeNumberField("alpha", sdrc.alpha);\n+        jgen.writeNumberField("actValueAlpha", sdrc.actValueAlpha);\n+        jgen.writeNumberField("learnIteration", sdrc.learnIteration);\n+        jgen.writeNumberField("recordNumMinusLearnIteration", sdrc.recordNumMinusLearnIteration);\n+        jgen.writeNumberField("maxInputIdx", sdrc.maxInputIdx);\n+        jgen.writeNumberField("maxBucketIdx", sdrc.maxBucketIdx);\n+\n+        StringBuilder sb = new StringBuilder();\n+        for(int i : sdrc.steps.toArray()) {\n+            sb.append(i).append(",");\n+        }\n+        sb.setLength(sb.length() - 1);\n+        jgen.writeStringField("steps", sb.toString());\n+\n+        sb = new StringBuilder();\n+        for(Tuple t : sdrc.patternNZHistory) {\n+            sb.append(t.get(0)).append("-").append(Arrays.toString((int[])t.get(1))).append(";");\n+        }\n+        sb.setLength(sb.length() - 1);\n+        jgen.writeStringField("patternNZHistory", sb.toString());\n+\n+        sb = new StringBuilder();\n+        for(Map.Entry<Integer, FlexCompRowMatrix> entry : sdrc.weightMatrix.entrySet()) {\n+            sb.append(entry.getKey()).append("-");\n+            double[][] matrix = Matrices.getArray(entry.getValue());\n+            jgen.writeStartArray();\n+            for(int row = 0; row < matrix.length; row++) {\n+                sb.append(Arrays.toString(matrix[row])).append(", ");\n+            }\n+            sb.setLength(sb.length() - 2);\n+            jgen.writeEndArray();\n+            sb.append(";");\n+        }\n+        sb.setLength(sb.length() - 1);\n+        jgen.writeStringField("weightMatrix", sb.toString());\n+\n+        jgen.writeArrayFieldStart("actualValues");\n+        for(Object o : sdrc.actualValues) {\n+            jgen.writeObject(o);\n+        }\n+        jgen.writeEndArray();\n+        jgen.writeEndObject();\n+    }\n+}\n', 'commit_subject': 'Added SDRClassifierSerializer class', 'repo_name': 'numenta/htm.java', 'committer': {'name': 'Andrew Dillon', 'email': '01fc0d9a2660b55ecb49d84714fb3e394c066455@gmail.com', 'time_sec': '1468694177', 'tz_offset': '-300', 'date': {'seconds': '1468694177'}}, 'commit_tree': '212e301c81d7a963ee222a79b59220114847121f', 'commit_message': 'Added SDRClassifierSerializer class\n', 'language_name': 'Shell', 'license': 'agpl-3.0', 'hunks': '@@ -0,0 +1,87 @@\n+/* ---------------------------------------------------------------------\n+ * Numenta Platform for Intelligent Computing (NuPIC)\n+ * Copyright (C) 2014, Numenta, Inc.  Unless you have an agreement\n+ * with Numenta, Inc., for a separate license for this software code, the\n+ * following terms and conditions apply:\n+ *\n+ * This program is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU Affero Public License version 3 as\n+ * published by the Free Software Foundation.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n+ * See the GNU Affero Public License for more details.\n+ *\n+ * You should have received a copy of the GNU Affero Public License\n+ * along with this program.  If not, see http://www.gnu.org/licenses.\n+ *\n+ * http://numenta.org/licenses/\n+ * ---------------------------------------------------------------------\n+ */\n+\n+package org.numenta.nupic.algorithms;\n+\n+import com.fasterxml.jackson.core.JsonGenerator;\n+import com.fasterxml.jackson.core.JsonProcessingException;\n+import com.fasterxml.jackson.databind.JsonSerializer;\n+import com.fasterxml.jackson.databind.SerializerProvider;\n+import no.uib.cipr.matrix.Matrices;\n+import no.uib.cipr.matrix.sparse.FlexCompRowMatrix;\n+import org.numenta.nupic.util.Tuple;\n+\n+import java.io.IOException;\n+import java.util.Arrays;\n+import java.util.Map;\n+\n+public class SDRClassifierSerializer extends JsonSerializer<SDRClassifier> {\n+\n+    @Override\n+    public void serialize(SDRClassifier sdrc, JsonGenerator jgen, SerializerProvider serializerProvider)\n+            throws IOException, JsonProcessingException {\n+\n+        jgen.writeStartObject();\n+        jgen.writeNumberField("alpha", sdrc.alpha);\n+        jgen.writeNumberField("actValueAlpha", sdrc.actValueAlpha);\n+        jgen.writeNumberField("learnIteration", sdrc.learnIteration);\n+        jgen.writeNumberField("recordNumMinusLearnIteration", sdrc.recordNumMinusLearnIteration);\n+        jgen.writeNumberField("maxInputIdx", sdrc.maxInputIdx);\n+        jgen.writeNumberField("maxBucketIdx", sdrc.maxBucketIdx);\n+\n+        StringBuilder sb = new StringBuilder();\n+        for(int i : sdrc.steps.toArray()) {\n+            sb.append(i).append(",");\n+        }\n+        sb.setLength(sb.length() - 1);\n+        jgen.writeStringField("steps", sb.toString());\n+\n+        sb = new StringBuilder();\n+        for(Tuple t : sdrc.patternNZHistory) {\n+            sb.append(t.get(0)).append("-").append(Arrays.toString((int[])t.get(1))).append(";");\n+        }\n+        sb.setLength(sb.length() - 1);\n+        jgen.writeStringField("patternNZHistory", sb.toString());\n+\n+        sb = new StringBuilder();\n+        for(Map.Entry<Integer, FlexCompRowMatrix> entry : sdrc.weightMatrix.entrySet()) {\n+            sb.append(entry.getKey()).append("-");\n+            double[][] matrix = Matrices.getArray(entry.getValue());\n+            jgen.writeStartArray();\n+            for(int row = 0; row < matrix.length; row++) {\n+                sb.append(Arrays.toString(matrix[row])).append(", ");\n+            }\n+            sb.setLength(sb.length() - 2);\n+            jgen.writeEndArray();\n+            sb.append(";");\n+        }\n+        sb.setLength(sb.length() - 1);\n+        jgen.writeStringField("weightMatrix", sb.toString());\n+\n+        jgen.writeArrayFieldStart("actualValues");\n+        for(Object o : sdrc.actualValues) {\n+            jgen.writeObject(o);\n+        }\n+        jgen.writeEndArray();\n+        jgen.writeEndObject();\n+    }\n+}\n', 'addition_count': 87, 'deletion_count': 0, 'src_file': '/dev/null', 'tgt_file': 'b/src/main/java/org/numenta/nupic/algorithms/SDRClassifierSerializer.java', 'file_extension': '.java', 'before_file': 'ADDFILE', 'message': 'Added SDRClassifierSerializer class\n', 'author_name': 'Andrew Dillon', 'lang': 'java'}