Added Optionsdialog for pca and pls
This commit is contained in:
		@@ -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
 | 
			
		||||
@@ -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()
 | 
			
		||||
@@ -150,6 +148,21 @@ class PCA(Model):
 | 
			
		||||
            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
 | 
			
		||||
@@ -271,6 +284,20 @@ class PLS(Model):
 | 
			
		||||
            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.
 | 
			
		||||
@@ -302,18 +329,6 @@ class Packer:
 | 
			
		||||
        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['all_plots'] = [(blmplots.PlsScorePlot, 'Scores', True),
 | 
			
		||||
                            (blmplots.PlsLoadingPlot, 'Loadings', True),
 | 
			
		||||
                            (blmplots.LineViewXc, 'Line view', True)]
 | 
			
		||||
                            
 | 
			
		||||
        opt['out_data'] = []
 | 
			
		||||
        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)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user