def __init__(self):
     super(Container, self).__init__()
     self.basis = Basis(self.X.shape[1])
     self.parent = ConstantBasisFunction()
     self.bf1 = HingeBasisFunction(self.parent, 1.0, 10, 1, False)
     self.bf2 = HingeBasisFunction(self.parent, 1.0, 4, 2, True)
     self.bf3 = HingeBasisFunction(self.bf2, 1.0, 4, 3, True)
     self.bf4 = LinearBasisFunction(self.parent, 2)
     self.bf5 = HingeBasisFunction(self.parent, 1.5, 8, 2, True)
     self.basis.append(self.parent)
     self.basis.append(self.bf1)
     self.basis.append(self.bf2)
     self.basis.append(self.bf3)
     self.basis.append(self.bf4)
     self.basis.append(self.bf5)
예제 #2
0
                            if_platform_not_win_32)
from nose.tools import (assert_equal, assert_true, assert_almost_equal,
                        assert_list_equal, assert_raises, assert_not_equal)
import numpy
from scipy.sparse import csr_matrix
from pyearth._types import BOOL
from pyearth._basis import (Basis, ConstantBasisFunction, HingeBasisFunction,
                            LinearBasisFunction)
from pyearth import Earth
import pyearth
from numpy.testing.utils import assert_array_almost_equal

regenerate_target_files = False

numpy.random.seed(1)
basis = Basis(10)
constant = ConstantBasisFunction()
basis.append(constant)
bf1 = HingeBasisFunction(constant, 0.1, 10, 1, False, 'x1')
bf2 = HingeBasisFunction(constant, 0.1, 10, 1, True, 'x1')
bf3 = LinearBasisFunction(bf1, 2, 'x2')
basis.append(bf1)
basis.append(bf2)
basis.append(bf3)
X = numpy.random.normal(size=(1000, 10))
missing = numpy.zeros_like(X, dtype=BOOL)
B = numpy.empty(shape=(1000, 4), dtype=numpy.float64)
basis.transform(X, missing, B)
beta = numpy.random.normal(size=4)
y = numpy.empty(shape=1000, dtype=numpy.float64)
y[:] = numpy.dot(B, beta) + numpy.random.normal(size=1000)