<commit_before>#!/usr/bin/env python
"""
This file introduces an extension to the basic Study-class which allows to add data step by step and keep an updated
parameter distribution, allowing to analyze data streams online.
"""

import numpy as np
from .study import Study


class OnlineStudy(Study):
    """
    This class builds on the Study-class and features a step-method to include new data points in the study as they
    arrive from a data stream. This online-analysis is performed in an forward-only way, resulting in filtering-
    distributions only. If one is interested in smoothing-distributions, use the conventional fit-method.

    Note: Only the complete rawData is preserved; all results are only current results and have to be stored by external
        functions to be used later.
    """
    def __init__(self):
        super(OnlineStudy, self).__init__()

        self.posteriorDistribution = None
        self.posteriorMeanValue = None
        print '  --> Online study'

    def step(self, dataPoint):
        """
        Update the current parameter distribution by adding a new data point to the data set.

        Parameters:
            dataPoint - Float, int, or 1D-array of those (for multidimensional data).

        Returns:
            None
        """
        self.rawData = np.append(self.rawData, dataPoint)

        # initialize posterior distribution as flat prior
        if self.posteriorDistribution is None:
            self.posteriorDistribution = np.ones(self.gridSize)/np.prod(np.array(self.gridSize))
            print '    + Initialized flat prior distribution.'<commit_msg>Fixed handling of multivariate data<commit_after>#!/usr/bin/env python
"""
This file introduces an extension to the basic Study-class which allows to add data step by step and keep an updated
parameter distribution, allowing to analyze data streams online.
"""

import numpy as np
from .study import Study


class OnlineStudy(Study):
    """
    This class builds on the Study-class and features a step-method to include new data points in the study as they
    arrive from a data stream. This online-analysis is performed in an forward-only way, resulting in filtering-
    distributions only. If one is interested in smoothing-distributions, use the conventional fit-method.

    Note: Only the complete rawData is preserved; all results are only current results and have to be stored by external
        functions to be used later.
    """
    def __init__(self):
        super(OnlineStudy, self).__init__()

        self.posteriorDistribution = None
        self.posteriorMeanValue = None
        print '  --> Online study'

    def step(self, dataPoint):
        """
        Update the current parameter distribution by adding a new data point to the data set.

        Parameters:
            dataPoint - Float, int, or 1D-array of those (for multidimensional data).

        Returns:
            None
        """
        if len(self.rawData) == 0:
            self.rawData = np.array([dataPoint])
        else:
            self.rawData = np.append(self.rawData, np.array([dataPoint]), axis=0)

        # initialize posterior distribution as flat prior
        if self.posteriorDistribution is None:
            self.posteriorDistribution = np.ones(self.gridSize)/np.prod(np.array(self.gridSize))
            print '    + Initialized flat prior distribution.'
{'fraction_non_alphanumeric': 0.06999409332545777, 'fraction_numerical': 0.0011813349084465446, 'mean_word_length': 2.754988913525499, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '322226', 'n_tokens_mistral': 870, 'n_tokens_neox': 815, 'n_words': 362}