<commit_before>/*
 * Copyright 2010-2011 DIMA Research Group, TU Berlin
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @author: <NAME> <<EMAIL>>
 */

#ifndef CLUSTEREDVALUEPROVIDER_H_
#define CLUSTEREDVALUEPROVIDER_H_

#include "runtime/provider/value/ValueProvider.h"
#include "runtime/provider/value/ConstValueProvider.h"

using namespace Poco;

namespace Myriad {

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// value provider for clustered values
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

template<typename ValueType, class CxtRecordType, class PrFunctionType, class RangeProviderType>
class ClusteredValueProvider: public ValueProvider<ValueType, CxtRecordType>
{
public:

    ClusteredValueProvider(const PrFunctionType& prFunction, RangeProviderType& rangeProvider) :
        ValueProvider<ValueType, CxtRecordType>(rangeProvider.arity()+1, true),
        _prFunction(prFunction),
        _rangeProvider(rangeProvider)
    {
    }

    virtual ~ClusteredValueProvider()
    {
    }

    virtual Interval<I64u> fieldValueRange(const ValueType& value, const AutoPtr<CxtRecordType>& cxtRecordPtr, RandomStream& random)
    {
        Interval<I64u> currentRange = _rangeProvider(cxtRecordPtr, random);
        Decimal currentRangeLength = currentRange.length();

        Decimal cdf = _prFunction.cdf(value);
        Decimal pdf = _prFunction.pdf(value);

        return Interval<I64u>(currentRange.min() + (cdf-pdf) * currentRangeLength + 0.5, currentRange.min() + cdf * currentRangeLength + 0.5);
    }

    virtual const ValueType operator()(const AutoPtr<CxtRecordType>& ctxRecordPtr, RandomStream& random)
    {
        Interval<I64u> currentRange = _rangeProvider(ctxRecordPtr, random);
        I64u currentRangeLength = currentRange.length();
        Decimal currentRangeLengthDecimal = currentRange.length();

        return static_cast<ValueType>(_prFunction.sample(((ctxRecordPtr->genID() - currentRange.min()) % currentRangeLength)/currentRangeLengthDecimal));
    }

private:

    const PrFunctionType& _prFunction;

    ConstRangeProvider<I64u, CxtRecordType>& _rangeProvider;
};

} // namespace Myriad

#endif /* CLUSTEREDVALUEPROVIDER_H_ */<commit_msg>Fixed wrong _rangeProvider member type in the ClusteredValueProvider.<commit_after>/*
 * Copyright 2010-2011 DIMA Research Group, TU Berlin
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @author: <NAME> <<EMAIL>>
 */

#ifndef CLUSTEREDVALUEPROVIDER_H_
#define CLUSTEREDVALUEPROVIDER_H_

#include "runtime/provider/value/ValueProvider.h"
#include "runtime/provider/value/ConstValueProvider.h"

using namespace Poco;

namespace Myriad {

// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
// value provider for clustered values
// ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

template<typename ValueType, class CxtRecordType, class PrFunctionType, class RangeProviderType>
class ClusteredValueProvider: public ValueProvider<ValueType, CxtRecordType>
{
public:

    ClusteredValueProvider(const PrFunctionType& prFunction, RangeProviderType& rangeProvider) :
        ValueProvider<ValueType, CxtRecordType>(rangeProvider.arity()+1, true),
        _prFunction(prFunction),
        _rangeProvider(rangeProvider)
    {
    }

    virtual ~ClusteredValueProvider()
    {
    }

    virtual Interval<I64u> fieldValueRange(const ValueType& value, const AutoPtr<CxtRecordType>& cxtRecordPtr, RandomStream& random)
    {
        Interval<I64u> currentRange = _rangeProvider(cxtRecordPtr, random);
        Decimal currentRangeLength = currentRange.length();

        Decimal cdf = _prFunction.cdf(value);
        Decimal pdf = _prFunction.pdf(value);

        return Interval<I64u>(currentRange.min() + (cdf-pdf) * currentRangeLength + 0.5, currentRange.min() + cdf * currentRangeLength + 0.5);
    }

    virtual const ValueType operator()(const AutoPtr<CxtRecordType>& ctxRecordPtr, RandomStream& random)
    {
        Interval<I64u> currentRange = _rangeProvider(ctxRecordPtr, random);
        I64u currentRangeLength = currentRange.length();
        Decimal currentRangeLengthDecimal = currentRange.length();

        return static_cast<ValueType>(_prFunction.sample(((ctxRecordPtr->genID() - currentRange.min()) % currentRangeLength)/currentRangeLengthDecimal));
    }

private:

    const PrFunctionType& _prFunction;

    RangeProviderType& _rangeProvider;
};

} // namespace Myriad

#endif /* CLUSTEREDVALUEPROVIDER_H_ */
{'fraction_non_alphanumeric': 0.1161452714850773, 'fraction_numerical': 0.010068320747932399, 'mean_word_length': 3.897007042253521, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 32, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6076415', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1616, 'n_words': 402}