/// <summary>
 ///
 /// </summary>
 /// <param name="parentIndex"></param>
 /// <param name="nodeType"></param>
 /// <param name="interval"></param>
 /// <param name="impurity"></param>
 /// <param name="nodeDepth"></param>
 public DecisionNodeCreationItem(int parentIndex, NodePositionType nodeType, Interval1D interval, double impurity, int nodeDepth)
 {
     ParentIndex = parentIndex;
     NodeType    = nodeType;
     Interval    = interval;
     Impurity    = impurity;
     NodeDepth   = nodeDepth;
 }
示例#2
0
 /// <summary>
 /// Creates a copy of the split info
 /// </summary>
 /// <param name="Position"></param>
 /// <returns></returns>
 public GBMSplitInfo Copy(NodePositionType Position)
 {
     return(new GBMSplitInfo
     {
         Samples = Samples,
         Sum = Sum,
         SumOfSquares = SumOfSquares,
         Cost = Cost,
         BestConstant = BestConstant,
         Position = Position,
         BinomialSum = BinomialSum
     });
 }
示例#3
0
            public int solution(int[] H)
            {
                const int norma        = 1000000007;
                long      count        = 0;
                int       dimension    = H.Length;
                var       tmpPlaces    = new NodePositionType[dimension];
                var       replacements = new int[dimension];
                var       ordered      = new List <KeyValuePair <int, int> > ();

                for (int i = 0; i < dimension; i++)
                {
                    ordered.Add(new KeyValuePair <int, int> (i, i));
                }
                ordered = ordered.OrderBy(x => H[x.Key]).ToList();
                for (int i = 0; i < dimension; i++)
                {
                    replacements[i] = ordered[i].Key;
                }
                for (int i = 0; i < dimension; tmpPlaces[i++] = NodePositionType.Left)
                {
                    int node = H[i];
                    if (i == 0)
                    {
                        tmpPlaces[i] = NodePositionType.Node;
                        for (int j = 1; j < dimension; j++)
                        {
                            tmpPlaces[j] = NodePositionType.Right;
                        }
                    }
                    else
                    {
                        tmpPlaces[i] = NodePositionType.Node;
                    }
                    Mdb.Print = H[i] == 46;
                    if (Mdb.Print && Mdb.ConsoleApp)
                    {
                        Console.WriteLine($"**** {H[i]} ***");
                    }
                    count = (count + CalcOne(H, tmpPlaces, replacements, node));
                    if (Mdb.ConsoleApp)
                    {
                        Mdb.ResultsDictionary.Add(i, count);
                    }
                }
                return((int)(count % norma));
            }
示例#4
0
            public int solutionV3(int[] H)
            {
                const int norma        = 1000000007;
                long      count        = 0;
                int       dimension    = H.Length;
                var       tmpPlaces    = new NodePositionType[dimension];
                var       replacements = new int[dimension];
                var       ordered      = new List <KeyValuePair <int, int> > ();

                for (int i = 0; i < dimension; i++)
                {
                    ordered.Add(new KeyValuePair <int, int> (i, i));
                }
                ordered = ordered.OrderBy(x => H[x.Key]).ToList();
                for (int i = 0; i < dimension; i++)
                {
                    replacements[i] = ordered[i].Key;
                }
                for (int i = 0; i < dimension; i++)
                {
                    int node = H[i];
                    tmpPlaces[i] = NodePositionType.Node;
                    for (int j = 0; j < i; j++)
                    {
                        tmpPlaces[j] = H[j] <= node ? NodePositionType.None : NodePositionType.Left;
                    }
                    for (int j = i + 1; j < dimension; j++)
                    {
                        tmpPlaces[j] = H[j] <= node ? NodePositionType.None : NodePositionType.Right;
                    }

                    //Mdb.Print = H[i] == 12;
                    //if (Mdb.Print && Mdb.ConsoleApp) Console.WriteLine ($"**** {H[i]} ***");
                    count = (count + CalcOneV3(H, tmpPlaces, replacements) % norma) % norma;
                    //if (Mdb.ConsoleApp) Mdb.ResultsDictionary.Add (i, count);
                }
                return((int)(count % norma));
            }
        /// <summary>
        /// Updates the parent node with the new child
        /// </summary>
        /// <param name="nodes"></param>
        /// <param name="parent"></param>
        /// <param name="child"></param>
        /// <param name="type"></param>
        public static void UpdateParent(this List <Node> nodes, Node parent, Node child, NodePositionType type)
        {
            switch (type)
            {
            case NodePositionType.Root:
                break;

            case NodePositionType.Left:
                nodes[parent.NodeIndex] = new Node(parent.FeatureIndex, parent.Value,
                                                   child.NodeIndex, parent.RightIndex, parent.NodeIndex, parent.LeafProbabilityIndex);
                break;

            case NodePositionType.Right:
                nodes[parent.NodeIndex] = new Node(parent.FeatureIndex, parent.Value,
                                                   parent.LeftIndex, child.NodeIndex, parent.NodeIndex, parent.LeafProbabilityIndex);
                break;

            default:
                throw new InvalidOperationException("Unsupported position type");
            }
        }