Ejemplo n.º 1
0
        public static NewtonResult[][] ExecuteChunk([ActivityTrigger] ChunkOptions options, ILogger log)
        {
            var fractalOptions = options.FractalOptions;
            var element        = MathElement.Parse(fractalOptions.Expression, fractalOptions.VariableName);
            var func           = element.ToNewtonFunction(fractalOptions.Multiplicity).ToFunc();

            var result = new NewtonResult[options.MaxWidth - options.MinWidth][];

            for (var px = options.MinWidth; px < options.MaxWidth; ++px)
            {
                var x = fractalOptions.DomainSize.MinX + (fractalOptions.DomainSize.MaxX - fractalOptions.DomainSize.MinX) * px / (fractalOptions.PixelSize.Width - 1);
                result[px - options.MinWidth] = new NewtonResult[fractalOptions.PixelSize.Height];
                for (var py = 0; py < fractalOptions.PixelSize.Height; ++py)
                {
                    var y             = fractalOptions.DomainSize.MaxY - (fractalOptions.DomainSize.MaxY - fractalOptions.DomainSize.MinY) * py / (fractalOptions.PixelSize.Height - 1);
                    var newtonOptions = new NewtonOptions
                    {
                        Precision     = fractalOptions.Precision,
                        StartingPoint = new Complex(x, y),
                        MaxIterations = fractalOptions.MaxIterations,
                    };
                    result[px - options.MinWidth][py] = MathUtils.NewtonMethod(func, newtonOptions);
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        private static List <ISolver> DeafaultSolvers()
        {
            var opts = new NewtonOptions()
            {
                MaxIterations = 20, DerivativeStep = new double[] { 0.01 }
            };
            var solver = new NewtonSolver(opts);

            return(new List <ISolver>()
            {
                solver
            });
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Provides the revesed model, according to the specified variables
        /// </summary>
        public WorkflowReversedModel Reverse(List <Data> inputs, List <Data> outputs)
        {
            var opts = new NewtonOptions()
            {
                MaxIterations = 20, DerivativeStep = new double[] { 0.01 }
            };
            var    solver        = new NewtonSolver(opts);
            string reversedName  = GetReversedName(inputs, outputs);
            var    reversedModel = new WorkflowReversedModel(reversedName, Description, inputs, outputs, this, new List <ISolver>()
            {
                solver
            });

            reversedModel.Rename(FullName + new string(reversedName.SkipWhile(c => c != ':').ToArray()));
            return(reversedModel);
        }
Ejemplo n.º 4
0
        private static List <ISolver> DeafaultSolversSCC()
        {
            var solver = new FixedPointSolver()
            {
                MaxEvals = 20
            };
            var opts = new NewtonOptions()
            {
                MaxIterations = 20, DerivativeStep = new double[] { 0.01 }
            };
            var solver2 = new NewtonSolver(opts);

            return(new List <ISolver>()
            {
                solver, solver2
            });
        }
        private NewtonResult[] NewtonBandInternal(int px)
        {
            var x      = Options.DomainSize.MinX + (Options.DomainSize.MaxX - Options.DomainSize.MinX) * px / (Options.PixelSize.Width - 1);
            var result = new NewtonResult[Options.PixelSize.Height];

            for (var py = 0; py < Options.PixelSize.Height; ++py)
            {
                var y             = Options.DomainSize.MaxY - (Options.DomainSize.MaxY - Options.DomainSize.MinY) * py / (Options.PixelSize.Height - 1);
                var newtonOptions = new NewtonOptions
                {
                    Precision     = Options.Precision,
                    StartingPoint = new Complex(x, y),
                    MaxIterations = Options.MaxIterations,
                };
                result[py] = MathUtils.NewtonMethod(Function, newtonOptions);
            }

            return(result);
        }
Ejemplo n.º 6
0
        public void NewtonMethodTests(string expression, double multiplicity, double startingPoint, double expected)
        {
            // Only testing the real part, as it makes it simpler to pass compile-time
            // inputs. The outcome should be the same for complex numbers, especially
            // given that the Complex library already existed

            var element = MathElement.Parse(expression);
            var newton  = element.ToNewtonFunction(new Complex(multiplicity, 0));
            var func    = newton.ToFunc();

            var options = new NewtonOptions
            {
                MaxIterations = 50,
                Precision     = 1e-3,
                StartingPoint = new Complex(startingPoint, 0),
            };

            var result = MathUtils.NewtonMethod(func, options);

            Assert.AreEqual(expected, result.Solution.Real, 1e-2);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This function identifies the Modified models (from imMatrixi and imMatrif) in the modelObjects, then creates a 'modified model subprocess' for each modified model,
        /// and therafter combines it with other models in the modelObjects and return it in a object array
        /// </summary>
        /// <param name="IMi"></param>
        /// <param name="IMf"></param>
        /// <param name="components"></param>
        /// <param name="data"></param>
        /// <param name="clusters"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private static WorkflowComponent[] CreateReversedModels(IncidenceMatrix IMi, IncidenceMatrix IMf, List <WorkflowComponent> components, List <Data> data, List <Cluster> clusters, string name)
        {
            var processedComponents = new WorkflowComponent[IMf.RowCount];

            for (int r = 0; r < IMi.RowCount; r++)
            {
                WorkflowComponent component = components[r];
                Vector <double>   row       = IMi.Row(r);
                if (!IMf.Row(r).CompareAssigned(row))
                {
                    List <int> inputIndices  = row.FindLocations(IN);
                    List <int> outputIndices = row.FindLocations(OUT);
                    var        inputs        = inputIndices.Select(i => data[i]).ToList();
                    var        outputs       = outputIndices.Select(i => data[i]).ToList();

                    if (component is Model model)
                    {
                        processedComponents[r] = model.Reverse(inputs, outputs);
                    }
                    else if (component is Workflow workflow)
                    {
                        var opts = new NewtonOptions()
                        {
                            MaxIterations = 20, DerivativeStep = new double[] { 0.01 }
                        };
                        var solver = new NewtonSolver(opts);
                        processedComponents[r] = new WorkflowGlobal($"{name}#GlobalWorkflow#{workflow.Name}", "", inputs, outputs, workflow.Components, workflow.Components, new List <ISolver>()
                        {
                            solver
                        });
                    }
                }
                else
                {
                    processedComponents[r] = components[r];
                }
            }
            return(processedComponents);
        }
Ejemplo n.º 8
0
        protected virtual Task <NewtonResult[][]> GenerateNewtonArrayAsync()
        {
            var result = new NewtonResult[Options.PixelSize.Width][];

            for (var px = 0; px < Options.PixelSize.Width; ++px)
            {
                var x = Options.DomainSize.MinX + (Options.DomainSize.MaxX - Options.DomainSize.MinX) * px / (Options.PixelSize.Width - 1);
                result[px] = new NewtonResult[Options.PixelSize.Height];
                for (var py = 0; py < Options.PixelSize.Height; ++py)
                {
                    var y             = Options.DomainSize.MaxY - (Options.DomainSize.MaxY - Options.DomainSize.MinY) * py / (Options.PixelSize.Height - 1);
                    var newtonOptions = new NewtonOptions
                    {
                        Precision     = Options.Precision,
                        StartingPoint = new Complex(x, y),
                        MaxIterations = Options.MaxIterations,
                    };
                    result[px][py] = MathUtils.NewtonMethod(Function, newtonOptions);
                }
            }

            return(Task.FromResult(result));
        }