Projects/laydi
Projects
/
laydi
Archived
7
0
Fork 0

Added Optionsdialog for pca and pls

This commit is contained in:
Arnar Flatberg 2007-01-04 13:53:47 +00:00
parent e08a8377ed
commit f7fe171896
1 changed files with 74 additions and 30 deletions

View File

@ -1,10 +1,8 @@
"""This module contains bilinear models(Functions) """This module contains bilinear models(Functions)
""" """
import sys
# add library import gtk
sys.path.append('/home/flatberg/fluents/fluents/lib') from fluents.workflow import Function, OptionsDialog, Options
import time
from fluents.workflow import Function
from fluents.dataset import Dataset from fluents.dataset import Dataset
from fluents import plots, dataset, workflow, logger from fluents import plots, dataset, workflow, logger
import scipy import scipy
@ -127,7 +125,7 @@ class PCA(Model):
#logger.log('debug', 'Plot: %s failed') %plt #logger.log('debug', 'Plot: %s failed') %plt
return out return out
def run(self, data): def run_o(self, data):
"""Run pca with present options. """Run pca with present options.
""" """
self.clear() self.clear()
@ -150,6 +148,21 @@ class PCA(Model):
out.append(plt) out.append(plt)
return out return out
def run(self, data):
"""Run Pca with option gui.
"""
dialog = PcaOptionsDialog([data], self._options)
dialog.show_all()
response = dialog.run()
dialog.hide()
if response == gtk.RESPONSE_OK:
# set output data and plots
dialog.set_output()
#run with current data and options
return self.run_o(data)
class PLS(Model): class PLS(Model):
def __init__(self, id='pls', name='PLS'): def __init__(self, id='pls', name='PLS'):
@ -238,7 +251,7 @@ class PLS(Model):
# logger.log('debug', 'Plot: %s failed' %plt) # logger.log('debug', 'Plot: %s failed' %plt)
return out return out
def run(self,a,b): def run_o(self, a, b):
options = self._options options = self._options
self._dataset['X'] = a self._dataset['X'] = a
self._dataset['Y'] = b self._dataset['Y'] = b
@ -271,6 +284,20 @@ class PLS(Model):
out.append(plt) out.append(plt)
return out return out
def run(self, a, b):
"""Run Pls with option gui.
"""
dialog = PlsOptionsDialog([a, b], self._options)
dialog.show_all()
response = dialog.run()
dialog.hide()
if response == gtk.RESPONSE_OK:
# set output data and plots
dialog.set_output()
#run with current data and options
return self.run_o(a, b)
class Packer: class Packer:
"""A compression object used to speed up model calculations. """A compression object used to speed up model calculations.
@ -302,18 +329,6 @@ class Packer:
return self._packed_data return self._packed_data
class Options(dict):
"""Options base class.
"""
def __init__(self, *args,**kw):
dict.__init__(self, *args, **kw)
def _copy_from_list(self, key_list):
d = {}
for key in key_list:
d[key] = self.get(key,None)
return d
class PcaOptions(Options): class PcaOptions(Options):
"""Options for Principal Component Analysis. """Options for Principal Component Analysis.
""" """
@ -344,9 +359,17 @@ class PcaOptions(Options):
opt['val_engine'] = pca_alter_val opt['val_engine'] = pca_alter_val
opt['val_n_sets'] = 10 opt['val_n_sets'] = 10
opt['all_data'] = ['T','P','E','p_tsq','rmsep'] opt['all_data'] = [('T', 'scores', True),
opt['all_plots'] = ['PcaScorePlot', 'PcaLoadingPlot', ('P', 'loadings', True),
'PcaRmsepPlot'] ('E','residuals', False),
('p_tsq', 't2', False),
('rmsep', 'root mean square error of prediction', False)
]
opt['all_plots'] = [(blmplots.PcaScorePlot, 'Scores', True),
(blmplots.PcaLoadingPlot, 'Loadings', True),
(blmplots.LineViewXc, 'Line view', True)
]
opt['out_data'] = ['T','P', 'p_tsq'] opt['out_data'] = ['T','P', 'p_tsq']
opt['out_plots'] = [blmplots.PcaScorePlot,blmplots.PcaLoadingPlot,blmplots.LineViewXc] opt['out_plots'] = [blmplots.PcaScorePlot,blmplots.PcaLoadingPlot,blmplots.LineViewXc]
@ -399,20 +422,27 @@ class PlsOptions(Options):
opt['val_engine'] = w_pls_cv_val opt['val_engine'] = w_pls_cv_val
opt['all_data'] = ['T','P','E','p_tsq','rmsep'] opt['all_data'] = [('T', 'scores', True),
opt['all_plots'] = ['PcaScorePlot', 'PcaLoadingPlot', ('P', 'loadings', True),
'PcaRmsepPlot'] ('E','residuals', False),
('p_tsq', 't2', False),
('rmsep', 'root mean square error of prediction', False)
]
opt['all_plots'] = [(blmplots.PlsScorePlot, 'Scores', True),
(blmplots.PlsLoadingPlot, 'Loadings', True),
(blmplots.LineViewXc, 'Line view', True)]
opt['out_data'] = []
opt['out_plots'] = [blmplots.PlsScorePlot, opt['out_plots'] = [blmplots.PlsScorePlot,
blmplots.PlsLoadingPlot, blmplots.PlsLoadingPlot,
blmplots.LineViewXc] blmplots.LineViewXc]
#blmplots.PlsQvalScatter] opt['out_data'] = None
opt['pack'] = False opt['pack'] = False
opt['calc_qvals'] = False opt['calc_qvals'] = False
opt['q_pert_mth'] = 'shuffle_vars' opt['q_pert_mth'] = 'shuffle_vars'
opt['q_iter'] = 20 opt['q_iter'] = 20
self.update(opt) self.update(opt)
def make_model_options(self): def make_model_options(self):
@ -430,3 +460,17 @@ class PlsOptions(Options):
"""Options for pre_validation method.""" """Options for pre_validation method."""
opt_list = ['amax', 'n_sets', 'val_engine'] opt_list = ['amax', 'n_sets', 'val_engine']
return self._copy_from_list(opt_list) return self._copy_from_list(opt_list)
class PcaOptionsDialog(OptionsDialog):
"""Options dialog for Principal Component Analysis.
"""
def __init__(self, data, options, input_names=['X']):
OptionsDialog.__init__(self, data, options, input_names)
class PlsOptionsDialog(OptionsDialog):
"""Options dialog for Partial Least Squares Regression.
"""
def __init__(self, data, options, input_names=['X', 'Y']):
OptionsDialog.__init__(self, data, options, input_names)