Added rudimentary version of the Logistic Regression Dialog 20121121030502/pspp
authorJohn Darrington <john@darrington.wattle.id.au>
Tue, 20 Nov 2012 18:04:00 +0000 (19:04 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 20 Nov 2012 18:04:00 +0000 (19:04 +0100)
src/ui/gui/automake.mk
src/ui/gui/data-editor.ui
src/ui/gui/logistic.ui [new file with mode: 0644]
src/ui/gui/psppire-dialog-action-logistic.c [new file with mode: 0644]
src/ui/gui/psppire-dialog-action-logistic.h [new file with mode: 0644]
src/ui/gui/widgets.c

index 405671095fe0693d91833c866916711ecd6466fb..115837343af8676dc7d9d0a882c0c84dca4400eb 100644 (file)
@@ -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 \
index 8e37b275f74f1014816dcd74e12891e0be296f13..367d92af3d005ddcbde6fc8bc888fc28ee46138a 100644 (file)
             <property name="label" translatable="yes">Linear _Regression...</property>
           </object>
         </child>
+        <child>
+          <object class="PsppireDialogActionLogistic" id="logistic-regression">
+            <property name="name">logistic-regression</property>
+            <property name="manager">uimanager1</property>
+            <property name="label" translatable="yes">Lo_gistic Regression...</property>
+          </object>
+        </child>
         <child>
           <object class="GtkAction" id="non-parametrics">
             <property name="name">non-parametrics</property>
           <menuitem action="reliability"/>
           <menu action="regression">
             <menuitem action="linear-regression"/>
+            <menuitem action="logistic-regression"/>
           </menu>
           <menu action="non-parametrics">
             <menuitem action="chi-square"/>
diff --git a/src/ui/gui/logistic.ui b/src/ui/gui/logistic.ui
new file mode 100644 (file)
index 0000000..c7679f2
--- /dev/null
@@ -0,0 +1,235 @@
+<?xml version="1.0"?>
+<interface>
+  <!-- interface-requires gtk+ 2.12 -->
+  <requires lib="psppire" version="2054.17080"/>
+  <!-- interface-naming-policy project-wide -->
+  <object class="PsppireDialog" id="logistic-dialog">
+    <property name="title" translatable="yes">Logistic Regression</property>
+    <property name="modal">True</property>
+    <child internal-child="hbox">
+      <object class="GtkHBox" id="dialog-hbox1">
+        <property name="visible">True</property>
+        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+        <property name="spacing">2</property>
+        <child>
+          <object class="GtkAlignment" id="alignment1">
+            <property name="visible">True</property>
+            <property name="top_padding">5</property>
+            <property name="left_padding">5</property>
+            <child>
+              <object class="GtkTable" id="table1">
+                <property name="visible">True</property>
+                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                <property name="n_rows">3</property>
+                <property name="n_columns">3</property>
+                <child>
+                  <object class="GtkHButtonBox" id="hbuttonbox1">
+                    <property name="visible">True</property>
+                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                    <property name="layout_style">spread</property>
+                    <child>
+                      <object class="GtkButton" id="stat-button">
+                        <property name="label" translatable="yes">S_tatistics...</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkButton" id="save-button">
+                        <property name="label" translatable="yes">_Save...</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="right_attach">3</property>
+                    <property name="top_attach">2</property>
+                    <property name="bottom_attach">3</property>
+                    <property name="y_options"></property>
+                    <property name="y_padding">5</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="PsppireSelector" id="dep-selector">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                    <property name="no_show_all">True</property>
+                    <property name="border_width">5</property>
+                    <property name="source_widget">dict-view</property>
+                    <property name="dest_widget">dependent-entry</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="x_options"></property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="PsppireSelector" id="indep-selector">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                    <property name="no_show_all">True</property>
+                    <property name="border_width">5</property>
+                    <property name="source_widget">dict-view</property>
+                    <property name="dest_widget">indep-view</property>
+                  </object>
+                  <packing>
+                    <property name="left_attach">1</property>
+                    <property name="right_attach">2</property>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                    <property name="x_options"></property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkScrolledWindow" id="variables">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                    <property name="hscrollbar_policy">never</property>
+                    <property name="vscrollbar_policy">automatic</property>
+                    <property name="shadow_type">etched-in</property>
+                    <child>
+                      <object class="PsppireDictView" id="dict-view">
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                        <property name="headers_visible">False</property>
+                        <property name="headers_clickable">False</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="bottom_attach">2</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkFrame" id="frame2">
+                    <property name="visible">True</property>
+                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                    <property name="label_xalign">0</property>
+                    <property name="shadow_type">none</property>
+                    <child>
+                      <object class="GtkAlignment" id="alignment2">
+                        <property name="visible">True</property>
+                        <property name="left_padding">10</property>
+                        <child>
+                          <object class="GtkEntry" id="dependent-entry">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="invisible_char">&#x25CF;</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                    <child type="label">
+                      <object class="GtkLabel" id="label1">
+                        <property name="visible">True</property>
+                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                        <property name="label" translatable="yes">_Dependent</property>
+                        <property name="use_markup">True</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">2</property>
+                    <property name="right_attach">3</property>
+                    <property name="y_options"></property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkFrame" id="frame3">
+                    <property name="visible">True</property>
+                    <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                    <property name="label_xalign">0</property>
+                    <property name="shadow_type">none</property>
+                    <child>
+                      <object class="GtkAlignment" id="alignment4">
+                        <property name="visible">True</property>
+                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                        <property name="left_padding">12</property>
+                        <child>
+                          <object class="GtkScrolledWindow" id="scrolledwindow2">
+                            <property name="visible">True</property>
+                            <property name="can_focus">True</property>
+                            <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                            <property name="hscrollbar_policy">never</property>
+                            <property name="vscrollbar_policy">automatic</property>
+                            <property name="shadow_type">etched-in</property>
+                            <child>
+                              <object class="PsppireVarView" id="indep-view">
+                                <property name="visible">True</property>
+                                <property name="can_focus">True</property>
+                                <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                                <property name="headers_visible">False</property>
+                                <property name="headers_clickable">False</property>
+                              </object>
+                            </child>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                    <child type="label">
+                      <object class="GtkLabel" id="label3">
+                        <property name="visible">True</property>
+                        <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+                        <property name="label" translatable="yes">_Independent</property>
+                        <property name="use_markup">True</property>
+                        <property name="use_underline">True</property>
+                        <property name="mnemonic_widget">indep-view</property>
+                      </object>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="left_attach">2</property>
+                    <property name="right_attach">3</property>
+                    <property name="top_attach">1</property>
+                    <property name="bottom_attach">2</property>
+                  </packing>
+                </child>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="PsppireVButtonBox" id="psppire-vbuttonbox1">
+            <property name="visible">True</property>
+            <property name="border_width">5</property>
+            <property name="orientation">vertical</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">False</property>
+            <property name="pack_type">end</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/src/ui/gui/psppire-dialog-action-logistic.c b/src/ui/gui/psppire-dialog-action-logistic.c
new file mode 100644 (file)
index 0000000..fab3b15
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>. */
+
+
+#include <config.h>
+
+#include "psppire-dialog-action-logistic.h"
+#include "psppire-value-entry.h"
+
+#include "dialog-common.h"
+#include "helper.h"
+#include <ui/syntax-gen.h>
+#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, &notused);
+}
+
+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 (file)
index 0000000..8607dff
--- /dev/null
@@ -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 <http://www.gnu.org/licenses/>. */
+
+
+#include <glib-object.h>
+#include <glib.h>
+
+#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__ */
index 5cff7e9265d98124c73c75416c7036a7dc51605b..5d8351c44126858d772acb3aaa1260d07fb4e8b5 100644 (file)
@@ -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 ();