[GRASS-SVN] r66482 - in grass-addons/grass7: raster/r.shaded.pca vector/v.class.ml vector/v.class.mlpy
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Oct 12 18:30:35 PDT 2015
Author: wenzeslaus
Date: 2015-10-12 18:30:35 -0700 (Mon, 12 Oct 2015)
New Revision: 66482
Modified:
grass-addons/grass7/raster/r.shaded.pca/r.shaded.pca.py
grass-addons/grass7/vector/v.class.ml/v.class.ml.html
grass-addons/grass7/vector/v.class.ml/v.class.ml.py
grass-addons/grass7/vector/v.class.mlpy/v.class.mlpy.html
grass-addons/grass7/vector/v.class.mlpy/v.class.mlpy.py
Log:
v.class.ml and v.class.mlpy: lazy import special dependencies to compile on build server
Also fix See also and add Author and svn date to manuals.
Modified: grass-addons/grass7/raster/r.shaded.pca/r.shaded.pca.py
===================================================================
--- grass-addons/grass7/raster/r.shaded.pca/r.shaded.pca.py 2015-10-13 00:34:33 UTC (rev 66481)
+++ grass-addons/grass7/raster/r.shaded.pca/r.shaded.pca.py 2015-10-13 01:30:35 UTC (rev 66482)
@@ -5,7 +5,7 @@
# MODULE: r.shaded.pca
# AUTHOR(S): Vaclav Petras
# PURPOSE: Creates RGB composition from PCA of hill shades
-# COPYRIGHT: (C) 2013-2014 by the GRASS Development Team
+# COPYRIGHT: (C) 2013-2014 by Vaclav Petras and the GRASS Development Team
#
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
@@ -14,7 +14,8 @@
#############################################################################
#%module
-#% description: Creates shades from various directions and combines then into RGB composition.
+#% label: Creates relief shades from various directions and combines them into RGB composition.
+#% description: The combined shades highlight terrain features which wouldn't be visible using standard shading technique.
#% keyword: raster
#% keyword: elevation
#% keyword: terrain
Modified: grass-addons/grass7/vector/v.class.ml/v.class.ml.html
===================================================================
--- grass-addons/grass7/vector/v.class.ml/v.class.ml.html 2015-10-13 00:34:33 UTC (rev 66481)
+++ grass-addons/grass7/vector/v.class.ml/v.class.ml.html 2015-10-13 01:30:35 UTC (rev 66482)
@@ -199,3 +199,15 @@
generate the output raster map for each algorithm.
+<h2>SEE ALSO</h2>
+
+<em><a href="v.class.mlpy.html">v.class.mlpy</a></em> (a simpler module
+for vector classification which uses <em>mlpy</em>)
+
+
+<h2>AUTHOR</h2>
+
+Pietro Zambelli, University of Trento
+
+<p>
+<i>Last changed: $Date$</i>
Modified: grass-addons/grass7/vector/v.class.ml/v.class.ml.py
===================================================================
--- grass-addons/grass7/vector/v.class.ml/v.class.ml.py 2015-10-13 00:34:33 UTC (rev 66481)
+++ grass-addons/grass7/vector/v.class.ml/v.class.ml.py 2015-10-13 01:30:35 UTC (rev 66482)
@@ -16,9 +16,10 @@
#############################################################################
#%Module
-#% description: Vector
+#% description: Classification of a vector maps based on the values in attribute tables
+#% keyword: vector
+#% keyword: classification
#% keyword: machine learning
-#% keyword: classification
#% overwrite: yes
#%End
#%option G_OPT_V_MAP
@@ -368,8 +369,6 @@
from fnmatch import fnmatch
import numpy as np
-from sklearn.preprocessing import StandardScaler
-from sklearn.svm import SVC
from grass.pygrass.utils import get_lib_path
from grass.pygrass.messages import get_msgr
@@ -385,18 +384,10 @@
from training_extraction import extract_training
-from ml_classifiers import CLASSIFIERS
-from ml_functions import (balance, explorer_clsfiers, run_classifier,
- optimize_training, explore_SVC, plot_grid)
from sqlite2npy import save2npy
from npy2table import export_results
-from features import importances, tocsv
-from sklearn.decomposition import (PCA, KernelPCA, ProbabilisticPCA,
- RandomizedPCA, FastICA, TruncatedSVD)
-from sklearn.lda import LDA
-
RULES = {'*_skewness': np.nanmean,
'*_coeff_var': np.nanmean,
'*_stddev': np.nanmean,
@@ -407,15 +398,25 @@
'*_min': np.nanmin, }
-DECMP = {'PCA': PCA,
- 'KernelPCA': KernelPCA,
- 'ProbabilisticPCA': ProbabilisticPCA,
- 'RandomizedPCA': RandomizedPCA,
- 'FastICA': FastICA,
- 'TruncatedSVD': TruncatedSVD,
- 'LDA': LDA}
+DECMP = {}
+def load_decompositions():
+ """Import decompositions and update dictionary which stores them"""
+ from sklearn.decomposition import (PCA, KernelPCA, ProbabilisticPCA,
+ RandomizedPCA, FastICA, TruncatedSVD)
+ from sklearn.lda import LDA
+ DECMP.update({
+ 'PCA': PCA,
+ 'KernelPCA': KernelPCA,
+ 'ProbabilisticPCA': ProbabilisticPCA,
+ 'RandomizedPCA': RandomizedPCA,
+ 'FastICA': FastICA,
+ 'TruncatedSVD': TruncatedSVD,
+ 'LDA': LDA
+ })
+
+
def get_indexes(string, sep=',', rangesep='-'):
"""
>>> indx = '1-5,34-36,40'
@@ -505,6 +506,11 @@
def main(opt, flg):
+ # import functions which depend on sklearn only after parser run
+ from ml_functions import (balance, explorer_clsfiers, run_classifier,
+ optimize_training, explore_SVC, plot_grid)
+ from features import importances, tocsv
+
msgr = get_msgr()
indexes = None
vect = opt['vector']
@@ -519,6 +525,7 @@
if opt['scalar']:
scapar = opt['scalar'].split(',')
+ from sklearn.preprocessing import StandardScaler
scaler = StandardScaler(with_mean='with_mean' in scapar,
with_std='with_std' in scapar)
@@ -528,6 +535,7 @@
else (opt['decomposition'], ''))
kwargs = ({k: v for k, v in (p.split('=') for p in params.split(','))}
if params else {})
+ load_decompositions()
decmp = DECMP[dec](**kwargs)
# if training extract training
@@ -549,10 +557,12 @@
mycls = imp.load_source("mycls", opt['pyclassifiers'])
classifiers = getattr(mycls, opt['pyvar'])
else:
+ from ml_classifiers import CLASSIFIERS
classifiers = CLASSIFIERS
# Append the SVC classifier
if opt['svc_c'] and opt['svc_gamma']:
+ from sklearn.svm import SVC
svc = {'name': 'SVC', 'classifier': SVC,
'kwargs': {'C': float(opt['svc_c']),
'gamma': float(opt['svc_gamma']),
Modified: grass-addons/grass7/vector/v.class.mlpy/v.class.mlpy.html
===================================================================
--- grass-addons/grass7/vector/v.class.mlpy/v.class.mlpy.html 2015-10-13 00:34:33 UTC (rev 66481)
+++ grass-addons/grass7/vector/v.class.mlpy/v.class.mlpy.html 2015-10-13 01:30:35 UTC (rev 66482)
@@ -88,14 +88,16 @@
<h2>SEE ALSO</h2>
-<em><a href="v.class">v.class</a></em> for unsupervised attributes
+<em><a href="v.class.html">v.class</a></em> for unsupervised attributes
classification,
-<em><a href="v.to.db">v.to.db</a></em> for populating attribute values
+<em><a href="v.to.db.html">v.to.db</a></em> for populating attribute values
from vector features,
-<em><a href="v.what.rast">v.what.rast</a></em> for uploading raster
+<em><a href="v.what.rast.html">v.what.rast</a></em> for uploading raster
values to attribute columns,
-<em><a href="v.rast.stats">v.rast.stats</a></em> for uploading raster
-statistics to attribute columns
+<em><a href="v.rast.stats.html">v.rast.stats</a></em> for uploading raster
+statistics to attribute columns,
+<em><a href="v.class.ml.html">v.class.ml</a></em> for a more powerful vector
+classification module which uses <em>scikit-learn</em>
<h2>REFERENCES</h2>
Modified: grass-addons/grass7/vector/v.class.mlpy/v.class.mlpy.py
===================================================================
--- grass-addons/grass7/vector/v.class.mlpy/v.class.mlpy.py 2015-10-13 00:34:33 UTC (rev 66481)
+++ grass-addons/grass7/vector/v.class.mlpy/v.class.mlpy.py 2015-10-13 01:30:35 UTC (rev 66482)
@@ -67,17 +67,7 @@
import numpy as np
-try:
- import mlpy
-except ImportError:
- grass.fatal(_("Cannot import mlpy (http://mlpy.sourceforge.net) library."
- " Please install it or ensure that it is on path"
- " (use PYTHONPATH variable)."))
-# Pytlit has a problem with this mlpy and v.class.mlpy.py
-# thus, warinings for objects from mlpy has to be disabled
-
-
def addColumn(mapName, columnName, columnType):
"""Adds column to the map's table."""
columnDefinition = columnName + ' ' + columnType
@@ -125,6 +115,15 @@
It does not uses numpy in the interface bu this may be wrong.
"""
def __init__(self):
+ try:
+ import mlpy
+ except ImportError:
+ grass.fatal(_("Cannot import mlpy (http://mlpy.sourceforge.net)"
+ " library."
+ " Please install it or ensure that it is on path"
+ " (use PYTHONPATH variable)."))
+ # Pytlit has a problem with this mlpy and v.class.mlpy.py
+ # thus, warinings for objects from mlpy has to be disabled
self.mlclassifier = mlpy.DLDA(delta=0.01) # pylint: disable=E1101
def learn(self, values, classes):
More information about the grass-commit
mailing list