Commit cdc39c09 authored by Jukka-Pekka Iivonen's avatar Jukka-Pekka Iivonen Committed by jpekka

Cleaned up `groupped by' radio button code. Added `Labels in First Row'

1999-07-07  Jukka-Pekka Iivonen  <iivonen@iki.fi>

	* src/dialog-analysis-tools.c: Cleaned up `groupped by' radio
 	button code.  Added `Labels in First Row' check buttons for all
 	tools.  Made the tool list inside of a scrolled window.

	* src/dialog-analysis-tools.c, src/analysis-tools.c: Implemented
 	`Random Number Generation' tool with the following distributions:
 	Discrete, Normal, and Uniform.
parent 257f8814
......@@ -15,6 +15,8 @@ Jukka:
assuming unequal variance)
- Implemented z-Test Tool
- Implemented F-Test Tool
- Implemented Random Number Generation Tool with the following
distributions: Discrete, Normal, and Uniform.
* Added the following functions:
- FORECAST() and INTERCEPT().
* And fixed these functions:
......
1999-07-07 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/dialog-analysis-tools.c: Cleaned up `groupped by' radio
button code. Added `Labels in First Row' check buttons for all
tools. Made the tool list inside of a scrolled window.
* src/dialog-analysis-tools.c, src/analysis-tools.c: Implemented
`Random Number Generation' tool with the following distributions:
Discrete, Normal, and Uniform.
1999-07-07 Michael Meeks <michael@edenproject.org>
* src/about.c (dialog_about): Add Jody, updated Sean.
......
1999-07-07 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/dialog-analysis-tools.c: Cleaned up `groupped by' radio
button code. Added `Labels in First Row' check buttons for all
tools. Made the tool list inside of a scrolled window.
* src/dialog-analysis-tools.c, src/analysis-tools.c: Implemented
`Random Number Generation' tool with the following distributions:
Discrete, Normal, and Uniform.
1999-07-07 Michael Meeks <michael@edenproject.org>
* src/about.c (dialog_about): Add Jody, updated Sean.
......
1999-07-07 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/dialog-analysis-tools.c: Cleaned up `groupped by' radio
button code. Added `Labels in First Row' check buttons for all
tools. Made the tool list inside of a scrolled window.
* src/dialog-analysis-tools.c, src/analysis-tools.c: Implemented
`Random Number Generation' tool with the following distributions:
Discrete, Normal, and Uniform.
1999-07-07 Michael Meeks <michael@edenproject.org>
* src/about.c (dialog_about): Add Jody, updated Sean.
......
1999-07-07 Jukka-Pekka Iivonen <iivonen@iki.fi>
* src/dialog-analysis-tools.c: Cleaned up `groupped by' radio
button code. Added `Labels in First Row' check buttons for all
tools. Made the tool list inside of a scrolled window.
* src/dialog-analysis-tools.c, src/analysis-tools.c: Implemented
`Random Number Generation' tool with the following distributions:
Discrete, Normal, and Uniform.
1999-07-07 Michael Meeks <michael@edenproject.org>
* src/about.c (dialog_about): Add Jody, updated Sean.
......
......@@ -1490,3 +1490,134 @@ ftest_tool (Workbook *wb, Sheet *sheet, Range *input_range1,
return 0;
}
/************* Random Number Generation Tool ******************************
*
* The results are given in a table which can be printed out in a new
* sheet, in a new workbook, or simply into an existing sheet.
*
* TODO: a new workbook output and output to an existing sheet
*
**/
int random_tool (Workbook *wb, Sheet *sheet, int vars, int count,
random_distribution_t distribution,
random_tool_t *param, data_analysis_output_t *dao)
{
char buf[256];
int i, n, j;
float_t range, p;
float_t *prob, *cumul_p;
Value **values, *v;
Cell *cell;
if (dao->type == NewSheetOutput) {
dao->sheet = sheet_new(wb, "Random Numbers");
dao->start_col = dao->start_row = 0;
workbook_attach_sheet(wb, dao->sheet);
}
switch (distribution) {
case DiscreteDistribution:
n = param->discrete.end_row-param->discrete.start_row + 1;
prob = g_new(float_t, n);
cumul_p = g_new(float_t, n);
values = g_new(Value *, n);
p = 0;
j = 0;
for (i=param->discrete.start_row;
i<=param->discrete.end_row; i++, j++) {
cell = sheet_cell_get(sheet,
param->discrete.start_col+1, i);
if (cell != NULL && cell->value != NULL) {
v = cell->value;
if (VALUE_IS_NUMBER(v))
prob[j] = value_get_as_float (v);
else {
g_free(prob);
g_free(cumul_p);
g_free(values);
return 1;
}
} else {
g_free(prob);
g_free(cumul_p);
g_free(values);
return 1;
}
p += prob[j];
cumul_p[j] = p;
cell = sheet_cell_get(sheet,
param->discrete.start_col, i);
if (cell != NULL && cell->value != NULL)
values[j] = value_duplicate(cell->value);
else {
g_free(prob);
g_free(cumul_p);
g_free(values);
return 1;
}
}
if (p != 1) {
g_free(prob);
g_free(cumul_p);
g_free(values);
return 2;
}
for (i=0; i<vars; i++) {
for (n=0; n<count; n++) {
float_t x = random_01();
for (j=0; cumul_p[j] < x; j++)
;
if (VALUE_IS_NUMBER(values[j]))
sprintf(buf, "%f",
value_get_as_float(values[j]));
else
sprintf(buf, "%s",
value_get_as_string(values[j]));
set_cell(dao, i, n, buf);
}
}
break;
case NormalDistribution:
for (i=0; i<vars; i++) {
for (n=0; n<count; n++) {
sprintf(buf, "%f",
qnorm(random_01(),
param->normal.mean,
param->normal.stdev));
set_cell(dao, i, n, buf);
}
}
break;
case UniformDistribution:
range = param->uniform.upper_limit-param->uniform.lower_limit;
for (i=0; i<vars; i++) {
for (n=0; n<count; n++) {
sprintf(buf, "%f", range*random_01() +
param->uniform.lower_limit);
set_cell(dao, i, n, buf);
}
}
break;
default:
printf("Not implemented yet.\n");
break;
}
return 0;
}
This diff is collapsed.
......@@ -111,7 +111,7 @@ add_check_buttons (GtkWidget *box, const char *ops[])
}
static GList *
GList *
add_strings_to_glist (const char *strs[])
{
int i;
......
......@@ -14,6 +14,57 @@ typedef struct {
GtkWidget *entry[5];
} descriptive_stat_tool_t;
typedef enum {
DiscreteDistribution, UniformDistribution, NormalDistribution,
BernoulliDistribution, BinomialDistribution, PoissonDistribution,
PatternedDistribution
} random_distribution_t;
typedef struct {
int start_col, start_row;
int end_col, end_row;
} discrete_random_tool_t;
typedef struct {
float_t lower_limit;
float_t upper_limit;
} uniform_random_tool_t;
typedef struct {
float_t mean;
float_t stdev;
} normal_random_tool_t;
typedef struct {
float_t p;
} bernoulli_random_tool_t;
typedef struct {
float_t p;
int trials;
} binomial_random_tool_t;
typedef struct {
float_t lambda;
} poisson_random_tool_t;
typedef struct {
float_t from, to;
float_t step;
int repeat_number;
int repeat_sequence;
} patterned_random_tool_t;
typedef union {
discrete_random_tool_t discrete;
uniform_random_tool_t uniform;
normal_random_tool_t normal;
bernoulli_random_tool_t bernoulli;
binomial_random_tool_t binomial;
poisson_random_tool_t poisson;
patterned_random_tool_t patterned;
} random_tool_t;
typedef enum {
NewSheetOutput, NewWorkbookOutput, RangeOutput
} data_analysis_output_type_t;
......@@ -74,5 +125,10 @@ int ztest_tool (Workbook *wb, Sheet *sheet, Range *range_input1,
Range *range_input2, float_t mean_diff,
float_t var1, float_t var2, float_t alpha,
data_analysis_output_t *dao);
int random_tool (Workbook *wb, Sheet *sheet, int vars, int count,
random_distribution_t distribution,
random_tool_t *param, data_analysis_output_t *dao);
GList *add_strings_to_glist (const char *strs[]);
#endif /* GNUMERIC_DIALOGS_H */
This diff is collapsed.
......@@ -111,7 +111,7 @@ add_check_buttons (GtkWidget *box, const char *ops[])
}
static GList *
GList *
add_strings_to_glist (const char *strs[])
{
int i;
......
......@@ -14,6 +14,57 @@ typedef struct {
GtkWidget *entry[5];
} descriptive_stat_tool_t;
typedef enum {
DiscreteDistribution, UniformDistribution, NormalDistribution,
BernoulliDistribution, BinomialDistribution, PoissonDistribution,
PatternedDistribution
} random_distribution_t;
typedef struct {
int start_col, start_row;
int end_col, end_row;
} discrete_random_tool_t;
typedef struct {
float_t lower_limit;
float_t upper_limit;
} uniform_random_tool_t;
typedef struct {
float_t mean;
float_t stdev;
} normal_random_tool_t;
typedef struct {
float_t p;
} bernoulli_random_tool_t;
typedef struct {
float_t p;
int trials;
} binomial_random_tool_t;
typedef struct {
float_t lambda;
} poisson_random_tool_t;
typedef struct {
float_t from, to;
float_t step;
int repeat_number;
int repeat_sequence;
} patterned_random_tool_t;
typedef union {
discrete_random_tool_t discrete;
uniform_random_tool_t uniform;
normal_random_tool_t normal;
bernoulli_random_tool_t bernoulli;
binomial_random_tool_t binomial;
poisson_random_tool_t poisson;
patterned_random_tool_t patterned;
} random_tool_t;
typedef enum {
NewSheetOutput, NewWorkbookOutput, RangeOutput
} data_analysis_output_type_t;
......@@ -74,5 +125,10 @@ int ztest_tool (Workbook *wb, Sheet *sheet, Range *range_input1,
Range *range_input2, float_t mean_diff,
float_t var1, float_t var2, float_t alpha,
data_analysis_output_t *dao);
int random_tool (Workbook *wb, Sheet *sheet, int vars, int count,
random_distribution_t distribution,
random_tool_t *param, data_analysis_output_t *dao);
GList *add_strings_to_glist (const char *strs[]);
#endif /* GNUMERIC_DIALOGS_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment