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)
"""
import sys
# add library
sys.path.append('/home/flatberg/fluents/fluents/lib')
import time
from fluents.workflow import Function
import gtk
from fluents.workflow import Function, OptionsDialog, Options
from fluents.dataset import Dataset
from fluents import plots, dataset, workflow, logger
import scipy
@ -40,7 +38,7 @@ class PCA(Model):
def __init__(self,id='pca',name='PCA'):
Model.__init__(self,id,name)
self._options = PcaOptions()
def pre_validation(self, amax, n_sets, val_engine):
"""Model calculations for maximum number of components.
"""
@ -127,7 +125,7 @@ class PCA(Model):
#logger.log('debug', 'Plot: %s failed') %plt
return out
def run(self, data):
def run_o(self, data):
"""Run pca with present options.
"""
self.clear()
@ -149,7 +147,22 @@ class PCA(Model):
for plt in self.get_out_plots(options):
out.append(plt)
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):
def __init__(self, id='pls', name='PLS'):
@ -238,7 +251,7 @@ class PLS(Model):
# logger.log('debug', 'Plot: %s failed' %plt)
return out
def run(self,a,b):
def run_o(self, a, b):
options = self._options
self._dataset['X'] = a
self._dataset['Y'] = b
@ -270,7 +283,21 @@ class PLS(Model):
for plt in self.get_out_plots(options):
out.append(plt)
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:
"""A compression object used to speed up model calculations.
@ -300,19 +327,7 @@ class Packer:
def get_packed_data(self):
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):
"""Options for Principal Component Analysis.
@ -344,9 +359,17 @@ class PcaOptions(Options):
opt['val_engine'] = pca_alter_val
opt['val_n_sets'] = 10
opt['all_data'] = ['T','P','E','p_tsq','rmsep']
opt['all_plots'] = ['PcaScorePlot', 'PcaLoadingPlot',
'PcaRmsepPlot']
opt['all_data'] = [('T', 'scores', True),
('P', 'loadings', True),
('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_plots'] = [blmplots.PcaScorePlot,blmplots.PcaLoadingPlot,blmplots.LineViewXc]
@ -399,20 +422,27 @@ class PlsOptions(Options):
opt['val_engine'] = w_pls_cv_val
opt['all_data'] = ['T','P','E','p_tsq','rmsep']
opt['all_plots'] = ['PcaScorePlot', 'PcaLoadingPlot',
'PcaRmsepPlot']
opt['all_data'] = [('T', 'scores', True),
('P', 'loadings', True),
('E','residuals', False),
('p_tsq', 't2', False),
('rmsep', 'root mean square error of prediction', False)
]
opt['out_data'] = []
opt['all_plots'] = [(blmplots.PlsScorePlot, 'Scores', True),
(blmplots.PlsLoadingPlot, 'Loadings', True),
(blmplots.LineViewXc, 'Line view', True)]
opt['out_plots'] = [blmplots.PlsScorePlot,
blmplots.PlsLoadingPlot,
blmplots.LineViewXc]
#blmplots.PlsQvalScatter]
opt['out_data'] = None
opt['pack'] = False
opt['calc_qvals'] = False
opt['q_pert_mth'] = 'shuffle_vars'
opt['q_iter'] = 20
self.update(opt)
def make_model_options(self):
@ -430,3 +460,17 @@ class PlsOptions(Options):
"""Options for pre_validation method."""
opt_list = ['amax', 'n_sets', 'val_engine']
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)