Annotation of loncom/homework/default_homework.lcpm, revision 1.44
1.42 albertel 1: # The LearningOnline Network with CAPA
1.1 harris41 2: # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
1.42 albertel 3: #
1.44 ! matthew 4: # $Id: default_homework.lcpm,v 1.43 2001/12/13 23:38:28 albertel Exp $
1.42 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.20 harris41 28: #
29: # Guy Albertelli
30: #
31: # 05/25/2001 H. K. Ng
1.24 ng 32: # 05/31/2001 H. K. Ng
1.44 ! matthew 33: # 12/21/2001 Matthew
1.20 harris41 34: #
1.25 albertel 35: #init some globals
1.38 albertel 36: $hidden::RANDOMINIT=0;
1.22 ng 37: $pi=atan2(1,1)*4;
38: $rad2deg=180.0/$pi;
39: $deg2rad=$pi/180.0;
1.44 ! matthew 40: $"=' ';
1.3 albertel 41:
1.7 albertel 42: sub caparesponse_check {
1.36 albertel 43: #not properly used yet: calc
44: #not to be used: $ans_fmt
1.39 albertel 45: my ($answer,$type,$tol,$sig,$ans_fmt,$unit,$calc,$samples) =
46: eval $_[1].
47: ';return ($answer,$type,$tol,$sig,$ans_fmt,$unit,$calc,$samples);';
1.36 albertel 48:
1.10 albertel 49: my $tol_type=''; # gets it's value from whether tol has a % or not done
1.19 albertel 50: my $sig_lbound=''; #done
51: my $sig_ubound=''; #done
1.7 albertel 52: my ($response,$expr)=@_;
1.31 albertel 53:
1.32 albertel 54:
1.8 albertel 55: #type's definitons come from capaParser.h
1.31 albertel 56: my $message='';
1.32 albertel 57: #remove leading and trailing whitespace
58: if ($response=~ /^\s|\s$/) {
59: $response=~ s:^\s+|\s+$::g;
60: $message .="Removed ws now :$response:<br />";
61: } else {
62: $message .="no ws in :$response:<br />";
63: }
64:
1.8 albertel 65: if ($type eq '' ) {
1.31 albertel 66: $message .= "Didn't find a type :$type:$expr: defaulting<br />";
1.8 albertel 67: if ( $answer eq ($answer *1.0)) { $type = 2;
68: } else { $type = 3; }
69: } else {
70: if ($type eq 'cs') { $type = 4;
71: } elsif ($type eq 'ci') { $type = 3;
72: } elsif ($type eq 'mc') { $type = 5;
73: } elsif ($type eq 'fml') { $type = 8;
1.9 albertel 74: } elsif ($type eq 'subj') { $type = 7;
1.41 albertel 75: } elsif ($type eq 'float') { $type = 2;
76: } elsif ($type eq 'int') { $type = 1;
1.9 albertel 77: } else { return "ERROR: Unknown type of answer: $type" }
1.8 albertel 78: }
79:
1.39 albertel 80: my $points;
81: my $id_list;
82: #formula type setup the sample points
83: if ($type eq '8') {
84: ($id_list,$points)=split(/@/,$samples);
85: $message.="Found :$points: points<br />";
86: }
1.10 albertel 87: if ($tol eq '') {
88: $tol=0.0;
89: $tol_type=1; #TOL_ABSOLUTE
90: } else {
91: if ($tol =~ /%$/) {
1.12 albertel 92: chop $tol;
1.10 albertel 93: $tol_type=2; #TOL_PERCENTAGE
94: } else {
95: $tol_type=1; #TOL_ABSOLUTE
96: }
97: }
1.12 albertel 98:
99: if ($sig eq '') {
100: $sig_lbound = 0; #SIG_LB_DEFAULT
101: $sig_ubound =15; #SIG_UB_DEFAULT
102: } else {
103: ($sig_lbound,$sig_ubound) = split /,/,$sig;
104: }
1.7 albertel 105: my $result = &caparesponse_capa_check_answer($response,$answer,$type,
1.10 albertel 106: $tol_type,$tol,
1.7 albertel 107: $sig_lbound,$sig_ubound,
1.39 albertel 108: $ans_fmt,$unit,$calc,$id_list,
109: $points,$external::randomseed);
1.9 albertel 110:
111: if ($result == '1') { $result='EXACT_ANS'; }
112: elsif ($result == '2') { $result='APPROX_ANS'; }
113: elsif ($result == '3') { $result='SIG_FAIL'; }
114: elsif ($result == '4') { $result='UNIT_FAIL'; }
115: elsif ($result == '5') { $result='NO_UNIT'; }
116: elsif ($result == '6') { $result='UNIT_OK'; }
117: elsif ($result == '7') { $result='INCORRECT'; }
118: elsif ($result == '8') { $result='UNIT_NOTNEEDED'; }
119: elsif ($result == '9') { $result='ANS_CNT_NOT_MATCH'; }
120: elsif ($result =='10') { $result='SUB_RECORDED'; }
121: elsif ($result =='11') { $result='BAD_FORMULA'; }
122: elsif ($result =='12') { $result='WANTED_NUMERIC'; }
1.13 albertel 123: else {$result = "ERROR: Unknown Result:$result:$@:";}
1.9 albertel 124:
1.36 albertel 125: return "$result:<br />Error $error:<br />Answer $answer:<br />Response $response:<br /> type-$type|$tol|$tol_type|$sig:$sig_lbound:$sig_ubound|$unit|<br />$message$expr";
1.14 albertel 126: }
127:
1.37 albertel 128: sub get_array_args {
129: my ($expr,$arg)=@_;
1.30 albertel 130: # do these first, because who knows what varname the instructor might have used
131: # but it probably isn't $CAPARESPONSE_CHECK_LIST_answer
1.37 albertel 132: my $CAPARESPONSE_CHECK_LIST_answer = eval $expr.';return $'.$arg; #'
1.40 albertel 133: my $GET_ARRAY_ARGS_result;
134: my @GET_ARRAY_ARGS_list;
1.39 albertel 135: if ($CAPARESPONSE_CHECK_LIST_answer =~ /^\s*[\$\@]/) {
1.40 albertel 136: (@GET_ARRAY_ARGS_list) = eval $CAPARESPONSE_CHECK_LIST_answer;
1.39 albertel 137: }
1.40 albertel 138: $GET_ARRAY_ARGS_result.="error:$@:<br />";
1.31 albertel 139: # if the eval fails just use what is in the answer exactly
1.40 albertel 140: if (!defined(@GET_ARRAY_ARGS_list) || !defined($GET_ARRAY_ARGS_list[0])) {
141: $GET_ARRAY_ARGS_result.="list zero is undefined<br />";
142: $GET_ARRAY_ARGS_list[0]=$CAPARESPONSE_CHECK_LIST_answer;
1.31 albertel 143: }
1.40 albertel 144: return $GET_ARRAY_ARGS_result,@GET_ARRAY_ARGS_list;
1.37 albertel 145: }
146:
147: sub caparesponse_check_list {
148: my ($response,$expr)=@_;
1.40 albertel 149: my $result;
150: my ($result,@list) = &get_array_args($expr,'answer');
1.15 albertel 151: my $aresult='';
1.14 albertel 152: my $current_answer;
1.39 albertel 153: my $answers=join(':',@list);
154: $result.="Got response :$answers:<br />";
1.31 albertel 155: my @responselist;
1.32 albertel 156: my $type =eval $expr.';return $answer;';
1.31 albertel 157: if ($type ne '' && $#list > 0) {
158: (@responselist)=split /,/,$response;
159: } else {
160: (@responselist)=($response);
161: }
1.15 albertel 162: my $unit='';
1.31 albertel 163: $result.="Initial final response :$responselist['-1']:<br />";
164: if ($type eq '') {
165: #for numerical problems split off the unit
166: if ( $responselist['-1']=~ /(.*[^\s])\s+([^\s]+)/ ) {
167: $responselist['-1']=$1;
168: $unit=$2;
169: }
1.15 albertel 170: }
1.31 albertel 171: $result.="Final final response :$responselist['-1']:<br />";
172: $result.=":$#list: answers<br />";
1.14 albertel 173: $unit=~s/\s//;
174: my $i=0;
175: my $awards='';
176: for ($i=0; $i<@list;$i++) {
1.31 albertel 177: $result.="trying answer :$list[$i]:<br />";
1.19 albertel 178: if ($unit eq '') {
179: $aresult=&caparesponse_check($responselist[$i],
1.31 albertel 180: $expr.';my $answer=\''.$list[$i].'\';');
1.19 albertel 181: } else {
182: $aresult=&caparesponse_check($responselist[$i]." $unit",
1.31 albertel 183: $expr.';my $answer=\''.$list[$i].'\';');
1.19 albertel 184: }
1.15 albertel 185: my ($temp)=split /:/, $aresult;
1.14 albertel 186: $awards.="$temp,";
1.15 albertel 187: $result.=$aresult;
1.14 albertel 188: }
189: chop $awards;
1.17 albertel 190: return "$awards:<br />$result";
1.7 albertel 191: }
192:
1.4 albertel 193: sub tex {
194: if ( $external::target eq "tex" ) {
195: return @_[0];
196: } else {
197: return @_[1];
198: }
199: }
200:
1.24 ng 201: sub var_in_tex {
202: if ( $external::target eq "tex" ) {
203: return @_[0];
204: } else {
205: return "";
206: }
207: }
208:
1.4 albertel 209: sub web {
210: if ( $external::target eq "tex" ) {
211: return @_[1];
212: } else {
1.43 albertel 213: if ( $external::target eq "web" || $external::target eq "answer") {
1.26 ng 214: return @_[2];
215: } else {
1.4 albertel 216: return @_[0];
217: }
218: }
219: }
220:
1.24 ng 221: sub html {
222: if ( $external::target eq "web" ) {
1.26 ng 223: return shift;
1.24 ng 224: }
225: }
226:
1.4 albertel 227: sub problem {
1.11 albertel 228: return '1';
1.4 albertel 229: }
230:
1.1 harris41 231: sub hinton {
232: return 0;
233: }
234:
235: sub random {
236: my ($start,$end,$step)=@_;
1.38 albertel 237: if ( ! $hidden::RANDOMINIT ) {
238: srand($external::randomseed);
239: $hidden::RANDOMINIT=1;
240: }
1.1 harris41 241: my $num=1+int(($end-$start)/$step);
242: my $result=$start + int(rand() * $num)*$step;
243: return $result;
244: }
245:
1.26 ng 246: sub random_normal {
247: my ($item_cnt,$seed,$av,$std_dev) = @_;
248: my @retArray;
249: &random_set_seed_from_phrase($seed);
250: @retArray=&math_random_normal($item_cnt,$av,$std_dev);
251: return @retArray;
252: }
253:
254: sub random_beta {
255: my ($item_cnt,$seed,$aa,$bb) = @_;
256: my @retArray;
257: &random_set_seed_from_phrase($seed);
258: @retArray=&math_random_beta($item_cnt,$aa,$bb);
259: return @retArray;
260: }
261:
262: sub random_gamma {
263: my ($item_cnt,$seed,$a,$r) = @_;
264: my @retArray;
265: &random_set_seed_from_phrase($seed);
266: @retArray=&math_random_gamma($item_cnt,$a,$r);
267: return @retArray;
268: }
269:
270: sub random_exponential {
271: my ($item_cnt,$seed,$av) = @_;
272: my @retArray;
273: &random_set_seed_from_phrase($seed);
274: @retArray=&math_random_exponential($item_cnt,$av);
275: return @retArray;
276: }
277:
278: sub random_poisson {
279: my ($item_cnt,$seed,$mu) = @_;
280: my @retArray;
281: &random_set_seed_from_phrase($seed);
282: @retArray=&math_random_poisson($item_cnt,$mu);
283: return @retArray;
284: }
285:
286: sub random_chi {
287: my ($item_cnt,$seed,$df) = @_;
288: my @retArray;
289: &random_set_seed_from_phrase($seed);
290: @retArray=&math_random_chi_square($item_cnt,$df);
291: return @retArray;
292: }
293:
294: sub random_noncentral_chi {
295: my ($item_cnt,$seed,$df,$nonc) = @_;
296: my @retArray;
297: &random_set_seed_from_phrase($seed);
298: @retArray=&math_random_noncentral_chi_square($item_cnt,$df,$nonc);
299: return @retArray;
300: }
301:
302: sub random_f {
303: my ($item_cnt,$seed,$dfn,$dfd) = @_;
304: my @retArray;
305: &random_set_seed_from_phrase($seed);
306: @retArray=&math_random_f($item_cnt,$dfn,$dfd);
307: return @retArray;
308: }
309:
310: sub random_noncentral_f {
311: my ($item_cnt,$seed,$dfn,$dfd,$nonc) = @_;
312: my @retArray;
313: &random_set_seed_from_phrase($seed);
314: @retArray=&math_random_noncentral_f($item_cnt,$dfn,$dfd,$nonc);
315: return @retArray;
316: }
317:
318: sub random_multivariate_normal {
1.33 ng 319: my ($item_cnt,$seed,$mean,$covar) = @_;
1.26 ng 320: &random_set_seed_from_phrase($seed);
1.33 ng 321: @retArray=&math_random_multivariate_normal($item_cnt,@$mean,@$covar);
1.26 ng 322: return @retArray;
323: }
324:
325: sub random_multinomial {
326: my ($item_cnt,$seed,@p) = @_;
327: my @retArray;
328: &random_set_seed_from_phrase($seed);
329: @retArray=&math_random_multinomial($item_cnt,@p);
330: return @retArray;
331: }
332:
333: sub random_permutation {
334: my ($seed,@inArray) = @_;
335: my @retArray;
336: &random_set_seed_from_phrase($seed);
337: @retArray=&math_random_permutation(@inArray);
338: return @retArray;
339: }
340:
341: sub random_uniform {
342: my ($item_cnt,$seed,$low,$high) = @_;
343: my @retArray;
344: &random_set_seed_from_phrase($seed);
345: @retArray=&math_random_uniform($item_cnt,$low,$high);
346: return @retArray;
347: }
348:
349: sub random_uniform_integer {
350: my ($item_cnt,$seed,$low,$high) = @_;
351: my @retArray;
352: &random_set_seed_from_phrase($seed);
353: @retArray=&math_random_uniform_integer($item_cnt,$low,$high);
354: return @retArray;
355: }
356:
357: sub random_binomial {
358: my ($item_cnt,$seed,$nt,$p) = @_;
359: my @retArray;
360: &random_set_seed_from_phrase($seed);
361: @retArray=&math_random_binomial($item_cnt,$nt,$p);
362: return @retArray;
363: }
364:
365: sub random_negative_binomial {
366: my ($item_cnt,$seed,$ne,$p) = @_;
367: my @retArray;
368: &random_set_seed_from_phrase($seed);
369: @retArray=&math_random_negative_binomial($item_cnt,$ne,$p);
370: return @retArray;
371: }
372:
1.23 ng 373: sub abs { abs(shift) }
374: sub sin { sin(shift) }
375: sub cos { cos(shift) }
376: sub exp { exp(shift) }
377: sub int { int(shift) }
378: sub log { log(shift) }
379: sub atan2 { atan2($_[0],$_[1]) }
380: sub sqrt { sqrt(shift) }
381:
1.1 harris41 382: sub tan { sin($_[0]) / cos($_[0]) }
1.21 harris41 383: #sub atan { atan2($_[0], 1); }
384: #sub acos { atan2(sqrt(1 - $_[0] * $_[0]), $_[0] ); }
385: #sub asin { atan2($_[0], sqrt(1- $_[0] * $_[0]) ); }
1.22 ng 386:
1.18 albertel 387: sub log10 { log($_[0])/log(10); }
1.22 ng 388:
1.20 harris41 389: sub factorial {
390: my $input = int(shift);
391: return "Error - unable to take factorial of an negative number ($input)" if $input < 0;
392: return "Error - factorial result is greater than system limit ($input)" if $input > 170;
393: return 1 if $input == 0;
394: my $result = 1;
395: for (my $i=2; $i<=$input; $i++) { $result *= $i }
396: return $result;
397: }
398:
399: sub sgn {
400: return -1 if $_[0] < 0;
401: return 0 if $_[0] == 0;
402: return 1 if $_[0] > 0;
403: }
404:
405: sub min {
406: my @sorted = sort { $a <=> $b || $a cmp $b } @_;
407: return shift @sorted;
408: }
409:
410: sub max {
411: my @sorted = sort { $a <=> $b || $a cmp $b } @_;
412: return pop @sorted;
413: }
1.1 harris41 414:
1.20 harris41 415: sub roundto {
416: my ($input,$n) = @_;
417: return sprintf('%.'.$n.'f',$input);
418: }
419:
420: sub to_string {
421: my ($input,$n) = @_;
1.26 ng 422: return sprintf($input) if $n eq "";
423: $n = '.'.$n if $n !~ /^\./;
1.20 harris41 424: return sprintf('%'.$n,$input) if $n ne "";
425: }
426:
427: sub sub_string {
428: my ($str,$start,$len) = @_;
429: return substr($str,$start-1,$len);
430: }
1.1 harris41 431:
432: sub pow {return $_[0] ** $_[1]; }
1.27 ng 433: sub ceil {return (($_[0]-int($_[0]))== 0.0) ? $_[0] : (($_[0] > 0) ? (int($_[0])+ 1) : int($_[0])); }
434: sub floor {return (($_[0]-int($_[0]))== 0.0) ? $_[0] : (($_[0] > 0) ? int($_[0]) : (int($_[0])-1)); }
435: #sub floor {return int($_[0]); }
1.1 harris41 436:
1.2 albertel 437: sub format {
438: my ($value,$fmt)=@_;
1.11 albertel 439: return sprintf('%.'.$fmt,$value);
1.2 albertel 440: }
1.5 albertel 441:
442: sub map {
1.27 ng 443: my ($phrase,$dest,$source)=@_;
444: my @seed = &random_seed_from_phrase($phrase);
445: &random_set_seed(@seed);
446: my $destct = scalar(@$dest);
1.28 ng 447: if (!$source) {
448: my @output;
449: my @idx = &math_random_permuted_index($destct);
450: my $ctr = 0;
451: while ($ctr < $destct) {
452: $output[$ctr] = $$dest[$idx[$ctr]];
1.27 ng 453: $ctr++;
1.28 ng 454: }
455: return @output;
1.27 ng 456: } else {
1.28 ng 457: my $num = scalar(@$source);
458: my @idx = &math_random_permuted_index($num);
459: my $ctr = 0;
460: my $tot = $num;
461: $tot = $destct if $destct < $num;
462: if (ref($$dest[0])) {
463: while ($ctr < $tot) {
464: ${$$dest[$ctr]} = $$source[$idx[$ctr]];
465: $ctr++;
466: }
467: } else {
468: while ($ctr < $tot) {
469: $$dest[$ctr] = $$source[$idx[$ctr]];
470: $ctr++;
471: }
472: }
1.27 ng 473: }
474: }
475:
476: sub rmap {
477: my ($phrase,$dest,$source)=@_;
478: my @seed = &random_seed_from_phrase($phrase);
479: &random_set_seed(@seed);
480: my $destct = scalar(@$dest);
1.28 ng 481: if (!$source) {
482: my @idx = &math_random_permuted_index($destct);
483: my $ctr = 0;
484: my @r_idx;
485: while ($ctr < $destct) {
486: $r_idx[$idx[$ctr]] = $ctr;
487: $ctr++;
488: }
489: my @output;
490: $ctr = 0;
491: while ($ctr < $destct) {
492: $output[$ctr] = $$dest[$r_idx[$ctr]];
1.27 ng 493: $ctr++;
1.28 ng 494: }
495: return @output;
1.27 ng 496: } else {
1.28 ng 497: my $num = scalar(@$source);
498: my @idx = &math_random_permuted_index($num);
499: my $ctr = 0;
500: my $tot = $num;
501: $tot = $destct if $destct < $num;
502: my @r_idx;
1.27 ng 503: while ($ctr < $tot) {
1.28 ng 504: $r_idx[$idx[$ctr]] = $ctr;
1.27 ng 505: $ctr++;
1.28 ng 506: }
507: $ctr = 0;
508: if (ref($$dest[0])) {
509: while ($ctr < $tot) {
510: ${$$dest[$ctr]} = $$source[$r_idx[$ctr]];
511: $ctr++;
512: }
513: } else {
514: while ($ctr < $tot) {
515: $$dest[$ctr] = $$source[$r_idx[$ctr]];
516: $ctr++;
517: }
518: }
1.6 albertel 519: }
1.5 albertel 520: }
1.22 ng 521:
1.23 ng 522: sub capa_id { return }
523:
524: sub problem { return }
525:
1.22 ng 526: sub name{
527: my $fullname = &EXT('environment.lastname').', '.&EXT('environment.firstname').' '.&EXT('environment.middlename');
528: $fullname = "" if $fullname eq ", ";
1.26 ng 529: $fullname =~ s/\%2d/-/g;
1.22 ng 530: return $fullname;
531: }
532:
533: sub student_number {
534: my $id = &EXT('environment.id');
535: $id = '' if $id eq "";
536: return $id;
537: }
538:
539: sub class {
540: my $course = &EXT('course.description');
541: $course = '' if $course eq "";
542: return $course;
543: }
544:
545: sub sec {
546: my $sec = &EXT('request.course.sec');
1.23 ng 547: $sec = '' if $sec eq "";
1.22 ng 548: return $sec;
549: }
550:
1.23 ng 551: sub open_date {
552: my @dc = split(/\s+/,localtime(&EXT('resource.0.opendate')));
1.24 ng 553: return '' if ($dc[0] eq "Wed" and $dc[2] == 31 and $dc[4] == 1969);
554: my @hm = split(/:/,$dc[3]);
555: my $ampm = " am";
556: if ($hm[0] > 12) {
557: $hm[0]-=12;
558: $ampm = " pm";
559: }
560: return $dc[0].', '.$dc[1].' '.$dc[2].', '.$dc[4].' at '.$hm[0].':'.$hm[1].$ampm;
1.23 ng 561: }
562:
563: sub due_date {
564: my @dc = split(/\s+/,localtime(&EXT('resource.0.duedate')));
1.24 ng 565: return '' if ($dc[0] eq "Wed" and $dc[2] == 31 and $dc[4] == 1969);
566: my @hm = split(/:/,$dc[3]);
567: my $ampm = " am";
568: if ($hm[0] > 12) {
569: $hm[0]-=12;
570: $ampm = " pm";
571: }
572: return $dc[0].', '.$dc[1].' '.$dc[2].', '.$dc[4].' at '.$hm[0].':'.$hm[1].$ampm;
573: # return $dc[0].', '.$dc[1].' '.$dc[2].', '.$dc[4].' at '.$dc[3];
1.23 ng 574: }
575:
576: sub answer_date {
577: my @dc = split(/\s+/,localtime(&EXT('resource.0.answerdate')));
1.24 ng 578: return '' if ($dc[0] eq "Wed" and $dc[2] == 31 and $dc[4] == 1969);
579: my @hm = split(/:/,$dc[3]);
580: my $ampm = " am";
581: if ($hm[0] > 12) {
582: $hm[0]-=12;
583: $ampm = " pm";
584: }
585: return $dc[0].', '.$dc[1].' '.$dc[2].', '.$dc[4].' at '.$hm[0].':'.$hm[1].$ampm;
586: # return $dc[0].', '.$dc[1].' '.$dc[2].', '.$dc[4].' at '.$dc[3];
587: }
588:
589: sub array_moments {
590: my @input=@_;
591: my (@output,$N);
592: $N=scalar (@input);
593: $output[0]=$N;
594: if ($N <= 1) {
595: $output[1]=$input[0];
1.28 ng 596: $output[1]="Input array not defined" if ($N == 0);
1.24 ng 597: $output[2]="variance undefined for N<=1";
598: $output[3]="skewness undefined for N<=1";
599: $output[4]="kurtosis undefined for N<=1";
600: return @output;
601: }
602: my $sum=0;
603: foreach my $line (@input) {
604: $sum+=$line;
605: }
606: $output[1] = $sum/$N;
607: my ($x,$sdev,$var,$skew,$kurt) = 0;
608: foreach my $line (@input) {
609: $x=$line-$output[1];
610: $var+=$x**2;
611: $skew+=$x**3;
612: $kurt+=$x**4;
613: }
614: $output[2]=$var/($N-1);
615: $sdev=sqrt($output[2]);
616: if ($sdev == 0) {
617: $output[3]="inf-variance=0";
618: $output[4]="inf-variance=0";
619: return @output;
620: }
621: $output[3]=$skew/($sdev**3*$N);
622: $output[4]=$kurt/($sdev**4*$N)-3;
623: return @output;
624: }
1.5 albertel 625:
626: sub choose {
627: my $num = $_[0];
628: return $_[$num];
629: }
1.23 ng 630:
631:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>