From: John Darrington Date: Tue, 20 Nov 2012 18:04:00 +0000 (+0100) Subject: Added rudimentary version of the Logistic Regression Dialog X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7b32c45b42723e8559c81fbad1d694339ac7fe6;p=pspp Added rudimentary version of the Logistic Regression Dialog --- diff --git a/src/ui/gui/automake.mk b/src/ui/gui/automake.mk index 405671095f..115837343a 100644 --- a/src/ui/gui/automake.mk +++ b/src/ui/gui/automake.mk @@ -22,6 +22,7 @@ UI_FILES = \ src/ui/gui/k-means.ui \ src/ui/gui/k-related.ui \ src/ui/gui/ks-one-sample.ui \ + src/ui/gui/logistic.ui \ src/ui/gui/means.ui \ src/ui/gui/missing-val-dialog.ui \ src/ui/gui/oneway.ui \ @@ -237,6 +238,8 @@ src_ui_gui_psppire_SOURCES = \ src/ui/gui/psppire-dialog-action-indep-samps.h \ src/ui/gui/psppire-dialog-action-kmeans.c \ src/ui/gui/psppire-dialog-action-kmeans.h \ + src/ui/gui/psppire-dialog-action-logistic.c \ + src/ui/gui/psppire-dialog-action-logistic.h \ src/ui/gui/psppire-dialog-action-means.c \ src/ui/gui/psppire-dialog-action-means.h \ src/ui/gui/psppire-dialog-action-rank.c \ diff --git a/src/ui/gui/data-editor.ui b/src/ui/gui/data-editor.ui index 8e37b275f7..367d92af3d 100644 --- a/src/ui/gui/data-editor.ui +++ b/src/ui/gui/data-editor.ui @@ -457,6 +457,13 @@ Linear _Regression... + + + logistic-regression + uimanager1 + Lo_gistic Regression... + + non-parametrics @@ -635,6 +642,7 @@ + diff --git a/src/ui/gui/logistic.ui b/src/ui/gui/logistic.ui new file mode 100644 index 0000000000..c7679f274c --- /dev/null +++ b/src/ui/gui/logistic.ui @@ -0,0 +1,235 @@ + + + + + + + Logistic Regression + True + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 2 + + + True + 5 + 5 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 3 + 3 + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + spread + + + S_tatistics... + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + + + False + False + 0 + + + + + _Save... + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + + + False + False + 1 + + + + + 3 + 2 + 3 + + 5 + + + + + True + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + 5 + dict-view + dependent-entry + + + 1 + 2 + + + + + + + True + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + True + 5 + dict-view + indep-view + + + 1 + 2 + 1 + 2 + + + + + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + never + automatic + etched-in + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + False + + + + + 2 + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + none + + + True + 10 + + + True + True + + + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + _Dependent + True + True + + + + + 2 + 3 + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 0 + none + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + 12 + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + never + automatic + etched-in + + + True + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + False + False + + + + + + + + + True + GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK + _Independent + True + True + indep-view + + + + + 2 + 3 + 1 + 2 + + + + + + + 0 + + + + + True + 5 + vertical + + + False + False + end + 1 + + + + + + diff --git a/src/ui/gui/psppire-dialog-action-logistic.c b/src/ui/gui/psppire-dialog-action-logistic.c new file mode 100644 index 0000000000..fab3b15aa1 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-logistic.c @@ -0,0 +1,138 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2008, 2010, 2011, 2012 Free Software Foundation + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + + +#include + +#include "psppire-dialog-action-logistic.h" +#include "psppire-value-entry.h" + +#include "dialog-common.h" +#include "helper.h" +#include +#include "psppire-var-view.h" + +#include "psppire-dialog.h" +#include "builder-wrapper.h" +#include "checkbox-treeview.h" +#include "psppire-dict.h" +#include "libpspp/str.h" + +#include "gettext.h" +#define _(msgid) gettext (msgid) +#define N_(msgid) msgid + + +static void +psppire_dialog_action_logistic_class_init (PsppireDialogActionLogisticClass *class); + +G_DEFINE_TYPE (PsppireDialogActionLogistic, psppire_dialog_action_logistic, PSPPIRE_TYPE_DIALOG_ACTION); + +static gboolean +dialog_state_valid (gpointer data) +{ + PsppireDialogActionLogistic *rd = PSPPIRE_DIALOG_ACTION_LOGISTIC (data); + + const gchar *text = gtk_entry_get_text (GTK_ENTRY (rd->dep_var)); + + GtkTreeModel *indep_vars = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->indep_vars)); + + GtkTreeIter notused; + + return 0 != strcmp ("", text) && + gtk_tree_model_get_iter_first (indep_vars, ¬used); +} + +static void +refresh (PsppireDialogAction *rd_) +{ + PsppireDialogActionLogistic *rd = PSPPIRE_DIALOG_ACTION_LOGISTIC (rd_); + + GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (rd->indep_vars)); + gtk_list_store_clear (GTK_LIST_STORE (liststore)); + + gtk_entry_set_text (GTK_ENTRY (rd->dep_var), ""); +} + + +static void +psppire_dialog_action_logistic_activate (GtkAction *a) +{ + PsppireDialogActionLogistic *act = PSPPIRE_DIALOG_ACTION_LOGISTIC (a); + PsppireDialogAction *pda = PSPPIRE_DIALOG_ACTION (a); + + GtkBuilder *xml = builder_new ("logistic.ui"); + + pda->dialog = get_widget_assert (xml, "logistic-dialog"); + pda->source = get_widget_assert (xml, "dict-view"); + + act->dep_var = get_widget_assert (xml, "dependent-entry"); + act->indep_vars = get_widget_assert (xml, "indep-view"); + + g_object_unref (xml); + + psppire_dialog_action_set_refresh (pda, refresh); + + psppire_dialog_action_set_valid_predicate (pda, + dialog_state_valid); + + if (PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_logistic_parent_class)->activate) + PSPPIRE_DIALOG_ACTION_CLASS (psppire_dialog_action_logistic_parent_class)->activate (pda); +} + + + +static char * +generate_syntax (PsppireDialogAction *a) +{ + PsppireDialogActionLogistic *rd = PSPPIRE_DIALOG_ACTION_LOGISTIC (a); + gchar *text = NULL; + + GString *string = g_string_new ("LOGISTIC REGRESSION "); + + const gchar *dep = gtk_entry_get_text (GTK_ENTRY (rd->dep_var)); + + g_string_append (string, dep); + + g_string_append (string, " WITH "); + + psppire_var_view_append_names (PSPPIRE_VAR_VIEW (rd->indep_vars), 0, string); + + g_string_append (string, ".\n"); + + text = string->str; + + g_string_free (string, FALSE); + + return text; +} + +static void +psppire_dialog_action_logistic_class_init (PsppireDialogActionLogisticClass *class) +{ + GtkActionClass *action_class = GTK_ACTION_CLASS (class); + + action_class->activate = psppire_dialog_action_logistic_activate; + + PSPPIRE_DIALOG_ACTION_CLASS (class)->generate_syntax = generate_syntax; +} + + +static void +psppire_dialog_action_logistic_init (PsppireDialogActionLogistic *act) +{ +} + diff --git a/src/ui/gui/psppire-dialog-action-logistic.h b/src/ui/gui/psppire-dialog-action-logistic.h new file mode 100644 index 0000000000..8607dff749 --- /dev/null +++ b/src/ui/gui/psppire-dialog-action-logistic.h @@ -0,0 +1,78 @@ +/* PSPPIRE - a graphical user interface for PSPP. + Copyright (C) 2012 Free Software Foundation + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + + +#include +#include + +#include "psppire-dialog-action.h" + +#ifndef __PSPPIRE_DIALOG_ACTION_LOGISTIC_H__ +#define __PSPPIRE_DIALOG_ACTION_LOGISTIC_H__ + +G_BEGIN_DECLS + + +#define PSPPIRE_TYPE_DIALOG_ACTION_LOGISTIC (psppire_dialog_action_logistic_get_type ()) + +#define PSPPIRE_DIALOG_ACTION_LOGISTIC(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_LOGISTIC, PsppireDialogActionLogistic)) + +#define PSPPIRE_DIALOG_ACTION_LOGISTIC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + PSPPIRE_TYPE_DIALOG_ACTION_LOGISTIC, \ + PsppireDialogActionLogisticClass)) + + +#define PSPPIRE_IS_DIALOG_ACTION_LOGISTIC(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PSPPIRE_TYPE_DIALOG_ACTION_LOGISTIC)) + +#define PSPPIRE_IS_DIALOG_ACTION_LOGISTIC_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), PSPPIRE_TYPE_DIALOG_ACTION_LOGISTIC)) + + +#define PSPPIRE_DIALOG_ACTION_LOGISTIC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + PSPPIRE_TYPE_DIALOG_ACTION_LOGISTIC, \ + PsppireDialogActionLogisticClass)) + +typedef struct _PsppireDialogActionLogistic PsppireDialogActionLogistic; +typedef struct _PsppireDialogActionLogisticClass PsppireDialogActionLogisticClass; + + +struct _PsppireDialogActionLogistic +{ + PsppireDialogAction parent; + + /*< private >*/ + gboolean dispose_has_run ; + + GtkWidget *dep_var; + GtkWidget *indep_vars; +}; + + +struct _PsppireDialogActionLogisticClass +{ + PsppireDialogActionClass parent_class; +}; + + +GType psppire_dialog_action_logistic_get_type (void) ; + +G_END_DECLS + +#endif /* __PSPPIRE_DIALOG_ACTION_LOGISTIC_H__ */ diff --git a/src/ui/gui/widgets.c b/src/ui/gui/widgets.c index 5cff7e9265..5d8351c441 100644 --- a/src/ui/gui/widgets.c +++ b/src/ui/gui/widgets.c @@ -54,6 +54,7 @@ preregister_widgets (void) psppire_dialog_action_descriptives_get_type (); psppire_dialog_action_examine_get_type (); psppire_dialog_action_factor_get_type (); + psppire_dialog_action_logistic_get_type (); psppire_dialog_action_kmeans_get_type (); psppire_dialog_action_means_get_type (); psppire_dialog_action_indep_samps_get_type ();