<commit_before>"""
Data-misfit functions.

* :class:`~fatiando.inversion.misfit.L2Norm`

----

"""
from __future__ import division
import numpy
import scipy.sparse

from .base import Objective
from ..utils import safe_dot


class L2Norm(Objective):
    """

    Examples:

        >>> import numpy
        >>> solver = L2Norm(numpy.array([1, 2, 3]), 2)
        >>> solver
        L2Norm(data=array([1, 2, 3]), nparams=2, weights=None, islinear=False)
        >>> solver.set_data(numpy.array([4, 5, 6]))
        L2Norm(data=array([4, 5, 6]), nparams=2, weights=None, islinear=False)

    """

    def __init__(self, data, nparams, weights=None, islinear=False):
        super(L2Norm, self).__init__(nparams, islinear=islinear)
        self.data = data
        self.ndata = len(data)
        self._cache['predicted'] = {'hash':'', 'array':None}
        self._cache['jacobian'] = {'hash':'', 'array':None}
        self._cache['hessian'] = {'hash':'', 'array':None}
        if weights is not None:
            self.set_weights(weights)
        else:
            self.weights = None

    def __repr__(self):
        return 'L2Norm(data=%s, nparams=%d, weights=%s, islinear=%s)' % (
                repr(self.data), self.nparams, repr(self.weights),
                str(self.islinear))

    def _get_predicted(self, p):
        raise NotImplementedError("Predicted data not implemented")

    def _get_jacobian(self, p):
        raise NotImplementedError("Jacobian matrix not implemented")

    def set_data(self, data):
        """
        """
        self.data = data
        return self<commit_msg>Better array representation in L2Norm<commit_after>"""
Data-misfit functions.

* :class:`~fatiando.inversion.misfit.L2Norm`

----

"""
from __future__ import division
import numpy
import scipy.sparse

from .base import Objective
from ..utils import safe_dot


class L2Norm(Objective):
    """

    Examples:

        >>> import numpy
        >>> solver = L2Norm(numpy.array([1, 2, 3]), 2)
        >>> solver
        L2Norm(
            data=array([1, 2, 3]),
            nparams=2,
            islinear=False,
            weights=None)
        >>> solver.set_data(numpy.array([4, 5, 6]))
        L2Norm(
            data=array([4, 5, 6]),
            nparams=2,
            islinear=False,
            weights=None)

    """

    def __init__(self, data, nparams, weights=None, islinear=False):
        super(L2Norm, self).__init__(nparams, islinear=islinear)
        self.data = data
        self.ndata = len(data)
        self._cache['predicted'] = {'hash':'', 'array':None}
        self._cache['jacobian'] = {'hash':'', 'array':None}
        self._cache['hessian'] = {'hash':'', 'array':None}
        if weights is not None:
            self.set_weights(weights)
        else:
            self.weights = None

    def __repr__(self):
        lw = 60
        prec = 3
        text = '\n'.join([
            'L2Norm(',
            '    data=%s,' % (numpy.array_repr(
                self.data, max_line_width=lw, precision=prec)),
            '    nparams=%d,'  % (self.nparams),
            '    islinear=%s,' % (repr(self.islinear)),
            '    weights=%s)' % (
                repr(self.weights) if self.weights is None
                else numpy.array_repr(
                    self.weights, max_line_width=lw, precision=prec))])
        return text

    def _get_predicted(self, p):
        raise NotImplementedError("Predicted data not implemented")

    def _get_jacobian(self, p):
        raise NotImplementedError("Jacobian matrix not implemented")

    def set_data(self, data):
        """
        """
        self.data = data
        return self
{'fraction_non_alphanumeric': 0.14512161792839573, 'fraction_numerical': 0.013118338343809785, 'mean_word_length': 2.23321554770318, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '3193338', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1141, 'n_words': 247}