Thanks to Owen Astrachan (Duke) and Julie Zelenski. Updates by Keith Schwarz, Stuart Reges, Marty Stepp and Chris Piech.
February 24th, 2016
In this assignment you will build a file compression algorithm that uses binary trees and priority queues. The starter code for this project is available as a ZIP archive. A demo is availible as a JAR (see handout on how to run a jar). Note that the JAR will look for files in the same directory:
Turn in the following files:
encoding.cpp
: code to perform Huffman encoding and decodingsecretmessage.huf
: a message from you to your section leader, which is compressed by your algorithm.huffmanmain.cpp
that contains the program's overall text menu system; you must implement the functions it calls
to perform various file compression / decompression operations. If you work in pairs, please turn in a single copy
This handout is split into different sections which explain the milestones in this assignment (click on a section title to expand it). The section Implementation Details explains where in the files to program your solution.
Huffman encoding is an algorithm devised by David A. Huffman of MIT in 1952 for compressing text data to make a file occupy a smaller number of bytes. This relatively simple compression algorithm is powerful enough that variations of it are still used today in computer networks, fax machines, modems, HDTV, and other areas.
Normally text data is stored in a standard format of 8 bits per
character using an encoding called ASCII that maps every
character to a binary integer value from 0-255. The idea of
Huffman encoding is to abandon the rigid 8-bits-percharacter
requirement and use different-length binary
encodings for different characters. The advantage of doing
this is that if a character occurs frequently in the file, such as
the common letter 'e'
, it could be given a shorter encoding
(fewer bits), making the file smaller. The tradeoff is that
some characters may need to use encodings that are longer
than 8 bits, but this is reserved for characters that occur
infrequently, so the extra cost is worth it.
The table below compares ASCII values of various characters to possible Huffman encodings for some English text. Frequent characters such as space and 'e' have short encodings, while rarer ones like 'z' have longer ones.
| Character | ASCII Value | ASCII Binary | Huffman Binary |
|---|---|---|---|
' ' |
32 |
00100000 |
10 |
'a' |
97 |
01100001 |
0001 |
'b' |
98 |
01100010 |
0111010 |
'c' |
99 |
01100011 |
001100 |
'e' |
101 |
01100101 |
1100 |
'z' |
122 |
01111010 |
00100011010 |
The steps involved in Huffman encoding a given text source file into a destination compressed file are:
priority
queue is used to help build the tree along the way.Your program's output format should exactly match the abridged log of execution above. Here are more examples of game logs:
As an example, suppose we have a file named example.txt
whose contents are: ab ab cab
.
In the original file, this text occupies 10 bytes (80 bits) of data. The 10th is a special "end-of-file" (EOF) byte.
In Step 1 of Huffman's algorithm, a count of each character is computed. The counts are represented as a map:
{' ':2, 'a':3, 'b':3, 'c':1, EOF:1}
Step 2 of Huffman's algorithm places our counts into binary tree nodes, with each node storing a character and a count of its occurrences. The nodes are then put into a priority queue, which keeps them in prioritized order with smaller counts having higher priority, so that characters with lower counts will come out of the queue sooner. (The priority queue is somewhat arbitrary in how it breaks ties, such as 'c' being before EOF and 'a' being before 'b').
Now the algorithm repeatedly removes the two nodes from the front of the queue (the two with the smallest frequencies) and joins them into a new node whose frequency is their sum. The two nodes are placed as children of the new node; the first removed becomes the left child, and the second the right. The new node is re-inserted into the queue in sorted order. This process is repeated until the queue contains only one binary tree node with all the others as its children. This will be the root of our finished Huffman tree. The following diagram shows this process. Notice that the nodes with low frequencies end up far down in the tree, and nodes with high frequencies end up near the root of the tree. This structure can be used to create an efficient encoding in the next step.
The Huffman code for each character is derived from your binary tree by thinking of each left branch as a bit value of 0 and each right branch as a bit value of 1, as shown in the diagram below:
The code for each character can be determined by traversing the tree. To reach ' ' we go left twice from the root, so the code for ' ' is 00. The code for 'c' is 010, the code for EOF is 011, the code for 'a is 10 and the code for 'b is 11. By traversing the tree, we can produce a map from characters to their binary representations. Though the binary representations are integers, since they consist of binary digits and can be arbitrary length, we will store them as strings. For this tree, it would be:
{' ':"00", 'a':"10", 'b':"11", 'c':"010", EOF:"011"}
Using the encoding map, we can encode the file's text into a shorter binary representation. Using the preceding encoding map, the text "ab ab cab" would be encoded as:
1011001011000101011011
The following table details the char-to-binary mapping in more detail. The overall encoded contents of the file require 22 bits, or almost 3 bytes, compared to the original file of 10 bytes.
Since the character encodings have different lengths, often the length of a Huffman-encoded file does not come out to an exact multiple of 8 bits. Files are stored as sequences of whole bytes, so in cases like this the remaining digits of the last bit are filled with 0s. You do not need to worry about this; it is part of the underlying file system.
It might worry you that the characters are stored without any delimiters between them, since their encodings can be different lengths and characters can cross byte boundaries, as with 'a' at the end of the second byte. But this will not cause problems in decoding the file, because Huffman encodings by definition have a useful prefix property where no character's encoding can ever occur as the start of another's encoding.
You can use a Huffman tree to decode text that was previously encoded with its binary patterns. The decoding algorithm is to read each bit from the file, one at a time, and use this bit to traverse the Huffman tree. If the bit is a 0, you move left in the tree. If the bit is 1, you move right. You do this until you hit a leaf node. Leaf nodes represent characters, so once you reach a leaf, you output that character. For example, suppose we are given the same encoding tree above, and we are asked to decode a file containing the following bits:
1110010001001010011
Using the Huffman tree, we walk from the root until we find characters, then output them and go back to the root.
1110010001001010011
1110010001001010011
1110010001001010011
1110010001001010011
1110010001001010011
1110010001001010011
1110010001001010011
We provide you with a file HuffmanNode.h that declares some useful support code including the HuffmanNode structure, which represents a node in a Huffman encoding tree.
struct HuffmanNode { int character; // character being represented by this node int count; // number of occurrences of that character HuffmanNode* zero; // 0 (left) subtree (NULL if empty) HuffmanNode* one; // 1 (right) subtree (NULL if empty) ... };
The character field is declared as type int, but you should think of it as a char. (Types char and int are largely interchangeable in C++, but using int here allows us to sometimes use character to store values outside the normal range of char, for use as special flags.) The character field can take one of three types of values:
PSEUDO_EOF
(defined in bitstream.h in the Stanford library), which represents the pseudo-EOF value (the symbol, denoted by ■ in the supplemental Huffman handout, that marks the end of the encoding) that you will need to place at the end of an encoded stream; orNOT_A_CHAR
(defined in bitstream.h in the Stanford library), which represents something that isn't actually a character. (This can be stored in branch nodes of the Huffman encoding tree that have children, because such nodes do not represent any one individual character.)In parts of this program you will need to read and write bits to files. In the past we have wanted to read input an entire line or word at a time, but in this program it is much better to read one single character (byte) at a time. So you should use the following in/output stream functions:
| ostream (output stream) member | Description |
|---|---|
void put(int byte) |
writes a single byte (character, 8 bits) to the output stream |
| istream (input stream) member | Description |
|---|---|
int get() |
reads a single byte (character, 8 bits) from input; -1 at EOF |
You might also find that you want to read an input stream, then "rewind" it back to the start and read it again. To do this on an input stream variable named input, you can use the rewindStream function from filelib.h:
rewindStream(input); // tells the stream to seek back to the beginning
To read or write a compressed file, even a whole byte is too much; you will want to read and write binary data one single bit at a time, which is not directly supported by the default in/output streams. Therefore the Stanford C++ library provides obitstream and ibitstream classes with writeBit and readBit members to make it easier.
| obitstream (bit output stream) member | Description |
|---|---|
void writeBit(int bit) |
writes a single bit (0 or 1) to the output stream |
| ibitstream (bit input stream) member | Description |
|---|---|
int readBit() |
reads a single bit (0 or 1) from input; -1 at end of file |
When reading from an bit input stream (ibitstream), you can detect the end of the file by either looking for a readBit result of -1, or by calling the fail() member function on the input stream after trying to read from it, which will return true if the last readBit call was unsuccessful due to reaching the end of the file.
Note that the bit in/output streams also provide the same members as the original ostream and istream classes from the C++ standard library, such as getline, <<, >>, etc. But you usually don't want to use them, because they operate on an entire byte (8 bits) at a time, or more; whereas you want to process these streams one bit at a time.
In this assignment you will write the following functions in the file encoding.cpp to encode and decode data using the Huffman algorithm described previously. Our provided main client program will allow you to test each function one at a time before moving on to the next. You must write the following functions; you can add more functions as helpers if you like, particularly to help you implement any recursive algorithms. Any members that traverse a binary tree from top to bottom should implement that traversal recursively whenever practical.
Map
This is Step 1 of the encoding process. In this function you read input from a given istream (which could be a file on disk, a string buffer, etc.). You should count and return a mapping from each character (represented as int here) to the number of times that character appears in the file. You should also add a single occurrence of the fake character PSEUDO_EOF into your map. You may assume that the input file exists and can be read, though the file might be empty. An empty file would cause you to return a map containing only the 1 occurrence of PSEUDO_EOF.
HuffmanNode* buildEncodingTree(Map
This is Step 2 of the encoding process. In this function you will accept a frequency table (like the one you built in buildFrequencyTable) and use it to create a Huffman encoding tree based on those frequencies. Return a pointer to the node representing the root of the tree.
You may assume that the frequency table is valid: that it does not contain any keys other than char values, PSEUDO_EOF, and NOT_A_CHAR; all counts are positive integers; it contains at least one key/value pairing; etc.
When building the encoding tree, you will need to use a priority queue to keep track of which nodes to process next. Use the PriorityQueue collection provided by the Stanford libraries, defined in library header pqueue.h. This priority queue allows each element to be enqueued along with an associated priority. The priority queue then sorts elements by their priority, with the dequeue function always returning the element with the minimum priority number. Consult the docs on the course website and lecture slides for more information about priority queues.
Map
This is Step 3 of the encoding process. In this function will you accept a pointer to the root node of a Huffman tree (like the one you built in buildEncodingTree) and use it to create and return a Huffman encoding map based on the tree's structure. Each key in the map is a character, and each value is the binary encoding for that character represented as a string. For example, if the character 'a' has binary value 10 and 'b' has 11, the map should store the key/value pairs 'a':"10" and 'b':"11". If the encoding tree is NULL, return an empty map.
void encodeData(istream& input, const Map
This is Step 4 of the encoding process. In this function you will read one character at a time from a given input file, and use the provided encoding map to encode each character to binary, then write the character's encoded binary bits to the given bit output bit stream. After writing the file's contents, you should write a single occurrence of the binary encoding for PSEUDO_EOF into the output so that you'll be able to identify the end of the data when decompressing the file later. You may assume that the parameters are valid: that the encoding map is valid and contains all needed data, that the input stream is readable, and that the output stream is writable. The streams are already opened and ready to be read/written; you do not need to prompt the user or open/close the files yourself.
void decodeData(ibitstream& input, HuffmanNode* encodingTree, ostream& output)
This is the "decoding a file" process described previously. In this function you should do the opposite of encodeData; you read bits from the given input file one at a time, and recursively walk through the specified decoding tree to write the original uncompressed contents of that file to the given output stream. The streams are already opened and you do not need to prompt the user or open/close the files yourself.
To manually verify that your implementations of encodeData and decodeData are working correctly, use our provided test code to compress strings of your choice into a sequence of 0s and 1s. The next page describes a header that you will add to compressed files, but in encodeData and decodeData, you should not write or read this header from the file. Instead, just use the encoding tree you're given. Worry about headers only in compress/decompress.
The functions above implement Huffman's algorithm, but they have one big flaw. The decoding function requires the encoding tree to be passed in as a parameter. Without the encoding tree, you don't know the mappings from bit patterns to characters, so you can't successfully decode the file.
We will work around this by writing the encodings into the compressed file, as a header. The idea is that when opening our compressed file later, the first several bytes will store our encoding information, and then those bytes are immediately followed by the compressed binary bits that we compressed earlier. It's actually easier to store the character frequency table, the map from Step 1 of the encoding process, and we can generate the encoding tree from that. For our ab ab cab example, the frequency table stores the following (the keys are shown by their ASCII integer values, such as 32 for ' ' and 97 for 'a', because that is the way the map would look if you printed it out):
{32:2, 97:3, 98:3, 99:1, 256:1}
We don't have to write the encoding header bit-by-bit; just write out normal ASCII characters for our encodings. We could come up with various ways to format the encoding text, but this would require us to carefully write code to write/read the encoding text. There's a simpler way. You already have a Map of character frequency counts from Step 1 of encoding. In C++, collections like Maps can easily be read and written to/from streams using << and >> operators. So all you need to do for your header is write your map into the bit output stream first before you start writing bits into the compressed file, and read that same map back in first later when you decompress it. The overall file is now 34 bytes: 31 for the header and 3 for the binary compressed data. Here's an attempt at a diagram:
Looking at this new rendition of the compressed file, you may be thinking, "The file is not compressed at all; it actually got larger than it was before! It went up from 9 bytes ("ab ab cab") to 34!" That's true for this contrived example. But for a larger file, the cost of the header is not so bad relative to the overall file size. There are more compact ways of storing the header, too, but they add too much challenge to this assignment, which is meant to practice trees and data structures and problem solving more than it is meant to produce a truly tight compression.
The last step is to glue all of your code together, along with code to read and write the encoding table to the file:
void compress(istream& input, obitstream& output)
This is the overall compression function; in this function you should compress the given input file into the given output file. You will take as parameters an input file that should be encoded and an output bit stream to which the compressed bits of that input file should be written. You should read the input file one character at a time, building an encoding of its contents, and write a compressed version of that input file, including a header, to the specified output file. This function should be built on top of the other encoding functions and should call them as needed. You may assume that the streams are both valid and read/writeable, but the input file might be empty. The streams are already opened and ready to be read/written; you do not need to prompt the user or open/close the files yourself.
void decompress(ibitstream& input, ostream& output)
This function should do the opposite of compress; it should read the bits from the given input file one at a time, including your header packed inside the start of the file, to write the original contents of that file to the file specified by the output parameter. You may assume that the streams are valid and read/writeable, but the input file might be empty. The streams are already open and ready to be used; you do not need to prompt the user or open/close files.
void freeTree(HuffmanNode* node)
This function should free the memory associated with the tree whose root node is represented by the given pointer. You must free the root node and all nodes in its subtrees. There should be no effect if the tree passed is NULL. If your compress or decompress function creates a Huffman tree, that function should also free the tree.
Along with your program, turn in a file secretmessage.huf that stores a compressed message from you to your section leader. Create the file by compressing a text file with your compress function. The message can be anything non-offensive you want. Your SL will decompress your message with your program and read it while grading.
Your code should have no memory leaks. Free the memory associated with any new objects you allocate internally. The Huffman nodes you will allocate when building encoding trees are passed back to the caller, so it is that caller's responsibility to call your freeTree function to clean up the memory.


This scenario connects to Facebook using the HttpClient "Filter" technology. Filters let you separate concerns like Auth from the rest of your app logic. Multiple filters can be used at once. The OAuth2 filter in this example can be configured to support a number of different social web sites.


{% extends 'base.html' %} {% load qr_code %} {% load isingroup %} {% block content %} To make a deposit to your balance you should do a wire transfer to the following account:
| IBAN | {{ settings.PETTYCASH_IBAN }} |
| ten name van: | {{ settings.PETTYCASH_TNS }} |
| onder vermelding van |
Storting Spacepot {{ user.id }} / {{ user }}
|
You must use exactly above descriptive strings; as this is what automates the process.
If you don't it may take longer. Or you may have to remind the trustee's in a few weeks time.
If your bank supports it - you can also scan the EPC QR code below (usually with your banking app).
{% qr_from_text epc size="m" border=1 %}


|
VirtualSCADA
1.0
VirtualSCADA Senior Design Project
|
Additional Inherited Members | |
| Static Public Member Functions inherited from Controller | |
| static | getRouter () |
| static | setRouter (Router $router) |
| static | getRouter () |
| static | setRouter (Router $router) |
| Protected Member Functions inherited from Controller | |
| parseFilter ($filter, array $options) | |
| registerClosureFilter (Closure $filter) | |
| registerInstanceFilter ($filter) | |
| isInstanceFilter ($filter) | |
| removeFilter ($removing, $current) | |
| parseFilter ($filter, array $options) | |
| registerClosureFilter (Closure $filter) | |
| registerInstanceFilter ($filter) | |
| isInstanceFilter ($filter) | |
| removeFilter ($removing, $current) | |
| Protected Attributes inherited from Controller | |
| $middleware = array() | |
| $beforeFilters = array() | |
| $afterFilters = array() | |
| Static Protected Attributes inherited from Controller | |
| static | $router |
Definition at line 21 of file ProjectController.php.
| __construct | ( | Project | $projects | ) |
| create | ( | ) |
| destroy | ( | Project | $project | ) |
Delete the selected project from database
| Project | $project |
Definition at line 135 of file ProjectController.php.
| edit | ( | Project | $project | ) |
Allow the user to edit high-level properties of project
| Project | $project |
Definition at line 84 of file ProjectController.php.
| editPermissions | ( | Project | $project | ) |
Edit the project permissions
| Project | $project |
Definition at line 200 of file ProjectController.php.
| index | ( | ) |
Return all of the logged in user's projects
Definition at line 36 of file ProjectController.php.
| open | ( | Project | $project | ) |
Show details of the project THIS IS WHERE WE WILL RUN SIMULATIONS AND ADD MODULES
| Project | $project |
Definition at line 149 of file ProjectController.php.
| show | ( | Project | $project | ) |
Show some details about the project
| Project | $project |
Definition at line 48 of file ProjectController.php.
| store | ( | CreateProjectRequest | $request | ) |
Store new project in the database
| CreateProjectRequest | $request |
Definition at line 119 of file ProjectController.php.
| update | ( | Project | $project | ) |
Update project in the database
| Project | $project |
Definition at line 101 of file ProjectController.php.
| updatePermissions | ( | Project | $project | ) |
Update the project permissions
| Project | $project |
Definition at line 217 of file ProjectController.php.


Id: 319
Name: Shmooglite Runner
Status: unknown
Species: Alien
Type: Animal
Gender: Male
OriginName: Resort Planet
OriginUrl: https://rickandmortyapi.com/api/location/37
LocationName: Resort Planet
LocationUrl: https://rickandmortyapi.com/api/location/37
Image: https://rickandmortyapi.com/api/character/avatar/319.jpeg
Episode: ['https://rickandmortyapi.com/api/episode/26']
Url: https://rickandmortyapi.com/api/character/319
Created: 2018-01-05T14:59:34.798Z


{ "$type": value }
.See: Description
| Interface | Description |
|---|---|
| ExtendedTypeNames |
Names of Mongo extended types.
|
| Class | Description |
|---|---|
| BaseExtendedValueParser | |
| ExtendedTypeFieldFactory | |
| MongoBinaryValueParser |
Parsers a binary.
|
| MongoDateValueParser |
Parses a Mongo date in the
V1 format:
|
| SimpleExtendedValueParser |
Parsers a Mongo extended type of the form:
|
{ "$type": value }
. Supports both
V1 and
V2 names. Supports both the Canonical and Relaxed formats.
Does not support all types as some appear internal to Mongo. Supported types:
VARBINARY
. The data must be encoded in
the
default Jackson Base64 format. The subType
field, if present, is ignored.TIMESTAMP
. Drill's times are
in the server local time. The UTC date in Mongo will be shifted to the local time
zone on read.VARDECIMAL
.VARDECIMAL
, but limited to the
supported DECIMAL range.MAP
. The map fields must be consistent
across documents: same names and types. (This is a restriction of Maps in Drill's
relational data model.) Field names cannot be the same as any of the extended type
names.FLOAT8
.BIGINT
.INT
.VARCHAR
.The BSON timestamp type is for internal MongoDB use. For most cases, in application development, you will want to use the BSON date type.
NULL
value.The unsupported types appear more for commands and queries rather than data. They do not represent a Drill type. If they appear in data, they will be translated to a Drill map.
Drill defines a few "extended extended" types:
$dateDay
) - a date-only field in the form YYYY-MM-DD
which
maps to a Drill DATE
vector.$time
) - a time-only field in the form HH:MM:SS.SSS
which
maps to a Drill TIME
vector.$interval
) - a date/time interval in ISO format which maps
to a Drill INTERVAL
vector.
Drill extends the extended types to allow null values in the usual way. Drill accepts normal "un-extended" JSON in the same file, but doing so can lead to ambiguities (see below.)
Once Drill defines a field as an extended type, parsing rules are tighter than for normal "non-extended" types. For example an extended double will not convert from a Boolean or float value.
null
, then the
provided schema will force the given type as though the data were in
canonical format.a: "30"
, Drill will infer the
type as string, even if a later field presents as a: { "numberInt": 30 }
.
To avoid ambiguities, either use only the canonical format, or use a provided
schema.
store.json.extended_types
system/session option (
ExecConstants.JSON_EXTENDED_TYPES_KEY
).
Extended types are implemented via a field factory. The field factory builds the
structure needed each time the JSON structure parser sees a new field. For extended types,
the field factory looks ahead to detect an extended type, specifically for the pattern
{ "$type":
. If the pattern is found, and the name is one of the supported
type names, then the factory creates a parser to accept the enhanced type in either the
canonical or relaxed forms.
Each field is represented by a Mongo-specific parser along with an associated value listener. The implementation does not reify the object structure; that structure is consumed by the field parser itself. The value listener receives value tokens as if the data were in relaxed format.
MapVectorOutput
for an older implementation
Copyright © 2021 The Apache Software Foundation. All rights reserved.


CoupledDEVS User Interface¶
-
class
DEVS.
CoupledDEVS
(name=None)[source] Abstract base class for all coupled-DEVS descriptive classes.
-
__init__
(name=None)[source] Constructor.
Parameters: name – the name of the coupled model, can be None for an automatically generated name
-
addInPort
(name=None) Add an input port to the DEVS model.
addInPort is the only proper way to add input ports to a DEVS model. As for the CoupledDEVS.addSubModel method, calls to addInPort and addOutPort can appear in any DEVS’ descriptive class constructor, or the methods can be used with an instantiated object.
The methods add a reference to the new port in the DEVS’ IPorts attributes and set the port’s hostDEVS attribute. The modeler should typically save the returned reference somewhere.
Parameters: name – the name of the port. A unique ID will be generated in case None is passed Returns: port – the generated port
-
addOutPort
(name=None) Add an output port to the DEVS model.
addOutPort is the only proper way to add output ports to DEVS. As for the CoupledDEVS.addSubModel method, calls to addInPort and addOutPort can appear in any DEVS’ descriptive class constructor, or the methods can be used with an instantiated object.
The methods add a reference to the new port in the DEVS’ OPorts attributes and set the port’s hostDEVS attribute. The modeler should typically save the returned reference somewhere.
Parameters: name – the name of the port. A unique ID will be generated in case None is passed Returns: port – the generated port
-
addSubModel
(model, location=None)[source] Adds a specified model to the current coupled model as its child. This is the function that must be used to make distributed simulation possible.
Parameters: - model – the model to be added as a child
- location – the location at which the child must run
Returns: model – the model that was created as a child
Changed in version 2.1.3: model can no longer be a string, this was previously a lot more efficient in partial distribution, though this functionality was removed together with the partial distribution functionality.
-
connectPorts
(p1, p2, z=None)[source] Connects two ports together. The coupling is to begin at p1 and to end at p2.
Parameters: - p1 – the port at the start of the new connection
- p2 – the port at the end of the new connection
- z – the translation function for the events either input-to-input, output-to-input or output-to-output.
-
disconnectPorts
(p1, p2)[source] Disconnect two ports
Note
If these ports are connected multiple times, only one of them will be removed.
Parameters: - p1 – the port at the start of the connection
- p2 – the port at the end of the connection
-
modelTransition
(state) DEFAULT function for Dynamic Structure DEVS, always returning False (thus indicating that no structural change is needed)
Parameters: state – a dict that can be used to save some kind of state, this object is maintained by the kernel and will be passed each time Returns: bool – whether or not a structural change is necessary
-
removePort
(port) Remove a port (either input or output) from the model, disconnecting all of its connections.
Parameters: port – the port to remove
-
removeSubModel
(model)[source] Remove a specified model from the current coupled model, only callable while in a simulation.
Parameters: model – the model to remove as a child
-
select
(imm_children)[source] DEFAULT select function, only used when using Classic DEVS simulation
Parameters: imm_children – list of all children that want to transition Returns: child – a single child that is allowed to transition
-
simSettings
(simulator) Modifies the simulation settings from within the model.
This function is called _before_ direct connection and distribution is performed, so the user can still access the complete hierarchy.
Note
This function is only called on the root model of the simulation, thus the model passed to the constructor of the Simulator object.
Parameters: simulator – the simulator object on which settings can be configured
-


Before Change
storage = storage_init_func()
trial_id_1 = storage.create_new_trial_id(storage.create_new_study_id())
trial_id_2 = storage.create_new_trial_id(storage.create_new_study_id())
// test setting new values
After Change
storage = storage_init_func()
// Setup test across multiple studies and trials.
study_id = storage.create_new_study_id()
trial_id_1 = storage.create_new_trial_id(study_id)
trial_id_2 = storage.create_new_trial_id(study_id)
trial_id_3 = storage.create_new_trial_id(storage.create_new_study_id())
// Test setting new values.


Module panthrMath
Author(s): unknown
panthrMath
Math computation library for PanthR
Provides special functions, probability distributions, and random number generators; inspired by the R code.
C
Frequently used constants. See C
Polynomial(coefs)
A small wrapper class for representing polynomial functions.
Polynomial.new(coefs)
Creates a polynomial function from coefs
, an array of coefficients.
For example, if the function is $ax^3 + bx^2 + cx + d$
the array is [a, b, c, d]
, that is, the array indexing is
the reverse of the usual coefficient indexing.
Rational(num, denom)
A small wrapper class for representing rational functions.
Rational.new(num, denom)
Creates a rational function.
num
and denom
can be instances of Polynomial
or arrays of coefficients for Polynomial.new
.
Common factors between the numerator and denominator are not eliminated.
basicfunc
A collection of basic and special functions. See basicFunc
.
distributions
Various probability distributions. See distributions
.
Polynomial.prototype.evalAt(x)
Evaluates the polynomial at a given value x
.
Rational.prototype.evalAt(x)
Evaluates the rational function at the value x
.
basicFunc
Basic math functions.
bd0(x, y)
Computes the expression $$bd0(x, y) = x \ln(x/y) + y - x$$
Based on: Fast and Accurate Computation of Binomial Probabilities, by Catherine Loader, 2000
beta(a, b)
Computes the beta function $$B(a,b) = \int_0^1 x^{a-1} (1-x)^{b-1} dx$$ where $a>0$ and $b>0$.
See also: lbeta
Based on: Algorithm 708: Significant Digit Computation of the Incomplete Beta Function Ratios, by DiDonato and Morris, 1992
bratio(a, b, x, lowerTail, logp)
Returns the lower tail of the incomplete beta function $$I_x(a, b)=G(a,b)\int_0^xt^{a-1}(1-t)^{b-1}dt$$ where $B(a,b)=1/G(a,b) = \Gamma(a)\Gamma(b)/\Gamma(a+b)$ is the usual beta function.
If lowerTail
is false
, returns the upper tail instead.
If logp
is true
, returns the logarithm of the tail.
Expects $a>0$, $b>0$, and $0 \leq x \leq 1$.
Based on: Algorithm 708: Significant Digit Computation of the Incomplete Beta Function Ratios, by DiDonato and Morris, 1992
dbinomLog(size, p)
Performs the raw binomial log computation, even when $x$ is not an integer.
Based on: Fast and Accurate Computation of Binomial Probabilities, by Catherine Loader, 2000
erf(x)
Implementation for erf, the real error function: $$\textrm{erf}(x) = \frac{2}{\sqrt{\pi}}\int_0^x e^{-t^2} dt$$ Based on: Rational Chebyshev Approximations for the Error Function, by W. J. Cody, 1969
erfc(x)
Implementation for erfc, the complement of the real error function: $$\textrm{erfc}(x) = \frac{2}{\sqrt{\pi}}\int_x^\infty e^{-t^2} dt$$ Based on: Rational Chebyshev Approximations for the Error Function, by W. J. Cody, 1969
expm1(x)
Computes $$\textrm{expm1}(x) = e^x - 1$$ with reasonable precision near $x = 0$.
Based on: Computation of the Incomplete Gamma Function Ratios and their Inverse, by DiDonato and Morris, 1986
gam1(x)
Computes $$H(x)=\frac{1}{\Gamma(x+1)} - 1$$ with reasonable precision even near the zeroes ($x = 0, 1$).
Based on: Computation of the Incomplete Gamma Function Ratios and their Inverse, by DiDonato and Morris, 1986
gaminv(a)(p, lower)
Returns the inverse function
of the incomplete gamma ratio (see: gratio
).
a
is the shape parameter and p
is the desired tail probability.
lower
is a boolean which determines whether p
is a left-tail
probability or not (defaults to true
).
See also: qgamma
Based on: Computation of the Incomplete Gamma Function Ratios and their Inverse, by DiDonato and Morris, 1986
gamma(x)
Computes $$\Gamma(x) = \int_0^\infty u^{x-1} e^{-u} du$$
Inspired by code in the Gnu Scientific Library
Also see: A Precision Approximation of the Gamma Function, by Lanczos, 1964
gratR(a, x, logr)
Computes the scaled complement of the incomplete gamma ratio function
(see: gratio
): $$\textrm{grat}_r(a,x,r) = \frac{Q(a,x)}{r}$$
where
$Q(a,x)$ is the upper-tail incomplete gamma function
(see: gratioc
) and $r = \frac{e^{-x} x^a}{\Gamma(a)}$
Meant to be used internally.
Based on: Computation of the Incomplete Gamma Function Ratios and their Inverse, by DiDonato and Morris, 1986
gratio(a)(x)
Returns the incomplete gamma ratio: $$P(a,x) = \frac{1}{\Gamma(a)} \int_0^x e^{-t} t^{a-1} dt$$
a
is the shape parameter and $0 < x < \infty$.
See also: pgamma
Based on: Computation of the Incomplete Gamma Function Ratios and their Inverse, by DiDonato and Morris, 1986
gratioc(a)(x)
Returns the complement of the incomplete gamma ratio: $$Q(a,x) = \frac{1}{\Gamma(a)} \int_x^\infty e^{-t} t^{a-1} dt$$
a
is the shape parameter and $0 < x < \infty$.
See also: pgamma
Based on: Computation of the Incomplete Gamma Function Ratios and their Inverse, by DiDonato and Morris, 1986
lbeta(a, b)
Computes the logarithm of the beta function.
See: beta
Based on: Algorithm 708: Significant Digit Computation of the Incomplete Beta Function Ratios, by DiDonato and Morris, 1992
lgamma(x)
Computes the logarithm of the gamma function. See: gamma
Inspired by code in the Gnu Scientific Library
Also see: A Precision Approximation of the Gamma Function, by Lanczos, 1964
log1p(x)
Computes $$\textrm{log1p}(x) = \ln(1+x)$$ with reasonable precision near $x = 0$.
Based on: Computation of the Incomplete Gamma Function Ratios and their Inverse, by DiDonato and Morris, 1986
lpoisson(lambda)(x)
Computes the logarithm of the Poisson pdf $$\log\left(\frac{\lambda^x}{\Gamma(x+1)}e^{-\lambda}\right) = -\lambda + x \ln(\lambda) - \ln(\Gamma(x+1))$$ where $x>0$ and $\lambda>0$.
Based on: Fast and Accurate Computation of Binomial Probabilities, by Catherine Loader, 2000
phi(x)
Computes $$\phi(x) = x - 1 - \ln(x)$$ with reasonable precision near $x = 1$.
Based on: Computation of the Incomplete Gamma Function Ratios and their Inverse, by DiDonato and Morris, 1986
stirlerr(n)
Computes the error term in Stirling's approximation
$$\textrm{stirlerr}(n) = \ln(\Gamma(n+1)) - n \ln(n) + n - \frac{1}{2} \ln\left(2\pi n\right)$$
where $n>0$ (n
does not need to be an integer).
Based on: Fast and Accurate Computation of Binomial Probabilities, by Catherine Loader, 2000
C
Constants module, provides frozen values for some frequently-used constants.
C
Constants module, provides frozen values for some frequently-used constants.
eulerGamma
The Euler-Mascheroni constant \[\gamma = \lim _ {n \to \infty} \left(-\ln(n) + \sum _ {k=1}^n \frac{1}{k}\right) = 0.57721566 \ldots\]
log2pi
$\ln(2\pi)$
sqrt2pi
$\sqrt{2\pi}$
twopi
$2\pi$
distributions
Probability Distributions
The correspondence between the possible values of a random variable and their associated probabilities is referred to as a probability distribution. Random variables can be discrete, that is, taking any of a specified finite or countable list of values, or continuous, taking any value in a specified subset of the real numbers (typically, an interval). This module provides some of the most commonly used discrete and continuous probability distributions.
If $X$ is a discrete random variable with sample space $S$ (the set of all possible values), then $X$ can be specified by a probability mass function (pmf) $f:\,S \rightarrow [0,1]$. The probability of $X$ taking the single value $x$ is given by $f(x)$: $$\textrm{Pr}(X = x) = f(x)$$ and the total mass is 1: $$\textrm{Pr}(X \in S) = \sum_{x \in S} f(x) = 1$$
If $X$ is a continuous random variable, then $X$ can be specified by a probability density function (pdf) $f:\,\Re \rightarrow [0, \infty)$. The probability of $X$ taking a value in a given interval $[a, b]$ is the corresponding area beneath the density curve: $$\textrm{Pr}(a \leq X \leq b) = \int_{a}^{b} f(x) \, dx$$
The probability for a continuous random variable $X$ to take any single value is thus zero. and the total mass is 1: $$\textrm{Pr}(-\infty \leq X \leq \infty) = \int_{-\infty}^{\infty} f(x) \, dx = 1$$
The cumulative distribution function (cdf) $F(x)$ is defined by $F(x) = \textrm{Pr}(X \leq x)$; $F(x)$ is is often referred to as the left-tail probability for the cutoff value $x$. In the discrete case, where $f(x)$ is the probability mass function and $S$ is the sample space (set of all possible values for $X$), the cdf is defined as a sum: $$ F(x) = \sum_{t \in S \text{, } t \leq x}f(t)$$
In the continuous case, where $f(x)$ is the probability density function, the cdf is defined as an integral: $$ F(x) = \int_{-\infty}^{x} f(t) \, dt$$
For $0 < p < 1$, the quantile function $Q(p)$ returns the smallest value of $X$ for which the left-tail probability is at least $p$: $$Q(p) = \textrm{inf} \{x : p \leq F(x) \}$$
When the cdf $F$ is continuous and strictly monotone, $Q = F^{-1}$; that is, $$Q(p) = x \text{ such that } \textrm{Pr}(X \leq x) = p$$ This explains the usage of inverse cdf as a synonym for quantile function.
If the sample space $S$ has a minimum, then $Q(0) = \textrm{min}(S)$; similarly, if the sample space $S$ has a maximum, then $Q(1) = \textrm{max}(S)$.
A single observation from a random variable is referred to as a variate or deviate. Each of the distributions provided in this module includes a method for generating random variates.
beta
The beta distribution. See beta
.
binom
The binomial distribution. See binomial
.
chisq
The chi squared distribution. See chisq
.
exp
The exponential distribution. See exponential
.
f
The f distribution. See f
.
finite
Constructor for finite distributions. See finite
.
gamma
The gamma distribution. See gamma
.
geom
The geometric distribution. See geometric
.
lognormal
The lognormal distribution. See lognormal
.
nbinom
The negative binomial distribution. See nbinom
.
normal
The normal distribution. See normal
.
poisson
The Poisson distribution. See poisson
.
t
The t distribution. See t
.
uniform
The uniform distribution. See uniform
.
beta
Provides density function, cumulative distribution function, quantile function, and random number generator for the Beta distribution, which is defined by the pdf $$f(x;a,b) = \frac{\Gamma(a+b)}{\Gamma(a)\Gamma(b)}x^{(a-1)}(1-x)^{(b-1)}$$ where $x\in[0,1]$ and the parameters $a,b > 0$.
dbeta
provides access to this probability density function,
pbeta
to the cumulative distribution function, qbeta
to the
quantile function (inverse cdf)
and rbeta
to random deviates.
Finally, you can use betadistr
to obtain an object
representing the distribution for some values of the parameters.
betadistr(a, b)
Returns an object representing a beta distribution, with properties d
, p
, q
, r
.
betadistr(a, b).d(x, logp) // same as dbeta(a, b, logp)(x)
betadistr(a, b).p(x, lowerTail, logp) // same as pbeta(a, b, lowerTail, logp)(x)
betadistr(a, b).q(x, lowerTail, logp) // same as qbeta(a, b, lowerTail, logp)(x)
betadistr(a, b).r(n) // same as rbeta(a, b)(n)
dbeta(a, b, logp)(x)
Evaluates the Beta density function at x
:
$$\textrm{dbeta}(a,b)(x) = \frac{\Gamma(a+b)}{\Gamma(a)\Gamma(b)}x^{(a-1)}(1-x)^{(b-1)}$$
Expects $a > 0$, $b > 0$, and $0 \leq x \leq 1$.
logp
defaults to false
; if logp
is true
, returns the
logarithm of the result.
pbeta(a, b, lowerTail, logp)(x)
Evaluates the Beta cumulative distribution
function at x
(lower tail probability):
$$\textrm{pbeta}(a, b)(x) = I_x(a, b)=G(a,b)\int_0^xt^{a-1}(1-t)^{b-1}dt$$
where $B(a,b)=1/G(a,b) = \Gamma(a)\Gamma(b)/\Gamma(a+b)$ is the
usual beta function.
lowerTail
defaults to true
; if lowerTail
is false
, returns
the upper tail probability instead.
logp
defaults to false
; if logp
is true
, returns the logarithm
of the result.
Expects $a>0$, $b>0$, and $0 \leq x \leq 1$.
Based on: Algorithm 708: Significant Digit Computation of the Incomplete Beta Function Ratios, by DiDonato and Morris, 1992
qbeta(a, b, lowerTail, logp)(p)
Evaluates the Beta quantile function (inverse cdf) at p
:
$$\textrm{qbeta}(a, b)(p) = x \textrm{ such that } \textrm{prob}(X \leq x) = p$$
where $X$ is a random variable with the $\textrm{Beta}(a,b)$ distribution.
lowerTail
defaults to true
; if lowerTail
is false
, p
is
interpreted as an upper tail probability (returns
$x$ such that $\textrm{prob}(X > x) = p)$.
logp
defaults to false
; if logp
is true
, interprets p
as
the logarithm of the desired probability.
Expects $a>0$, $b>0$, and $0 \leq p \leq 1$.
rbeta(a, b)()
Returns a random variate from the $\textrm{Beta}(a, b)$ distribution.
Expects $a>0$ and $b>0$.
Based on R's code; see: Generating beta variates with nonintegral shape parameters, by RCH Cheng, 1978
binomial
Provides probability mass function, cumulative distribution function, quantile function, and random number generator for the Binomial distribution, which is defined by the pmf $$f(x;n,p) = {n \choose x}p^x(1-p)^{n-x}$$ where $x=0,\ldots,n$, $n$ is the size and $p$ is the probability of success.
dbinom
provides access to this probability mass function,
pbinom
to the cumulative distribution function, qbinom
to the
quantile function (inverse cdf)
and rbinom
to random deviates.
Finally, you can use binom
to obtain an object
representing the distribution for some values of the parameters.
binom(size, p)
Returns an object representing a binomial distribution, with properties d
, p
, q
, r
.
binom(size, p).d(x, logp) // same as dbinom(size, p, logp)(x)
binom(size, p).p(x, lowerTail, logp) // same as pbinom(size, p, lowerTail, logp)(x)
binom(size, p).q(x, lowerTail, logp) // same as qbinom(size, p, lowerTail, logp)(x)
binom(size, p).r() // same as rbinom(size, p)()
dbinom(size, p, logp)(x)
Returns the Binomial probability at x
:
$$\textrm{dbinom}(\textrm{size}, p)(x) = \binom{\textrm{size}}{p}p^{x}(1-p)^{(\textrm{size}-x)}$$
where x
is an integer, $0 \leq x \leq \textrm{size}$.
size
is a positive integer (number of trials) and $0 \leq p \leq 1$
(the probability of success on a single trial).
logp
defaults to false
; if logp
is true
, returns the
logarithm of the result.
Based on: Fast and Accurate Computation of Binomial Probabilities, by Catherine Loader, 2000
pbinom(size, p, lowerTail, logp)(x)
Evaluates the Binomial cumulative distribution
function at x
(lower tail probability):
$$\textrm{pbinom}(\textrm{size}, p)(x) = \sum_{k \leq x} \binom{\textrm{size}}{p}p^{k}(1-p)^{(\textrm{size}-k)}$$
size
is a positive integer (number of trials) and $0 \leq p \leq 1$
(the probability of success on a single trial).
lowerTail
defaults to true
; if lowerTail
is false
, returns
the upper tail probability instead:
$$\textrm{pbinom}(\textrm{size}, p, \textrm{false})(x) = \sum_{k>x} \binom{\textrm{size}}{p}p^{k}(1-p)^{(\textrm{size}-k)}$$
logp
defaults to false
; if logp
is true
, returns the logarithm
of the result.
qbinom(size, prob, lowerTail, logp)(prob)
Returns the quantile corresponding to prob
for the $\textrm{Binomial}(size, p)$ distribution.
In general, for a discrete probability
distribution, the quantile is defined as the smallest domain value
x
such that $F(x) \geq prob$, where $F$ is the cumulative
distribution function.
size
is a positive integer (number of trials) and $0 \leq p \leq 1$
(the probability of success on a single trial).
lowerTail
defaults to true
; if lowerTail
is false
, prob
is
interpreted as an upper tail probability.
logp
defaults to false
; if logp
is true
, interprets prob
as
the logarithm of the desired probability.
rbinom(size, p)()
Returns a random variate from the $\textrm{Binomial}(size, p)$ distribution.
size
is a positive integer (number of trials) and $0 \leq p \leq 1$
(the probability of success on a single trial).
chisq
Provides density function, cumulative distribution function, quantile function, and random number generator for the chi squared distribution on $k$ degrees of freedom, defined by the pdf: $$f(x; u) = \frac{1}{2^u\Gamma(u)}x^{u - 1} e^{-x/2}$$ where $u = k / 2$, the integer $k > 0$ is the degrees of freedom and $x \in [0, \infty)$.
dchisq
provides access to this probability density function,
pchisq
to the cumulative distribution function, qchisq
to the
quantile function (inverse cdf)
and rchisq
to random deviates.
Finally, you can use chisq
to obtain an object
representing the chi squared distribution for a given value of
the degrees of freedom $k$.
The implementation uses the gamma distribution. See gamma
.
chisq(df)
Returns an object representing a chi squared distribution for df
degrees
of freedom, with properties d
, p
, q
, r
.
chisq(df).d(x, logp) // same as dchisq(df, logp)(x)
chisq(df).p(x, lowerTail, logp) // same as pchisq(df, lowerTail, logp)(x)
chisq(df).q(x, lowerTail, logp) // same as qchisq(df, lowerTail, logp)(x)
chisq(df).r() // same as rchisq(df)()
dchisq(df, logp)(x)
Evaluates the chi squared distribution's density function at x
.
df
is the degrees of freedom $k$.
logp
defaults to false
; if logp
is true
, returns the
logarithm of the result.
pchisq(df, lowerTail, logp)(x)
Evaluates the lower-tail cdf at x
for the chi squared distribution:
$$\textrm{pchisq}(k)(x) = \frac{\gamma(k/2, x/2)}{\Gamma(k/2)}$$
where $\gamma$ is the incomplete gamma function, and
df
is the degrees of freedom $k$.
lowerTail
defaults to true
; if lowerTail
is false
, returns
the upper tail probability instead.
logp
defaults to false
; if logp
is true
, returns the logarithm
of the result.
qchisq(df, lowerTail, logp)(p)
Evaluates the chi-squared distribution's quantile function
(inverse cdf) at p
:
$$\textrm{qchisq}(k)(p) = x \textrm{ such that } \textrm{prob}(X \leq x) = p$$
where $X$ is a random variable with the chi-squared distribution.
df
is the degrees of freedom $k$.
lowerTail
defaults to true
; if lowerTail
is false
, p
is
interpreted as an upper tail probability (returns
$x$ such that $\textrm{prob}(X > x) = p)$.
logp
defaults to false
; if logp
is true
, interprets p
as
the logarithm of the desired probability.
rchisq(df)()
Returns a random variate from the chi squared distribution with df
degrees
of freedom.
exponential
Provides density function, cumulative distribution function, quantile function, and random number generator for the continuous exponential distribution with rate $\lambda$, which is defined by the pdf $$ f(x; \lambda) = \lambda e^{-\lambda x}$$ where $\lambda > 0$ and $x \in [0, \infty)$.
dexp
provides access to this probability density function,
pexp
to the cumulative distribution function, qexp
to the
quantile function (inverse cdf)
and rexp
to random deviates.
Finally, you can use expdistr
to obtain an object
representing the exponential distribution for a given value of
the rate $\lambda$.
dexp(rate, logp)(x)
Evaluates the exponential distribution's density function at x
:
$$\textrm{dexp}(\lambda)(x) = \lambda e^{-\lambda x}$$
for $x \geq 0$.
Expects the rate $\lambda > 0$.
logp
defaults to false
; if logp
is true
, returns the
logarithm of the result.
expdistr(rate)
Returns an object representing an exponential distribution with a
given rate $\lambda > 0$,
with properties d
, p
, q
, r
.
expdistr(rate).d(x, logp) // same as dexp(rate, logp)(x)
expdistr(rate).p(x, lowerTail, logp) // same as pexp(rate, lowerTail, logp)(x)
expdistr(rate).q(x, lowerTail, logp) // same as qexp(rate, lowerTail, logp)(x)
expdistr(rate).r() // same as rexp(rate)()
pexp(rate, lowerTail, logp)(x)
Evaluates the lower-tail cdf at x
for the exponential distribution:
$$\textrm{pexp}(\lambda)(x) = 1 - e^{-\lambda x}$$
Expects the rate $\lambda > 0$.
lowerTail
defaults to true
; if lowerTail
is false
, returns
the upper tail probability instead.
logp
defaults to false
; if logp
is true
, returns the logarithm
of the result.
qexp(rate, lowerTail, logp)(p)
Evaluates the exponential distribution's quantile function
(inverse cdf) at p
:
$$\textrm{qexp}(\lambda)(p) = x \textrm{ such that } \textrm{prob}(X \leq x) = p$$
where $X$ is a random variable with the exponential distribution.
Expects the rate $\lambda > 0$.
lowerTail
defaults to true
; if lowerTail
is false
, p
is
interpreted as an upper tail probability (returns
$x$ such that $\textrm{prob}(X > x) = p)$.
logp
defaults to false
; if logp
is true
, interprets p
as
the logarithm of the desired probability.
rexp(rate)()
Returns a random variate from the exponential distribution.
Expects the rate $\lambda > 0$.
Based on the R code in sexp.c (nmath)
f
Provides density function, cumulative distribution function,
quantile function, and random number generator
for the Fisher-Snedecor F distribution with parameters df1
and df2
(degrees of freedom). It is the distribution of the ratio of the mean
squares of df1
and df2
independent standard normal variates.
df
provides access to the probability density function,
pf
to the cumulative distribution function, qf
to the
quantile function (inverse cdf)
and rf
to random deviates.
Finally, you can use fdistr
to obtain an object
representing the F distribution for given values of
df1
and df2
.
df(df1, df2, logp)(x)
Evaluates the F distribution's density function at x
, where
$x \geq 0$.
Expects df1
and df2
to be positive.
logp
defaults to false
; if logp
is true
, returns the
logarithm of the result.
Adapted from df.c in R's code.
fdistr(df1, df2)
Returns an object representing an F distribution with
given degrees of freedom df1
and df2
. The object has
properties d
, p
, q
, r
.
fdistr(df1, df2).d(x, logp) // same as df(df1, df2, logp)(x)
fdistr(df1, df2).p(x, lowerTail, logp) // same as pf(df1, df2, lowerTail, logp)(x)
fdistr(df1, df2).q(x, lowerTail, logp) // same as qf(df1, df2, lowerTail, logp)(x)
fdistr(df1, df2).r() // same as rf(df1, df2)()
pf(df1, df2, lowerTail, logp)(x)
Evaluates the lower-tail cdf at x
for the F distribution.
Expects df1
and df2
to be positive.
lowerTail
defaults to true
; if lowerTail
is false
, returns
the upper tail probability instead.
logp
defaults to false
; if logp
is true
, returns the logarithm
of the result.
qf(df1, df2, lowerTail, logp)(p)
Evaluates the F distribution's quantile function
(inverse cdf) at p
.
Expects df1
and df2
to be positive.
lowerTail
defaults to true
; if lowerTail
is false
, p
is
interpreted as an upper tail probability (returns
$x$ such that $\textrm{prob}(X > x) = p)$.
logp
defaults to false
; if logp
is true
, interprets p
as
the logarithm of the desired probability.
rf(df1, df2)()
Returns a random variate from the F distribution, computed as a ratio of chi square variates.
Expects df1
and df2
to be positive.
finite
Provides probability mass function, constructor, cumulative distribution function, quantile function, and random number generator for finite discrete probability distributions.
For all members of the finite
module, distributions are provided
via appropriate properties of the object o
. There are two possible options
for that object:
- It can have properties
xs
,ws
, which are arrays of equal length, corresponding to the values the distribution can take and their respective probabilities. In this case thexs
are assumed to be distinct and in increasing order, and thews
are treated as weights, so if they do not add up to 1 then they will be scaled appropriately. Thews
need to be positive. - It can have properties
f
,min
,max
, wheremin
andmax
are numbers andf(i)
is a function. Then the distribution's values are meant to be the sequential numbers (arithmetic sequence) frommin
tomax
with an increment of 1, andf(i)
gives the probability of the valuei
(similar to thews
).
finite
returns an object representing the distribution, dfinite
returns
the probability mass function, pfinite
the cumulative distribution function,
qfinite
the inverse cdf, and rfinite
generates random variates.
Examples:
finite({ min: 1, max: 10, f: function() { return 1; } }) // 10-sided fair die
finite({ xs: [0, 1], ws: [2, 1] }) // Bernoulli trial P(0) = 2/3
dfinite(o, logp)(x)
Returns the probability at x
for the finite distribution
represented by object o
.
logp
defaults to false
; if logp
is true
, returns the
logarithm of the result.
finite(o)
Returns an object representing a finite distribution, with properties
d
, p
, q
, r
.
finite(o).d(x, logp) // same as dfinite(o, logp)(x)
finite(o).p(x, lowerTail, logp) // same as pfinite(o, lowerTail, logp)(x)
finite(o).q(x, lowerTail, logp) // same as qfinite(o, lowerTail, logp)(x)
finite(o).r(n) // same as rfinite(o)(n)
pfinite(o, lowerTail, logp)(x)
Evaluates the cumulative distribution function at x
for the finite distribution represented by object o
:
$$\textrm{pfinite}(o)(x) = \sum_{k \leq x} dfinite(k)$$
lowerTail
defaults to true
; if lowerTail
is false
, returns
the upper tail probability instead:
$$\textrm{pfinite}(o)(x) = \sum_{k > x} dfinite(k)$$
logp
defaults to false
; if logp
is true
, returns the logarithm
of the result.
qfinite(o, lowerTail, logp)(p)
Evaluates the quantile function for the finite distribution
specified by object o
.
In general, for a discrete probability
distribution, the quantile is defined as the smallest domain value
x
such that $F(x) \geq p$, where $F$ is the cumulative
distribution function.
p
is the desired probability ($0 \leq p \leq 1$).
lowerTail
defaults to true
; if lowerTail
is false
, p
is
interpreted as an upper tail probability.
logp
defaults to false
; if logp
is true
, interprets p
as
the logarithm of the desired probability.
qfinite
tries to invert pfinite
but cannot be an exact inverse.
In particular, for lowerTail = true
:
- if asked for the smallest quantile for which the left area (<=) is 0,
qfinite
returnsmin
- if asked for the smallest quantile for which the left area (<=) is 1,
qfinite
returnsmax
.
The edge cases for lowerTail = false
are symmetrical to the preceding:
qfinite
returns min
or max
for a right-tail area (>) of 1 or 0, respectively.
rfinite(o)()
Returns a random variate from the finite distribution
specified by object o
.
gamma
Provides density function, cumulative distribution function, quantile function, and random number generator for the Gamma distribution, which is defined by the pdf $$f(x;a,s) = \frac{1}{s^a\Gamma(a)}x^{a-1}e^{-x/s}$$ where $x\in(0,\infty)$. The parameter $a>0$ is called the shape and the parameter $s>0$ the scale.
dgamma
provides access to this probability density function,
pgamma
to the cumulative distribution function, qgamma
to the
quantile function (inverse cdf)
and rgamma
to random deviates.
Finally, you can use gammadistr
to obtain an object
representing the distribution for some values of the parameters.
dgamma(a, s, logp)(x)
Evaluates the Gamma density function at x
:
$$\textrm{dgamma}(a, s)(x) = \frac{1}{s^a\Gamma(a)}x^{a-1}e^{-x/s}$$
Expects $a > 0$, $s > 0$, and $x > 0$.
logp
defaults to false
; if logp
is true
, returns the
logarithm of the result.
gammadistr(a, s)
Returns an object representing a gamma distribution, with properties d
, p
, q
, r
.
gammadistr(a, s).d(x, logp) // same as dgamma(a, s, logp)(x)
gammadistr(a, s).p(x, lowerTail, logp) // same as pgamma(a, s, lowerTail, logp)(x)
gammadistr(a, s).q(x, lowerTail, logp) // same as qgamma(a, s, lowerTail, logp)(x)
gammadistr(a, s).r() // same as rgamma(a, s)()
pgamma(a, s, lowerTail, logp)(x)
Evaluates the Gamma cumulative distribution
function at x
(lower tail probability):
$$\textrm{pgamma}(a, s)(x) = \frac{1}{s^a\Gamma(a)}\int_0^x t^{a-1}e^{-t/s}dt$$
lowerTail
defaults to true
; if lowerTail
is false
, returns
the upper tail probability instead.
logp
defaults to false
; if logp
is true
, returns the logarithm
of the result.
Expects $a > 0$, $s > 0$, and $x > 0$.
Based on: Computation of the Incomplete Gamma Function Ratios and their Inverse, by DiDonato and Morris, 1992
qgamma(a, s, lowerTail, logp)(p)
Evaluates the Gamma distribution's quantile function (inverse cdf) at p
:
$$\textrm{qgamma}(a, s)(p) = x \textrm{ such that } \textrm{prob}(X \leq x) = p$$
where $X$ is a random variable with the $\textrm{Gamma}(a, s)$ distribution.
lowerTail
defaults to true
; if lowerTail
is false
, p
is
interpreted as an upper tail probability (returns
$x$ such that $\textrm{prob}(X > x) = p)$.
logp
defaults to false
; if logp
is true
, interprets p
as
the logarithm of the desired probability.
Expects $a>0$, $s>0$, and $0 \leq p \leq 1$.
rgamma(a, s)()
Returns a random variate from the $\textrm{Gamma}(a, s)$ distribution.
Expects $a > 0$ and $s > 0$.
Based on:
- Some simple gamma variate generators, by Cheng and Feast, 1979
- Computer methods for sampling from gamma, beta, Poisson and binomial distributions, by Ahrens and Dieter, 1974
- A note on gamma variate generators with shape parameter less than unity, by Best, 1983
As seen in: Random Number Generation and Monte Carlo Methods, Second Edition, by Gentle, Springer 2005
geometric
Provides probability mass function, cumulative distribution function, quantile function, and random number generator for the geometric distribution with parameter the probability $p$, which is defined by the pdf $$ f(x; p) = p (1-p)^x$$ where $0 < p \leq 1$ and $x \in\left\{0,1,2,\ldots\right\}$.
dgeom
provides access to this probability mass function,
pgeom
to the cumulative distribution function, qgeom
to the
quantile function (inverse cdf)
and rgeom
to random deviates.
Finally, you can use geom
to obtain an object
representing the geometric distribution for a given value of
the probability parameter $p$.
dgeom(prob, logp)(x)
Evaluates the geometric distribution's probability mass function at x
:
$$\textrm{dgeom}(p)(x) = p(1-p)^x$$
for $x \in\left\{0,1,2,\ldots\right\}$.
Expects the probability $0 < p\leq 1$.
logp
defaults to false
; if logp
is true
, returns the
logarithm of the result.
The implementation uses dbinom
.
geom(prob)
Returns an object representing an geometric distribution with a
given probability parameter $0 < p \leq 1$,
with properties d
, p
, q
, r
.
geom(prob).d(x, logp) // same as dgeom(prob, logp)(x)
geom(prob).p(x, lowerTail, logp) // same as pgeom(prob, lowerTail, logp)(x)
geom(prob).q(x, lowerTail, logp) // same as qgeom(prob, lowerTail, logp)(x)
geom(prob).r() // same as rgeom(prob)()
pgeom(prob, lowerTail, logp)(x)
Evaluates the lower-tail cdf at x
for the geometric distribution:
$$\textrm{pgeom}(p)(x) = 1 - (1-p)^{x+1}$$
Expects the probability $0 < p \leq 1$.
lowerTail
defaults to true
; if lowerTail
is false
, returns
the upper tail probability instead.
logp
defaults to false
; if logp
is true
, returns the logarithm
of the result.
The implementation uses pbinom
.
qgeom(prob, lowerTail, logp)(p)
Evaluates the geometric distribution's quantile function
(inverse cdf) at p
:
$$\textrm{qexp}(\textrm{prob})(p) = x \textrm{ such that } \textrm{prob}(X \leq x) = p$$
where $X$ is a random variable with the geometric distribution.
Expects the probability parameter $0 < \textrm{prob} \leq 1$.
lowerTail
defaults to true
; if lowerTail
is false
, p
is
interpreted as an upper tail probability (returns
$x$ such that $\textrm{prob}(X > x) = p)$.
logp
defaults to false
; if logp
is true
, interprets p
as
the logarithm of the desired probability.
rgeom(prob)()
Returns a random variate from the geometric distribution.
Expects the probability parameter $0 < p \leq 1$.
Following R's code (rgeom.c)
lognormal
Provides density function, cumulative distribution function,
quantile function, and random number generator
for the lognormal distribution, with parameter $\mu$ (meanlog
) and
$\sigma$ (sdlog
) for the associated normal distribution.
The lognormal is defined by the pdf: $$f(x;\mu,\sigma) = \frac{1}{x\sigma \sqrt{2\pi}} e^{\displaystyle -\frac{(\ln x-\mu)^2}{2\sigma^2}}$$ where $x\in(0,\infty)$.
dlnorm
provides access to this probability density function,
plnorm
to the cumulative distribution function, qlnorm
to the
quantile function (inverse cdf)
and rlnorm
to random deviates.
Finally, you can use lognormal
to obtain an object
representing the distribution for some values of the parameters.
dlnorm(meanlog, sdlog, logp)(x)
Evaluates the lognormal distribution's density function at x
.
Expects $x > 0$ and $\textrm{sdlog} > 0$.
lognormal(meanlog, sdlog)
Returns an object representing a normal distribution, with properties d
, p
, q
, r
.
lognormal(meanlog, sdlog).d(x, logp) // same as dlnorm(meanlog, sdlog, logp)(x)
lognormal(meanlog, sdlog).p(x, lowerTail, logp) // same as plnorm(meanlog, sdlog, lowerTail, logp)(x)
lognormal(meanlog, sdlog).q(x, lowerTail, logp) // same as qlnorm(meanlog, sdlog, lowerTail, logp)(x)
lognormal(meanlog, sdlog).r() // same as rlnorm(meanlog, sdlog)()
plnorm(meanlog, sdlog, lowerTail, logp)(x)
Evaluates the lower-tail cdf at x
for the lognormal distribution:
$$\textrm{pnorm}(\mu, \sigma)(x) = \frac{1}{2}\left(1 + \textrm{erf}\left(\frac{\ln x - \mu}{\sigma\sqrt{2}}\right)\right)$$
lowerTail
defaults to true
; if lowerTail
is false
, returns
the upper tail probability instead.
logp
defaults to false
; if logp
is true
, returns the logarithm
of the result.
Expects $\textrm{sdlog} > 0$ and $x > 0$.
qlnorm(meanlog, sdlog, lowerTail, logp)(p)
Evaluates the lognormal distribution's quantile function (inverse cdf) at p
:
$$\textrm{qlnorm}(\mu, \sigma)(p) = x \textrm{ such that } \textrm{prob}(X \leq x) = p$$
where $X$ is a random variable with the lognormal distribution.
lowerTail
defaults to true
; if lowerTail
is false
, p
is
interpreted as an upper tail probability (returns
$x$ such that $\textrm{prob}(X > x) = p)$.
logp
defaults to false
; if logp
is true
, interprets p
as
the logarithm of the desired probability.
Expects $\textrm{sdlog} > 0$.
rlnorm(meanlog, sdlog)()
Returns a random variate from the lognormal distribution.
Expects $\textrm{sdlog} > 0$.
Uses a rejection polar method.
nbinom
Provides probability mass function, cumulative distribution function,
quantile function, and random number generator
for the negative binomial distribution with parameters size
and prob
.
This represents the number of failures which occur in a sequence of Bernoulli
trials before a target number (size
) of successes is reached. The parameter
prob
represents the probability of success in each trial.
size
must be strictly positive, and prob
must be in (0, 1]
.
dnbinom
provides access to the probability mass function,
pnbinom
to the cumulative distribution function, qnbinom
to the
quantile function (inverse cdf)
and rnbinom
to random deviates.
Finally, you can use nbinom
to obtain an object
representing the negative binomial distribution for given values of
size
and prob
.
dnbinom(size, prob, logp)(x)
Evaluates the negative binomial distribution's probability mass function
at x
, where $x \geq 0$.
size
must be strictly positive, and prob
must be in (0, 1]
.
logp
defaults to false
; if logp
is true
, returns the
logarithm of the result.
Adapted from dnbinom.c in R's code.
nbinom(size, prob)
Returns an object representing a negative binomial distribution with
given parameters size
and prob
. The object has
properties d
, p
, q
, r
.
size
must be strictly positive, and prob
must be in (0, 1]
.
nbinom(size, prob).d(x, logp) // same as dnbinom(size, prob, logp)(x)
nbinom(size, prob).p(x, lowerTail, logp) // same as pnbinom(size, prob, lowerTail, logp)(x)
nbinom(size, prob).q(x, lowerTail, logp) // same as qnbinom(size, prob, lowerTail, logp)(x)
nbinom(size, prob).r() // same as rnbinom(size, prob)()
pnbinom(size, prob, lowerTail, logp)(x)
Evaluates the lower-tail cdf at x
for the negative binomial distribution.
size
must be strictly positive, and prob
must be in (0, 1]
.
lowerTail
defaults to true
; if lowerTail
is false
, returns
the upper tail probability instead.
logp
defaults to false
; if logp
is true
, returns the logarithm
of the result.
qnbinom(size, prob, lowerTail, logp)(p)
Evaluates the negative binomial distribution's quantile function
(inverse cdf) at p
.
size
must be strictly positive, and prob
must be in (0, 1]
.
lowerTail
defaults to true
; if lowerTail
is false
, p
is
interpreted as an upper tail probability (returns
$x$ such that $\textrm{prob}(X > x) = p)$.
logp
defaults to false
; if logp
is true
, interprets p
as
the logarithm of the desired probability.
rnbinom(size, prob)()
Returns a random variate from the negative binomial distribution.
size
must be strictly positive, and prob
must be in (0, 1]
.
normal
Provides density function, cumulative distribution function, quantile function, and random number generator for the normal distribution, which is defined by the pdf $$f(x;\mu,\sigma) = \frac{1}{\sigma \sqrt{2\pi}} e^{\displaystyle -\frac{(x-\mu)^2}{2\sigma^2}}$$ where $x\in(-\infty,\infty)$ and as usual $\mu$ is the mean and $\sigma>0$ is the standard deviation.
dnorm
provides access to this probability density function,
pnorm
to the cumulative distribution function, qnorm
to the
quantile function (inverse cdf)
and rnorm
to random deviates.
Finally, you can use normal
to obtain an object
representing the distribution for some values of the parameters.
dnorm(mu, sigma, logp)(x)
Evaluates the Normal density function at x
:
$$\textrm{dnorm}(\mu, \sigma)(x) = \frac{1}{\sigma \sqrt{2\pi}} e^{\displaystyle -\frac{(x-\mu)^2}{2\sigma^2}}$$
Expects $\sigma > 0$.
logp
defaults to false
; if logp
is true
, returns the
logarithm of the result.
normal(mu, sigma)
Returns an object representing a normal distribution, with properties d
, p
, q
, r
.
normal(mu, sigma).d(x, logp) // same as dnorm(mu, sigma, logp)(x)
normal(mu, sigma).p(x, lowerTail, logp) // same as pnorm(mu, sigma, lowerTail, logp)(x)
normal(mu, sigma).q(x, lowerTail, logp) // same as qnorm(mu, sigma, lowerTail, logp)(x)
normal(mu, sigma).r() // same as rnorm(mu, sigma)()
pnorm(mu, sigma, lowerTail, logp)(x)
Evaluates the lower-tail cdf at x
for the Normal distribution:
$$\textrm{pnorm}(\mu, \sigma)(x) = \frac{1}{\sigma \sqrt{2\pi}}\int_{-\infty}^x e^{\displaystyle -\frac{(t-\mu)^2}{2\sigma^2}}dt$$
lowerTail
defaults to true
; if lowerTail
is false
, returns
the upper tail probability instead.
logp
defaults to false
; if logp
is true
, returns the logarithm
of the result.
Expects $\sigma > 0$.
qnorm(mu, sigma, lowerTail, logp)(p)
Evaluates the Normal distribution's quantile function (inverse cdf) at p
:
$$\textrm{qnorm}(\mu, \sigma)(p) = x \textrm{ such that } \textrm{prob}(X \leq x) = p$$
where $X$ is a random variable with the $N(\mu,\sigma)$ distribution.
lowerTail
defaults to true
; if lowerTail
is false
, p
is
interpreted as an upper tail probability (returns
$x$ such that $\textrm{prob}(X > x) = p)$.
logp
defaults to false
; if logp
is true
, interprets p
as
the logarithm of the desired probability.
Expects $\sigma > 0$.
rnorm(mu, sigma)()
Returns a random variate from the $N(\mu, \sigma)$ distribution.
Expects $\sigma > 0$.
Uses a rejection polar method.
poisson
Provides probability mass function, cumulative distribution function, quantile function, and random number generator for the Poisson distribution, which is defined by the pmf $$f(x;\lambda) = \frac{\lambda^x}{x!}e^{-\lambda}$$ where $x=0,1,2,\ldots$ and $\lambda > 0$ is the mean.
dpois
provides access to this probability mass function,
ppois
to the cumulative distribution function, qpois
to the
quantile function (inverse cdf)
and rpois
to random deviates.
Finally, you can use pois
to obtain an object
representing the Poisson distribution for a given value of $\lambda$.
dpois(lambda, logp)(x)
Evaluates the Poisson probability mass function at x
:
$$\textrm{dpois}(\lambda)(x) = \frac{\lambda^x}{x!}e^{-\lambda}$$
Expects $\lambda > 0$.
logp
defaults to false
; if logp
is true
, returns the
logarithm of the result.
pois(lambda)
Returns an object representing a Poisson distribution
for a given value of $\lambda > 0$, with properties d
, p
, q
, r
.
pois(a, b).d(x, logp) // same as dpois(a, b, logp)(x)
pois(a, b).p(x, lowerTail, logp) // same as ppois(a, b, lowerTail, logp)(x)
pois(a, b).q(x, lowerTail, logp) // same as qpois(a, b, lowerTail, logp)(x)
pois(a, b).r() // same as rpois(a, b)()
ppois(lambda, lowerTail, logp)(x)
Evaluates the lower-tail cdf at x
for the Poisson distribution:
$$\textrm{ppois}(\lambda)(x) = e^{-\lambda} \sum_{i=0}^{\left \lfloor{x}\right \rfloor}\frac{\lambda^i}{i!}$$
Expects $\lambda > 0$.
lowerTail
defaults to true
; if lowerTail
is false
, returns
the upper tail probability ($P(X > x)$) instead.
logp
defaults to false
; if logp
is true
, returns the logarithm
of the result.
qpois(lambda, lowerTail, logp)(p)
Evaluates the Poisson distribution's quantile function
(inverse cdf) at p
:
$$\textrm{qpois}(\lambda)(p) = x \textrm{ such that } \textrm{prob}(X \leq x) = p$$
where $X$ is a random variable with the $\textrm{Poisson}(\lambda)$ distribution.
Expects $\lambda > 0$ and $0 \leq p \leq 1$.
lowerTail
defaults to true
; if lowerTail
is false
, p
is
interpreted as an upper tail probability (returns
$x$ such that $\textrm{prob}(X > x) = p)$.
logp
defaults to false
; if logp
is true
, interprets p
as
the logarithm of the desired probability.
rpois(lambda)()
Returns a random variate from the $\textrm{Poisson}(\lambda)$ distribution.
Expects $\lambda > 0$.
t
Provides density function, cumulative distribution function, quantile function, and random number generator for the Student's t distribution, which is defined by the pdf $$f(x;\nu) = \frac{1}{\sqrt{\nu}\,\textrm{B}(1/2, \nu/2)} \left(1+\frac{x^2}{\nu} \right)^{-\frac{\nu + 1}{2}}$$ where B is the Beta function, $x \in (-\infty, \infty)$ and $\nu >0$ is the degrees of freedom.
dt
provides access to this probability density function,
pt
to the cumulative distribution function, qt
to the
quantile function (inverse cdf)
and rt
to random deviates.
Finally, you can use tdistr
to obtain an object
representing the t distribution for a given value of $\nu$.
dt(df, logp)(x)
Evaluates the t density function at x
:
$$\textrm{dt}(\textrm{df})(x) = \frac{1}{\sqrt{\textrm{df}}\,\textrm{B}(1/2, \textrm{df}/2)} \left(1+\frac{x^2}{\textrm{df}} \right)^{-\frac{\textrm{df} + 1}{2}}$$
Expects $\textrm{df} > 0$.
logp
defaults to false
; if logp
is true
, returns the
logarithm of the result.
pt(df, lowerTail, logp)(x)
Evaluates the lower-tail cdf at x
for the t distribution:
$$\textrm{pt}(\textrm{df})(x) = \int_{-\infty}^{x} \frac{1}{\sqrt{\textrm{df}}\,\textrm{B}(1/2, \textrm{df}/2)} \left(1+\frac{x^2}{\textrm{df}} \right)^{-\frac{\textrm{df} + 1}{2}}$$
Expects $\textrm{df} > 0$.
lowerTail
defaults to true
; if lowerTail
is false
, returns
the upper tail probability instead.
logp
defaults to false
; if logp
is true
, returns the logarithm
of the result.
qt(df, lowerTail, logp)(p)
Evaluates the t distribution's quantile function
(inverse cdf) at p
:
$$\textrm{qt}(\textrm{df})(p) = x \textrm{ such that } \textrm{prob}(X \leq x) = p$$
where $X$ is a random variable with the $t(\textrm{df})$ distribution.
Expects $\textrm{df} > 0$ and $0 \leq p \leq 1$.
lowerTail
defaults to true
; if lowerTail
is false
, p
is
interpreted as an upper tail probability (returns
$x$ such that $\textrm{prob}(X > x) = p)$.
logp
defaults to false
; if logp
is true
, interprets p
as
the logarithm of the desired probability.
Based on: R code
rt(df)()
Returns a random variate from the $t(\textrm{df})$ distribution.
Expects $\textrm{df} > 0$.
tdistr(df)
Returns an object representing a t distribution with $\textrm{df} > 0$
degrees of freedom, with properties d
, p
, q
, r
.
tdistr(a, b).d(x, logp) // same as dt(a, b, logp)(x)
tdistr(a, b).p(x, lowerTail, logp) // same as pt(a, b, lowerTail, logp)(x)
tdistr(a, b).q(x, lowerTail, logp) // same as qt(a, b, lowerTail, logp)(x)
tdistr(a, b).r() // same as rt(a, b)()
uniform
Provides density function, cumulative distribution function, quantile function, and random number generator for the continuous uniform distribution on $[a, b]$, which is defined by the pdf $$ f(x; a, b) = \begin{cases} \frac{1}{b-a}, & \text{if $a \leq x \leq b$} \\ 0, & \text{if $x < a$ or $x > b$} \end{cases} $$ where $a < b$ and $x \in (-\infty, \infty)$.
dunif
provides access to this probability density function,
punif
to the cumulative distribution function, qunif
to the
quantile function (inverse cdf)
and runif
to random deviates.
Finally, you can use unif
to obtain an object
representing the Uniform distribution for given values of
a
and b
.
dunif(a, b, logp)(x)
Evaluates the Uniform density function at x
:
$$\textrm{dunif}(a, b)(x) = \begin{cases}
\frac{1}{b-a}, & \text{if $a \leq x \leq b$} \\
0, & \text{if $x < a$ or $x > b$} \end{cases} $$
Expects $a < b$.
logp
defaults to false
; if logp
is true
, returns the
logarithm of the result.
punif(a, b, lowerTail, logp)(x)
Evaluates the lower-tail cdf at x
for the Uniform distribution:
$$\textrm{punif}(a, b)(x) = \begin{cases}
\frac{x-a}{b-a}, & \text{if $a \leq x \leq b$} \\
0, & \text{if $x < a$} \\
1, & \text{if $x > b$} \end{cases} $$
Expects $a < b$.
lowerTail
defaults to true
; if lowerTail
is false
, returns
the upper tail probability instead.
logp
defaults to false
; if logp
is true
, returns the logarithm
of the result.
qunif(a, b, lowerTail, logp)(p)
Evaluates the Uniform distribution's quantile function
(inverse cdf) at p
:
$$\textrm{qunif}(a, b)(p) = x \textrm{ such that } \textrm{prob}(X \leq x) = p$$
where $X$ is a random variable with the $\textrm{Uniform}(a, b)$ distribution.
Expects $a < b$ and $0 \leq p \leq 1$.
lowerTail
defaults to true
; if lowerTail
is false
, p
is
interpreted as an upper tail probability (returns
$x$ such that $\textrm{prob}(X > x) = p)$.
logp
defaults to false
; if logp
is true
, interprets p
as
the logarithm of the desired probability.
runif(a, b)()
Returns a random variate from the $\textrm{Uniform}(a,b)$ distribution.
Expects $a<b$.
unif(a, b)
Returns an object representing a Uniform distribution on $[a, b]$,
with properties d
, p
, q
, r
.
unif(a, b).d(x, logp) // same as dunif(a, b, logp)(x)
unif(a, b).p(x, lowerTail, logp) // same as punif(a, b, lowerTail, logp)(x)
unif(a, b).q(x, lowerTail, logp) // same as qunif(a, b, lowerTail, logp)(x)
unif(a, b).r() // same as runif(a, b)()
rgen
Random number generation
panthrMath implements its own random number generation, to provide consistency across platforms. Currently, only one algorithm is provided. See: Random Number Generation and Monte Carlo Methods, 2nd edition, by J. Gentle (Springer).
Available algorithms:
slcg
: simple linear congruential generator, using the congruence $x_i \equiv a x _ {i-1} + c \bmod m$ where $a = 16807$, $c = 0$, and $m = 2^{31} - 1$.
getAlgorithms()
Returns a list of the available algorithms for random number generation.
random()
Generates a random number uniformly on the interval $(0, 1)$.
setAlgorithm(name)
Sets the algorithm to be used for random number generation.
Expects name
to be one of the strings returned by getAlgorithms
.
setRandomSeed()
Sets a seed for random number generation, based on the system date.
setSeed(seed)
Sets a seed for the random number generator. Expects seed
to
be an integer.


Let's Play Rock Paper Scissors!
Watch two computers play!
Want to play with the computer, click here!
Rock, Paper, Scissors, Lizard & Spock!!
Rules for Playing...Rock beats Scissors, Scissors cuts Paper, Paper covers Rock
Make a choice from the dropdown, see what the computer chose and check out the result!
Make a Choice
Rock
Paper
Scissors
Computer Chose :

It's a tie , try choosing oher options to win..
Awesome you won, keep going and pray for your luck..
Oh snap!! You lost this time..better luck next time , don't lose hope..
Score
Your's Score
Computer's Score
0
0
Reset Score


We invite you to celebrate our wedding @ Ocean Villa Heights Hotel
I don't need the whole world to love me.I just need that one person and I'm proud to say that special person is you! Then I suffered from AJIRITIES.A disease I caught and don't need a cure for it
If I did anything right in my life, it was when I gave my heart to you.If I could turn back the clock I'd find you sooner and love you longer Habeebi
Address: Ocean Villa Heights Hotel 51 Brufut Heights, Brufut, Gambia
There will be folks around turn table at Brufut to help for guidance
When we first met, we never imagined that we would sing, dance and fall in love together.Decades from this day, when our voices gets croaky but our steps still stay graceful,we will remember these moments.
On this very night. You agreed to be always in my heart. On this very night you put your hand in your heart and feel me. Please never leave me and never ever let me go because I will never find a more beautiful place to live. Please be with me till the end of life. I love you Jamie
Your love is something that I can’t control.  Before I met you, I was not familiar with the feeling of love. But now I came to know what love is. My heart misses its beats when I come closer to you. I love you My ELHAJIE
Our first date was beautiful.In comfortable surroundings. A place with excellent food, where we got on really well and our conversations was effortless."#Mbeguel"
The most beautiful things are not associated with money.They are memories and moments.If you don't celebrate those they can pass you by. [Alen Wek]


e.s.ServerSetup : class documentation
Part of
elita
.
servers
View In Hierarchy
Initialization routines for new servers.
Method
__init__
Method
set_server_type
Undocumented
Method
set_server_status
Undocumented
Method
do_server_setup
Undocumented
Method
new
Undocumented
def __init__(self, datasvc):
def set_server_type(self, rc, name):
Undocumented
def set_server_status(self, rc, name):
Undocumented
def do_server_setup(self, rc, name, os_type):
Undocumented
def new(self, name):
Undocumented
API Documentation
for elita, generated by
pydoctor
at 2014-10-29 15:25:55.


Going for regular check ups
Type 2 diabetes check ups help to make sure your condition doesn’t lead to other health problems, eg with your eyesight, heart or your feet.
Every 3 months
Long-term blood sugar checks (HbA1C test)
Checks your average blood sugar levels and how close they are to normal.
You have these checks every 3 months when newly diagnosed, then every 6 months once you’re stable.
Once a year
Feet
Checks if you’ve lost any sensation in your feet and possibly for ulcers and infections.
You have these checks once a year. Speak to your GP if you have cuts and bruises on your feet.
Eyes
Checks for damage to blood vessels in your eyes.
You have these checks once a year. Speak to your GP if you have blurred vision.
Blood pressure, blood fats (cholesterol) and kidneys
Checks for high blood pressure, heart and kidney disease.
You have these checks once a year.
Why it’s important to have these check ups
What happens after your appointment
The person you have the appointment with, for example your diabetes nurse, will tell you how long it takes to get the test results and if you need to come in again.
{{ ui_element_macros.simple_pagination({ previous: { url: "/type-2-diabetes/type-2-diabetes-medicines", title: "Understanding medication" }, next: { url: "/type-2-diabetes/health-problems-caused-by-diabetes-type-2", title: "Health problems" } }) }} {% include "includes/nhs.uk/page_meta.html" %}


Ettus X310 and Gnuradio¶
Some of the following information can also be applied to other Ettus USRP devices.
The Ettus USRP¶
Ettus Research and the National instruments company provides a broad product line of SDR platforms with e.g different frequency coverage and bandwidths [4]. The Ettus USRP X3x0 series is currently the most high performing platform and would be the most suitable for radio systems with high demands on bandwidth and accuracy. The provided General Purpose Input Output (GPIO) interface in the x3x0 series also makes implementations of Dicke-switching an easier task, and as we shall see is fundamental for the FFTS described here. A general USRP architecture is provided in the figure below, specifics may vary depending on the model [5].
The first part of the receiver (RX) chain consist of a fundamental Low Noise Amplifier (LNA) with variable attenuation exposed in software e.g GNURadio. The signal is further modulated into inphase and quadrature signals I and Q. Analog and Digital (A/D) converters handles the discretization of the RF providing a bandwidth determined by the daughterboard i.e the front-end of the Ettus USRP [2]. The onboard FPGA down converts the signal by an Digital Down Converter (DDC) implementation providing fine frequency tuning and filters for decimation. The data is subsequently exposed to the host computer through Ethernet or PCIe interfaces.
PCIe interface¶
The PCIe interface provides high data throughput together with low latency, where the latter is a important part for Dicke-switched purposes due to the importance of deterministic timings. However the 10 Gbit ethernet interface provides higher throughput.
Installation¶
The latest PCIe driver can be downloaded here. Follow the instructions at the site to install the driver. This simply involves unpacking the software and running the install script followed by a reboot. Se the manual on how to disable and enable the PCIe drivers. Navigate to http://files.ettus.com for older versions of the driver.
Sampling rates¶
The x3x0 series delivers up to 200 M samples/s (I/Q), thus your host computer might have trouble keeping up to speed. Overflow, lost samples, is indicated by a an O in the terminal and is an indication that there is a bottle neck at your host. Several things can be done to address this issue.
First of all is to check that your hardware is up to speed. Check the CPU load, RAM usage and not least the harddrive. A mechanical drive would allow a sample rate up to about 30 Mhz of I/Q sampling depending on the harddrive. The other option would be to use a SSD and it can get you alot higher, however I experienced quite alot of performance issues when running under Linux, with write speeds way below the specifications. I eventually abandoned the SSD and right now I’m using Ramdisk, which in theory should have no problem whatsoever for a complex sample rate of 200Mhz (800MB/s).
Other host side improvements that can be done is to expand the socket buffers, setting the governors for your CPU to run at maximum performance and several other parameters. More information and instructions on this can be found here.
If perfomance issues is still a problem go back to the base of your application and check for issues there. There is also another option, which is FPGA programming. Go to this section for more information.
Sampling rate decimations¶
There are several half band filters incorporated in the Ettus X310 device and some decimations may result in all of them not being activated. Those decimations are the uneven ones. For example a sampling frequency of 50 Mhz = 200 Mhz / 4 will have all the half band filters activated. Figure 1,2,3 and 4 show examples how this unfolds on Gaussian noise from a receiver. In the first figure And now it is possible to see the This is, for the most part, not very interesting
Master Clock Rates¶
The Ettus x310 currently support three different Master Clock Rates; 200Mhz (Default), 184.32Mhz and 120Mhz. In practice this means that other even sampling rate decimations can be achieved, allowing for better filter trade-off. The Master Clock Rate can be set in the GnuRadio application, see Code explanation for details.
GNU Radio¶
The software interface GNU Radio performs signal processing through the use of dedicated blocks, e.g. infinite impulse response filters (IIR) or FFT calculations, designed in C++. The signal processing blocks can be linked to perform the desired computations in the GNU Radio Companion (GRC) Graphical User Interface (GUI) or directly through the use of a programming language such as Python. GNU Radio provides a vast library of signal processing blocks that can easily be modified to custom specifications. GNU Radio is also published under the GNU General Public Licence (GPL), thus making it free to use and modify.
Installation¶
From my experience I found that the easiest way to get a USRP device up and running with Gnuradio is to use Marcus Leech installation script. It will install both the Ettus UHD software (to interface with the device) and Gnuradio from source. The other approach is to use Pybombs or to do it direcly from source, this is however abit more work. Marcus Leech script can be found here.
The Python Dicke-switching application presented does, however, require atlatest UHD build 3.8.5 in order to work. This due to the fact that the GPIO, on the Ettus X310, has only recently been exposed through swig. To update UHD and Gnuradio enter your UHD/Gnuradio directory and perform a git pull on the following repositories:
https://github.com/EttusResearch/uhd
https://github.com/gnuradio/gnuradio
Then perform the usual compile and install procedure. Alternatively navigate to http://files.ettus.com and download the approriate version. It is important to update UHD before Gnuradio in order for it to work otherwise GnuRadio will compile without UHD.
Updating the FPGA image¶
Different versions of UHD might require another FPGA image in order to function properly. This is also displayed when trying to initiate the device. To get the FPGA image that corresponds to the current running UHD simply run:
sudo uhd_images_downloader
Thereafter run:
uhd_image_loader --args="type=x300,resource=RIO0,fpga=HGS"
to burn the FPGA image to the device. The above command will automatically identify the correct FPGA image, however the possibility to specify the path also exist by simply providing the argument –fpga-path=”<path>”. If the command fails try instead to navigate to:
/usr/local/lib/uhd/utils
and run:
./usrp_x3xx_fpga_burner --type=HGS --resource=RIO0
to burn the FPGA image. The FPGA can also be loaded using JTAG see files.ettus.com/manual for more information.
Note on UHD and FPGA version¶
The impact on e.g. overflows as a function bandwidth has a notable dependance on UHD and the loaded FPGA image. I have found that several UHD versions will result in overflow at e.g. 120 MHz bandwidth using the PCIe interface whilst other do not. I have not yet been able to isolate the reason behind this but it as a important note. Currently the GNU Radio FFTS is operating on UHD version 3.9.1 with the corresponding FPGA image with no overflows at 120 MHz.
Interfacing with JTAG¶
The Ettus X310 has a JTAG interface that can be accessed using standard USB. This allows interfacing with several utilites such as the Xilinx design tool softwares. This also allows access to the FPGA temperature sensor which, at this time, is only exposed through this interface.


This page has the Polymer component called "socket-chat" in its HTML code. When a Normal user talks with you, its name will appear in the "Talking with" selector.


Click and Speak!!!
Processing...
Comments from VOICE PI
Click and Speak!!!
Processing...
Full Name
Email ID
PASSWORD
Read Me
You should include the enrollment audio file in the request body. The audio file should be at least 5 seconds long and no longer than 5 minutes. The minimum recommended amount of accumulated speech for enrollment, after removing silence, is 30 seconds. After accumulating 30 seconds of speech, the profile’s enrollment status is changed from enrolling to enrolled to indicate that it is ready for identification. In the case you wish to enroll using any amount of speech time, you should include the "shortAudio" parameter. It instructs the service to waive the recommended amount of audio limit needed for enrollment and accordingly the profile’s enrollment status is changed from enrolling to enrolled. When doing so you can send audio files starting 1-second-long but no longer than 5 minutes. Enrollment for speaker identification is text-independent, which means that there are no restrictions on what the speaker says in the audio. The speaker's voice is recorded, and a number of features are extracted to form a unique voiceprint.