text:
## for my paper
### Disclaimer

The official Faster R-CNN code (written in MATLAB) is available [here](https://github.com/ShaoqingRen/faster_rcnn).
If your goal is to reproduce the results in our NIPS 2015 paper, please use the [official code](https://github.com/ShaoqingRen/faster_rcnn).

This repository contains a Python *reimplementation* of the MATLAB code.
This Python implementation is built on a fork of [Fast R-CNN](https://github.com/rbgirshick/fast-rcnn).
There are slight differences between the two implementations.
In particular, this Python port
 - is ~10% slower at test-time, because some operations execute on the CPU in Python layers (e.g., 220ms / image vs. 200ms / image for VGG16)
 - gives similar, but not exactly the same, mAP as the MATLAB version
 - is *not compatible* with models trained using the MATLAB code due to the minor implementation differences
 - **includes approximate joint training** that is 1.5x faster than alternating optimization (for VGG16) -- see these [slides](https://www.dropbox.com/s/xtr4yd4i5e0vw8g/iccv15_tutorial_training_rbg.pdf?dl=0) for more information

# *Faster* R-CNN: Towards Real-Time Object Detection with Region Proposal Networks

By Shaoqing Ren, Kaiming He, Ross Girshick, Jian Sun (Microsoft Research)

This Python implementation contains contributions from Sean Bell (Cornell) written during an MSR internship.

Please see the official [README.md](https://github.com/ShaoqingRen/faster_rcnn/blob/master/README.md) for more details.

Faster R-CNN was initially described in an [arXiv tech report](http://arxiv.org/abs/1506.01497) and was subsequently published in NIPS 2015.

### License

Faster R-CNN is released under the MIT License (refer to the LICENSE file for details).

### Citing Faster R-CNN

If you find Faster R-CNN useful in your research, please consider citing:

    @inproceedings{renNIPS15fasterrcnn,
        Author = {Shaoqing Ren and Kaiming He and Ross Girshick and Jian Sun},
        Title = {Faster {R-CNN}: Towards Real-Time Object Detection
                 with Region Proposal Networks},
        Booktitle = {Advances in Neural Information Processing Systems ({NIPS})},
        Year = {2015}
    }

### Contents
1. [Requirements: software](#requirements-software)
2. [Requirements: hardware](#requirements-hardware)
3. [Basic installation](#installation-sufficient-for-the-demo)
4. [Demo](#demo)
5. [Beyond the demo: training and testing](#beyond-the-demo-installation-for-training-and-testing-models)
6. [Usage](#usage)

### Requirements: software

1. Requirements for `Caffe` and `pycaffe` (see: [Caffe installation instructions](http://caffe.berkeleyvision.org/installation.html))

  **Note:** Caffe *must* be built with support for Python layers!

  ```make
  # In your Makefile.config, make sure to have this line uncommented
  WITH_PYTHON_LAYER := 1
  # Unrelatedly, it's also recommended that you use CUDNN
  USE_CUDNN := 1
  ```

  You can download my [Makefile.config](https://dl.dropboxusercontent.com/s/6joa55k64xo2h68/Makefile.config?dl=0) for reference.
2. Python packages you might not have: `cython`, `python-opencv`, `easydict`
3. [Optional] MATLAB is required for **official** PASCAL VOC evaluation only. The code now includes unofficial Python evaluation code.

### Requirements: hardware

1. For training smaller networks (ZF, VGG_CNN_M_1024) a good GPU (e.g., Titan, K20, K40, ...) with at least 3G of memory suffices
2. For training Fast R-CNN with VGG16, you'll need a K40 (~11G of memory)
3. For training the end-to-end version of Faster R-CNN with VGG16, 3G of GPU memory is sufficient (using CUDNN)

### Installation (sufficient for the demo)

1. Clone the Faster R-CNN repository
  ```Shell
  # Make sure to clone with --recursive
  git clone --recursive https://github.com/rbgirshick/py-faster-rcnn.git
  ```

2. We'll call the directory that you cloned Faster R-CNN into `FRCN_ROOT`

   *Ignore notes 1 and 2 if you followed step 1 above.*

   **Note 1:** If you didn't clone Faster R-CNN with the `--recursive` flag, then you'll need to manually clone the `caffe-fast-rcnn` submodule:
    ```Shell
    git submodule update --init --recursive
    ```
    **Note 2:** The `caffe-fast-rcnn` submodule needs to be on the `faster-rcnn` branch (or equivalent detached state). This will happen automatically *if you followed step 1 instructions*.

3. Build the Cython modules
    ```Shell
    cd $FRCN_ROOT/lib
    make
    ```

4. Build Caffe and pycaffe
    ```Shell
    cd $FRCN_ROOT/caffe-fast-rcnn
    # Now follow the Caffe installation instructions here:
    #   http://caffe.berkeleyvision.org/installation.html

    # If you're experienced with Caffe and have all of the requirements installed
    # and your Makefile.config in place, then simply do:
    make -j8 && make pycaffe
    ```

5. Download pre-computed Faster R-CNN detectors
    ```Shell
    cd $FRCN_ROOT
    ./data/scripts/fetch_faster_rcnn_models.sh
    ```

    This will populate the `$FRCN_ROOT/data` folder with `faster_rcnn_models`. See `data/README.md` for details.
    These models were trained on VOC 2007 trainval.

### Demo

*After successfully completing [basic installation](#installation-sufficient-for-the-demo)*, you'll be ready to run the demo.

To run the demo
```Shell
cd $FRCN_ROOT
./tools/demo.py
```
The demo performs detection using a VGG16 network trained for detection on PASCAL VOC 2007.

### Beyond the demo: installation for training and testing models
1. Download the training, validation, test data and VOCdevkit

	```Shell
	wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
	wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar
	wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCdevkit_08-Jun-2007.tar
	```

2. Extract all of these tars into one directory named `VOCdevkit`

	```Shell
	tar xvf VOCtrainval_06-Nov-2007.tar
	tar xvf VOCtest_06-Nov-2007.tar
	tar xvf VOCdevkit_08-Jun-2007.tar
	```

3. It should have this basic structure

	```Shell
  	$VOCdevkit/                           # development kit
  	$VOCdevkit/VOCcode/                   # VOC utility code
  	$VOCdevkit/VOC2007                    # image sets, annotations, etc.
  	# ... and several other directories ...
  	```

4. Create symlinks for the PASCAL VOC dataset

	```Shell
    cd $FRCN_ROOT/data
    ln -s $VOCdevkit VOCdevkit2007
    ```
    Using symlinks is a good idea because you will likely want to share the same PASCAL dataset installation between multiple projects.
5. [Optional] follow similar steps to get PASCAL VOC 2010 and 2012
6. [Optional] If you want to use COCO, please see some notes under `data/README.md`
7. Follow the next sections to download pre-trained ImageNet models

### Download pre-trained ImageNet models

Pre-trained ImageNet models can be downloaded for the three networks described in the paper: ZF and VGG16.

```Shell
cd $FRCN_ROOT
./data/scripts/fetch_imagenet_models.sh
```
VGG16 comes from the [Caffe Model Zoo](https://github.com/BVLC/caffe/wiki/Model-Zoo), but is provided here for your convenience.
ZF was trained at MSRA.

### Usage

To train and test a Faster R-CNN detector using the **alternating optimization** algorithm from our NIPS 2015 paper, use `experiments/scripts/faster_rcnn_alt_opt.sh`.
Output is written underneath `$FRCN_ROOT/output`.

```Shell
cd $FRCN_ROOT
./experiments/scripts/faster_rcnn_alt_opt.sh [GPU_ID] [NET] [--set ...]
# GPU_ID is the GPU you want to train on
# NET in {ZF, VGG_CNN_M_1024, VGG16} is the network arch to use
# --set ... allows you to specify fast_rcnn.config options, e.g.
#   --set EXP_DIR seed_rng1701 RNG_SEED 1701
```

("alt opt" refers to the alternating optimization training algorithm described in the NIPS paper.)

To train and test a Faster R-CNN detector using the **approximate joint training** method, use `experiments/scripts/faster_rcnn_end2end.sh`.
Output is written underneath `$FRCN_ROOT/output`.

```Shell
cd $FRCN_ROOT
./experiments/scripts/faster_rcnn_end2end.sh [GPU_ID] [NET] [--set ...]
# GPU_ID is the GPU you want to train on
# NET in {ZF, VGG_CNN_M_1024, VGG16} is the network arch to use
# --set ... allows you to specify fast_rcnn.config options, e.g.
#   --set EXP_DIR seed_rng1701 RNG_SEED 1701
```

This method trains the RPN module jointly with the Fast R-CNN network, rather than alternating between training the two. It results in faster (~ 1.5x speedup) training times and similar detection accuracy. See these [slides](https://www.dropbox.com/s/xtr4yd4i5e0vw8g/iccv15_tutorial_training_rbg.pdf?dl=0) for more details.

Artifacts generated by the scripts in `tools` are written in this directory.

Trained Fast R-CNN networks are saved under:

```
output/<experiment directory>/<dataset name>/
```

Test outputs are saved under:

```
output/<experiment directory>/<dataset name>/<network snapshot name>/
```


text:
# Polysynnema Constant. & Seifert GENUS

#### Status
ACCEPTED

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

#### Published in
Trans. Br. mycol. Soc. 90(2): 332 (1988)

#### Original name
Polysynnema Constant. & Seifert

### Remarks
null

repository: mdoering/backbone

branch_name: refs/heads/master

extension: md

license_type: permissive

repo_name: mdoering/backbone


text:
# Example 4 - Accretion disk image (equatorial plane)

This example illustrates how SIM5 library can be used in a C program and in a Python script to compute an image of an axially symmetric thin accretion disk around a black hole. The disk assumed to be located at the equatroial plane and to have zero geometrical thickness (an usual astrophysical assumption for disks accreting at low rates).
The equatorial plane setup allows a fast evaluation (up to ~105 photons per second) of the image because the radius from which the photons originate may be calculated by an inversion of an elliptic positional integral. Thus, by using
```C
geodesic_init_inf(inclination, spin, alpha, beta, &gd, &error);
P = geodesic_find_midplane_crossing(&gd, 0);
r = geodesic_position_rad(&gd, P);
```
one can quickly and efficiently find the original radius of a photon coming out of the disk surface that has  impact parameters *alpha* and *beta*.

## Running in C
```bash
make
./disk-image 0.5 60 > image.dat
```

First argument is the black-hole spin (0 to 0.999), second argument is the angle of the line of sight of an observer with respect to symmetry axis (0 to 90 degrees).

The program computes the disk image and dumps the image data to standard output. Stdout can be redirected to a file. The format of each printed line is:
`y  x  flux  g_factor`
where *x*, *y* are pixel coordinates, *flux* is a frequency-integrated radiative flux received a pixels and *g_factor* is the value of the energy shift due to relativistic effects.

## Running in Python
```bash
python disk-image.py 0.5 80
```

First argument is the black-hole spin (0 to 0.999), second argument is the line-of-sight angle (0 to 90 degrees). The script diaplays the plot of flux and g-factor.

## Extending the example
In addition to `geodesic_position_rad()` function, other positional parameters of the photon can be determined by `geodesic_position_azm()` (azimuthal angle) for non-axisymmteric applications, and `geodesic_timedelay()` for timing applications. Direction of the outgoing photon can be obtained from `geodesic_momentum()`.

license: MIT


text:
# Svelte Language Server

A language server (implementing the [language server protocol](https://microsoft.github.io/language-server-protocol/))
for Svelte.

## What is a language server?

From https://microsoft.github.io/language-server-protocol/overview

> The idea behind a Language Server is to provide the language-specific smarts inside a server that can communicate with development tooling over a protocol that enables inter-process communication.

In simpler terms, this allows editor and addon devs to add support for svelte specific 'smarts' (e.g. diagnostics, autocomplete, etc) to any editor without reinventing the wheel.

## Features

Svelte language server is under development and the list of features will surely grow over time.

Currently Supported:

-   Svelte
    -   Diagnostic messages for warnings and errors
    -   Svelte specific formatting (via [prettier-plugin-svelte](https://github.com/UnwrittenFun/prettier-plugin-svelte))
-   HTML (via [vscode-html-languageservice](https://github.com/Microsoft/vscode-html-languageservice))
    -   Hover info
    -   Autocompletions
    -   [Emmet](https://emmet.io/)
    -   Symbols in Outline panel
-   CSS / SCSS / LESS (via [vscode-css-languageservice](https://github.com/Microsoft/vscode-css-languageservice))
    -   Diagnostic messages for syntax and lint errors
    -   Hover info
    -   Autocompletions
    -   Formatting (via [prettier](https://github.com/prettier/prettier))
    -   [Emmet](https://emmet.io/)
    -   Color highlighting and color picker
    -   Symbols in Outline panel
-   TypeScript / JavaScript (via TypeScript)
    -   Diagnostics messages for syntax errors, semantic errors, and suggestions
    -   Hover info
    -   Formatting (via [prettier](https://github.com/prettier/prettier))
    -   Symbols in Outline panel
    -   Autocompletions
    -   Go to definition
    -   Code Actions

## How can I use it?

Install a plugin for your editor:

-   [VS Code](https://github.com/UnwrittenFun/svelte-vscode)
-   [Atom](https://github.com/UnwrittenFun/svelte-atom)
-   [(Neo)vim](https://github.com/coc-extensions/coc-svelte)

repository: orta/language-tools

gha_language: TypeScript

gha_license_id: MIT

repo_name: orta/language-tools


text:
# serverless-boilerplate
This is a boilerplate for serverless framework with architectural best practices

# Installation - Backend
- setup aws credentials in .aws directory
- cd backend && npm install
- serverless deploy

# Angular Client
- cd client-angular
- Replace graphQL API_URL in app/services/common.service.js with your API_URL
- gulp server

repository: mjzone/serverless-react-boilerplate

repo_name: mjzone/serverless-react-boilerplate


text:
# Contributing

If you want to contribute please follow the guide in this file.

<!-- toc -->

- [Pull request](#pull-request)
- [Issues](#issues)
- [Development](#development)
- [New release](#new-release)

<!-- tocstop -->

## Pull request

Ensure that the changes are tested and documented.
DO NOT commit any built versions.

This project uses commitizen and conventional changelog. Please use either
to ensure that the changes are listed correctly and the commits can be parsed.

Squash before merging and remove the source branch.

## Issues

Please include the browser and operating system.

A snippet of example code helps a lot, a link to the repo with the issue helps even more.
If the issue can be seen live please provide a link.

Include info about your development environment

* Chrome version

## Development

`npm <command>`

* `start`: starts the development server

## New release

* `npm version` to update the version & the docs/CHANGELOG.md
* `npm run release`: This will publish the release on npm and push the released tag to GitHub


text:
This is code developed by BBN to support the
2015 KBP Event Argument and Linking Shared Task.
A description of this task may be found [here](http://www.nist.gov/tac/2015/KBP/Event/Argument/guidelines.html).

This repository contains three artifacts:
* `kbp-events2014` contains classes to represent system responses, assessments, and linkings for
the task. While these are mainly to support the executables in this repository,
if your system is based on Java or another JVM language, you are strongly encouraged
to use them.  Note that they can be used from Python via Jython.
* `kbp-events2014-scorer` contains the scoring code (but not scoring binary).
* `kbp-events2014-bin` contains all the executable programs: the validator, the pooler, the scorer, etc.

## Building

Requirements:
* [Maven](http://maven.apache.org/)

Build steps:
* Do `mvn install` from the root of this repository.
* do `chmod +x kbp-events2014-bin/target/appassembler/bin/*` (you only need to do this the first time)
* do `chmod +x kbp-events2014-scorer/target/appassembler/bin/*` (you only need to do this the first time)

[![Build Status](https://semaphoreci.com/api/v1/projects/a11da8fb-4e16-48bf-af3a-a4e1680f161e/467466/badge.svg)](https://semaphoreci.com/rgabbard-bbn/kbp-2014-event-arguments)

## Using
### System Output Stores and Annotation Stores
A _system output store_ represents the output for a KBP Event Argument system on
a collection of documents. It consists of a directory containing exactly one
file per input document, named by the docID. The internal format of these files
is described in the task specification linked to above.

An _annotation store_ contains assessments of the answers from a system output
store.  Its format is the same as a system output store except within the files
there are additional assessment columns, as described in the task specification.

A _linking store_ groups arguments into event frames.  It consists of a directory
containing exactly one file per input document, named by the docID. The internal format
of these files is described in the task specification linked to above.

### Evaluation Workflow

The following workflow will be used during the evaluation.  All executables referenced below may be found in
either `kbp-events2014-bin/target/appassembler/bin` or `kbp-events-2014-scorer/target/appassembler/bin`.

* a 'quote filter' to remove material with CAS and BF offsets in quoted regions
will be built from the original text of the data set.
* competitor submissions will be validated using `validateSystemOutput`.
* all material from quoted regions will be removed from competitor submissions.
* all submissions will be combined into a single system output store using
`poolSystemOutput`.
* this combined system output store will be transformed into an annotation store
using `importSystemOutputToAnnotationStore`.
* LDC annotators will assess this annotation store.
* LDC annotators will link all correctly assesses linkable responses to create reference linkings
for each document.
* All competitor submissions will be evaluated against the complete annotation
store and reference linkings using `KBP2015Scorer`.

### Parameter Files
Most of the executables take parameter files as input.  These have the format
```
key1: value1
# this is a comment!
key2: value2
```

### `validateSystemOutput`
This program will check that your submission:
* has the correct format
* contains only legal event roles and types

If either of these fail, the program will halt with an error message. In the future,
we plan to add enforcement of rules concerning what portions of answers may
come from within `<quote>` regions.

Additionally, this program will dump to standard output a human-readable version
of your responses with all offsets resolved to strings from the original documents
so that you can check for mistakes.

This program takes the following parameters:
* `systemOutputStore`: the path of the system output store to be validated
* `validRoles`: is `data/2014.types.txt` (for KBP 2014)
* `dump`: whether to dump response to `stdout` in a human readable format.
* `docIDMap`: (required if `dump` is `true`) a list of tab-separated pairs of doc ID and path to the
them to standard output.

Note that this currently does not validate linkings.

### `poolSystemOutput`
Combines the system output from multiple systems into a single system output store.

Parameters:
* `storesToPool`: a file listing paths to stores to pool, one per line
* `pooledStore`: the location to write the pooled store to
* `addMode`: either `CREATE` to create a new store for output (overwriting anything
currently there) or `ADD` to append to an existing store.

### `importSystemOutputToAnnotationStore`
Turns a system output store into an annotation store ready for LDC's annotators.

Parameters:
* `argumentOutput`: system output to import
* `annotationStore`: location to create annotation store. The program will
refused to create a new annotation store over an existing, non-empty one.

### `KBP2015Scorer`
Scores system output against an annotation store.

Parameters:
* `answerKey`: the path to an annotation store containing assessments for all system responses
* `referenceLinking`: the path to the reference linking store
* `documentsToScore`: a file listing the IDs of the documents to be scored, one per line
* either `argumentOutput` or `systemOutputsDir`.  If `argumentOutput`, the value must be a path to the system output to be scored.  This path must have an `arguments` and a `linking` subdirectory containing a system output store and a linking store, respectively.  If `systemOutputsDir`, the path must contain sub-directories representing the outputs of multiple systems.  Each such sub-directory must have the format described above for `argumentOutput`.
* neutralizeRealis: map all realises in system input and the answer key to ACTUAL. This will be false for the evaluation, but setting it to true can be useful for diagnostic purposes.
*attemptToNeutralizeCoref: Another diagnostic parameter. If set to true, attempts to minimize the impact of system coreference errors on scoring by
  * Leaving untouched any system response whose base filler assessment correctness matched its CAS assessment correctness.
  * For other responses, if the base filler assessment is correct, replace the response with another which matches it in type, role, and base filler but with a correctly annotated CAS, if possible.  If this is not possible, replace it with any correcrly assessed response match its type and role.  If this is still not possible, delete the response.

## Baseline linking
We provide a baseline implementation of event argument linking for those who wish to try out the 2015 scorer but have not yet developed their own algorithm.  This baseline implementation simply links together all arguments of the same event type in a document.  To run this, use `ApplyLinkingStrategy`.

Parameters:
* `argumentSystemStore`: the system's argument output
* `linkingSystemStore`: the path to write the baseline linking to

## Questions
### How can I use the `Response`, etc. in my system's code?
Add the following to the `dependencies` section of your project's `pom.xml` (or take similar steps if using Gradle, etc.):
```
<dependency>
      <groupId>com.bbn.kbp.events2014</groupId>
      <artifactId>kbp-events2014</artifactId>
      <version>current version listed in pom.xml of this repository</version>
</dependency>
```
This artifact is not deployed to Maven Central, so you will need to
install it in your local repository as described above.

## Contact
For questions concerning the software, please contact<EMAIL_ADDRESS> If you
have bugs or feature requests, you can use the GitHub Issue Tracker. The issue tracker is preferred so future users can benefit from the answers to your questions. To track changes to this repository, follow https://github.com/rgabbard-bbn/kbp-2014-event-arguments/commits/master.atom in an RSS reader.

repository: osgirl/tac-kbp-eal

repo_name: osgirl/tac-kbp-eal


text:
# UETsegmenter

UETsegmenter is a toolkit for Vietnamese word segmentation. It uses a hybrid approach that is based on longest matching with logistic regression.

UETsegmenter is written in Java and developed in Esclipse IDE.

## Note
UETsegmenter was inherited in [UETnlp](https://github.com/phongnt570/UETnlp). UETnlp is a toolkit for Vietnamese text processing which can be used for word segmentation and POS tagging. UETnlp is much easier to use than UETsegmenter.

## Overview

+ ```src``` : folder of java source code

+ ```uetsegmenter.jar``` : an executable jar file (see [How to use](#how-to-use))

+ ```models``` : a pre-trained model for Vietnamese word segmentation

+ ```dictionary``` : necessary dictionaries for word segmentation

## How to use

The following command is used to run this toolkit, your PC needs JDK 1.8 or newer:

```
java -jar uetsegmenter.jar -r <what_to_execute> {additional arguments}

	-r	:	the method you want to execute (required: seg|train|test)
```

Additional arguments for each method:

+ ```-r seg``` : Method for word segmentation. Needed arguments:

```
-m <models_path> -i <input_path> [-ie <input_extension>] -o <output_path> [-oe <output_extension>]

	-m	:	path to the folder of segmenter model (required)
	-i	:	path to the input text (file/folder) (required)
	-ie	:	input extension, only use when input_path is a folder (default: *)
	-o	:	path to the output text (file/folder) (required)
	-oe	:	output extension, only use when output_path is a folder (default: seg)
```

+ ```-r train``` : Method for training a new model. Needed arguments:

```
-i <training_data> [-e <file_extension>] -m <models_path>

	-i	:	path to the training data (file/folder) (required)
	-e	:	file extension, only use when training_data is a folder (default: *)
	-m	:	path to the folder you want to save model after training (required)
```

After training, the ```models_path``` folder will contain 2 files: ```model``` and ```features```.

+ ```-r test``` : Method for testing a model. Needed arguments:

```
-m <models_path> -t <test_file>

	-m	:	path to the folder of segmenter model (required)
	-t	:	path to the test file (required)
```

## APIs

3 APIs for Vietnames word segmentation are provided:

+ Segment a raw text:

```java
	String modelsPath = "models"; // path to the model folder. This folder must contain two files: model, features
	UETSegmenter segmenter = new UETSegmenter(modelsPath); // construct the segmenter
	String raw_text_1 = "Tốc độ truyền thông tin ngày càng cao.";
	String raw_text_2 = "Tôi yêu Việt Nam!";

	String seg_text_1 = segmenter.segment(raw_text_1); // Tốc_độ truyền thông_tin ngày_càng cao .
	String seg_text_2 = segmenter.segment(raw_text_2); // Tôi yêu Việt_Nam !

	// ... You only need to construct the segmenter one time, then you can segment any number of texts.
```

+ Segment a tokenized text:

```java
	// ...
	// ... construct the segmenter

	String tokenized = "Tôi , bạn tôi yêu Việt Nam !";
	String segmented = segmenter.segmentTokenizedText(raw_text_2); // Tôi , bạn tôi yêu Việt_Nam !
```

+ Segment a raw text and return list of segmented sentences:

```java
	// ...
	// ... construct the segmenter

	String text = "Tốc độ truyền thông tin ngày càng cao. Tôi, bạn tôi yêu Việt Nam!";
	List<String> segmented_sents = segmenter.segmentSentences(text); // [0] : Tốc_độ truyền thông_tin ngày_càng cao .
																	// [1] : Tôi , bạn tôi yêu Việt_Nam !
```

## Citation

If you use the toolkit for academic work, please cite:

```
@INPROCEEDINGS{7800279,
	author={T. P. Nguyen and A. C. Le},
	booktitle={2016 IEEE RIVF International Conference on Computing Communication Technologies, Research, Innovation, and Vision for the Future (RIVF)},
	title={A hybrid approach to Vietnamese word segmentation},
	year={2016},
	pages={114-119},
	doi={10.1109/RIVF.2016.7800279},
	month={Nov},
}
```

The approach used in the toolkit is also explained in the paper.

repository: comfyneet/BachelorThesis

repo_name: comfyneet/BachelorThesis


text:
---
title: 'Touch Bar does not change to f1-f12 when I press the fn key'
weight: 300
---

It's an issue of macOS, and unfortunately, Karabiner-Elements cannot avoid this issue.

Instead, please change fn+number keys to function keys in Karabiner-Elements configuration.

1.  Import [Map fn + number keys to function keys](https://ke-complex-modifications.pqrs.org/#fn_plus_numbers_to_function_keys)
2.  Enable `Map fn + number keys to their corresponding function keys`.
3.  You can use f1-f12 keys by fn+number keys.
    {{< local-image<EMAIL_ADDRESS>>}}

{{% alert title="Note" color="primary" %}}
If you are using "Use all F1, F2, etc. keys as standard function keys.",
enable `Map fn + number keys to their corresponding media control keys` instead.
{{% /alert %}}

{{% alert title="Detail of the problem" color="dark" %}}
The fn key events are ignored by Touch Bar since the following facts.

-   Touch Bar accepts the fn key event only from the build-in keyboard.
-   The fn key events are sent from Karabiner's virtual keyboard when Karabiner-Elements is running.

Unfortunately, posting input events via own virtual keyboard is the only way to accomplish the stable input event modification.

In other words, we cannot post the fn key event through the built-in keyboard if we want to change key events stably.
{{% /alert %}}

license: Unlicense

branch_name: refs/heads/main

gha_language: HTML

gha_license_id: Unlicense


text:
## Problem description

Find and display all pairs of 5-digit numbers that collectively use the digits 0 through 9 once each, such that the first number divided by the second is equal to an integer N, where 2 <= N <= 79. That is, abcde / fghij = N, where each letter represents a different digit.

## Algorithm analysis

Complete search solution:
Through analysis, we can find that fghij must fall into the range of [1234, 98765 / N], so we enumerate all possible values of fghij and calculate the corresponding abcde, then check whether they used every digit from 0 through 9.
The number of total operations we would execute is at most 50K * 10 = 500K, so it can be solved within one second.

## Knowledge base

1. For a complete search solution, we need to quickly find the minimum range of possible values for the related variables in the problem.
   For example, in this problem the original range of fghij is [1234, 98765]. With considering the given value of N, we can shrink the range into [1234, 98765 / N].

2. To check whether a set of size N of integers have covered all digits or numbers from 0 through N-1, we can use the bit manipulation method:
   Starting from an bitmask 0, scan each integer x in the set and use the bit manipulation to set the xth bit in the bitmask. If the set covers from 0 through N-1, after setting all the corresponding bits, the bitmask would be equal to 2^N-1 (0b1111...1111). The example code is like:

   ```c++
   int used = 0;
   for (int i = 0; i != N; ++i)
       used |= (1 << x[i]);
   return used == (1 << N) - 1;
   ```

repository: jinxinwangstd/UVa-Online-Judge

repo_name: jinxinwangstd/UVa-Online-Judge


text:
# L1000FWD Consensus Drugs

This Appyter takes up and down gene sets and returns the consensus mimicker and reverser drugs associated to them. It sends the up and down gene sets to [L1000FWD](https://amp.pharm.mssm.edu/l1000fwd/) to get the top 50 mimicker and reverser signatures. It then counts the number of times a drug appear in the top 50 signatures of a query gene set. The appyter only keeps drugs that appear in a certain percentage of query gene sets defined by **drug percentage**. The p-value for each drug is then computed using a pre-computed empirical distribution using [CREEDS](https://amp.pharm.mssm.edu/creeds/#downloads) gene sets as background signatures. The drugs are then visualized using [clustergrammer](https://amp.pharm.mssm.edu/clustergrammer/). A publication ready static heatmap is also provided for the users.

## File Format
The appyter takes up and down gene sets gmt files with the following format:
```
signature 1\t\tGENE 1\tGENE 2\tGENE 3
signature 2\t\tGENE 3\tGENE 4\tGENE 5
signature 3\t\tGENE 2\tGENE 5\tGENE 6
signature 4\t\tGENE 1\tGENE 2\tGENE 6
```

Signature names should be _the same_ on both up and down gmt files. Below are the sample up and down gene sets:

* [Up Gene Set](https://appyterbucket.s3.amazonaws.com/sample_data/up_down_signatures/up_diseases)
* [Down Gene Set](https://appyterbucket.s3.amazonaws.com/sample_data/up_down_signatures/down_diseases)

## References
[1] Wang Z, Lachmann A, Keenan AB, Ma'ayan A (2018) L1000FWD: fireworks visualization of drug-induced transcriptomic signatures. Bioinformatics doi: 10.1093/bioinformatics/bty060

[2] Wang, Z., Monteiro, C. D., Jagodnik, K. M., Fernandez, N. F., Gundersen, G. W., ... & Ma'ayan, A. (2016) Extraction and Analysis of Signatures from the Gene Expression Omnibus by the Crowd. Nature Communications doi: 10.1038/ncomms12846

[3] Fernandez, N. F. et al. Clustergrammer, a web-based heatmap visualization and analysis tool for high-dimensional biological data. Sci. Data 4:170151 doi: 10.1038/sdata.2017.151 (2017).


text:
# Parity Terminal Client

Parity Terminal Client is a simple console application for entering orders
into the trading system. This version configures a Parity market as needed for this project.

See the uploaded ZIP archive; instructions below.

## Instruments and Setup
The file *hourly-1.conf* in the respective *etc-system* and *etc-client* directories creates one order
book for each **instrument** which represents each one hour period on February 20, 0220-00 through 0220-23 using month-only ISO 8601 dates.

The conf files for the server and client are different but coordinated; the server ignores
requests that use an instrument that is not configured.

The client code is the basis for the RESTcontroller for the NIST-CTS-Agents project, which will use the same entry points for entering orders and getting matches, mapping the internal timestamp IDs to the
CTS transactionIDs.

The product for all instruments is energy, with the time specifying the instrument in Parity.

## Usage

See the file *parity-orders.txt* in the directory *CTSsamples*; output is in *parity-orders.out.txt* in the same directory. Order lines are copied and pasted as shown.

For these specific inputs and outputs start the system server in the background with

````
java -jar parity-system.jar system-etc/hourly-1.conf&
````

Followed by running the client in a terminal window:

````
java -jar parity-client.jar client-etc/hourly-1.conf
````

The general case Parity instructions follow.

Run Parity Terminal Client with Java:

```
java -jar parity-client.jar <configuration-file>
```

The command line arguments are as follows:

- `<configuration-file>`: A configuration file. The configuration file
  specifies how to connect to the trading system.

Once started, the application displays a command prompt:

```
Type 'help' for help.
>
```

You can interact with the application by entering commands into the command
prompt. For example, to enter a buy order, use the `buy` command:

```
> buy 100 AAPL 150.00
```

The command enters a buy order of 100 units of the instrument AAPL at the
limit price of 150.00 into the trading system. Assuming that AAPL can be
traded on the trading system and that there is no matching sell order in
the order book, the order will remain open. To list the open orders, use
the `orders` command:

```
> orders
```

Use the `help` command to see a list of all available commands.

## Configuration

Parity Terminal Client uses a configuration file to specify how to connect to
the trading system.

The following configuration parameters are required:

```
order-entry {

    # The IP address of the trading system.
    address = <IP_ADDRESS>

    # The TCP port for order entry at the trading system.
    port = 4000

    # The order entry username.
    username = parity

    # The order entry password.
    password = parity

}

instruments {

    # The number of digits in the integer part of a price.
    price-integer-digits = 4

    # The number of digits in the integer part of a size.
    size-integer-digits = 7

    AAPL {

        # The number of digits in the fractional part of a price.
        price-fraction-digits = 2

        # The number of digits in the fractional part of a size.
        size-fraction-digits = 0

    }

}
```

See the `etc` directory for an example configuration file.

## License

Released under the Apache License, Version 2.0.

repository: EnergyMashupLab/NIST-CTS-Agents

gha_language: Java

repo_name: EnergyMashupLab/NIST-CTS-Agents


text:
# Specifications for the Sinatra Assessment

Specs:
- [x] Use Sinatra to build the app
- [x] Use ActiveRecord for storing information in a database --
      See Migrations -- tables built for users, records, artists, and labels, as well as join table for record_users

- [x] Include more than one model class (list of model class names e.g. User, Post, Category) --
      Models for each of the aformentioned tables, as well as "slugify" module for converting model :name attributes to URL

- [x] Include at least one has_many relationship (x has_many y e.g. User has_many Posts) --
      Artists, Users, and Labels have many Records, Records have many Users, Users have many Artists through Records, etc.

- [x] Include user accounts --
      User accounts with encrypted passwords included

- [x] Ensure that users can't modify content created by other users --
      Attempts to access another user's content result in redirect to logged-in user's Index page

- [x] Include user input validations --
      All view routes verify user is valid and logged in before displaying content

- [ ] Display validation failures to user with error message (example form URL e.g. /posts/new)

- [ ] Your README.md includes a short description, install instructions, a contributors guide and a link to the license for your code

Confirm
- [x] You have a large number of small Git commits
- [x] Your commit messages are meaningful
- [x] You made the changes in a commit that relate to the commit message
- [x] You don't include changes in a commit that aren't related to the commit message

repository: kevinladkins/Record-Collector

repo_name: kevinladkins/Record-Collector


text:
---
layout: note
tags:
  - tech
  - computer-science
  - book
  - learning
  - ai
---

# Fastbook

YouTube Playlist: https://youtube.com/playlist?list=PLD80i8An1OEHdlrBwa7mKFaHX9tH86b93

Notes from the [Fastbook][1].

### Overview

The simplest equation that can power an AI is:

```python
w*x + b = y
```

- Where `x` is the input, `y` is the output. `w` and `b` are parameters, i.e. weights and biases (so that `x=0` is handled).
- During training, we learn the perfect values for `w` and `b` for the given values of `x` and `y`.
- During prediction, we use the same equation with the learned values of `w` and `b` to get the value of `y` for a given value of `x`.

### Chapter 1: Intro

- GPUs are capable of PDP (parallel distributed processing), an important ability necessary to train AI models mimicking the neural networks in our brain.
- As of now it's preferable to rent GPUs than to buy them because
  - Prices and specs are rapidly changing.
  - Hard to setup.
  - Hard to maintain.
- "Deep Learning" is the state of the art machine learning approach, usable in a wide range of applications.
- Two things can be learned by AI are - text and visual data.
- Many kinds of data (e.g. sound, temperature) can be represented as pictures, and thus be used by a visual learner.
- An "architecture" is the implementation of a deep leaning algorithm that can recognize patterns from the given set of inputs and outputs, and use them to predict outputs for future inputs, even unseen ones.
- A "model" is an instance of an architecture with parameters, i.e. an instance of an architecture that has learned things.
- "resnet34" is an example of a pre-trained model using the CNN (Convolutional Neural Network) architecture with 34 layers.
- While learning, the model goes through the training data, often multiple times, each time, storing the recognized patterns in its layers as values called "parameters" aka "weights" + "biases".
- The last layer of a model, aka the "head", stores the most specialized parameters for the dataset it has been trained on.
- While training a pre-trained model, the parameters in the latter layers, specially the head is replaced with new parameters acquired from the new dataset.
- It's easier and faster to fine-tune, i.e. train a pre-trained model (aka transfer learning), than training one from scratch.
- Before training, the learner sets aside about 20% of the data for validation after the training.
- Use the same set of data for validation in all iterations to avoid bias.
- The error rate (percentage of incorrect predictions) should reduce after each epoch (iteration) of processing the dataset.
- Too much training on limited data can cause over-fitting, i.e. the model starts memorizing outputs for the given inputs, rather than predicting.
- Over-fitting will cause error rate to increase.
- There the two kinds of predictions: Classification and regression.
- Classification: given an input, predict the matching label as output from a given set of discrete labels (e.g. recognizing dogs vs cats).
- Regression: given a continuous series of inputs, predict the future trajectory of the series as output (e.g. predicting temperature changes).

```python
# Import all the useful utilities to train a visual learning model
from fastai.vision.all import *

# Download and extract dataset
path = untar_data(URLs.PETS)/'images'

# Function to process a filename and return the label
def is_cat(x):
  return x[0].isupper()

# A loader that can load data and label them by processing filenames
data_loaders = ImageDataLoaders.from_name_func(
  path,  # path to the dataset
  get_image_files(path),  # The input data.
  valid_pct=0.2,  # Set aside 20% for validation after training.
  seed=42,  # Use the same seed in each epoch to ensure same set of validation data is used.
  label_func=is_cat,  # Function to process labels from filename
  item_tfms=Resize(224),  # Resize the images to the same size for processing them efficiently in GPU.
  # item_tfms=RandomResizedCrop(128, min_scale=0.35),  # Alternative
)

# Use a CNN implementation with 34 layers
architecture = resnet34

# Use predefined function error_rate for validating and measuring the quality
metric = error_rate

# Initialize the vision learner model
learner = vision_learner(
  data_loaders,
  architecture,
  metrics=metrics,
)

# Fine-tune the pre-trained model in 1 epoch (iteration)
learner.fine_tune(1)
```

### Chapter 2: Production

- Use the [Drivetrain][3] approach to get better results.
- When training vision learning models, use Data Augmentation i.e. transform the training images by cropping, rotating, applying filters etc.
- Think about the possible biases in the dataset.
- Train a small model first, and use that to clean the data before training bigger models.
- Data cleaning can be done by plotting confusion matrix (`ClassificationInterpretation().plot_confusion_matrix()`).
- Create notebook apps as POC first.
- To avoid disaster, do human checks, keep the scope limited, expand gradually.
- Be aware of positive feedback loops, where the model starts learning biases when data doesn't represent the intention.

### Chapter 3: Ethics

Computers can be (too) powerful. Be responsible.

### Chapter 4: MNIST basics

- MNIST is a popular dataset containing images of handwritten digits.
- We generally use the Image library from PIL to work on images, it's supported directly by Jupyter Notebook.
- numpy "array" and pytorch "tensor" are mathematical data structures (matrix) that can store values of any dimension.
  - Single digit i.e. scalar i.e. rank 0
  - Array of digits i.e. vector i.e. rank 1
  - Array of array of digits i.e. matrix i.e. rank 2
  - Multi rank matrix and matrices
- They are almost similar, but tensor restricts its elements to be of the same type and shape, which lets it utilize the GPU and provide some other conveniences required for deep learning.
- Images can be stored in a tensor by dividing each pixel by 255.
- Image stored in a tensor can be shown in Jupyter notebook using the `show_image()` function.
- Multiple images can be stacked into a tensor using the `torch.stack()` function.
- The first axis of the stacked tensor is the indexes of the images.
- To implement a simple digit recognizer without using deep learning is to compare the target image with the ideal image (mean of all the images of the same category).
- Get the mean image of all stacked images using the `.mean()` method.
- `.mean((-1,-2))` will take the mean ranging over the values indexed by the last two axes (horizontal, vertical) of the stacked tensor.
- Get the mean absolute value loss (L1 loss) (`(img1-img2).abs().mean()`) using the `F.l1_loss()` function.
- Get the mean squared error (MSE) (`((img1-img2)^2).mean().sqrt()`) using the `F.mse_loss()` function.
- These functions can be used to get the differences between two images.
- As compared to L1 loss, MSE is more strict towards large differences.

Typical deep learning flow:

```mermaid
flowchart LR;
  init-->predict-->loss-->gradient-->step-->stop
  step--repeat-->predict
```

- Init: Initialize the parameters to random values.
- Loss: A number that is small for good performance (prediction).
- Gradient: A measure of - for each weight, how changing that weight would change the loss, i.e. d(loss) / d(weight), for each weight, treating other weights as constant.
- Step: Increase of decrease the weights a bit to minimize the loss. Use calculus magic to avoid doing it the slow way (i.e. try and measure).
- Stop: We can stop the loop either after a specific number of iterations (epochs), or until the accuracy starts degrading.

Code for implementing (unoptimized) linear learner for classifying images of 3s and 7s and training it:

```python
def sigmoid(x):
    """Function to ensure the loss is between (0, 1)."""
    return 1 / (1 + torch.exp(-x))

def batch_accuracy(predictions_batch, targets_batch):
    preds = predictions_batch.sigmoid()  # i.e. sigmoid(prediction_batch)
    threes = preds > 0.5
    correct = threes == targets_batch
    return correct.float().mean()

def mnist_loss(predictions, targets):
    predictions = predictions.sigmoid()

    # Similar to [(1-predictions)[i] if targets[i]==1 else predictions[i] for i in range(len(targets))]
    # but faster (uses GPU)
    loss = torch.where(targets==1, 1-predictions, predictions).mean()

    return loss

def init_params(size, std=1.0):
    params = torch.randn(size) * std

    # Tell pytorch to track the gradient, i.e. d(loss) / d(weight) for each param
    # which is updated via `params.backward()`, and accessible via params.grad
    params = params.requires_grad_()

    return params

# Similar to Pytorch's nn.Linear()
class LinearModel:
    """A simple linear model."""
    def __init__(self, in_features, out_features):
        self.weights = init_params((in_features, out_features))  # torch.Size([in_features, out_features])
        # w*x will always be 0 if "x" is 0. Hence, we need a bias "b"
        # So, the eq is: y = w*x + b
        self.bias = init_params(out_features)  # torch.Size([out_features])

    def parameters(self):
        return self.weights, self.bias

    def __call__(self, xb):
        return (xb @ self.weights) + self.bias  # Matrix multiplication

class SimpleLearner:
    """A simple learner to train models."""
    def __init__(self, data_loaders, model):
        self.data_loaders = data_loaders
        self.model = model

    def calculate_gradient(self, image, target):
        """Calculate gradients i.e. slope i.e. `d(loss) / d(weight)` of weights and biases.

        If it's is very small, it means we're closer to the optimal value.
        """

        predictions = self.model(image)
        loss = mnist_loss(predictions, target)

        # Updates self.model.parameters[n].grad for each layer, see init_params()
        # It could've been named `.calculate_gradient()` to make life easier.
        loss.backward()

    def step(self, learning_rate):
        """Step function to update the weights and biases.

        If learning rate is too low, it might require a lot of steps to reach the optimal value.
        If learning rate is too high, it might result in loss getting worse, or bounce around in circles.
        """
        for param in self.model.parameters():
            param.data -= param.grad.data * learning_rate

    def reset_gradient(self):
        """Reset the calculated gradients."""
        for p in self.model.parameters():
            p.grad = None

    def train_epoch(self, learning_rate):
        for batch_of_images, batch_of_targets in self.data_loaders.train:
            self.calculate_gradient(batch_of_images, batch_of_targets)
            self.step(learning_rate)
            self.reset_gradient()

    def validate_epoch(self):
        accuracy = []
        for batch_of_images, batch_of_targets in self.data_loaders.valid:
            batch_of_predictions = self.model(batch_of_images)
            acc = batch_accuracy(batch_of_predictions, batch_of_targets)
            accuracy.append(acc)

        return round(torch.stack(accuracy).mean().item(), 4)

    def train_model(self, epochs, learning_rate):
        for _ in range(epochs):
            self.train_epoch(learning_rate)
            print(self.validate_epoch(), end=' ')

# Load data from MNIST dataset
path = untar_data(URLs.MNIST_SAMPLE)
Path.BASE_PATH = path

# Load images into pytorch tensors

# Load data from MNIST dataset
path = untar_data(URLs.MNIST_SAMPLE)
Path.BASE_PATH = path

# Load images into pytorch tensors

train_threes = (path/'train'/'3').ls().sorted()
train_threes = torch.stack([tensor(Image.open(o)) for o in train_threes]).float() / 255

valid_threes = (path/'valid'/'3').ls().sorted()
valid_threes = torch.stack([tensor(Image.open(o)) for o in valid_threes]).float() / 255

train_sevens = (path/'train'/'7').ls().sorted()
train_sevens = torch.stack([tensor(Image.open(o)) for o in train_sevens]).float() / 255

valid_sevens = (path/'valid'/'7').ls().sorted()
valid_sevens = torch.stack([tensor(Image.open(o)) for o in valid_sevens]).float() / 255

train_images = torch.cat([train_threes, train_sevens]).view(-1, 28*28)
train_targets = tensor([1]*len(train_threes) + [0]*len(train_sevens)).unsqueeze(1)
train_dset = list(zip(train_images, train_targets))

valid_images = torch.cat([valid_threes, valid_sevens]).view(-1, 28*28)
valid_targets = tensor([1]*len(valid_threes) + [0]*len(valid_sevens)).unsqueeze(1)
valid_dset = list(zip(valid_images, valid_targets))

# DataLoader builds on top of Dataset, and adds additional functionalitiies.
# Batch size is a tradeoff between speed vs GPU memory
train_dl = DataLoader(train_dset, batch_size=256)
valid_dl = DataLoader(valid_dset, batch_size=256)

# DataLoaders builds on top of Datasets
data_loaders = DataLoaders(train_dl, valid_dl)

# Using our custom learner
model = LinearModel(28*28, 1)
learner = SimpleLearner(data_loaders, model)
learner.train_model(20, learning_rate=1.0)

## Similar to Pytorch's Learner
# model = nn.Linear(28*28, 1)
# learn = Learner(data_loaders, model, opt_func=SGD, loss_func=mnist_loss, metrics=batch_accuracy)
# learn.fit(20, lr=1.0)
#
## Plot the recorded learning proces with
# plt.plot(L(learn.recorder.values).itemgot(2));
# print("Final accuracy:", learn.recorder.values[-1][2])
```

- To turn it into a more complex and capable neural network, we need to add more layers.
- Just adding more linear layers isn't very useful because multiple linear layers in a row can be represented
  with one single layer with a different set of parameters. It's not true if there's a non-linear layer
  between them (e.g. ReLU).
- Deeper models, i.e. models with more layers require less parameters, hence are faster, but harder to train (i.e. optimize the params).

```python
class SimpleNet:
    """A simple multi layer neural network."""
    def __init__(self, in_features, out_features):
        # Layer 1: Linear
        # Has 30 output activations, meaning the first layer can construct 30 different
        # features, each representing some different mix of pixels, it can be anything based on
        # complexity.
        self.layer1 = LinearModel(in_features, 30)

        # Layer 2: Nonlinearity a.k.a Activation Function
        # Similar to `F.relu` i.e. Rectified Linear Unit to replace all negative numbers to zero.
        self.layer2 = lambda xb: xb.max(tensor(0.0))

        # Layer 3: Linear
        # Must have 30 inputs activations so they match.
        self.layer3 = LinearModel(30, out_features)

    def parameters(self):
        w1, b1 = self.layer1.parameters()
        w2, b2 = self.layer3.parameters()
        return w1, b1, w2, b2

    def __call__(self, xb):
        res = self.layer1(xb)
        res = self.layer2(res)
        res = self.layer3(res)
        return res

model = SimpleNet(28*28, 1)

## Similar to Pytorch's
# model = nn.Sequential(
#     nn.Linear(28*28, 30),  # Layer 1
#     nn.ReLU(),             # Layer 2
#     nn.Linear(30, 1),      # Layer 3
# )
```

### Chapter 5: Pet Breeds

- "Presizing" of images is necessary to ensure images are of the same dimension, so they can collate into tensors.
- To make the presizing transformations faster without losing pixels:
  - `item_tfms`: First resize image to a relatively larger dimension to avoid empty spaces after the transformations.
  - `batch_tfms`: Compose all other transformations, including resizing to the final dimension, into one single transformation, and perform it in GPU.
- Use `DataLoaders().show_batch(nrows: int, ncol: int)` to ensure data and labels are correct. Use `.summary(path: Path)` to debug issues.
- If not provided, fastai will select a loss function automatically based on the dataset.
- Use `DataLoaders().one_batch()` to get a batch of tensors, and pass it to `Learner().get_preds()` to get predictions for it.
- "Softmax", a multi-category equivalent of "Sigmoid", is an activation function used in the final layer to ensure the numbers are between 0-1 and add up to 1.

  ```python
  # For any increase in x, exponential(x) increases very rapidly.
  # It ensures all the numbers are positive, and amplifies the slightly bigger numbers
  exponential = lambda x: e ** x  # e ~= 2.718,

  # Dividing by sum ensures all the numbers add up to 1
  softmax = lambda x: exponential(x) / exponential(x).sum(dim=1, keepdim=True)
  ```

- For more that two categories, we need an activation per category.
- Logarithms increase linearly when the underlying signal increases exponentially or multiplicatively.

  ```python
  log(a * b) = log(a) + log(b)
  ```

  i.e. multiplication, which can create really large or really small numbers, can be replaced by addition,
  which is much less likely to result in scales that are difficult for computers to handle.

- To classify categories from loss, we need to invert the scale of log function, i.e. `-1 * log(loss)`.
- Cross-Entropy Loss (`nn.CrossEntropyLoss(reduction='none')`/`F.cross_entropy`), aka Negative Log Likelihood loss (`F.nll_loss`) works on images,
  of more than two categories, is faster and reliable. `reduction='none'` disables taking mean of the loss of all items.

  ```python
  cross_entropy = lambda activations, targets: nll_loss(log_softmax(activations, targets))
  ```

- Plot confusion matrix to interpret loss functions.

  ```python
    interp = ClassificationInterpretation.from_learner(learner)
    interp.plot_confusion_matrix(figsize=(12,12), dpi=60)

    # Use this method to get the confusion matrix with the most incorrect predictions.
    interp.most_confused(min_val=5)
  ```

- Use `Learner().lr_find(suggest_funcs=(minimum, steep))` to find a suitable learning rate.
- In general, the first few layers of an image classification model encode very general concepts
  such as finding gradients and edges. Later layer encode more specific but still useful concepts.
- Since the final layer of a (pre)trained model has specific number of activations (output
  for each category) for the classification of the old training data, we replace it with new
  layer(s) with random weights when finetuning.
- Instead of using FastAI's `.fine_tune()` we can also manualy:
  - Train the randomly added layers for one epoch, with all other layers "frozen",
    i.e. `.fit_one_cycle()`.
  - Unfreeze all of the layers, and train them all for the number of epochs requested,
    i.e. `.unfreeze()`, `.lr_find()` and `.fit_one_cycle()` again.
- We can pass learning rate in the format `(initial, final)` to tell FastAI to use a lower
  learning rate initially, and gradually increase it upto a final value in the final layer,
  because we may want to train the later layers quicker than initial layers (not entirely sure why).
  This is called "discriminative learning rate".
- "capacity" of a model = how many layers and parameters does it have?
- The higher the capacity the more GPU RAM it needs. Use smaller batch size (`bs=batch_size`) to avoid:
  ```
  Cuda runtime error: out of memory
  ```
- Use `Learner().to_fp16()` to enable GPU feature "tensor cores" that uses "mixed-precision training"
  i.e. less precise numbers (aka fp16) where possible to achieve 2x-3x speed boost.

### Chapter 6: Multicat

- Pandas DataFrame is used to manipulate tabular or time-series data.
  ```python
  path = untar_data(URLs.PASCAL_2007)
  df = pd.read_csv(path/'train.csv')  # Also supports reading from DB, py dicts and many other sources
  df.head()  # Display preview
  df.iloc[:, 0]  # Access rows and columns by number
  df['fname']  # Access columns by name
  ```
- Use DataBlock to load datasets/dataloaders from DataFrame.
  ```python
  datablock = DataBlock(
    blocks=(
      ImageBlock,  # get_x points to a valid image
      MultiCategoryBlock,  # For multiple labels, rather than single integer
    ),
    get_x=lambda r: path/'train'/r['fname'],
    get_y=lambda r: r['labels'].split(' '),
  )
  datasets = datablock.datasets(df)
  # datasets.train, datasets.valid
  dataloaders = datablock.dataloaders(df)
  ```
- jargon: One-hot encoding: Using a vector of zeros, with a one in each location that is
  represented in the data, to encode a list of integers. e.g.
  ```python
  TensorMultiCategory([0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.])
  ```
  This format is used to keep the size of multi category outputs same.
- Debug models by passing mini batches of data into it.
  ```python
  learn = vision_learner(dataloaders, resnet18)
  x, y = to_cpu(dataloaders.train.one_batch())
  activs = learn.model(x)
  activs.shape
  # torch.Size([64, 20])
  activs[0]
  # TensorBase([-1.4608,  0.9895,  0.5279, -1.0224, -1.4174, -0.1778, -0.4821, -0.2561,  0.6638,  0.1715,  2.3625,  4.2209,  1.0515,  4.5342,  0.5485,  1.0585, -0.7959,  2.2770, -1.9935,  1.9646], grad_fn=)
  ```
- `sigmoid`, `nll_loss`, `softmax`, and thus `cross_entropy` etc won't work with multi category since they return single digit. We need array of digits.
  - F.cross_entropy / nn.CrossEntropyLoss -> F.binary_cross_entropy / nn.BCELoss
    ```python
    def binary_cross_entropy(inputs, targets):
        inputs = inputs.sigmoid()
        return -torch.where(targets==1, inputs, 1-inputs).log().mean()
    ```
  - For one-hot-encoded targets, we need F.binary_cross_entropy_with_logits / nn.BCEWithLogitsLoss.

[1]: https://github.com/fastai/fastbook
[2]: https://www.fast.ai
[3]: https://www.oreilly.com/radar/drivetrain-approach-data-products

gha_language: JavaScript


text:
mc-mms-tls
==========

Sandbox project for testing the handling of SSL on the websocket client and server side.

Testing Self-signed SSL Certificate
================================

Generate server and client keystores and truststores using:

    ./gen-certs.sh

To test server SSL certificate validation, run:

* On the server side, start _SSLServer_.
* On the client side, run the Tomcat and Jetty versions of _JavaX_SystemProperties_ and _JavaX_Programatically_.

To test both client and server SSL certificate validation, run:

* On the server side, start _SSLServerWithClientCertificateValidation_.
* On the client side, run the Tomcat and Jetty versions of _JavaX_ClientCertificate_.

Testing CA-issued Certificate
=============================

If you are using a CA-issued SSL certificate, consult your documentation regarding how to import the certificate + private key
into a java keystore.<br>
If you have used **keytool** to generate a CSR, you will have the private key in a keystore already. You then need to get hold of
a PKCS-7 version of the certificate, and import it into the private key keystore. Something along the lines of:

    keytool -import -keystore maritimecloud.net.jks -alias maritimecloud.net -file cert.p7s

Next, ensure that

* You have added localhost.maritimecloud.net for localhost in /etc/hosts
* The keystore should be placed at ~/cert/maritimecloud.net.jks

Start the websocket server using the class: _SSL_CustomCertificate_.
The java class must be run with a system property for KeyStorePassword, i.e. -DKeyStorePassword=XXX.

Test the tomcat or jetty _JavaX_NoTrust_ clients.

Testing with SSL Proxy Server
=========================

If you wish to test with a proxy-server, such as nginx, in front of MMS and use it to handle SSL-decryption, first convert the keystore to PKCS12:

    keytool -importkeystore -srckeystore maritimecloud.net.jks \
            -destkeystore maritimecloud.net.p12 -deststoretype PKCS12

Extract the pem (certificate) and key from  p12 keystore:

    openssl  pkcs12 -nokeys -in maritimecloud.net.p12 -out nginx-ssl.pem
    openssl pkcs12 -nocerts -nodes -in maritimecloud.net.p12 -out nginx-ssl.key

Configure nginx to point to the pem and key files using the *ssl_certificate* and *ssl_certificate_key* parameters.

repository: dma-graveyard/Sandbox

repo_name: dma-graveyard/Sandbox


text:
# CaveSurv

A cross platform survey data application that will accept measurements from a modified Distox.

Features:

- Create a new survey
- Retrieve previous surveys
- Manually enter measurements
- Capture measurements via bluetooth
- Save measurements to internal storage
- Export as csv, svx etc
- Display survey points and connections
- Draw walls and features

repository: JamesPaganLodge/CaveSurv

repo_name: JamesPaganLodge/CaveSurv


text:
# FirstAppOnGrails
How to create an application in grails Example with Notes by Ketan Pandey. Special thanks to my Seniors
Create Apps on Grails
Step 1 : Run Following Command :
	grails create-app app_name
	cd app_name
	grails run-app
Step 2 : Create Domain Class under a package
	grails create-domain-class com.firstApp.User
	package com.firstApp
	class User {
	    String username;
	    String password;
	    String email;
	    static constraints = {
	        email email: true;
	    }
	}
Step 3 : Generate Controller
grails generate-controller com.firstApp.User
static scaffold = true; // Write in UserController class
Step 4 : Generate View
grails generate-view com.firstApp.User
Step 5 : Run App
grails run-app

repository: ketan-jft/FirstAppOnGrails

repo_name: ketan-jft/FirstAppOnGrails


text:
---
layout: post
title: Intro to Javascript Regexes
---
IN PROGRESS

Regular Expressions (Regex for short) are a powerful technique for searching text.  They allow you to concisely describe a pattern you want to match in a give string.  However, they can also be a little intimidating, as to the beginner they look like a incomprehensible series of symbols (for the ultimate confusing regex example, check out this one for validating email addresses http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html).  In this post, we're going to build up the basics of constructing regexes with a few simple exercises that'll get you regexing in no time.  (Note: this article will be using the syntax of Javascript regexes; there are occasionally small differences between different languages' implementations.)

Basics

The simplest kind of regex is simply a string of characters to match exactly.
For example /cat/ is only going to match the string 'cat'.
To add a bit of flexibility, we can surround some characters in brackets.  This would
indicate a match with any one of the characters within the brackets.  Example: /[cb]at/ will match both 'cat' and 'bat'.

What about repeated characters? for this we can use a '*'.  This will match the preceding element 0 or more times.  /c*at/ will match 'cat', 'cccat', and 'at'.   + has a similar function, except the element must occur at least once (so /c+at/ would not match 'at').  Let's try a few exercises.

1.  write a regex that will match either 'meat' or 'meet'.

2. write a regex to match at least one 's', followed by either a '5' or a '6', followed by any number of 't's.

3.

4. What does this regex do? /[mcb][ia]*n/

Resources:
This site is great for checking that your regexes do what you expect: https://regex101.com/

path: /pending/2015-10-17-Intro to Regex.md

filename: 2015-10-17-Intro to Regex.md


text:
# ALF

![CI](https://github.com/HorizonRobotics/alf/workflows/CI/badge.svg?branch=pytorch)

Agent Learning Framework (ALF) is a reinforcement learning framework emphasizing on the flexibility and easiness of implementing complex algorithms involving many different components. ALF is built on [PyTorch](https://pytorch.org/). The development of [previous version](https://github.com/HorizonRobotics/alf/tree/tensorflow) based on [Tensorflow 2.1](https://www.tensorflow.org/) has stopped as of Feb 2020.

## Tutorial
A draft tutorial can be accessed on [RTD](https://alf.readthedocs.io/en/latest/tutorial.html). This tutorial is still under
construction and some chapters are unfinished yet.

## Documentation

Read the ALF documentation [here](https://alf.readthedocs.io/).

## Algorithms

|Algorithm|Type|Reference|
|---------|----|---------|
|[A2C](alf/algorithms/actor_critic_algorithm.py)|On-policy RL|[OpenAI Baselines: ACKTR & A2C](https://openai.com/blog/baselines-acktr-a2c/)|
|[PPO](alf/algorithms/ppo_algorithm.py)|On-policy RL|Schulman et al. "Proximal Policy Optimization Algorithms" [arXiv:1707.06347](https://arxiv.org/abs/1707.06347)|
|[PPG](alf/algorithms/ppo_algorithm.py)|On-policy RL|Cobbe et al. "Phasic Policy Gradient" [arXiv:2009.04416](https://arxiv.org/abs/2009.04416)|
|[DDQN](alf/algorithms/dqn_algorithm.py)|Off-policy RL|Hasselt et al. "Deep Reinforcement Learning with Double Q-learning" [arXiv:1509.06461](https://arxiv.org/abs/1509.06461)|
|[DDPG](alf/algorithms/ddpg_algorithm.py)|Off-policy RL|Lillicrap et al. "Continuous control with deep reinforcement learning" [arXiv:1509.02971](https://arxiv.org/abs/1509.02971)|
|[QRSAC](alf/algorithms/qrsac_algorithm.py)|Off-policy RL|Dabney et al. "Distributional Reinforcement Learning with Quantile Regression" [arXiv:1710.10044](https://arxiv.org/abs/1710.10044)|
|[SAC](alf/algorithms/sac_algorithm.py)|Off-policy RL|Haarnoja et al. "Soft Actor-Critic Algorithms and Applications" [arXiv:1812.05905](https://arxiv.org/abs/1812.05905)|
|[OAC](alf/algorithms/oac_algorithm.py)|Off-policy RL|Ciosek et al. "Better Exploration with Optimistic Actor-Critic" [arXiv:1910.12807](https://arxiv.org/abs/1910.12807)|
|[HER](https://github.com/HorizonRobotics/alf/blob/911d9573866df41e9e3adf6cdd94ee03016bf5a8/alf/algorithms/data_transformer.py#L672)|Off-policy RL|Andrychowicz et al. "Hindsight Experience Replay" [arXiv:1707.01495](https://arxiv.org/abs/1707.01495)|
|[TAAC](alf/algorithms/taac_algorithm.py)|Off-policy RL|Yu et al. "TAAC: Temporally Abstract Actor-Critic for Continuous Control" [arXiv:2104.06521](https://arxiv.org/abs/2104.06521)|
|[DIAYN](alf/algorithms/diayn_algorithm.py)|Intrinsic motivation/Exploration|Eysenbach et al. "Diversity is All You Need: Learning Diverse Skills without a Reward Function" [arXiv:1802.06070](https://arxiv.org/abs/1802.06070)|
|[ICM](alf/algorithms/icm_algorithm.py)|Intrinsic motivation/Exploration|Pathak et al. "Curiosity-driven Exploration by Self-supervised Prediction" [arXiv:1705.05363](https://arxiv.org/abs/1705.05363)|
|[RND](alf/algorithms/rnd_algorithm.py)|Intrinsic motivation/Exploration|Burda et al. "Exploration by Random Network Distillation" [arXiv:1810.12894](https://arxiv.org/abs/1810.12894)|
|[MuZero](alf/algorithms/muzero_algorithm.py)|Model-based RL|Schrittwieser et al. "Mastering Atari, Go, Chess and Shogi by Planning with a Learned Model" [arXiv:1911.08265](https://arxiv.org/abs/1911.08265)|
|[BC](alf/algorithms/bc_algorithm.py)|Offline RL|Pomerleau "ALVINN: An Autonomous Land Vehicle in a Neural Network" [NeurIPS 1988](https://papers.nips.cc/paper/1988/hash/812b4ba287f5ee0bc9d43bbf5bbe87fb-Abstract.html)
  Bain et al. "A framework for behavioural cloning" [Machine Intelligence 1999](http://www.cse.unsw.edu.au/~claude/papers/MI15.pdf)|
|[Causal BC](alf/algorithms/causal_bc_algorithm.py)|Offline RL|Swamy et al. "Causal Imitation Learning under Temporally Correlated Noise" [ICML2022](https://proceedings.mlr.press/v162/swamy22a/swamy22a.pdf)|
|[IQL](alf/algorithms/iql_algorithm.py)|Offline RL|Kostrikov, et al. "Offline Reinforcement Learning with Implicit Q-Learning" [arXiv:2110.06169](https://arxiv.org/abs/2110.06169)|
|[MERLIN](alf/algorithms/merlin_algorithm.py)|Unsupervised learning|Wayne et al. "Unsupervised Predictive Memory in a Goal-Directed Agent"[arXiv:1803.10760](https://arxiv.org/abs/1803.10760)|
|[MoNet](alf/algorithms/monet_algorithm.py)|Unsupervised learning|Burgess et al. "MONet: Unsupervised Scene Decomposition and Representation" [arXiv:1901.11390](https://arxiv.org/abs/1901.11390)|
|[Amortized SVGD](alf/algorithms/generator.py)|General|Feng et al. "Learning to Draw Samples with Amortized Stein Variational Gradient Descent" [arXiv:1707.06626](https://arxiv.org/abs/1707.06626)|
|[HyperNetwork](alf/algorithms/hypernetwork_algorithm.py)|General|Ratzlaff and Fuxin. "HyperGAN: A Generative Model for Diverse, Performant Neural Networks" [arXiv:1901.11058](https://arxiv.org/abs/1901.11058)|
|[MCTS](alf/algorithms/mcts_algorithm.py)|General|Grill et al. "Monte-Carlo tree search as regularized policy optimization" [arXiv:2007.12509](https://arxiv.org/abs/2007.12509)|
|[MINE](alf/algorithms/mi_estimator.py)|General|Belghazi et al. "Mutual Information Neural Estimation" [arXiv:1801.04062](https://arxiv.org/abs/1801.04062)|
|[ParticleVI](alf/algorithms/particle_vi_algorithm.py)|General|Liu and Wang. "Stein Variational Gradient Descent: A General Purpose Bayesian Inference Algorithm" [arXiv:1608.04471](https://arxiv.org/abs/1608.04471)
 Liu et al. "Understanding and accelerating particle-based variational inference" [arXiv:1807.01750](https://arxiv.org/abs/1807.01750)|
|[GPVI](alf/algorithms/generator.py)|General|Ratzlaff, Bai et al. "Generative Particle Variational Inference via Estimation of Functional Gradients" [arXiv:2103.01291](https://arxiv.org/abs/2103.01291)|
|[SVGD optimizer](alf/optimizers/optimizers.py)|General|Liu et al. "Stein Variational Gradient Descent: A General Purpose Bayesian Inference Algorithm" [arXiv:1608.04471](https://arxiv.org/abs/1608.04471)|
|[VAE](alf/algorithms/vae.py)|General|Higgins et al. "beta-VAE: Learning Basic Visual Concepts with a Constrained Variational Framework" [ICLR2017](https://openreview.net/forum?id=Sy2fzU9gl)|
|[RealNVP](alf/networks/normalizing_flow_networks.py)|General|Dinh et al. "Density estimation using Real NVP" [arXiv:1605.08803](https://arxiv.org/abs/1605.08803)|
|[SpatialBroadcastDecoder](alf/networks/encoding_networks.py)|General|Watters et al. "Spatial Broadcast Decoder: A Simple Architecture for Learning Disentangled Representations in VAEs" [arXiv:1901.07017](https://arxiv.org/abs/1901.07017)|
|[VQ-VAE](alf/algorithms/vq_vae.py)|General|A van den Oord et al. "Neural Discrete Representation Learning" [NeurIPS2017](https://proceedings.neurips.cc/paper/2017/file/7a98af17e63a0ac09ce2e96d03992fbc-Paper.pdf)|

## Installation

#### OS softwares
The following installation was tested on Ubuntu20.04 with CUDA 11.4.

Python3.8 (and above) is currently supported by ALF. Note that some pip packages (e.g., pybullet) need python dev files, so make sure python3-dev is installed:

```
sudo apt install -y python3-dev
```

Boost is also required by ALF for fast parallel environments.

```
sudo apt install libboost-all-dev
```

#### Python environment
[Virtualenv](https://virtualenv.pypa.io/en/latest/) is recommended for the installation. After creating and activating a virtual env, you can run the following commands to install ALF:

```
git clone https://github.com/HorizonRobotics/alf
cd alf
pip install -e . --extra-index-url https://download.pytorch.org/whl/cu113
```

#### For Nix Users

There is a built-in Nix-based development environment defined in [flake.nix](./flake.nix). To activate it, run

```bash
$ nix develop
```

in the root of your local repository.

## Docker
We also provide a docker image of ALF for convenience. In order to use this image, you need to have [docker](https://www.docker.com/) and [nvidia-docker](https://github.com/NVIDIA/nvidia-docker) (for ALF gpu usage) installed first.

```bash
docker run --gpus all -it horizonrobotics/cuda:11.4-cudnn8-py3.8-ubuntu20.04 /bin/bash
```
This will give you a shell that have all ALF and dependencies pre-installed.

The current docker image contains an ALF version on Mar 10, 2023. Regular version updates are expected in the future.

## Examples

You can train any `_conf.py` file under `alf/examples` as follows:
```bash
python -m alf.bin.train --conf=CONF_FILE --root_dir=LOG_DIR
```
* CONF_FILE is the path to your conf file which follows ALF configuration file format (basically python).
* LOG_DIR is the directory when you want to store the training results. Note that if you want to train from scratch, LOG_DIR must point to a location that doesn't exist. Othewise, it is assumed to resume the training from a previous checkpoint (if any).

During training, we use tensorboard to show the progress of training:
```bash
tensorboard --logdir=LOG_DIR
```

After training, you can evaluate the trained model and visualize environment
frames using the following command:
```bash
python -m alf.bin.play --root_dir=LOG_DIR
```

#### **Deprecated**

An older version of ALF used [gin](https://github.com/google/gin-config)
for job configuration. Its syntax is not as flexible as ALF conf (e.g., you can't easily
do math computation in a gin file). There are still some examples with `.gin`
under `alf/examples`. We are in the process of converting all `.gin` examples to `_conf.py`
examples.

You can train any `.gin` file under `alf/examples` using the following command:
```bash
cd alf/examples; python -m alf.bin.train --gin_file=GIN_FILE --root_dir=LOG_DIR
```
* GIN_FILE is the path to the gin conf (some `.gin` files under `alf/examples` might be invalid; they have not been converted to use the latest pytorch version of ALF).
* LOG_DIR has the same meaning as in the ALF conf example above.

*Warning*: When using **gin**, ALF has to be launched in the same directory with the gin file(s). If an error says that no configuration file is found, then probably you've launched ALF in a wrong place.

All the examples below are trained on a single machine Intel(R) Core(TM) i9-7960X CPU @ 2.80GHz with 32 CPUs and one RTX 2080Ti GPU.

### A2C
* [Cart pole](alf/examples/ac_cart_pole.gin). The training score took only 30 seconds to reach 200, using 8 environments.

* [Atari games](alf/examples/ac_breakout_conf.py). Need to install python package atari-py for atari game environments. The evaluation score (by taking argmax of the policy) took 1.5 hours to reach 800 on Breakout, using 64 environments.

* [Simple navigation with visual input](alf/examples/ac_simple_navigation.gin). Follow the instruction at [SocialRobot](https://github.com/HorizonRobotics/SocialRobot) to install the environment.

### PPO
* [PR2 grasping state only](alf/examples/ppo_pr2.gin). Follow the instruction at [SocialRobot](https://github.com/HorizonRobotics/SocialRobot) to install the environment.

* [Humanoid](alf/examples/ppo_bullet_humanoid.gin). Learning to walk using the pybullet Humanoid environment. Need to install python pybullet>=2.5.0 for the environment. The evaluation score reaches 3k in 50M steps, using 96 parallel environments.

### PPG

* [procgen](alf/examples/ppg_procgen_bossfight_conf.py). Game "bossfight" as an example. Need to install python package [procgen](https://github.com/openai/procgen).

* [MetaDrive](alf/examples/metadrive/ppg_metadrive_conf.py). Learning to drive on randomly generated map with interaction on the [MetaDrive](https://metadriverse.github.io/metadrive/) simulator, with BEV as input. Need to install python package [metadrive-simulator](https://github.com/metadriverse/metadrive).

### DDQN
* [DDQN on Atari](alf/examples/dqn_breakout_conf.py).  Game "Q*Bert" performance.

### DDPG
* [FetchSlide (sparse rewards)](alf/examples/ddpg_fetchslide_conf.py). Need to install the [MuJoCo](https://www.roboti.us/index.html) simulator first. This example reproduces the performance of vanilla DDPG reported in the OpenAI's Robotics environment [paper](https://arxiv.org/pdf/1802.09464.pdf). Our implementation doesn't use MPI, but obtains (evaluation) performance on par with the original implementation. (*The original MPI implementation has 19 workers, each worker containing 2 environments for rollout and sampling a minibatch of size 256 from its replay buffer for computing gradients. All the workers' gradients will be summed together for a centralized optimizer step. Our implementation simply samples a minibatch of size 5000 from a common replay buffer per optimizer step.*) The training took about 1 hour with 38 (19*2) parallel environments on a single GPU.

### SAC
* [Bipedal Walker](alf/examples/sac_bipedal_walker_conf.py).

* [FetchReach (sparse rewards)](alf/examples/sac_fetchreach.gin). Need to install the [MuJoCo](https://www.roboti.us/index.html) simulator first. The training took about 20 minutes with 20 parallel environments on a single GPU.

* [FetchSlide (sparse rewards)](alf/examples/sac_fetchslide.gin). Need to install the [MuJoCo](https://www.roboti.us/index.html) simulator first. This is the same task with the DDPG example above, but with SAC as the learning algorithm.
Also it has only 20 (instead of 38) parallel environments to improve sample efficiency. The training took about 2 hours on a single GPU.

* [Fetch Environments (sparse rewards) w/ Action Repeat](alf/examples/sac_actrepeat_fetch/sac_actrepeat_fetch.gin). We are able to achieve even better performance than reported by DDPG + Hindsight Experience Replay in some cases simply by using SAC + Action Repeat with length 3 timesteps. See [this note](docs/notes/fetch_env_sac_actrepeat_notes.rst) to view learning curves, videos, and more details.

### ICM
* [Super Mario](alf/examples/icm_super_mario_intrinsic_only.gin). Playing Super Mario only using intrinsic reward.
  Python package gym-retro>=0.7.0 is required for this experiment and also a suitable `SuperMarioBros-Nes` rom should be obtained and imported (roms are not included in gym-retro). See [this doc](https://retro.readthedocs.io/en/latest/getting_started.html#importing-roms) on how to import roms.

### RND
* [Montezuma's Revenge](alf/examples/ppo_rnd_mrevenge.gin). Training the hard exploration game Montezuma's Revenge with intrinsic rewards generated by [RND](alf/algorithms/rnd_algorithm.py). A lucky agent can get an episodic score of 6600 in 160M frames (40M steps with `frame_skip=4`). A normal agent would get an episodic score of 4000~6000 in the same number of frames. The training took about 6.5 hours with 128 parallel environments on a single GPU.

### DIAYN
* [Pendulum](alf/examples/diayn_pendulum.gin). Learning diverse skills without external rewards.

### BC
* [Pendulum](alf/examples/hybrid_rl/bc_pendulum_conf.py). Learning a control policy from [offline demonstrations](alf/examples/hybrid_rl/replay_buffer_data/pendulum_replay_buffer_from_sac_10k).

### Merlin
* [Collect Good Objects](alf/examples/merlin_dmlab_collect_good_objects.gin). Learn to collect good objects and avoid bad objects.
  `DeepmindLab` is required,  Follow the instruction at [DeepmindLab](https://github.com/deepmind/lab/blob/master/python/pip_package/README.md) to install the environment.

### MuZero
* [6x6 Go](alf/examples/muzero_go_6x6.gin). It took about a day to train a reasonable agent to play 6x6 go using one GPU.

## Citation
If you use ALF for research and find it useful, please consider citing:
```
@software{Xu2021ALF,
  title={{{ALF}: Agent Learning Framework}},
  author={Xu, Wei and Yu, Haonan and Zhang, Haichao and Hong, Yingxiang and Yang, Break and Zhao, Le and Bai, Jerry and ALF contributors},
  url={https://github.com/HorizonRobotics/alf},
  year={2021}
}
```

## Contribute to ALF

You are welcome to contribute to ALF. Please follow the guideline [here](https://alf.readthedocs.io/en/latest/contributing.html).

repository: HorizonRobotics/alf

branch_name: refs/heads/pytorch

gha_language: Python

repo_name: HorizonRobotics/alf


text:
Stream Memory Map Mixed
===============================================================

This example demonstrate how to process an input stream of data from host for computation along with memory mapped OpenCL buffer inputs. `krnl_stream_vadd` has 1 stream input, one memory mapped buffer input and 1 stream output.

Following is the kernel definition along with Interface pragma:

```c++
typedef qdma_axis<DWIDTH, 0, 0, 0> pkt;
void krnl_stream_vadd(hls::stream<pkt> &out, // Write-Only output Stream
                      hls::stream<pkt> &in1, // Input Stream 1
                      int *in2,              // Memory mapped Input Vector 2
                      int size               // Size in integer
) {
#pragma HLS INTERFACE axis port = out
#pragma HLS INTERFACE axis port = in1
#pragma HLS INTERFACE m_axi port = in2 offset = slave bundle = gmem
#pragma HLS INTERFACE s_axilite port = in2 bundle = control
#pragma HLS INTERFACE s_axilite port = size bundle = control
#pragma HLS INTERFACE s_axilite port = return bundle = control
...
}
```
Here kernel has two input argument in1 and in2. in1 is axis (AXI Streaming) type and in2 is m_axi (memory Master AXI) Interface type.

Inside host code, user has to set argument only for non-streaming interface as shown below:
```c++
cl::Kernel krnl_vadd = cl::Kernel(program, "krnl_stream_vadd", &err));
krnl_vadd.setArg(2, buffer_in2);
krnl_vadd.setArg(3, size);
```

For `axis` streaming interface type argument, host needs to creates streaming objects as below:

```c++
cl_int ret;
cl_mem_ext_ptr_t ext;
ext.param = krnl_vadd.get(); //specifying the kernel object on which stream connection will be established
ext.obj = NULL;

ext.flags = 0; //Create read stream for argument 0 of kernel
cl_stream read_stream = xcl::Stream::createStream(device.get(), XCL_STREAM_WRITE_ONLY, CL_STREAM, &ext, &ret));
ext.flags = 1; //Create write stream for argument 1
cl_stream write_stream_a = xcl::Stream::createStream(device.get(), XCL_STREAM_READ_ONLY, CL_STREAM, &ext, &ret));
```

Please refer `streaming_simple` example to more about Streaming kernel usage.


text:
Nginx configuration
===================

Rename the configuration file:

    mv nginx.conf yourapplication.conf

Make all the necessary adjustments to the configuration file and create a
symlink to it into nginx's *sites-enabled* directory:

    ln -s yourapplication.conf /etc/nginx/sites-enabled/


text:
# Error Message

Most of the time you want to display a customized error message for the built-in validation. Here's how to achieve that.

**Note:** When you provide a string to the errorMessage prop, that will be used as the default for all built-in validation rules. The same can be achieved by adding a property with the key \_ (underscore).

<!-- STORY -->

```jsx
import {
  Form,
  Input,
  TextArea,
  RadioGroup,
  Radio,
  Select,
  Option,
  Checkbox,
  Scope,
  Debug
} from 'informed';

const validate = value => {
  if (!value || value.length < 5)
    return 'Field must be at least five characters';
};

const Example = () => (
  <Form
    errorMessage={{ required: 'This is field is required for your profile!' }}
    onSubmit={({ values }) => window.alert(JSON.stringify(values, null, 2))}>
    <Input
      name="name"
      label="First name:"
      required
      errorMessage="There is a problem with this field!"
    />
    <Input
      name="last"
      label="Last name:"
      required
      errorMessage={{ required: 'Last name is required!' }}
    />
    <Input name="favoriteColor" label="Favorite color:" required />
    <button type="submit">Submit</button>
    <Debug values errors invalid valid />
  </Form>
);
```

repository: joepuzzo/informed

repo_name: joepuzzo/informed


text:
---
title: 'How to set up a DataFX application'
layout: post
author: hendrik
categories: [DataFX, JavaFX]
excerpt: 'This tutorial describes how you can add DataFX to your JavaFX application or start a new application that is based on DataFX.'
featuredImage: java-6
permalink: '2015/01/set-datafx-application/'
header:
  text: How to set up a DataFX application
  image: sample
---
A lot of people start using DataFX in small projects without a build file and by doing so they sometimes use old builds. Because of that I will give you some hints how to setup a project that is using DataFX.

## DataFX builds

Every stable DataFX build can be found at Maven Central. If you are new to Maven or Maven Central just open this [link](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22io.datafx%22). On the page you will find all artifacts of DataFX. If you for example want to use DataFX core you can download the jar, sources and javadoc [here](http://search.maven.org/#artifactdetails%7Cio.datafx%7Ccore%7C8.0%7Cjar).

![maven central](/assets/posts/guigarage-legacy/maven-central.png)

Each DataFX artifact is defined by the group-id, artifact-id and version. The group-id is always "io.datafx" and the artifact-id depends on the DataFX-Module. If you for example want to create an application that is suing the DataFX Flow you need the datafx-flow module and all it's dependencies. At the moment the last stable version is 8.0.

If you want to download the DataFX jars by hand and add them to your application you need to download all dependencies of the module, too. Thankfully DataFX doesn't have much dependencies. Here is an overview:

![datafx-dep.016](/assets/posts/guigarage-legacy/datafx-dep.016.png)

Once you have downloaded the last version of DataFX and added the jars to the class path of your application you can start coding.

## Using builds tools

Normally you won't download the dependencies of your application manually. Build tools like [Maven](http://maven.apache.org) or [Gradle](https://gradle.org) can do this job for you. By using one of the tools you only need to define the dependencies in your build file and the build tool will automatically download all needed jars. In addition the tools support transitive dependencies. This allows you to avoid needing to discover and specify the libraries that your own dependencies require, and including them automatically. If you Maven as build tool and you only want to add the DataFX Flow API to your application you only need to add one dependency:

{% highlight xml %}
<dependency>
    <groupId>io.datafx</groupId>
    <artifactId>flow</artifactId>
    <version>8.0</version>
</dependency>
{% endhighlight %}

## Use DataFX in your application

Once you added DataFX as dependency to your application you can using it as described in the [tutorials]({{ site.baseurl }}{% post_url 2014-05-19-datafx-8-0-tutorials %}).

gha_language: CSS


text:
---
layout: engineering-education
status: publish
published: true
url: /how-to-create-a-dataset-for-machine-learning/
title: How to Create a Dataset for Machine Learning
description: This article gives an overview of how datasets are created for Machine Learning models. Having good quality data is very important to ML systems. There are three key steps that have to be followed to achieve this. These include data acquisition, data cleaning, and data labeling.
author: willies-ogola
date: 2021-02-10T00:00:00-09:00
topics: []
excerpt_separator: <!--more-->
images:
  - url: /engineering-education/how-to-create-a-dataset-for-machine-learning/hero.jpg
    alt: Machine Learning (ML) Datasets example image
---
Machine Learning (ML) has had a profound influence on a diverse range of applications. This has been possible mainly due to the better computing power and large amounts of training data. I cannot emphasize enough the importance of training data in ML systems.
<!--more-->
In fact, most of the machine learning models' problems aren't caused by the models but by issues in the dataset. And yet, the process in which a dataset is created is an underrated topic. This is because creating and improving datasets is a human task and tends to be very time-consuming. In the world of artificial intelligence, tasks that require human labor aren't considered exciting.

### Table of contents
1. [Prerequisites](#prerequisites)
2. [Introduction](#introduction)
3. [Data Acquisition](#data-acquisition)
4. [Data Cleaning](#data-cleaning)
5. [Data Labeling](#data-labeling)
6. [Wrapping Up](#wrapping-up)
7. [References](#references)

### Prerequisites
Before reading this article, the reader needs to have a little knowledge in Artificial Intelligence and Machine Learning. If you're still a beginner, feel free to read my previously published [article](/engineering-education/differences-between-artificial-intelligence-machine-learning-and-deep-learning/) explaining the difference between Artificial Intelligence and Machine Learning.

### Introduction
In any case, before we train a model, we need a dataset. There are many publicly available datasets that one can use in a project.

For example, if one wanted a model that would help classify YouTube videos by genres, one can use the [YouTube-8M Segments dataset](https://research.google.com/youtube8m/) that is publicly available. Likewise, if one is looking to classify patients having breast cancer, the [Wisconsin Breast Cancer dataset](https://archive.ics.uci.edu/ml/datasets/Breast+Cancer+Wisconsin+%28Diagnostic%29) will come in handy.

What if your desired dataset for the problem is not publicly available?

That means that you'll have to create one yourself.

The process of creating a dataset involves three important steps:
1. Data Acquisition
2. Data Cleaning
3. Data Labeling

### Data acquisition
The process of data acquisition involves finding datasets that can be used for training machine learning models. There are a couple of ways you can go about doing this, and your approach will largely depend on the problem that you are trying to solve and the type of data that you think is best suited for it. There are largely two key approaches.

They include:
1. Data Generation
2. Data Augmentation

#### Data generation
The Data Generation technique is applied when there is no existing dataset that can be used for training.
It involves:

#### 1. Crowdsourcing
Crowdsourcing is a business model that involves connecting with large groups of people via the internet to accomplish tasks. These tasks range from simple tasks such as data labeling to complex tasks involving collaborative writing. A good example of crowdsourcing's usage is in the popular [ImageNet project](http://www.image-net.org/), which gave rise to the ImageNet image classification dataset.

In Machine Learning, crowdsourcing is used to aid in data generation tasks.

There are two main crowdsourcing platforms that one can utilize to generate new data:
1. The [Amazon Mechanical Turk (MTurk)](https://www.mturk.com/) is one of the earliest and most popular examples of a crowdsourcing platform. One can sign up on this platform and leverage the power of large groups of people to complete data generation tasks, and you pay them for their services. This saves you a lot of time and improves efficiency.

2. [Citizen Science](https://en.wikipedia.org/wiki/Citizen_science) is also a crowdsourcing platform whereby you can engage the public in the process of data collection, which not only helps you collect more data but also help the public learn more about the science that you are trying to do.

#### 2. Synthetic data generation
Synthetic data is the data created via a computer to increase the size of our training data or introduce changes in the data that we would like our model to handle in the future. Generative models such as the Generative Adversarial Network is good example of a computer program that generate synthetic data.

We need these large amounts of data to have enough information to train a machine learning models properly. Thus, synthetic data generation usually offers us a cheaper and more flexible way of expanding our datasets. Generative Adversarial Networks (GANs) is an advanced technique that we can use to generate synthetic data.

It involves training two contesting networks: a generator and a discriminator. The generator's role is to learn to map a latent space to a data distribution (from a dataset). The discriminator's role is to discriminate (compare) between examples from the true distribution and the generated distribution.

The goal is to increase the error rate for the discriminator network to make the generator networks so good at generating samples, that it will fool the discriminator into thinking that the samples are from the true data distribution (the dataset).

Using GANs effectively generates synthetic videos and images that look realistic for use in different applications. It takes in existing data and creates new data that looks like your original dataset. Thus, generating more data.

#### Data augmentation
Data Augmentation is another method for data acquisition. The process involves augmenting existing datasets with newly-acquired external data. Some basic steps in the data augmentation process might include cropping, flipping, rotating, adjusting the brightness, and contrast of the existing input images.

This technique enhances the size and quality of training datasets enabling you to collect more data without actually going out to physically collect more data. Another advantage of data augmentation is that, it makes models generalize better to new unseen data.

### Data cleaning
If you do have enough data, but the quality of the dataset isn't that great (e.g., data is noisy), or there's an issue with the general formatting in your dataset (e.g., some data intervals are in minutes while some in hours), we move on to the second most important process, which involves cleaning the data.

You can perform data operations manually, but it is labor-intensive and would take a lot of time. Alternatively, you can leverage already built systems and frameworks to help you achieve the same goal easier and faster.

The tools and frameworks include:

1. [HoloClean](http://www.holoclean.io/)

HoloClean repairs, cleans, and enriches the data. The system leverages value correlations, quality rules, and reference data to help build probabilistic models that capture the process of data generation. It also helps data scientists save on the time needed to clean data.

2. [ActiveClean](https://activeclean.github.io/)

ActiveClean is an iterative cleaning framework that cleans samples of data based on how much cleaning would improve the models accuracy. This means that you only need to clean a small subset of the data to achieve a model similar to a fully cleaned dataset.

3. [BoostClean](https://arxiv.org/pdf/1711.01299.pdf)

BoostClean automatically detects and repairs errors in data using statistical boosting. Statistical boosting is an ensembling technique that enables the system to find the best ensemble of pairs that maximize the final model's accuracy.

4. [MLClean](https://arxiv.org/pdf/1904.10761.pdf)

MLClean is the most recent data cleaning framework.

The framework performs three main tasks:
- Data sanitization - This is the process of removing poisoned data before it is used for training.
- Traditional data cleaning - This process involve performing traditional data cleaning techniques such as removing duplicated data and adjusting values to correct ranges.
- Unfairness mitigation in data - This process involves removing unfairness in data e.g., bias against people from certain demographics or discrimination based on gender.

The framework also cleans data to achieve robust, accurate, and fair models.

An important point to note is that you shouldn't clean too much. Ideally, cleaning a dataset should not result in a dataset that's no longer representative of the population that you are looking to perform a study on.

### Data labeling
Data Labeling is an important part of data preprocessing that involves attaching meaning to digital data. Input and output data are labeled for classification purposes, and provides a learning basis for future data processing. For example, the picture of a dog can be attached to the label "a dog".

Now you have acquired enough data to have a representative dataset (a dataset that captures the most important information), clean, and in the right format.

Time to label that data? Maybe.

The answer to that question solely depends on whether you are using [supervised learning or unsupervised learning](/engineering-education/supervised-learning-algorithms/). Unsupervised learning doesn't require your data to be labeled, while supervised learning does require data labeling.

The processes of labeling can be subjective and also labor-intensive. One can utilize crowdsourcing platforms such as [Amazon Mechanical Turk (MTurk)](https://www.mturk.com/) and [Citizen Science](https://en.wikipedia.org/wiki/Citizen_science) to achieve this goal.

### Wrapping up
Is that the end of the process for creating a dataset? Well, probably, probably not.

Training a model can reveal some issues that may negatively impact the outcomes that you may try to predict or classify. Often, these issues can be traced back to the dataset itself. You may have to return to the [Data Acquisition](#data-acquisition), [Data Cleaning](#data-cleaning), and [Data Labeling](#data-labeling) drawing board to figure out how to create a better dataset for your ML system. But if your dataset lacks any of these issues, you're good to go.

To summarize the contents of this article, having good quality data is very important to ML systems. There are three key steps that have to be followed to achieve this. These include data acquisition, data cleaning, and data labeling. Leveraging these three steps will not only enable you create a good dataset, but also have a good quality dataset.

That's it for this article on how to create a dataset for machine learning.

Hope the article was helpful.

### References
1. [A Survey on Data Collection for Machine Learning](https://arxiv.org/pdf/1811.03402.pdf)
2. [YouTube-8M Segments Dataset](https://research.google.com/youtube8m/)
3. [Amazon Mechanical Turk (MTurk) ](https://www.mturk.com/)
4. [Citizen Science](https://en.wikipedia.org/wiki/Citizen_science)
5. [ImageNet project](http://www.image-net.org/)
6. [HoloClean](http://www.holoclean.io/)
7. [BoostClean](https://arxiv.org/pdf/1711.01299.pdf)
8. [MLClean](https://arxiv.org/pdf/1904.10761.pdf)

---
Peer Review Contributions by: [Srishilesh P S](/engineering-education/authors/srishilesh-p-s/)

repository: mbuguac/engineering-education

gha_language: SCSS

repo_name: mbuguac/engineering-education