Esempio n. 1
0
        private IEnumerable <BasisFunction> CreateUnivariateBases(IRegressionProblemData problemData)
        {
            var B1             = new List <BasisFunction>();
            var inputVariables = problemData.AllowedInputVariables;
            var validExponents = ConsiderExponentiations ? exponents : new double[] { 1 };
            var validFuncs     = ConsiderNonlinearFuncs ? NonlinearFuncs.CheckedItems.Select(val => val.Value) : new List <OpCode>();

            // TODO: add Hinge functions

            foreach (var variableName in inputVariables)
            {
                foreach (var exp in validExponents)
                {
                    var data = problemData.Dataset.GetDoubleValues(variableName).Select(x => Math.Pow(x, exp)).ToArray();
                    if (!ok(data))
                    {
                        continue;
                    }
                    var name = expToString(exp, variableName);
                    B1.Add(new BasisFunction(name, data, false));
                    foreach (OpCode _op in validFuncs)
                    {
                        var inner_data = data.Select(x => Utils.eval(_op, x)).ToArray();
                        if (!ok(inner_data))
                        {
                            continue;
                        }
                        // the name is for later parsing the Basis Functions to an ISymbolicExpressionTree
                        var inner_name = OpCodeToString.GetByFirst(_op) + "(" + name + ")";
                        B1.Add(new BasisFunction(inner_name, inner_data, true));
                    }
                }
            }
            return(B1);
        }
        public void GetByFirstFact(string firstValue, string secondValue, bool expectedResult)
        {
            var results = _dictionary.GetByFirst(firstValue);

            var result = results.ToList().Contains(secondValue);

            result.Should().Be(expectedResult);
        }
Esempio n. 3
0
        public void TestBidirectionalDictionary()
        {
            var dict1 = new BidirectionalDictionary <int, double>();

            dict1.Add(4, 2.0);
            Assert.IsTrue(dict1.ContainsFirst(4) && dict1.ContainsSecond(2));
            bool exceptionOnDuplicate = false;

            try {
                dict1.Add(4, 3.0);
            }
            catch (ArgumentException) { exceptionOnDuplicate = true; }
            Assert.IsTrue(exceptionOnDuplicate);
            Assert.IsTrue(dict1.GetByFirst(4) == 2);
            Assert.IsTrue(dict1.GetBySecond(2) == 4);
            Assert.IsTrue(dict1.Count == 1);
            dict1.Clear();
            Assert.IsTrue(dict1.Count == 0);

            var dict2 = new BidirectionalDictionary <ComplexType, int>(new ComplexTypeEqualityComparer());

            Assert.IsTrue(!dict2.Any());
            dict2.Add(new ComplexType(1), 2);
            Assert.IsTrue(dict2.Any());
            dict2.Add(new ComplexType(2), 1);
            Assert.IsTrue(dict2.ContainsFirst(new ComplexType(2)));
            Assert.IsTrue(dict2.ContainsSecond(2));
            exceptionOnDuplicate = false;
            try {
                dict2.Add(new ComplexType(2), 3);
            }
            catch (ArgumentException) { exceptionOnDuplicate = true; }
            Assert.IsTrue(exceptionOnDuplicate);
            exceptionOnDuplicate = false;
            try {
                dict2.Add(new ComplexType(3), 1);
            }
            catch (ArgumentException) { exceptionOnDuplicate = true; }
            Assert.IsTrue(exceptionOnDuplicate);
            Assert.IsTrue(dict2.Count == 2);
            Assert.IsTrue(dict2.GetBySecond(1).Field == 2);
            Assert.IsTrue(dict2.GetByFirst(new ComplexType(1)) == 2);
            dict2.Clear();
            Assert.IsTrue(!dict2.Any());
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="type"></param>
 /// <returns></returns>
 public SqlDbType Get(string type)
 {
     return(_typeMap.GetByFirst(type.ToLower()).FirstOrDefault());
 }