Beispiel #1
0
            public override void Next <T>(Propagate prop)
            {
                switch (prop)
                {
                case Propagate.Error:
                    for (int c = 0, i = 0; i < sources.Count; i++)
                    {
                        for (int j = 0; j < sources[i].Columns; j++)
                        {
                            for (int k = 0; k < sources[i].Rows; k++)
                            {
                                ((double?[])sources[i].GetElement(k, j).Element)[ANN.Global.Err] =
                                    ((double?[])target.GetElement(c++, 0).Element)[ANN.Global.Err].Value;
                            }
                        }
                    }
                    return;

                case Propagate.Signal:
                    for (int c = 0, i = 0; i < sources.Count; i++)
                    {
                        for (int j = 0; j < sources[i].Columns; j++)
                        {
                            for (int k = 0; k < sources[i].Rows; k++)
                            {
                                ((double?[])target.GetElement(c++, 0).Element)[ANN.Global.Sig] =
                                    ((double?[])sources[i].GetElement(k, j).Element)[ANN.Global.Sig].Value;
                            }
                        }
                    }
                    return;
                }
            }
Beispiel #2
0
            public override void Next <T>(Propagate prop)
            {
                switch (prop)
                {
                case Propagate.Error:
                    for (int i = 0; i < target.Rows; i++)
                    {
                        for (int j = 0; j < target.Columns; j++)
                        {
                            kernels[0].Next(((double?[])target.GetElement(i, j).Element)[Global.Err].Value, i, j);
                        }
                    }
                    break;

                case Propagate.Signal:
                    for (int i = 0; i < target.Rows; i++)
                    {
                        for (int j = 0; j < target.Columns; j++)
                        {
                            target.WriteAt <double?>(i, j, Global.Sig, kernels[0].Next(i, j));
                        }
                    }
                    break;
                }
            }
Beispiel #3
0
            public override void Next <T>(Propagate prop)
            {
                switch (prop)
                {
                case Propagate.Error:
                    // 0. set gradients
                    double x;
                    for (int i = 0; i < target.Rows; i++)
                    {
                        for (int j = 0; j < target.Columns; j++)
                        {
                            x          = function.Next(((double?[])target.GetElement(i, j).Element)[Global.Sig].Value);
                            grad[i][j] = x * ((double?[])target.GetElement(i, j).Element)[Global.Err].Value;
                        }
                    }
                    // 1.
                    // 1a. compute bias weight
                    x = 0.0;
                    for (int i = 0; i < grad.Length; i++)
                    {
                        for (int j = 0; j < grad[i].Length; j++)
                        {
                            x += grad[i][j].Value;
                        }
                    }
                    ((Kernel)kernels[0]).WeightCorrection[0][0] = x;
                    // 1b. backprop error
                    for (int i = 0; i < grad.Length; i++)
                    {
                        for (int j = 0; j < grad[i].Length; j++)
                        {
                            for (int k = 1; k < kernels.Count; k++)
                            {
                                kernels[k].Next(grad[i][j].Value, i, j);
                            }
                        }
                    }
                    break;

                case Propagate.Signal:
                    function.Input[0] = kernels[0].Next(0, 0);

                    for (int i = 0; i < target.Rows; i++)
                    {
                        for (int j = 0; j < target.Columns; j++)
                        {
                            for (int k = 1; k < kernels.Count; k++)
                            {
                                function.Input[k] = kernels[k].Next(i, j);
                            }
                            target.WriteAt <double?>(i, j, Global.Sig, function.Next());
                        }
                    }
                    break;
                }
            }
        public OperationResult <Tuple <string, DateTime> > PassSuccessfullMergedOperation()
        {
            var innerResult = this._dependencyLogic.SomeSuccessfullReadOperation();

            if (innerResult.Success)
            {
                return(new Tuple <string, DateTime>(innerResult.Value, DateTime.Now));
            }
            else
            {
                return(Propagate.Fail(innerResult)); // 1st method, proffered
            }
        }
Beispiel #5
0
            public override void Next <T>(Propagate prop)
            {
                Foundation.Node[] n;

                switch (prop)
                {
                case Propagate.Error:

                    double x, y;

                    for (int i = 0; i < target.Rows; i++)
                    {
                        for (int j = 0; j < target.Columns; j++)
                        {
                            x = ((double?[])target.GetElement(i, j).Element)[Global.Err].Value;
                            y = function.Next(x);
                            n = kernel[0].GetSourceNodes(i * stride.Value, j * stride.Value);
                            for (int c = 0, u = 0; u < kernelSize.Value; u++)
                            {
                                for (int v = 0; v < kernelSize.Value; v++)
                                {
                                    ((double?[])n[c++].Element)[Global.Err] += y;
                                }
                            }
                        }
                    }

                    return;

                case Propagate.Signal:

                    int      nr = rows.Value - kernelSize.Value;
                    int      nc = cols.Value - kernelSize.Value;
                    double[] output;
                    for (int i = 0; i <= nr; i += stride.Value)
                    {
                        for (int j = 0; j <= nc; j += stride.Value)
                        {
                            output = kernel[0].Output(i, j);
                            for (int k = 0; k < output.Length; k++)
                            {
                                function.Input[k] = output[k];
                            }
                            Target.WriteAt <double?>(i / stride.Value, j / stride.Value, 0, function.Next());
                        }
                    }

                    return;
                }
            }
Beispiel #6
0
        public override bool Run()
        {
            // There is no input assumed. This is a dedicated rotation rate sensor.

            // get aircraft rates
            Rates = Propagate.GetPQRi();

            // transform to the specified orientation
            vRates = sensorOrientation.mT * Rates;

            input = vRates[sensorOrientation.axis - 1];

            ProcessSensorSignal();

            SetOutput();

            return(true);
        }
Beispiel #7
0
        public override bool Run()
        {
            // There is no input assumed. This is a dedicated acceleration sensor.

            vRadius = MassBalance.StructuralToBody(vLocation);

            //aircraft forces
            vAccel = (Accelerations.GetBodyAccel()
                      + Accelerations.GetPQRidot() * vRadius
                      + Propagate.GetPQRi() * (Propagate.GetPQRi() * vRadius));

            // transform to the specified orientation
            vAccel = sensorOrientation.mT * vAccel;

            input = vAccel[sensorOrientation.axis - 1];

            ProcessSensorSignal();

            SetOutput();

            return(true);
        }
Beispiel #8
0
            public override void Next <T>(Propagate prop)
            {
                double x; double?[][] y; double?[][] c; Foundation.Node[] n;

                Synapse[,] s;

                switch (prop)
                {
                case Propagate.Error:

                    // 0. set gradients
                    c = (double?[][])Gradient;
                    for (int i = 0; i < target.Rows; i++)
                    {
                        for (int j = 0; j < target.Columns; j++)
                        {
                            x       = function.Next(((double?[])target.GetElement(i, j).Element)[Global.Sig].Value);
                            c[i][j] = x * ((double?[])target.GetElement(i, j).Element)[Global.Err].Value;
                        }
                    }

                    // 1. set weight correction in bias
                    x = 0.0;
                    for (int i = 0; i < c.Length; i++)
                    {
                        for (int j = 0; j < c[i].Length; j++)
                        {
                            x += c[i][j].Value;
                        }
                    }
                    ((Kernel)kernel[0]).WeightCorrection = x;

                    // 2. set weight correction in kernels
                    for (int i = 1; i < kernel.Count; i++)
                    {
                        y = (double?[][])((Kernel)kernel[i]).WeightCorrection;
                        // set weight corrections to zero
                        for (int j = 0; j < y.Length; j++)
                        {
                            for (int k = 0; k < y[j].Length; k++)
                            {
                                y[j][k] = 0.0;
                            }
                        }

                        for (int j = 0; j < c.Length; j++)
                        {
                            for (int k = 0; k < c[j].Length; k++)
                            {
                                x = c[j][k].Value;
                                n = ((Kernel)kernel[i]).GetSourceNodes(j * stride.Value, k * stride.Value);
                                for (int m = 0, u = 0; u < y.Length; u++)
                                {
                                    for (int v = 0; v < y[u].Length; v++)
                                    {
                                        if (n[m] == null)
                                        {
                                            continue;
                                        }
                                        y[u][v] += x * ((double?[])n[m++].Element)[Global.Sig].Value;
                                    }
                                }
                            }
                        }
                    }

                    // 3. propagate error to previous layer
                    for (int i = 1; i < kernel.Count; i++)
                    {
                        s = ((Kernel)kernel[i]).Synapse;

                        for (int j = 0; j < c.Length; j++)
                        {
                            for (int k = 0; k < c[j].Length; k++)
                            {
                                x = c[j][k].Value;
                                n = ((Kernel)kernel[i]).GetSourceNodes(j * stride.Value, k * stride.Value);     // nodes is fMap
                                for (int m = 0, u = 0; u < s.GetLength(0); u++)
                                {
                                    for (int v = 0; v < s.GetLength(1); v++)
                                    {
                                        if (n[m] == null)
                                        {
                                            continue;
                                        }
                                        ((double?[])n[m++].Element)[Global.Err] += x * s[u, v].Weights[0].Value;
                                    }
                                }
                            }
                        }
                    }

                    return;

                case Propagate.Signal:

                    function.Input[0] = kernel[0].Output(0, 0)[0];

                    for (int i = 0; i < rows.Value; i += stride.Value)
                    {
                        for (int j = 0; j < cols.Value; j += stride.Value)
                        {
                            for (int k = 1; k < kernel.Count; k++)
                            {
                                function.Input[k] = kernel[k].Output(i, j)[0];
                            }
                            Target.WriteAt <double?>(i / stride.Value, j / stride.Value, 0, function.Next());
                        }
                    }

                    return;
                }
            }
Beispiel #9
0
        private bool Allocate()
        {
            bool result = true;

            atmosphere      = new Atmosphere(this);
            propulsion      = new Propulsion(this);
            aerodynamics    = new Aerodynamics(this);
            FCS             = new FlightControlSystem(this);
            groundReactions = new GroundReactions(this);
            inertial        = new Inertial(this);
            massBalance     = new MassBalance(this);
            propagate       = new Propagate(this);
            auxiliary       = new Auxiliary(this);
            aircraft        = new Aircraft(this);
            //output = new Output(this);
            input          = new Input(this);
            groundCallback = new GroundCallback();
            state          = new State(this); // This must be done here, as the State
            // class needs valid pointers to the above model classes


            // Initialize models so they can communicate with each other

            if (!atmosphere.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Atmosphere model init failed");
                }
                error += 1;
            }
            if (!FCS.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("FCS model init failed");
                }
                error += 2;
            }
            if (!propulsion.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Propulsion model init failed");
                }
                error += 4;
            }
            if (!massBalance.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("MassBalance model init failed");
                }
                error += 8;
            }
            if (!aerodynamics.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Aerodynamics model init failed");
                }
                error += 16;
            }
            if (!inertial.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Inertial model init failed");
                }
                error += 32;
            }
            if (!groundReactions.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Ground Reactions model init failed");
                }
                error += 64;
            }
            if (!aircraft.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Aircraft model init failed");
                }
                error += 128;
            }
            if (!propagate.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Propagate model init failed");
                }
                error += 256;
            }
            if (!auxiliary.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Auxiliary model init failed");
                }
                error += 512;
            }
            if (!input.InitModel())
            {
                if (log.IsErrorEnabled)
                {
                    log.Error("Intput model init failed");
                }
                error += 1024;
            }

            if (error > 0)
            {
                result = false;
            }

            ic = new InitialCondition(this);

            // Schedule a model. The second arg (the integer) is the pass number. For
            // instance, the atmosphere model gets executed every fifth pass it is called
            // by the executive. Everything else here gets executed each pass.
            // IC and Trim objects are NOT scheduled.

            Schedule(input, 1);
            Schedule(atmosphere, 1);
            Schedule(FCS, 1);
            Schedule(propulsion, 1);
            Schedule(massBalance, 1);
            Schedule(aerodynamics, 1);
            Schedule(inertial, 1);
            Schedule(groundReactions, 1);
            Schedule(aircraft, 1);
            Schedule(propagate, 1);
            Schedule(auxiliary, 1);
            //Schedule(output, 1);

            modelLoaded = false;
            return(result);
        }
Beispiel #10
0
 public abstract void Next <T>(Propagate prop);