Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing seed, added icon #3550

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Buildings/Occupants/BaseClasses/binaryVariableGeneration.mo
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
within Buildings.Occupants.BaseClasses;
function binaryVariableGeneration "Binary variables random generator"
extends Modelica.Icons.Function;
input Real p(min=0, max=1) "Probaility of 1";
input Integer globalSeed "Seed for the random number generator";
output Boolean y "Random number";
protected
Integer localSeed "Local seed";
Integer localSeed = 0 "Local seed";
Integer state[Modelica.Math.Random.Generators.Xorshift1024star.nState];
Real r(min=0, max=1) "Generated random number";
algorithm
Expand All @@ -24,6 +25,11 @@ Higher <code>p</code> indicates a higher chance of generating <code>true</code>.
</html>", revisions="<html>
<ul>
<li>
October 3, 2023, by Michael Wetter:<br/>
Initialized <code>localSeed</code>.<br/>
This is for <a href=\"https://github.com/lbl-srg/modelica-buildings/issues/3549\">#3549</a>.
</li>
<li>
July 20, 2018, by Zhe Wang:<br/>
First implementation.
</li>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
within Buildings.Occupants.BaseClasses;
function exponentialVariableGeneration "Random variable generator from the exponential distribution"
extends Modelica.Icons.Function;
input Real mu "Mean exponential distribution";
input Integer globalSeed "Seed for the random number generator";
output Real y "duration of event";
protected
Integer localSeed;
Integer localSeed = 0 "Local seed";
Integer state[Modelica.Math.Random.Generators.Xorshift1024star.nState];
Real r "Generated random numberin the range 0 < random ≤ 1";
algorithm
Expand All @@ -24,6 +25,11 @@ chance to generate a larger output <code>y</code>.
</html>", revisions="<html>
<ul>
<li>
October 3, 2023, by Michael Wetter:<br/>
Initialized <code>localSeed</code>.<br/>
This is for <a href=\"https://github.com/lbl-srg/modelica-buildings/issues/3549\">#3549</a>.
</li>
<li>
July 20, 2018, by Zhe Wang:<br/>
First implementation.
</li>
Expand Down
2 changes: 2 additions & 0 deletions Buildings/Occupants/BaseClasses/linear1D.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
within Buildings.Occupants.BaseClasses;
function linear1D "Mapping a continuous input to a binary output through a linear relation"
extends Modelica.Icons.Function;

input Real x "Continuous variable";
input Real A=1 "Slope of the linear function";
input Real B=0 "Intercept of the linear function";
Expand Down
2 changes: 2 additions & 0 deletions Buildings/Occupants/BaseClasses/logit1D.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
within Buildings.Occupants.BaseClasses;
function logit1D "Mapping a continuous input to a binary output through a logistic relation"
extends Modelica.Icons.Function;

input Real x "Continuous variable";
input Real A=1.0 "Logistic relation: Slope";
input Real B=1.0 "Logistic relation: Intercept";
Expand Down
2 changes: 2 additions & 0 deletions Buildings/Occupants/BaseClasses/logit1DQuadratic.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
within Buildings.Occupants.BaseClasses;
function logit1DQuadratic "Mapping a continuous input to a binary output through a quadratic logistic relation"
extends Modelica.Icons.Function;

input Real x "Continous variable";
input Real A=1.0 "Parameter defining the quadratic logistic relation";
input Real B=1.0 "Parameter defining the quadratic logistic relation";
Expand Down
2 changes: 2 additions & 0 deletions Buildings/Occupants/BaseClasses/logit2D.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
within Buildings.Occupants.BaseClasses;
function logit2D "Mapping two continuous inputs to a binary output through a 2-dimension logistic relation"
extends Modelica.Icons.Function;

input Real x1 "The first input variable";
input Real x2 "The second input variable";
input Real A=1.0 "Parameter defining the 2D logistic relation: mutiplier for the first input";
Expand Down
8 changes: 5 additions & 3 deletions Buildings/Occupants/BaseClasses/weibull1DOFF.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
within Buildings.Occupants.BaseClasses;
function weibull1DOFF "Mapping a continuous input to a binary output through a Weibull Distribution Relation"
function weibull1DOFF "Mapping a continuous input to a binary output through a Weibull distribution relation"
extends Modelica.Icons.Function;

input Real x "Continous variable";
input Real u=1.0 "Parameter defining the Weibull distribution threshold";
input Real L=1.0 "Parameter defining the Weibull distribution normalization factor";
Expand All @@ -16,11 +18,11 @@ annotation (
Documentation(info="<html>
<p>
This function generates a random binary variable with a continuous inputs
<code>x</code> from a Weibull Distribution relation.
<code>x</code> from a Weibull distribution relation.
</p>
<p>
The probability of being 1 is calculated from the input <code>x</code> from a
Weibull Distribution relation with three predefined parameters <code>u</code>
Weibull distribution relation with three predefined parameters <code>u</code>
(threshold, the output would be 0 if <code>x</code> is bigger than <code>u</code>),
<code>L</code> (normalization faction) and <code>k</code> (shape factor).
Then a random generator generates the output, which should be a binary variable.
Expand Down
8 changes: 5 additions & 3 deletions Buildings/Occupants/BaseClasses/weibull1DON.mo
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
within Buildings.Occupants.BaseClasses;
function weibull1DON "Mapping a continuous input to a binary output through a Weibull Distribution Relation"
function weibull1DON "Mapping a continuous input to a binary output through a Weibull distribution relation"
extends Modelica.Icons.Function;

input Real x "Continous variable";
input Real u=1.0 "Parameter defining the Weibull distribution threshold";
input Real L=1.0 "Parameter defining the Weibull distribution normalization factor";
Expand All @@ -16,11 +18,11 @@ annotation (
Documentation(info="<html>
<p>
This function generates a random binary variable with a continuous inputs
<code>x</code> from a Weibull Distribution relation.
<code>x</code> from a Weibull distribution relation.
</p>
<p>
The probability of being 1 is calculated from the input <code>x</code> from a
Weibull Distribution relation with three predefined parameters <code>u</code>
Weibull distribution relation with three predefined parameters <code>u</code>
(threshold, the output would be 0 if <code>x</code> is less than <code>u</code>),
<code>L</code> (normalization faction) and <code>k</code> (shape factor). Then
a random generator generates the output, which should be a binary variable.
Expand Down
23 changes: 15 additions & 8 deletions Buildings/Occupants/BaseClasses/weibullVariableGeneration.mo
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
within Buildings.Occupants.BaseClasses;
function weibullVariableGeneration "Random variable generator from the Weibull distribution"
extends Modelica.Icons.Function;

input Real lambda "Parameter defining the Weibull distribution scale factor";
input Real k "Parameter defining the Weibull distribution shape factor";
input Integer globalSeed "Seed for the random number generator";
output Real y "Random variable generated from Weibull Distribution";
protected
Integer localSeed;
Integer localSeed = 0 "Local seed";
Integer state[Modelica.Math.Random.Generators.Xorshift1024star.nState];
Real r "Generated random numberin the range 0 < random ≤ 1";
algorithm
Expand All @@ -14,21 +16,26 @@ algorithm
y := lambda*(Modelica.Math.log((1 - r)^(-1)))^(1/k);
annotation (Documentation(info="<html>
<p>
This function generates a random variable, from a Weibull distribution with the
inputs of <code>lambda</code> and <code>k</code>. The random variable might be
This function generates a random variable, from a Weibull distribution with the
inputs of <code>lambda</code> and <code>k</code>. The random variable might be
the duration of a specific event, for instance the time to keep the HVAC on.
</p>
<p>
The inputs <code>lambda</code> and <code>k</code> defines the probability density
function. <code>lambda</code> is similar to the mean value of exponential
distribution, and <code>k</code> defines the shape. A value of <code>k</code> = 1
means the Weibull distribution reduces to an exponential distribution. Genrally
speaking, higher <code>lambda</code> and higher <code>k</code> indicate a higher
The inputs <code>lambda</code> and <code>k</code> defines the probability density
function. <code>lambda</code> is similar to the mean value of exponential
distribution, and <code>k</code> defines the shape. A value of <code>k</code> = 1
means the Weibull distribution reduces to an exponential distribution. Genrally
speaking, higher <code>lambda</code> and higher <code>k</code> indicate a higher
chance to generate a higher output.
</p>
</html>", revisions="<html>
<ul>
<li>
October 3, 2023, by Michael Wetter:<br/>
Initialized <code>localSeed</code>.<br/>
This is for <a href=\"https://github.com/lbl-srg/modelica-buildings/issues/3549\">#3549</a>.
</li>
<li>
July 20, 2018, by Zhe Wang:<br/>
First implementation.
</li>
Expand Down