diff options
author | Karl Berry <karl@freefriends.org> | 2021-11-02 20:35:53 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2021-11-02 20:35:53 +0000 |
commit | 2a9b5355807fbd56fda14357bcc71a3b579aaaec (patch) | |
tree | 51dc482ca5723ff0e0867fe030b240cb11f53c58 | |
parent | ee41f9e645bed9a812261894a086d51d85f137ff (diff) |
mptrees (2nov21)
git-svn-id: svn://tug.org/texlive/trunk@60929 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r-- | Master/texmf-dist/doc/metapost/mptrees/README.md | 4 | ||||
-rw-r--r-- | Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.pdf | bin | 429600 -> 168458 bytes | |||
-rw-r--r-- | Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex | 131 | ||||
-rw-r--r-- | Master/texmf-dist/metapost/mptrees/mptrees.mp | 152 | ||||
-rwxr-xr-x | Master/tlpkg/libexec/ctan2tds | 1 |
5 files changed, 251 insertions, 37 deletions
diff --git a/Master/texmf-dist/doc/metapost/mptrees/README.md b/Master/texmf-dist/doc/metapost/mptrees/README.md index ee9e901ceab..e439a51d1fd 100644 --- a/Master/texmf-dist/doc/metapost/mptrees/README.md +++ b/Master/texmf-dist/doc/metapost/mptrees/README.md @@ -1,7 +1,7 @@ -Package mptrees - Version 17.06 - June 1, 2017 +Package mptrees - Version 21.10 - November 2, 2021 This package provides MetaPost tools for drawing simple probability trees. -One command and several parameters to control the output are provided. +One main command, some variants and several parameters to control the output are provided. License LPPL 1.3 diff --git a/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.pdf b/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.pdf Binary files differindex 816b302304c..1c9ba9fe38d 100644 --- a/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.pdf +++ b/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.pdf diff --git a/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex b/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex index e1a2387913a..f83d2b81488 100644 --- a/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex +++ b/Master/texmf-dist/doc/metapost/mptrees/mptrees-doc.tex @@ -424,7 +424,7 @@ It can be used inside the first set of parameters of the tree (see example below \end{exemplev} -\item[abscoord] With the boolean \verb|abscoord| set to \verb|true|, all the coordinates are given from the origin of the \emph{first} tree instead of the origin of the subtree, which make easier the alignment of all the subtrees. +\item[abscoord] With the boolean \verb|abscoord| set to \verb|true|, all the coordinates are given from the origin of the \emph{first} tree instead of the origin of the subtree, which makes easier the alignment of all the subtrees. \end{description} @@ -448,33 +448,40 @@ abscoord:=false; \section{Parameters} -\begin{description} - -\item[scaleprob] numeric controlling the scale of the label above the edge (the probability). Default is $0.85$. +\subsection{Event} +\begin{description} +\item[scaleev] numeric controlling the scale of the label at the end of the edge (the event). Default is $1$. \begin{exemple}[0.65] - scaleprob:=1.5; + scaleev:=2; draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$q$"); \end{exemple} \begin{codecache} -scaleprob:=0.85; +scaleev:=1; \end{codecache} -\item[scaleev] numeric controlling the scale of the label at the end of the edge (the event). Default is $1$. +\end{description} + +\subsection{Probability} +\begin{description} + + +\item[scaleprob] numeric controlling the scale of the label above the edge (the probability). Default is $0.85$. \begin{exemple}[0.65] - scaleev:=2; + scaleprob:=1.5; draw tree[1][1](3cm,2cm)("$A$","$p$","$B$","$q$"); \end{exemple} \begin{codecache} -scaleev:=1; +scaleprob:=0.85; \end{codecache} + \item[posprob] numeric controlling the position of the label above the edge. Default is $0.6$. @@ -526,6 +533,30 @@ typeprob:=1; proboffset:=3bp; \end{codecache} +\end{description} + +\subsection{Edge} +\begin{description} +\item[endedgeshift] vertical space added at the end of the edge. Default is $0$. Useful when various edges end at the same point + +\begin{exemple}[0.65] + draw startlabel("$S$"); + draw tree[1][1]((3cm,-1cm))("$A$","$p$"); +\end{exemple} + + +\begin{exemple}[0.65] + endedgeshift:=10; + draw startlabel("$S$"); + draw tree[1][1]((3cm,-1cm))("$A$","$p$"); +\end{exemple} + +\begin{codecache} +endedgeshift:=0; +\end{codecache} + + + \item[edgearrow] When the boolean \verb|edgearrow| is set to true, edges end with an arrow. Default is \verb|false|. \begin{exemple}[0.65] @@ -537,26 +568,87 @@ proboffset:=3bp; edgearrow:=false; \end{codecache} -\item[endedgeshift] vertical space added at the end of the edge. Default is $0$. Useful when various edges end at the same point +\item[branchtype] string which controls the shape of the edge. Possible values are \verb|segment| (default), \verb|curve|, \verb|broken|. With the last one, the length of the first segment of the broken line depends on a numeric parameter, \verb|brokenlineratio| which indicates the ratio between the length of this segment and the length of the horizontal space. Default value is \verb|0.2|. +\end{description} \begin{exemple}[0.65] - draw startlabel("$S$"); - draw tree[1][1]((3cm,-1cm))("$A$","$p$"); + branchtype:="curve"; + draw tree[1][1](3cm,3cm)("$A$","$p$","$B$","$q$"); \end{exemple} +\begin{exemple}[0.65] + branchtype:="broken"; + draw tree[1][1](3cm,3cm)("$A$","$p$","$B$","$q$"); +\end{exemple} \begin{exemple}[0.65] - endedgeshift:=10; - draw startlabel("$S$"); - draw tree[1][1]((3cm,-1cm))("$A$","$p$"); + branchtype:="broken"; + posprob:=0.8; + brokenlineratio:=0.5; + draw tree[1][1](3cm,3cm)("$A$","$p$","$B$","$q$"); +\end{exemple} + + +\begin{exemple}[0.65] + branchtype:="broken"; + posprob:=0.8; + brokenlineratio:=0.75; + draw tree[1][1](3cm,3cm)("$A$","$p$","$B$","$q$"); \end{exemple} \begin{codecache} -endedgeshift:=0; + posprob:=0.6; + branchtype:="segment"; + brokenlineratio:=0.2; \end{codecache} +\section{Binomial trees} + +\begin{description} +\item[bernoulliprocess(n)(l,h)] tree describing the Bernoulli process with $n$ trials. \verb|l| is the length of the first edges and \verb|h| is the space between two final nodes. +\item[bernoulliprocessL(n)(L,H)] same as above where \verb|L| is the whole width of the tree and \verb|H| its height. \end{description} +Several parameters control the output: + +\begin{description} +\item[bernoullisuccessevent] string printed at every node representing a success. Default is \verb|"$S$"|. +\item[bernoullifailureevent] string printed at every node representing a failure. Default is \verb|"$\overline{S}$"|. +\item[bernoullisuccessprob] string printed above every edge representing a success. Default is \verb|"$p$"|. +\item[bernoullifailureprob] string printed above every edge representing a success. Default is \verb|"$q$"|. +\item[bernoulliscalebranch] ratio between width of consecutive edges. Default is \verb|0.8|. +\end{description} + +\begin{exemple}[0.45] +draw bernoulliprocess(3)(3cm,0.7cm); +\end{exemple} + +\begin{exemple}[0.45] +typeprob:=4; +bernoullisuccessevent:="$A$"; +bernoullifailureevent:="$B$"; +bernoullisuccessprob:="$0.7$"; +bernoullifailureprob:="$0.3$"; +draw bernoulliprocess(3)(3cm,0.7cm); +\end{exemple} + +\begin{codecache} +typeprob:=1; +bernoullisuccessevent := "$S$"; +bernoullifailureevent := "$\overline{S}$"; +bernoullisuccessprob := "$p$"; +bernoullifailureprob := "$q$"; +\end{codecache} + +\begin{description} +\item[binomialtree(n)(l,h)] tree describing the binomial distribution with $n$ trials. \verb|l| is the length of the first edges and \verb|h| is the space between two final nodes. It uses \verb|bernoullisuccesprob| and \verb|bernoullifailureprob| but \verb|bernoulliscalebranch| is set to \verb|1|. +\item[binomialtreeL(n)(L,H)] same as above where \verb|L| is the whole width of the tree and \verb|H| its height. +\end{description} + +\begin{exemplev}{1} +draw binomialtree(4)(3cm,1.5cm); +\end{exemplev} + \section{Embedded code in \LaTeX{} files} @@ -649,6 +741,7 @@ endfig; \begin{exemplev}[0.9]{1} u:=0.4cm; +branchtype:="curve"; dirlabel:=90; abscoord:=true; endlabelspace:=0.5cm; @@ -670,18 +763,20 @@ endlabelspace:=1cm; \begin{exemplev}[0.9]{1} u:=1cm; +branchtype:="broken"; dirlabel:=-90; abscoord:=true; scaleev:=2; -label.top(textext("\Large Tree diagram of $(2x+1)(x-1)$"),(0,1cm)); +label.top(textext("\Large Tree diagram of $(2x+1)(x-3)$"),(0,1cm)); draw startlabel("$\times$"); draw tree[1][1]((-2u,-1.5u),(2u,-1.5u))("$+$","","$-$",""); draw tree[2][1]((-3u,-3.5u),(-1u,-3.5u))("$\times$","","$1$",""); -draw tree[2][2]((1u,-3.5u),(3u,-3.5u))("$x$","","$2$",""); +draw tree[2][2]((1u,-3.5u),(3u,-3.5u))("$x$","","$3$",""); draw tree[3][1]((-4u,-5.5u),(-2u,-5.5u))("$2$","","$x$",""); \end{exemplev} \begin{codecache} +branchtype:="segment"; dirlabel:=0; abscoord:=false; scaleev:=1; diff --git a/Master/texmf-dist/metapost/mptrees/mptrees.mp b/Master/texmf-dist/metapost/mptrees/mptrees.mp index d9a5e49833c..cedcdb1f95c 100644 --- a/Master/texmf-dist/metapost/mptrees/mptrees.mp +++ b/Master/texmf-dist/metapost/mptrees/mptrees.mp @@ -2,8 +2,10 @@ %% mptrees.mp %% %% Probability trees with MetaPost %% %% o.peault@posteo.net %% -%% Version 17.06 (June 2017) %% +%% Version 21.11 (November 2021) %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +string mptreesversion; +mptreesversion:="21.11"; % % This work may be distributed and/or modified under the conditions of % the LaTeX Project Public License, either version 1.3 of this license @@ -11,6 +13,8 @@ % license is in http://www.latex-project.org/lppl.txt % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +message "mptrees version " & mptreesversion; + if not known mplib: input latexmp fi; boolean arbres_latexmp; @@ -35,6 +39,9 @@ proboffset:=labeloffset; numeric endedgeshift; endedgeshift:=0; +numeric brokenlineratio; +brokenlineratio:=0.2; + pair Orig_arbre[][]; % sommet de l'arbre i,j Orig_arbre[1][1]:=origin; @@ -66,7 +73,12 @@ endlabelspace:=1cm; % Étiquette au début de l'arbre + +picture mptreestartlabel; +mptreestartlabel:=nullpicture; + vardef startlabel(expr s)= + mptreestartlabel:=labelarbres(s); if dirtree<>0: dirlabel:=dirtree fi; if dirlabel>0: theevlabel(labelarbres(s) scaled scaleev,origin,-180+dirlabel) @@ -88,12 +100,12 @@ vardef endlabel[][](expr s)= boolean tmpabscoord; i:=colonne.#@; j:=@; - if string s: tmps:= "\strut " & s else: tmps:=s fi; + if string s: tmps:= "\strut \phantom{.}" & s else: picture tmps;tmps:=s fi; tmpbranchtype:=branchtype; branchtype:=endlabeltype; tmpabscoord:=abscoord; abscoord:=false; - tree[i][j]((endlabelspace,0) rotated (dirlabel-dirtree))(tmps,"") + tree[i][j]((endlabelspace,0) rotated (dirlabel-dirtree))(tmps," ") hide(branchtype:=tmpbranchtype;abscoord:=tmpabscoord;) enddef; @@ -126,7 +138,6 @@ vardef theevlabel(expr s,z,inc)= else: p = textext(s) fi; d=0.5*longdir(p,inc); -% p shifted (z - 0.5(lrcorner p - llcorner p) - 0.5(ulcorner p - llcorner p) + (d+labeloffset)*dir(inc)) p shifted (z - center p + (d+labeloffset)*dir(inc)) enddef; @@ -136,15 +147,16 @@ def evlabel = draw theevlabel enddef; vardef thelabelbranchehaut(expr Ori,Fin,Fig)= interim labeloffset:=proboffset; - save M,pp; - pair M; path pp; + save M,pp,tt; + pair M; path pp;numeric tt; pp=dessinbranche(Ori,Fin); - M= point (arctime posprob*(arclength pp) of pp) of pp; + tt = arctime posprob*(arclength pp) of pp; + M= point tt of pp; M:=M + 0.5(llcorner Fig - lrcorner Fig); - if xpart Ori <= xpart Fin: - M:=M+proboffset*unitvector(dir (dirlabel+90)) + if (angle(direction tt of pp) <= 90) and (angle(direction tt of pp) > -90): + M:=M+proboffset*unitvector((direction tt of pp) rotated 90) else: - M:=M-proboffset*unitvector(dir (dirlabel+90)) + M:=M-proboffset*unitvector((direction tt of pp) rotated 90) fi; Fig shifted M enddef; @@ -152,19 +164,27 @@ enddef; vardef thelabelbranchehautrot(expr Ori,Fin,Fig)= interim labeloffset:=proboffset; + save M,pp,tt; + pair M; path pp;numeric tt; + pp=dessinbranche(Ori,Fin); + tt = arctime posprob*(arclength pp) of pp; + M= point tt of pp; if xpart Ori <= xpart Fin: - Fig shifted (0.5*(ulcorner Fig - lrcorner Fig) + llcorner Fig+(0,proboffset)) rotated (angle(Fin-Ori)) shifted posprob[Ori,Fin] + Fig shifted ( - 0.5*lrcorner Fig- 0.5* llcorner Fig+(0,proboffset)) rotated angle(direction tt of pp) shifted M else: - Fig shifted (0.5*(ulcorner Fig - lrcorner Fig) + llcorner Fig+(0,proboffset)) rotated (angle(Ori-Fin)) shifted posprob[Ori,Fin] + Fig shifted ( - 0.5*lrcorner Fig- 0.5* llcorner Fig+(0,proboffset)) rotated (-180+angle(direction tt of pp)) shifted M fi enddef; vardef thelabelbranchesuper(expr Ori,Fin,Fig)= - save figtmp; + save figtmp,M,pp; + pair M; path pp; picture figtmp; - figtmp:=Fig shifted (posprob[Ori,Fin]-0.5*(lrcorner Fig + ulcorner Fig)); + pp=dessinbranche(Ori,Fin); + M= point (arctime posprob*(arclength pp) of pp) of pp; + figtmp:=Fig shifted (M-0.5*(lrcorner Fig + ulcorner Fig)); image(fill bbox figtmp withcolor background; draw figtmp) enddef; @@ -173,7 +193,12 @@ enddef; vardef thelabelbranchesuperrot(expr Ori,Fin,Fig)= save figtmp; picture figtmp; - figtmp:=Fig shifted (-0.5*(lrcorner Fig + ulcorner Fig)) rotated (angle(Fin-Ori)) shifted posprob[Ori,Fin]; + save M,pp,tt; + pair M; path pp;numeric tt; + pp=dessinbranche(Ori,Fin); + tt = arctime posprob*(arclength pp) of pp; + M= point tt of pp; + figtmp:=Fig shifted (-0.5*(lrcorner Fig + ulcorner Fig)) rotated angle(direction tt of pp) shifted M; image(fill bbox figtmp withcolor background; draw figtmp) enddef; @@ -192,10 +217,22 @@ vardef thelabelbranche(expr Ori,Fin,Fig)= fi enddef; +vardef brokenline(expr Ori,Fin)= + save B,M; + pair B,M; + B=(xpart (Fin rotated -dirlabel), ypart (Ori rotated -dirlabel)); + M = (brokenlineratio*abs(B-(Ori rotated -dirlabel)),0) rotated dirlabel; + Ori -- (Ori + M) -- (Fin - M) -- Fin +enddef; + %%%%%%%% Dessin de la branche vardef dessinbranche(expr Ori,Fin)= if branchtype="segment": Ori--Fin + elseif branchtype="curve": + Ori{dir dirlabel}..{dir dirlabel}Fin + elseif branchtype="broken": + brokenline(Ori,Fin) else: Ori--Fin fi @@ -222,7 +259,8 @@ vardef branche_abs(expr Ori,Fin,Eve,Pro)= else: draw fi - dessinbranche(Ori,Fin + (0,tmpshft)) rotatedaround(Ori,dirtree) +% dessinbranche(Ori,Fin + (0,tmpshft)) rotatedaround(Ori,dirtree) + dessinbranche(Ori,(Fin + (0,tmpshft)) rotatedaround(Ori,dirtree)) fi; draw figlab; evlabel(Eve,Fin rotatedaround(Ori,dirtree),dirlabel) @@ -242,7 +280,7 @@ vardef _arbre_(expr Ori)(text t)(text r)= % (pt)(pt1,pt2...)(ev,proba,ev,proba.. numeric counttmp,countlab; pair Fintmp[]; if dirtree<>0: dirlabel:=dirtree fi; - if colonne_cour=1: for i=1 upto 6: countligne[i]:=0; endfor fi + if colonne_cour=1: for i=1 upto 128: countligne[i]:=0; endfor fi figtmp=image(% counttmp:=0; for i=t: @@ -467,3 +505,83 @@ vardef arbre[][](text t)(text r)= enddef; def tree = arbre enddef; + + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%% Binomial + +string bernoullisuccessevent, bernoullifailureevent, bernoullisuccessprob, bernoullifailureprob; +bernoullisuccessevent := "$S$"; +bernoullifailureevent := "$\overline{S}$"; +bernoullisuccessprob := "$p$"; +bernoullifailureprob := "$q$"; +numeric bernoulliscalebranch; +bernoulliscalebranch := 0.8; + +vardef bernoulliprocess(expr n)(expr l,h)= + save tmp,ll,shiftev; + numeric ll; + shiftev:=max(longdir(labelarbres(bernoullisuccessevent),dirtree),longdir(labelarbres(bernoullifailureevent),dirtree))+2*labeloffset; + ll := l; + picture tmp; + tmp := image(% + for i := 1 upto n: + for j := 1 upto (2**(i-1)): + draw tree[i][j](ll,h*(2**(n-i)))(bernoullisuccessevent, bernoullisuccessprob, bernoullifailureevent, bernoullifailureprob); + endfor + ll := ll * bernoulliscalebranch; + endfor + ); + tmp +enddef; + + +vardef bernoulliprocessL(expr n)(expr L,H)= + save l,h,lpic,hpic; + numeric l,h,lpic,hpic; + hpic:=0.5*longdir(labelarbres(bernoullisuccessevent),90+dirtree) + 0.5*longdir(labelarbres(bernoullifailureevent),90+dirtree); + h := (H-hpic)/((2**n)-1); + lpic:=longdir(mptreestartlabel,dirtree) + n*max(longdir(labelarbres(bernoullisuccessevent),dirtree) , longdir(labelarbres(bernoullifailureevent),dirtree)) + (2*n-1)*labeloffset; + if bernoulliscalebranch<>1: + l:= (L-lpic)*(1-bernoulliscalebranch)/(1-bernoulliscalebranch**n) + else: + l:= (L-lpic)/n + fi; + bernoulliprocess(n)(l,h) +enddef; + + +vardef binomialtree(expr n)(expr l,h)= + save tmp,ll,posprob,shiftev,bernoulliscalebranch; + numeric ll; + posprob:=0.5;bernoulliscalebranch:=1; + shiftev:=longdir(labelarbres("3"),dirtree)+2*labeloffset; + ll := l; + picture tmp; + tmp := image(% + draw tree[1][1](ll,h)("$1$", bernoullisuccessprob, "$0$", bernoullifailureprob); + if n>1: + for i := 2 upto n: + for j := 1 upto (i-1): + draw tree[i][2*j-1](ll,h)(decimal(i-j+1), bernoullisuccessprob, " ", bernoullifailureprob); + endfor + draw tree[i][2*i-2](ll,h)("$1$", bernoullisuccessprob, "$0$", bernoullifailureprob); + endfor + ll := ll * bernoulliscalebranch; + fi + ); + tmp +enddef; + +vardef binomialtreeL(expr n)(expr L,H)= + save l,h,lpic,hpic; + numeric l,h,lpic,hpic; + hpic:=longdir(labelarbres("0"),90+dirtree); + h := (H-hpic)/n; + lpic:=longdir(mptreestartlabel,dirtree) + n*max(longdir(labelarbres("0"),dirtree) , longdir(labelarbres("0"),dirtree)) + (2*n-1)*labeloffset; + l:= (L-lpic)/n; + binomialtree(n)(l,h) +enddef; + + + diff --git a/Master/tlpkg/libexec/ctan2tds b/Master/tlpkg/libexec/ctan2tds index 98933be00f1..4f09494dca1 100755 --- a/Master/tlpkg/libexec/ctan2tds +++ b/Master/tlpkg/libexec/ctan2tds @@ -1452,6 +1452,7 @@ chomp (my $ctan_root = `tlpkginfo --ctan-root`); 'windycity', "&MAKEflatten", 'winedt', "die 'skipping, nonfree license'", 'winfonts', "die 'skipping, support for nonfree fonts'", + 'winshell', "die 'skipping, installed manually by siep?", 'withesis', "die 'skipping, thesis package ca.2002, wait for request'", 'wntamil', "die 'skipping, nonfree license'", 'worldflags', "&MAKEflatten", |