How to load data into a model, edit it using a table view, use data as a model input, as a constant, show it in output and analyze results
var iframer = require('./iframer')
Constants and parameters¶
There're two ways you can use data blocks. The first is working with a data block as a model inner constant. That's basically a static value, used by the model somewhere else. It's not visible in the Preview mode, not visible in compiled binaries and hidden when the model is called as a function from another model.
Below we added a not really useful model with 2 data-constants and a formula that sums their values (click Run
to get results):
iframer('https://statsim.com/app/?a=%5B%7B%22b%22%3A%5B%7B%22n%22%3A%22x%22%2C%22sh%22%3Afalse%2C%22t%22%3A2%2C%22u%22%3Afalse%2C%22dims%22%3A%22%22%2C%22v%22%3A%225%22%7D%2C%7B%22n%22%3A%22y%22%2C%22sh%22%3Afalse%2C%22t%22%3A2%2C%22u%22%3Afalse%2C%22dims%22%3A%22%22%2C%22v%22%3A%2210%22%7D%2C%7B%22n%22%3A%22results%22%2C%22h%22%3Afalse%2C%22sh%22%3Atrue%2C%22t%22%3A1%2C%22v%22%3A%22x%20%2B%20y%22%7D%5D%2C%22mod%22%3A%7B%22n%22%3A%22Main%22%2C%22e%22%3A%22%22%2C%22s%22%3A1%2C%22m%22%3A%22deterministic%22%7D%2C%22met%22%3A%7B%22sm%22%3A1000%7D%7D%5D')
A lot of models are based on dynamic data, in other words data that changes in time and is used as input for a model.
To make a data block work as an input value for a model, select 'Use as model input' checkbox on bottom of the data block. When the block has such checkbox activated it appears in the preview and executable files. The model can also receive those values when called as a function (for example myModel(10) or myModel({x: 10}))
Let's change the previous example and make x
and y
input parameters. Now we can use the preview mode of our model to hide the inner logic and show only input fields we need.
iframer('https://statsim.com/app/?a=%5B%7B%22b%22%3A%5B%7B%22n%22%3A%22X%22%2C%22sh%22%3Afalse%2C%22t%22%3A2%2C%22u%22%3Atrue%2C%22dims%22%3A%22%22%2C%22v%22%3A%225%22%7D%2C%7B%22n%22%3A%22Y%22%2C%22sh%22%3Afalse%2C%22t%22%3A2%2C%22u%22%3Atrue%2C%22dims%22%3A%22%22%2C%22v%22%3A%2210%22%7D%2C%7B%22n%22%3A%22Result%22%2C%22h%22%3Afalse%2C%22sh%22%3Atrue%2C%22t%22%3A1%2C%22v%22%3A%22X%20%2B%20Y%22%7D%5D%2C%22mod%22%3A%7B%22n%22%3A%22Main%22%2C%22e%22%3A%22%22%2C%22s%22%3A1%2C%22m%22%3A%22deterministic%22%7D%2C%22met%22%3A%7B%22sm%22%3A1000%7D%7D%5D&preview=1')
The result is basically a program that sums two values when runned.
Data types¶
At the moment StatSim accepts such types: Boolean
, Integer
, Float
, String
, Category
. You can also define Objects
, Arrays
and Tensors
as
Scalar values are simply numbers and special cases such as Infinity
and NaN
.
Arrays are lists composed of other object like numbers, strings or arrays. There's a shorthand format for entering a simple array - using coma-separated values. StatSim automatically wraps it in brackets [ ]
. Use brackets if you need to create arrays of arrays. Valid arrays:
34, 2, 7, 1, 0, 7, 1
['bob', 'joe', 'rebecca']
Tensors are multi-dimensional structures needed for linear algebra expressions and complex neural networks. Internally they are still stored as a one-dimensional lists and entered in the same way. However to make them work each tensor should have dimensions specified.
Table editor¶
Starting from the 0.8.0 version of StatSim it's possible to view and edit data using a table editor. To activate it click the ▦
button just near the input field or in the to right corner of the app. By default the table works as a separate element, not connected to the data blocks. To save data or reload the table special buttons should be clicked Save changes
or Reload
. To automatically update values active Reactive Updates
switcher on top of the table element
Output¶
By default, data blocks are not displayed in the output. However sometimes it's useful to analyze not only generated values, but the data itself. To do that, select Show in output
checkbox on bottom of the datablock. If the data type is Array
StatSim processes data as time series providing some descriptive statistics.
Let's load Bitcoin price data for the last year. Click Run
to get output.
iframer('https://statsim.com/app/?a=%5B%7B%22b%22%3A%5B%7B%22n%22%3A%22Price%22%2C%22sh%22%3Atrue%2C%22t%22%3A2%2C%22u%22%3Afalse%2C%22dims%22%3A%22%22%2C%22v%22%3A%225895.3%2C5518.85%2C5733.9%2C5888.14%2C5767.68%2C5732.82%2C6140.53%2C6121.8%2C6447.67%2C6750.17%2C7030%2C7161.45%2C7387%2C7382.45%2C6958.21%2C7118.8%2C7458.79%2C7146.78%2C6570.31%2C6337%2C5857.32%2C6517.68%2C6598.77%2C7279%2C7843.94%2C7689.91%2C7776.94%2C8033.94%2C8238.2%2C8095.59%2C8230.69%2C8002.64%2C8201.46%2C8763.78%2C9326.59%2C9739.05%2C9908.23%2C9816.35%2C9916.54%2C10859.56%2C10895.01%2C11180.89%2C11616.85%2C11696.06%2C13708.99%2C16858.02%2C16057.14%2C14913.4%2C15036.96%2C16699.68%2C17178.1%2C16407.2%2C16531.08%2C17601.94%2C19343.04%2C19086.64%2C18960.52%2C17608.35%2C16454.72%2C15561.05%2C13857.14%2C14548.71%2C13975.44%2C13917.03%2C15745.26%2C15378.28%2C14428.76%2C14427.87%2C12629.81%2C13860.14%2C13412.44%2C14740.76%2C15134.65%2C15155.23%2C16937.17%2C17135.84%2C16178.49%2C14970.36%2C14439.47%2C14890.72%2C13287.26%2C13812.71%2C14188.78%2C13619.03%2C13585.9%2C11348.02%2C11141.25%2C11250.65%2C11514.92%2C12759.64%2C11522.86%2C10772.15%2C10839.83%2C11399.52%2C11137.24%2C11090.06%2C11407.15%2C11694.47%2C11158.39%2C10035%2C10166.51%2C9052.58%2C8827.63%2C9224.39%2C8186.65%2C6914.26%2C7700.39%2C7581.8%2C8237.24%2C8689.84%2C8556.61%2C8070.8%2C8891.21%2C8516.24%2C9477.84%2C10016.49%2C10178.71%2C11092.15%2C10396.63%2C11159.72%2C11228.24%2C10456.17%2C9830.43%2C10149.46%2C9682.38%2C9586.46%2C10313.08%2C10564.42%2C10309.64%2C10907.59%2C11019.52%2C11438.65%2C11479.73%2C11432.98%2C10709.53%2C9906.8%2C9299.28%2C9237.05%2C8787.16%2C9532.74%2C9118.27%2C9144.15%2C8196.9%2C8256.99%2C8269.33%2C7862.11%2C8196.02%2C8594.19%2C8915.9%2C8895.4%2C8712.89%2C8918.74%2C8535.89%2C8449.83%2C8138.34%2C7790.16%2C7937.2%2C7086.49%2C6844.32%2C6926.02%2C6816.74%2C7049.79%2C7417.89%2C6789.3%2C6774.75%2C6620.41%2C6896.28%2C7022.71%2C6773.94%2C6830.9%2C6939.55%2C7916.37%2C7889.23%2C8003.68%2C8357.04%2C8051.34%2C7890.15%2C8163.69%2C8273.74%2C8863.5%2C8917.6%2C8792.83%2C8938.3%2C9652.16%2C8864.09%2C9279%2C8978.33%2C9342.47%2C9392.03%2C9244.32%2C9067.71%2C9219.86%2C9734.67%2C9692.72%2C9826.6%2C9619.14%2C9362.53%2C9180.16%2C9306%2C9014.61%2C8406.17%2C8467.66%2C8688.03%2C8675.21%2C8474.24%2C8340.3%2C8058.6%2C8240.72%2C8234.15%2C8520.81%2C8395.23%2C7983.52%2C7502.56%2C7578.69%2C7460.69%2C7334.16%2C7344.97%2C7105.67%2C7460.58%2C7375.67%2C7487.19%2C7518.24%2C7636.19%2C7711.36%2C7490.59%2C7616.89%2C7655.98%2C7688%2C7616.1%2C7497.34%2C6765.8%2C6877.18%2C6548.33%2C6299.52%2C6637.74%2C6410.72%2C6485.87%2C6443.67%2C6709.48%2C6737.41%2C6758.38%2C6717.2%2C6053.9%2C6170.56%2C6150.19%2C6247.47%2C6074.92%2C6132.56%2C5848.26%2C6203.9%2C6387.31%2C6347.86%2C6613.27%2C6504.93%2C6584.77%2C6531.2%2C6600.99%2C6755.56%2C6704.18%2C6664.21%2C6302.49%2C6381.87%2C6245.63%2C6217.61%2C6247.23%2C6349.04%2C6726.4%2C7314.94%2C7378.76%2C7470.82%2C7330.54%2C7404.29%2C7396.29%2C7717.5%2C8397.63%2C8166.76%2C7929.61%2C8183.02%2C8229.96%2C8215.56%2C8168%2C7726.89%2C7603.75%2C7535.02%2C7415.56%2C7009.09%2C7026.99%2C6937.07%2C6717.21%2C6280.58%2C6537.9%2C6143.3%2C6233.38%2C6312.83%2C6252.37%2C6192.31%2C6270.04%2C6314.24%2C6583.24%2C6395.35%2C6485.75%2C6256.61%2C6477.38%2C6357.59%2C6525.61%2C6692.62%2C6732.5%2C6707.63%2C6907.66%2C7076.74%2C7035.81%2C6982.4%2C7013.97%2C7192.3%2C7295.13%2C7261.49%2C7358.5%2C6687.01%2C6498.62%2C6396.27%2C6183.38%2C6238.54%2C6305.57%2C6282.92%2C6328.93%2C6486.62%2C6492.37%2C6515.9%2C6497.37%2C6251.16%2C6334.2%2C6388.98%2C6491.64%2C6753.18%2C6712.17%2C6701.3%2C6581.51%2C6434.65%2C6458.65%2C6684.13%2C6621.66%2C6583.77%2C6606.08%2C6578.79%2C6506.66%2C6470.71%2C6555.87%2C6589.4%2C6563.42%2C6582.4%2C6622.4%2C6606.88%2C6550.73%2C6177.23%2C6211.67%2C6227.51%2C6222.21%2C6513.38%2C6531.36%2C6514.64%2C6450.78%2C6418.85%2C6455.48%2C6453.82%2C6448.1%2C6443.15%22%7D%5D%2C%22mod%22%3A%7B%22n%22%3A%22BTC%20Price%22%2C%22e%22%3A%22%22%2C%22s%22%3A1%2C%22m%22%3A%22deterministic%22%7D%2C%22met%22%3A%7B%22sm%22%3A1000%7D%7D%5D&preview=1')
Data size¶
The latest version of StatSim uses Web Workers to run the models. The model code is isolated from the main document and don't make it freeze when processed. The drawback is a smaller stack size in the worker process (details..). That's not a problem when doing simulations, but processing big arrays causes a recursion error.
If you really need to process huge amounts of data instead of doing simulations, use Analyze.li, free open-source app for data processing and analysis.