Пример #1
0
        private void _jobUpdateCandidate(int candidateID, double metricValue, object resultsObj)
        {
            bool       nullResults = (resultsObj == null);
            NamedTuple results;

            if (nullResults)
            {
                results = new NamedTuple(new [] { "bestModel", "bestValue" }, null, null);
            }
            else
            {
                results = JsonConvert.DeserializeObject <NamedTuple>(resultsObj as string);
                LOGGER.Debug(string.Format("Updating old results {0}", results));
            }
            int    oldCandidateID = (int)results["bestModel"];
            double oldMetricValue = (double)results["bestValue"];

            results["bestModel"] = candidateID;
            results["bestValue"] = metricValue;
            bool isUpdated = candidateID == oldCandidateID;

            if (isUpdated)
            {
                LOGGER.Info(string.Format("Choosing new model. Old candidate: (id={0}, value={1}) New candidate: (id={2}, value={3})",
                                          oldCandidateID, oldMetricValue, candidateID, metricValue));
            }
            else
            {
                LOGGER.Info(string.Format("Same model as before. id={0}, metric={1}", candidateID,
                                          metricValue));
            }

            LOGGER.Debug(string.Format("New Results {0}", results));
            _cjDB.jobUpdateResults(_jobID, JsonConvert.SerializeObject(results));
        }
Пример #2
0
        public Statistic(double mean, double variance, double stdev)
        {
            this.mean     = mean;
            this.variance = variance;
            this.stdev    = stdev;

            this.entries = new NamedTuple(new string[] { "mean", "variance", "stdev" }, mean, variance, stdev);
        }
        private void SpecializeMembers()
        {
            var location = new Location(this);

            _members["TypeVar"] = new TypeVar(this);
            _members["NewType"] = SpecializeNewType(location);
            _members["Type"]    = new Type(this);

            _members["Iterator"] = new SpecializedGenericType("Iterator", CreateIteratorType, this);

            _members["Iterable"]        = new SpecializedGenericType("Iterable", typeArgs => CreateListType("Iterable", BuiltinTypeId.List, typeArgs, false), this);
            _members["Sequence"]        = new SpecializedGenericType("Sequence", typeArgs => CreateListType("Sequence", BuiltinTypeId.List, typeArgs, false), this);
            _members["MutableSequence"] = new SpecializedGenericType("MutableSequence",
                                                                     typeArgs => CreateListType("MutableSequence", BuiltinTypeId.List, typeArgs, true), this);
            _members["List"] = new SpecializedGenericType("List",
                                                          typeArgs => CreateListType("List", BuiltinTypeId.List, typeArgs, true), this);

            _members["MappingView"] = new SpecializedGenericType("MappingView",
                                                                 typeArgs => CreateDictionary("MappingView", typeArgs, false), this);

            _members["KeysView"]   = new SpecializedGenericType("KeysView", CreateKeysViewType, this);
            _members["ValuesView"] = new SpecializedGenericType("ValuesView", CreateValuesViewType, this);
            _members["ItemsView"]  = new SpecializedGenericType("ItemsView", CreateItemsViewType, this);

            _members["AbstractSet"] = new SpecializedGenericType("AbstractSet",
                                                                 typeArgs => CreateListType("AbstractSet", BuiltinTypeId.Set, typeArgs, true), this);
            _members["Set"] = new SpecializedGenericType("Set",
                                                         typeArgs => CreateListType("Set", BuiltinTypeId.Set, typeArgs, true), this);
            _members["MutableSet"] = new SpecializedGenericType("MutableSet",
                                                                typeArgs => CreateListType("MutableSet", BuiltinTypeId.Set, typeArgs, true), this);
            _members["FrozenSet"] = new SpecializedGenericType("FrozenSet",
                                                               typeArgs => CreateListType("FrozenSet", BuiltinTypeId.Set, typeArgs, false), this);

            _members["Tuple"] = new SpecializedGenericType("Tuple", CreateTupleType, this);

            _members["Mapping"] = new SpecializedGenericType("Mapping",
                                                             typeArgs => CreateDictionary("Mapping", typeArgs, false), this);
            _members["MutableMapping"] = new SpecializedGenericType("MutableMapping",
                                                                    typeArgs => CreateDictionary("MutableMapping", typeArgs, true), this);
            _members["Dict"] = new SpecializedGenericType("Dict",
                                                          typeArgs => CreateDictionary("Dict", typeArgs, true), this);
            _members["OrderedDict"] = new SpecializedGenericType("OrderedDict",
                                                                 typeArgs => CreateDictionary("OrderedDict", typeArgs, true), this);
            _members["DefaultDict"] = new SpecializedGenericType("DefaultDict",
                                                                 typeArgs => CreateDictionary("DefaultDict", typeArgs, true), this);

            _members["Union"] = new SpecializedGenericType("Union", CreateUnion, this);

            _members["Counter"] = Specialized.Function("Counter", this, GetMemberDocumentation("Counter"),
                                                       Interpreter.GetBuiltinType(BuiltinTypeId.Int)).CreateInstance(ArgumentSet.WithoutContext);

            // TODO: make these classes that support __float__, etc per spec.
            //_members["SupportsInt"] = Interpreter.GetBuiltinType(BuiltinTypeId.Int);
            //_members["SupportsFloat"] = Interpreter.GetBuiltinType(BuiltinTypeId.Float);
            //_members["SupportsComplex"] = Interpreter.GetBuiltinType(BuiltinTypeId.Complex);
            //_members["SupportsBytes"] = Interpreter.GetBuiltinType(BuiltinTypeId.Bytes);
            _members["ByteString"] = Interpreter.GetBuiltinType(BuiltinTypeId.Bytes);

            _members["NamedTuple"] = new NamedTuple(this);

            _members["Any"]    = new AnyType(this);
            _members["AnyStr"] = CreateAnyStr();

            _members["Optional"] = new SpecializedGenericType("Optional", CreateOptional, this);
            _members["Type"]     = new SpecializedGenericType("Type", CreateType, this);

            _members["Generic"] = new SpecializedGenericType("Generic", CreateGenericClassBase, this);
        }
Пример #4
0
        public void TestCopy()
        {
            Map <string, NamedTuple> classifierInput = new Map <string, NamedTuple>();
            NamedTuple classifiers = new NamedTuple(new[] { "one", "two" }, 1, 2);
            object     layerInput  = new object();

            int[]                   sdr                = new[] { 20 };
            int[]                   encoding           = new int[40];
            int[]                   activeColumns      = new int[25];
            int[]                   sparseActives      = new int[2];
            HashSet <Cell>          activeCells        = new HashSet <Cell>(); activeCells.Add(new Cell(new Column(4, 0), 1));
            HashSet <Cell>          previousPrediction = new HashSet <Cell>(); previousPrediction.Add(new Cell(new Column(4, 0), 2));
            HashSet <Cell>          currentPrediction  = new HashSet <Cell>(); currentPrediction.Add(new Cell(new Column(4, 0), 3));
            Classification <object> classification     = new Classification <object>();
            double                  anomalyScore       = 0.48d;
            object                  customObject       = new Net.Network.Network("MI Network", NetworkTestHarness.GetNetworkDemoTestEncoderParams());

            ManualInput mi = new ManualInput()
                             .SetClassifierInput(classifierInput)
                             .SetLayerInput(layerInput)
                             .SetSdr(sdr)
                             .SetEncoding(encoding)
                             .SetFeedForwardActiveColumns(activeColumns)
                             .SetFeedForwardSparseActives(sparseActives)
                             .SetPredictiveCells(previousPrediction)
                             .SetPredictiveCells(currentPrediction) // last prediction internally becomes previous
                             .SetActiveCells(activeCells)
                             .SetClassifiers(classifiers)
                             .StoreClassification("foo", classification)
                             .SetAnomalyScore(anomalyScore)
                             .SetCustomObject(customObject);

            ManualInput copy = mi.Copy();

            Assert.IsTrue(copy.GetClassifierInput().DictEquals(classifierInput));
            Assert.IsFalse(copy.GetClassifierInput() == classifierInput);

            Assert.IsTrue(copy.GetLayerInput() == layerInput);

            Assert.IsTrue(Arrays.AreEqual(copy.GetSdr(), sdr));
            Assert.IsFalse(copy.GetSdr() == sdr);

            Assert.IsTrue(Arrays.AreEqual(copy.GetEncoding(), encoding));
            Assert.IsFalse(copy.GetEncoding() == encoding);

            Assert.IsTrue(Arrays.AreEqual(copy.GetFeedForwardActiveColumns(), activeColumns));
            Assert.IsFalse(copy.GetFeedForwardActiveColumns() == activeColumns);

            Assert.IsTrue(Arrays.AreEqual(copy.GetFeedForwardSparseActives(), sparseActives));
            Assert.IsFalse(copy.GetFeedForwardSparseActives() == sparseActives);

            Assert.IsTrue(copy.GetPredictiveCells().SetEquals(currentPrediction));
            Assert.IsFalse(copy.GetPredictiveCells() == currentPrediction);

            Assert.IsTrue(copy.GetActiveCells().SetEquals(activeCells));
            Assert.IsFalse(copy.GetActiveCells() == activeCells);

            Assert.IsTrue(copy.GetPreviousPredictiveCells().SetEquals(previousPrediction));
            Assert.IsFalse(copy.GetPreviousPredictiveCells() == previousPrediction);

            Assert.IsTrue(copy.GetClassifiers().Equals(classifiers));
            Assert.IsFalse(copy.GetClassifiers() == classifiers);

            Assert.IsTrue(copy.GetClassification("foo").Equals(classification));

            Assert.AreEqual(copy.GetAnomalyScore(), anomalyScore, 0.0); // zero deviation

            Assert.AreEqual(copy.GetCustomObject(), customObject);
        }
Пример #5
0
 /// <summary>
 /// Sets the <see cref="NamedTuple"/> containing the classifiers used for each particular input field.
 /// </summary>
 /// <param name="tuple"></param>
 /// <returns></returns>
 public ManualInput SetClassifiers(NamedTuple tuple)
 {
     this._classifiers = tuple;
     return(this);
 }