示例#1
0
        public async Task <IEnumerable <MathErrorOutcome> > DoExperiment(IExperiment experiment)
        {
            if (!(experiment.ExperimentPositions?.Any() ?? false))
            {
                throw new Exception("No Experiment Positions generated.");
            }
            if (!IsDataSetCalculated)
            {
                throw new ApplicationException("DataSet is not calculated");
            }
            if (!IsANFISTrained)
            {
                throw new ApplicationException("ANFIS is not trained");
            }

            var mathematicalOutcomes = new List <IKinematicOutcome>();
            var anfisOutcomes        = new List <IKinematicOutcome>();

            experiment.ExperimentPositions.ToList().ForEach(point => {
                var anfisOut = CalculateAngelsUsingANFIS(point).GetAwaiter().GetResult();
                var mathOuts = CalculateArmJoint(point).GetAwaiter().GetResult()
                               .Select(x => new KinematicOutcome(x.Theta1.ConvertRadiansToDegrees(), x.Theta2.ConvertRadiansToDegrees(), x.JointPosition));
                var mathOut = mathOuts.OrderBy(x => x, new CustomSort(anfisOut)).FirstOrDefault();

                anfisOutcomes.Add(anfisOut);
                mathematicalOutcomes.Add(mathOut);
            });
            experiment.SetActualOutputs(mathematicalOutcomes);
            experiment.SetAnfisOutputs(anfisOutcomes);

            return(await experiment.CalculateError());
        }