/// <summary> /// Calculate the error of ANFIS against the mathematical solution /// </summary> /// <returns></returns> public async Task <IEnumerable <MathErrorOutcome> > CalculateMathError() { 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>(); Positions.ToList().ForEach((endPoint) => { var anfisOut = CalculateAngelsUsingANFIS(endPoint).GetAwaiter().GetResult(); var mathOuts = CalculateArmJoint(endPoint).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); }); return(await _fuzzyHelper.CalculateMathError(mathematicalOutcomes, anfisOutcomes)); }