
jason.functions.StdDev Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jason Show documentation
Show all versions of jason Show documentation
Jason is a programming language to develop BDI/cognitive agents
The newest version!
package jason.functions;
import jason.JasonException;
import jason.asSemantics.DefaultArithFunction;
import jason.asSemantics.TransitionSystem;
import jason.asSyntax.ListTerm;
import jason.asSyntax.NumberTerm;
import jason.asSyntax.Term;
/**
Function: math.std_dev(L)
: returns the standard deviation of all values of L.
Examples:
-
math.std_dev([1,2,3])
: returns 1.
-
math.std_dev([])
: returns 0.
@author Francisco Grimaldo
@see jason.functions.Min
@see jason.functions.Max
@see jason.functions.Sum
@see jason.functions.Average
*/
public class StdDev extends DefaultArithFunction {
public String getName() {
return "math.std_dev";
}
@Override
public double evaluate(TransitionSystem ts, Term[] args) throws Exception {
if (args[0].isList()) {
double sum = 0, squareSum = 0, num;
int n = 0;
for (Term t: (ListTerm)args[0])
if (t.isNumeric()) {
if (t.isNumeric()) {
num = ((NumberTerm)t).solve();
sum += num;
n++;
}
}
double mean = sum / n;
for (Term t: (ListTerm)args[0])
if (t.isNumeric()) {
num = ((NumberTerm)t).solve();
squareSum += (num - mean) * (num - mean);
}
return Math.sqrt( squareSum/(n - 1) );
}
throw new JasonException(getName()+" is not implemented for type '"+args[0]+"'.");
}
@Override
public boolean checkArity(int a) {
return a == 1;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy