text:
# Installing software using CONDA

We are going to install all our software using conda and bioconda. First, we need to install conda:

## Download conda

Head to the [miniconda download page](https://docs.conda.io/en/latest/miniconda.html) and download the appropriate installer.

You want the one from _Latest Miniconda Installer Links_. Get:

 - **Linux Installer**
 - **Python** with the biggest number
 - **Miniconda3 Linux 64-bit**

Here is a quick way to download that script!

Right click on the appropriate link, and choose *Copy link address*. Go back to your terminal window (probably Putty) and type `wget` and a space, and then paste the URL that you just copied. Press return and it should download the file for you!

The file should be called `Miniconda3-latest-Linux-x86_64.sh` but in case it is not, just substitute the appropriate file name below. Remember that you can check with `ls -ltr` to see the newest file downloaded.

Run the miniconda installer:

```bash
bash Miniconda3-latest-Linux-x86_64.sh
```

This will ask you some questions, and you can pretty much accept the default answer to all the questions.

Once the installer has finished the best way to continue is to log out, and then log back in. This will reset your account and you will have conda activated. At the bottom left of your screen you should see it say `(base)` which means that you are in the base conda installation.

### `Conda` is great, but `Mamba` is better!

[Mamba](https://github.com/mamba-org/mamba) is a drop in replacement for conda, and it is the first thing we will install.

```bash
conda install -c conda-forge mamba
```

This will take a moment to set everything up and figure out what needs to be installed, and then ask you if you are sure.

Type `yes` and press return and `mamba` will be installed. From here on out, forget conda and think mamba!

## Install your first bioinformatics package

We are going to install `fastp` and test to see if it works. This will demonstrate how to install a conda package.

```bash
mamba install -c conda-forge -c bioconda fastp
```

Again, this will work on resolution of the packages for you and ask if you are sure. Once it is complete, you should be able to issue the command:

```bash
fastp -v
```

to see the version of `fastp` that has been installed.

You can also run

```bash
fastp -h
```

To get the full `fastp` help menu

## Install snakemake

For the next steps of this tutorial, we are going to use [snakemake](https://snakemake.readthedocs.io/en/stable/) to run some software. So we are going to use `mamba` to install that:

```bash
mamba install -c conda-forge -c bioconda snakemake
```

Once that has completed, `snakemake -v` should show you the current version.

## Install other bioinformatics packages

You can install pretty much any bioinformatics package using conda. The [anaconda website has a complete list](https://anaconda.org/bioconda/repo) and you can visit the [bioconda](https://bioconda.github.io/) page for more information about bioconda.

but to get started, you might want to install:

```bash
mamba install -c conda-forge -c bioconda fastp minimap2 samtools
```

## Adding channels

It is a pain to keep typing `-c conda-forge -c bioconda` so we can just add those two channels to our configuration

```bash
conda config --add channels conda-forge
conda config --add channels bioconda
```

## Updating a package

With `conda` (or `mamba`) you can easily update a package if there is a newer version. For example, to update `snakemake` you would use:

```bash
mamba update snakemake
```

What this means is the _you_ are responsible for ensuring your software is up-to-date. Or not. If you are working on a set of data analyses you may want to keep all the software at the same version so that each time you do an analysis you get comparable answers. With `conda`, you have control over the update cycles, but don't forget from time-to-time you might want to update the software!

## Environments

If you want to keep different versions of software or run different pipelines you can do that with conda, in what are called `environments`. Each one can have different software. `conda` is clever, because if you have the same software in two different environments you don't need an entire copy of the software. At this stage, you don't need to worry about that, and you can just install everything in the `base` environment. But if you start to run into installation issues, then remember you can separate things into different environments.

repository: linsalrob/ComputationalGenomicsManual

gha_language: Shell

repo_name: linsalrob/ComputationalGenomicsManual


text:
Attending: Scott, Alex, Jörn, Rafael, Kris, Sarah

## Core
* Releasing 3.0.0 alpha today

## UI
* [Splitting up UI and Effects Core into several files](https://github.com/jquery/jquery-ui/pull/1569)
* [Switching to AMD for demos](https://github.com/jquery/jquery-ui/pull/1557)
  * [jqueryui.com updates](https://github.com/jquery/jqueryui.com/pull/113)

## Mobile
* Fix remaining 1.5 issues.
* landed a lot of PRs
* Closing issues for 1.5 triaging remaining
* Update css for style guide
* Landing remaining classes PRs
* Finishing new enhancer module updates

## Chassis
* A lot of interest at the conference, some PRs and Issues commented on as a result
* Good progress on ThemeRoller
* JSASS is almost ready to land, will allow SASS variables to be accessible via the JS in the themeroller

## QUnit
* [Working on splitting core module](https://github.com/jquery/qunit/pull/785#issuecomment-113143354)
* Working on js-reporters, finalising [proposal for event data](https://docs.google.com/document/d/1E9X90ODgnMW8bTssIAkfRIQiGX0n0FaGI1vk3geviIs/edit) to request feedback on that
* [Working on adapters](https://github.com/fcarstens/js-test-examples), will try them within browserstack-runner soon

## PEP
* Working on full W3C test automation
  * Submitting tests to W3C when we find holes
  * Sparked a discussion in W3C about using WebDriver

## Globalize
* Twitter follow up: Rafael sent them an integration demo using their stack (i.e., webpack): https://github.com/rxaviers/yarsk/tree/react-globalize

license: MIT

branch_name: refs/heads/main

extension: md

gha_language: JavaScript

gha_license_id: NOASSERTION

license_type: permissive


text:
# Contributing Guide

Contributions are welcome, and greatly appreciated!
We recommend you to check our [Developer Tools Guide](#developer-tools-guide)
to make the development process easier and standard.

Notably, you can follow the tag of [call for contributors](https://github.com/keras-team/autokeras/labels/call%20for%20contributors) in the issues.
Those issues are designed for the external contributors to solve.
The pull requests solving these issues are most likely to be merged.

There are many ways to contribute to AutoKeras,
including submit feedback, fix bugs, implement features, and write documentation.
The guide for each type of contribution is as follows.

#### Submit Feedback
The feedback should be submitted by creating an issue at [GitHub issues](https://github.com/keras-team/autokeras/issues).
Select the related template (bug report, feature request, or custom) to write the details of the feedback.

#### Fix Bugs:
You may look through the [GitHub issues](https://github.com/keras-team/autokeras/issues) for bugs.
Anything tagged with "bug report" is open to whomever wants to fix.
Please follow the
[Pull Request Guide](#pull-request-guide) to submit your pull request.
Please also read
[Code Style Guide](#code-style-guide),
to ensure your pull request meet our requirements.

#### Implement Features
You may look through the [GitHub issues](https://github.com/keras-team/autokeras/issues) for feature requests.
Anything tagged with "feature request" is open to whoever wants to implement it.
Unit tests are needed to test the new feature implemented and fully cover the new code you wrote.
Please follow the
[Pull Request Guide](#pull-request-guide) to submit your pull request.
Please also read
[Code Style Guide](#code-style-guide),
to ensure your pull request meet our requirements.

#### Write Documentation
The documentation of AutoKeras is either directly written into the Markdown files in
[templates directory](https://github.com/keras-team/autokeras/tree/master/docs/templates),
or automatically extracted from the docstrings by executing the [autogen.py](https://github.com/keras-team/autokeras/blob/master/docs/autogen.py).
Please follow the
[Pull Request Guide](#pull-request-guide) to submit your pull request.
Please also read
[Code Style Guide](#code-style-guide).

## Pull Request Guide
Before you submit a pull request, check that it meets these guidelines:

1. Is this the first pull request that you're making with GitHub? If so, read the guide [Making a pull request to an open-source project](https://github.com/gabrieldemarmiesse/getting_started_open_source).

2. Include "resolves #issue_number" in the description of the pull request if applicable and briefly describe your contribution.

3. Submit the pull request from the first day of your development and create it as a [draft pull request](https://github.blog/2019-02-14-introducing-draft-pull-requests/). Click `ready for review` when finished and passed the all the checks.

4. For the case of bug fixes, add new test cases which would fail before your bug fix.

## Code Style Guide
1. Your code should pass the `flake8` check.
2. Docstrings should follow our style.
3. Imports should follow our style.
For "our style", just check the code of AutoKeras.

## Developer Tools Guide
We highly recommend you to use [Pycharm](https://www.jetbrains.com/pycharm/)
and [virtualenvwrapper](https://virtualenvwrapper.readthedocs.io/en/latest/)
as well as a pre-commit hook.

### Visual Studio Code
We suggest using Visual Studio Code (VSCode) to develop for AutoKeras. It can automatically format your code, sort your imports, mark any code style violations, generate docstrings according to our format for you. Check VSCode configuration [here](https://gist.github.com/jhfjhfj1/68714194e2faa6fb81c53eea59779458).

### virtualenv
Use [virtualenv](https://virtualenv.pypa.io/en/latest/) to create a isolated Python environment for AutoKeras project to avoid dependency version conflicts with your other projects.
[Virtualenvwrapper](https://virtualenvwrapper.readthedocs.io/en/latest/) is a even simpler command-line tool to manage multiple virtualenvs.

### pre-commit hook
You can make git run `flake8` before every commit automatically. It will make you go faster by
avoiding pushing commit which are not passing the flake8 tests. To do this,
open `.git/hooks/pre-commit` with a text editor and write `flake8` inside. If the `flake8` doesn't
pass, the commit will be aborted.

## Main Contributor List
We really appreciate all the contributions.
To show our appreciation to those who contributed most,
we would like to maintain a list of main contributors.
To be in the list, you need to meet the following requirments.
1. Be on campus of Texas A&M University.
2. Constantly present in our meetings.
3. Constantly contribute code to our repository.
4. Keep the above for over 6 months.

branch_name: refs/heads/master

gha_license_id: MIT


text:
Ensembl Variation Deprecated Methods
===================

This file contains the list of methods deprecated in the Ensembl Variation API. A method is deprecated when it is not functional anymore (schema/data change) or has been replaced by a better one. Backwards compatibility is provided whenever possible. When a method is deprecated, a deprecation warning is thrown whenever the method is used. The warning also contains instructions on replacing the deprecated method and when it will be removed. A year after deprecation (4 Ensembl releases), the method is removed from the API.

### Removed in Ensembl Release 101 (deprecated from Ensembl Release 95) ###
- Bio::EnsEMBL::Variation::**VariationFeature**::*add_consequence_type()*
- Bio::EnsEMBL::Variation::**VariationFeature**::*get_consequence_type()*

### Removed in Ensembl Release 100 (deprecated from Ensembl Release 96) ###
- Bio::EnsEMBL::**Variation**::*ancestral_allele()*

### Removed in Ensembl Release 98 ###
- Bio::EnsEMBL::Variation::**OverlapConsequence**::*get_all_parent_SO_terms()*

### Removed in Ensembl Release 91 (deprecated from Ensembl Release 87) ###
- Bio::EnsEMBL::Variation::Utils::**Sequence**::*array_to_bitval()*
- Bio::EnsEMBL::Variation::Utils::**Sequence**::*bitval_to_array()*

### Removed in Ensembl Release 89 (deprecated from Ensembl Release 85) ###
- Bio::EnsEMBL::Variation::DBSQL::**PopulationAdaptor**::*fetch_tagged_Population()*
- Bio::EnsEMBL::Variation::DBSQL::**PopulationAdaptor**::*fetch_tag_Population()*
- Bio::EnsEMBL::Variation::DBSQL::**VariationFeatureAdaptor**::*fetch_all_tagged_by_VariationFeature()*
- Bio::EnsEMBL::Variation::DBSQL::**VariationFeatureAdaptor**::*fetch_all_tags_by_VariationFeature()*
- Bio::EnsEMBL::Variation::DBSQL::**VariationFeatureAdaptor**::*fetch_all_tags_and_tagged_by_VariationFeature()*
- Bio::EnsEMBL::Variation::**VariationFeature**::*is_tag()*
- Bio::EnsEMBL::Variation::**VariationFeature**::*is_tagged()*
- Bio::EnsEMBL::Variation::**VariationFeature**::*get_all_tag_VariationFeatures()*
- Bio::EnsEMBL::Variation::**VariationFeature**::*get_all_tagged_VariationFeatures()*
- Bio::EnsEMBL::Variation::**VariationFeature**::*get_all_tag_and_tagged_VariationFeatures()*

### Removed in Ensembl Release 87 (deprecated from Ensembl Release 83) ###

#### Deprecated methods related to the validation_status data:####
- Bio::EnsEMBL::Variation::**Variation**::*get_all_validation_states()*
- Bio::EnsEMBL::Variation::**Variation**::*add_validation_state()*
- Bio::EnsEMBL::Variation::**VariationFeature**::*get_all_validation_states()*
- Bio::EnsEMBL::Variation::**VariationFeature**::*add_validation_state()*
- Bio::EnsEMBL::Variation::Utils::**Sequence**::*get_all_validation_states()*
- Bio::EnsEMBL::Variation::Utils::**Sequence**::*get_validation_code()*
- Bio::EnsEMBL::Variation::Utils::**Sequence**::*add_validation_state()*

#### Deprecated method source_object() in various objects:####
- Bio::EnsEMBL::Variation::**Variation**::*source_object()*
- Bio::EnsEMBL::Variation::**VariationFeature**::*source_object()*
- Bio::EnsEMBL::Variation::**PhenotypeFeature**::*source_object()*
- Bio::EnsEMBL::Variation::**BaseStructuralVariation**::*source_object()*
- Bio::EnsEMBL::Variation::**StructuralVariationFeature**::*source_object()*
- Bio::EnsEMBL::Variation::**Study**::*source_object()*

repository: Ensembl/ensembl-variation

gha_language: Perl

repo_name: Ensembl/ensembl-variation


text:
### [CVE-2017-11317](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-11317)
![](https://img.shields.io/static/v1?label=Product&message=n%2Fa&color=blue)
![](https://img.shields.io/static/v1?label=Version&message=n%2Fa&color=blue)
![](https://img.shields.io/static/v1?label=Vulnerability&message=n%2Fa&color=brighgreen)

### Description

Telerik.Web.UI in Progress Telerik UI for ASP.NET AJAX before R1 2017 and R2 before R2 2017 SP2 uses weak RadAsyncUpload encryption, which allows remote attackers to perform arbitrary file uploads or execute arbitrary code.

### POC

#### Reference
- http://packetstormsecurity.com/files/159653/Telerik-UI-ASP.NET-AJAX-RadAsyncUpload-Deserialization.html
- https://www.exploit-db.com/exploits/43874/

#### Github
- https://github.com/0xT11/CVE-POC
- https://github.com/ARPSyndicate/cvemon
- https://github.com/SABUNMANDICYBERTEAM/telerik
- https://github.com/ThanHuuTuan/CVE_2019_18935
- https://github.com/alphaSeclab/sec-daily-2019
- https://github.com/bao7uo/RAU_crypto
- https://github.com/bao7uo/dp_crypto
- https://github.com/developer3000S/PoC-in-GitHub
- https://github.com/hectorgie/PoC-in-GitHub
- https://github.com/lnick2023/nicenice
- https://github.com/mcgyver5/scrap_telerik
- https://github.com/qazbnm456/awesome-cve-poc
- https://github.com/vinhjaxt/telerik-rau
- https://github.com/xbl3/awesome-cve-poc_qazbnm456

repository: trickest/cve

gha_language: HTML

repo_name: trickest/cve


text:
# How to update favicons

Apps icons are designed with Photoshop thanks to [Pixel Resort's](http://appicontemplate.com/ios8) App Icon Template.

Once exported, the *iTunesArtwork@2x* is uploaded to [http://realfavicongenerator.net/](http://realfavicongenerator.net/) in order to generate all different sizes and html code.

repository: bcldvd/workouts

repo_name: bcldvd/workouts


text:
---
title: update_nba_db
sidebar_label: update_nba_db
---

Update or create a hoopR play-by-play database

## Description

`update_nba_db()` updates or creates a database with `hoopR`
play by play data of all completed and available games since 2002.

## Usage

```r
update_nba_db(
  dbdir = ".",
  dbname = "hoopR_db",
  tblname = "hoopR_nba_pbp",
  force_rebuild = FALSE,
  db_connection = NULL
)
```

## Arguments

Argument      |Description
------------- |----------------
`dbdir`     |     Directory in which the database is or shall be located
`dbname`     |     File name of an existing or desired SQLite database within `dbdir`
`tblname`     |     The name of the play by play data table within the database
`force_rebuild`     |     Hybrid parameter (logical or numeric) to rebuild parts of or the complete play by play data table within the database (please see details for further information)
`db_connection`     |     A `DBIConnection` object, as returned by [`DBI::dbConnect()`](dbi::dbconnect()) (please see details for further information)

## Details

This function creates and updates a data table with the name `tblname`
within a SQLite database (other drivers via `db_connection`) located in
`dbdir` and named `dbname`.

The data table combines all play by play data for every available game back
to the 2002 season and adds the most recent completed games as soon as they
are available for `hoopR` .

The argument `force_rebuild` is of hybrid type. It can rebuild the play
by play data table either for the whole hoopR era (with `force_rebuild = TRUE` )
or just for specified seasons (e.g. `force_rebuild = c(2019, 2020)`).

Please note the following behavior:

*  `force_rebuild = TRUE`: The data table with the name `tblname` will be removed completely and rebuilt from scratch. This is helpful when new columns are added during the Off-Season.

*  `force_rebuild = c(2019, 2020)` The data table with the name `tblname` will be preserved and only rows from the 2019 and 2020 seasons will be deleted and re-added. This is intended to be used for ongoing seasons because ESPN's data provider can make changes to the underlying data during the week.

The parameter `db_connection` is intended for advanced users who want
to use other DBI drivers, such as MariaDB, Postgres or odbc. Please note that
the arguments `dbdir` and `dbname` are dropped in case a `db_connection`
is provided but the argument `tblname` will still be used to write the
data table into the database.

repository: mrcaseb/hoopR

repo_name: mrcaseb/hoopR


text:
# Section1 - DataGrid

Display sales records on a DataGrid conrtol to see the data to be analyzed & visualized in this lab.

## Steps
1. [Get started with XamDataGrid](01-01-Get-started-with-XamDataGrid.md)
1. [Configure XamDataGrid](01-02-Configure-XamDataGrid.md)

## What you build in this section

![](../assets/01-02-01.png)

## Next

[01-01 Get started with XamDataGrid](01-01-Get-started-with-XamDataGrid.md)


text:
---
title: MQTT Statestream
description: Instructions on how to setup MQTT Statestream within Open Peer Power.
logo: mqtt.png
ha_category:
  - Other
ha_release: 0.54
ha_iot_class: Configurable
ha_domain: mqtt_statestream
excerpt: none
---

The `mqtt_statestream` integration publishes state changes in Open Peer Power to individual MQTT topics.

## Configuration

To enable MQTT Statestream in Open Peer Power, add the following section to your `configuration.yaml` file:

```yaml
# Example configuration.yaml entry
mqtt_statestream:
  base_topic: openpeerpower
  publish_attributes: true
  publish_timestamps: true
```

## Operation

When any Open Peer Power entity changes, this integration will publish that change to MQTT.

The topic for each entity is different, so you can easily subscribe other systems to just the entities you are interested in.
The topic will be in the form `base_topic/domain/entity/state`.

For example, with the example configuration above, if an entity called 'light.master_bedroom_dimmer' is turned on, this integration will publish `on` to `openpeerpower/light/master_bedroom_dimmer/state`.

If that entity also has an attribute called `brightness`, the integration will also publish the value of that attribute to `openpeerpower/light/master_bedroom_dimmer/brightness`.

All states and attributes are passed through JSON serialization before publishing. **Please note** that this causes strings to be quoted (e.g., the string 'on' will be published as '"on"'). You can access the JSON deserialized values (as well as unquoted strings) at many places by using `value_json` instead of `value`.

The last_updated and last_changed values for the entity will be published to `openpeerpower/light/master_bedroom_dimmer/last_updated` and `openpeerpower/light/master_bedroom_dimmer/last_changed`, respectively. The timestamps are in ISO 8601 format - for example, `2017-10-01T23:20:30.920969+00:00`.

## Include/exclude

The **exclude** and **include** configuration variables can be used to filter the items that are published to MQTT.

1\. If neither **exclude** or **include** are specified, all entities are published.

2\. If only **exclude** is specified, then all entities except the ones listed are published.

```yaml
# Example of excluding entities
mqtt_statestream:
  base_topic: openpeerpower
  exclude:
    domains:
      - switch
    entities:
      - sensor.nopublish
```
In the above example, all entities except for *switch.x* and *sensor.nopublish* will be published to MQTT.

3\. If only **include** is specified, then only the specified entries are published.

```yaml
# Example of excluding entities
mqtt_statestream:
  base_topic: openpeerpower
  include:
    domains:
      - sensor
    entities:
      - lock.important
```
In this example, only *sensor.x* and *lock.important* will be published.

4\. If both **include** and **exclude** are specified then all entities specified by **include** are published except for the ones
specified by **exclude**.

```yaml
# Example of excluding entities
mqtt_statestream:
  base_topic: openpeerpower
  include:
    domains:
      - sensor
  exclude:
    entities:
      - sensor.noshow
```
In this example, all sensors except for *sensor.noshow* will be published.

extension: markdown


text:
## v1.3.6:

* teach userdefaults how to cope with hashes (via Ben Bleything)
* move changes from README.md to CHANGELOG.md

## v1.3.4:

* delete the *lockfile* not the *plist*

## v1.3.2:

* typo in `updated_by_last_action` - http://troll.me?p=32 :)

## v1.3.0:

* Issue 4 - action create should set `updated_by_last_action`
* Issue 5 - remove lockfile before updating plist

## v1.2.2:

* tweaks to userdefaults provider by Ben Bleything. Thanks Ben!
* ensure lion tweaks only runs on lion
* use strings not integers
* move mail tweaks to their own recipe
* add mail archive hotkey

## v1.2.0:

* add `plist_file` LWRP
* add recipes for managing various useful user defaults

repository: joemiller/workstation-bootstrap

repo_name: joemiller/workstation-bootstrap


text:
# Specifications
Specification pattern composer package

## Composer:

- {
    "require": {
        "malots/specifications": "dev-master"
    }
  }

## Installation:

- composer require "malots/specifications:dev-master"

## Example:

- Check the units tests project

## Reference:

- This package is based on this article -> https://en.wikipedia.org/wiki/Specification_pattern

repository: leovene/Specifications

repo_name: leovene/Specifications


text:
# windows_ipv6

A Puppet module for configuring ipv6 settings in Windows.

# Usage

Typical usage:

    include '::windows_ipv6'

This will "Prefer ipv4 to ipv6"

See $disabled_components_value in init.pp for possible values to pass to the
class.


text:
---
title: Easy | Meeting Rooms
tags:
  - common
  - tricky
categories:
  - Leetcode
  - Greedy
date: 2020-07-21 20:18:05
---

Given an array of meeting time intervals consisting of start and end times `[[s1,e1],[s2,e2],...]` (si < ei), determine if a person could attend all meetings.

[Leetcode](https://leetcode.com/problems/meeting-rooms/)

<!--more-->

**Example 1:**

```
Input: [[0,30],[5,10],[15,20]]
Output: false
```

**Example 2:**

```
Input: [[7,10],[2,4]]
Output: true
```

**Follow up:**

[Meeting Rooms II](https://leetcode.com/problems/meeting-rooms-ii/)

---

#### Standard solution

This is a typical *Greedy* problem about **Interval grouping**

```java
class Solution {
    public boolean canAttendMeetings(int[][] ranges) {
        if (ranges == null || ranges.length == 0) return true;
        int n = ranges.length;

        Arrays.sort(ranges, (a, b) -> a[0] - b[0]);

        int end = -1;
        for (int i = 0; i < n; i++) {
            if (end == -1 || end <= ranges[i][0]) {
                end = ranges[i][1];
            } else {
                return false;
            }
        }
        return true;
    }
}
```

T: O(nlong)		S: O(1)

repository: weiranfu/leetcode-with-me

gha_language: Python

repo_name: weiranfu/leetcode-with-me


text:
# Business Analytics: Marketing and Decisions
### 1. Cosmetics Purchases
The data shown in Table 14.14 and the output in Table 14.15 are
based on a subset of a dataset on cosmetic purchases (Cosmetics.csv) at a large chain
drugstore.
The store wants to analyze associations among purchases of these items for purposes of
point-of-sale display, guidance to sales personnel in promoting cross-sales, and guidance
for piloting an eventual time-of-purchase electronic recommender system to boost crosssales. Consider first only the data shown in Table 14.14, given in binary matrix form.

### 2. Course ratings.
The Institute for Statistics Education at Statistics.com asks students to
rate a variety of aspects of a course as soon as the student completes it. The Institute is
contemplating instituting a recommendation system that would provide students with
recommendations for additional courses as soon as they submit their rating for a
completed course. Consider the excerpt from student ratings of online statistics courses
shown in Table 14.16, and the problem of what to recommend to student E.N.

### 3. Clustering
Use the “movieLens.txt” data in Lecture 3 and perform cluster analysis of the
1664 non-duplicate movies.

License
----

MIT

**Free Software, Hell Yeah!**

[//]: # (These are reference links used in the body of this note and get stripped out when the markdown processor does its job. There is no need to format nicely because it shouldn't be seen. Thanks SO - http://stackoverflow.com/questions/4823468/store-comments-in-markdown-syntax)

   [dill]: <https://github.com/joemccann/dillinger>
   [git-repo-url]: <https://github.com/joemccann/dillinger.git>
   [john gruber]: <http://daringfireball.net>
   [df1]: <http://daringfireball.net/projects/markdown/>
   [markdown-it]: <https://github.com/markdown-it/markdown-it>
   [Ace Editor]: <http://ace.ajax.org>
   [node.js]: <http://nodejs.org>
   [Twitter Bootstrap]: <http://twitter.github.com/bootstrap/>
   [jQuery]: <http://jquery.com>
   [@tjholowaychuk]: <http://twitter.com/tjholowaychuk>
   [express]: <http://expressjs.com>
   [AngularJS]: <http://angularjs.org>
   [Gulp]: <http://gulpjs.com>

   [PlDb]: <https://github.com/joemccann/dillinger/tree/master/plugins/dropbox/README.md>
   [PlGh]: <https://github.com/joemccann/dillinger/tree/master/plugins/github/README.md>
   [PlGd]: <https://github.com/joemccann/dillinger/tree/master/plugins/googledrive/README.md>
   [PlOd]: <https://github.com/joemccann/dillinger/tree/master/plugins/onedrive/README.md>
   [PlMe]: <https://github.com/joemccann/dillinger/tree/master/plugins/medium/README.md>
   [PlGa]: <https://github.com/RahulHP/dillinger/blob/master/plugins/googleanalytics/README.md>

repository: mulderfang/Movie-catagory-analysis

repo_name: mulderfang/Movie-catagory-analysis


text:
# Viegasia Bat. GENUS

#### Status
ACCEPTED

#### According to
The Catalogue of Life, 3rd January 2011

#### Published in
Bol. Secr. Agric. (Pernambuco) 18: 32 (1951)

#### Original name
Viegasia Bat.

### Remarks
null

repository: mdoering/backbone

repo_name: mdoering/backbone


text:
# lita-simpsonssearch

[![Build Status](https://travis-ci.org/jaxxstorm/lita-simpsonssearch.png?branch=master)](https://travis-ci.org/jaxxstorm/lita-simpsonssearch)
[![Coverage Status](https://coveralls.io/repos/jaxxstorm/lita-simpsonssearch/badge.png)](https://coveralls.io/r/jaxxstorm/lita-simpsonssearch)

Searches [Frinkiac](https://frinkiac.com/) for a quote from The Simpsons

## Installation

Add lita-simpsonssearch to your Lita instance's Gemfile:

``` ruby
gem "lita-simpsonssearch"
```

## Configuration

None. Should just work

## Usage

```
Lita: simpsons search fail english, that's unpossible
Lita: simpsons me nothing at all
```

## License
[MIT](http://opensource.org/licenses/MIT)

repository: jaxxstorm/lita-simpsonssearch

gha_language: Ruby

repo_name: jaxxstorm/lita-simpsonssearch


text:
# gitpod-gui-example

This is a example that is shown the Gui application in Gitpod. (using gitpod-full-vnc docker file)

[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/devlights/gitpod-gui-example)

## Run

```sh
$ make run
```

repository: devlights/gitpod-gui-example

repo_name: devlights/gitpod-gui-example


text:
# slack-theme
Setting theme of slack

## Installing into Slack application directory based on OS

## For Mac users,

* `cd` into `/Applications/Slack.app/Contents/` directory
* If you have `wget` installed in your machine, run below command -
  `wget -q -O - https://raw.githubusercontent.com/iamshreeram/slack-theme/master/customizer.js >> /Resources/app.asar.unpacked/src/static/ssb-interop.js`
* Restart your `slack`
* If you don't have `wget`,
  * Copy the content of `https://raw.githubusercontent.com/iamshreeram/slack-theme/master/customizer.js`
  * Paste it to the last line of `/Resources/app.asar.unpacked/src/static/ssb-interop.js`

## For Windows or Linux users,
* Only the base slack installation directory will vary. Other steps would remain same.
* Debian based Linux Users, Find: `/usr/lib/slack/` (Debian-based)
* Windows: `%homepath%\AppData\Local\slack\`
* We are working on updating further steps. Stay tuned.

## Note
* This script works only for SLACK Version 3.x.x

repository: iamshreeram/slack-theme

gha_language: CSS

repo_name: iamshreeram/slack-theme


text:
---
title: Language
path: /en/docs/draft/settings/locale
setting: locale
---

This determines the language used on your pattern.

By default, we use the same language as you're using on the website, but if for
some reason you want a pattern in a different language, this is where to configure that.

repository: freesewing-bot/website

branch_name: refs/heads/develop

repo_name: freesewing-bot/website


text:
# AutoPPL
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors)
<!-- ALL-CONTRIBUTORS-BADGE:END -->
[![Build Status](https://travis-ci.org/JamesYang007/autoppl.svg?branch=master)](https://travis-ci.org/JamesYang007/autoppl)
[![Coverage Status](https://coveralls.io/repos/github/JamesYang007/autoppl/badge.svg?branch=master)](https://coveralls.io/github/JamesYang007/autoppl?branch=master)

## Table of Contents

- [Overview](#overview)
    - [Who should use AutoPPL?](#who-should-use-autoppl)
    - [How is AutoPPL different from existing PPLs like STAN and PyMC3?](#how-is-autoppl-different-from-existing-ppls-like-stan-and-pymc3)
- [Design Choices](#design-choices)
    - [Intuitive Model Specification](#intuitive-model-specification)
    - [Efficient Memory Usage](#efficient-memory-usage)
    - [High-performance Inference Methods](#high-performance-inference-methods)
- [Installation](#installation)
- [Quick Guide](#quick-guide)
    - [Variable](#variable)
    - [Variable Expression](#variable-expression)
    - [Constraint](#constraint)
    - [Distribution Expression](#distribution-expression)
    - [Model Expression](#model-expression)
    - [Transformed Parameters](#transformed-parameters)
    - [Program Expression](#program-expression)
    - [Sampling Algorithms](#sampling-algorithms)
- [Examples](#examples)
    - [Sampling from Joint Distribution](#sampling-from-joint-distribution)
    - [Sampling Posterior Mean and Standard Deviation](#sampling-posterior-mean-and-standard-deviation)
    - [Bayesian Linear Regression](#bayesian-linear-regression)
    - [Stochastic Volatility](#stochastic-volatility)
- [Benchmarks](#benchmarks)
    - [Bayesian Linear Regression](#benchmarks-bayesian-linear-regression)
    - [Gaussian Model](#gaussian-model)
- [Contributors](#contributors)
- [Third Party Tools](#third-party-tools)

## Overview

AutoPPL is a C++ template library providing high-level support for probabilistic programming.
Using operator overloading and expression templates, AutoPPL provides a
generic framework for specifying probabilistic models and applying inference algorithms.

The library is still at an experimental stage.

### Who should use AutoPPL?

The goal of this project is to provide a framework for practitioners, students, and researchers.
It is often desired to have a framework for specifying a probabilistic model separate from any inference algorithms.
While AutoPPL does provide a few inference algorithms such as NUTS and Metropolis-Hastings,
it allows users to write their _own_ sampling algorithms and even add new distributions.

### How is AutoPPL different from existing PPLs like STAN and PyMC3?

AutoPPL can be thought of as a hybrid of STAN and PyMC3.
It is similar to STAN in that it is extremely optimized for high performance (see [Benchmarks](#benchmarks))
and it uses much of the same logic discussed in the STAN reference guide.
It is similar to PyMC3 in that it is a library rather than a separate domain-specific language.

However, it is unique in that it is purely a C++ library.
While STAN requires the user to write STAN code, which gets translated into C++ code by the STAN compiler
and then compiled into a binary, AutoPPL just requires the user to directly write C++ code.
Some benefits include the following:
- eliminates the extra layer of abstraction to a separate domain-specific language
- users can use native C++ tools to clean and prepare data, and also examine the posterior samples
- easily extend the library such as adding new distributions or a sampling algorithm

In the future, we plan to provide Python and R bindings such that
the user can write a C++ function using AutoPPL that defines and samples from the model
and export the Python/R binding to examine the posterior samples using a more comfortable, scripting language.

## Design Choices

### Intuitive Model Specification

In Bayesian statistics, the first step in performing probabilistic inference is to
specify a generative model for the data of interest. For example, in mathematical notation,
a Gaussian model could look like the following:
```
X ~ Normal(theta, I)
theta ~ Uniform(-1, 1)
```

Given its simplicity and expressiveness, we wanted to mimic this compact notation as much
as possible for users of our library.
For the model specified above, the code in AutoPPL could look like the following:
```cpp
Data<double, vec> X({...});   // load data
Param<double> theta;          // define scalar parameter
auto model = (                // specify model
    theta |= uniform(-1., 1.),
    X |= normal(theta, 1.)
);
```

### Efficient Memory Usage

We make the assumption that users are able to specify the probabilistic model at compile-time.
As a result, AutoPPL can construct all model expressions at compile-time simply from the type information.
A model object makes no heap-allocations (with the exception of `ppl::for_each`) and is minimal in size.
It is simply a small, contiguous slab of memory representing the binary tree.
The `model` object in the [previous section](#intuitive-model-specification)
is about `88 bytes` on `x86_64-apple-darwin17.7.0` using `clang-11.0.3`.

For a more complicated model such as the following:
```cpp
Data<double> X;
std::array<Param<double>, 6> theta;
auto model = (
    theta[0] |= uniform(-1., 1.),
    theta[1] |= uniform(theta[0], theta[0] + 2.),
    theta[2] |= normal(theta[1], theta[0] * theta[0]),
    theta[3] |= normal(-2., 1.),
    theta[4] |= uniform(-0.5, 0.5),
    theta[5] |= normal(theta[2] + theta[3], theta[4]),
    X |= normal(theta[5], 1.)
);
```
The size of the model is `440 bytes` on the same machine and compiler.

A model expression simply references the variables used in the expression
such as `theta[0], theta[1], ..., theta[5], X`, i.e. it does not copy any data or values.

### High-performance Inference Methods

Users interface with the inference methods via model expressions and other
configuration parameters for that particular method.
Hence, the inference algorithms are completely general and work with any model
so long as the model expression is properly constructed.
Due to the statically-known model specification, algorithms
have opportunities to make compile-time optimizations.
See [Benchmarks](#benchmarks) for performance comparisons with STAN.

We were largely inspired by STAN and followed their
[reference](https://mc-stan.org/docs/2_23/reference-manual/index.html)
and also their
[implementation](https://github.com/stan-dev/stan)
to compute ESS, perform adaptations, and stabilize sampling algorithms.
However, our library works very differently underneath, especially
with automatic differentiation and handling model expressions.

## Installation

First, clone the repository:
```
git clone https://github.com/JamesYang007/autoppl ~/autoppl
```

The following are the dependencies:
- [Eigen3.3](http://eigen.tuxfamily.org/index.php?title=Main_Page)
- [FastAD](https://github.com/JamesYang007/FastAD)

We provide a shell script for Mac and Linux that automatically installs these libraries locally in `lib`:
```
cd ~/autoppl
./setup.sh
```

Since AutoPPL is a template library, there is nothing to build!
Just pass the compiler flag `-I<path>` when building your program
to include the path to `include` inside cloned directory,
`include` to Eigen3.3, and `include` to FastAD.
If you ran `./setup.sh`, the paths for the latter two are
`lib/FastAD/libs/eigen-3.3.7/build/include` and
`lib/FastAD/build/include` (relative to cloned directory).

For CMake users, they can follow these steps:
```
./clean-build.sh release -DCMAKE_INSTALL_PREFIX=.. -DAUTOPPL_ENABLE_TEST=OFF
cd build/release
make install
```
This will simply set the CMake variable `CMAKE_INSTALL_PREFIX` to the `build` directory and won't build anything.
If you want to install AutoPPL into the system, remove `-DCMAKE_INSTALL_PREFIX=..`.
The `make install` will install the `include` directory and CMake shared files in `build` directory.

In your own CMake project, assuming you have a single source file
`main.cpp` in the same directory as your CMakeLists.txt,
write the following as a minimal configuration:
```cmake
cmake_minimum_required(VERSION 3.7)
project("MyProject")
find_package(AutoPPL CONFIG REQUIRED)
find_package(FastAD CONFIG REQUIRED)
find_package(Eigen3 CONFIG REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main AutoPPL::AutoPPL FastAD::FastAD Eigen3::Eigen)
```

If you installed `AutoPPL` locally as instructed before,
you should add a hint to the `find_package` like:
```
find_package(AutoPPL CONFIG REQUIRED HINTS path_to_autoppl/build/share)
```

The above rule applies for `FastAD` and `Eigen3` as well.
If you installed these libraries using `setup.sh` locally,
the required hint paths are:
```
find_package(FastAD CONFIG REQUIRED HINTS path_to_autoppl/lib/FastAD/build/share)
find_package(Eigen3 CONFIG REQUIRED HINTS path_to_autoppl/lib/FastAD/libs/Eigen3/build/share)
```

## Quick Guide

We assume that we are in `namespace ppl` throughout this section.

### Variable

There are only a few variable types that a user will need to define a model.
```cpp
DataView<ValueType, ShapeType> Xv(ptr, rows, cols);
Data<ValueType, ShapeType> X(rows, cols);
Param<ValueType, ShapeType, ConstraintType> p(rows, cols);
TParam<ValueType, ShapeType> tp(rows, cols);
```

For all types listed above, `ValueType` should be either `double` or `int`, and
`ShapeType` must be one of `scl, vec, mat` (scalar, column vector, matrix) to indicate the general shape.
By default, `ShapeType` is `scl`.
Depending on the shape, the user may omit `rows` or `cols`.
For example, if `ShapeType` is `scl`, one can omit both `rows` and `cols` (both set to 1),
and if `ShapeType` is `vec`, one can omit `cols` (set to 1).
For `Param` specifically, see [Constraint](#constraint) for more information about `ConstraintType`.
For this section, this third template parameter is not important.

The difference between `DataView` and `Data` is that
`DataView` only views existing data (does not copy any data) and `Data` _owns_ data.
`DataView` will view data in column major format and `Data` will own data in column major format.
To get the underlying data that `DataView` views or `Data` owns,
we expose the member function `get`, which will return a reference to `Eigen::Map` or `Eigen::Matrix`, respectively.
We ask the users to refer to `Eigen` documentation for modifying the data.

`Param` and `TParam` objects do not own or view any values.
There is nothing to do from the user other than constructing them.
More details on their distinction will become clearer in the later sections.
At a high level, a `Param` is a parameter that can be sampled
and a `TParam` is a transformation of parameters and is not sampled.

It is worth mentioning that currently `TParam<T, vec>` objects are the only ones
that provide subsetting, i.e. have `operator[]` defined.
There should be no need with `Data` or `DataView` since one can subset the underlying Eigen object itself
and create a new `Data` or `DataView` object to own a copy of or view that subset.
Note that `tp[i]` returns another expression and does not actually retrieve any value;
it is simply a lightweight object that refers to `tp` and the `i`th value it represents.
Users should not concern themselves how `tp` actually binds to values during MCMC.

### Variable Expression

Variable expressions are any expressions that are "mathematical" functions of variables.
We provide overloads for `operator+,-,*,/,+=,-=,*=,/=,=`,
functions such as `sin, cos, tan, log, exp, sqrt, dot, for_each`.
All functions are vectorized whenever possible.
Here is an example:
```cpp
Data<double, mat> X(m,n);
Param<double, vec> w(n), w2(m);
TParam<double, scl> s;
auto var_expr = sin(dot(X, w) + s) - w2;
```

The expression above first creates an expression for the dot-product,
then a vectorized sum with a scalar (`s`),
then a vectorized `sin`,
then finally vectorized `operator-` with `w2`.

The only non-obvious function is `for_each`.
It has the same syntax as `std::for_each`,
however, the lambda function must return some variable expression:
```cpp
TParam<double, vec> h(10);
auto expr = for_each(util::counting_iterator<size_t>(0),
                     util::counting_iterator<size_t>(h.size()),
                     [&](size_t i) { return h[i] += h[i-1] * 2.; });
```

Note that we provide our own `counting_iterator` since they become quite useful in this context.
One can think of this expression as a "lazy-version" of the following:

```cpp
for (size_t i = 0; i < h.size(); ++i) {
    h[i] += h[i-1] * 2.;
}
```
assuming `h` in this context is, for example, `std::vector<double>`.
Again, nothing is computed when the expression is constructed.
All computation is done lazily during MCMC sampling.

Finally, users can create constants by writing literals directly,
as shown above, when constructing variable expressions.
If the user wishes to create a constant vector or matrix,
they can simply use those objects when constructing the variable expression
and our library will wrap them as constant objects.
The difference between constants and data is that constants cannot be assigned a distribution.

### Constraint

This section only applies to `Param` objects.
Sometimes, parameters must be constrained.
Some notable examples are
covariance matrix (symmetric and positive definite),
probability values (bounded by 0 and 1),
and standard deviation (bounded below by 0).
It is a well-known problem that sampling constrained parameters directly is highly-inefficient.

Every parameter has an associated unconstrained and constrained value.
Most MCMC algorithms like NUTS and Metropolis-Hastings will sample unconstrained values,
and transform the unconstrained values to constrained values when computing the log-pdf (corrected with the Jacobian).
For more information on how these transformations are performed, we direct the readers to look at
[STAN reference guide](https://mc-stan.org/docs/2_21/reference-manual/variable-transforms-chapter.html).
Note that users will always receive _constrained_ values as their samples after invoking a MCMC sampler.

Currently we only support lower bounds, lower-and-upper bounds, (symmetric) positive-definite, and no constraint.
We recommend using C++17 class template argument deduction (CTAD)
instead of `auto` to indicate that these objects are indeed parameters,
but of course, one can certainly just use `auto`:
```cpp
// Declaration pseudo-code:

// make_param<ValueType, ShapeType=scl, ConstraintType>(rows, cols, constraint);
// make_param<ValueType, ShapeType=scl, ConstraintType>(rows, constraint);
// make_param<ValueType, ShapeType=scl, ConstraintType>(constraint);

Param sigma = make_param<double>(lower(0.));                // scalar lower bounded by 0.
Param p = make_param<double, vec>(10, bounded(0., 1.));     // 10-element vector bounded by 0., 1.
Param Sigma = make_param<double, mat>(3, pos_def());        // 3x3 covariance matrix
```
From section [Variable](#variable), we saw that `Param` had a third template parameter.
Using the `make_param` helper function, we can deduce that third parameter type,
which is precisely the constraint argument to `make_param`.
In general, the constraint can be a complicated expression depending on other parameters as such:
```cpp
Param<double> w1;
Param w2 = make_param<double>(lower(w1 - 1. + w1 * w1));
```
so it is crucial that we are able to deduce the type.

### Distribution Expression

A distribution expression internally defines how to compute the log-pdf (dropping any constants).
Currently we support the following distributions:

| Distribution | Syntax |
| ------------ | ------ |
| [Bernoulli](https://en.wikipedia.org/wiki/Bernoulli_distribution) | `ppl::bernoulli(p)` |
| [Cauchy](https://en.wikipedia.org/wiki/Cauchy_distribution) | `ppl::cauchy(x0, gamma)` |
| [Normal](https://en.wikipedia.org/wiki/Normal_distribution) | `ppl::normal(mu, sigma)` |
| [Multivariate Normal](https://en.wikipedia.org/wiki/Multivariate_normal_distribution) | `ppl::normal(mu, Sigma)` |
| [Uniform](https://en.wikipedia.org/wiki/Uniform_distribution_(continuous)) | `ppl::uniform(min, max)` |
| [Wishart](https://en.wikipedia.org/wiki/Wishart_distribution) | `ppl::wishart(V, n)` |

Here are some examples:
```cpp
Param<double> m1, m2, M1, M2;
auto uniform_expr = uniform(m1 + m2, M1 + M2);

Param<double> l1, l2, s;
auto normal_expr = normal(l1 + l2, s);

Param V = make_param<double, mat>(3, pos_def);
auto wishart_expr = wishart(V, 5);
```

### Model Expression

There are two operators that govern model expressions: `operator|=` and `operator,`.
`operator|=` assigns a distribution to a parameter or data and
`operator,` "glues" such assignments together, defining a joint distribution.
The choice for `operator|=` is deliberate because it captures both the intuition that we are
assigning a distribution to a variable and that the distribution is _conditional_ (`|`).

Example:
```cpp
Data<double, vec> y(10);
Param<double> m1, m2, M1, M2;
Param<double> l1, l2, s;

auto model = (
    m1 |= normal(1., 1.),
    m2 |= normal(-1., 1.),
    M1 |= uniform(m2, m1),
    M2 |= uniform(M, 3.24 + m1),
    y |= normal(l1 + l2, s)
);
```

### Transformed Parameters

There are cases where defining a model expression is not enough.
Sometimes parameters have to be further transformed to cache some common transformation.
For example, here is a stochastic volatility model taken from
[STAN](https://mc-stan.org/docs/2_21/stan-users-guide/stochastic-volatility-models.html),
but using AutoPPL:

```cpp
DataView<double, vec> y(ptr, n_data);
Param phi = make_param<double>(bounded(-1., 1.));
Param sigma = make_param<double>(lower(0.));
Param<double> mu;
Param<double, vec> h_std(n_data);
TParam<double, vec> h(n_data);

// define transformed parameter expression
auto tp_expr = (
    h = h_std * sigma,
    h[0] /= sqrt(1. - phi * phi),
    h += mu,
    for_each(util::counting_iterator<>(1),
             util::counting_iterator<>(h.size()),
             [&](size_t i) { return h[i] += phi * (h[i-1] - mu); })
);

auto model = (
    phi |= uniform(-1., 1.),
    sigma |= cauchy(0., 5.),
    mu |= cauchy(0., 10.),
    h_std |= normal(0., 1.),
    y |= normal(0., exp(h / 2.))
);
```

A couple of notes:
- transformed parameter expression _must_ be defined as a separate expression from model expression
- it is more efficient to make a transformed parameter expression
  if there is a common transformation used in multiple places when defining a model expression
- all variable expressions are perfectly valid when defining TP expressions,
  but note that `operator=` is only available for `TParam` objects.
  In fact, all `TParam` objects that are used in a model expression _must have exactly one_
  `operator=` expression assigning some expression to that `TParam` object.
  The user cannot assign a vector `TParam` with some expression and then also assign a subview again like:
  ```cpp
  h = h_std * sigma,
  h[0] = 1.
  ```
  because this introduces ambiguity when back-evaluating during automatic differentiation.
  However, it is fine to assign each subview exactly once like:
  ```cpp
  for_each(util::counting_iterator<>(0),
           util::counting_iterator<>(h.size),
           [&](size_t i) { return h[i] = h_std[i] * sigma; });
  ```
- it is possible to assign a `TParam` with an expression composed of only data and constants,
  but this is much less efficient than precomputing that expression and creating a new constant out of that.
  This precomputation only requires using Eigen library and should not be a part of any autoppl expressions.

### Program Expression

A program expression simply combines a transformed parameter expression with a model expression.
If there is no transformed parameter expression, then a program expression simply wraps a model expression.
A program expression is what gets passed to MCMC samplers.
The user does not need to convert a model expression into a program expression,
but if there is a transformed parameter expression,
the user should use `operator|` to "pipe" transformed parameter expression with a model expression
to create a program expression (order matters! The wrong order will raise a compiler error):

```cpp
auto program = tp_expr | model;
```

### Sampling Algorithms

Currently, we support the following algorithms:

| MCMC Algorithm | Syntax |
| -------------- | ------ |
| [Metropolis-Hastings](https://en.wikipedia.org/wiki/Metropolis%E2%80%93Hastings_algorithm) | ppl::mh(program, config) |
| [No-U-Turn Sampler (NUTS)](http://www.stat.columbia.edu/~gelman/research/published/nuts.pdf) | ppl::nuts(program, config) |

Every sampling algorithm has a corresponding configuration object associated with it.
The user does not need to pass a configuration, in which case, a default-constructed object gets passed with the default settings.

We briefly list the configuration declaration:

```cpp
struct ConfigBase
{
    size_t warmup = 1000;               // number of warmup iterations
    size_t samples = 1000;              // number of samples
    size_t seed = mcmc::random_seed();  // seed (default: random)
    bool prune = true;                  // extra step during initialization to make sure log-pdf is not degenerate
};

// MH-specific

struct MHConfig : ConfigBase
{
    double sigma = 1.0;     // proposal distribution SD (N(0, sigma))
    double alpha = 0.25;    // discrete proposal distribution (triangular on {-1,0,1})
                            // with alpha probability on -1 and 1 (1-2*alpha on 0).
};

// NUTS-specific

struct StepConfig
{
    double delta = 0.8;
    double gamma = 0.05;
    double t0 = 10.;
    double kappa = 0.75;
};

struct VarConfig
{
    size_t init_buffer = 75;
    size_t term_buffer = 50;
    size_t window_base = 25;
};

// template parameter one of: unit_var, diag_var
template <class VarAdapterPolicy=diag_var>
struct NUTSConfig: ConfigBase
{
    using var_adapter_policy_t = VarAdapterPolicy;
    size_t max_depth = 10;
    StepConfig step_config;
    VarConfig var_config;
};
```

For the NUTS-specific configuration, we direct the reader to
[STAN](https://mc-stan.org/docs/2_18/reference-manual/hmc-algorithm-parameters.html).

Every sampler will return a `ppl::MCMCResult<>` object.
The template parameter indicates the row or column-major for the underlying sample matrix.
The sampler may choose to sample the unconstrained values and write in a row-major result object
for speed purposes and then convert to a column-major result object with constrained values.
We briefly show the class declaration:

```cpp
template <int Major = Eigen::ColMajor>
struct MCMCResult
{
    // ...
    cont_samples_t cont_samples;    // (continuous) sample matrix
    disc_samples_t disc_samples;    // (discrete) sample matrix
    std::string name;               // MCMC algorithm name
    double warmup_time = 0;         // time elapsed for warmup
    double sampling_time = 0;       // time elapsed for sampling
};
```

The sample matrices will always be `samples x n_constrained_values`,
where `samples` is the number of samples requested from the config object
and `n_constrained_values` is the number of constrained parameter values (flattened into a row).
The algorithms guarantee that each row consists of sampled parameter values
in the same order as the priors in the model.
As an example, for the following model
```cpp
auto model = (
    t1 |= ...,
    t2 |= ...,
    t3 |= ...,
    ...
);
```
a sample row would consist of values for `t1`, `t2`, `t3` in that order.
If the parameters are multi-dimensional, their values are flattened assuming column-major format.
So if `t1` is a vector with 4 elements, the first four elements of a row will be values for `t1`.
If `t2` is a 2x2 matrix, the next four elements of a row will be values for `t2(0,0), t2(1,0), t2(0,1), t2(1,1)`.

Currently, we do not support a `summary` function yet to output a summary of the samples.
The user can, however, directly call `res.cont_samples.colwise().mean()` to compute the mean for each column.
We also provide `ppl::math::ess(matrix)` to compute column-wise effective-sample-size (ESS).
The user can then divide this result with `res.sampling_time` to get `ESS/s`,
which is the preferred metric to compare performance among MCMC algorithms.
ESS was computed as outlined
[here](https://mc-stan.org/docs/2_23/reference-manual/effective-sample-size-section.html).
We also made some adjustments to use Geyer's biased estimator for ESS
as in the current implementation of STAN
([source](https://github.com/stan-dev/stan/blob/525998129ea838ec685f1d1f65dc76063d0fd40d/src/stan/analyze/mcmc/compute_effective_sample_size.hpp)).

## Examples

### Sampling from Joint Distribution

Although AutoPPL was designed to perform inference on posterior distributions,
one can certainly use it to sample from any joint distribution defined by the priors and conditional distributions.
For example, we can sample `1000` points with `1000` warmup iterations from a
standard normal distribution using Metropolis-Hastings in the following way:

```cpp
Param<double> theta;
auto model = (theta |= normal(0., 1.));
auto res = mh(model, config);
```

In general, so long as the joint PDF is known,
or equivalently and more commonly if the conditional and prior PDFs are known,
one can sample from the distribution.
As another example, we may sample from a more complicated joint distribution:
```cpp
Param<double> theta1;
Param<double> theta2;
auto model = (
    theta1 |= uniform(-1., 1.),
    theta2 |= normal(theta1, 1.)
);
auto res = mh(model);
```

### Sampling Posterior Mean and Standard Deviation

The following is an example of fitting a Gaussian model to some data.
We put a `Normal(0,3)` prior on the mean and `Uniform(0,2)` prior on the
standard deviation.
While in the previous section, we used Metropolis-Hastings
to demonstrate how to use it,
it is recommended to use the state-of-the-art NUTS sampler to sample
from the posterior distribution.

```cpp
Data<double, vec> x(5);
Param<double> mu;
Param<double> sigma;

x.get() << 1.0, 1.5, 1.7, 1.2, 1.5; // load data

auto model = (
    mu |= normal(0., 3.),
    sigma |= uniform(0., 2.),
    x |= normal(mu, sigma)
);

auto res = nuts(model);
```

### Bayesian Linear Regression

This example covers ridge regression in a Bayesian setting.
We created a fictitious dataset consisting of `(x,y)` coordinates.
The true relationship is the following: `y = x + 1`.
By specifying two parameters for the weight and bias, we propose
the following probabilistic model:

```
y ~ Normal(x*w + b, 0.5)
w ~ Uniform(0, 2)
b ~ Uniform(0, 2)
```

In AutoPPL, we can write the following code and sample from the posterior:
```cpp
Data<double> x(6);
Data<double> y(6);
Param<double> w;
Param<double> b;

x.get() << 2.4, 3.1, 3.6, 4, 4.5, 5.;
y.get() << 3.5, 4, 4.4, 5.01, 5.46, 6.1;

auto model = (
        w |= uniform(0., 2.),
        b |= uniform(0., 2.),
        y |= normal(x * w + b, 0.5)
);

auto res = nuts(model);
```

### Stochastic Volatility

This example was discussed in a previous section, but we mention it again as reference:
```cpp
DataView<double, vec> y(ptr, n_data);
Param phi = make_param<double>(bounded(-1., 1.));
Param sigma = make_param<double>(lower(0.));
Param<double> mu;
Param<double, vec> h_std(n_data);
TParam<double, vec> h(n_data);

auto tp_expr = (
    h = h_std * sigma,
    h[0] /= sqrt(1. - phi * phi),
    h += mu,
    for_each(util::counting_iterator<>(1),
             util::counting_iterator<>(h.size()),
             [&](size_t i) { return h[i] += phi * (h[i-1] - mu); })
);

auto model = (
    phi |= uniform(-1., 1.),
    sigma |= cauchy(0., 5.),
    mu |= cauchy(0., 10.),
    h_std |= normal(0., 1.),
    y |= normal(0., exp(h / 2.))
);

auto res = nuts(tp_expr | model);
```

## Benchmarks

In the following examples, we show benchmarks with STAN.

We list the benchmark settings for completion:
- Machine: x86_64-apple-darwin19.5.0
- CPU: 3.4 GHz Quad-Core Intel Core i5
- Compiler: Clang 11.0.3

### Bayesian Linear Regression <a name="benchmarks-bayesian-linear-regression"></a>

We collected a dataset regarding life expectancy released by WHO
([source](https://www.kaggle.com/kumarajarshi/life-expectancy-who)).
After cleaning and extracting three predictors: "Alcohol", "HIV/AIDS", and "GDP",
the dataset consisted of 157 points.
We performed a Bayesian linear regression with this data and the following model:

```
y ~ Normal(X*w + b, s*s + 2.)
w ~ Normal(0., 5.)
b ~ Normal(0., 5.)
s ~ Uniform(0.5, 8.)
```

where `w` is a 3-dimensional parameter vector,
and `b` and `s` are scalar parameters.

Using the same dataset and model specification,
we performed NUTS to sample various number of samples.
We also set the number of chains and cores to 1 and
adaptation method to diagonal precision matrix.

The following plots show benchmarks between
run-times and effective sample size (ESS) per second:

![](docs/figures/regression_benchmark_plot/runtime.png)
![](docs/figures/regression_benchmark_plot/ess_s.png)

The reported mean, standard deviation, and ESS values were
almost identical in all cases,
which is not surprising since we used the same algorithm to estimate ESS
and perform NUTS.

The runtimes have similar log-like behavior,
but it is clear that STAN (dotted lines) takes far longer
in both sampling and warmup times by a factor of about 6.5-7.
As for ESS/s, upon comparing by colors (corresponding to a parameter)
between dotted (STAN) and solid (AutoPPL) lines,
we see that AutoPPL has uniformly larger ESS/s by a factor of 6.5-7 as well.
This difference quickly becomes more noticeable as sample size grows.
From these plots and that sampling results were identical
show that the drastic difference in ESS/s is simply from faster
automatic differentation and a good use of memory to take advantage of cache.

The following is the AutoPPL code for the model specification without data loading.
The full code can be found
[here](benchmark/regression_autoppl.cpp):

```cpp
DataView<double, mat> X(X_data.data(), X_data.rows(), X_data.cols());
DataView<double, vec> y(y_data.data(), y_data.rows());
Param<double, vec> w(3);
Param<double> b;
Param<double> s;

auto model = (s |= uniform(0.5, 8.),
              b |= normal(0., 5.),
              w |= normal(0., 5.),
              y |= normal(dot(X, w) + b, s * s + 2.));

NUTSConfig<> config;
config.warmup = num_samples;
config.samples = num_samples;

auto res = nuts(model, config);
```

### Gaussian Model

We generated 1000 values from standard normal distribution to form our data.
Our model is defined as follows:

```
y ~ Normal(l1 + l2, s)
l1 ~ Normal(0., 10.)
l2 ~ Normal(0., 10.)
s ~ Uniform(0., 20.)
```

where all parameters are scalar.
The benchmark configurations are exactly the same as in the
[previous section](#benchmarks-bayesian-linear-regression).
The following plots show benchmarks between
run-times and effective sample size (ESS) per second:

![](docs/figures/gaussian_benchmark_plot/runtime.png)
![](docs/figures/gaussian_benchmark_plot/ess_s.png)

We note that both STAN and AutoPPL outputted almost identical
means, standard deviation, and ESS.

The runtimes have a similar linear trend,
and it is clear that STAN (dotted lines) takes far longer
in both sampling and warmup times.
Comparing the sampling times, for example, we see about 20 times improvement.
The ESS/s for `l1` and `l2` overlap completely (red and blue) in both STAN and AutoPPL
and this is expected since they are symmetric in the model specification.
With the exception of the two smallest sample sizes (100, 500),
ESS/s is fairly constant as sample size varies.
It is quite evident that AutoPPL (solid) has a larger ESS/s by a factor of 20.

The reason for this difference is in how we handle expressions
where data vector elements are iid (independent and identically distributed).
For most distributions, especially those that are in some exponential family,
they can be highly optimized in iid settings to perform quicker differentiation.
However, it is worth noting that this optimization does not apply when
the data are simply independent but not identically distributed
(as in the [linear regression](#benchmarks-bayesian-linear-regression) case),
or when the variable is a parameter, not data.
Nonetheless, our AD is extremely fast due to vectorization and is in general faster than STAN.

The following is the AutoPPL code without data generation.
The full code can be found
[here](benchmark/normal_two_prior_distribution.cpp).

```cpp
Data<double, vec> y(n_data);
Param<double> lambda1, lambda2, sigma;

auto model = (
    sigma |= uniform(0.0, 20.0),
    lambda1 |= normal(0.0, 10.0),
    lambda2 |= normal(0.0, 10.0),
    y |= normal(lambda1 + lambda2, sigma)
);

NUTSConfig<> config;
config.n_samples = n_samples;
config.warmup = n_samples;

auto res = nuts(model, config);
```

## Contributors

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
  <tr>
    <td align="center"><a href="https://jacobaustin123.github.io/"><img src="https://avatars0.githubusercontent.com/u/28993550?v=4" width="100px;" alt=""/><br /><sub><b>Jacob Austin</b></sub></a><br /><a href="https://github.com/JamesYang007/autoppl/commits?author=jacobaustin123" title="Code">💻</a> <a href="#design-jacobaustin123" title="Design">🎨</a> <a href="https://github.com/JamesYang007/autoppl/commits?author=jacobaustin123" title="Documentation">📖</a></td>
    <td align="center"><a href="http://jenny-chen.net"><img src="https://avatars0.githubusercontent.com/u/13106682?v=4" width="100px;" alt=""/><br /><sub><b>Jenny Chen</b></sub></a><br /><a href="https://github.com/JamesYang007/autoppl/commits?author=jenchen1398" title="Code">💻</a> <a href="#design-jenchen1398" title="Design">🎨</a></td>
    <td align="center"><a href="https://github.com/lucieleblanc"><img src="https://avatars3.githubusercontent.com/u/14223323?v=4" width="100px;" alt=""/><br /><sub><b>lucieleblanc</b></sub></a><br /><a href="https://github.com/JamesYang007/autoppl/commits?author=lucieleblanc" title="Code">💻</a> <a href="#design-lucieleblanc" title="Design">🎨</a></td>
    <td align="center"><a href="http://lancaster.ac.uk/~ludkinm/"><img src="https://avatars3.githubusercontent.com/u/28777642?v=4" width="100px;" alt=""/><br /><sub><b>Matt Ludkin</b></sub></a><br /><a href="https://github.com/JamesYang007/autoppl/commits?author=ludkinm" title="Code">💻</a></td>
  </tr>
</table>

<!-- markdownlint-enable -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->

## Third Party Tools

Many thanks to the following third party tools used in this project:
- [Clang](https://clang.llvm.org/): one of the main compilers used.
- [CMake](https://cmake.org/): build system.
- [Coveralls](https://coveralls.io/): check test coverage.
- [Cpp Coveralls](https://github.com/eddyxu/cpp-coveralls): check test coverage specifically for C++ code.
- [Eigen](http://eigen.tuxfamily.org/index.php?title=Main_Page): matrix library.
- [FastAD](https://github.com/JamesYang007/FastAD): automatic differentiation library.
- [GCC](https://gcc.gnu.org/): one of the main compilers used.
- [Google Benchmark](https://github.com/google/benchmark): benchmark library algorithms.
- [GoogleTest](https://github.com/google/googletest): unit/integration-tests.
- [Travis CI](https://travis-ci.org/): continuous integration for Linux using GCC.
- [Valgrind](http://valgrind.org/): check memory leak and errors.

repository: StHamish/autoppl

repo_name: StHamish/autoppl


text:
![First-To-React](/first-to-react/f2r-logo.png)

### Welcome to First-To-React

_An overview and interactive introduction into using and working with React._

___Who is this for?___ Developers interested in learning more about and/or getting started with React.

___What can I do here?___ Read through the information, and play and modify the examples right in the browser!

_A basic understanding of JavaScript syntax and features will benefit the examples contained._

repository: pgeeh/first-to-react

repo_name: pgeeh/first-to-react


text:
# Telegraf setup

In this setup we will see how to install the Telegraf agent in your system and create a background service to run the telegraf automatically when the system restarts (Ubuntu and Windows)

### Telegraf Installation

* To install telegraf in your system [click on the telegraf link][telegraf] and then scroll down to `Telegraf` and then select your OS and follow the instructions provided over there

* If you are having RaspberryPi and in which if you have installed `Ubuntu` Image then select

## Setup Instructions for Ubuntu

Once the telegraf is installed you could see the folder named telegraf-1.19.3 navigate to that folder and do the following

```
cd telegraf-1.19.3 ;
sudo cp -rp usr/* /usr ;
sudo cp -rp etc/* /etc ;
sudo cp -rp var/* /var
```

We have moved the telegraf binaries, configuration file and then libraries to the respective locations

Now navigate to `/etc/systemmd/system` and then create a new file named `telegraf.service` and then open that file in your text editor and then add the below contents to start the telegraf service automatically during system restart

```
[Unit]
Description=Telegraf service

[Service]
ExecStart=/usr/bin/telegraf -config /etc/telegraf/telegraf.conf
NotifyAccess=main
#WatchdogSec=10
Restart=on-failure
ProtectHome=true
ProtectSystem=full

[Install]
WantedBy=multi-user.target

```

`Save` the configuration file and then navigate to `/etc/telegraf` and then open `telegraf.conf` file and then clear the contents inside that file and add the contents of the telegraf configuration which you have downloaded during InfluxDB setup

**Note:** If you accidentally deleted the telegraf.conf file no problem, create a new telegraf.conf file and then add the telegraf configurations which you have downloaded earlier.Make sure to give the file permission with the following command

```
//file mode: Telegraf conf: -rwx------
sudo chmod 700 telegraf.conf
```

and then enable the service using the below commands in your terminal

```
sudo systemctl enable telegraf.service
sudo systemctl start telegraf.service
sudo systemctl status telegraf.service
```
**Note:** If you make any changes in `telegraf.conf` file then restart the telegraf service using the above command

Once the telegraf status is like the below image means then your are good to go

## Setup Instructions for Windows

1. Open a Windows shell and navigate to the directory where Telegraf file is downloaded and then install telegraf using the below command

```
.\telegraf.exe --service install --config "pathofyour \telegraf.conf"
```

#### Example

```
C:\Program Files\InfluxData\Telegraf> .\telegraf.exe --service install --config "C:\Program Files\InfluxData\Telegraf\telegraf.conf"
```

In the above case i have created a folder named `InfluxData` in that a sub-folder `Telegraf` downloaded the telegraf binary in that location

2. To start the telegraf service use the below command in that path itself

```
.\telegraf.exe --service start
```

Once the telegraf service is started open your InfluxDB cloud and then click `Explore` and the click the `Bucket` which you have created Now you could see the metrics reported from your system to InfluxDB via Telegraf agent

Congrats you have completed the telegraf setup

[telegraf]: https://portal.influxdata.com/downloads/


text:
<!-- README.md is generated from README.Rmd. Please edit that file -->

# bank

<!-- badges: start -->

[![R-CMD-check](https://github.com/ThinkR-open/bank/workflows/R-CMD-check/badge.svg)](https://github.com/ThinkR-open/bank/actions)
<!-- badges: end -->

The goal of `{bank}` is to provide alternative backends for caching with
`{memoise}` & `{shiny}`.

## Installation

``` r
# install.packages("remotes")
remotes::install_github("thinkr-open/bank")
```

## Some things to know before starting

### Caching scope

When using `{bank}` backends with `{shiny}`, caching will done at the
app-level, in other words the cache is stored across sessions. Be aware
of this behavior if you have sensitive data inside your app, as this
might imply data leakage.

See `?shiny::bindCache`

> With an app-level cache scope, one user can benefit from the work done
> for another user’s session. In most cases, this is the best way to get
> performance improvements from caching. However, in some cases, this
> could leak information between sessions. For example, if the cache key
> does not fully encompass the inputs used by the value, then data could
> leak between the sessions. Or if a user sees that a cached reactive
> returns its value very quickly, they may be able to infer that someone
> else has already used it with the same values.

### Cache flushing

As with any `{cachem}` compatible objects, the cache can be manually
flushed using the `$reset()` method – this will call `drop()` on MongoDB
and `FLUSHALL` in Redis.

``` r
library(bank)
mongo_cache <- cache_mongo$new(
  db = "bank",
  url = "mongodb://localhost:27066",
  prefix = "sn"
)

mongo_cache$reset()
```

As `{bank}` relies on external backends, it’s probably better to let the
DBMS handle the flushing of cache. For example, in `redis.conf`, you can
set :

    maxmemory 2mb
    maxmemory-policy allkeys-lru

LRU (least recently used) will allow redis to flush the key based on
when they were used. See <https://redis.io/topics/lru-cache>.

MongoDB doesn’t come with a LRU mechanism, but you can set data to be
ephemeral with [TTL
index](https://docs.mongodb.com/manual/core/index-ttl/) inside your
collection.

`{bank}` also tries to help with that by updating a `lastAccessed` date
metadata field whenever you `$get()` the key, meaning that you can
implement your own caching strategy to evict least recently used cached
objects.

## Backends

Note that if you want to use `{bank}` in a `{shiny}` app:

  - `renderCachedPlot()` require `{shiny}` version 1.5.0 or higher

  - `bindCache()` require `{shiny}` version 1.6.0 or higher

For now, the following backends are supported:

  - [MongoDB](#mongo)

  - [Redis](#redis)

### Mongo

Launching a container with mongo.

``` bash
docker run --rm --name mongobank -d -p 27066:27017 -e MONGO_INITDB_ROOT_USERNAME=bebop -e MONGO_INITDB_ROOT_PASSWORD=aloula mongo:3.4
```

#### With `{memoise}`

First, the `cache_mongo` can be used

``` r
library(memoise)
library(bank)
# Create a mongo cache.
# The arguments will be passed to mongo::gridfs
mongo_cache <- cache_mongo$new(
  db = "bank",
  url = "mongodb://bebop:aloula@localhost:27066",
  prefix = "sn"
)
#> Loading required namespace: mongolite

f <- function(x) {
  sample(1:1000, x)
}

mf <- memoise(f, cache = mongo_cache)
mf(5)
#> [1]  34 831 763 518 609
mf(5)
#> [1]  34 831 763 518 609
```

#### Inside `{shiny}`

Here is a first simple application that shows you the basics :

``` r
library(shiny)
ui <- fluidPage(
  # Creating a slider input that will be used as a cache key
  sliderInput("nrow", "NROW", 1, 32, 32),
  # Plotting a piece of mtcars
  plotOutput("plot")
)

server <- function(input, output, session){

  output$plot <- renderCachedPlot({
    # Pretending this takes a long time
    Sys.sleep(2)
    plot(mtcars[1:input$nrow, ])

  }, cacheKeyExpr = list(
    # Defining the cache key
    input$nrow
  ),
  # Using our mongo cache
  cache = mongo_cache
  )

}
shinyApp(ui, server)
```

As you can see, the first time you set the slider to a given value, it
takes a little bit to compute. Then it’s almost instantaneous.

Let’s try a more complex application:

``` r
# We'll put everything in a function so that it can later be reused with other backends
library(magrittr)

generate_app <- function(cache_object){
  ui <- fluidPage(
    h1(
      sprintf(
        "Caching in an external DB using %s",
        deparse(
          substitute(cache_object)
        )
      )
    ),
    sidebarLayout(
      sidebarPanel = sidebarPanel(
        # This sliderInput will be the cache key
        # i.e we don't want to recompute the plot everytime
        sliderInput("nrow", "Nrow", 1, 32, 32),
        # Allow to clear the cache
        actionButton("clear", "Clear Cache")
      ),
      mainPanel = mainPanel(
        # Outputing the reactive and a plot
        verbatimTextOutput("txt"),
        plotOutput("plot"),
        # If you care about listing the cache keys
        uiOutput("keys")
      )
    )
  )

  server <- function(
    input,
    output,
    session
  ){

    # Our plot, cached using the cache object and
    # watching the nrow
    output$plot <- renderCachedPlot({

      showNotification(
        h2("I'm computing the plot"),
        type = "message"
      )

      # Fake long computation
      Sys.sleep(2)

      # Plot
      plot(mtcars[1:input$nrow, ])

    },
    # We cache on the input$nrow
    cacheKeyExpr = list(
      input$nrow
    ),
    # The cache object is used here
    cache = cache_object
    )

    rc <- reactive({

      showNotification(
        h2("I'm computing the reactive()"),
        type = "message"
      )
      # Fake long computation
      Sys.sleep(2)

      input$nrow * 100

    }) %>%
      # Using bindCache() require shiny > 1.6.0
      bindCache(
        input$nrow,
        cache = cache_object
      )

    output$txt <- renderText({
      rc()
    })

    keys <- reactive({
      # Listing the keys
      invalidateLater(500)
      cache_object$keys()
    })

    output$keys <- renderUI({
      tags$ul(
        lapply(keys(), tags$li)
      )
    })

    observeEvent( input$clear , {
      # Sometime you might want to remove everything from the cache
      cache_object$reset()

      showNotification(
        h2("Cache reset"),
        type = "message"
      )

    })
  }

  shinyApp(ui, server)
}

generate_app(mongo_cache)
```

#### Flushing MongoDB cache using LRU

All keys registered to MongoDB comes with a `metadata.lastAccessed`
parameter.
# The arguments will be passed to redux::hiredis
redis_cache <- cache_redis$new(password = "bebopalula")
#> Loading required namespace: redux

f <- function(x) {
  sample(1:1000, x)
}

mf <- memoise(f, cache = redis_cache)
mf(5)
#> [1] 433 551 342 130 265
mf(5)
#> [1] 433 551 342 130 265
```

#### Inside `{shiny}`

Here is a first simple application that shows you the basics :

``` r
ui <- fluidPage(
  # Creating a slider input that will be used as a cache key
  sliderInput("nrow", "NROW", 1, 32, 32),
  # Plotting a piece of mtcars
  plotOutput("plot")
)

server <- function(input, output, session){

  output$plot <- renderCachedPlot({
    # Pretending this takes a long time
    Sys.sleep(2)
    plot(mtcars[1:input$nrow, ])

  }, cacheKeyExpr = list(
    # Defining the cache key
    input$nrow
  ),
  # Using our redis cache
  cache = redis_cache
  )

}
shinyApp(ui, server)
```

For the larger app:

``` r
generate_app(redis_cache)
```

## Chosing a cache method

### Benchmark

As we are deporting the caching to an external DBMS, the query will of
course be slower than using memory cache of disk cache. But this
difference in speed comes with a simpler scalability of the caching, as
several instances of the app can rely on the same caching backend
without the need to be on the same machine.

``` r
library(magrittr)
#> Warning: package 'magrittr' was built under R version 3.6.2
library(bank)
big_iris <- purrr::rerun(100, iris) %>% data.table::rbindlist()

nrow(big_iris)
#> [1] 15000
pryr::object_size(big_iris)
#> Registered S3 method overwritten by 'pryr':
#>   method      from
#>   print.bytes Rcpp
#> 542 kB

library(cachem)

mem_cache <- cache_mem()

disk_cache <- cache_disk()

mongo_cache <- cache_mongo$new(
  db = "bank",
  url = "mongodb://bebop:aloula@localhost:27066",
  prefix = "sn"
)

redis_cache <- cache_redis$new(password = "bebopalula")

bench::mark(
  mem_cache = mem_cache$set("iris", big_iris),
  disk_cache = disk_cache$set("iris", big_iris),
  mongo_cache = mongo_cache$set("iris", big_iris),
  redis_cache = redis_cache$set("iris", big_iris),
  check = FALSE,
  iterations = 100
)
#> # A tibble: 4 x 6
#>   expression       min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>  <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 mem_cache     24.6µs  33.77µs   19585.     5.02KB    0
#> 2 disk_cache    6.33ms   8.23ms      94.0   18.45KB    0
#> 3 mongo_cache  49.27ms  67.34ms      11.6    2.52MB    0.482
#> 4 redis_cache  26.91ms  36.95ms      21.3  536.58KB    0.215

bench::mark(
  mem_cache = mem_cache$get("iris"),
  disk_cache = disk_cache$get("iris"),
  mongo_cache = mongo_cache$get("iris"),
  redis_cache = redis_cache$get("iris"),
  iterations = 100
)
#> # A tibble: 4 x 6
#>   expression       min   median `itr/sec` mem_alloc `gc/sec`
#>   <bch:expr>  <bch:tm> <bch:tm>     <dbl> <bch:byt>    <dbl>
#> 1 mem_cache    14.45µs  20.17µs   38244.         0B    0
#> 2 disk_cache    2.13ms   2.66ms     335.   548.19KB    3.38
#> 3 mongo_cache  41.14ms  60.34ms      15.0    2.06MB    0.624
#> 4 redis_cache     19ms  30.32ms      25.9    1.03MB    0.529
```

``` bash
docker stop mongobank redisbank
```

## You want another backend?

If you have any other backend in mind, feel free to open an issue here
and we’ll discuss the possibility of implementing it in `{bank}`.

## Code of Conduct

Please note that the bank project is released with a [Contributor Code
of
Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html).
By contributing to this project, you agree to abide by its terms.

repository: jimsforks/bank

repo_name: jimsforks/bank


text:
# FunNumbers

This is an Actions on Google project using a [Dialogflow](https://dialogflow.com) agent.

Trigger is "Talk to Fun Numbers".

It consists of two parts: A Number Game and A Basic Calculator.

The ApiAi_Agents folder contains the Api.Ai agent which you can restore you project to.

You can extend the [Project](https://github.com/IkechukwuAKalu/fun-numbers) to make something complex.

Feel free to follow me on [Twitter](https://twitter.com/ikechukwuakalu)

repository: IkechukwuAKalu/fun-numbers

repo_name: IkechukwuAKalu/fun-numbers