Added Optionsdialog for pca and pls
This commit is contained in:
parent
e08a8377ed
commit
f7fe171896
|
@ -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
|
||||||
|
@ -40,7 +38,7 @@ class PCA(Model):
|
||||||
def __init__(self,id='pca',name='PCA'):
|
def __init__(self,id='pca',name='PCA'):
|
||||||
Model.__init__(self,id,name)
|
Model.__init__(self,id,name)
|
||||||
self._options = PcaOptions()
|
self._options = PcaOptions()
|
||||||
|
|
||||||
def pre_validation(self, amax, n_sets, val_engine):
|
def pre_validation(self, amax, n_sets, val_engine):
|
||||||
"""Model calculations for maximum number of components.
|
"""Model calculations for maximum number of components.
|
||||||
"""
|
"""
|
||||||
|
@ -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()
|
||||||
|
@ -149,7 +147,22 @@ class PCA(Model):
|
||||||
for plt in self.get_out_plots(options):
|
for plt in self.get_out_plots(options):
|
||||||
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
|
||||||
|
@ -270,7 +283,21 @@ class PLS(Model):
|
||||||
for plt in self.get_out_plots(options):
|
for plt in self.get_out_plots(options):
|
||||||
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.
|
||||||
|
@ -300,19 +327,7 @@ class Packer:
|
||||||
|
|
||||||
def get_packed_data(self):
|
def get_packed_data(self):
|
||||||
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['out_data'] = []
|
opt['all_plots'] = [(blmplots.PlsScorePlot, 'Scores', True),
|
||||||
|
(blmplots.PlsLoadingPlot, 'Loadings', True),
|
||||||
|
(blmplots.LineViewXc, 'Line view', True)]
|
||||||
|
|
||||||
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)
|
||||||
|
|
Reference in New Issue