You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: cpd_P.m
    path of file: ./repos/GMM-FEM/Core
    
    the code of the file until where you have to start completion: function [ P, P1, Pt1, Np ] = cpd_P( X, TY, sigma2, w)
%CPD_P Computes the probability matrix for the CPD algorithm

    
function [ P, P1, Pt1, Np ] = cpd_P( X, TY, sigma2, w)
%CPD_P Computes the probability matrix for the CPD algorithm
%
%   P = cpd_P(x, Ty, sigma2, w) computes the CPD probability matrix 
%
%   Inputs:
%   X    N x D matrix of the data points
%   TY   M x D matrix of transformed Gaussian centres
%   sigma2  Standard deviation of Gaussians
%   w    weight to account for noise and outliers (optional, defaults to 0)
%   Outputs:
%   P    M x N matrix of assignment
%   P1   M x 1 vector, sum(Pij,j=1..N)
%   Pt1  N x 1 vector, sum(Pij',i=1..M);
%   Np   Summation over all elements of P

    % default to w = 0
    if (nargin < 4 || isempty(w)) 
        w = 0;
    end