Commit 80b46e76 authored by Klaas Winter's avatar Klaas Winter

Made standardisation before kmeans optional

In the clustering menu, an switch has been added with which this
behaviour can be switched. Closes #6.
parent e61bb6b1
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# cluster.kmeans(vars=c("M4", "M20", "M28", "M36", "M40", "M44", "M48"), identifier="kmeans_30_7", centers=30) # cluster.kmeans(vars=c("M4", "M20", "M28", "M36", "M40", "M44", "M48"), identifier="kmeans_30_7", centers=30)
cluster.kmeans <- function(rows = c(), vars, identifier, centers = NA, iter.max=10) { cluster.kmeans <- function(rows = c(), vars, identifier, centers = NA, iter.max=10, standardize = T) {
clusterData <- data.get(rows, vars) clusterData <- data.get(rows, vars)
clusterRows <- clusterData$row clusterRows <- clusterData$row
clusterData$row <- NULL clusterData$row <- NULL
...@@ -25,7 +25,7 @@ cluster.kmeans <- function(rows = c(), vars, identifier, centers = NA, iter.max= ...@@ -25,7 +25,7 @@ cluster.kmeans <- function(rows = c(), vars, identifier, centers = NA, iter.max=
if (is.na(centers)) centers <- floor(sqrt(nrow(clusterData))) if (is.na(centers)) centers <- floor(sqrt(nrow(clusterData)))
# Make sure that the data is standardised # Make sure that the data is standardised
clusterData <- scale(clusterData) if (standardize) clusterData <- scale(clusterData)
clusters <- as.factor(stats::kmeans(clusterData, centers, iter.max)$cluster) clusters <- as.factor(stats::kmeans(clusterData, centers, iter.max)$cluster)
clusters <- data.frame(row = clusterRows, cluster = clusters) clusters <- data.frame(row = clusterRows, cluster = clusters)
......
This diff is collapsed.
...@@ -48,6 +48,7 @@ angular.module('contigBinningApp.controllers') ...@@ -48,6 +48,7 @@ angular.module('contigBinningApp.controllers')
method: $scope.options.methods[0], method: $scope.options.methods[0],
identifier: $scope.options.methods[0].name + '_' + previousCentersCount + '_0', identifier: $scope.options.methods[0].name + '_' + previousCentersCount + '_0',
centers: previousCentersCount, // NOTE: The naming is kmeans specific centers: previousCentersCount, // NOTE: The naming is kmeans specific
standardize: true,
variables: [] variables: []
}; };
...@@ -59,6 +60,10 @@ angular.module('contigBinningApp.controllers') ...@@ -59,6 +60,10 @@ angular.module('contigBinningApp.controllers')
$modalInstance.close($scope.specified); $modalInstance.close($scope.specified);
}; };
$scope.hideStandardization = function () {
return $scope.specified.method.name !== "kmeans";
};
$scope.hideCenters = function () { $scope.hideCenters = function () {
if ($scope.specified.method.name !== "kmeans") { if ($scope.specified.method.name !== "kmeans") {
previousCentersCount = $scope.specified.centers; previousCentersCount = $scope.specified.centers;
......
...@@ -42,11 +42,12 @@ angular.module('contigBinningApp.controllers') ...@@ -42,11 +42,12 @@ angular.module('contigBinningApp.controllers')
// every clustering method we add. // every clustering method we add.
if (config.method.name === "kmeans") { if (config.method.name === "kmeans") {
args.centers = config.centers; args.centers = config.centers;
args.standardize = config.standardize;
} else if (config.method.name !== "correlation") { } else if (config.method.name !== "correlation") {
//FIXME get rid of this hard coded value, change it to a simple else //FIXME get rid of this hard coded value, change it to a simple else
throw "Unknown clustering method: " + config.method.name; throw "Unknown clustering method: " + config.method.name;
} }
Analytics.cluster( Analytics.cluster(
config.method.name, config.method.name,
_.map(config.variables, _.map(config.variables,
......
...@@ -38,6 +38,16 @@ ...@@ -38,6 +38,16 @@
</div> </div>
</div> </div>
</fieldset> </fieldset>
<fieldset>
<div class="form-group">
<div class="col-sm-3" ng-hide="hideStandardization()"></div>
<div class="col-sm-9">
<button type="button" class="btn btn-sm btn-default" ng-model="specified.standardize" btn-checkbox btn-checkbox-true="true" btn-checkbox-false="false" ng-hide="hideStandardization()">
Standardize data before clustering
</button>
</div>
</div>
</fieldset>
<fieldset> <fieldset>
<div class="from-group"> <div class="from-group">
<label class="col-sm-3 control-label" for="inpIdentifier">Cluster variables:</label> <label class="col-sm-3 control-label" for="inpIdentifier">Cluster variables:</label>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment