Widget:WJG UserExamQuery: Difference between revisions

Jump to navigation Jump to search
No edit summary
No edit summary
Line 34: Line 34:
}
}
</style>
</style>
<script>
var testScores=[53.4,49.8,61.8,44.5,47.8,62.9,68.7,64.9,65.0,82.7,77.9,78.6,80.1,84.6];
// I define a function here that takes in an array of values, calculates the exponential moving average based on a certain half-life
// and returns an array with the exponential moving average at each point.
function calc_exp_moving_average(values,half_life){
var exp_avg_vals=new Array(values.length); //Initialize new array in which we'll put our calculated values
for (var i = values.length; i >(-1); i=i-1) {
exp_weights=[];
for (var j=0; j<i; j+=1){
var weight=Math.pow(half_life, i-j-1);
exp_weights[j]=weight;
};//Ends the calculation of the exponential weights for each timepoint.
var score_sum = 0;
var subvalues=values.slice(0,i+1);
var exp_weight_sum=0;
for(var i=0; i< exp_weights.length; i++) {
score_sum += exp_weights[i]*subvalues[i];
exp_weight_sum+=exp_weights[i];
}//Ends the multiplication of the weights by the scores.
var average_score=score_sum/exp_weight_sum;
if (i==0){average_score=values[i];}
exp_avg_vals[i]=average_score;
} //Ends the iteration through values.length
return exp_avg_vals.slice(1,exp_avg_vals.length+1);
}//Ends the function
exp_vals=calc_exp_moving_average(testScores,2/3);
</script>
<script type="text/javascript">
<script type="text/javascript">
function ensureLoggedIn() {
function ensureLoggedIn() {

Revision as of 13:58, 27 July 2014