Skip to main content
added 1071 characters in body
Source Link
user4860
user4860

I have a function,

f[dist_, samp_]:=somework[dist, samp]

that I want to return Null or zero if passed a null distribution. I can't find a way to test for a difference between Null and Data distribution: none of ===, =!=, SameQ and == can identify them.

How can I tell if I'm being passed a Null value to handle it correctly?

f[dist_, samp_]:=something[dist, samp] /; TrueQ[dist==DataDistribution]

Seems to be close to what I want.

EDIT: Edited for some clarity.

Here's my function. If probKern is a Null, I want to return a Null, otherwise, I want to calculate the PDF for the sample, with the distribution. I can't quite get a handle on matching the types to make this work though.

calcPDF[probKern_, samp_] := 
 Null /; TrueQ[probKern != DataDistribution]

calcPDF[probKern_Symbol, samp_] := 
 PDF[probKern, samp] /; TrueQ[probKern == DataDistribution]

edit: Okay, I'm still having trouble with this. Here's what I have:

calcPDF[probKern_DataDistribution, samp_] := PDF[probKern, samp]  
calcPDF[Except[_DataDistribution, probkern_?DistributionParameterQ], samp_] := -1 
calcPDF[_] := $Failed

Given a data distribution and a value it works fine.

In[38]:= calcPDF[data, 3]

Out[38]= 0.007500611755

Given two numbers, it produces the symbolic value, rather than the -1 I was expect. (The -1 is just a placeholder)

In[39]:= calcPDF[3, 3]

Out[39]= calcPDF[3, 3]

EDIT dec 5th: Running calcPDF by hand seems to result in correct results, but now, when it is threaded over data, the result is a single result of whatever you return in the Except case. There's two sets of distributions I'm running over the sample data, so the final result is a list of two Nulls (or -1's).

If you remove the Except case, you get closer to the expected result - two lists 205 elements long, containing PDF's for entries with matching Distributions, and PDF[Null, value] for those without.

I'm confused.

Clear[calcPDF] (*calcPDF[probKern_, samp_]:=PDF[probKern, samp]; *) calcPDF[probKern_DataDistribution, samp_] := PDF[probKern, samp]; calcPDF[Except[DataDistribution], samp] := Null;

(* Pass a list of samples, and a list of distributions's *)

applyKernel[lsamples_, kernel_] := Thread[calcPDF[kernel, lsamples]];

(* Pass a list of samples, and a list of two lists of distribution's *)

predClass[samples_, kernels_] := Map[applyKernel[samples, #] &, kernels]; predPDF = predClass[predictionSamples[[1]], kernels]

I have a function,

f[dist_, samp_]:=somework[dist, samp]

that I want to return Null or zero if passed a null distribution. I can't find a way to test for a difference between Null and Data distribution: none of ===, =!=, SameQ and == can identify them.

How can I tell if I'm being passed a Null value to handle it correctly?

f[dist_, samp_]:=something[dist, samp] /; TrueQ[dist==DataDistribution]

Seems to be close to what I want.

EDIT: Edited for some clarity.

Here's my function. If probKern is a Null, I want to return a Null, otherwise, I want to calculate the PDF for the sample, with the distribution. I can't quite get a handle on matching the types to make this work though.

calcPDF[probKern_, samp_] := 
 Null /; TrueQ[probKern != DataDistribution]

calcPDF[probKern_Symbol, samp_] := 
 PDF[probKern, samp] /; TrueQ[probKern == DataDistribution]

edit: Okay, I'm still having trouble with this. Here's what I have:

calcPDF[probKern_DataDistribution, samp_] := PDF[probKern, samp]  
calcPDF[Except[_DataDistribution, probkern_?DistributionParameterQ], samp_] := -1 
calcPDF[_] := $Failed

Given a data distribution and a value it works fine.

In[38]:= calcPDF[data, 3]

Out[38]= 0.007500611755

Given two numbers, it produces the symbolic value, rather than the -1 I was expect. (The -1 is just a placeholder)

In[39]:= calcPDF[3, 3]

Out[39]= calcPDF[3, 3]

I have a function,

f[dist_, samp_]:=somework[dist, samp]

that I want to return Null or zero if passed a null distribution. I can't find a way to test for a difference between Null and Data distribution: none of ===, =!=, SameQ and == can identify them.

How can I tell if I'm being passed a Null value to handle it correctly?

f[dist_, samp_]:=something[dist, samp] /; TrueQ[dist==DataDistribution]

Seems to be close to what I want.

EDIT: Edited for some clarity.

Here's my function. If probKern is a Null, I want to return a Null, otherwise, I want to calculate the PDF for the sample, with the distribution. I can't quite get a handle on matching the types to make this work though.

calcPDF[probKern_, samp_] := 
 Null /; TrueQ[probKern != DataDistribution]

calcPDF[probKern_Symbol, samp_] := 
 PDF[probKern, samp] /; TrueQ[probKern == DataDistribution]

edit: Okay, I'm still having trouble with this. Here's what I have:

calcPDF[probKern_DataDistribution, samp_] := PDF[probKern, samp]  
calcPDF[Except[_DataDistribution, probkern_?DistributionParameterQ], samp_] := -1 
calcPDF[_] := $Failed

Given a data distribution and a value it works fine.

In[38]:= calcPDF[data, 3]

Out[38]= 0.007500611755

Given two numbers, it produces the symbolic value, rather than the -1 I was expect. (The -1 is just a placeholder)

In[39]:= calcPDF[3, 3]

Out[39]= calcPDF[3, 3]

EDIT dec 5th: Running calcPDF by hand seems to result in correct results, but now, when it is threaded over data, the result is a single result of whatever you return in the Except case. There's two sets of distributions I'm running over the sample data, so the final result is a list of two Nulls (or -1's).

If you remove the Except case, you get closer to the expected result - two lists 205 elements long, containing PDF's for entries with matching Distributions, and PDF[Null, value] for those without.

I'm confused.

Clear[calcPDF] (*calcPDF[probKern_, samp_]:=PDF[probKern, samp]; *) calcPDF[probKern_DataDistribution, samp_] := PDF[probKern, samp]; calcPDF[Except[DataDistribution], samp] := Null;

(* Pass a list of samples, and a list of distributions's *)

applyKernel[lsamples_, kernel_] := Thread[calcPDF[kernel, lsamples]];

(* Pass a list of samples, and a list of two lists of distribution's *)

predClass[samples_, kernels_] := Map[applyKernel[samples, #] &, kernels]; predPDF = predClass[predictionSamples[[1]], kernels]

added 30 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

I have a function,

f[dist_, samp_]:=somework[dist, samp]

that I want to return Null or zero if passed a null distribution. I can't find a way to test for a difference between Null and Data distribution: none of ===, =!=, SameQ and == can identify them.

How can I tell if I'm being passed a Null value to handle it correctly?

f[dist_, samp_]:=something[dist, samp] /; TrueQ[dist==DataDistribution]

Seems to be close to what I want.

EDIT: Edited for some clarity.

Here's my function. If probKern is a Null, I want to return a Null, otherwise, I want to calculate the PDF for the sample, with the distribution. I can't quite get a handle on matching the types to make this work though.

calcPDF[probKern_, samp_] := 
 Null /; TrueQ[probKern != DataDistribution]

calcPDF[probKern_Symbol, samp_] := 
 PDF[probKern, samp] /; TrueQ[probKern == DataDistribution]

edit: Okay, I'm still having trouble with this. Here's what I have:

calcPDF[probKern_DataDistribution, samp_] := PDF[probKern, samp]
calcPDF[Except[DataDistribution, probkern?DistributionParameterQ], samp_] := -1 calcPDF[_] := $Failed

calcPDF[probKern_DataDistribution, samp_] := PDF[probKern, samp]  
calcPDF[Except[_DataDistribution, probkern_?DistributionParameterQ], samp_] := -1 
calcPDF[_] := $Failed

Given a data distribution and a value it works fine. `In[38]:= calcPDF[data, 3]

Out[38]= 0.007500611755`

In[38]:= calcPDF[data, 3]

Out[38]= 0.007500611755

Given two numbers, it produces the symbolic value, rather than the -1 I was expect. (The -1 is just a placeholder)

`In[39]:= calcPDF[3, 3]

Out[39]= calcPDF[3, 3] `

In[39]:= calcPDF[3, 3]

Out[39]= calcPDF[3, 3]

I have a function,

f[dist_, samp_]:=somework[dist, samp]

that I want to return Null or zero if passed a null distribution. I can't find a way to test for a difference between Null and Data distribution: none of ===, =!=, SameQ and == can identify them.

How can I tell if I'm being passed a Null value to handle it correctly?

f[dist_, samp_]:=something[dist, samp] /; TrueQ[dist==DataDistribution]

Seems to be close to what I want.

EDIT: Edited for some clarity.

Here's my function. If probKern is a Null, I want to return a Null, otherwise, I want to calculate the PDF for the sample, with the distribution. I can't quite get a handle on matching the types to make this work though.

calcPDF[probKern_, samp_] := 
 Null /; TrueQ[probKern != DataDistribution]

calcPDF[probKern_Symbol, samp_] := 
 PDF[probKern, samp] /; TrueQ[probKern == DataDistribution]

edit: Okay, I'm still having trouble with this. Here's what I have:

calcPDF[probKern_DataDistribution, samp_] := PDF[probKern, samp]
calcPDF[Except[DataDistribution, probkern?DistributionParameterQ], samp_] := -1 calcPDF[_] := $Failed

Given a data distribution and a value it works fine. `In[38]:= calcPDF[data, 3]

Out[38]= 0.007500611755`

Given two numbers, it produces the symbolic value, rather than the -1 I was expect. (The -1 is just a placeholder)

`In[39]:= calcPDF[3, 3]

Out[39]= calcPDF[3, 3] `

I have a function,

f[dist_, samp_]:=somework[dist, samp]

that I want to return Null or zero if passed a null distribution. I can't find a way to test for a difference between Null and Data distribution: none of ===, =!=, SameQ and == can identify them.

How can I tell if I'm being passed a Null value to handle it correctly?

f[dist_, samp_]:=something[dist, samp] /; TrueQ[dist==DataDistribution]

Seems to be close to what I want.

EDIT: Edited for some clarity.

Here's my function. If probKern is a Null, I want to return a Null, otherwise, I want to calculate the PDF for the sample, with the distribution. I can't quite get a handle on matching the types to make this work though.

calcPDF[probKern_, samp_] := 
 Null /; TrueQ[probKern != DataDistribution]

calcPDF[probKern_Symbol, samp_] := 
 PDF[probKern, samp] /; TrueQ[probKern == DataDistribution]

edit: Okay, I'm still having trouble with this. Here's what I have:

calcPDF[probKern_DataDistribution, samp_] := PDF[probKern, samp]  
calcPDF[Except[_DataDistribution, probkern_?DistributionParameterQ], samp_] := -1 
calcPDF[_] := $Failed

Given a data distribution and a value it works fine.

In[38]:= calcPDF[data, 3]

Out[38]= 0.007500611755

Given two numbers, it produces the symbolic value, rather than the -1 I was expect. (The -1 is just a placeholder)

In[39]:= calcPDF[3, 3]

Out[39]= calcPDF[3, 3]
added 542 characters in body
Source Link
user4860
user4860

I have a function,

f[dist_, samp_]:=somework[dist, samp]

that I want to return Null or zero if passed a null distribution. I can't find a way to test for a difference between Null and Data distribution: none of ===, =!=, SameQ and == can identify them.

How can I tell if I'm being passed a Null value to handle it correctly?

f[dist_, samp_]:=something[dist, samp] /; TrueQ[dist==DataDistribution]

Seems to be close to what I want.

EDIT: Edited for some clarity.

Here's my function. If probKern is a Null, I want to return a Null, otherwise, I want to calculate the PDF for the sample, with the distribution. I can't quite get a handle on matching the types to make this work though.

calcPDF[probKern_, samp_] := 
 Null /; TrueQ[probKern != DataDistribution]

calcPDF[probKern_Symbol, samp_] := 
 PDF[probKern, samp] /; TrueQ[probKern == DataDistribution]

edit: Okay, I'm still having trouble with this. Here's what I have:

calcPDF[probKern_DataDistribution, samp_] := PDF[probKern, samp]
calcPDF[Except[DataDistribution, probkern?DistributionParameterQ], samp_] := -1 calcPDF[_] := $Failed

Given a data distribution and a value it works fine. `In[38]:= calcPDF[data, 3]

Out[38]= 0.007500611755`

Given two numbers, it produces the symbolic value, rather than the -1 I was expect. (The -1 is just a placeholder)

`In[39]:= calcPDF[3, 3]

Out[39]= calcPDF[3, 3] `

I have a function,

f[dist_, samp_]:=somework[dist, samp]

that I want to return Null or zero if passed a null distribution. I can't find a way to test for a difference between Null and Data distribution: none of ===, =!=, SameQ and == can identify them.

How can I tell if I'm being passed a Null value to handle it correctly?

f[dist_, samp_]:=something[dist, samp] /; TrueQ[dist==DataDistribution]

Seems to be close to what I want.

EDIT: Edited for some clarity.

Here's my function. If probKern is a Null, I want to return a Null, otherwise, I want to calculate the PDF for the sample, with the distribution. I can't quite get a handle on matching the types to make this work though.

calcPDF[probKern_, samp_] := 
 Null /; TrueQ[probKern != DataDistribution]

calcPDF[probKern_Symbol, samp_] := 
 PDF[probKern, samp] /; TrueQ[probKern == DataDistribution]

I have a function,

f[dist_, samp_]:=somework[dist, samp]

that I want to return Null or zero if passed a null distribution. I can't find a way to test for a difference between Null and Data distribution: none of ===, =!=, SameQ and == can identify them.

How can I tell if I'm being passed a Null value to handle it correctly?

f[dist_, samp_]:=something[dist, samp] /; TrueQ[dist==DataDistribution]

Seems to be close to what I want.

EDIT: Edited for some clarity.

Here's my function. If probKern is a Null, I want to return a Null, otherwise, I want to calculate the PDF for the sample, with the distribution. I can't quite get a handle on matching the types to make this work though.

calcPDF[probKern_, samp_] := 
 Null /; TrueQ[probKern != DataDistribution]

calcPDF[probKern_Symbol, samp_] := 
 PDF[probKern, samp] /; TrueQ[probKern == DataDistribution]

edit: Okay, I'm still having trouble with this. Here's what I have:

calcPDF[probKern_DataDistribution, samp_] := PDF[probKern, samp]
calcPDF[Except[DataDistribution, probkern?DistributionParameterQ], samp_] := -1 calcPDF[_] := $Failed

Given a data distribution and a value it works fine. `In[38]:= calcPDF[data, 3]

Out[38]= 0.007500611755`

Given two numbers, it produces the symbolic value, rather than the -1 I was expect. (The -1 is just a placeholder)

`In[39]:= calcPDF[3, 3]

Out[39]= calcPDF[3, 3] `

added 35 characters in body
Source Link
user4860
user4860
Loading
added 23 characters in body
Source Link
whuber
  • 20.6k
  • 2
  • 61
  • 113
Loading
added 513 characters in body
Source Link
user4860
user4860
Loading
added 16 characters in body
Source Link
Sjoerd C. de Vries
  • 66.2k
  • 15
  • 189
  • 327
Loading
Source Link
user4860
user4860
Loading