Giter Site home page Giter Site logo

joint-and-conditional-pdfs-plots's Introduction

Joint-and-Conditional-PDFs-Plots

Given below is the joint pdf of random variables X and Y and c is normalising constant.

Plotting their marginals, joint pdfs, conditional pdf for a given x or y is done in MATLAB.

Plot Joint PDF f(x,y)

  1. First we will initialise range spaces of x and y
  2. Then form a grid with x and y coordinates
  3. Initialise the function and apply the conditions
  4. Then plot the 3D plot.S
  5. Sample code and output is shown below.
%initialising range spaces of x and y
g = 0:0.01:1-0.01;
[x,y]=meshgrid(g); %x and y  coordinates are taken as a grid

cond = (y <= x);   %storing values x>=y   if y>x value will be zero
cond = double(cond); %converting it into matrix so that we can access each element
 
f = 8*x.*y;  %given function
f_plot = f.*cond; %applying condition to the function

% plotting the given function
figure(1)
surfc(g,g,f_plot)
xlabel('X');
ylabel('Y');
zlabel('f(x,y)');
title("Joint pdf f(x,y)");

Marginal PDF of x

  1. Calculate mar_x function for all y's
  2. Since function f is stored as matrix and mar_x is stored as vector , we use bsxfun to divide matrix with vector.
marg_x = 4*g.^3;%marginal of x
z2 = bsxfun(@rdivide,f,marg_x);%func used to divide matrix and an array to find condtional func y|x
figure(5)
plot(g,marg_x)
xlabel('X');
ylabel('marg_x');
title("marginal pdf of x");

Marginal PDF of y

  1. Calculate mar_y function for all x's
  2. Since function f is stored as matrix and mar_y is stored as vector , we use bsxfun to divide matrix with vector.
marg_y=(4*g)-(4*g.^3);%marginal of y
z1 = bsxfun(@rdivide,f,marg_y');  %func used to divide matrix and an array to find condtional func x|y
figure(4)
plot(g,marg_y)
xlabel('Y');
ylabel('marg_y');
title("marginal pdf of y");

Conditional PDFs

%plotting conditional pdfs of x and y for given y and x values repectively
figure(2)
plot(g,z1(50,:))
xlabel('X');
ylabel('f(x|y)');
title("Conditional PDFs f(x|y) for given y value (y = 0.5)");

figure(3)
plot(g,z2(:,50))
xlabel('Y');
ylabel('f(y|x)');
title("Conditional PDFs f(y|x) for given x value");

joint-and-conditional-pdfs-plots's People

Contributors

ashcode028 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.