Dr. Arne Jachens

Arnes Skriptbibliothek

searchMedian

Wird verwendet von:

Having timeseries of measurements for multiple samples this routine calculates the median and probabilities (0.25, 0.75, minimum, maximum) for a wiskersplot of the samples for all points in time.

inputdimension
$NoSamplesnumber of samples - should be > 4
$NoMeasurementsnumber of measurements for each sample - should be > 0
$datameasured data[$NoSamples][$NoMeasurements]
$flagdecide to concern all or only ["pos"|"neg"] values, default is all
$typesome string as extension for the output, can be left blank
$pathpath for all the output to go, can be left blank
output 
$p050median value at each point in time[$NoMeasurements]
$p025value at p=0.25 at each point in time[$NoMeasurements]
$p075value at p=0.75 at each point in time[$NoMeasurements]
$p000minimal value at each point in time[$NoMeasurements]
$p100maximal value at each point in time[$NoMeasurements]

Afterwards there is the output data median1.dat and the plotting script plotMedian1.sh in $path. The Wiskersplot can also be done by using xmgrace.

<?php
function searchMedian($data,$flag,$type,$path){
  $NN=count($data);    #number of measurements
  $MM=count($data[0]); #number of samples
  for($n=0; $n<$NN; $n++){
    $i=-1;
    for($m=0; $m<$MM; $m++){
      switch ($flag){
      case all:
	$i++;
	$vector[$i]=$data[$n][$m];
	break;
      case pos:
	if ($data[$n][$m]>0.0){
	  $i++;
	  $vector[$i]=$data[$n][$m];
	}
	break;
      case neg:
	if ($data[$n][$m]<0.0){
	  $i++;
	  $vector[$i]=$data[$n][$m];
	}
	break;
      }
    } //m
    sort($vector);
    $i=count($vector)+1;
    $alpha1=floor($i/4);
    $alpha2=floor($i/2);
    $alpha3=floor($i*3/4);
    $beta1=$i/4-floor($i/4);
    $beta2=$i/2-floor($i/2);
    $beta3=$i*3/4-floor($i*3/4);
    $a000[$n]=$vector[0];
    $a025[$n]=(1-$beta1)*$vector[$alpha1-1]+$beta1*$vector[$alpha1];
    $a050[$n]=(1-$beta2)*$vector[$alpha2-1]+$beta2*$vector[$alpha2];
    $a075[$n]=(1-$beta3)*$vector[$alpha3-1]+$beta3*$vector[$alpha3];
    $a100[$n]=$vector[$i-2];
    #print_r($vector);
    #echo "beta ".$beta2." ".$a050[$n]."\n";
  }//n


  /* save result */
  $file=$path."median".$type.".dat";
  $fid = fopen($file, "w");
  for($n=0;$n<$NN;$n++){
    $nn=$n+1;
    $string=sprintf("%d %f %f %f %f %f \n",$nn,$a050[$n],$a025[$n],$a075[$n],$a000[$n],$a100[$n]);
    //printf("%s ",$string);
    fputs($fid,$string);
  } //n
  fclose($fid);

  /* show result */

  $nn++;
  $plot ="set key right top\n";
  $plot.=" #set term pdf\n";
  $plot.=" #set term epslatex color solid 12 size 12cm,8cm\n";
  $plot.=" #set output '".$path."plotMedian".$type.".eps'\n";
  $plot.="set grid\n";
  $plot.="set xrange [0:".$nn."]\n";
  $plot.="set yrange [0:120]\n";
  $plot.="set xlabel 'Zeit $\left[\\right.$min$\left.\\right]$'\n";
  $plot.="set ylabel 'Fl{\\\"a}che $\left[\\right.$ \% $\left.\\right]$'\n";
  $plot.="set boxwidth 0.3\n";
  $plot.="set style fill solid\n";
  $plot.="set style line 1 lw 1 pt 7 ps 1 lc rgb 'blue'\n";
  $plot.="set style line 2 lw 1 pt 7 ps 1 lc rgb 'red'\n";
  $plot.="plot '".$path."median".$type.".dat' u 1:2 ls 1 w l notitle,\\\n";
  $plot.=" '".$path."median".$type.".dat' u 1:3:5:6:4 w candlesticks ls 2 notitle,\\\n";
  $plot.=" '".$path."median".$type.".dat' u 1:5:5:5:5 w candlesticks lt -1 lw 1 notitle,\\\n";
  $plot.=" '".$path."median".$type.".dat' u 1:6:6:6:6 w candlesticks lt -1 lw 1 notitle,\\\n";
  $plot.=" '".$path."median".$type.".dat' u 1:2:2:2:2 w candlesticks lt -1 lw 1 notitle";
  $plot.="\npause -1";

  /*
  $plotMedian=" #!/bin/sh\ngnuplot << EOF\nset output '".$path."plotMedian".$type.".png'\n";
  $gnuplotHeader="set xlabel 'time [min]'\nset ylabel 'median'\nset key right top\nset term png\nset boxwidth 0.3\nset style fill solid\n";
  $plotMedian.=$gnuplotHeader;
  $plotMedian.="plot '".$path."median".$type.".dat' u 1:2 w l notitle,\\\n";
  $plotMedian.=" '".$path."median".$type.".dat' u 1:3:5:6:4 w candlesticks lt 3 lw 1 ti 'box', '".$path."median".$type.".dat' u 1:5:5:5:5 w candlesticks lt -1 lw 2 notitle, '".$path."median".$type.".dat' u 1:6:6:6:6 w candlesticks lt -1 lw 2 notitle, '".$path."median".$type.".dat' u 1:2:2:2:2 w candlesticks lt -1 lw 2 ti 'median'";
  $plotMedian.="\nEOF\ndisplay ".$path."plotMedian".$type.".png&";
  */

  $file=$path."median".$type.".plot";
  $fid = fopen($file, "w");
  fputs($fid,$plot);
  fclose($fid);

  return array($a050,$a025,$a075,$a000,$a100);
}
?>
1fraktal.php
2VereinsverwaltungKartei.php
3VereinsverwaltungKarteikarte.php
4VereinsverwaltungKonto.php
5VereinsverwaltungLastschriften.php
6VereinsverwaltungMenue.php
7whichLengthDoWeHaveInXfigFile.php
8XML_extractAttribute.php
9XML_extractElement.php
10XML_extractTag.php
11XML_findAllElements.php
12XML_readFile.php
13writeNamedData.php
14menu.php
15content.php
16cms.php
17indexCms.php
18areaOfPolygon.php
19areaOfTriangle.php
20calculateAreasOfPolygonsInXfig.php
21calculateMeanStd.php
22checkChanges.php
23closeFigures.php
24db.php
25distanceOfPoints.php
26dtaus.php
27enumerateFiles.php
28fileGrep.php
29fitData.php
30fotoalbum.php
31genAlbum.php
32genDTAUS.php
33genFotoalbum.php
34genThumbnails.php
35globals.php
36hex2dec.php
37LaTeXbrief.php
38norm.php
39pdf.php
40plotResult.php
41pointsOfPolygon.php
42polynominalFit.php
43readData.php
44readDymolaOuput.php
45readFilenames.php
46readFromStdIn.php
47readNamedData.php
48readXmlFile.php
49searchMedian.php
50sortIEindex.php
51sortIntoBins.php
52sortPDF.php
53synchronise.php
54synchroniseDirectories.php
55Vereinsverwaltung.php
56writeData.php

 

gnuplot

gnuplot is used to visualise the results - via script you can do infinite diagrams in 1 second.
Run 'test' in gnuplot to get an owerview of the available line- and symbolstyles.