|
22 | 22 |
|
23 | 23 | package org.numenta.nupic.algorithms;
|
24 | 24 |
|
25 |
| -import gnu.trove.iterator.TDoubleIterator; |
26 |
| -import gnu.trove.list.TDoubleList; |
27 |
| -import gnu.trove.list.array.TDoubleArrayList; |
28 |
| -import gnu.trove.map.TObjectDoubleMap; |
29 |
| - |
30 |
| -import java.io.IOException; |
31 |
| -import java.io.StringWriter; |
32 | 25 | import java.util.ArrayList;
|
33 | 26 | import java.util.Arrays;
|
34 | 27 | import java.util.List;
|
|
40 | 33 | import org.slf4j.Logger;
|
41 | 34 | import org.slf4j.LoggerFactory;
|
42 | 35 |
|
43 |
| -import com.fasterxml.jackson.core.JsonFactory; |
44 |
| -import com.fasterxml.jackson.core.JsonGenerator; |
45 |
| -import com.fasterxml.jackson.core.JsonProcessingException; |
46 |
| -import com.fasterxml.jackson.databind.ObjectMapper; |
47 |
| -import com.fasterxml.jackson.databind.SerializationFeature; |
48 |
| -import com.fasterxml.jackson.databind.node.ArrayNode; |
49 |
| -import com.fasterxml.jackson.databind.node.JsonNodeFactory; |
50 |
| -import com.fasterxml.jackson.databind.node.ObjectNode; |
| 36 | +import gnu.trove.list.TDoubleList; |
| 37 | +import gnu.trove.list.array.TDoubleArrayList; |
| 38 | +import gnu.trove.map.TObjectDoubleMap; |
51 | 39 |
|
52 | 40 | /**
|
53 | 41 | * <p>The anomaly likelihood computer.</p>
|
@@ -607,9 +595,6 @@ public boolean isValidEstimatorParams(NamedTuple params) {
|
607 | 595 | public static class AnomalyParams extends NamedTuple {
|
608 | 596 | private static final long serialVersionUID = 1L;
|
609 | 597 |
|
610 |
| - /** Cached Json formatting. Possible because Objects of this class are immutable */ |
611 |
| - private ObjectNode cachedNode; |
612 |
| - |
613 | 598 | private final Statistic distribution;
|
614 | 599 | private final MovingAverage movingAverage;
|
615 | 600 | private final double[] historicalLikelihoods;
|
@@ -666,90 +651,6 @@ public int windowSize() {
|
666 | 651 | return windowSize;
|
667 | 652 | }
|
668 | 653 |
|
669 |
| - /** |
670 |
| - * Lazily creates and returns a JSON ObjectNode containing this {@code AnomalyParams}' data. |
671 |
| - * |
672 |
| - * @param factory |
673 |
| - * @return |
674 |
| - */ |
675 |
| - public ObjectNode toJsonNode(JsonNodeFactory factory) { |
676 |
| - if(cachedNode == null) { |
677 |
| - ObjectNode distribution = factory.objectNode(); |
678 |
| - distribution.put(KEY_MEAN, this.distribution.mean); |
679 |
| - distribution.put(KEY_VARIANCE, this.distribution.variance); |
680 |
| - distribution.put(KEY_STDEV, this.distribution.stdev); |
681 |
| - |
682 |
| - double[] historicalLikelihoods = (double[])get(KEY_HIST_LIKE); |
683 |
| - ArrayNode historics = factory.arrayNode(); |
684 |
| - for(double d : historicalLikelihoods) { |
685 |
| - historics.add(d); |
686 |
| - } |
687 |
| - |
688 |
| - ObjectNode mvgAvg = factory.objectNode(); |
689 |
| - mvgAvg.put(KEY_WINDOW_SIZE, windowSize); |
690 |
| - |
691 |
| - ArrayNode histVals = factory.arrayNode(); |
692 |
| - TDoubleList hVals = this.movingAverage.getSlidingWindow(); |
693 |
| - for(TDoubleIterator it = hVals.iterator();it.hasNext();) { |
694 |
| - histVals.add(it.next()); |
695 |
| - } |
696 |
| - mvgAvg.set(KEY_HIST_VALUES, histVals); |
697 |
| - mvgAvg.put(KEY_TOTAL, this.movingAverage.getTotal()); |
698 |
| - |
699 |
| - cachedNode = factory.objectNode(); |
700 |
| - cachedNode.set(KEY_DIST, distribution); |
701 |
| - cachedNode.set(KEY_HIST_LIKE, historics); |
702 |
| - cachedNode.set(KEY_MVG_AVG, mvgAvg); |
703 |
| - } |
704 |
| - |
705 |
| - return cachedNode; |
706 |
| - } |
707 |
| - |
708 |
| - /** |
709 |
| - * Returns the processed Json Node with possible pretty print indentation |
710 |
| - * formatting if the flag specified is true. |
711 |
| - * |
712 |
| - * @param doPrettyPrint |
713 |
| - * @return |
714 |
| - */ |
715 |
| - public String toJson(boolean doPrettyPrint) { |
716 |
| - // Create the node factory that gives us nodes. |
717 |
| - JsonNodeFactory factory = new JsonNodeFactory(false); |
718 |
| - |
719 |
| - // create a json factory to write the tree node as json. for the example |
720 |
| - // we just write to console |
721 |
| - JsonFactory jsonFactory = new JsonFactory(); |
722 |
| - JsonGenerator generator = null; |
723 |
| - StringWriter out = new StringWriter(); |
724 |
| - try { |
725 |
| - generator = jsonFactory.createGenerator(out); |
726 |
| - }catch(IOException e) { |
727 |
| - LOG.error("Error while creating JsonGenerator", e); |
728 |
| - } |
729 |
| - |
730 |
| - ObjectMapper mapper = new ObjectMapper(); |
731 |
| - if(doPrettyPrint) { |
732 |
| - mapper.enable(SerializationFeature.INDENT_OUTPUT); |
733 |
| - } |
734 |
| - try { |
735 |
| - mapper.writeTree(generator, toJsonNode(factory)); |
736 |
| - } catch(JsonProcessingException e) { |
737 |
| - LOG.error("Error while writing json", e); |
738 |
| - } catch(IOException e) { |
739 |
| - LOG.error("Error while writing json", e); |
740 |
| - } |
741 |
| - |
742 |
| - return out.getBuffer().toString(); |
743 |
| - } |
744 |
| - |
745 |
| - /** |
746 |
| - * Returns the processed Json Node as a String |
747 |
| - * @return |
748 |
| - */ |
749 |
| - public String toJson() { |
750 |
| - return toJson(false); |
751 |
| - } |
752 |
| - |
753 | 654 | /* (non-Javadoc)
|
754 | 655 | * @see java.lang.Object#hashCode()
|
755 | 656 | */
|
|
0 commit comments