private static void ShrinkKernel(Index2 index,
                                         ArrayView2D <float> xImage,
                                         ArrayView2D <float> bMap,
                                         ArrayView2D <float> aMap,
                                         ArrayView <float> lambdaAlpha,
                                         ArrayView <Pixel> output)
        {
            if (index.X == 0 & index.Y == 0)
            {
                output[0].AbsDiff = 0;
            }

            if (index.InBounds(xImage.Extent))
            {
                var xOld      = xImage[index];
                var gradient  = bMap[index];
                var lipschitz = aMap[index];
                var lambda    = lambdaAlpha[0];
                var alpha     = lambdaAlpha[1];

                var xNew     = GPUProximalOperator(xOld * lipschitz + gradient, lipschitz, lambda, alpha);
                var xAbsDiff = XMath.Abs(xNew - xOld);
                var xIndex   = index.X;
                var yIndex   = index.Y;
                var sign     = XMath.Sign(xNew - xOld);

                var pix = new Pixel()
                {
                    AbsDiff = xAbsDiff,
                    X       = xIndex,
                    Y       = yIndex,
                    Sign    = sign
                };
                Atomic.MakeAtomic(ref output[0], pix, new MaxPixelOperation(), new PixelCompareExchange());
            }
        }
Exemplo n.º 2
0
        static double Evaluate(int individualIndex, int independentsRowIndex, ArrayView2D <double> independents, ArrayView <NodeGPU> nodes, ArrayView <int> nodeArrayStarts)
        {
            for (int nodeIndex = 0; nodeIndex < nodeArrayStarts.Length; nodeIndex++)
            {
                Index1 currentNodeIndex = new Index1(nodeArrayStarts[individualIndex] + nodeIndex);
                //NodeGPU currentNode = nodes[currentNodeIndex];
                if (nodes[currentNodeIndex].IndependentIndex >= 0)
                {
                    int independentIndex = nodes[currentNodeIndex].IndependentIndex;
                    nodes[currentNodeIndex].Number = independents[independentsRowIndex, independentIndex];
                }
                else if (nodes[currentNodeIndex].OperatorIndex >= 0)
                {
                    Index1 branchIndex1 = new Index1(nodeArrayStarts[individualIndex] + nodes[currentNodeIndex].Branch1);
                    Index1 branchIndex2 = new Index1(nodeArrayStarts[individualIndex] + nodes[currentNodeIndex].Branch2);
                    if (nodes[currentNodeIndex].OperatorIndex < 6)
                    {
                        if (nodes[currentNodeIndex].OperatorIndex < 4)
                        {
                            if (nodes[currentNodeIndex].OperatorIndex == 2)
                            {
                                nodes[currentNodeIndex].Number = nodes[branchIndex1].Number + nodes[branchIndex2].Number;
                            }
                            else if (nodes[currentNodeIndex].OperatorIndex == 3)
                            {
                                nodes[currentNodeIndex].Number = nodes[branchIndex1].Number - nodes[branchIndex2].Number;
                            }
                        }
                        else
                        {
                            if (nodes[currentNodeIndex].OperatorIndex == 4)
                            {
                                nodes[currentNodeIndex].Number = nodes[branchIndex1].Number * nodes[branchIndex2].Number;
                            }
                            else if (nodes[currentNodeIndex].OperatorIndex == 5)
                            {
                                nodes[currentNodeIndex].Number = nodes[branchIndex1].Number / nodes[branchIndex2].Number;
                            }
                        }
                    }
                    else if (nodes[currentNodeIndex].OperatorIndex >= 6 && nodes[currentNodeIndex].OperatorIndex <= 15)
                    {
                        if (nodes[currentNodeIndex].OperatorIndex == 6)
                        {
                            nodes[currentNodeIndex].Number = -nodes[branchIndex1].Number;
                        }
                        else if (nodes[currentNodeIndex].OperatorIndex == 8)
                        {
                            nodes[currentNodeIndex].Number = XMath.Sin(nodes[branchIndex1].Number);
                        }
                        else if (nodes[currentNodeIndex].OperatorIndex == 9)
                        {
                            nodes[currentNodeIndex].Number = XMath.Cos(nodes[branchIndex1].Number);
                        }
                        else if (nodes[currentNodeIndex].OperatorIndex == 14)
                        {
                            nodes[currentNodeIndex].Number = XMath.Pow(nodes[branchIndex1].Number, nodes[branchIndex2].Number);
                        }
                        else if (nodes[currentNodeIndex].OperatorIndex == 15)
                        {
                            nodes[currentNodeIndex].Number = XMath.Sign(nodes[branchIndex1].Number);
                        }
                    }
                    else
                    {
                        Index1 branchIndex3 = new Index1(nodeArrayStarts[individualIndex] + nodes[currentNodeIndex].Branch3);
                        Index1 branchIndex4 = new Index1(nodeArrayStarts[individualIndex] + nodes[currentNodeIndex].Branch4);
                        if (nodes[currentNodeIndex].OperatorIndex == 18)
                        {
                            if (nodes[branchIndex1].Number == nodes[branchIndex2].Number)
                            {
                                nodes[currentNodeIndex].Number = nodes[branchIndex3].Number;
                            }
                            else
                            {
                                nodes[currentNodeIndex].Number = nodes[branchIndex4].Number;
                            }
                        }
                        else if (nodes[currentNodeIndex].OperatorIndex == 19)
                        {
                            if (nodes[branchIndex1].Number < nodes[branchIndex2].Number)
                            {
                                nodes[currentNodeIndex].Number = nodes[branchIndex3].Number;
                            }
                            else
                            {
                                nodes[currentNodeIndex].Number = nodes[branchIndex4].Number;
                            }
                        }
                        else if (nodes[currentNodeIndex].OperatorIndex == 20)
                        {
                            if (nodes[branchIndex1].Number <= nodes[branchIndex2].Number)
                            {
                                nodes[currentNodeIndex].Number = nodes[branchIndex3].Number;
                            }
                            else
                            {
                                nodes[currentNodeIndex].Number = nodes[branchIndex4].Number;
                            }
                        }
                        else if (nodes[currentNodeIndex].OperatorIndex == 21)
                        {
                            if (nodes[branchIndex1].Number == 0)
                            {
                                nodes[currentNodeIndex].Number = nodes[branchIndex2].Number;
                            }
                            else
                            {
                                nodes[currentNodeIndex].Number = nodes[branchIndex3].Number;
                            }
                        }
                        else if (nodes[currentNodeIndex].OperatorIndex == 22)
                        {
                            if (nodes[branchIndex1].Number == 1)
                            {
                                nodes[currentNodeIndex].Number = nodes[branchIndex2].Number;
                            }
                            else
                            {
                                nodes[currentNodeIndex].Number = nodes[branchIndex3].Number;
                            }
                        }
                    }
                    if (nodes[currentNodeIndex].Number == double.NaN)
                    {
                        return(double.NaN);
                    }
                }

                if (nodes[currentNodeIndex].IsRoot == 1)
                {
                    return(nodes[currentNodeIndex].Number);
                }
            }
            return(double.NaN);
        }