|
| 1 | +import React from 'react' |
| 2 | + |
| 3 | +import { Field, useFormikContext } from 'formik' |
| 4 | +import { FormGroup, Label, Col, InputGroup } from 'reactstrap' |
| 5 | + |
| 6 | +import Hint from '../../../../../Hint' |
| 7 | +import { Input } from '../../../../../Form' |
| 8 | +import { integerOrPlaceholder } from '../../../Behavior/components/Timeline/util' |
| 9 | + |
| 10 | +const switchLabels = ({ |
| 11 | + templateParameters={ rows: [] }, |
| 12 | + sample={ n: undefined } |
| 13 | +}, labels) => { |
| 14 | + const samples = parseInt(sample.n) |
| 15 | + const parameters = templateParameters.rows.length |
| 16 | + |
| 17 | + if (samples < parameters) { |
| 18 | + return labels[0] |
| 19 | + } else if (isNaN(samples) || samples === parameters) { |
| 20 | + return labels[1] |
| 21 | + } else { |
| 22 | + return labels[2] |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +export default () => { |
| 27 | + const { values } = useFormikContext() |
| 28 | + |
| 29 | + return <FormGroup row> |
| 30 | + <Label xs={ 2 } for="sampleN"> |
| 31 | + Sample |
| 32 | + <Hint |
| 33 | + title="Sampling" |
| 34 | + className="float-right" |
| 35 | + placement="left" |
| 36 | + > |
| 37 | + <p className="font-weight-bold"> |
| 38 | + Control how many, and which of the above parameter sets are used. |
| 39 | + </p> |
| 40 | + <p className="text-muted"> |
| 41 | + The <strong>sample size</strong> defines the number of loop iterations. The <strong>mode</strong> determines how the iterations are drawn from the entries above. |
| 42 | + </p> |
| 43 | + <dl className="text-muted"> |
| 44 | + <dt>Sequential</dt> |
| 45 | + <dd>Proceed in order, starting from the top. If more samples are requested than entries are available, start over.</dd> |
| 46 | + |
| 47 | + <dt>Random order</dt> |
| 48 | + <dd>Present entries in shuffled order<br /> (only available without sampling).</dd> |
| 49 | + |
| 50 | + <dt>Sample without replacement</dt> |
| 51 | + <dd>Draw entries at random, starting over when all are exhausted. Shuffles the result for a completely random order.</dd> |
| 52 | + |
| 53 | + <dt>Sample w/o replacement (in blocks)</dt> |
| 54 | + <dd>As above, but without shuffling.<br /> If the number of samples exceeds the number of entries, this results in blocks of all entries in random order.</dd> |
| 55 | + |
| 56 | + <dt>Sample with replacement</dt> |
| 57 | + <dd>Draw entries without regard to which have been selected before.</dd> |
| 58 | + </dl> |
| 59 | + </Hint> |
| 60 | + </Label> |
| 61 | + <Col xs={10}> |
| 62 | + <InputGroup> |
| 63 | + <Field |
| 64 | + name="sample.n" |
| 65 | + component={ Input } |
| 66 | + pattern={ integerOrPlaceholder } |
| 67 | + placeholder={ |
| 68 | + (values.sample || {}).mode === 'draw-replace' |
| 69 | + ? 'As many as rows above' |
| 70 | + : 'Use all' |
| 71 | + } |
| 72 | + className="text-monospace" |
| 73 | + /> |
| 74 | + <Field |
| 75 | + name={ 'sample.mode' } |
| 76 | + as="select" |
| 77 | + className="form-control custom-select text-monospace" |
| 78 | + > |
| 79 | + <option value="sequential"> |
| 80 | + In sequence |
| 81 | + </option> |
| 82 | + <option value="draw-shuffle"> |
| 83 | + { |
| 84 | + switchLabels(values, [ |
| 85 | + 'Sampled without replacement', |
| 86 | + 'In random order', |
| 87 | + 'Sampled without replacement (then shuffled)' |
| 88 | + ]) |
| 89 | + } |
| 90 | + </option> |
| 91 | + <option value="draw"> |
| 92 | + Sampled without replacement (in blocks) |
| 93 | + </option> |
| 94 | + <option value="draw-replace"> |
| 95 | + Sampled with replacement |
| 96 | + </option> |
| 97 | + </Field> |
| 98 | + </InputGroup> |
| 99 | + </Col> |
| 100 | + </FormGroup> |
| 101 | +} |
0 commit comments