Comments (3)
Hey, thanks for using the package.
dp$numberClusters
is the number of clusters for the last iteration of the fitting process, so will vary, it's just one sample of the DP process. As its a Bayesian model, each data point will have a distribution of likely cluster assignment, rather than just one label.
Does that help?
from dirichletprocess.
Hi, thanks for your answer. So when I understood correctly, ``dp$numberClusters` refers only to the last iteration of the MCMC fit. Given that, how can I determine the most likely cluster label for a given data point? In your blog about "Dirichlet Process Cluster Probabilities," you use
numClusters <- dp$numberClusters
clusterLabelProbs <- matrix(nrow=nrow(faithfulTrans), ncol=numClusters + 1)
to determine the required number of columns. As you see in my case, this won't work since the number of clusters strongly varies between iterations.
Does it make sense that when I have n-iterations for my cluster labels contained in the dp$labelsChain, to extract always i-th element, for the i-th data point and use the most frequently occurring cluster assignment?
Something like:
library(purrr) # includes the map function to extract ith element from a list of lists
labels1 <- list()
for(i in 1:length(dp$clusterLabels)){
labels1[[as.character(i)]] <- as.numeric(rownames(as.matrix(sort(table(unlist(map(dp$labelsChain, i))),
decreasing = T)))[1])
unlist(labels1)
Moreover, I have a similar problem with the ClusterLabelPredict
function.
When I apply it twice to the same newData
and the same fitted dp-object I get varying results. I assume this is also because it is a random draw from the posterior. However, when I repeat the prediction several times and take the most frequent clusterLabel prediction is stabilized, something like:
## Generating prediction for first two rows of the training set
prediction1 <- replicate(1000, list(ClusterLabelPredict(dp, newData = dp$data[1:2,])))
prediction2 <- replicate(1000, list(ClusterLabelPredict(dp, newData = dp$data[1:2,])))
ยด## Extracting Frequencies for newData item 2`
t1 <- sort(table(unlist(map(map(prediction1, 1),2))), decreasing = T)[1]
t2 <- sort(table(unlist(map(map(prediction2, 1),2))), decreasing = T)[1]
Or is there any more convenient way to extract the most likely cluster label?
from dirichletprocess.
Yeah everything above is correct, you ClusterLabelPredict
is just one sample from the posterior and therefore need to do multiple draws, like you have.
Unfortunately, nothing more convenient, but your code looks fine.
from dirichletprocess.
Related Issues (20)
- pre-allocation issue in PosteriorDraw.nonconjugate HOT 1
- Limit on the post_draws in Initialise HOT 1
- dirichletprocess.rdb is corrupt HOT 3
- Only symmetric kernels supported for proposals in Metropolis-Hastings algorithm HOT 1
- Error in y[which(clusterLabels == i), , drop = FALSE] : subscript out of bounds HOT 1
- constrain clusters to have common parameters? HOT 1
- clustering high-dimensional data? HOT 6
- Error in update_concentration ? HOT 1
- Problem with convergence of the likelihoodChain HOT 4
- Restart the chain from where it stops HOT 8
- HDP Fit function returns an empty object with an error when accessed HOT 2
- wrong number of dimensions from LikelihoodDP() HOT 2
- The role of "n" in the PosteriorDrawer.exp function (in custom mixtures part)
- Potential bug in Predictive.mvnormal()
- Wrong number of dimensions in Likelihood.normal()
- Issue with the LikelihoodDP() function
- Sampling Posterior HOT 3
- plot's dimension in a clustering of multivariate case. HOT 1
- Initialization to one cluster with all data points. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dirichletprocess.