Mimi Framework

Custom Random Variable

Is it possible to define a custom random variable with a list of probability densities without using the standard distributions such as Normal, Gamma etc.?
I want to define a random ECS variable where I have list of 50 pairs of ECS © and probability densities (1/C).

There is a custom distribution type defined in Mimi for this case called an EmpiricalDistribution with the following constructor:

Mimi.EmpiricalDistribution(values, probabilities)

I added “climatesensitivity = EmpiricalDistribution(LC18ECS,LC18PD)” to my defmcs.jl file in my Notebook.
As it requires a definition of EmpiricalDistribution I added the EmpiricalDistribution.jl file to my Noterbook. Running this file gives message “cannot assign a value to variable Mimi.EmpiricalDistribution from module Main”.
How can I fix this error?
I don’t think running the file should try to assign a value to the distribution, and I don’t know what “module Main” is. What is it?
Most of the file is just defining functions, including “function EmpiricalDistribution”, but the top of the file also has:

struct EmpiricalDistribution{T} <: PseudoDistribution
values::Vector{T}
weights::ProbabilityWeights
dist::Distribution

What does this code do? Do I need it and do I need to modify it?
I tried commenting out this code and its ‘end’ with #, then run it, which runs without giving any message. Then I ran my modified defmcs.jl file which gave message "MethodError: no method matching EmpiricalDistribution(::NTuple{63,Float64}, ::NTuple{63,Float64})
I appreciate your help!

Hi Ken, you actually don’t need to copy the whole definition over, which is causing the conflict. The EmpiricalDistribution type is actually exported by Mimi, so you should just be able to do:

climatesensitivity = EmpiricalDistribution(LC18ECS,LC18PD)

in your simulation definition, so long as you’ve already included a “using Mimi” statement.

I am using a revised defmcs.jl file in notebook because I want to run the SCC function, which is also copied > into my notebook. I removed the EmpiricalDistribution.jl file from the notebood.
The first cell is:

using Mimi
using MimiFUND #downloaded 2020-04-05
using Statistics
using Distributions

The second cell is;

import Mimi.compinstance
fund_rev_mcs = @defsim begin
aceiadd = [“USA” => Normal(0.0,0.025), “CAN” => Normal(0.0,0.025), “WEU” => Normal(0.0,0.025),

climatesensitivity = EmpiricalDistribution(LC18ECS,LC18PD)

end

function getmcsrev()
return deepcopy(fund_rev_mcs)
end

Running this cell gives;
MethodError: no method matching EmpiricalDistribution(::NTuple{63,Float64}, ::NTuple{63,Float64})

Stacktrace:
[1] top-level scope at In[2]:2

That is why I previously wrote “As it requires a definition of EmpiricalDistribution I added the EmpiricalDistribution.jl file to my Noterbook.”
How can I get notebook to find the find the EmpiricalDistribution.jl file?

Actually, the second cell defines

LC18ECS = (0.65,0.7,0.75, …)
LC18PD = (0.00012,0.00023,0.0007, …)

the third cell is the revised @defsim

The arguments to the EmpiricalDistribution need to be vectors, not NTuples. Try:

LC18ECS = [0.65,0.7,0.75, …]
LC18PD = [0.00012,0.00023,0.0007, …]

Thank you Cora. That worked!
I couldn’t find this information in the Mimi documentation or User Guide. I am not a programmer, just a user, so much of the jargon is difficult to understand.
Can you please point me to where in the documentation;

  1. That vector are defined by ( ) brackets
  2. That tuples are defined by [ ] brackets
  3. That arguments to the EmpiricalDistribution need to be vectors ?
  4. Is there documentation for EmpiricalDistribution ?

I read the Mimi user guide https://www.mimiframework.org/Mimi.jl/stable/
and didn’t find the information there.

The help: ?EmpiricalDistribution gives no useful information, just;
No documentation found.

Mimi.EmpiricalDistribution is of type UnionAll .

I also searched the Julia Language site https://docs.julialang.org/en/v1/
and didn’t find anything showing the rules for vectors, tuples and Ntules.
What documentation am I missing?