public void GivenStringAndCombinationIterator_GetNextMultipleTimes_ShouldReturnReturnNext()
        {
            var iterator = new CombinationIterator("abc", 2).Build();

            Assert.IsTrue(iterator.GetNext() == "ab");
            Assert.IsTrue(iterator.GetNext() == "ac");
        }
    // Start is called before the first frame update
    void Start()
    {
        var mul = 10.0f;

        var it = new CombinationIterator(8, coords.Count);
        var destVectorRichtingFoenestra = new Sv(expectedValues[0], expectedValues[1], expectedValues[2]);
        var destVectorTerug             = new Sv(-expectedValues[0], -expectedValues[1], -expectedValues[2]);

        var dest = destVectorRichtingFoenestra;

        var summedList = it
                         .Select(t => new { ItemsToSelect = it, Data = coords.GetElementsAt(t) })
                         .Select(t => new { ItemsToSelect = t.ItemsToSelect, Data = t.Data, Sum = SumSv(t.Data) })
                         .OrderBy(t => DistTwoVectors(dest, t.Sum.Normalized))
                         .ToList();

        float brrr = 1;

        foreach (var dist in summedList.Take(1))
        {
            var cur = Vector3.zero;
            foreach (var item in dist.Data)
            {
                DrawBol(cur * mul, (item.ToVector3() + cur) * mul, prefabje, new Color(1 - brrr, brrr, 0));
                cur = item.ToVector3() + cur;
            }

            DrawBol(cur * mul, dist.Sum.Normalized.ToVector3() * mul, prefabjeBlue, new Color(1 - brrr, brrr, 255));
            DrawLine(Vector3.zero, cur * mul, new Color(1 - brrr, brrr, 255));
            brrr = brrr - 0.1f;
        }
    }
Ejemplo n.º 3
0
        public void MinorSizeTest(int matrixSize, int minorSize)
        {
            var loops = new CombinationIterator(init: 0, max: matrixSize - 1, loopCount: minorSize);
            var count = MathUtils.Combinations(matrixSize, minorSize);

            Assert.AreEqual(count, loops.Iterations.Count());
        }
Ejemplo n.º 4
0
        public void Test_1(string characters, int length, string expected)
        {
            var iterator = new CombinationIterator(characters, length);
            var json     = JsonConvert.SerializeObject(iterator.combinations);

            json.Should().Be(expected);
        }
Ejemplo n.º 5
0
        public void Test_2()
        {
            var iterator = new CombinationIterator("abc", 2);

            iterator.Next().Should().Be("ab");
            iterator.HasNext().Should().BeTrue();
            iterator.Next().Should().Be("ac");
            iterator.HasNext().Should().BeTrue();
            iterator.Next().Should().Be("bc");
            iterator.HasNext().Should().BeFalse();
        }
Ejemplo n.º 6
0
        public void TestMethod1()
        {
            var iterator = new CombinationIterator("chp", 1);

            var k1 = iterator.HasNext();
            var k2 = iterator.Next();    // returns "ab"
            var k3 = iterator.HasNext(); // returns "ab"
            var k4 = iterator.HasNext(); // returns true
            var k5 = iterator.Next();    // returns true
            var k6 = iterator.Next();    // returns "ac"
            var k7 = iterator.HasNext(); // returns "bc"
            var k8 = iterator.HasNext(); // returns false
            var k9 = iterator.HasNext(); // returns false
        }
Ejemplo n.º 7
0
        private static string CreateHeader(string[] cols, int n)
        {
            var sb = new StringBuilder();
            var iter = new CombinationIterator(cols, n);
            sb.Append(_loader.IdName);

            while (iter.MoveNext())
            {
                var ftuple = new TupleData(iter.Current);
                sb.Append(";" + ftuple);
            }

            sb.Append(";" + _loader.TargetName);
            return sb.ToString();
        }
Ejemplo n.º 8
0
        private static string CreateHeader(string[] cols, int n)
        {
            var sb   = new StringBuilder();
            var iter = new CombinationIterator(cols, n);

            sb.Append(_loader.IdName);

            while (iter.MoveNext())
            {
                var ftuple = new TupleData(iter.Current);
                sb.Append(";" + ftuple);
            }

            sb.Append(";" + _loader.TargetName);
            return(sb.ToString());
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            if (args.Length < 4 || args.Length > 4)
            {
                Logger.Log("usage: program.exe <train.csv> <conf.csv> <id> <target_name>");
                return;
            }

            string dataPath = args[0];
            string confPath = args[1];
            string id = args[2];
            string target = args[3];

            Logger.Log("data: " + dataPath);
            Logger.Log("conf : " + confPath);
            Logger.Log("id : " + id);
            Logger.Log("target : " + target);

            try
            {
                var fmgr = new FactorManager();
                fmgr.Load(confPath, target);
                fmgr.TargDep = 10;
                fmgr.FactorDep = 100;
                fmgr.SelectFactors();
                var cols = fmgr.VisibleFactors.ToArray();

                //_loader.MaxRowsLoaded = 10000;
                _loader.AddTargetColumn(target);
                _loader.AddIdColumn(id);
                _loader.CollectDistrStat = true;
                _loader.Load(dataPath);

                var statDict = new Dictionary<TupleData, Dictionary<TupleData, StatItem>>();

                // collecting stats
                int idx = 0;
                int n = 4;
                var iter = new CombinationIterator(cols, n);
                while (iter.MoveNext())
                {
                    idx++;

                    var cval = iter.Current;
                    var ftuple = new TupleData(cval);

                    statDict.Add(ftuple, new Dictionary<TupleData, StatItem>());

                    foreach (var row in _loader.Rows)
                    {
                        var vtuple = CreateValueTuple(cval, row);
                        if (!statDict[ftuple].ContainsKey(vtuple))
                            statDict[ftuple].Add(vtuple, new StatItem());
                        if (row.Target<=1)
                        {
                            statDict[ftuple][vtuple].Count++;
                            statDict[ftuple][vtuple].Targets += (int)row.Target;
                        }
                    }

                    foreach (var t in statDict[ftuple].Keys)
                    {
                        statDict[ftuple][t].TargetProb = statDict[ftuple][t].Targets / (double)statDict[ftuple][t].Count;
                    }

                    Logger.Log(ftuple + " done;");
                }

                // creating modified file
                using (var sw = new StreamWriter(new FileStream(dataPath + "_cat.csv", FileMode.Create, FileAccess.Write)))
                {
                    idx = 0;
                    sw.WriteLine(CreateHeader(cols, n));
                    sw.Flush();
                    double defProb = (double)_loader.TargetStat[1] / (_loader.TargetStat[1] + _loader.TargetStat[0]);

                    foreach (var row in _loader.Rows)
                    {
                       idx++;

                        var sb = new StringBuilder();
                        iter = new CombinationIterator(cols, n);
                        sb.Append(row.Id);

                        while (iter.MoveNext())
                        {
                            var cval = iter.Current;
                            var ftuple = new TupleData(cval);
                            var t = CreateValueTuple(cval, row);

                            double prob = statDict[ftuple].ContainsKey(t) ? statDict[ftuple][t].TargetProb : defProb;

                            sb.Append(";" + prob.ToString("F05"));
                        }
                        sb.Append(";" + row.Target);
                        sw.WriteLine(sb);

                        if (idx%12345==0)
                        {
                            Logger.Log(idx + " lines writed;");
                            sw.Flush();
                        }
                    }
                    Logger.Log(idx + " lines writed; done;");
                }
            }
            catch (Exception e)
            {
                Logger.Log(e);
            }
        }
Ejemplo n.º 10
0
 public void RunProblem()
 {
     var temp = new CombinationIterator("abc", 2);
 }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            if (args.Length < 4 || args.Length > 4)
            {
                Logger.Log("usage: program.exe <train.csv> <conf.csv> <id> <target_name>");
                return;
            }

            string dataPath = args[0];
            string confPath = args[1];
            string id       = args[2];
            string target   = args[3];

            Logger.Log("data: " + dataPath);
            Logger.Log("conf : " + confPath);
            Logger.Log("id : " + id);
            Logger.Log("target : " + target);

            try
            {
                var fmgr = new FactorManager();
                fmgr.Load(confPath, target);
                fmgr.TargDep   = 10;
                fmgr.FactorDep = 100;
                fmgr.SelectFactors();
                var cols = fmgr.VisibleFactors.ToArray();

                //_loader.MaxRowsLoaded = 10000;
                _loader.AddTargetColumn(target);
                _loader.AddIdColumn(id);
                _loader.CollectDistrStat = true;
                _loader.Load(dataPath);

                var statDict = new Dictionary <TupleData, Dictionary <TupleData, StatItem> >();

                // collecting stats
                int idx  = 0;
                int n    = 4;
                var iter = new CombinationIterator(cols, n);
                while (iter.MoveNext())
                {
                    idx++;

                    var cval   = iter.Current;
                    var ftuple = new TupleData(cval);

                    statDict.Add(ftuple, new Dictionary <TupleData, StatItem>());

                    foreach (var row in _loader.Rows)
                    {
                        var vtuple = CreateValueTuple(cval, row);
                        if (!statDict[ftuple].ContainsKey(vtuple))
                        {
                            statDict[ftuple].Add(vtuple, new StatItem());
                        }
                        if (row.Target <= 1)
                        {
                            statDict[ftuple][vtuple].Count++;
                            statDict[ftuple][vtuple].Targets += (int)row.Target;
                        }
                    }

                    foreach (var t in statDict[ftuple].Keys)
                    {
                        statDict[ftuple][t].TargetProb = statDict[ftuple][t].Targets / (double)statDict[ftuple][t].Count;
                    }

                    Logger.Log(ftuple + " done;");
                }

                // creating modified file
                using (var sw = new StreamWriter(new FileStream(dataPath + "_cat.csv", FileMode.Create, FileAccess.Write)))
                {
                    idx = 0;
                    sw.WriteLine(CreateHeader(cols, n));
                    sw.Flush();
                    double defProb = (double)_loader.TargetStat[1] / (_loader.TargetStat[1] + _loader.TargetStat[0]);

                    foreach (var row in _loader.Rows)
                    {
                        idx++;

                        var sb = new StringBuilder();
                        iter = new CombinationIterator(cols, n);
                        sb.Append(row.Id);

                        while (iter.MoveNext())
                        {
                            var cval   = iter.Current;
                            var ftuple = new TupleData(cval);
                            var t      = CreateValueTuple(cval, row);

                            double prob = statDict[ftuple].ContainsKey(t) ? statDict[ftuple][t].TargetProb : defProb;

                            sb.Append(";" + prob.ToString("F05"));
                        }
                        sb.Append(";" + row.Target);
                        sw.WriteLine(sb);

                        if (idx % 12345 == 0)
                        {
                            Logger.Log(idx + " lines writed;");
                            sw.Flush();
                        }
                    }
                    Logger.Log(idx + " lines writed; done;");
                }
            }
            catch (Exception e)
            {
                Logger.Log(e);
            }
        }