Code

Project: jvfeatures

jvtypes.h      jvfeatures.h      chessSeg.cpp      jvtypes.cpp      jvtest.cpp      jvfeatures.cpp     

Project: Other

migrateMailbox.scpt.txt     

Project: Infinite HMM Tutorial

run.m      iHMM_tutorial.zip      HDP_HMM.m      README.txt      ConditionalProbabilityTable.m      HDP.m      HMMProblem.m      HMM.m     

Project: RRT

RRT.h      plot_output.py      RRT.tgz      rrt_test.cpp      RRT.cpp      BidirectionalRRT.cpp      AbstractRRT.cpp     

Project: Box2D_friction_mod

WheelConstraint.h      test_TopDownCar.py      b2FrictionJoint.h      python_friction_joint.patch      test_TopDownFrictionJoint.py      TestEntries.cpp      TopDownCar.h      b2FrictionJoint.cpp      box2d_friction_joint.patch     

Project: Dirichlet Process Mixture Tutorial

EM_GM.m      DP_Demo.m      DPMM.m      DP_Tutorial.zip      DirichletProcess.m      gaussian_EM.m     

Project: Arduino_Code

plot_ardunio_data.sh      Arduino_Code.zip      convert_range2D.py      arduino-serial.c      oscilloscope.sh      oscilloscope.pde      motordriver.pde      helicopter_controller.pde      accelerometer_test.pde      ranger_plane_sweep.pde      clodbuster_controller.pde      pwm_manual.pde      ranger_test.pde      servo_test.pde     

Project: ArduCom

arducom.py      setup.py     

Project: support

geshi.php      Protector.php     

Project: Cogent

CodePane.php      NotesPane.php      PicsPane.php      Cogent.php      PubsTable.php     
Click here to download "resources/code/Dirichlet Process Mixture Tutorial/DirichletProcess.m"

resources/code/Dirichlet Process Mixture Tutorial/DirichletProcess.m

classdef DirichletProcess < handle
    %DIRICHLETPROCESS A simple class for simulating runs from a dirichlet
    % process (implements polya urn)
    %
   
    properties(Access=public)
        alpha = 1;  % concentration parameter
        X = [];     % vector of cluster values (can be nominal or numeric)
    end
   
    methods(Access=public)
        function obj = DirichletProcess(varargin)
            if nargin > 0
                obj.alpha = varargin{1};
            end
            obj.X = obj.H_samp;
        end
       
        function DP_step(obj)
            % Generates one sample according to polya urn process for
            % current parameters of the process; equivalent to predictive
            % distribution of DP given base distribution and all observed
            % data so far.
           
            a = obj.alpha;
            n = length(obj.X);
           
            if rand < a/(n+a)
                % draw new sample from H
                obj.X = [obj.X obj.H_samp];
                %fprintf('new cluster at %f\n', obj.X(end));
            else
                % draw sample from empirical distribution
                newX = obj.X(ceil(rand*length(obj.X)));
                obj.X = [obj.X newX];
                %fprintf('incrementing cluster at %f\n', newX);
            end
        end
       
        function DP_run(obj, n)
            % Run the DP for n steps
            for i=1:n
                obj.DP_step;
            end
        end
       
        function k = get_k(obj)
            % @return the number of clusters in the current distribution
            k = length(unique(obj.X));
        end
    end
   
    methods(Access=public, Static)
        function k = get_k_expected(a, n)
            % @return the expected number of clusters given the values of
            % a and n
            k = floor(a * log(1 + n/a));
        end
    end
   
    methods(Access=private)
        function x = H_samp(obj)
            x = normrnd(0, 1); % A standard Normal
            %x = unifrnd(-5, 5); % A uniform on 0:1
            % obj.alpha/length(obj.X) % symmetric dirichlet
        end
    end
end

About me

Pic of me