<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>In-Database Factorized Learning</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>Hung Q. Ngo</string-name>
          <email>hung.ngo@logicblox.com</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>XuanLong Nguyen</string-name>
          <email>xuanlong@umich.edu</email>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Dan Olteanu</string-name>
          <email>dan.olteanu@cs.ox.ac.uk</email>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Maximilian Schleich</string-name>
          <email>max.schleich@cs.ox.ac.uk</email>
          <xref ref-type="aff" rid="aff2">2</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>LogicBlox, Inc</institution>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>University of Michigan</institution>
          ,
          <country country="US">USA</country>
        </aff>
        <aff id="aff2">
          <label>2</label>
          <institution>University of Oxford</institution>
        </aff>
      </contrib-group>
      <abstract>
        <p>In this paper, we overview recent contributions on in-database analytics for a class of optimization problems that are important for LogicBlox retail-planning and forecasting applications [4, 5, 7]. The class includes ridge linear regression, polynomial regression, factorization machines, principal component analysis and classi cation models. Such problems are typically computed over input data dened by a feature extraction join query on data sources residing inside a database. The query result can have a large number of attributes and records, which leads to large compute times or failure to process the entire dataset for conventional analytics engines. Pushing analytical computation inside the database engine saves non-trivial time usually spent on data import/export at the interface between database systems and statistical packages. In addition, a large part of the computational challenge for optimization problems can be addressed with conventional database techniques. To show this, we decouple the data-dependent computation from the computation of the optimal solution. The data-dependent step can be phrased as factorized computation of many inter-related aggregates over database joins [3,7]. We further exploit functional dependencies to reduce the dimensionality of the optimization problem [4]. Motivated by the industrial applications, this line of work attracted increasing interest in academia recently [1].</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>Introduction</title>
    </sec>
    <sec id="sec-2">
      <title>Problem formulation</title>
      <p>
        We use a uni ed framework to express and solve optimization problems [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
      </p>
      <p>In the following, bold face letters (e.g., x, xi, ) denote vectors or matrices,
normal face letters (e.g., xi, j ) denote scalars, and h ; i denotes the Frobenius
inner product of two matrices. Let Q be a feature extraction join query and D
a database that de nes the training dataset Q(D) for an optimization problem.
Suppose the problem has p parameters = ( 1; : : : ; p) 2 Rp, as well as response
y and n numeric features x = (x1; : : : ; xn), provided by the data points (x; y) 2
Q(D). For a positive integer m, there exist two vector-valued functions g : Rp !
Rm and h : Rn ! Rm. Each component function gj of g = (gj )j2[m] is a
multivariate polynomial of model parameters. Each component function hj of h =
(hj )j2[m] is a multivariate monomial of input features. Using the least-squares
J ( ) :=</p>
      <p>J ( ) =
1
1</p>
      <p>X</p>
      <p>X
loss function with `2-regularization, all problems in our class of optimization
problems are captured in the following objective function:</p>
      <p>
        We exemplify the case of ridge linear and polynomial regression [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
      </p>
      <p>The ridge linear regression model with response y and features x = (x0 =
1; x1; : : : ; xn) has p = n + 1 parameters = ( 0; : : : ; n) and the objective
2jQ(D)j (x;y)2Q(D)
(hg( ); h(x)i
y)2 + 2 k k22 :
(1)
2jQ(D)j (x;y)2Q(D) i=0
n
X
ixi
y
!2
+ 2 k k22 :
This has the form (1) with m = n + 1, where g and h are the identity functions:
g( ) = and h(x) = x.</p>
      <p>The degree-d polynomial regression model with response y and features x =
(x0 = 1; x1; : : : ; xn) extends the ridge linear regression model with all possible
feature interactions up to degree d. Thus, each component function hj de nes
one interaction (e.g. x2x3x5) and gj de nes the corresponding parameter ( 235).
Formally, the model has p = m = Pid=0 ni parameters = ( a), where a =
(a1; : : : ; an) is a tuple of non-negative integers such that Pin=1 ai d. In this
case, g( ) = and h is de ned by the component functions ha(x) = Qin=1 xiai .
3</p>
      <p>E</p>
      <p>
        ciently Solving the Optimization Problems
We outline how to compute e ciently solutions to problems of the form (1).
First, we consider problems with continuous features [
        <xref ref-type="bibr" rid="ref5 ref7">5,7</xref>
        ], and then generalize to
continuous and categorical features [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. The di erence is that continuous features
are quantitative, whereas categorical features encode qualitative properties (e.g.
color or store id). We then show how functional dependencies can be exploited
to reduce the dimensionality of the problem.
      </p>
      <p>
        Solutions for (1) can be computed with a variant of batch gradient descent
(BGD), which repeatedly updates the parameters in the direction of the gradient
until convergence := rJ ( ). To compute each BGD iteration e ciently,
we rewrite (1) to decouple the data-dependent computation from the parameters.
Theorem 1 ( [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] ) Let w = jQ(1D)j . De ne the matrix
vector c = (ci)i2[m], and the scalar sY by
h(x)h(x)&gt;;
c = w
      </p>
      <p>y h(x);</p>
      <p>X
(x;y)2Q(D)
= w</p>
      <p>X
(x;y)2Q(D)
Then, (1) becomes</p>
      <p>J ( ) =
rJ ( ) =
g( )
hg( ); ci + sY +
2</p>
      <p>2
2 k k2
(x;y)2Q(D)
(2)
, c, and sY can be expressed as sum-product functional aggregate queries
(FAQ) and computed inside the database. For example, in the case of linear
regression, the aggregates in are the sums of all possible pairwise products of
features (e.g. the SQL-aggregate SUM(Xi Xj ), 8i j 2 [n]).</p>
      <p>
        Our algorithms draw on earlier work on factorized databases [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ] and the
FAQ framework for computing aggregates over joins [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ]. All aggregates can be
computed in one pass over the (non-materialized) factorized join [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ]. Once these
aggregates are computed, each BGD iteration computes the gradient in
Equation (2) without scanning the data Q(D). The following runtime bounds do not
include log factors in the database size.
      </p>
      <p>
        Proposition 2 ( [
        <xref ref-type="bibr" rid="ref5 ref7">5, 7</xref>
        ] ) Let Q be a feature extraction join query, fhtw(Q)
denote its fractional hypertree width, and D a database. If all variables in Q are
continuous, then the aggregates ( ; c; sY ) for an optimization problem (1) can
be computed in O m2 jDjfhtw(Q) .
      </p>
      <p>
        For continuous variables, the size of and c is O(m2) and respectively
O(m). Thus, using the gradient (2) and the precomputed quantities ( ; c; sY ),
the running-time for BGD is bounded by a polynomial in terms of m, p, and the
number of iterations, but not database size. To put this result into context, if
we would rst compute the join using a worst-case optimal join algorithm and
then the aggregates, this would take time O(m2 jDj (Q)). For acyclic joins,
fhtw(Q) = 1, whereas (Q) can be as large as the number of relations in Q [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ].
      </p>
      <p>
        Our problem formulation (1) naturally captures the case of categorical
variables [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. Such variables are a common source of sparsity in optimization
problems, because they are one-hot encoded. Assume city is a categorical variable in
query Q and London, Oxford, Bristol are the only three cities occurring in the
query result. One-hot encoding transforms each component xcity of (x; y) 2 Q(D)
into a 3-dimensional vector xcity = [xLondon; xOxford; xBristol], where one of the three
values is 1 and the others 0, indicating which city occurs in this data point. If a
particular data point has city = \Oxford", then xcity = [0; 1; 0].
      </p>
      <p>One-hot encoding can potentially blow up the size of the input data, which
makes subsequent processing ine cient. In order to avoid the blow up, modern
analytics engines use a sparse representation of the input data. Transforming
the data into a sparse format, however, requires non-trivial time.</p>
      <p>In our framework, we can capture categorical features by turning the
aggregates required to compute , c, and sY into group-by aggregates with categorical
feature as free variables, as opposed to the sum aggregates without free variables
in Theorem 1. In the problem formulation (1), the feature vector x becomes a
vector of vectors, each component gj of g = (gj )j2[m] and hj of h = (hj )j2[m] is
a matrix, and each ( ij )i;j2[m] of as well as c are tensors.</p>
      <p>
        The dimensionality of ( ij )i;j2[m] and c can be very large, but fortunately
these tensors are very sparse and have many repeating values. Thus, we compute
a sparse tensor representation of and c with an algorithm that factorizes and
massively shares aggregate computation. We refer the reader to the full report
for details on the algorithm [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
      </p>
      <p>
        Proposition 3 ( [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ] ) Let faqw(i; j) denote the FAQ-width of the query
corresponding to ij , and S(i; j) denote the size of the sparse representation, i.e.,
the number of aggregates used to represent the tensor ij . Then, the aggregates
( ; c; sY ) can be computed in time O Pi;j2[m](jDjfaqw(i;j) + S(i; j)) .
      </p>
      <p>
        For acyclic queries, the FAQ-width [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ] is faqw(i; j) = 1. The gradient (2) can
now be computed over each tensor ij , whose size S(i; j) is bounded by the
database size due to the one-hot encoding. Thus, BGD is not completely
independent of the data size if the feature extraction query has categorical variables.
      </p>
      <p>
        A side e ect of one-hot encoding is that the categorical variables become
\linearized". We can exploit functional dependencies (FDs) on categorical variables
to reduce the dimensionality of the optimization problem [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
      </p>
      <p>
        Suppose we have the FD city ! country, where city and country are two
categorical variables in Q and xcity and xcountry are one-hot encoded vectors.
Then, using the one-hot encoding example from above, the following identity
must hold: xEngland = xLondon + xOxford + xBristol. We use this linear relationship
to rewrite the monomials in each component hj of h = (hj )j2[m] such that all
occurrences of xcountry are replaced by the functionally determining quantity xcity.
This leads to a reparameterization of the loss term [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ].
      </p>
      <p>
        The direct implication of the reparameterization is that the number of
required aggregates to compute and c can be reduced drastically. The e ect of
the reparameterization on the parameter space is less obvious, because the
`2regularization term is non-linear. Depending on the structure of the FD, however,
many of parameters corresponding to functionally determined statistics can be
optimized out [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ]. Therefore, the transformed parameter space is also reduced in
dimension, which can help speed up the convergence in the optimization phase.
      </p>
      <p>
        In practice, the interplay of e cient algorithms that compute ( ; c; sY ) and
the exploitation of FDs to reduce the dimensionality of the problem leads to
orders-of-magnitude performance improvements over state-of-the-art analytics
engines for optimization problems that are common for LogicBlox analytics [
        <xref ref-type="bibr" rid="ref4 ref7">4,7</xref>
        ].
      </p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          1.
          <string-name>
            <given-names>S.</given-names>
            <surname>Abiteboul</surname>
          </string-name>
          and et al.
          <source>Research Directions for Principles of Data Management (Dagstuhl Perspectives Workshop</source>
          <volume>16151</volume>
          ). CoRR, abs/1701.09007,
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          2.
          <string-name>
            <given-names>A.</given-names>
            <surname>Atserias</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Grohe</surname>
          </string-name>
          , and
          <string-name>
            <given-names>D.</given-names>
            <surname>Marx</surname>
          </string-name>
          .
          <article-title>Size bounds and query plans for relational joins</article-title>
          .
          <source>SIAM Journal on Computing</source>
          ,
          <volume>42</volume>
          (
          <issue>4</issue>
          ):
          <volume>1737</volume>
          {
          <fpage>1767</fpage>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          3.
          <string-name>
            <given-names>M. A.</given-names>
            <surname>Khamis</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H. Q.</given-names>
            <surname>Ngo</surname>
          </string-name>
          ,
          <article-title>and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Rudra</surname>
          </string-name>
          . FAQ:
          <article-title>Questions asked frequently</article-title>
          .
          <source>In PODS</source>
          , pages
          <volume>13</volume>
          {
          <fpage>28</fpage>
          ,
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          4.
          <string-name>
            <given-names>H.</given-names>
            <surname>Ngo</surname>
          </string-name>
          ,
          <string-name>
            <given-names>X.</given-names>
            <surname>Nguyen</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Olteanu</surname>
          </string-name>
          , and
          <string-name>
            <given-names>M.</given-names>
            <surname>Schleich</surname>
          </string-name>
          .
          <article-title>In-database learning with sparse tensors</article-title>
          ,
          <source>Technical Report. CoRR, abs/1703.04780</source>
          ,
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          5.
          <string-name>
            <given-names>D.</given-names>
            <surname>Olteanu</surname>
          </string-name>
          and
          <string-name>
            <given-names>M.</given-names>
            <surname>Schleich</surname>
          </string-name>
          .
          <article-title>Factorized databases</article-title>
          .
          <source>SIGMOD Rec</source>
          .,
          <volume>45</volume>
          (
          <issue>2</issue>
          ):5{
          <fpage>16</fpage>
          ,
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          6.
          <string-name>
            <given-names>D.</given-names>
            <surname>Olteanu</surname>
          </string-name>
          and
          <string-name>
            <given-names>J.</given-names>
            <surname>Zavodny</surname>
          </string-name>
          .
          <article-title>Size bounds for factorised representations of query results</article-title>
          .
          <source>TODS</source>
          ,
          <volume>40</volume>
          (
          <issue>1</issue>
          ):
          <fpage>2</fpage>
          ,
          <year>2015</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          7.
          <string-name>
            <given-names>M.</given-names>
            <surname>Schleich</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Olteanu</surname>
          </string-name>
          , and
          <string-name>
            <given-names>R.</given-names>
            <surname>Ciucanu</surname>
          </string-name>
          .
          <article-title>Learning linear regression models over factorized joins</article-title>
          .
          <source>In SIGMOD</source>
          , pages
          <volume>3</volume>
          {
          <fpage>18</fpage>
          ,
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>