spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mengxr <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-1553] Alternating nonnegative least-squ...
Date Fri, 25 Apr 2014 06:48:31 GMT
Github user mengxr commented on a diff in the pull request:

    https://github.com/apache/spark/pull/460#discussion_r11984717
  
    --- Diff: mllib/src/main/scala/org/apache/spark/mllib/optimization/NNLSbyPCG.scala ---
    @@ -0,0 +1,183 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You 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.
    + */
    +
    +package org.apache.spark.mllib.optimization
    +
    +import org.jblas.{DoubleMatrix, SimpleBlas}
    +
    +import org.apache.spark.annotation.DeveloperApi
    +
    +
    +/**
    + * :: DeveloperApi ::
    + * Object used to solve nonnegative least squares problems using a modified
    + * projected gradient method.
    + */
    +@DeveloperApi
    +private[mllib] object NNLSbyPCG {
    +  class Workspace(val n: Int) {
    +    val scratch = new DoubleMatrix(n, 1)
    +    val grad = new DoubleMatrix(n, 1)
    +    val x = new DoubleMatrix(n, 1)
    +    val dir = new DoubleMatrix(n, 1)
    +    val lastDir = new DoubleMatrix(n, 1)
    +    val res = new DoubleMatrix(n, 1)
    +
    +    def wipe() {
    +      var i: Int = 0
    +      while (i < n) {
    +        scratch.data(i) = 0.0
    +        grad.data(i) = 0.0
    +        x.data(i) = 0.0
    +        dir.data(i) = 0.0
    +        lastDir.data(i) = 0.0
    +        res.data(i) = 0.0
    +        i = i + 1
    +      }
    +    }
    +  }
    +
    +  def createWorkspace(n: Int): Workspace = {
    +    new Workspace(n)
    +  }
    +
    +  /**
    +   * Solve a least squares problem, possibly with nonnegativity constraints, by a modified
    +   * projected gradient method.  That is, find x minimising ||Ax - b||_2 given A^T A
and A^T b.
    +   *
    +   * We solve the problem
    +   *   min_x      1/2 x^T ata x^T - x^T atb
    --- End diff --
    
    Do we need to mention `lambda I` somewhere? It is actually `AtA + \lambda I`. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message