[Home] DMelt member access. Java source code: com.datumbox.framework.core.machinelearning.clustering.GaussianDPMM
/**
* Copyright (C) 2013-2017 Vasilis Vryniotis
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.datumbox.framework.core.machinelearning.clustering;
import com.datumbox.framework.common.Configuration;
import com.datumbox.framework.core.common.dataobjects.DataframeMatrix;
import com.datumbox.framework.core.common.dataobjects.Record;
import com.datumbox.framework.common.storage.interfaces.StorageEngine;
import com.datumbox.framework.core.machinelearning.common.abstracts.AbstractTrainer;
import com.datumbox.framework.core.machinelearning.common.abstracts.algorithms.AbstractDPMM;
import com.datumbox.framework.core.machinelearning.common.abstracts.modelers.AbstractClusterer;
import org.apache.commons.math3.linear.*;
import java.util.Map;
/**
* The GaussianDPMM implements Dirichlet Process Mixture Models with Multivariate
* Normal and Normal-Inverse-Wishart prior.
*
* References:
* http://blog.datumbox.com/overview-of-cluster-analysis-and-dirichlet-process-mixture-models/
* http://blog.datumbox.com/clustering-documents-and-gaussian-data-with-dirichlet-process-mixture-models/
* http://snippyhollow.github.io/blog/2013/03/10/collapsed-gibbs-sampling-for-dirichlet-process-gaussian-mixture-models/
* http://blog.echen.me/2012/03/20/infinite-mixture-models-with-nonparametric-bayes-and-the-dirichlet-process/
* http://www.cs.princeton.edu/courses/archive/fall07/cos597C/scribe/20070921.pdf
*
* @author Vasilis Vryniotis
*/
public class GaussianDPMM extends AbstractDPMM {
/**
* The AbstractCluster class of the GaussianDPMM model.
*/
public static class Cluster extends AbstractDPMM.AbstractCluster {
private static final long serialVersionUID = 2L;
//informational fields
private final int dimensions;
//hyper parameters
private final int kappa0;
private final int nu0;
private final RealVector mu0;
private final RealMatrix psi0;
//cluster parameters
private RealVector mean;
private RealMatrix covariance;
//validation - confidence interval vars
private RealMatrix meanError;
private int meanDf;
//internal vars for calculation
private RealVector xi_sum;
private RealMatrix xi_square_sum;
//Cache
private volatile Double cache_covariance_determinant;
private volatile Array2DRowRealMatrix cache_covariance_inverse;
/**
* @param clusterId
* @param kappa0
* @param nu0
* @param dimensions
* @param mu0
* @param psi0
* @see AbstractClusterer.AbstractCluster
*/
protected Cluster(Integer clusterId, int dimensions, int kappa0, int nu0, RealVector mu0, RealMatrix psi0) {
super(clusterId);
if(nu0 getFeatureIds() {
return featureIds;
}
/** {@inheritDoc} */
@Override
protected void setFeatureIds(Map