Skip to content

Commit

Permalink
Added missing seed, added icon (#3552)
Browse files Browse the repository at this point in the history
For #3549
  • Loading branch information
mwetter authored Oct 4, 2023
1 parent f6888a1 commit 7554db2
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 24 deletions.
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
19 changes: 11 additions & 8 deletions Buildings/package.mo
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ Each class (i.e., model, block and function) must be used in an example or valid
extends Modelica.Icons.ReleaseNotes;


class Version_9_1_2 "Version 9.1.2"
extends Modelica.Icons.ReleaseNotes;
annotation (Documentation(info="<html>
class Version_9_1_2 "Version 9.1.2"
extends Modelica.Icons.ReleaseNotes;
annotation (Documentation(info="<html>
<div class=\"release-summary\">
<p>
Version 9.1.2 is backward compatible with 9.1.0 and 9.1.1, except that relative to 9.1.0, the Spawn binaries need to be updated as described
Expand Down Expand Up @@ -246,12 +246,15 @@ have been <b style=\"color:blue\">improved</b> in a
<b style=\"color:blue\">backward compatible</b> way:
</p>
<table class=\"releaseTable\" summary=\"summary\" border=\"1\" cellspacing=\"0\" cellpadding=\"2\" style=\"border-collapse:collapse;\">
<tr><td colspan=\"2\"><b>xxx</b>
<tr><td colspan=\"2\"><b>Buildings.Occupants</b>
</td>
</tr>
<tr><td valign=\"top\">xxx
<tr><td valign=\"top\">Buildings.Occupants.BaseClasses.binaryVariableGeneration<br/>
Buildings.Occupants.BaseClasses.exponentialVariableGeneration<br/>
Buildings.Occupants.BaseClasses.weibullVariableGeneration
</td>
<td valign=\"top\">xxx.
<td valign=\"top\">Initialized <code>localSeed</code>.<br/>
This is for <a href=\"https://github.com/lbl-srg/modelica-buildings/issues/3549\">#3549</a>.
</td>
</tr>
<tr><td colspan=\"2\"><b>xxx</b>
Expand Down Expand Up @@ -319,7 +322,7 @@ xxx
</li>
</ul>
</html>"));
end Version_9_1_2;
end Version_9_1_2;


class Version_9_1_1 "Version 9.1.1"
Expand Down Expand Up @@ -11941,4 +11944,4 @@ requirements definition or providing feedback regarding the model applicability
to solve specific problems.
</p>
</html>"));
end Buildings;
end Buildings;

0 comments on commit 7554db2

Please sign in to comment.