public QsValue StdDeviation(int fromIndex, int toIndex) { var n = toIndex - fromIndex + 1; if (this.Parameters.Length > 0) { throw new QsException("Standard Deviation with symbolic quantities (I think you went so far ^_^ )", new NotImplementedException()); } else { FixIndices(ref fromIndex, ref toIndex); var mean = Average(fromIndex, toIndex); var Two = "2".ToScalarValue(); QsValue Total = (GetElementValue(fromIndex) - mean).PowerOperation(Two); for (int i = fromIndex + 1; i <= toIndex; i++) { var p = GetElementValue(i) - mean; var pp2 = p.PowerOperation(Two); Total = Total + pp2; } var count = new QsScalar { NumericalQuantity = Qs.ToQuantity((double)n) }; return(Total / count); } }
public QsValue Average(int fromIndex, int toIndex, QsValue arg0, QsValue arg1, QsValue arg2, QsValue arg3) { FixIndices(ref fromIndex, ref toIndex); var tot = SumElements(fromIndex, toIndex, arg0, arg1, arg2, arg3); var n = toIndex - fromIndex + 1; var count = new QsScalar { NumericalQuantity = Qs.ToQuantity((double)n) }; return(tot / count); }
/// <summary> /// Take the average of the sequence. /// Corresponds To: S[i!!k] /// </summary> /// <param name="fromIndex"></param> /// <param name="toIndex"></param> /// <returns></returns> public QsValue Average(int fromIndex, int toIndex) { var n = toIndex - fromIndex + 1; if (this.Parameters.Length > 0) { // this is a call to form symbolic element // like g[n](x) ..> x^n // and calling g[0++2] // the output should be x^0 + x^1 + x^2 // and be parsed into function (QsFunction) string porma = string.Empty; // the parameters separated by comma ',' foreach (var prm in this.Parameters) { porma += prm.Name + ", "; } porma = porma.TrimEnd(',', ' '); string FunctionBody = "(" + JoinElementsWithOperation(fromIndex, toIndex, "+") + ")/" + n.ToString(CultureInfo.InvariantCulture); string FunctionDeclaration = "_(" + porma + ") = " + FunctionBody; QsFunction qs = QsFunction.ParseFunction(QsEvaluator.CurrentEvaluator, FunctionDeclaration); return(qs); } else { FixIndices(ref fromIndex, ref toIndex); var tot = SumElements(fromIndex, toIndex); var count = new QsScalar { NumericalQuantity = Qs.ToQuantity((double)n) }; return(tot / count); } }
public QsValue StdDeviation(int fromIndex, int toIndex, QsValue arg0, QsValue arg1, QsValue arg2) { var n = toIndex - fromIndex + 1; FixIndices(ref fromIndex, ref toIndex); var mean = Average(fromIndex, toIndex, arg0, arg1, arg2); var Two = "2".ToScalarValue(); QsValue Total = (GetElementValue(fromIndex, arg0, arg1, arg2) - mean).PowerOperation(Two); for (int i = fromIndex + 1; i <= toIndex; i++) { var p = GetElementValue(i, arg0, arg1, arg2) - mean; var pp2 = p.PowerOperation(Two); Total = Total + pp2; } var count = new QsScalar { NumericalQuantity = Qs.ToQuantity((double)n) }; return(Total / count); }