Search in sources :

Example 1 with Deviation

use of com.amazon.randomcutforest.parkservices.statistics.Deviation in project random-cut-forest-by-aws by aws.

the class PreprocessorMapper method toModel.

@Override
public Preprocessor toModel(PreprocessorState state, long seed) {
    DeviationMapper deviationMapper = new DeviationMapper();
    Deviation timeStampDeviation = deviationMapper.toModel(state.getTimeStampDeviationState());
    Deviation dataQuality = deviationMapper.toModel(state.getDataQualityState());
    Deviation[] deviations = null;
    if (state.getDeviationStates() != null) {
        deviations = new Deviation[state.getDeviationStates().length];
        for (int i = 0; i < state.getDeviationStates().length; i++) {
            deviations[i] = deviationMapper.toModel(state.getDeviationStates()[i]);
        }
    }
    Preprocessor.Builder<?> preprocessorBuilder = new Preprocessor.Builder<>().forestMode(ForestMode.valueOf(state.getForestMode())).shingleSize(state.getShingleSize()).dimensions(state.getDimensions()).normalizeTime(state.isNormalizeTime()).imputationMethod(ImputationMethod.valueOf(state.getImputationMethod())).fillValues(state.getDefaultFill()).inputLength(state.getInputLength()).weights(state.getWeights()).transformMethod(TransformMethod.valueOf(state.getTransformMethod())).startNormalization(state.getStartNormalization()).useImputedFraction(state.getUseImputedFraction()).timeDeviation(timeStampDeviation).dataQuality(dataQuality);
    if (deviations != null) {
        preprocessorBuilder.deviations(deviations);
    }
    Preprocessor preprocessor = preprocessorBuilder.build();
    preprocessor.setInitialValues(state.getInitialValues());
    preprocessor.setInitialTimeStamps(state.getInitialTimeStamps());
    preprocessor.setClipFactor(state.getClipFactor());
    preprocessor.setValuesSeen(state.getValuesSeen());
    preprocessor.setInternalTimeStamp(state.getInternalTimeStamp());
    preprocessor.setLastShingledInput(state.getLastShingledInput());
    preprocessor.setLastShingledPoint(state.getLastShingledPoint());
    preprocessor.setPreviousTimeStamps(state.getPreviousTimeStamps());
    preprocessor.setNormalizeTime(state.isNormalizeTime());
    return preprocessor;
}
Also used : DeviationMapper(com.amazon.randomcutforest.parkservices.state.statistics.DeviationMapper) Preprocessor(com.amazon.randomcutforest.parkservices.preprocessor.Preprocessor) Deviation(com.amazon.randomcutforest.parkservices.statistics.Deviation)

Example 2 with Deviation

use of com.amazon.randomcutforest.parkservices.statistics.Deviation in project random-cut-forest-by-aws by aws.

the class BasicThresholderMapper method toModel.

@Override
public BasicThresholder toModel(BasicThresholderState state, long seed) {
    DeviationMapper deviationMapper = new DeviationMapper();
    Deviation primaryDeviation = deviationMapper.toModel(state.getPrimaryDeviationState());
    Deviation secondaryDeviation = deviationMapper.toModel(state.getSecondaryDeviationState());
    Deviation thresholdDeviation = deviationMapper.toModel(state.getThresholdDeviationState());
    BasicThresholder thresholder = new BasicThresholder(primaryDeviation, secondaryDeviation, thresholdDeviation);
    thresholder.setAbsoluteThreshold(state.getAbsoluteThreshold());
    thresholder.setLowerThreshold(state.getLowerThreshold(), state.isAutoThreshold());
    thresholder.setUpperThreshold(state.getUpperThreshold());
    thresholder.setInitialThreshold(state.getInitialThreshold());
    thresholder.setElasticity(state.getElasticity());
    thresholder.setInPotentialAnomaly(state.isInAnomaly());
    thresholder.setHorizon(state.getHorizon());
    thresholder.setCount(state.getCount());
    thresholder.setMinimumScores(state.getMinimumScores());
    thresholder.setAbsoluteScoreFraction(state.getAbsoluteScoreFraction());
    thresholder.setUpperZfactor(state.getUpperZfactor());
    thresholder.setZfactor(state.getZFactor());
    return thresholder;
}
Also used : DeviationMapper(com.amazon.randomcutforest.parkservices.state.statistics.DeviationMapper) Deviation(com.amazon.randomcutforest.parkservices.statistics.Deviation) BasicThresholder(com.amazon.randomcutforest.parkservices.threshold.BasicThresholder)

Example 3 with Deviation

use of com.amazon.randomcutforest.parkservices.statistics.Deviation in project random-cut-forest-by-aws by aws.

the class ImputePreprocessor method dischargeInitial.

/**
 * a block which is executed once. It first computes the multipliers for
 * normalization and then processes each of the stored inputs
 */
protected void dischargeInitial(RandomCutForest forest) {
    Deviation tempTimeDeviation = new Deviation();
    for (int i = 0; i < initialTimeStamps.length - 1; i++) {
        tempTimeDeviation.update(initialTimeStamps[i + 1] - initialTimeStamps[i]);
    }
    double timeFactor = tempTimeDeviation.getMean();
    prepareInitialInput();
    double[] factors = getFactors();
    Arrays.fill(previousTimeStamps, initialTimeStamps[0]);
    numberOfImputed = shingleSize;
    for (int i = 0; i < valuesSeen; i++) {
        // initial imputation; not using the global dependency
        long lastInputTimeStamp = previousTimeStamps[shingleSize - 1];
        if (internalTimeStamp > 0) {
            double[] previous = new double[inputLength];
            System.arraycopy(lastShingledInput, lastShingledInput.length - inputLength, previous, 0, inputLength);
            int numberToImpute = determineGap(initialTimeStamps[i] - lastInputTimeStamp, timeFactor) - 1;
            if (numberToImpute > 0) {
                double step = 1.0 / (numberToImpute + 1);
                // the last impute corresponds to the current observed value
                for (int j = 0; j < numberToImpute; j++) {
                    double[] result = basicImpute(step * (j + 1), previous, initialValues[i], DEFAULT_INITIAL);
                    double[] scaledInput = transformValues(result, factors);
                    updateShingle(result, scaledInput);
                    updateTimestamps(initialTimeStamps[i]);
                    numberOfImputed = numberOfImputed + 1;
                    if (updateAllowed()) {
                        forest.update(lastShingledPoint);
                    }
                }
            }
        }
        double[] scaledInput = transformValues(initialValues[i], factors);
        updateState(initialValues[i], scaledInput, initialTimeStamps[i], lastInputTimeStamp);
        if (updateAllowed()) {
            forest.update(lastShingledPoint);
        }
    }
    initialTimeStamps = null;
    initialValues = null;
}
Also used : Deviation(com.amazon.randomcutforest.parkservices.statistics.Deviation)

Example 4 with Deviation

use of com.amazon.randomcutforest.parkservices.statistics.Deviation in project random-cut-forest-by-aws by aws.

the class PreprocessorMapper method toState.

@Override
public PreprocessorState toState(Preprocessor model) {
    PreprocessorState state = new PreprocessorState();
    state.setShingleSize(model.getShingleSize());
    state.setDimensions(model.getDimension());
    state.setInputLength(model.getInputLength());
    state.setClipFactor(model.getClipFactor());
    state.setDefaultFill(model.getDefaultFill());
    state.setImputationMethod(model.getImputationMethod().name());
    state.setTransformMethod(model.getTransformMethod().name());
    state.setWeights(model.getWeights());
    state.setForestMode(model.getMode().name());
    state.setInitialTimeStamps(model.getInitialTimeStamps());
    state.setInitialValues(model.getInitialValues());
    state.setUseImputedFraction(model.getUseImputedFraction());
    state.setNormalizeTime(model.isNormalizeTime());
    state.setStartNormalization(model.getStartNormalization());
    state.setStopNormalization(model.getStopNormalization());
    state.setPreviousTimeStamps(model.getPreviousTimeStamps());
    state.setLastShingledInput(model.getLastShingledInput());
    state.setLastShingledPoint(model.getLastShingledPoint());
    state.setValuesSeen(model.getValuesSeen());
    state.setInternalTimeStamp(model.getInternalTimeStamp());
    DeviationMapper deviationMapper = new DeviationMapper();
    state.setTimeStampDeviationState(deviationMapper.toState(model.getTimeStampDeviation()));
    state.setDataQualityState(deviationMapper.toState(model.getDataQuality()));
    DeviationState[] deviationStates = null;
    if (model.getDeviationList() != null) {
        Deviation[] list = model.getDeviationList();
        deviationStates = new DeviationState[list.length];
        for (int i = 0; i < list.length; i++) {
            deviationStates[i] = deviationMapper.toState(list[i]);
        }
    }
    state.setDeviationStates(deviationStates);
    return state;
}
Also used : DeviationMapper(com.amazon.randomcutforest.parkservices.state.statistics.DeviationMapper) DeviationState(com.amazon.randomcutforest.parkservices.state.statistics.DeviationState) Deviation(com.amazon.randomcutforest.parkservices.statistics.Deviation)

Example 5 with Deviation

use of com.amazon.randomcutforest.parkservices.statistics.Deviation in project random-cut-forest-by-aws by aws.

the class InitialSegmentPreprocessor method getFactors.

// computes the normalization factors
protected double[] getFactors() {
    double[] factors = null;
    if (requireInitialSegment(false, transformMethod)) {
        Deviation[] tempList = new Deviation[inputLength];
        for (int j = 0; j < inputLength; j++) {
            tempList[j] = new Deviation(deviationList[j].getDiscount());
        }
        for (int i = 0; i < initialValues.length; i++) {
            for (int j = 0; j < inputLength; j++) {
                double value;
                if (transformMethod == TransformMethod.NORMALIZE) {
                    value = initialValues[i][j];
                } else {
                    value = (i == 0) ? 0 : initialValues[i][j] - initialValues[i - 1][j];
                }
                tempList[j].update(value);
            }
        }
        factors = new double[inputLength];
        for (int j = 0; j < inputLength; j++) {
            factors[j] = tempList[j].getDeviation();
        }
    }
    return factors;
}
Also used : Deviation(com.amazon.randomcutforest.parkservices.statistics.Deviation)

Aggregations

Deviation (com.amazon.randomcutforest.parkservices.statistics.Deviation)6 DeviationMapper (com.amazon.randomcutforest.parkservices.state.statistics.DeviationMapper)3 Preprocessor (com.amazon.randomcutforest.parkservices.preprocessor.Preprocessor)1 DeviationState (com.amazon.randomcutforest.parkservices.state.statistics.DeviationState)1 BasicThresholder (com.amazon.randomcutforest.parkservices.threshold.BasicThresholder)1