/** * Convenience method to provide an isolated copy of * this <see cref="IInference"/> * * @return */ internal ManualInput Copy() { ManualInput retVal = new ManualInput(); retVal._classifierInput = new Map <string, NamedTuple>(this._classifierInput); retVal._classifiers = new NamedTuple(this._classifiers.GetKeys(), this._classifiers.Values().ToArray()); retVal._layerInput = this._layerInput; retVal._sdr = Arrays.CopyOf(this._sdr, this._sdr.Length); retVal._encoding = Arrays.CopyOf(this._encoding, this._encoding.Length); retVal._feedForwardActiveColumns = Arrays.CopyOf(this._feedForwardActiveColumns, this._feedForwardActiveColumns.Length); retVal._feedForwardSparseActives = Arrays.CopyOf(this._feedForwardSparseActives, this._feedForwardSparseActives.Length); retVal._previousPredictiveCells = new HashSet <Cell>(this._previousPredictiveCells); retVal._predictiveCells = new HashSet <Cell>(this._predictiveCells); retVal._classification = new Map <string, Classification <object> >(this._classification); retVal._anomalyScore = this._anomalyScore; retVal._customObject = this._customObject; retVal._activeCells = new HashSet <Cell>(this._activeCells); return(retVal); }
/** * Connects the output of the specified {@code Region} to the * input of this Region * * @param inputRegion the Region who's emissions will be observed by * this Region. * @return */ public Region Connect(Region inputRegion) { ManualInput localInf = new ManualInput(); inputRegion.Observe().Subscribe(output => { localInf.SetSdr(output.GetSdr()).SetRecordNum(output.GetRecordNum()).SetClassifierInput(output.GetClassifierInput()).SetLayerInput(output.GetSdr()); if (output.GetSdr().Length > 0) { ((Layer <IInference>)tail).Compute(localInf); } }, Console.WriteLine, () => { tail.NotifyComplete(); }); //inputRegion.Observe().Subscribe(new Observer<IInference>() { //ManualInput localInf = new ManualInput(); //@Override public void onCompleted() //{ //tail.notifyComplete(); //} //@Override public void onError(Throwable e) { e.printStackTrace(); } //@SuppressWarnings("unchecked") // @Override public void onNext(IInference i) //{ //localInf.sdr(i.getSDR()).recordNum(i.getRecordNum()).classifierInput(i.getClassifierInput()).layerInput(i.getSDR()); //if (i.getSDR().length > 0) //{ // ((Layer<IInference>)tail).compute(localInf); //} //} //}); // Set the upstream region this.upstreamRegion = inputRegion; inputRegion.downstreamRegion = this; return(this); }
public override object PostDeSerialize(object manualInput) { ManualInput mi = (ManualInput)manualInput; ManualInput retVal = new ManualInput(); retVal._activeCells = mi._activeCells; retVal._anomalyScore = mi._anomalyScore; retVal._classification = mi._classification; retVal._classifierInput = mi._classifierInput; retVal._classifiers = mi._classifiers; retVal._customObject = mi._customObject; retVal._encoding = mi._encoding; retVal._feedForwardActiveColumns = mi._feedForwardActiveColumns; retVal._feedForwardSparseActives = mi._feedForwardSparseActives; retVal._layerInput = mi._layerInput; retVal._predictiveCells = mi._predictiveCells; retVal._previousPredictiveCells = mi._previousPredictiveCells; retVal._sdr = mi._sdr; return(retVal); }
public override bool Equals(Object obj) { if (this == obj) { return(true); } if (obj == null) { return(false); } if (!typeof(IInference).IsAssignableFrom(obj.GetType())) { return(false); } ManualInput other = (ManualInput)obj; if (_activeCells == null) { if (other._activeCells != null) { return(false); } } else if (!_activeCells.Equals(other._activeCells)) { return(false); } if (BitConverter.DoubleToInt64Bits(_anomalyScore) != BitConverter.DoubleToInt64Bits(other._anomalyScore)) { return(false); } if (_classification == null) { if (other._classification != null) { return(false); } } else if (!_classification.Equals(other._classification)) { return(false); } if (_classifierInput == null) { if (other._classifierInput != null) { return(false); } } else if (!_classifierInput.Equals(other._classifierInput)) { return(false); } if (_computeCycle == null) { if (other._computeCycle != null) { return(false); } } else if (!_computeCycle.Equals(other._computeCycle)) { return(false); } if (!Arrays.AreEqual(_encoding, other._encoding) && _encoding != null && other._encoding != null) { return(false); } if (!Arrays.AreEqual(_feedForwardActiveColumns, other._feedForwardActiveColumns) && _feedForwardActiveColumns != null && other._feedForwardActiveColumns != null) { return(false); } if (!Arrays.AreEqual(_feedForwardSparseActives, other._feedForwardSparseActives) && _feedForwardSparseActives != null && other._feedForwardSparseActives != null) { return(false); } if (_predictiveCells == null) { if (other._predictiveCells != null) { return(false); } } else if (!_predictiveCells.Equals(other._predictiveCells)) { return(false); } if (_previousPredictiveCells == null) { if (other._previousPredictiveCells != null) { return(false); } } else if (!_previousPredictiveCells.Equals(other._previousPredictiveCells)) { return(false); } if (_recordNum != other._recordNum) { return(false); } if (!Arrays.AreEqual(_sdr, other._sdr) && _sdr != null && other._sdr != null) { return(false); } return(true); }
/** * Called internally to "connect" two {@link Layer} <see cref="IObservable{T}"/>s * taking care of other connection details such as passing the inference * up the chain and any possible encoder. * * @param in the sink end of the connection between two layers * @param out the source end of the connection between two layers * @throws IllegalStateException if Region is already closed */ private void Connect <I, O>(I @in, O @out) // <I extends Layer<IInference>, O extends Layer<IInference>> where I : Layer <IInference> where O : Layer <IInference> { if (assemblyClosed) { throw new InvalidOperationException("Cannot add Layers when Region has already been closed."); } HashSet <Layer <IInference> > all = new HashSet <Layer <IInference> >(sources); foreach (var sink in sinks) { all.Add(sink); } //all.addAll(sinks); LayerMask inMask = @in.GetMask(); LayerMask outMask = @out.GetMask(); if (!all.Contains(@out)) { layersDistinct = (int)(flagAccumulator & outMask) < 1; flagAccumulator |= outMask; } if (!all.Contains(@in)) { layersDistinct = (int)(flagAccumulator & inMask) < 1; flagAccumulator |= inMask; } sources.Add(@out); sinks.Add(@in); ManualInput localInf = new ManualInput(); @out.Subscribe(Observer.Create <IInference>(i => { if (layersDistinct) { @in.Compute(i); } else { localInf.SetSdr(i.GetSdr()).SetRecordNum(i.GetRecordNum()).SetLayerInput(i.GetSdr()); @in.Compute(localInf); } }, Console.WriteLine, () => { @in.NotifyComplete(); })); // @out.subscribe(new Subscriber<IInference>() { // ManualInput localInf = new ManualInput(); // @Override public void onCompleted() { in.notifyComplete(); } // @Override public void onError(Throwable e) { e.printStackTrace(); } // @Override public void onNext(IInference i) // { // if (layersDistinct) // { // in.compute(i); // } // else { // localInf.sdr(i.getSDR()).recordNum(i.getRecordNum()).layerInput(i.getSDR()); // in.compute(localInf); // } // } //}); }