[rkward-cvs] [rkward/work/distributions] rkward/plugins: Continued work on refactoring distributions calculator plugins. Focusing on binomial, for now.

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Tue Jan 20 19:41:14 UTC 2015


Git commit 21760aafec8e3a4da3b7ac63e244603e5cda3e77 by Thomas Friedrichsmeier.
Committed on 20/01/2015 at 19:40.
Pushed by tfry into branch 'work/distributions'.

Continued work on refactoring distributions calculator plugins. Focusing on binomial, for now.

M  +2    -4    rkward/plugins/distributions.pluginmap
A  +22   -0    rkward/plugins/distributions/binomial.js
A  +24   -0    rkward/plugins/distributions/binomial.rkh
R  +4    -3    rkward/plugins/distributions/binomial.xml [from: rkward/plugins/distributions/binomial_tail_probabilities.xml - 070% similarity]
D  +0    -16   rkward/plugins/distributions/binomial_quantiles.js
D  +0    -14   rkward/plugins/distributions/binomial_quantiles.xml
D  +0    -14   rkward/plugins/distributions/binomial_tail_probabilities.js
A  +38   -0    rkward/plugins/distributions/dist_common.js
A  +11   -0    rkward/plugins/distributions/dist_help_snippets.xml
M  +0    -7    rkward/plugins/distributions/dist_snippets.xml

http://commits.kde.org/rkward/21760aafec8e3a4da3b7ac63e244603e5cda3e77

diff --git a/rkward/plugins/distributions.pluginmap b/rkward/plugins/distributions.pluginmap
index 2ac743b..98cdb1c 100644
--- a/rkward/plugins/distributions.pluginmap
+++ b/rkward/plugins/distributions.pluginmap
@@ -31,8 +31,7 @@
 		<component type="standard" id="beta_probabilities" file="beta_probabilities.xml" label="Beta probabilities" />
 		<component type="standard" id="plot_beta_distribution" file="plot_beta_distribution.xml" label="Plot Beta distribution" />
 
-		<component type="standard" id="binomial_quantiles" file="binomial_quantiles.xml" label="Binomial quantiles" />
-		<component type="standard" id="binomial_tail_probabilities" file="binomial_tail_probabilities.xml" label="Binomial tail probabilities" />
+		<component type="standard" id="binomial_calculator" file="binomial.xml" label="Binomial probabilities, quantiles, densities" />
 		<component type="standard" id="plot_binomial_distribution" file="plot_binomial_distribution.xml" label="Plot binomial distribution" />
 
 		<component type="standard" id="cauchy_quantiles" file="cauchy_quantiles.xml" label="Cauchy quantiles" />
@@ -224,8 +223,7 @@
 
 			<menu id="univariate_discrete_distributions" label="Univariate discrete distributions">
 				<menu id="binomial_distribution" label="Binomial">
-					<entry component="binomial_quantiles" label="Binomial quantiles"/>
-					<entry component="binomial_tail_probabilities" label="Binomial tail probabilities"/>
+					<entry component="binomial_calculator" label="Binomial probabilities, quantiles, densities"/>
 					<entry component="plot_binomial_clt" label="Binomial CLT"/>
 					<entry component="plot_binomial_distribution" label="Plot binomial distribution"/>
 				</menu>
diff --git a/rkward/plugins/distributions/binomial.js b/rkward/plugins/distributions/binomial.js
new file mode 100644
index 0000000..e210483
--- /dev/null
+++ b/rkward/plugins/distributions/binomial.js
@@ -0,0 +1,22 @@
+include ("dist_common.js");
+
+function getDistSpecifics () {
+	var dist = new Object;
+	dist["params"] = "bla";
+	dist["funstem"] = "binom";
+	dist["header"] = new Header (i18n ("Binomial tail probability"));
+	return dist;
+}
+
+/*function calculate () {
+	q = "c (" + getString ("q").replace (/[, ]+/g, ", ") + ")";
+
+	echo ('result <- (pbinom (q = ' + q + ', size = ' + getValue ("size") + ', prob = ' + getValue ("prob") + ', ' + getValue ("tail") + ', ' + getValue ("logp") + '))\n');
+}
+
+function printout () {
+	echo ('rk.header (, list ("Vector of quantiles", "' + q + '", "Binomial trials", "' + getValue ("size") + '", "Probability of success", "' + getValue ("prob") + '", "Tail", "' + getValue ("tail") + '", "Probabilities p are given as", "' + getValue ("logp") + '"));\n');
+	echo ('rk.results (result, titles="Binomial tail probabilities")\n');
+}
+
+*/
\ No newline at end of file
diff --git a/rkward/plugins/distributions/binomial.rkh b/rkward/plugins/distributions/binomial.rkh
new file mode 100644
index 0000000..7afcc63
--- /dev/null
+++ b/rkward/plugins/distributions/binomial.rkh
@@ -0,0 +1,24 @@
+<!DOCTYPE rkhelp>
+<document>
+	<summary>
+		Provides a calculator for probabilities, quantiles, and densities in the binonmial distribution.
+
+		Note: For the binomial distribution, quantiles can be interpreted as number of successes in the given number of trials.
+	</summary>
+	<usage>
+		Select the desired mode of operation, then specify the values of interest.
+	</usage>
+	<snippets>
+		<include file="dist_help_snippets.xml"/>
+	</snippets>
+	<settings>
+		<insert snippet="dialog_settings"/>
+		<setting id="size">Number of binomial trials</setting>
+		<setting id="prob">Probability of success in each trial. Note that this setting is <b>not</b> affected by the "log probabilities" setting, i.e. always specify the plain probability, here.</setting>
+	</settings>
+	<related>
+		<ul>
+			<li><link href="rkward://rhelp/Binomial"/></li>
+		</ul>
+	</related>
+</document>
diff --git a/rkward/plugins/distributions/binomial_tail_probabilities.xml b/rkward/plugins/distributions/binomial.xml
similarity index 70%
rename from rkward/plugins/distributions/binomial_tail_probabilities.xml
rename to rkward/plugins/distributions/binomial.xml
index 79842c6..b964ee1 100644
--- a/rkward/plugins/distributions/binomial_tail_probabilities.xml
+++ b/rkward/plugins/distributions/binomial.xml
@@ -1,6 +1,7 @@
 <!DOCTYPE rkplugin>
 <document>
-	<code file="binomial_tail_probabilities.js" />
+	<code file="binomial.js" />
+	<help file="binomial.rkh" />
 	<logic>
 		<insert snippet="dialog_logic"/>
 	</logic>
@@ -9,10 +10,10 @@
 			<spinbox default_precision="2" type="integer" initial="1" id="size" min="1" label="Binomial trials"/>
 			<spinbox default_precision="2" type="real" initial="0.5" id="prob" min="0" max="1" label="Probability of success"/>
 		</snippet>
-		<snippet id="ui_note"><text>Note: For the binomial distribution, quantiles can be interpreted as number of successes.</text></snippet>
+		<snippet id="ui_note"><text>Note: For the binomial distribution, quantiles can be interpreted as number of successes in the given number of trials.</text></snippet>
 		<include file="dist_snippets.xml"/>
 	</snippets>
-	<dialog label="Binomial tail probability" >
+	<dialog label="Binomial probabilities, quantiles, densities" >
 		<insert snippet="dialog_layout"/>
 	</dialog>
 </document>
diff --git a/rkward/plugins/distributions/binomial_quantiles.js b/rkward/plugins/distributions/binomial_quantiles.js
deleted file mode 100644
index ae81961..0000000
--- a/rkward/plugins/distributions/binomial_quantiles.js
+++ /dev/null
@@ -1,16 +0,0 @@
-// globals
-var p;
-
-function calculate () {
-	p = "c (" + getList ("p.0").join (", ") + ")";
-
-	echo ('result <- (qbinom (p = ' + p + ', size = ' + getValue ("size") + ', prob = ' + getValue ("prob") + ', ' + getValue ("lower") + ', ' + getValue ("logp") + '))\n');
-}
-
-function printout () {
-	//produce the output
-
-	echo ('rk.header ("Binomial quantile", list ("Vector of quantiles probabilities", "' + p + '", "Binomial trials", "' + getValue ("size") + '", "Probability of success", "' + getValue ("prob") + '", "Tail", "' + getValue ("tail") + '", "Probabilities p are given as", "' + getValue ("logp") + '"));\n');
-	echo ('rk.results (result, titles="Binomial quantiles")\n');
-}
-
diff --git a/rkward/plugins/distributions/binomial_quantiles.xml b/rkward/plugins/distributions/binomial_quantiles.xml
deleted file mode 100644
index 44227b3..0000000
--- a/rkward/plugins/distributions/binomial_quantiles.xml
+++ /dev/null
@@ -1,14 +0,0 @@
-<!DOCTYPE rkplugin>
-<document>
-	<code file="binomial_quantiles.js" />
-	<snippets>
-		<snippet id="dist_options">
-			<spinbox default_precision="2" type="integer" initial="1" id="size" min="1" label="Binomial trials"/>
-			<spinbox default_precision="2" type="real" initial="0.5" id="prob" min="0" max="1" label="Probability of success"/>
-		</snippet>
-		<include file="dist_snippets.xml"/>
-	</snippets>
-	<dialog label="Binomial quantiles" >
-		<insert snippet="quantiles_layout"/>
-	</dialog>
-</document>
diff --git a/rkward/plugins/distributions/binomial_tail_probabilities.js b/rkward/plugins/distributions/binomial_tail_probabilities.js
deleted file mode 100644
index c5d6d5b..0000000
--- a/rkward/plugins/distributions/binomial_tail_probabilities.js
+++ /dev/null
@@ -1,14 +0,0 @@
-// globals
-var q;
-
-function calculate () {
-	q = "c (" + getString ("q").replace (/[, ]+/g, ", ") + ")";
-
-	echo ('result <- (pbinom (q = ' + q + ', size = ' + getValue ("size") + ', prob = ' + getValue ("prob") + ', ' + getValue ("tail") + ', ' + getValue ("logp") + '))\n');
-}
-
-function printout () {
-	echo ('rk.header ("Binomial tail probability", list ("Vector of quantiles", "' + q + '", "Binomial trials", "' + getValue ("size") + '", "Probability of success", "' + getValue ("prob") + '", "Tail", "' + getValue ("tail") + '", "Probabilities p are given as", "' + getValue ("logp") + '"));\n');
-	echo ('rk.results (result, titles="Binomial tail probabilities")\n');
-}
-
diff --git a/rkward/plugins/distributions/dist_common.js b/rkward/plugins/distributions/dist_common.js
new file mode 100644
index 0000000..d92eb35
--- /dev/null
+++ b/rkward/plugins/distributions/dist_common.js
@@ -0,0 +1,38 @@
+var mode;
+var values;
+var logp;
+var lowert;
+var dist;
+
+function calculate () {
+	mode = getString ("mode");
+	if (mode == "q") values = getList ("p.0");
+	else values = getList ("q.0");
+	if (values.length > 1) values = 'c (' + values.join (', ') + ')';
+
+	logp = getBoolean ("logp.state");
+	var logparam = logp ? ', logp=TRUE' : '';
+	lowert = getBoolean ("lower.state");
+	var tailparam = lowert ? '' : ', lower.tail=FALSE';
+
+	dist = getDistSpecifics ();
+
+	var plabel = logp ? i18n ('Log Probability') : i18n ('Probability');
+	var qlabel = i18n ('Quantile');
+	var dlabel = i18n ('Density');
+
+	echo ('result <- data.frame (');
+	echo (mode == "q" ? plabel : qlabel); 
+	echo ('=' + values + ', ');
+	if (mode == "d") echo (dlabel + '=d' + dist["funstem"] + ' (' + values + dist["params"] + logparam + ')');                  // NOTE: param lower.tail is not applicable for density function
+	else if (mode == "p") echo (plabel + '=p' + dist["funstem"] + ' (' + values + dist["params"] + tailparam + logparam + ')');
+	else if (mode == "q") echo (qlabel + '=q' + dist["funstem"] + ' (' + values + dist["params"] + tailparam + logparam + ')');
+	echo (')\n');
+}
+
+function printout () {
+	header = dist["header"];
+	header.add (i18nc ("Tail of distribution function: lower / upper", 'Tail'), lowert ? i18n ('Lower tail: P[X ≤ x]') : i18n ('Upper tail: P[X > x]'));
+	header.print ();
+	echo ('rk.print (result)\n');
+}
diff --git a/rkward/plugins/distributions/dist_help_snippets.xml b/rkward/plugins/distributions/dist_help_snippets.xml
new file mode 100644
index 0000000..a32c2e3
--- /dev/null
+++ b/rkward/plugins/distributions/dist_help_snippets.xml
@@ -0,0 +1,11 @@
+<document>
+	<snippet id="dialog_settings">
+		<caption title="Generic settings"/>
+		<setting id="mode">Specify the quantitiy to be calculated (probabilites, densities, or quantiles), and the quantity given (probabilities or quantiles)</setting>
+		<setting id="q">When calculating densities or probabilites, specify one or more quantiles.</setting>
+		<setting id="p">When calculating quantiles, specify one or more probabilities (optionally logarithmic; see below).</setting>
+		<setting id="logp">When calculating probabilities, return these as log (p). When specifying probabilites, these are supplied as log (p).</setting>
+		<setting id="lower">If checked (the default) probabilities are P[X ≤ x]. Otherwise (upper tail) probabilities are P[X > x]</setting>
+		<caption title="Distribution specific settings"/>
+	</snippet>
+</document>
diff --git a/rkward/plugins/distributions/dist_snippets.xml b/rkward/plugins/distributions/dist_snippets.xml
index c1f4f2e..c325d17 100644
--- a/rkward/plugins/distributions/dist_snippets.xml
+++ b/rkward/plugins/distributions/dist_snippets.xml
@@ -34,11 +34,4 @@
 			</row>
 			<insert snippet="ui_note"/>
 	</snippet>
-	<snippet id="dialog_settings">
-		<setting id="mode">Specify the quantitiy to be calculated (probabilites, densities, or quantiles), and the quantity given (probabilities or quantiles)</setting>
-		<setting id="q">When calculating densities or probabilites, specify one or more quantiles.</setting>
-		<setting id="p">When calculating quantiles, specify one or more probabilities (optionally logarithmic; see below).</setting>
-		<setting id="logp">When calculating probabilities, return these as log (p). When specifying probabilites, these are supplied as log (p).</setting>
-		<setting id="lower">If checked (the default) probabilities are given are P[X ≤ x]. Otherwise (upper tail) probabilities are  P[X > x]</setting>
-	</snippet>
 </document>


------------------------------------------------------------------------------
New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
GigeNET is offering a free month of service with a new server in Ashburn.
Choose from 2 high performing configs, both with 100TB of bandwidth.
Higher redundancy.Lower latency.Increased capacity.Completely compliant.
http://p.sf.net/sfu/gigenet
_______________________________________________
rkward-cvs mailing list
rkward-cvs at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rkward-cvs


More information about the rkward-tracker mailing list