Пример #1
0
        public override void CalculateGradients(Tensor nextLayerGradients)
        {
            for (int x = 0; x < In.Size.X; x++)
            {
                for (int y = 0; y < In.Size.Y; y++)
                {
                    Range range = MapToOutput(x, y);
                    for (int z = 0; z < In.Size.Z; z++)
                    {
                        float sum_error = 0;
                        for (int i = range.MinX; i <= range.MaxX; i++)
                        {
                            int minx = i * Stride;
                            for (int j = range.MinY; j <= range.MaxY; j++)
                            {
                                int miny = j * Stride;

                                int is_max = (In.Get(x, y, z) == Out.Get(i, j, z)) ? 1 : 0;
                                sum_error += is_max * nextLayerGradients.Get(i, j, z);
                            }
                        }
                        GradsIn.Set(x, y, z, sum_error);
                    }
                }
            }
        }
Пример #2
0
 public override void Activate()
 {
     for (int x = 0; x < Out.Size.X; x++)
     {
         for (int y = 0; y < Out.Size.Y; y++)
         {
             for (int z = 0; z < Out.Size.Z; z++)
             {
                 TdSize val = new TdSize {
                     X = x, Y = y, Z = 0
                 };
                 TdSize mapped = MapToInput(val, 0);
                 float  mval   = float.MinValue;
                 for (int i = 0; i < ExtendFilter; i++)
                 {
                     for (int j = 0; j < ExtendFilter; j++)
                     {
                         float v = In.Get(mapped.X + i, mapped.Y + j, z);
                         if (v > mval)
                         {
                             mval = v;
                         }
                     }
                 }
                 Out.Set(x, y, z, mval);
             }
         }
     }
 }
 public override void Activate()
 {
     for (int filter = 0; filter < Filters.Length; filter++)
     {
         Tensor currentFilter = Filters[filter];
         for (int x = 0; x < Out.Size.X; x++)
         {
             for (int y = 0; y < Out.Size.Y; y++)
             {
                 TdSize mapped = MapToInput(new TdSize {
                     X = x, Y = y, Z = 0
                 }, 0);
                 float sum = 0;
                 for (int i = 0; i < ExtendFilter; i++)
                 {
                     for (int j = 0; j < ExtendFilter; j++)
                     {
                         for (int z = 0; z < In.Size.Z; z++)
                         {
                             float f = currentFilter.Get(i, j, z);
                             float v = In.Get(mapped.X + i, mapped.Y + j, z);
                             sum += f * v;
                         }
                     }
                 }
                 Out.Set(x, y, filter, sum);
             }
         }
     }
 }
Пример #4
0
        static void Main(string[] args)
        {
            int height = In.Get <int>("Input your height: ");

            Console.WriteLine("Your height is {0}", height);
            Console.ReadLine();
        }
Пример #5
0
 public override void CalculateGradients(Tensor nextLayerGradients)
 {
     for (int i = 0; i < In.Size.X; i++)
     {
         for (int j = 0; j < In.Size.Y; j++)
         {
             for (int z = 0; z < In.Size.Z; z++)
             {
                 float value = (In.Get(i, j, z) < 0) ? 0 : nextLayerGradients.Get(i, j, z);
                 GradsIn.Set(i, j, z, value);
             }
         }
     }
 }
Пример #6
0
 public override void Activate()
 {
     for (int i = 0; i < In.Size.X; i++)
     {
         for (int j = 0; j < In.Size.Y; j++)
         {
             for (int z = 0; z < In.Size.Z; z++)
             {
                 float v = In.Get(i, j, z);
                 if (v < 0)
                 {
                     v = 0;
                 }
                 Out.Set(i, j, z, v);
             }
         }
     }
 }
Пример #7
0
        public override void Activate()
        {
            for (int n = 0; n < Out.Size.X; n++)
            {
                float inputV = 0;

                for (int i = 0; i < In.Size.X; i++)
                {
                    for (int j = 0; j < In.Size.Y; j++)
                    {
                        for (int z = 0; z < In.Size.Z; z++)
                        {
                            int m = Map(i, j, z);
                            inputV += In.Get(i, j, z) * Weights.Get(m, n, 0);
                        }
                    }
                }
                Input[n] = inputV;
                Out.Set(n, 0, 0, (float)Utilities.Sigmoid(inputV));
            }
        }
Пример #8
0
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (InputObject.Expression != null)
            {
                targetCommand.AddParameter("InputObject", InputObject.Get(context));
            }

            if (FilterScript.Expression != null)
            {
                targetCommand.AddParameter("FilterScript", FilterScript.Get(context));
            }

            if (Property.Expression != null)
            {
                targetCommand.AddParameter("Property", Property.Get(context));
            }

            if (Value.Expression != null)
            {
                targetCommand.AddParameter("Value", Value.Get(context));
            }

            if (EQ.Expression != null)
            {
                targetCommand.AddParameter("EQ", EQ.Get(context));
            }

            if (CEQ.Expression != null)
            {
                targetCommand.AddParameter("CEQ", CEQ.Get(context));
            }

            if (NE.Expression != null)
            {
                targetCommand.AddParameter("NE", NE.Get(context));
            }

            if (CNE.Expression != null)
            {
                targetCommand.AddParameter("CNE", CNE.Get(context));
            }

            if (GT.Expression != null)
            {
                targetCommand.AddParameter("GT", GT.Get(context));
            }

            if (CGT.Expression != null)
            {
                targetCommand.AddParameter("CGT", CGT.Get(context));
            }

            if (LT.Expression != null)
            {
                targetCommand.AddParameter("LT", LT.Get(context));
            }

            if (CLT.Expression != null)
            {
                targetCommand.AddParameter("CLT", CLT.Get(context));
            }

            if (GE.Expression != null)
            {
                targetCommand.AddParameter("GE", GE.Get(context));
            }

            if (CGE.Expression != null)
            {
                targetCommand.AddParameter("CGE", CGE.Get(context));
            }

            if (LE.Expression != null)
            {
                targetCommand.AddParameter("LE", LE.Get(context));
            }

            if (CLE.Expression != null)
            {
                targetCommand.AddParameter("CLE", CLE.Get(context));
            }

            if (Like.Expression != null)
            {
                targetCommand.AddParameter("Like", Like.Get(context));
            }

            if (CLike.Expression != null)
            {
                targetCommand.AddParameter("CLike", CLike.Get(context));
            }

            if (NotLike.Expression != null)
            {
                targetCommand.AddParameter("NotLike", NotLike.Get(context));
            }

            if (CNotLike.Expression != null)
            {
                targetCommand.AddParameter("CNotLike", CNotLike.Get(context));
            }

            if (Match.Expression != null)
            {
                targetCommand.AddParameter("Match", Match.Get(context));
            }

            if (CMatch.Expression != null)
            {
                targetCommand.AddParameter("CMatch", CMatch.Get(context));
            }

            if (NotMatch.Expression != null)
            {
                targetCommand.AddParameter("NotMatch", NotMatch.Get(context));
            }

            if (CNotMatch.Expression != null)
            {
                targetCommand.AddParameter("CNotMatch", CNotMatch.Get(context));
            }

            if (Contains.Expression != null)
            {
                targetCommand.AddParameter("Contains", Contains.Get(context));
            }

            if (CContains.Expression != null)
            {
                targetCommand.AddParameter("CContains", CContains.Get(context));
            }

            if (NotContains.Expression != null)
            {
                targetCommand.AddParameter("NotContains", NotContains.Get(context));
            }

            if (CNotContains.Expression != null)
            {
                targetCommand.AddParameter("CNotContains", CNotContains.Get(context));
            }

            if (In.Expression != null)
            {
                targetCommand.AddParameter("In", In.Get(context));
            }

            if (CIn.Expression != null)
            {
                targetCommand.AddParameter("CIn", CIn.Get(context));
            }

            if (NotIn.Expression != null)
            {
                targetCommand.AddParameter("NotIn", NotIn.Get(context));
            }

            if (CNotIn.Expression != null)
            {
                targetCommand.AddParameter("CNotIn", CNotIn.Get(context));
            }

            if (Is.Expression != null)
            {
                targetCommand.AddParameter("Is", Is.Get(context));
            }

            if (IsNot.Expression != null)
            {
                targetCommand.AddParameter("IsNot", IsNot.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
        public override void CalculateGradients(Tensor nextLayerGradients)
        {
            for (int k = 0; k < Gradients.Length; k++)
            {
                for (int i = 0; i < ExtendFilter; i++)
                {
                    for (int j = 0; j < ExtendFilter; j++)
                    {
                        for (int z = 0; z < In.Size.Z; z++)
                        {
                            Gradients[k].Set(i, j, z, 0);
                        }
                    }
                }
            }

            for (int x = 0; x < In.Size.X; x++)
            {
                for (int y = 0; y < In.Size.Y; y++)
                {
                    Range range = MapToOutput(x, y);
                    for (int z = 0; z < In.Size.Z; z++)
                    {
                        float sumError = 0;
                        for (int i = range.MinX; i <= range.MaxX; i++)
                        {
                            int minX = i * Stride;
                            for (int j = range.MinY; j <= range.MaxY; j++)
                            {
                                int minY = j * Stride;
                                for (int k = range.MinZ; k <= range.MaxZ; k++)
                                {
                                    int wApplied = (int)Filters[k].Get(x - minX, y - minY, z); //TODO eigentlich int
                                    sumError += wApplied * nextLayerGradients.Get(i, j, k);
                                    var oldValue = Gradients[k].Get(x - minX, y - minY, z);
                                    Gradients[k].Set(x - minX, y - minY, z, oldValue + In.Get(x, y, z) * nextLayerGradients.Get(i, j, k));
                                }
                            }
                        }
                        GradsIn.Set(x, y, z, sumError);
                    }
                }
            }
        }
Пример #10
0
 public override void FixWeights()
 {
     for (int n = 0; n < Out.Size.X; n++)
     {
         float gradient    = Gradients[n];
         float oldGradient = OldGradients[n];
         for (int i = 0; i < In.Size.X; i++)
         {
             for (int j = 0; j < In.Size.Y; j++)
             {
                 for (int z = 0; z < In.Size.Z; z++)
                 {
                     int   m = Map(i, j, z);
                     float w = Weights.Get(m, n, 0);
                     Weights.Set(m, n, 0, Utilities.UpdateWeight(w, gradient, oldGradient, In.Get(i, j, z)));
                 }
             }
         }
         oldGradient     = Utilities.UpdateGradient(gradient, oldGradient);
         OldGradients[n] = oldGradient;
     }
 }
Пример #11
0
 public override void Execute(INodeExecutionContext ctx)
 {
     OutValue = In.Get(ctx);
 }
Пример #12
0
 public override void Execute(INodeExecutionContext ctx)
 {
     Out.Set(ctx, In.Get(ctx));
 }