width = 800 height = 400 scale = 1.5 * max(map(lambda i: gt_weight[i]*gt[i].prob(gt[i].getMean()), xrange(len(gt)))) # Fill in the model... model = DPGMM(dims) for point in samples: model.add(point) model.setPrior() # Iterate over the number of sticks, increasing till it stops getting better... prev = None while True: print 'Stick count = %i'%model.getStickCap() p = ProgBar() it = model.solve() del p print 'Updated fitting in %i iterations'%it # Now plot the estimated distribution against the actual distribution... img = numpy.ones((height,width,3)) draw = model.sampleMixture() for px in xrange(width): x = float(px)/float(width) * (high-low) + low y_gt = 0.0 for ii in xrange(len(gt)): y_gt += gt_weight[ii] * gt[ii].prob([x])
# Train a model... print 'Trainning model...' model = DPGMM(3) for feat in train: model.add(feat) model.setPrior( ) # This sets the models prior using the data that has already been added. model.setConcGamma( 1.0, 0.25 ) # Make the model a little less conservative about creating new categories.. p = ProgBar() iters = model.solveGrow() del p print 'Solved model with %i iterations' % iters # Classify the test set... probs = model.stickProb(numpy.array(map(lambda t: t[0], test))) catGuess = probs.argmax(axis=1) catTruth = numpy.array(map(lambda t: t[1], test)) confusion_matrix = numpy.zeros((count, model.getStickCap() + 1), dtype=numpy.int32) for i in xrange(len(catGuess)): confusion_matrix[catTruth[i], catGuess[i]] += 1 print 'Confusion matrix [truth, guess], noting that class labels will not match:' print confusion_matrix
test.append((s, which)) # Train a model... print "Trainning model..." model = DPGMM(3) for feat in train: model.add(feat) model.setPrior() # This sets the models prior using the data that has already been added. model.setConcGamma(1.0, 0.25) # Make the model a little less conservative about creating new categories.. p = ProgBar() iters = model.solveGrow() del p print "Solved model with %i iterations" % iters # Classify the test set... probs = model.stickProb(numpy.array(map(lambda t: t[0], test))) catGuess = probs.argmax(axis=1) catTruth = numpy.array(map(lambda t: t[1], test)) confusion_matrix = numpy.zeros((count, model.getStickCap() + 1), dtype=numpy.int32) for i in xrange(len(catGuess)): confusion_matrix[catTruth[i], catGuess[i]] += 1 print "Confusion matrix [truth, guess], noting that class labels will not match:" print confusion_matrix
high = 14.0 width = 800 height = 400 scale = 1.5 * max( map(lambda i: gt_weight[i] * gt[i].prob(gt[i].getMean()), xrange(len(gt)))) # Fill in the model... model = DPGMM(dims) for point in samples: model.add(point) model.setPrior() # Iterate over the number of sticks, increasing till it stops getting better... prev = None while True: print 'Stick count = %i' % model.getStickCap() p = ProgBar() it = model.solve() del p print 'Updated fitting in %i iterations' % it # Now plot the estimated distribution against the actual distribution... img = numpy.ones((height, width, 3)) draw = model.sampleMixture() for px in xrange(width): x = float(px) / float(width) * (high - low) + low y_gt = 0.0 for ii in xrange(len(gt)): y_gt += gt_weight[ii] * gt[ii].prob([x])