program hgraph(input,output); (* calculate uncertainty h *) const (* begin module version *) version = 1.08; (* of hgraph.p 1995 July 27 program updated and released 1995 July 27 program completed 1988 Oct 4 origin from unc.p 1987 May 1 *) (* end module version *) (* begin module describe.hgraph *) (* name hgraph: make uncertainty (H) graph synopsis hgraph(input: intty, output: out) files input: number of divisions output: probability versus h for graphing description Shannon's uncertainty H is calculated for two symbols. The probabilities run from 0 to 1. The number of divisions from 0 to 1 is given by the input. The output can be plotted directly with the xyplo program. examples 1.0 0.4 zerox zeroy graph coordinate center x 0 1 zx min max (character, real, real) if zx='x' then set xaxis y 0 1 zy min max (character, real, real) if zy='y' then set yaxis 10 10 1 1 xinterval yinterval number of intervals on axes to plot 4 4 xwidth ywidth width of numbers in characters 1 1 xdecimal ydecimal number of decimal places 3 3 xsize ysize size of axes in inches probability uncertainty, H (bits) a zc 'c' crosshairs, axXyYnN n 2 zxl base if zxl='l' then make x axis log to the given base n 2 zyl base if zyl='l' then make y axis log to the given base ********************************************************************* 1 2 xcolumn ycolumn columns of xyin that determine plot location 0 symbol column the xyin column to read symbols from 0 0 xscolumn yscolumn columns of xyin that determine the symbol size 0 0 0 hue saturation brightness columns for color manipulation ********************************************************************* symbol-to-plot c(circle)bd(dotted box)x+Ifgpr(rectangle) 0 symbol-flag character in xyin that indicates that this symbol 0.05 symbol sizex side in inches on the x axis of the symbol. 0.05 symbol sizey as for the x axis, get size from yscolumn cl 0.05 no connection (example for connection is c- 0.05 for dashed 0.05 inch) n 0.05 linetype size linetype l.-in and size of dashes or dots ********************************************************************* . ********************************************************************* documentation Figure created by this program (with 100 divisions) is used in ftp://ftp.ncifcrf.gov/pub/delila/primer.ps see also xyplo.p author Thomas Dana Schneider bugs none known *) (* end module describe.hgraph *) var d: integer; (* index to the plot *) divisions: integer; (* number of divisions to plot *) p: real; (* probability *) h: real; (* uncertainty *) ln2: real; (* precalculate ln(2) *) total: real; (* sum of input ratios for normalizing them *) function plop(p: real): real; (* calculate negative p log (base 2) of p *) begin plop := -p * ln(p)/ln2 end; begin writeln(output,'* hgraph ',version:4:2); ln2 := ln(2); writeln(output,'* number of divisions: '); readln(input,divisions); writeln(output,'* ',divisions:1); if divisions < 2 then divisions := 2; for d := 0 to divisions do begin if (d <> 0) and (d <> divisions) then begin p := d / divisions; h := plop(p) + plop(1-p) end else begin if d = 0 then p := 0.0 else p := 1.0; h := 0.0; end; writeln(output,p:10:8,' ',h:10:8) end; end.